summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Android.mk47
-rw-r--r--build/apex/Android.bp37
-rwxr-xr-xbuild/apex/runtests.sh9
-rw-r--r--compiler/optimizing/code_generator_x86_64.cc29
-rw-r--r--dex2oat/dex2oat_test.cc11
-rw-r--r--runtime/class_linker.cc81
-rw-r--r--runtime/class_linker.h10
-rw-r--r--runtime/class_loader_context.cc221
-rw-r--r--runtime/class_loader_context_test.cc311
-rw-r--r--runtime/class_root.h1
-rw-r--r--runtime/gc/heap.cc12
-rw-r--r--test/411-checker-hdiv-hrem-pow2/src/DivTest.java12
12 files changed, 666 insertions, 115 deletions
diff --git a/Android.mk b/Android.mk
index b9f617035c..3388b35aca 100644
--- a/Android.mk
+++ b/Android.mk
@@ -326,6 +326,53 @@ endif
#######################
+# Android Runtime APEX.
+
+include $(CLEAR_VARS)
+
+# The Android Runtime APEX comes in two flavors:
+# - the release module (`com.android.runtime.release`), containing
+# only "release" artifacts;
+# - the debug module (`com.android.runtime.debug`), containing both
+# "release" and "debug" artifacts, as well as additional tools.
+#
+# The Android Runtime APEX module (`com.android.runtime`) is an
+# "alias" for one of the previous modules. By default, "user" build
+# variants contain the release module, while "userdebug" and "eng"
+# build variant contain the debug module. However, if
+# `PRODUCT_ART_TARGET_INCLUDE_DEBUG_BUILD` is defined, it overrides
+# the previous logic:
+# - if `PRODUCT_ART_TARGET_INCLUDE_DEBUG_BUILD` is set to `false`, the
+# build will include the release module (whatever the build
+# variant);
+# - if `PRODUCT_ART_TARGET_INCLUDE_DEBUG_BUILD` is set to `true`, the
+# build will include the debug module (whatever the build variant).
+
+art_target_include_debug_build := $(PRODUCT_ART_TARGET_INCLUDE_DEBUG_BUILD)
+ifneq (false,$(art_target_include_debug_build))
+ ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT)))
+ art_target_include_debug_build := true
+ endif
+endif
+ifeq (true,$(art_target_include_debug_build))
+ # Module with both release and debug variants, as well as
+ # additional tools.
+ TARGET_RUNTIME_APEX := com.android.runtime.debug
+else
+ # Release module (without debug variants nor tools).
+ TARGET_RUNTIME_APEX := com.android.runtime.release
+endif
+
+LOCAL_MODULE := com.android.runtime
+LOCAL_REQUIRED_MODULES := $(TARGET_RUNTIME_APEX)
+
+# Clear locally used variable.
+art_target_include_debug_build :=
+
+include $(BUILD_PHONY_PACKAGE)
+
+
+#######################
# Fake packages for ART
# The art-runtime package depends on the core ART libraries and binaries. It exists so we can
diff --git a/build/apex/Android.bp b/build/apex/Android.bp
index 8bddb5dfe7..bfaacb10fa 100644
--- a/build/apex/Android.bp
+++ b/build/apex/Android.bp
@@ -72,8 +72,41 @@ apex_key {
private_key: "runtime.pem",
}
+// TODO: Introduce `apex_defaults` to factor common parts of `apex`
+// module definitions below?
+
+// Release version of the Runtime APEX module (not containing debug
+// variants nor tools), included in user builds. Also used for
+// storage-constrained devices in userdebug and eng builds.
+apex {
+ name: "com.android.runtime.release",
+ compile_multilib: "both",
+ manifest: "manifest.json",
+ native_shared_libs: art_runtime_base_native_shared_libs
+ + art_runtime_fake_native_shared_libs,
+ multilib: {
+ both: {
+ // TODO: Add logic to create a `dalvikvm` symlink to `dalvikvm32` or `dalvikvm64`
+ // (see `symlink_preferred_arch` in art/dalvikvm/Android.bp).
+ binaries: art_runtime_base_binaries_both,
+ },
+ prefer32: {
+ binaries: art_runtime_base_binaries_prefer32,
+ },
+ first: {
+ binaries: [],
+ }
+ },
+ key: "com.android.runtime.key",
+ // TODO: Also package a `ld.config.txt` config file (to be placed in `etc/`).
+ // ...
+}
+
+// "Debug" version of the Runtime APEX module (containing both release and
+// debug variants, as well as additional tools), included in userdebug and
+// eng build.
apex {
- name: "com.android.runtime",
+ name: "com.android.runtime.debug",
compile_multilib: "both",
manifest: "manifest.json",
native_shared_libs: art_runtime_base_native_shared_libs
@@ -87,7 +120,7 @@ apex {
},
prefer32: {
binaries: art_runtime_base_binaries_prefer32
- + art_runtime_debug_binaries_prefer32
+ + art_runtime_debug_binaries_prefer32,
},
first: {
binaries: art_tools_binaries,
diff --git a/build/apex/runtests.sh b/build/apex/runtests.sh
index 6af2a8bc5c..86cd8cb758 100755
--- a/build/apex/runtests.sh
+++ b/build/apex/runtests.sh
@@ -79,7 +79,8 @@ function finish {
trap finish EXIT
-apex_module="com.android.runtime"
+# TODO: Also exercise the Release Runtime APEX (`com.android.runtime.release`).
+apex_module="com.android.runtime.debug"
# Build the Android Runtime APEX package (optional).
$build_apex_p && say "Building package" && make "$apex_module"
@@ -190,10 +191,8 @@ check_library libprofiled.so
# libsigchain.so
# libtombstoned_client.so
# libunwindstack.so
-# libvixl-arm64.so
-# libvixl-arm.so
-# libvixld-arm64.so
-# libvixld-arm.so
+# libvixl.so
+# libvixld.so
# ...
#
# ?
diff --git a/compiler/optimizing/code_generator_x86_64.cc b/compiler/optimizing/code_generator_x86_64.cc
index 14cff05f58..e7212cd479 100644
--- a/compiler/optimizing/code_generator_x86_64.cc
+++ b/compiler/optimizing/code_generator_x86_64.cc
@@ -3608,9 +3608,17 @@ void InstructionCodeGeneratorX86_64::DivByPowerOfTwo(HDiv* instruction) {
CpuRegister tmp = locations->GetTemp(0).AsRegister<CpuRegister>();
if (instruction->GetResultType() == DataType::Type::kInt32) {
- __ leal(tmp, Address(numerator, abs_imm - 1));
- __ testl(numerator, numerator);
- __ cmov(kGreaterEqual, tmp, numerator);
+ // When denominator is equal to 2, we can add signed bit and numerator to tmp.
+ // Below we are using addl instruction instead of cmov which give us 1 cycle benefit.
+ if (abs_imm == 2) {
+ __ leal(tmp, Address(numerator, 0));
+ __ shrl(tmp, Immediate(31));
+ __ addl(tmp, numerator);
+ } else {
+ __ leal(tmp, Address(numerator, abs_imm - 1));
+ __ testl(numerator, numerator);
+ __ cmov(kGreaterEqual, tmp, numerator);
+ }
int shift = CTZ(imm);
__ sarl(tmp, Immediate(shift));
@@ -3622,11 +3630,16 @@ void InstructionCodeGeneratorX86_64::DivByPowerOfTwo(HDiv* instruction) {
} else {
DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64);
CpuRegister rdx = locations->GetTemp(0).AsRegister<CpuRegister>();
-
- codegen_->Load64BitValue(rdx, abs_imm - 1);
- __ addq(rdx, numerator);
- __ testq(numerator, numerator);
- __ cmov(kGreaterEqual, rdx, numerator);
+ if (abs_imm == 2) {
+ __ movq(rdx, numerator);
+ __ shrq(rdx, Immediate(63));
+ __ addq(rdx, numerator);
+ } else {
+ codegen_->Load64BitValue(rdx, abs_imm - 1);
+ __ addq(rdx, numerator);
+ __ testq(numerator, numerator);
+ __ cmov(kGreaterEqual, rdx, numerator);
+ }
int shift = CTZ(imm);
__ sarq(rdx, Immediate(shift));
diff --git a/dex2oat/dex2oat_test.cc b/dex2oat/dex2oat_test.cc
index baeebd9371..1fa21d51fc 100644
--- a/dex2oat/dex2oat_test.cc
+++ b/dex2oat/dex2oat_test.cc
@@ -1202,6 +1202,17 @@ TEST_F(Dex2oatClassLoaderContextTest, ChainContext) {
RunTest(context.c_str(), expected_classpath_key.c_str(), true);
}
+TEST_F(Dex2oatClassLoaderContextTest, ContextWithSharedLibrary) {
+ std::vector<std::unique_ptr<const DexFile>> dex_files1 = OpenTestDexFiles("Nested");
+ std::vector<std::unique_ptr<const DexFile>> dex_files2 = OpenTestDexFiles("MultiDex");
+
+ std::string context = "PCL[" + GetTestDexFileName("Nested") + "]" +
+ "{PCL[" + GetTestDexFileName("MultiDex") + "]}";
+ std::string expected_classpath_key = "PCL[" + CreateClassPathWithChecksums(dex_files1) + "]" +
+ "{PCL[" + CreateClassPathWithChecksums(dex_files2) + "]}";
+ RunTest(context.c_str(), expected_classpath_key.c_str(), true);
+}
+
class Dex2oatDeterminism : public Dex2oatTest {};
TEST_F(Dex2oatDeterminism, UnloadCompile) {
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index ce7dfaf8af..639fa7ec92 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -798,6 +798,8 @@ bool ClassLinker::InitWithoutImage(std::vector<std::unique_ptr<const DexFile>> b
FindSystemClass(self, "Ljava/lang/StackTraceElement;"));
SetClassRoot(ClassRoot::kJavaLangStackTraceElementArrayClass,
FindSystemClass(self, "[Ljava/lang/StackTraceElement;"));
+ SetClassRoot(ClassRoot::kJavaLangClassLoaderArrayClass,
+ FindSystemClass(self, "[Ljava/lang/ClassLoader;"));
// Create conflict tables that depend on the class linker.
runtime->FixupConflictTables();
@@ -8994,21 +8996,14 @@ void ClassLinker::AllocAndSetPrimitiveArrayClassRoot(Thread* self,
CheckSystemClass(self, primitive_array_class, descriptor);
}
-jobject ClassLinker::CreateWellKnownClassLoader(Thread* self,
- const std::vector<const DexFile*>& dex_files,
- jclass loader_class,
- jobject parent_loader) {
- CHECK(self->GetJniEnv()->IsSameObject(loader_class,
- WellKnownClasses::dalvik_system_PathClassLoader) ||
- self->GetJniEnv()->IsSameObject(loader_class,
- WellKnownClasses::dalvik_system_DelegateLastClassLoader));
-
- // SOAAlreadyRunnable is protected, and we need something to add a global reference.
- // We could move the jobject to the callers, but all call-sites do this...
- ScopedObjectAccessUnchecked soa(self);
+ObjPtr<mirror::ClassLoader> ClassLinker::CreateWellKnownClassLoader(
+ Thread* self,
+ const std::vector<const DexFile*>& dex_files,
+ Handle<mirror::Class> loader_class,
+ Handle<mirror::ObjectArray<mirror::ClassLoader>> shared_libraries,
+ Handle<mirror::ClassLoader> parent_loader) {
- // For now, create a libcore-level DexFile for each ART DexFile. This "explodes" multidex.
- StackHandleScope<6> hs(self);
+ StackHandleScope<5> hs(self);
ArtField* dex_elements_field =
jni::DecodeArtField(WellKnownClasses::dalvik_system_DexPathList_dexElements);
@@ -9098,8 +9093,8 @@ jobject ClassLinker::CreateWellKnownClassLoader(Thread* self,
}
// Create the class loader..
- Handle<mirror::Class> h_loader_class = hs.NewHandle(soa.Decode<mirror::Class>(loader_class));
- Handle<mirror::Object> h_class_loader = hs.NewHandle(h_loader_class->AllocObject(self));
+ Handle<mirror::ClassLoader> h_class_loader = hs.NewHandle<mirror::ClassLoader>(
+ ObjPtr<mirror::ClassLoader>::DownCast(loader_class->AllocObject(self)));
DCHECK(h_class_loader != nullptr);
// Set DexPathList.
ArtField* path_list_field =
@@ -9115,15 +9110,59 @@ jobject ClassLinker::CreateWellKnownClassLoader(Thread* self,
"parent",
"Ljava/lang/ClassLoader;");
DCHECK(parent_field != nullptr);
+ if (parent_loader.Get() == nullptr) {
+ ScopedObjectAccessUnchecked soa(self);
+ ObjPtr<mirror::Object> boot_loader(soa.Decode<mirror::Class>(
+ WellKnownClasses::java_lang_BootClassLoader)->AllocObject(self));
+ parent_field->SetObject<false>(h_class_loader.Get(), boot_loader);
+ } else {
+ parent_field->SetObject<false>(h_class_loader.Get(), parent_loader.Get());
+ }
+
+ ArtField* shared_libraries_field =
+ jni::DecodeArtField(WellKnownClasses::dalvik_system_BaseDexClassLoader_sharedLibraryLoaders);
+ DCHECK(shared_libraries_field != nullptr);
+ shared_libraries_field->SetObject<false>(h_class_loader.Get(), shared_libraries.Get());
- ObjPtr<mirror::Object> parent = (parent_loader != nullptr)
- ? soa.Decode<mirror::ClassLoader>(parent_loader)
- : soa.Decode<mirror::Class>(WellKnownClasses::java_lang_BootClassLoader)->AllocObject(self);
- parent_field->SetObject<false>(h_class_loader.Get(), parent);
+ return h_class_loader.Get();
+}
+
+jobject ClassLinker::CreateWellKnownClassLoader(Thread* self,
+ const std::vector<const DexFile*>& dex_files,
+ jclass loader_class,
+ jobject parent_loader) {
+ CHECK(self->GetJniEnv()->IsSameObject(loader_class,
+ WellKnownClasses::dalvik_system_PathClassLoader) ||
+ self->GetJniEnv()->IsSameObject(loader_class,
+ WellKnownClasses::dalvik_system_DelegateLastClassLoader));
+
+ // SOAAlreadyRunnable is protected, and we need something to add a global reference.
+ // We could move the jobject to the callers, but all call-sites do this...
+ ScopedObjectAccessUnchecked soa(self);
+
+ // For now, create a libcore-level DexFile for each ART DexFile. This "explodes" multidex.
+ StackHandleScope<3> hs(self);
+
+ Handle<mirror::Class> h_loader_class =
+ hs.NewHandle<mirror::Class>(soa.Decode<mirror::Class>(loader_class));
+ Handle<mirror::ClassLoader> parent =
+ hs.NewHandle<mirror::ClassLoader>(ObjPtr<mirror::ClassLoader>::DownCast(
+ (parent_loader != nullptr)
+ ? soa.Decode<mirror::ClassLoader>(parent_loader)
+ : nullptr));
+ Handle<mirror::ObjectArray<mirror::ClassLoader>> shared_libraries =
+ hs.NewHandle<mirror::ObjectArray<mirror::ClassLoader>>(nullptr);
+
+ ObjPtr<mirror::ClassLoader> loader = CreateWellKnownClassLoader(
+ self,
+ dex_files,
+ h_loader_class,
+ shared_libraries,
+ parent);
// Make it a global ref and return.
ScopedLocalRef<jobject> local_ref(
- soa.Env(), soa.Env()->AddLocalReference<jobject>(h_class_loader.Get()));
+ soa.Env(), soa.Env()->AddLocalReference<jobject>(loader));
return soa.Env()->NewGlobalRef(local_ref.get());
}
diff --git a/runtime/class_linker.h b/runtime/class_linker.h
index a65299a514..47931fec75 100644
--- a/runtime/class_linker.h
+++ b/runtime/class_linker.h
@@ -586,6 +586,16 @@ class ClassLinker {
REQUIRES_SHARED(Locks::mutator_lock_)
REQUIRES(!Locks::dex_lock_);
+ // Non-GlobalRef version of CreateWellKnownClassLoader
+ ObjPtr<mirror::ClassLoader> CreateWellKnownClassLoader(
+ Thread* self,
+ const std::vector<const DexFile*>& dex_files,
+ Handle<mirror::Class> loader_class,
+ Handle<mirror::ObjectArray<mirror::ClassLoader>> shared_libraries,
+ Handle<mirror::ClassLoader> parent_loader)
+ REQUIRES_SHARED(Locks::mutator_lock_)
+ REQUIRES(!Locks::dex_lock_);
+
PointerSize GetImagePointerSize() const {
return image_pointer_size_;
}
diff --git a/runtime/class_loader_context.cc b/runtime/class_loader_context.cc
index 4eacdad747..5fffa641c7 100644
--- a/runtime/class_loader_context.cc
+++ b/runtime/class_loader_context.cc
@@ -24,11 +24,14 @@
#include "base/stl_util.h"
#include "class_linker.h"
#include "class_loader_utils.h"
+#include "class_root.h"
#include "dex/art_dex_file_loader.h"
#include "dex/dex_file.h"
#include "dex/dex_file_loader.h"
#include "handle_scope-inl.h"
#include "jni/jni_internal.h"
+#include "mirror/object_array-alloc-inl.h"
+#include "nativehelper/scoped_local_ref.h"
#include "oat_file_assistant.h"
#include "obj_ptr-inl.h"
#include "runtime.h"
@@ -107,6 +110,39 @@ std::unique_ptr<ClassLoaderContext> ClassLoaderContext::Create(const std::string
}
}
+static size_t FindMatchingSharedLibraryCloseMarker(const std::string& spec,
+ size_t shared_library_open_index) {
+ // Counter of opened shared library marker we've encountered so far.
+ uint32_t counter = 1;
+ // The index at which we're operating in the loop.
+ uint32_t string_index = shared_library_open_index + 1;
+ size_t shared_library_close = std::string::npos;
+ while (counter != 0) {
+ shared_library_close =
+ spec.find_first_of(kClassLoaderSharedLibraryClosingMark, string_index);
+ size_t shared_library_open =
+ spec.find_first_of(kClassLoaderSharedLibraryOpeningMark, string_index);
+ if (shared_library_close == std::string::npos) {
+ // No matching closing marker. Return an error.
+ break;
+ }
+
+ if ((shared_library_open == std::string::npos) ||
+ (shared_library_close < shared_library_open)) {
+ // We have seen a closing marker. Decrement the counter.
+ --counter;
+ // Move the search index forward.
+ string_index = shared_library_close + 1;
+ } else {
+ // New nested opening marker. Increment the counter and move the search
+ // index after the marker.
+ ++counter;
+ string_index = shared_library_open + 1;
+ }
+ }
+ return shared_library_close;
+}
+
// The expected format is:
// "ClassLoaderType1[ClasspathElem1*Checksum1:ClasspathElem2*Checksum2...]{ClassLoaderType2[...]}".
// The checksum part of the format is expected only if parse_cheksums is true.
@@ -160,7 +196,9 @@ std::unique_ptr<ClassLoaderContext::ClassLoaderInfo> ClassLoaderContext::ParseCl
}
}
- if (class_loader_spec[class_loader_spec.length() - 1] == kClassLoaderSharedLibraryClosingMark) {
+ if ((class_loader_spec[class_loader_spec.length() - 1] == kClassLoaderSharedLibraryClosingMark) &&
+ (class_loader_spec[class_loader_spec.length() - 2] != kClassLoaderSharedLibraryOpeningMark)) {
+ // Non-empty list of shared libraries.
size_t start_index = class_loader_spec.find_first_of(kClassLoaderSharedLibraryOpeningMark);
if (start_index == std::string::npos) {
return nullptr;
@@ -168,8 +206,43 @@ std::unique_ptr<ClassLoaderContext::ClassLoaderInfo> ClassLoaderContext::ParseCl
std::string shared_libraries_spec =
class_loader_spec.substr(start_index + 1, class_loader_spec.length() - start_index - 2);
std::vector<std::string> shared_libraries;
- Split(shared_libraries_spec, kClassLoaderSharedLibrarySeparator, &shared_libraries);
- for (const std::string& shared_library_spec : shared_libraries) {
+ size_t cursor = 0;
+ while (cursor != shared_libraries_spec.length()) {
+ size_t shared_library_separator =
+ shared_libraries_spec.find_first_of(kClassLoaderSharedLibrarySeparator, cursor);
+ size_t shared_library_open =
+ shared_libraries_spec.find_first_of(kClassLoaderSharedLibraryOpeningMark, cursor);
+ std::string shared_library_spec;
+ if (shared_library_separator == std::string::npos) {
+ // Only one shared library, for example:
+ // PCL[...]
+ shared_library_spec =
+ shared_libraries_spec.substr(cursor, shared_libraries_spec.length() - cursor);
+ cursor = shared_libraries_spec.length();
+ } else if ((shared_library_open == std::string::npos) ||
+ (shared_library_open > shared_library_separator)) {
+ // We found a shared library without nested shared libraries, for example:
+ // PCL[...]#PCL[...]{...}
+ shared_library_spec =
+ shared_libraries_spec.substr(cursor, shared_library_separator - cursor);
+ cursor = shared_library_separator + 1;
+ } else {
+ // The shared library contains nested shared libraries. Find the matching closing shared
+ // marker for it.
+ size_t closing_marker =
+ FindMatchingSharedLibraryCloseMarker(shared_libraries_spec, shared_library_open);
+ if (closing_marker == std::string::npos) {
+ // No matching closing marker, return an error.
+ return nullptr;
+ }
+ shared_library_spec = shared_libraries_spec.substr(cursor, closing_marker + 1 - cursor);
+ cursor = closing_marker + 1;
+ if (cursor != shared_libraries_spec.length() &&
+ shared_libraries_spec[cursor] == kClassLoaderSharedLibrarySeparator) {
+ // Pass the shared library separator marker.
+ ++cursor;
+ }
+ }
std::unique_ptr<ClassLoaderInfo> shared_library(
ParseInternal(shared_library_spec, parse_checksums));
if (shared_library == nullptr) {
@@ -250,50 +323,24 @@ ClassLoaderContext::ClassLoaderInfo* ClassLoaderContext::ParseInternal(
// The class loader spec contains shared libraries. Find the matching closing
// shared library marker for it.
- // Counter of opened shared library marker we've encountered so far.
- uint32_t counter = 1;
- // The index at which we're operating in the loop.
- uint32_t string_index = first_shared_library_open + 1;
- while (counter != 0) {
- size_t shared_library_close =
- remaining.find_first_of(kClassLoaderSharedLibraryClosingMark, string_index);
- size_t shared_library_open =
- remaining.find_first_of(kClassLoaderSharedLibraryOpeningMark, string_index);
- if (shared_library_close == std::string::npos) {
- // No matching closing market. Return an error.
- LOG(ERROR) << "Invalid class loader spec: " << class_loader_spec;
- return nullptr;
- }
-
- if ((shared_library_open == std::string::npos) ||
- (shared_library_close < shared_library_open)) {
- // We have seen a closing marker. Decrement the counter.
- --counter;
- if (counter == 0) {
- // Found the matching closing marker.
- class_loader_spec = remaining.substr(0, shared_library_close + 1);
-
- // Compute the remaining string to analyze.
- if (remaining.size() == shared_library_close + 1) {
- remaining = "";
- } else if ((remaining.size() == shared_library_close + 2) ||
- (remaining.at(shared_library_close + 1) != kClassLoaderSeparator)) {
- LOG(ERROR) << "Invalid class loader spec: " << class_loader_spec;
- return nullptr;
- } else {
- remaining = remaining.substr(shared_library_close + 2,
- remaining.size() - shared_library_close - 2);
- }
- } else {
- // Move the search index forward.
- string_index = shared_library_close + 1;
- }
- } else {
- // New nested opening marker. Increment the counter and move the search
- // index after the marker.
- ++counter;
- string_index = shared_library_open + 1;
- }
+ uint32_t shared_library_close =
+ FindMatchingSharedLibraryCloseMarker(remaining, first_shared_library_open);
+ if (shared_library_close == std::string::npos) {
+ LOG(ERROR) << "Invalid class loader spec: " << class_loader_spec;
+ return nullptr;
+ }
+ class_loader_spec = remaining.substr(0, shared_library_close + 1);
+
+ // Compute the remaining string to analyze.
+ if (remaining.size() == shared_library_close + 1) {
+ remaining = "";
+ } else if ((remaining.size() == shared_library_close + 2) ||
+ (remaining.at(shared_library_close + 1) != kClassLoaderSeparator)) {
+ LOG(ERROR) << "Invalid class loader spec: " << class_loader_spec;
+ return nullptr;
+ } else {
+ remaining = remaining.substr(shared_library_close + 2,
+ remaining.size() - shared_library_close - 2);
}
}
@@ -571,20 +618,57 @@ static jclass GetClassLoaderClass(ClassLoaderContext::ClassLoaderType type) {
UNREACHABLE();
}
-static jobject CreateClassLoaderInternal(Thread* self,
- const ClassLoaderContext::ClassLoaderInfo& info)
+static ObjPtr<mirror::ClassLoader> CreateClassLoaderInternal(
+ Thread* self,
+ ScopedObjectAccess& soa,
+ const ClassLoaderContext::ClassLoaderInfo& info,
+ bool add_compilation_sources,
+ const std::vector<const DexFile*>& compilation_sources)
REQUIRES_SHARED(Locks::mutator_lock_) {
- CHECK(info.shared_libraries.empty()) << "Class loader shared library not implemented yet";
- jobject parent = nullptr;
+ StackHandleScope<3> hs(self);
+ MutableHandle<mirror::ObjectArray<mirror::ClassLoader>> libraries(
+ hs.NewHandle<mirror::ObjectArray<mirror::ClassLoader>>(nullptr));
+
+ if (!info.shared_libraries.empty()) {
+ libraries.Assign(mirror::ObjectArray<mirror::ClassLoader>::Alloc(
+ self,
+ GetClassRoot<mirror::ObjectArray<mirror::ClassLoader>>(),
+ info.shared_libraries.size()));
+ for (uint32_t i = 0; i < info.shared_libraries.size(); ++i) {
+ // We should only add the compilation sources to the first class loader.
+ libraries->Set(i,
+ CreateClassLoaderInternal(
+ self,
+ soa,
+ *info.shared_libraries[i].get(),
+ /* add_compilation_sources= */ false,
+ compilation_sources));
+ }
+ }
+
+ MutableHandle<mirror::ClassLoader> parent = hs.NewHandle<mirror::ClassLoader>(nullptr);
if (info.parent != nullptr) {
- parent = CreateClassLoaderInternal(self, *info.parent.get());
+ // We should only add the compilation sources to the first class loader.
+ parent.Assign(CreateClassLoaderInternal(
+ self, soa, *info.parent.get(), /* add_compilation_sources= */ false, compilation_sources));
}
std::vector<const DexFile*> class_path_files = MakeNonOwningPointerVector(
info.opened_dex_files);
+ if (add_compilation_sources) {
+ // For the first class loader, its classpath comes first, followed by compilation sources.
+ // This ensures that whenever we need to resolve classes from it the classpath elements
+ // come first.
+ class_path_files.insert(class_path_files.end(),
+ compilation_sources.begin(),
+ compilation_sources.end());
+ }
+ Handle<mirror::Class> loader_class = hs.NewHandle<mirror::Class>(
+ soa.Decode<mirror::Class>(GetClassLoaderClass(info.type)));
return Runtime::Current()->GetClassLinker()->CreateWellKnownClassLoader(
self,
class_path_files,
- GetClassLoaderClass(info.type),
+ loader_class,
+ libraries,
parent);
}
@@ -598,30 +682,21 @@ jobject ClassLoaderContext::CreateClassLoader(
ClassLinker* const class_linker = Runtime::Current()->GetClassLinker();
if (class_loader_chain_ == nullptr) {
+ CHECK(special_shared_library_);
return class_linker->CreatePathClassLoader(self, compilation_sources);
}
// Create the class loader of the parent.
- jobject parent = nullptr;
- if (class_loader_chain_->parent != nullptr) {
- parent = CreateClassLoaderInternal(self, *class_loader_chain_->parent.get());
- }
-
- // We set up all the parents. Move on to create the first class loader.
- // Its classpath comes first, followed by compilation sources. This ensures that whenever
- // we need to resolve classes from it the classpath elements come first.
-
- std::vector<const DexFile*> first_class_loader_classpath = MakeNonOwningPointerVector(
- class_loader_chain_->opened_dex_files);
- first_class_loader_classpath.insert(first_class_loader_classpath.end(),
- compilation_sources.begin(),
- compilation_sources.end());
-
- return class_linker->CreateWellKnownClassLoader(
- self,
- first_class_loader_classpath,
- GetClassLoaderClass(class_loader_chain_->type),
- parent);
+ ObjPtr<mirror::ClassLoader> loader =
+ CreateClassLoaderInternal(self,
+ soa,
+ *class_loader_chain_.get(),
+ /* add_compilation_sources= */ true,
+ compilation_sources);
+ // Make it a global ref and return.
+ ScopedLocalRef<jobject> local_ref(
+ soa.Env(), soa.Env()->AddLocalReference<jobject>(loader));
+ return soa.Env()->NewGlobalRef(local_ref.get());
}
std::vector<const DexFile*> ClassLoaderContext::FlattenOpenedDexFiles() const {
diff --git a/runtime/class_loader_context_test.cc b/runtime/class_loader_context_test.cc
index f3e2ac00ba..e4aae47239 100644
--- a/runtime/class_loader_context_test.cc
+++ b/runtime/class_loader_context_test.cc
@@ -19,12 +19,14 @@
#include <gtest/gtest.h>
#include "android-base/strings.h"
+#include "art_field-inl.h"
#include "base/dchecked_vector.h"
#include "base/stl_util.h"
#include "class_linker.h"
#include "common_runtime_test.h"
#include "dex/dex_file.h"
#include "handle_scope-inl.h"
+#include "jni/jni_internal.h"
#include "mirror/class.h"
#include "mirror/class_loader.h"
#include "mirror/object-inl.h"
@@ -284,6 +286,25 @@ TEST_F(ClassLoaderContextTest, ParseEnclosingSharedLibraries) {
VerifyClassLoaderSharedLibraryPCL(context.get(), 0, 0, "s1.dex");
}
+TEST_F(ClassLoaderContextTest, ParseComplexSharedLibraries1) {
+ std::unique_ptr<ClassLoaderContext> context = ClassLoaderContext::Create(
+ "PCL[]{PCL[s4.dex]{PCL[s5.dex]{PCL[s6.dex]}#PCL[s6.dex]}}");
+ VerifyContextSize(context.get(), 1);
+ VerifyClassLoaderSharedLibraryPCL(context.get(), 0, 0, "s4.dex");
+}
+
+TEST_F(ClassLoaderContextTest, ParseComplexSharedLibraries2) {
+ std::unique_ptr<ClassLoaderContext> context = ClassLoaderContext::Create(
+ "PCL[]{PCL[s1.dex]{PCL[s2.dex]}#PCL[s2.dex]#"
+ "PCL[s3.dex]#PCL[s4.dex]{PCL[s5.dex]{PCL[s6.dex]}#PCL[s6.dex]}#PCL[s5.dex]{PCL[s6.dex]}}");
+ VerifyContextSize(context.get(), 1);
+ VerifyClassLoaderSharedLibraryPCL(context.get(), 0, 0, "s1.dex");
+ VerifyClassLoaderSharedLibraryPCL(context.get(), 0, 1, "s2.dex");
+ VerifyClassLoaderSharedLibraryPCL(context.get(), 0, 2, "s3.dex");
+ VerifyClassLoaderSharedLibraryPCL(context.get(), 0, 3, "s4.dex");
+ VerifyClassLoaderSharedLibraryPCL(context.get(), 0, 4, "s5.dex");
+}
+
TEST_F(ClassLoaderContextTest, ParseValidEmptyContextDLC) {
std::unique_ptr<ClassLoaderContext> context =
ClassLoaderContext::Create("DLC[]");
@@ -316,6 +337,10 @@ TEST_F(ClassLoaderContextTest, ParseInvalidValidContexts) {
ASSERT_TRUE(nullptr == ClassLoaderContext::Create("DLC[s4.dex]}"));
ASSERT_TRUE(nullptr == ClassLoaderContext::Create("DLC[s4.dex]{"));
ASSERT_TRUE(nullptr == ClassLoaderContext::Create("DLC{DLC[s4.dex]}"));
+ ASSERT_TRUE(nullptr == ClassLoaderContext::Create("PCL{##}"));
+ ASSERT_TRUE(nullptr == ClassLoaderContext::Create("PCL{PCL[s4.dex]#}"));
+ ASSERT_TRUE(nullptr == ClassLoaderContext::Create("PCL{PCL[s4.dex]##}"));
+ ASSERT_TRUE(nullptr == ClassLoaderContext::Create("PCL{PCL[s4.dex]{PCL[s3.dex]}#}"));
}
TEST_F(ClassLoaderContextTest, OpenInvalidDexFiles) {
@@ -605,6 +630,292 @@ TEST_F(ClassLoaderContextTest, CreateClassLoaderWithComplexChain) {
soa.Decode<mirror::Class>(WellKnownClasses::java_lang_BootClassLoader));
}
+TEST_F(ClassLoaderContextTest, CreateClassLoaderWithSharedLibraries) {
+ // Setup the context.
+ std::vector<std::unique_ptr<const DexFile>> classpath_dex_a = OpenTestDexFiles("ForClassLoaderA");
+ std::vector<std::unique_ptr<const DexFile>> classpath_dex_b = OpenTestDexFiles("ForClassLoaderB");
+ std::vector<std::unique_ptr<const DexFile>> classpath_dex_c = OpenTestDexFiles("ForClassLoaderC");
+ std::vector<std::unique_ptr<const DexFile>> classpath_dex_d = OpenTestDexFiles("ForClassLoaderD");
+
+ std::string context_spec =
+ "PCL[" + CreateClassPath(classpath_dex_a) + ":" + CreateClassPath(classpath_dex_b) + "]{" +
+ "DLC[" + CreateClassPath(classpath_dex_c) + "]#" +
+ "PCL[" + CreateClassPath(classpath_dex_d) + "]}";
+
+ std::unique_ptr<ClassLoaderContext> context = ClassLoaderContext::Create(context_spec);
+ ASSERT_TRUE(context->OpenDexFiles(InstructionSet::kArm, ""));
+
+ // Setup the compilation sources.
+ std::vector<std::unique_ptr<const DexFile>> compilation_sources = OpenTestDexFiles("MultiDex");
+ std::vector<const DexFile*> compilation_sources_raw =
+ MakeNonOwningPointerVector(compilation_sources);
+
+ // Create the class loader.
+ jobject jclass_loader = context->CreateClassLoader(compilation_sources_raw);
+ ASSERT_TRUE(jclass_loader != nullptr);
+
+ // Verify the class loader.
+ ScopedObjectAccess soa(Thread::Current());
+
+ StackHandleScope<4> hs(soa.Self());
+ Handle<mirror::ClassLoader> class_loader_1 = hs.NewHandle(
+ soa.Decode<mirror::ClassLoader>(jclass_loader));
+
+ // For the first class loader the class path dex files must come first and then the
+ // compilation sources.
+ std::vector<const DexFile*> class_loader_1_dex_files =
+ MakeNonOwningPointerVector(classpath_dex_a);
+ for (auto& dex : classpath_dex_b) {
+ class_loader_1_dex_files.push_back(dex.get());
+ }
+ for (auto& dex : compilation_sources_raw) {
+ class_loader_1_dex_files.push_back(dex);
+ }
+ VerifyClassLoaderDexFiles(soa,
+ class_loader_1,
+ WellKnownClasses::dalvik_system_PathClassLoader,
+ class_loader_1_dex_files);
+
+ // Verify the shared libraries.
+ ArtField* field =
+ jni::DecodeArtField(WellKnownClasses::dalvik_system_BaseDexClassLoader_sharedLibraryLoaders);
+ ObjPtr<mirror::Object> raw_shared_libraries = field->GetObject(class_loader_1.Get());
+ ASSERT_TRUE(raw_shared_libraries != nullptr);
+
+ Handle<mirror::ObjectArray<mirror::ClassLoader>> shared_libraries(
+ hs.NewHandle(raw_shared_libraries->AsObjectArray<mirror::ClassLoader>()));
+ ASSERT_EQ(shared_libraries->GetLength(), 2);
+
+ // Verify the first shared library.
+ Handle<mirror::ClassLoader> class_loader_2 = hs.NewHandle(shared_libraries->Get(0));
+ std::vector<const DexFile*> class_loader_2_dex_files =
+ MakeNonOwningPointerVector(classpath_dex_c);
+ VerifyClassLoaderDexFiles(soa,
+ class_loader_2,
+ WellKnownClasses::dalvik_system_DelegateLastClassLoader,
+ class_loader_2_dex_files);
+ raw_shared_libraries = field->GetObject(class_loader_2.Get());
+ ASSERT_TRUE(raw_shared_libraries == nullptr);
+
+ // Verify the second shared library.
+ Handle<mirror::ClassLoader> class_loader_3 = hs.NewHandle(shared_libraries->Get(1));
+ std::vector<const DexFile*> class_loader_3_dex_files =
+ MakeNonOwningPointerVector(classpath_dex_d);
+ VerifyClassLoaderDexFiles(soa,
+ class_loader_3,
+ WellKnownClasses::dalvik_system_PathClassLoader,
+ class_loader_3_dex_files);
+ raw_shared_libraries = field->GetObject(class_loader_3.Get());
+ ASSERT_TRUE(raw_shared_libraries == nullptr);
+
+ // All class loaders should have the BootClassLoader as a parent.
+ ASSERT_TRUE(class_loader_1->GetParent()->GetClass() ==
+ soa.Decode<mirror::Class>(WellKnownClasses::java_lang_BootClassLoader));
+ ASSERT_TRUE(class_loader_2->GetParent()->GetClass() ==
+ soa.Decode<mirror::Class>(WellKnownClasses::java_lang_BootClassLoader));
+ ASSERT_TRUE(class_loader_3->GetParent()->GetClass() ==
+ soa.Decode<mirror::Class>(WellKnownClasses::java_lang_BootClassLoader));
+}
+
+TEST_F(ClassLoaderContextTest, CreateClassLoaderWithSharedLibrariesInParentToo) {
+ // Setup the context.
+ std::vector<std::unique_ptr<const DexFile>> classpath_dex_a = OpenTestDexFiles("ForClassLoaderA");
+ std::vector<std::unique_ptr<const DexFile>> classpath_dex_b = OpenTestDexFiles("ForClassLoaderB");
+ std::vector<std::unique_ptr<const DexFile>> classpath_dex_c = OpenTestDexFiles("ForClassLoaderC");
+ std::vector<std::unique_ptr<const DexFile>> classpath_dex_d = OpenTestDexFiles("ForClassLoaderD");
+
+ std::string context_spec =
+ "PCL[" + CreateClassPath(classpath_dex_a) + "]{" +
+ "PCL[" + CreateClassPath(classpath_dex_b) + "]};" +
+ "PCL[" + CreateClassPath(classpath_dex_c) + "]{" +
+ "PCL[" + CreateClassPath(classpath_dex_d) + "]}";
+
+ std::unique_ptr<ClassLoaderContext> context = ClassLoaderContext::Create(context_spec);
+ ASSERT_TRUE(context->OpenDexFiles(InstructionSet::kArm, ""));
+
+ // Setup the compilation sources.
+ std::vector<std::unique_ptr<const DexFile>> compilation_sources = OpenTestDexFiles("MultiDex");
+ std::vector<const DexFile*> compilation_sources_raw =
+ MakeNonOwningPointerVector(compilation_sources);
+
+ // Create the class loader.
+ jobject jclass_loader = context->CreateClassLoader(compilation_sources_raw);
+ ASSERT_TRUE(jclass_loader != nullptr);
+
+ // Verify the class loader.
+ ScopedObjectAccess soa(Thread::Current());
+
+ StackHandleScope<6> hs(soa.Self());
+ Handle<mirror::ClassLoader> class_loader_1 = hs.NewHandle(
+ soa.Decode<mirror::ClassLoader>(jclass_loader));
+
+ // For the first class loader the class path dex files must come first and then the
+ // compilation sources.
+ std::vector<const DexFile*> class_loader_1_dex_files =
+ MakeNonOwningPointerVector(classpath_dex_a);
+ for (auto& dex : compilation_sources_raw) {
+ class_loader_1_dex_files.push_back(dex);
+ }
+ VerifyClassLoaderDexFiles(soa,
+ class_loader_1,
+ WellKnownClasses::dalvik_system_PathClassLoader,
+ class_loader_1_dex_files);
+
+ // Verify its shared library.
+ ArtField* field =
+ jni::DecodeArtField(WellKnownClasses::dalvik_system_BaseDexClassLoader_sharedLibraryLoaders);
+ ObjPtr<mirror::Object> raw_shared_libraries = field->GetObject(class_loader_1.Get());
+ ASSERT_TRUE(raw_shared_libraries != nullptr);
+
+ Handle<mirror::ObjectArray<mirror::ClassLoader>> shared_libraries(
+ hs.NewHandle(raw_shared_libraries->AsObjectArray<mirror::ClassLoader>()));
+ ASSERT_EQ(shared_libraries->GetLength(), 1);
+
+ Handle<mirror::ClassLoader> class_loader_2 = hs.NewHandle(shared_libraries->Get(0));
+ std::vector<const DexFile*> class_loader_2_dex_files =
+ MakeNonOwningPointerVector(classpath_dex_b);
+ VerifyClassLoaderDexFiles(soa,
+ class_loader_2,
+ WellKnownClasses::dalvik_system_PathClassLoader,
+ class_loader_2_dex_files);
+ raw_shared_libraries = field->GetObject(class_loader_2.Get());
+ ASSERT_TRUE(raw_shared_libraries == nullptr);
+
+ // Verify the parent.
+ Handle<mirror::ClassLoader> class_loader_3 = hs.NewHandle(class_loader_1->GetParent());
+ std::vector<const DexFile*> class_loader_3_dex_files =
+ MakeNonOwningPointerVector(classpath_dex_c);
+ VerifyClassLoaderDexFiles(soa,
+ class_loader_3,
+ WellKnownClasses::dalvik_system_PathClassLoader,
+ class_loader_3_dex_files);
+
+ // Verify its shared library.
+ raw_shared_libraries = field->GetObject(class_loader_3.Get());
+ ASSERT_TRUE(raw_shared_libraries != nullptr);
+
+ Handle<mirror::ObjectArray<mirror::ClassLoader>> shared_libraries_2(
+ hs.NewHandle(raw_shared_libraries->AsObjectArray<mirror::ClassLoader>()));
+ ASSERT_EQ(shared_libraries->GetLength(), 1);
+
+ Handle<mirror::ClassLoader> class_loader_4 = hs.NewHandle(shared_libraries_2->Get(0));
+ std::vector<const DexFile*> class_loader_4_dex_files =
+ MakeNonOwningPointerVector(classpath_dex_d);
+ VerifyClassLoaderDexFiles(soa,
+ class_loader_4,
+ WellKnownClasses::dalvik_system_PathClassLoader,
+ class_loader_4_dex_files);
+ raw_shared_libraries = field->GetObject(class_loader_4.Get());
+ ASSERT_TRUE(raw_shared_libraries == nullptr);
+
+ // Class loaders should have the BootClassLoader as a parent.
+ ASSERT_TRUE(class_loader_2->GetParent()->GetClass() ==
+ soa.Decode<mirror::Class>(WellKnownClasses::java_lang_BootClassLoader));
+ ASSERT_TRUE(class_loader_3->GetParent()->GetClass() ==
+ soa.Decode<mirror::Class>(WellKnownClasses::java_lang_BootClassLoader));
+ ASSERT_TRUE(class_loader_4->GetParent()->GetClass() ==
+ soa.Decode<mirror::Class>(WellKnownClasses::java_lang_BootClassLoader));
+}
+
+TEST_F(ClassLoaderContextTest, CreateClassLoaderWithSharedLibrariesDependencies) {
+ // Setup the context.
+ std::vector<std::unique_ptr<const DexFile>> classpath_dex_a = OpenTestDexFiles("ForClassLoaderA");
+ std::vector<std::unique_ptr<const DexFile>> classpath_dex_b = OpenTestDexFiles("ForClassLoaderB");
+ std::vector<std::unique_ptr<const DexFile>> classpath_dex_c = OpenTestDexFiles("ForClassLoaderC");
+ std::vector<std::unique_ptr<const DexFile>> classpath_dex_d = OpenTestDexFiles("ForClassLoaderD");
+
+ std::string context_spec =
+ "PCL[" + CreateClassPath(classpath_dex_a) + "]{" +
+ "PCL[" + CreateClassPath(classpath_dex_b) + "]{" +
+ "PCL[" + CreateClassPath(classpath_dex_c) + "]}};" +
+ "PCL[" + CreateClassPath(classpath_dex_d) + "]";
+
+ std::unique_ptr<ClassLoaderContext> context = ClassLoaderContext::Create(context_spec);
+ ASSERT_TRUE(context->OpenDexFiles(InstructionSet::kArm, ""));
+
+ // Setup the compilation sources.
+ std::vector<std::unique_ptr<const DexFile>> compilation_sources = OpenTestDexFiles("MultiDex");
+ std::vector<const DexFile*> compilation_sources_raw =
+ MakeNonOwningPointerVector(compilation_sources);
+
+ // Create the class loader.
+ jobject jclass_loader = context->CreateClassLoader(compilation_sources_raw);
+ ASSERT_TRUE(jclass_loader != nullptr);
+
+ // Verify the class loader.
+ ScopedObjectAccess soa(Thread::Current());
+
+ StackHandleScope<6> hs(soa.Self());
+ Handle<mirror::ClassLoader> class_loader_1 = hs.NewHandle(
+ soa.Decode<mirror::ClassLoader>(jclass_loader));
+
+ // For the first class loader the class path dex files must come first and then the
+ // compilation sources.
+ std::vector<const DexFile*> class_loader_1_dex_files =
+ MakeNonOwningPointerVector(classpath_dex_a);
+ for (auto& dex : compilation_sources_raw) {
+ class_loader_1_dex_files.push_back(dex);
+ }
+ VerifyClassLoaderDexFiles(soa,
+ class_loader_1,
+ WellKnownClasses::dalvik_system_PathClassLoader,
+ class_loader_1_dex_files);
+
+ // Verify its shared library.
+ ArtField* field =
+ jni::DecodeArtField(WellKnownClasses::dalvik_system_BaseDexClassLoader_sharedLibraryLoaders);
+ ObjPtr<mirror::Object> raw_shared_libraries = field->GetObject(class_loader_1.Get());
+ ASSERT_TRUE(raw_shared_libraries != nullptr);
+
+ Handle<mirror::ObjectArray<mirror::ClassLoader>> shared_libraries(
+ hs.NewHandle(raw_shared_libraries->AsObjectArray<mirror::ClassLoader>()));
+ ASSERT_EQ(shared_libraries->GetLength(), 1);
+
+ Handle<mirror::ClassLoader> class_loader_2 = hs.NewHandle(shared_libraries->Get(0));
+ std::vector<const DexFile*> class_loader_2_dex_files =
+ MakeNonOwningPointerVector(classpath_dex_b);
+ VerifyClassLoaderDexFiles(soa,
+ class_loader_2,
+ WellKnownClasses::dalvik_system_PathClassLoader,
+ class_loader_2_dex_files);
+
+ // Verify the shared library dependency of the shared library.
+ raw_shared_libraries = field->GetObject(class_loader_2.Get());
+ ASSERT_TRUE(raw_shared_libraries != nullptr);
+
+ Handle<mirror::ObjectArray<mirror::ClassLoader>> shared_libraries_2(
+ hs.NewHandle(raw_shared_libraries->AsObjectArray<mirror::ClassLoader>()));
+ ASSERT_EQ(shared_libraries_2->GetLength(), 1);
+
+ Handle<mirror::ClassLoader> class_loader_3 = hs.NewHandle(shared_libraries_2->Get(0));
+ std::vector<const DexFile*> class_loader_3_dex_files =
+ MakeNonOwningPointerVector(classpath_dex_c);
+ VerifyClassLoaderDexFiles(soa,
+ class_loader_3,
+ WellKnownClasses::dalvik_system_PathClassLoader,
+ class_loader_3_dex_files);
+ raw_shared_libraries = field->GetObject(class_loader_3.Get());
+ ASSERT_TRUE(raw_shared_libraries == nullptr);
+
+ // Verify the parent.
+ Handle<mirror::ClassLoader> class_loader_4 = hs.NewHandle(class_loader_1->GetParent());
+ std::vector<const DexFile*> class_loader_4_dex_files =
+ MakeNonOwningPointerVector(classpath_dex_d);
+ VerifyClassLoaderDexFiles(soa,
+ class_loader_4,
+ WellKnownClasses::dalvik_system_PathClassLoader,
+ class_loader_4_dex_files);
+ raw_shared_libraries = field->GetObject(class_loader_4.Get());
+ ASSERT_TRUE(raw_shared_libraries == nullptr);
+
+ // Class loaders should have the BootClassLoader as a parent.
+ ASSERT_TRUE(class_loader_2->GetParent()->GetClass() ==
+ soa.Decode<mirror::Class>(WellKnownClasses::java_lang_BootClassLoader));
+ ASSERT_TRUE(class_loader_3->GetParent()->GetClass() ==
+ soa.Decode<mirror::Class>(WellKnownClasses::java_lang_BootClassLoader));
+ ASSERT_TRUE(class_loader_4->GetParent()->GetClass() ==
+ soa.Decode<mirror::Class>(WellKnownClasses::java_lang_BootClassLoader));
+}
TEST_F(ClassLoaderContextTest, RemoveSourceLocations) {
std::unique_ptr<ClassLoaderContext> context =
diff --git a/runtime/class_root.h b/runtime/class_root.h
index 1cd135f2aa..1ff48457d6 100644
--- a/runtime/class_root.h
+++ b/runtime/class_root.h
@@ -101,6 +101,7 @@ class VarHandle;
M(kLongArrayClass, "[J", mirror::PrimitiveArray<int64_t>) \
M(kShortArrayClass, "[S", mirror::PrimitiveArray<int16_t>) \
M(kJavaLangStackTraceElementArrayClass, "[Ljava/lang/StackTraceElement;", mirror::ObjectArray<mirror::StackTraceElement>) \
+ M(kJavaLangClassLoaderArrayClass, "[Ljava/lang/ClassLoader;", mirror::ObjectArray<mirror::ClassLoader>) \
M(kDalvikSystemClassExt, "Ldalvik/system/ClassExt;", mirror::ClassExt)
// Well known mirror::Class roots accessed via ClassLinker::GetClassRoots().
diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc
index e7f14c39d4..4359bea421 100644
--- a/runtime/gc/heap.cc
+++ b/runtime/gc/heap.cc
@@ -1064,7 +1064,7 @@ void Heap::RemoveSpace(space::Space* space) {
uint64_t Heap::GetTotalGcCpuTime() {
uint64_t sum = 0;
- for (auto& collector : garbage_collectors_) {
+ for (auto* collector : garbage_collectors_) {
sum += collector->GetTotalCpuTime();
}
return sum;
@@ -1076,7 +1076,7 @@ void Heap::DumpGcPerformanceInfo(std::ostream& os) {
uint64_t total_duration = 0;
// Dump cumulative loggers for each GC type.
uint64_t total_paused_time = 0;
- for (auto& collector : garbage_collectors_) {
+ for (auto* collector : garbage_collectors_) {
total_duration += collector->GetCumulativeTimings().GetTotalNs();
total_paused_time += collector->GetTotalPausedTimeNs();
collector->DumpPerformanceInfo(os);
@@ -1136,7 +1136,7 @@ void Heap::DumpGcPerformanceInfo(std::ostream& os) {
}
void Heap::ResetGcPerformanceInfo() {
- for (auto& collector : garbage_collectors_) {
+ for (auto* collector : garbage_collectors_) {
collector->ResetMeasurements();
}
total_bytes_freed_ever_ = 0;
@@ -1157,7 +1157,7 @@ void Heap::ResetGcPerformanceInfo() {
uint64_t Heap::GetGcCount() const {
uint64_t gc_count = 0U;
- for (auto& collector : garbage_collectors_) {
+ for (auto* collector : garbage_collectors_) {
gc_count += collector->GetCumulativeTimings().GetIterations();
}
return gc_count;
@@ -1165,7 +1165,7 @@ uint64_t Heap::GetGcCount() const {
uint64_t Heap::GetGcTime() const {
uint64_t gc_time = 0U;
- for (auto& collector : garbage_collectors_) {
+ for (auto* collector : garbage_collectors_) {
gc_time += collector->GetCumulativeTimings().GetTotalNs();
}
return gc_time;
@@ -3505,7 +3505,7 @@ bool Heap::IsMovableObject(ObjPtr<mirror::Object> obj) const {
}
collector::GarbageCollector* Heap::FindCollectorByGcType(collector::GcType gc_type) {
- for (const auto& collector : garbage_collectors_) {
+ for (auto* collector : garbage_collectors_) {
if (collector->GetCollectorType() == collector_type_ &&
collector->GetGcType() == gc_type) {
return collector;
diff --git a/test/411-checker-hdiv-hrem-pow2/src/DivTest.java b/test/411-checker-hdiv-hrem-pow2/src/DivTest.java
index a3882e7c15..1a086ef04d 100644
--- a/test/411-checker-hdiv-hrem-pow2/src/DivTest.java
+++ b/test/411-checker-hdiv-hrem-pow2/src/DivTest.java
@@ -94,6 +94,9 @@ public class DivTest {
/// CHECK-START-ARM64: java.lang.Integer DivTest.$noinline$IntDivBy2(int) disassembly (after)
/// CHECK: add w{{\d+}}, w{{\d+}}, w{{\d+}}, lsr #31
/// CHECK: asr w{{\d+}}, w{{\d+}}, #1
+ /// CHECK-START-X86_64: java.lang.Integer DivTest.$noinline$IntDivBy2(int) disassembly (after)
+ /// CHECK-NOT: cmovnl/geq
+ /// CHECK: add
private static Integer $noinline$IntDivBy2(int v) {
int r = v / 2;
return r;
@@ -102,6 +105,9 @@ public class DivTest {
/// CHECK-START-ARM64: java.lang.Integer DivTest.$noinline$IntDivByMinus2(int) disassembly (after)
/// CHECK: add w{{\d+}}, w{{\d+}}, w{{\d+}}, lsr #31
/// CHECK: neg w{{\d+}}, w{{\d+}}, asr #1
+ /// CHECK-START-X86_64: java.lang.Integer DivTest.$noinline$IntDivByMinus2(int) disassembly (after)
+ /// CHECK-NOT: cmovnl/geq
+ /// CHECK: add
private static Integer $noinline$IntDivByMinus2(int v) {
int r = v / -2;
return r;
@@ -205,6 +211,9 @@ public class DivTest {
/// CHECK-START-ARM64: java.lang.Long DivTest.$noinline$LongDivBy2(long) disassembly (after)
/// CHECK: add x{{\d+}}, x{{\d+}}, x{{\d+}}, lsr #63
/// CHECK: asr x{{\d+}}, x{{\d+}}, #1
+ /// CHECK-START-X86_64: java.lang.Long DivTest.$noinline$LongDivBy2(long) disassembly (after)
+ /// CHECK-NOT: cmovnl/geq
+ /// CHECK: addq
private static Long $noinline$LongDivBy2(long v) {
long r = v / 2;
return r;
@@ -213,6 +222,9 @@ public class DivTest {
/// CHECK-START-ARM64: java.lang.Long DivTest.$noinline$LongDivByMinus2(long) disassembly (after)
/// CHECK: add x{{\d+}}, x{{\d+}}, x{{\d+}}, lsr #63
/// CHECK: neg x{{\d+}}, x{{\d+}}, asr #1
+ /// CHECK-START-X86_64: java.lang.Long DivTest.$noinline$LongDivByMinus2(long) disassembly (after)
+ /// CHECK-NOT: cmovnl/geq
+ /// CHECK: addq
private static Long $noinline$LongDivByMinus2(long v) {
long r = v / -2;
return r;