diff options
author | 2022-10-12 14:15:31 +0000 | |
---|---|---|
committer | 2022-11-07 18:15:11 +0000 | |
commit | 2b7be1efa1ba363778057d4e42fccab8afe3046b (patch) | |
tree | 968e6b9f257ff1848ba47cab5c33171fb82ead91 | |
parent | f776c17dbe99b989dcbefd08b746c3709b1752bf (diff) |
Merge libart and libart-compiler into a single library
Rename old libart into libart-runtime
Build libart-runtime and libart-compiler separately as static libraries
This is required to support PGO (compiler) and AFDO (runtime) without
mixing them
Combine libart-runtime and libart-compiler into libart with
whole-archive linking
This change negates all size savings from libart-compiler
version script, it will be restored in a follow-up CL
Bug: 186902856
Test: m test-art-host-gtest
Test: m libart libartd dex2oat dex2oatd oatdump oatdumps
Test: art/build/apex/runtests.sh
Test: art/tools/run-gtests.sh
Test: art/test/testrunner/testrunner.py --target --64
Test: art/tools/run-libcore-tests.sh --mode=device --variant=X64
Test: art/tools/run-libjdwp-tests.sh --mode=device --variant=X64
Change-Id: I6b9717cf49007e77691d49a2dca18a8064749154
-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, 375 insertions, 278 deletions
diff --git a/Android.mk b/Android.mk index 041c23c437..5324c3168d 100644 --- a/Android.mk +++ b/Android.mk @@ -411,7 +411,6 @@ 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) \ @@ -434,7 +433,6 @@ 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) \ @@ -516,7 +514,6 @@ 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 \ @@ -545,7 +542,6 @@ 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 07b37f97ea..1e91de90de 100644 --- a/build/apex/Android.bp +++ b/build/apex/Android.bp @@ -58,7 +58,6 @@ 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", @@ -107,7 +106,6 @@ 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 900ada7926..8f145b9357 100755 --- a/build/apex/art_apex_test.py +++ b/build/apex/art_apex_test.py @@ -475,7 +475,6 @@ 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') @@ -620,7 +619,6 @@ 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 117e8dc6b0..3b44e37e0a 100644 --- a/compiler/Android.bp +++ b/compiler/Android.bp @@ -28,6 +28,124 @@ 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"], @@ -157,29 +275,30 @@ art_cc_defaults { ], }, }, - static: { - cflags: ["-DART_STATIC_LIBART_COMPILER"], - }, generated_sources: ["art_compiler_operator_srcs"], - shared_libs: [ - "libbase", - "liblzma", // libelffile(d) dependency; must be repeated here since it's a static lib. - ], + export_include_dirs: ["."], header_libs: [ "art_cmdlineparser_headers", // For compiler_options. "art_disassembler_headers", "libnativehelper_header_only", ], - - export_include_dirs: ["."], + // TODO: since libart-compiler is a static lib now + // replace version script with EXPORT/HIDDEN attributes // Not using .map.txt because this is an internal API version_script: "libart-compiler.map", } -cc_defaults { - name: "libart-compiler_static_base_defaults", - whole_static_libs: [ - "libbase", +// 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", ], } @@ -198,41 +317,18 @@ gensrcs { output_extension: "operator_out.cc", } -art_cc_library { +art_cc_library_static { name: "libart-compiler", defaults: [ - "libart-compiler-defaults", - "dex2oat-pgo-defaults", "art_hugepage_defaults", + "dex2oat-pgo-defaults", + "libart-compiler-defaults", + "libart-compiler_dependencies", ], - 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", + header_libs: [ + "libart_headers", + "libart_generated_headers", ], - target: { android: { lto: { @@ -249,58 +345,25 @@ art_cc_library { cc_defaults { name: "libart-compiler_static_defaults", defaults: [ - "libart-compiler_static_base_defaults", + "libart-compiler_dependencies", "libart-disassembler_static_defaults", - "libart_static_defaults", "libartbase_static_defaults", "libdexfile_static_defaults", "libprofile_static_defaults", ], - whole_static_libs: ["libart-compiler"], } -art_cc_library { +art_cc_library_static { name: "libartd-compiler", defaults: [ "art_debug_defaults", "libart-compiler-defaults", + "libartd-compiler_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", - "libartpalette", - "libprofiled", - "libdexfiled", - ], - static_libs: ["libelffiled"], - runtime_libs: [ - // `art::HGraphVisualizerDisassembler::HGraphVisualizerDisassembler` may dynamically load - // `libartd-disassembler.so`. - "libartd-disassembler", + header_libs: [ + "libart_headers", + "libart_generated_headers", ], - apex_available: [ "com.android.art.debug", // TODO(b/183882457): This lib doesn't go into com.android.art, but @@ -313,14 +376,12 @@ art_cc_library { 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`. @@ -341,7 +402,6 @@ art_cc_library { "libart-compiler-gtest-common", ], shared_libs: [ - "libart-compiler", "libart-disassembler", "libartbase-art-gtest", "libart-runtime-gtest", @@ -355,7 +415,6 @@ art_cc_library { "libart-compiler-gtest-common", ], shared_libs: [ - "libartd-compiler", "libartd-disassembler", "libartbased-art-gtest", "libartd-runtime-gtest", @@ -490,7 +549,6 @@ art_cc_test { "liblzma", ], static_libs: [ - "libartd-compiler", "libelffiled", "libvixld", ], @@ -516,7 +574,6 @@ art_cc_test { // TODO(b/192070541): Consider linking `libart-simulator-container` // dynamically. "libart-simulator-container", - "libart-compiler", "libelffile", "libvixl", ], @@ -554,8 +611,6 @@ art_cc_test { "liblzma", ], static_libs: [ - "libartd-compiler", "libelffiled", - "libvixld", ], } diff --git a/compiler/export/jit_load.h b/compiler/export/jit_load.h new file mode 100644 index 0000000000..21a0254180 --- /dev/null +++ b/compiler/export/jit_load.h @@ -0,0 +1,31 @@ +/* + * 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 f12a3ad52b..07a9969285 100644 --- a/compiler/jit/jit_compiler.cc +++ b/compiler/jit/jit_compiler.cc @@ -29,6 +29,7 @@ #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 e1199dfb72..1e41a22e91 100644 --- a/compiler/optimizing/graph_visualizer.cc +++ b/compiler/optimizing/graph_visualizer.cc @@ -115,7 +115,9 @@ std::ostream& operator<<(std::ostream& os, const StringList& list) { } } -#ifndef ART_STATIC_LIBART_COMPILER +// 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 using create_disasm_prototype = Disassembler*(InstructionSet, DisassemblerOptions*); #endif @@ -125,7 +127,7 @@ class HGraphVisualizerDisassembler { const uint8_t* base_address, const uint8_t* end_address) : instruction_set_(instruction_set), disassembler_(nullptr) { -#ifndef ART_STATIC_LIBART_COMPILER +#ifdef ART_TARGET constexpr const char* libart_disassembler_so_name = kIsDebugBuild ? "libartd-disassembler.so" : "libart-disassembler.so"; libart_disassembler_handle_ = dlopen(libart_disassembler_so_name, RTLD_NOW); @@ -159,7 +161,7 @@ class HGraphVisualizerDisassembler { ~HGraphVisualizerDisassembler() { // We need to call ~Disassembler() before we close the library. disassembler_.reset(); -#ifndef ART_STATIC_LIBART_COMPILER +#ifdef ART_TARGET if (libart_disassembler_handle_ != nullptr) { dlclose(libart_disassembler_handle_); } @@ -184,7 +186,7 @@ class HGraphVisualizerDisassembler { InstructionSet instruction_set_; std::unique_ptr<Disassembler> disassembler_; -#ifndef ART_STATIC_LIBART_COMPILER +#ifdef ART_TARGET void* libart_disassembler_handle_; #endif }; diff --git a/dex2oat/Android.bp b/dex2oat/Android.bp index 5f7735fa9e..7bd2211143 100644 --- a/dex2oat/Android.bp +++ b/dex2oat/Android.bp @@ -104,9 +104,8 @@ art_cc_library_static { name: "libart-dex2oat", defaults: ["libart-dex2oat-defaults"], shared_libs: [ - "libart-compiler", - "libart-dexlayout", "libart", + "libart-dexlayout", "libartpalette", "libprofile", ], @@ -127,7 +126,6 @@ cc_defaults { "libprofile_static_defaults", ], whole_static_libs: [ - "libart-compiler", "libart-dexlayout", "libart-dex2oat", ], @@ -158,9 +156,8 @@ art_cc_library_static { "libart-dex2oat-defaults", ], shared_libs: [ - "libartd-compiler", - "libartd-dexlayout", "libartd", + "libartd-dexlayout", "libartpalette", "libprofiled", ], @@ -180,7 +177,6 @@ cc_defaults { "libprofiled_static_defaults", ], whole_static_libs: [ - "libartd-compiler", "libartd-dexlayout", "libartd-dex2oat", ], @@ -304,7 +300,6 @@ art_cc_binary { android: { shared_libs: [ "libart", - "libart-compiler", "libart-dexlayout", "libartbase", "libdexfile", @@ -365,7 +360,6 @@ art_cc_binary { shared_libs: [ "libartbased", "libartd", - "libartd-compiler", "libartd-dexlayout", "libdexfiled", "libprofiled", @@ -442,7 +436,6 @@ 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. @@ -462,7 +455,6 @@ 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. @@ -580,7 +572,6 @@ art_cc_test { "libprofiled", ], static_libs: [ - "libartd-compiler", "libartd-dex2oat", "libartd-dex2oat-gtest", "libelffiled", @@ -603,7 +594,6 @@ 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 afd86a0f32..d54d7ac3d2 100644 --- a/imgdiag/Android.bp +++ b/imgdiag/Android.bp @@ -66,7 +66,6 @@ art_cc_binary { shared_libs: [ "libart", "libartbase", - "libart-compiler", ], apex_available: [ "com.android.art", @@ -83,7 +82,6 @@ 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 ba7ceb5930..e22165d6b7 100644 --- a/oatdump/Android.bp +++ b/oatdump/Android.bp @@ -62,7 +62,6 @@ art_cc_binary { android: { shared_libs: [ "libart", - "libart-compiler", "libart-dexlayout", "libart-disassembler", "libartbase", @@ -94,11 +93,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", @@ -120,7 +119,6 @@ art_cc_binary { shared_libs: [ "libartbased", "libartd", - "libartd-compiler", "libartd-dexlayout", "libartd-disassembler", "libbase", @@ -169,12 +167,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: [ @@ -187,12 +185,12 @@ art_cc_binary { name: "oatdumpds", defaults: [ "art_debug_defaults", - "libartd_static_defaults", "libartbased_static_defaults", - "libdexfiled_static_defaults", - "libprofiled_static_defaults", "libartd-compiler_static_defaults", "libartd-dexlayout_static_defaults", + "libartd_static_defaults", + "libdexfiled_static_defaults", + "libprofiled_static_defaults", "oatdumps-defaults", ], static_libs: [ diff --git a/openjdkjvmti/Android.bp b/openjdkjvmti/Android.bp index c3df6db9c8..ed9eb9610b 100644 --- a/openjdkjvmti/Android.bp +++ b/openjdkjvmti/Android.bp @@ -110,7 +110,6 @@ art_cc_library { defaults: ["libopenjdkjvmti_defaults"], shared_libs: [ "libart", - "libart-compiler", "libdexfile", "libartbase", ], @@ -128,7 +127,6 @@ art_cc_library { ], shared_libs: [ "libartd", - "libartd-compiler", "libdexfiled", "libartbased", ], diff --git a/runtime/Android.bp b/runtime/Android.bp index 7bc685de3e..f88a0bea44 100644 --- a/runtime/Android.bp +++ b/runtime/Android.bp @@ -82,8 +82,14 @@ 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"], - export_header_lib_headers: ["art_libartbase_headers"], + header_libs: [ + "art_libartbase_headers", + "dlmalloc", + ], + export_header_lib_headers: [ + "art_libartbase_headers", + "dlmalloc", + ], // We optimize Thread::Current() with a direct TLS access. This requires // access to a platform specific Bionic header. @@ -104,10 +110,82 @@ 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_defaults", + name: "libart_common_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", @@ -413,34 +491,10 @@ 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", @@ -451,60 +505,16 @@ 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 { @@ -540,6 +550,7 @@ 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", @@ -557,6 +568,7 @@ cc_defaults { defaults: [ "libart_static_base_defaults", "libartbased_static_defaults", + "libartd-compiler_static_defaults", "libdexfiled_static_defaults", "libdexfiled_support_static_defaults", "libprofiled_static_defaults", @@ -607,15 +619,13 @@ 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` and `libart-broken`. +// Properties common to `libart-runtime` and `libart-runtime-broken`. art_cc_defaults { - name: "libart_common_defaults", + name: "libart-runtime_common_defaults", defaults: [ - "libart_defaults", - "libart_nativeunwind_defaults", "art_hugepage_defaults", - ], - whole_static_libs: [ + "libart-runtime_defaults", + "libart_nativeunwind_defaults", ], static_libs: [ "libelffile", @@ -637,37 +647,100 @@ 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_common_defaults"], + 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", + ], apex_available: [ "com.android.art", "com.android.art.debug", ], - afdo: true, +} + +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", + ], } // "Broken" version of the ART runtime library, used only for testing. art_cc_test_library { name: "libart-broken", - defaults: ["libart_common_defaults"], + defaults: [ + "libart-compiler_dependencies", + "libart_defaults", + ], stem: "libart", gtest: false, - cflags: ["-DART_CRASH_RUNTIME_DELIBERATELY"], + whole_static_libs: [ + "libart-runtime-broken", + "libart-compiler", + ], apex_available: [ "test_broken_com.android.art", ], } -// Debug version of the ART runtime library. -art_cc_library { - name: "libartd", +art_cc_library_static { + name: "libartd-runtime", defaults: [ "art_debug_defaults", - "libart_defaults", - ], - whole_static_libs: [ + "libart-runtime_defaults", ], static_libs: [ "libelffiled", @@ -682,6 +755,24 @@ art_cc_library { ], 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 2cc4aef27a..21eddb513e 100644 --- a/runtime/jit/jit.cc +++ b/runtime/jit/jit.cc @@ -31,13 +31,14 @@ #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" @@ -81,9 +82,7 @@ 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; @@ -188,15 +187,7 @@ Jit::Jit(JitCodeCache* code_cache, JitOptions* options) fd_methods_size_(0) {} Jit* Jit::Create(JitCodeCache* code_cache, JitOptions* options) { - 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; - } + jit_compiler_ = jit_load(); std::unique_ptr<Jit> jit(new Jit(code_cache, options)); // If the code collector is enabled, check if that still holds: @@ -232,32 +223,6 @@ 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, @@ -409,10 +374,6 @@ 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 c95fd9d934..7949926cb5 100644 --- a/runtime/jit/jit.h +++ b/runtime/jit/jit.h @@ -475,10 +475,7 @@ 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 b38b2cb548..b43d190ed2 100644 --- a/runtime/runtime.cc +++ b/runtime/runtime.cc @@ -993,11 +993,6 @@ 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 @@ -3044,15 +3039,8 @@ void Runtime::CreateJit() { return; } - 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(); - } + jit_.reset(jit::Jit::Create(jit_code_cache_.get(), jit_options_.get())); + jit_->CreateThreadPool(); } bool Runtime::CanRelocate() const { diff --git a/test/Android.bp b/test/Android.bp index c5322cbd72..2795b929e0 100644 --- a/test/Android.bp +++ b/test/Android.bp @@ -302,7 +302,6 @@ art_cc_defaults { // not contain the "d" (debug) variants. shared_libs: [ "libart", - "libart-compiler", "libart-disassembler", "libdexfile", "libprofile", @@ -391,7 +390,6 @@ art_cc_defaults { ], shared_libs: [ "libart", - "libart-compiler", "libdexfile", "libprofile", "libartbase", @@ -406,7 +404,6 @@ art_cc_defaults { ], shared_libs: [ "libartd", - "libartd-compiler", "libdexfiled", "libprofiled", "libartbased", @@ -462,7 +459,6 @@ art_cc_library { ], shared_libs: [ "libart", - "libart-compiler", "libdexfile", "libprofile", "libartbase", @@ -483,7 +479,6 @@ art_cc_library { ], shared_libs: [ "libartd", - "libartd-compiler", "libdexfiled", "libprofiled", "libartbased", |