diff options
-rw-r--r-- | Android.mk | 4 | ||||
-rw-r--r-- | build/apex/Android.bp | 2 | ||||
-rwxr-xr-x | build/apex/art_apex_test.py | 2 | ||||
-rw-r--r-- | compiler/Android.bp | 237 | ||||
-rw-r--r-- | compiler/export/jit_load.h | 31 | ||||
-rw-r--r-- | compiler/jit/jit_compiler.cc | 1 | ||||
-rw-r--r-- | compiler/optimizing/graph_visualizer.cc | 10 | ||||
-rw-r--r-- | dex2oat/Android.bp | 14 | ||||
-rw-r--r-- | imgdiag/Android.bp | 2 | ||||
-rw-r--r-- | oatdump/Android.bp | 14 | ||||
-rw-r--r-- | openjdkjvmti/Android.bp | 2 | ||||
-rw-r--r-- | runtime/Android.bp | 265 | ||||
-rw-r--r-- | runtime/jit/jit.cc | 45 | ||||
-rw-r--r-- | runtime/jit/jit.h | 3 | ||||
-rw-r--r-- | runtime/runtime.cc | 16 | ||||
-rw-r--r-- | test/Android.bp | 5 |
16 files changed, 278 insertions, 375 deletions
diff --git a/Android.mk b/Android.mk index 5324c3168d..041c23c437 100644 --- a/Android.mk +++ b/Android.mk @@ -411,6 +411,7 @@ LOCAL_REQUIRED_MODULES := \ $(call art_module_lib,dex2oat) \ $(call art_module_lib,dexoptanalyzer) \ $(call art_module_lib,libart) \ + $(call art_module_lib,libart-compiler) \ $(call art_module_lib,libopenjdkjvm) \ $(call art_module_lib,libopenjdkjvmti) \ $(call art_module_lib,odrefresh) \ @@ -433,6 +434,7 @@ LOCAL_REQUIRED_MODULES += \ $(call art_module_debug_lib,dex2oatd) \ $(call art_module_debug_lib,dexoptanalyzerd) \ $(call art_module_debug_lib,libartd) \ + $(call art_module_debug_lib,libartd-compiler) \ $(call art_module_debug_lib,libopenjdkd) \ $(call art_module_debug_lib,libopenjdkjvmd) \ $(call art_module_debug_lib,libopenjdkjvmtid) \ @@ -514,6 +516,7 @@ PRIVATE_ART_APEX_DEPENDENCY_LIBS := \ lib/libadbconnection.so \ lib/libandroidio.so \ lib/libartbase.so \ + lib/libart-compiler.so \ lib/libart-dexlayout.so \ lib/libart-disassembler.so \ lib/libartpalette.so \ @@ -542,6 +545,7 @@ PRIVATE_ART_APEX_DEPENDENCY_LIBS := \ lib64/libadbconnection.so \ lib64/libandroidio.so \ lib64/libartbase.so \ + lib64/libart-compiler.so \ lib64/libart-dexlayout.so \ lib64/libart-disassembler.so \ lib64/libartpalette.so \ diff --git a/build/apex/Android.bp b/build/apex/Android.bp index 1e91de90de..07b37f97ea 100644 --- a/build/apex/Android.bp +++ b/build/apex/Android.bp @@ -58,6 +58,7 @@ art_runtime_base_native_shared_libs_minus_libart = [ "libadbconnection", // TODO(b/124476339): Clean up the following libraries once "required" // dependencies work with APEX libraries. + "libart-compiler", "libdt_fd_forward", "libdt_socket", "libjdwp", @@ -106,6 +107,7 @@ art_runtime_debug_binaries_both_on_device_first_on_host = [ art_runtime_debug_native_shared_libs = [ "libadbconnectiond", "libartd", + "libartd-compiler", "libdexfiled", "libopenjdkjvmd", "libopenjdkjvmtid", diff --git a/build/apex/art_apex_test.py b/build/apex/art_apex_test.py index 8f145b9357..900ada7926 100755 --- a/build/apex/art_apex_test.py +++ b/build/apex/art_apex_test.py @@ -475,6 +475,7 @@ class ReleaseChecker: # Check internal libraries for ART. self._checker.check_native_library('libadbconnection') self._checker.check_native_library('libart') + self._checker.check_native_library('libart-compiler') self._checker.check_native_library('libart-dexlayout') self._checker.check_native_library('libart-disassembler') self._checker.check_native_library('libartbase') @@ -619,6 +620,7 @@ class DebugChecker: self._checker.check_native_library('libadbconnectiond') self._checker.check_native_library('libartbased') self._checker.check_native_library('libartd') + self._checker.check_native_library('libartd-compiler') self._checker.check_native_library('libartd-dexlayout') self._checker.check_native_library('libartd-disassembler') self._checker.check_native_library('libopenjdkjvmd') diff --git a/compiler/Android.bp b/compiler/Android.bp index 3b44e37e0a..117e8dc6b0 100644 --- a/compiler/Android.bp +++ b/compiler/Android.bp @@ -28,124 +28,6 @@ package { default_applicable_licenses: ["art_license"], } -// Common dependencies for debug/release libart-compiler builds -libart_cc_defaults { - name: "libart-compiler_common_dependencies", - shared_libs: [ - "libbase", - "liblzma", // libelffile(d) dependency; must be repeated here since it's a static lib. - ], -} - -// Collect all required dependencies for build targets that link against libart-compiler -// Workaround for lack of static_libs transitive dependencies propagation (b/169779783) -libart_cc_defaults { - name: "libart-compiler_dependencies", - defaults: ["libart-compiler_common_dependencies"], - - codegen: { - arm: { - // VIXL assembly support for ARM targets. - static_libs: [ - "libvixl", - ], - }, - arm64: { - // VIXL assembly support for ARM64 targets. - static_libs: [ - "libvixl", - ], - }, - }, - shared_libs: [ - "libartbase", - "libartpalette", - "libdexfile", - "libprofile", - ], - static_libs: [ - "libelffile", - ], - - // In order to save memory on device `art::HGraphVisualizerDisassembler` loads `libart-disassembler.so` - // dynamically. Host builds of `libart-compiler` depend on `libart-disassembler` directly with - // `shared_libs` or `static_libs` - target: { - host: { - shared: { - shared_libs: [ - "libart-disassembler", - ], - }, - }, - android: { - runtime_libs: [ - // `art::HGraphVisualizerDisassembler::HGraphVisualizerDisassembler` may dynamically load - // `libart-disassembler.so`. - "libart-disassembler", - ], - }, - }, -} - -libart_cc_defaults { - name: "libartd-compiler_dependencies", - defaults: ["libart-compiler_common_dependencies"], - - codegen: { - arm: { - // VIXL assembly support for ARM targets. - static_libs: [ - "libvixld", - ], - // Export vixl headers as they are included in this library's headers used by tests. - export_static_lib_headers: [ - "libvixld", - ], - }, - arm64: { - // VIXL assembly support for ARM64 targets. - static_libs: [ - "libvixld", - ], - // Export vixl headers as they are included in this library's headers used by tests. - export_static_lib_headers: [ - "libvixld", - ], - }, - }, - shared_libs: [ - "libartbased", - "libartd-disassembler", - "libartpalette", - "libdexfiled", - "libprofiled", - ], - static_libs: [ - "libelffiled", - ], - - // In order to save memory on device `art::HGraphVisualizerDisassembler` loads `libartd-disassembler.so` - // dynamically. Host builds of `libartd-compiler` depend on `libartd-disassembler` directly with - // `shared_libs` or `static_libs` - target: { - host: { - shared: { - shared_libs: [ - "libartd-disassembler", - ], - }, - }, - android: { - runtime_libs: [ - // `art::HGraphVisualizerDisassembler::HGraphVisualizerDisassembler` may dynamically load - // `libartd-disassembler.so`. - "libartd-disassembler", - ], - }, - }, -} - art_cc_defaults { name: "libart-compiler-defaults", defaults: ["art_defaults"], @@ -275,30 +157,29 @@ art_cc_defaults { ], }, }, + static: { + cflags: ["-DART_STATIC_LIBART_COMPILER"], + }, generated_sources: ["art_compiler_operator_srcs"], - export_include_dirs: ["."], + shared_libs: [ + "libbase", + "liblzma", // libelffile(d) dependency; must be repeated here since it's a static lib. + ], header_libs: [ "art_cmdlineparser_headers", // For compiler_options. "art_disassembler_headers", "libnativehelper_header_only", ], - // TODO: since libart-compiler is a static lib now - // replace version script with EXPORT/HIDDEN attributes + + export_include_dirs: ["."], // Not using .map.txt because this is an internal API version_script: "libart-compiler.map", } -// Export headers required by `libart-runtime` to use JIT from `libart-compiler` -cc_library_headers { - name: "libart-compiler_jit_headers", - defaults: ["art_defaults"], - host_supported: true, - - export_include_dirs: ["export"], - - apex_available: [ - "com.android.art", - "com.android.art.debug", +cc_defaults { + name: "libart-compiler_static_base_defaults", + whole_static_libs: [ + "libbase", ], } @@ -317,18 +198,41 @@ gensrcs { output_extension: "operator_out.cc", } -art_cc_library_static { +art_cc_library { name: "libart-compiler", defaults: [ - "art_hugepage_defaults", - "dex2oat-pgo-defaults", "libart-compiler-defaults", - "libart-compiler_dependencies", + "dex2oat-pgo-defaults", + "art_hugepage_defaults", ], - header_libs: [ - "libart_headers", - "libart_generated_headers", + codegen: { + arm: { + // VIXL assembly support for ARM targets. + static_libs: [ + "libvixl", + ], + }, + arm64: { + // VIXL assembly support for ARM64 targets. + static_libs: [ + "libvixl", + ], + }, + }, + shared_libs: [ + "libart", + "libartbase", + "libartpalette", + "libprofile", + "libdexfile", + ], + static_libs: ["libelffile"], + runtime_libs: [ + // `art::HGraphVisualizerDisassembler::HGraphVisualizerDisassembler` may dynamically load + // `libart-disassembler.so`. + "libart-disassembler", ], + target: { android: { lto: { @@ -345,25 +249,58 @@ art_cc_library_static { cc_defaults { name: "libart-compiler_static_defaults", defaults: [ - "libart-compiler_dependencies", + "libart-compiler_static_base_defaults", "libart-disassembler_static_defaults", + "libart_static_defaults", "libartbase_static_defaults", "libdexfile_static_defaults", "libprofile_static_defaults", ], + whole_static_libs: ["libart-compiler"], } -art_cc_library_static { +art_cc_library { name: "libartd-compiler", defaults: [ "art_debug_defaults", "libart-compiler-defaults", - "libartd-compiler_dependencies", ], - header_libs: [ - "libart_headers", - "libart_generated_headers", + codegen: { + arm: { + // VIXL assembly support for ARM targets. + static_libs: [ + "libvixld", + ], + // Export vixl headers as they are included in this library's headers used by tests. + export_static_lib_headers: [ + "libvixld", + ], + }, + arm64: { + // VIXL assembly support for ARM64 targets. + static_libs: [ + "libvixld", + ], + // Export vixl headers as they are included in this library's headers used by tests. + export_static_lib_headers: [ + "libvixld", + ], + }, + }, + shared_libs: [ + "libartbased", + "libartd", + "libartpalette", + "libprofiled", + "libdexfiled", + ], + static_libs: ["libelffiled"], + runtime_libs: [ + // `art::HGraphVisualizerDisassembler::HGraphVisualizerDisassembler` may dynamically load + // `libartd-disassembler.so`. + "libartd-disassembler", ], + apex_available: [ "com.android.art.debug", // TODO(b/183882457): This lib doesn't go into com.android.art, but @@ -376,12 +313,14 @@ art_cc_library_static { cc_defaults { name: "libartd-compiler_static_defaults", defaults: [ + "libart-compiler_static_base_defaults", "libartbased_static_defaults", - "libartd-compiler_dependencies", "libartd-disassembler_static_defaults", + "libartd_static_defaults", "libdexfiled_static_defaults", "libprofiled_static_defaults", ], + whole_static_libs: ["libartd-compiler"], } // Properties common to `libart-compiler-gtest` and `libartd-compiler-gtest`. @@ -402,6 +341,7 @@ art_cc_library { "libart-compiler-gtest-common", ], shared_libs: [ + "libart-compiler", "libart-disassembler", "libartbase-art-gtest", "libart-runtime-gtest", @@ -415,6 +355,7 @@ art_cc_library { "libart-compiler-gtest-common", ], shared_libs: [ + "libartd-compiler", "libartd-disassembler", "libartbased-art-gtest", "libartd-runtime-gtest", @@ -549,6 +490,7 @@ art_cc_test { "liblzma", ], static_libs: [ + "libartd-compiler", "libelffiled", "libvixld", ], @@ -574,6 +516,7 @@ art_cc_test { // TODO(b/192070541): Consider linking `libart-simulator-container` // dynamically. "libart-simulator-container", + "libart-compiler", "libelffile", "libvixl", ], @@ -611,6 +554,8 @@ art_cc_test { "liblzma", ], static_libs: [ + "libartd-compiler", "libelffiled", + "libvixld", ], } diff --git a/compiler/export/jit_load.h b/compiler/export/jit_load.h deleted file mode 100644 index 21a0254180..0000000000 --- a/compiler/export/jit_load.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2022 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef ART_COMPILER_EXPORT_JIT_LOAD_H_ -#define ART_COMPILER_EXPORT_JIT_LOAD_H_ - -namespace art { -namespace jit { - -class JitCompilerInterface; - -// used in `libart-runtime` to load `libart-compiler` JIT -extern "C" JitCompilerInterface* jit_load(); - -} // namespace jit -} // namespace art - -#endif // ART_COMPILER_EXPORT_JIT_LOAD_H_ diff --git a/compiler/jit/jit_compiler.cc b/compiler/jit/jit_compiler.cc index 07a9969285..f12a3ad52b 100644 --- a/compiler/jit/jit_compiler.cc +++ b/compiler/jit/jit_compiler.cc @@ -29,7 +29,6 @@ #include "compiler.h" #include "debug/elf_debug_writer.h" #include "driver/compiler_options.h" -#include "export/jit_load.h" #include "jit/debugger_interface.h" #include "jit/jit.h" #include "jit/jit_code_cache.h" diff --git a/compiler/optimizing/graph_visualizer.cc b/compiler/optimizing/graph_visualizer.cc index 1e41a22e91..e1199dfb72 100644 --- a/compiler/optimizing/graph_visualizer.cc +++ b/compiler/optimizing/graph_visualizer.cc @@ -115,9 +115,7 @@ std::ostream& operator<<(std::ostream& os, const StringList& list) { } } -// On target: load `libart-disassembler` only when required (to save on memory) -// On host: `libart-disassembler` should be linked directly (either as a static or dynamic lib) -#ifdef ART_TARGET +#ifndef ART_STATIC_LIBART_COMPILER using create_disasm_prototype = Disassembler*(InstructionSet, DisassemblerOptions*); #endif @@ -127,7 +125,7 @@ class HGraphVisualizerDisassembler { const uint8_t* base_address, const uint8_t* end_address) : instruction_set_(instruction_set), disassembler_(nullptr) { -#ifdef ART_TARGET +#ifndef ART_STATIC_LIBART_COMPILER constexpr const char* libart_disassembler_so_name = kIsDebugBuild ? "libartd-disassembler.so" : "libart-disassembler.so"; libart_disassembler_handle_ = dlopen(libart_disassembler_so_name, RTLD_NOW); @@ -161,7 +159,7 @@ class HGraphVisualizerDisassembler { ~HGraphVisualizerDisassembler() { // We need to call ~Disassembler() before we close the library. disassembler_.reset(); -#ifdef ART_TARGET +#ifndef ART_STATIC_LIBART_COMPILER if (libart_disassembler_handle_ != nullptr) { dlclose(libart_disassembler_handle_); } @@ -186,7 +184,7 @@ class HGraphVisualizerDisassembler { InstructionSet instruction_set_; std::unique_ptr<Disassembler> disassembler_; -#ifdef ART_TARGET +#ifndef ART_STATIC_LIBART_COMPILER void* libart_disassembler_handle_; #endif }; diff --git a/dex2oat/Android.bp b/dex2oat/Android.bp index 7bd2211143..5f7735fa9e 100644 --- a/dex2oat/Android.bp +++ b/dex2oat/Android.bp @@ -104,8 +104,9 @@ art_cc_library_static { name: "libart-dex2oat", defaults: ["libart-dex2oat-defaults"], shared_libs: [ - "libart", + "libart-compiler", "libart-dexlayout", + "libart", "libartpalette", "libprofile", ], @@ -126,6 +127,7 @@ cc_defaults { "libprofile_static_defaults", ], whole_static_libs: [ + "libart-compiler", "libart-dexlayout", "libart-dex2oat", ], @@ -156,8 +158,9 @@ art_cc_library_static { "libart-dex2oat-defaults", ], shared_libs: [ - "libartd", + "libartd-compiler", "libartd-dexlayout", + "libartd", "libartpalette", "libprofiled", ], @@ -177,6 +180,7 @@ cc_defaults { "libprofiled_static_defaults", ], whole_static_libs: [ + "libartd-compiler", "libartd-dexlayout", "libartd-dex2oat", ], @@ -300,6 +304,7 @@ art_cc_binary { android: { shared_libs: [ "libart", + "libart-compiler", "libart-dexlayout", "libartbase", "libdexfile", @@ -360,6 +365,7 @@ art_cc_binary { shared_libs: [ "libartbased", "libartd", + "libartd-compiler", "libartd-dexlayout", "libdexfiled", "libprofiled", @@ -436,6 +442,7 @@ art_cc_library_static { shared_libs: [ "libart-compiler-gtest", "libart-runtime-gtest", + "libart-compiler", "libart-disassembler", "libbase", "liblz4", // libart-dex2oat dependency; must be repeated here since it's a static lib. @@ -455,6 +462,7 @@ art_cc_library_static { shared_libs: [ "libartd-compiler-gtest", "libartd-runtime-gtest", + "libartd-compiler", "libartd-disassembler", "libbase", "liblz4", // libartd-dex2oat dependency; must be repeated here since it's a static lib. @@ -572,6 +580,7 @@ art_cc_test { "libprofiled", ], static_libs: [ + "libartd-compiler", "libartd-dex2oat", "libartd-dex2oat-gtest", "libelffiled", @@ -594,6 +603,7 @@ art_cc_test { "libprofile", ], static_libs: [ + "libart-compiler", "libart-dex2oat", "libart-dex2oat-gtest", "libelffile", diff --git a/imgdiag/Android.bp b/imgdiag/Android.bp index d54d7ac3d2..afd86a0f32 100644 --- a/imgdiag/Android.bp +++ b/imgdiag/Android.bp @@ -66,6 +66,7 @@ art_cc_binary { shared_libs: [ "libart", "libartbase", + "libart-compiler", ], apex_available: [ "com.android.art", @@ -82,6 +83,7 @@ art_cc_binary { shared_libs: [ "libartd", "libartbased", + "libartd-compiler", ], apex_available: [ "com.android.art.debug", diff --git a/oatdump/Android.bp b/oatdump/Android.bp index e22165d6b7..ba7ceb5930 100644 --- a/oatdump/Android.bp +++ b/oatdump/Android.bp @@ -62,6 +62,7 @@ art_cc_binary { android: { shared_libs: [ "libart", + "libart-compiler", "libart-dexlayout", "libart-disassembler", "libartbase", @@ -93,11 +94,11 @@ art_cc_library_static { device_supported: false, host_supported: true, defaults: [ - "libartbased_static_defaults", "libartd-compiler_static_defaults", "libartd-dexlayout_static_defaults", "libartd-disassembler_static_defaults", "libartd_static_defaults", + "libartbased_static_defaults", "libdexfiled_static_defaults", "libprofiled_static_defaults", "oatdump-defaults", @@ -119,6 +120,7 @@ art_cc_binary { shared_libs: [ "libartbased", "libartd", + "libartd-compiler", "libartd-dexlayout", "libartd-disassembler", "libbase", @@ -167,12 +169,12 @@ cc_defaults { art_cc_binary { name: "oatdumps", defaults: [ - "libart-compiler_static_defaults", - "libart-dexlayout_static_defaults", "libart_static_defaults", "libartbase_static_defaults", "libdexfile_static_defaults", "libprofile_static_defaults", + "libart-compiler_static_defaults", + "libart-dexlayout_static_defaults", "oatdumps-defaults", ], static_libs: [ @@ -185,12 +187,12 @@ art_cc_binary { name: "oatdumpds", defaults: [ "art_debug_defaults", - "libartbased_static_defaults", - "libartd-compiler_static_defaults", - "libartd-dexlayout_static_defaults", "libartd_static_defaults", + "libartbased_static_defaults", "libdexfiled_static_defaults", "libprofiled_static_defaults", + "libartd-compiler_static_defaults", + "libartd-dexlayout_static_defaults", "oatdumps-defaults", ], static_libs: [ diff --git a/openjdkjvmti/Android.bp b/openjdkjvmti/Android.bp index ed9eb9610b..c3df6db9c8 100644 --- a/openjdkjvmti/Android.bp +++ b/openjdkjvmti/Android.bp @@ -110,6 +110,7 @@ art_cc_library { defaults: ["libopenjdkjvmti_defaults"], shared_libs: [ "libart", + "libart-compiler", "libdexfile", "libartbase", ], @@ -127,6 +128,7 @@ art_cc_library { ], shared_libs: [ "libartd", + "libartd-compiler", "libdexfiled", "libartbased", ], diff --git a/runtime/Android.bp b/runtime/Android.bp index f88a0bea44..7bc685de3e 100644 --- a/runtime/Android.bp +++ b/runtime/Android.bp @@ -82,14 +82,8 @@ cc_library_headers { // ART's macros.h depends on libbase's macros.h. // Note: runtime_options.h depends on cmdline. But we don't really want to export this // generically. dex2oat takes care of it itself. - header_libs: [ - "art_libartbase_headers", - "dlmalloc", - ], - export_header_lib_headers: [ - "art_libartbase_headers", - "dlmalloc", - ], + header_libs: ["art_libartbase_headers"], + export_header_lib_headers: ["art_libartbase_headers"], // We optimize Thread::Current() with a direct TLS access. This requires // access to a platform specific Bionic header. @@ -110,82 +104,10 @@ cc_library_headers { ], } -// cpp-define-generator-asm-support depends on libart_headers through "asm_defines.s" -// This is a separate header lib to avoid circular dependency -cc_library_headers { - name: "libart_generated_headers", - defaults: ["art_defaults"], - host_supported: true, - - // asm_support_gen.h (used by asm_support.h) is generated with cpp-define-generator - generated_headers: ["cpp-define-generator-asm-support"], - // export our headers so the libart(d)-gtest targets can use it as well. - export_generated_headers: ["cpp-define-generator-asm-support"], - - apex_available: [ - "com.android.art", - "com.android.art.debug", - ], -} - -// Common defaults for libart-runtime_defaults and libart_defaults libart_cc_defaults { - name: "libart_common_defaults", + name: "libart_defaults", defaults: ["art_defaults"], host_supported: true, - target: { - android: { - header_libs: [ - "libnativeloader-headers", // For dlext_namespaces.h - ], - shared_libs: [ - "libdl_android", - "libstatssocket", - "libz", // For adler32. - "heapprofd_client_api", - ], - static_libs: [ - "libstatslog_art", - ], - }, - host: { - shared_libs: [ - "libz", // For adler32. - ], - }, - }, - header_libs: [ - "art_cmdlineparser_headers", - "cpp-define-generator-definitions", - "dlmalloc", - "jni_platform_headers", - "libart-compiler_jit_headers", - "libart_generated_headers", - "libart_headers", - "libnativehelper_header_only", - ], - export_header_lib_headers: [ - "dlmalloc", - "libart_generated_headers", - "libart_headers", - ], - shared_libs: [ - "libartpalette", - "libbase", // For common macros. - "liblog", - "liblz4", - "liblzma", // libelffile(d) dependency; must be repeated here since it's a static lib. - "libnativebridge", - "libnativeloader", - "libsigchain", - "libunwindstack", - ], - static_libs: ["libodrstatslog"], -} - -libart_cc_defaults { - name: "libart-runtime_defaults", - defaults: ["libart_common_defaults"], srcs: [ "app_info.cc", "aot_class_linker.cc", @@ -491,10 +413,34 @@ libart_cc_defaults { "thread_android.cc", "metrics/statsd.cc", ], + header_libs: [ + "libnativeloader-headers", // For dlext_namespaces.h + ], + shared_libs: [ + "libdl_android", + "libstatssocket", + "libz", // For adler32. + "heapprofd_client_api", + ], + static_libs: [ + "libstatslog_art", + ], generated_sources: [ "apex-info-list-tinyxml", ], }, + android_arm: { + ldflags: JIT_DEBUG_REGISTER_CODE_LDFLAGS, + }, + android_arm64: { + ldflags: JIT_DEBUG_REGISTER_CODE_LDFLAGS, + }, + android_x86: { + ldflags: JIT_DEBUG_REGISTER_CODE_LDFLAGS, + }, + android_x86_64: { + ldflags: JIT_DEBUG_REGISTER_CODE_LDFLAGS, + }, host: { srcs: [ "monitor_linux.cc", @@ -505,16 +451,60 @@ libart_cc_defaults { "-fsanitize-address-use-after-return=never", "-Wno-unused-command-line-argument", ], + shared_libs: [ + "libz", // For adler32. + ], }, }, generated_sources: [ "art_operator_srcs", ], + // asm_support_gen.h (used by asm_support.h) is generated with cpp-define-generator + generated_headers: ["cpp-define-generator-asm-support"], + // export our headers so the libart(d)-gtest targets can use it as well. + export_generated_headers: ["cpp-define-generator-asm-support"], + header_libs: [ + "art_cmdlineparser_headers", + "cpp-define-generator-definitions", + "dlmalloc", + "jni_platform_headers", + "libart_headers", + "libnativehelper_header_only", + ], + export_header_lib_headers: [ + "dlmalloc", + "libart_headers", + ], whole_static_libs: [ "libcpu_features", ], + shared_libs: [ + "libartpalette", + "libbase", // For common macros. + "liblog", + "liblz4", + "liblzma", // libelffile(d) dependency; must be repeated here since it's a static lib. + "libnativebridge", + "libnativeloader", + "libsigchain", + "libunwindstack", + ], + static_libs: ["libodrstatslog"], + + runtime_libs: [ + // Libraries loaded at runtime. Exceptions: + // - libart(d)-compiler.so and libopenjdk(d).so cannot be listed here + // due to cyclic dependency. + // - libicu_jni.so is only loaded to handle dependency order in VM + // startup (see Runtime::InitNativeMethods), but its API is internal + // to com.android.i18n and not used by ART/libcore. Therefore it's not + // listed here to avoid visibility issues. Instead it's linked from + // the ART module namespace through an entry in requireNativeLibs in + // manifest-art.json. + "libjavacore", + ], } libart_static_cc_defaults { @@ -550,7 +540,6 @@ libart_static_cc_defaults { cc_defaults { name: "libart_static_defaults", defaults: [ - "libart-compiler_static_defaults", "libart_static_base_defaults", "libartbase_static_defaults", "libdexfile_static_defaults", @@ -568,7 +557,6 @@ cc_defaults { defaults: [ "libart_static_base_defaults", "libartbased_static_defaults", - "libartd-compiler_static_defaults", "libdexfiled_static_defaults", "libdexfiled_support_static_defaults", "libprofiled_static_defaults", @@ -619,13 +607,15 @@ gensrcs { // We always build dex2oat and dependencies, even if the host build is otherwise disabled, since // they are used to cross compile for the target. -// Properties common to `libart-runtime` and `libart-runtime-broken`. +// Properties common to `libart` and `libart-broken`. art_cc_defaults { - name: "libart-runtime_common_defaults", + name: "libart_common_defaults", defaults: [ - "art_hugepage_defaults", - "libart-runtime_defaults", + "libart_defaults", "libart_nativeunwind_defaults", + "art_hugepage_defaults", + ], + whole_static_libs: [ ], static_libs: [ "libelffile", @@ -647,100 +637,37 @@ art_cc_defaults { }, } -// `libart-runtime` is runtime-only side of `libart` (without compiler) -// It doesn't have a source-level dependency on `libart-compiler`, except for the headers -// required to load JIT -art_cc_library_static { - name: "libart-runtime", - defaults: ["libart-runtime_common_defaults"], - apex_available: [ - "com.android.art", - "com.android.art.debug", - ], - afdo: true, -} - -libart_cc_defaults { - name: "libart_defaults", - defaults: ["libart_common_defaults"], - target: { - android_arm: { - ldflags: JIT_DEBUG_REGISTER_CODE_LDFLAGS, - }, - android_arm64: { - ldflags: JIT_DEBUG_REGISTER_CODE_LDFLAGS, - }, - android_x86: { - ldflags: JIT_DEBUG_REGISTER_CODE_LDFLAGS, - }, - android_x86_64: { - ldflags: JIT_DEBUG_REGISTER_CODE_LDFLAGS, - }, - }, - runtime_libs: [ - // Libraries loaded at runtime. Exceptions: - // - libopenjdk(d).so cannot be listed here due to cyclic dependency. - // - libicu_jni.so is only loaded to handle dependency order in VM - // startup (see Runtime::InitNativeMethods), but its API is internal - // to com.android.i18n and not used by ART/libcore. Therefore it's not - // listed here to avoid visibility issues. Instead it's linked from - // the ART module namespace through an entry in requireNativeLibs in - // manifest-art.json. - "libjavacore", - ], -} - // Release version of the ART runtime library. art_cc_library { name: "libart", - defaults: [ - "libart-compiler_dependencies", - "libart_defaults", - ], - // `libart-runtime` and `libart-compiler` are built separately because they use different - // optimization profiles (AFDO and PGO respectively), which can't be combined - whole_static_libs: [ - "libart-runtime", - "libart-compiler", - ], + defaults: ["libart_common_defaults"], apex_available: [ "com.android.art", "com.android.art.debug", ], -} - -art_cc_library_static { - name: "libart-runtime-broken", - defaults: ["libart-runtime_common_defaults"], - cflags: ["-DART_CRASH_RUNTIME_DELIBERATELY"], - apex_available: [ - "test_broken_com.android.art", - ], + afdo: true, } // "Broken" version of the ART runtime library, used only for testing. art_cc_test_library { name: "libart-broken", - defaults: [ - "libart-compiler_dependencies", - "libart_defaults", - ], + defaults: ["libart_common_defaults"], stem: "libart", gtest: false, - whole_static_libs: [ - "libart-runtime-broken", - "libart-compiler", - ], + cflags: ["-DART_CRASH_RUNTIME_DELIBERATELY"], apex_available: [ "test_broken_com.android.art", ], } -art_cc_library_static { - name: "libartd-runtime", +// Debug version of the ART runtime library. +art_cc_library { + name: "libartd", defaults: [ "art_debug_defaults", - "libart-runtime_defaults", + "libart_defaults", + ], + whole_static_libs: [ ], static_libs: [ "libelffiled", @@ -755,24 +682,6 @@ art_cc_library_static { ], apex_available: [ "com.android.art.debug", - "com.android.art", - ], -} - -// Debug version of the ART runtime library. -art_cc_library { - name: "libartd", - defaults: [ - "art_debug_defaults", - "libart_defaults", - "libartd-compiler_dependencies", - ], - whole_static_libs: [ - "libartd-compiler", - "libartd-runtime", - ], - apex_available: [ - "com.android.art.debug", // TODO(b/183882457): This lib doesn't go into com.android.art, but // apex_available lists need to be the same for internal libs to avoid // stubs, and this depends on libsigchain. diff --git a/runtime/jit/jit.cc b/runtime/jit/jit.cc index 21eddb513e..2cc4aef27a 100644 --- a/runtime/jit/jit.cc +++ b/runtime/jit/jit.cc @@ -31,14 +31,13 @@ #include "compilation_kind.h" #include "debugger.h" #include "dex/type_lookup_table.h" +#include "gc/space/image_space.h" #include "entrypoints/entrypoint_utils-inl.h" #include "entrypoints/runtime_asm_entrypoints.h" -#include "gc/space/image_space.h" #include "image-inl.h" #include "interpreter/interpreter.h" #include "jit-inl.h" #include "jit_code_cache.h" -#include "jit_load.h" #include "jni/java_vm_ext.h" #include "mirror/method_handle_impl.h" #include "mirror/var_handle.h" @@ -82,7 +81,9 @@ static constexpr uint32_t kJitSlowStressDefaultWarmupThreshold = DEFINE_RUNTIME_DEBUG_FLAG(Jit, kSlowMode); // JIT compiler +void* Jit::jit_library_handle_ = nullptr; JitCompilerInterface* Jit::jit_compiler_ = nullptr; +JitCompilerInterface* (*Jit::jit_load_)(void) = nullptr; JitOptions* JitOptions::CreateFromRuntimeArguments(const RuntimeArgumentMap& options) { auto* jit_options = new JitOptions; @@ -187,7 +188,15 @@ Jit::Jit(JitCodeCache* code_cache, JitOptions* options) fd_methods_size_(0) {} Jit* Jit::Create(JitCodeCache* code_cache, JitOptions* options) { - jit_compiler_ = jit_load(); + if (jit_load_ == nullptr) { + LOG(WARNING) << "Not creating JIT: library not loaded"; + return nullptr; + } + jit_compiler_ = (jit_load_)(); + if (jit_compiler_ == nullptr) { + LOG(WARNING) << "Not creating JIT: failed to allocate a compiler"; + return nullptr; + } std::unique_ptr<Jit> jit(new Jit(code_cache, options)); // If the code collector is enabled, check if that still holds: @@ -223,6 +232,32 @@ Jit* Jit::Create(JitCodeCache* code_cache, JitOptions* options) { return jit.release(); } +template <typename T> +bool Jit::LoadSymbol(T* address, const char* name, std::string* error_msg) { + *address = reinterpret_cast<T>(dlsym(jit_library_handle_, name)); + if (*address == nullptr) { + *error_msg = std::string("JIT couldn't find ") + name + std::string(" entry point"); + return false; + } + return true; +} + +bool Jit::LoadCompilerLibrary(std::string* error_msg) { + jit_library_handle_ = dlopen( + kIsDebugBuild ? "libartd-compiler.so" : "libart-compiler.so", RTLD_NOW); + if (jit_library_handle_ == nullptr) { + std::ostringstream oss; + oss << "JIT could not load libart-compiler.so: " << dlerror(); + *error_msg = oss.str(); + return false; + } + if (!LoadSymbol(&jit_load_, "jit_load", error_msg)) { + dlclose(jit_library_handle_); + return false; + } + return true; +} + bool Jit::CompileMethodInternal(ArtMethod* method, Thread* self, CompilationKind compilation_kind, @@ -374,6 +409,10 @@ Jit::~Jit() { delete jit_compiler_; jit_compiler_ = nullptr; } + if (jit_library_handle_ != nullptr) { + dlclose(jit_library_handle_); + jit_library_handle_ = nullptr; + } } void Jit::NewTypeLoadedIfUsingJit(mirror::Class* type) { diff --git a/runtime/jit/jit.h b/runtime/jit/jit.h index 7949926cb5..c95fd9d934 100644 --- a/runtime/jit/jit.h +++ b/runtime/jit/jit.h @@ -475,7 +475,10 @@ class Jit { REQUIRES_SHARED(Locks::mutator_lock_); // JIT compiler + static void* jit_library_handle_; static JitCompilerInterface* jit_compiler_; + static JitCompilerInterface* (*jit_load_)(void); + template <typename T> static bool LoadSymbol(T*, const char* symbol, std::string* error_msg); // JIT resources owned by runtime. jit::JitCodeCache* const code_cache_; diff --git a/runtime/runtime.cc b/runtime/runtime.cc index b43d190ed2..b38b2cb548 100644 --- a/runtime/runtime.cc +++ b/runtime/runtime.cc @@ -993,6 +993,11 @@ bool Runtime::Start() { // recoding profiles. Maybe we should consider changing the name to be more clear it's // not only about compiling. b/28295073. if (jit_options_->UseJitCompilation() || jit_options_->GetSaveProfilingInfo()) { + // Try to load compiler pre zygote to reduce PSS. b/27744947 + std::string error_msg; + if (!jit::Jit::LoadCompilerLibrary(&error_msg)) { + LOG(WARNING) << "Failed to load JIT compiler with error " << error_msg; + } CreateJitCodeCache(/*rwx_memory_allowed=*/true); CreateJit(); #ifdef ADDRESS_SANITIZER @@ -3039,8 +3044,15 @@ void Runtime::CreateJit() { return; } - jit_.reset(jit::Jit::Create(jit_code_cache_.get(), jit_options_.get())); - jit_->CreateThreadPool(); + jit::Jit* jit = jit::Jit::Create(jit_code_cache_.get(), jit_options_.get()); + jit_.reset(jit); + if (jit == nullptr) { + LOG(WARNING) << "Failed to allocate JIT"; + // Release JIT code cache resources (several MB of memory). + jit_code_cache_.reset(); + } else { + jit->CreateThreadPool(); + } } bool Runtime::CanRelocate() const { diff --git a/test/Android.bp b/test/Android.bp index 2795b929e0..c5322cbd72 100644 --- a/test/Android.bp +++ b/test/Android.bp @@ -302,6 +302,7 @@ art_cc_defaults { // not contain the "d" (debug) variants. shared_libs: [ "libart", + "libart-compiler", "libart-disassembler", "libdexfile", "libprofile", @@ -390,6 +391,7 @@ art_cc_defaults { ], shared_libs: [ "libart", + "libart-compiler", "libdexfile", "libprofile", "libartbase", @@ -404,6 +406,7 @@ art_cc_defaults { ], shared_libs: [ "libartd", + "libartd-compiler", "libdexfiled", "libprofiled", "libartbased", @@ -459,6 +462,7 @@ art_cc_library { ], shared_libs: [ "libart", + "libart-compiler", "libdexfile", "libprofile", "libartbase", @@ -479,6 +483,7 @@ art_cc_library { ], shared_libs: [ "libartd", + "libartd-compiler", "libdexfiled", "libprofiled", "libartbased", |