Introduce BaseDexClassLoader.computeClassLoaderContextsNative
This will be used to compute the contexts that should be sent over to
the dex load reporter. See associated changes in libcore &
frameworks/base.
Motivation: At the moment of committing there are two classloader
context encoders- one in ART and one in the package manager. The
duplicate logic is susceptible to divergences. For example at the moment
if a package uses shared libraries and has secondary dex files then the
context encoded for secondary dex files will be incorrect[1]. In order to
eliminate this bug and future possible bugs lets centralize where all
classloader context computation is done.
[1]: The context will be incorrect because it doesn't take into account
the shared libraries that are loaded at runtime.
Test: m test-art-host-gtest-class_loader_context_test
Test: m test-art-host-gtest
Test: ./test/testrunner/testrunner.py --host -b
Test: Introduced a set of tests for the new API(s)
Test: See tests in associated libcore & framework/base commits
Bug: 148494302
Change-Id: Id39293a2e1d3d05194f2864f4febb3e652bce075
diff --git a/runtime/common_runtime_test.cc b/runtime/common_runtime_test.cc
index 64d2503..40f35b3 100644
--- a/runtime/common_runtime_test.cc
+++ b/runtime/common_runtime_test.cc
@@ -272,16 +272,19 @@
return class_loader;
}
-jobject CommonRuntimeTestImpl::LoadDexInWellKnownClassLoader(const std::string& dex_name,
- jclass loader_class,
- jobject parent_loader,
- jobject shared_libraries) {
- std::vector<std::unique_ptr<const DexFile>> dex_files = OpenTestDexFiles(dex_name.c_str());
+jobject
+CommonRuntimeTestImpl::LoadDexInWellKnownClassLoader(const std::vector<std::string>& dex_names,
+ jclass loader_class,
+ jobject parent_loader,
+ jobject shared_libraries) {
std::vector<const DexFile*> class_path;
- CHECK_NE(0U, dex_files.size());
- for (auto& dex_file : dex_files) {
- class_path.push_back(dex_file.get());
- loaded_dex_files_.push_back(std::move(dex_file));
+ for (const std::string& dex_name : dex_names) {
+ std::vector<std::unique_ptr<const DexFile>> dex_files = OpenTestDexFiles(dex_name.c_str());
+ CHECK_NE(0U, dex_files.size());
+ for (auto& dex_file : dex_files) {
+ class_path.push_back(dex_file.get());
+ loaded_dex_files_.push_back(std::move(dex_file));
+ }
}
Thread* self = Thread::Current();
ScopedObjectAccess soa(self);
@@ -320,7 +323,15 @@
jobject CommonRuntimeTestImpl::LoadDexInPathClassLoader(const std::string& dex_name,
jobject parent_loader,
jobject shared_libraries) {
- return LoadDexInWellKnownClassLoader(dex_name,
+ return LoadDexInPathClassLoader(std::vector<std::string>{ dex_name },
+ parent_loader,
+ shared_libraries);
+}
+
+jobject CommonRuntimeTestImpl::LoadDexInPathClassLoader(const std::vector<std::string>& names,
+ jobject parent_loader,
+ jobject shared_libraries) {
+ return LoadDexInWellKnownClassLoader(names,
WellKnownClasses::dalvik_system_PathClassLoader,
parent_loader,
shared_libraries);
@@ -328,14 +339,14 @@
jobject CommonRuntimeTestImpl::LoadDexInDelegateLastClassLoader(const std::string& dex_name,
jobject parent_loader) {
- return LoadDexInWellKnownClassLoader(dex_name,
+ return LoadDexInWellKnownClassLoader({ dex_name },
WellKnownClasses::dalvik_system_DelegateLastClassLoader,
parent_loader);
}
jobject CommonRuntimeTestImpl::LoadDexInInMemoryDexClassLoader(const std::string& dex_name,
jobject parent_loader) {
- return LoadDexInWellKnownClassLoader(dex_name,
+ return LoadDexInWellKnownClassLoader({ dex_name },
WellKnownClasses::dalvik_system_InMemoryDexClassLoader,
parent_loader);
}