summaryrefslogtreecommitdiff
path: root/runtime/class_loader_context.cc
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/class_loader_context.cc')
-rw-r--r--runtime/class_loader_context.cc289
1 files changed, 134 insertions, 155 deletions
diff --git a/runtime/class_loader_context.cc b/runtime/class_loader_context.cc
index 074a819d0a..2f34f04f5b 100644
--- a/runtime/class_loader_context.cc
+++ b/runtime/class_loader_context.cc
@@ -63,8 +63,7 @@ static constexpr char kDexFileChecksumSeparator = '*';
static constexpr char kInMemoryDexClassLoaderDexLocationMagic[] = "<unknown>";
ClassLoaderContext::ClassLoaderContext()
- : dex_files_state_(ContextDexFilesState::kDexFilesNotOpened),
- owns_the_dex_files_(true) {}
+ : dex_files_state_(ContextDexFilesState::kDexFilesNotOpened), owns_the_dex_files_(true) {}
ClassLoaderContext::ClassLoaderContext(bool owns_the_dex_files)
: dex_files_state_(ContextDexFilesState::kDexFilesOpened),
@@ -72,9 +71,8 @@ ClassLoaderContext::ClassLoaderContext(bool owns_the_dex_files)
// Utility method to add parent and shared libraries of `info` into
// the `work_list`.
-static void AddToWorkList(
- ClassLoaderContext::ClassLoaderInfo* info,
- std::vector<ClassLoaderContext::ClassLoaderInfo*>& work_list) {
+static void AddToWorkList(ClassLoaderContext::ClassLoaderInfo* info,
+ std::vector<ClassLoaderContext::ClassLoaderInfo*>& work_list) {
if (info->parent != nullptr) {
work_list.push_back(info->parent.get());
}
@@ -106,9 +104,7 @@ ClassLoaderContext::~ClassLoaderContext() {
}
}
-std::unique_ptr<ClassLoaderContext> ClassLoaderContext::Default() {
- return Create("");
-}
+std::unique_ptr<ClassLoaderContext> ClassLoaderContext::Default() { return Create(""); }
std::unique_ptr<ClassLoaderContext> ClassLoaderContext::Create(const std::string& spec) {
std::unique_ptr<ClassLoaderContext> result(new ClassLoaderContext());
@@ -127,8 +123,7 @@ static size_t FindMatchingSharedLibraryCloseMarker(const std::string& spec,
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);
+ 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) {
@@ -156,8 +151,7 @@ static size_t FindMatchingSharedLibraryCloseMarker(const std::string& spec,
// "ClassLoaderType1[ClasspathElem1*Checksum1:ClasspathElem2*Checksum2...]{ClassLoaderType2[...]}".
// The checksum part of the format is expected only if parse_cheksums is true.
std::unique_ptr<ClassLoaderContext::ClassLoaderInfo> ClassLoaderContext::ParseClassLoaderSpec(
- const std::string& class_loader_spec,
- bool parse_checksums) {
+ const std::string& class_loader_spec, bool parse_checksums) {
ClassLoaderType class_loader_type = ExtractClassLoaderType(class_loader_spec);
if (class_loader_type == kInvalidClassLoader) {
return nullptr;
@@ -200,8 +194,8 @@ std::unique_ptr<ClassLoaderContext::ClassLoaderInfo> ClassLoaderContext::ParseCl
// At this point we know the format is ok; continue and extract the classpath.
// Note that class loaders with an empty class path are allowed.
- std::string classpath = class_loader_spec.substr(type_str_size + 1,
- closing_index - type_str_size - 1);
+ std::string classpath =
+ class_loader_spec.substr(type_str_size + 1, closing_index - type_str_size - 1);
std::unique_ptr<ClassLoaderInfo> info(new ClassLoaderInfo(class_loader_type));
@@ -299,7 +293,7 @@ std::unique_ptr<ClassLoaderContext::ClassLoaderInfo> ClassLoaderContext::ParseCl
}
std::unique_ptr<ClassLoaderInfo> shared_library_info(
- ParseInternal(shared_library_spec, parse_checksums));
+ ParseInternal(shared_library_spec, parse_checksums));
if (shared_library_info == nullptr) {
return nullptr;
}
@@ -317,11 +311,10 @@ std::unique_ptr<ClassLoaderContext::ClassLoaderInfo> ClassLoaderContext::ParseCl
// Extracts the class loader type from the given spec.
// Return ClassLoaderContext::kInvalidClassLoader if the class loader type is not
// recognized.
-ClassLoaderContext::ClassLoaderType
-ClassLoaderContext::ExtractClassLoaderType(const std::string& class_loader_spec) {
- const ClassLoaderType kValidTypes[] = { kPathClassLoader,
- kDelegateLastClassLoader,
- kInMemoryDexClassLoader };
+ClassLoaderContext::ClassLoaderType ClassLoaderContext::ExtractClassLoaderType(
+ const std::string& class_loader_spec) {
+ const ClassLoaderType kValidTypes[] = {
+ kPathClassLoader, kDelegateLastClassLoader, kInMemoryDexClassLoader};
for (const ClassLoaderType& type : kValidTypes) {
const char* type_str = GetClassLoaderTypeName(type);
if (class_loader_spec.compare(0, strlen(type_str), type_str) == 0) {
@@ -348,8 +341,8 @@ bool ClassLoaderContext::Parse(const std::string& spec, bool parse_checksums) {
return class_loader_chain_ != nullptr;
}
-ClassLoaderContext::ClassLoaderInfo* ClassLoaderContext::ParseInternal(
- const std::string& spec, bool parse_checksums) {
+ClassLoaderContext::ClassLoaderInfo* ClassLoaderContext::ParseInternal(const std::string& spec,
+ bool parse_checksums) {
CHECK(!spec.empty());
std::string remaining = spec;
std::unique_ptr<ClassLoaderInfo> first(nullptr);
@@ -391,8 +384,8 @@ ClassLoaderContext::ClassLoaderInfo* ClassLoaderContext::ParseInternal(
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);
+ remaining =
+ remaining.substr(shared_library_close + 2, remaining.size() - shared_library_close - 2);
}
}
@@ -420,9 +413,12 @@ bool ClassLoaderContext::OpenDexFiles(const std::string& classpath_dir,
const std::vector<int>& fds,
bool only_read_checksums) {
switch (dex_files_state_) {
- case kDexFilesNotOpened: break; // files not opened, continue.
- case kDexFilesOpenFailed: return false; // previous attempt failed.
- case kDexFilesOpened: return true; // previous attempt succeed.
+ case kDexFilesNotOpened:
+ break; // files not opened, continue.
+ case kDexFilesOpenFailed:
+ return false; // previous attempt failed.
+ case kDexFilesOpened:
+ return true; // previous attempt succeed.
case kDexFilesChecksumsRead:
if (only_read_checksums) {
return true; // we already read the checksums.
@@ -531,7 +527,7 @@ bool ClassLoaderContext::OpenDexFiles(const std::string& classpath_dir,
// as we have encountered while iterating over this class loader context.
if (dex_file_index != fds.size()) {
LOG(WARNING) << fds.size() << " FDs provided but only " << dex_file_index
- << " dex files are in the class loader context";
+ << " dex files are in the class loader context";
dex_files_state_ = kDexFilesOpenFailed;
}
@@ -558,13 +554,13 @@ bool ClassLoaderContext::RemoveLocationsFromClassPaths(
ClassLoaderInfo* info = work_list.back();
work_list.pop_back();
size_t initial_size = info->classpath.size();
- auto kept_it = std::remove_if(
- info->classpath.begin(),
- info->classpath.end(),
- [canonical_locations](const std::string& location) {
- return ContainsElement(canonical_locations,
- DexFileLoader::GetDexCanonicalLocation(location.c_str()));
- });
+ auto kept_it = std::remove_if(info->classpath.begin(),
+ info->classpath.end(),
+ [canonical_locations](const std::string& location) {
+ return ContainsElement(
+ canonical_locations,
+ DexFileLoader::GetDexCanonicalLocation(location.c_str()));
+ });
info->classpath.erase(kept_it, info->classpath.end());
if (initial_size != info->classpath.size()) {
removed_locations = true;
@@ -575,16 +571,16 @@ bool ClassLoaderContext::RemoveLocationsFromClassPaths(
}
std::string ClassLoaderContext::EncodeContextForDex2oat(const std::string& base_dir) const {
- return EncodeContext(base_dir, /*for_dex2oat=*/ true, /*stored_context=*/ nullptr);
+ return EncodeContext(base_dir, /*for_dex2oat=*/true, /*stored_context=*/nullptr);
}
std::string ClassLoaderContext::EncodeContextForOatFile(const std::string& base_dir,
ClassLoaderContext* stored_context) const {
- return EncodeContext(base_dir, /*for_dex2oat=*/ false, stored_context);
+ return EncodeContext(base_dir, /*for_dex2oat=*/false, stored_context);
}
-std::map<std::string, std::string>
-ClassLoaderContext::EncodeClassPathContexts(const std::string& base_dir) const {
+std::map<std::string, std::string> ClassLoaderContext::EncodeClassPathContexts(
+ const std::string& base_dir) const {
CheckDexFilesOpened("EncodeClassPathContexts");
if (class_loader_chain_ == nullptr) {
return std::map<std::string, std::string>{};
@@ -636,8 +632,7 @@ std::string ClassLoaderContext::EncodeContext(const std::string& base_dir,
if (class_loader_chain_ == nullptr) {
// We can get in this situation if the context was created with a class path containing the
// source dex files which were later removed (happens during run-tests).
- out << GetClassLoaderTypeName(kPathClassLoader)
- << kClassLoaderOpeningMark
+ out << GetClassLoaderTypeName(kPathClassLoader) << kClassLoaderOpeningMark
<< kClassLoaderClosingMark;
return out.str();
}
@@ -667,8 +662,7 @@ void ClassLoaderContext::EncodeClassPath(const std::string& base_dir,
}
if (type == kInMemoryDexClassLoader) {
out << kInMemoryDexClassLoaderDexLocationMagic;
- } else if (!base_dir.empty()
- && location.substr(0, base_dir.length()) == base_dir) {
+ } else if (!base_dir.empty() && location.substr(0, base_dir.length()) == base_dir) {
// Find paths that were relative and convert them back from absolute.
out << location.substr(base_dir.length() + 1).c_str();
} else {
@@ -703,8 +697,8 @@ void ClassLoaderContext::EncodeContextInternal(const ClassLoaderInfo& info,
if (for_dex2oat) {
// dex2oat only needs the base location. It cannot accept multidex locations.
// So ensure we only add each file once.
- bool new_insert = seen_locations.insert(
- DexFileLoader::GetBaseLocation(dex_file->GetLocation())).second;
+ bool new_insert =
+ seen_locations.insert(DexFileLoader::GetBaseLocation(dex_file->GetLocation())).second;
if (!new_insert) {
continue;
}
@@ -765,12 +759,11 @@ void ClassLoaderContext::EncodeSharedLibAndParent(const ClassLoaderInfo& info,
}
if (info.parent != nullptr) {
out << kClassLoaderSeparator;
- EncodeContextInternal(
- *info.parent.get(),
- base_dir,
- for_dex2oat,
- (stored_info == nullptr ? nullptr : stored_info->parent.get()),
- out);
+ EncodeContextInternal(*info.parent.get(),
+ base_dir,
+ for_dex2oat,
+ (stored_info == nullptr ? nullptr : stored_info->parent.get()),
+ out);
}
}
@@ -784,7 +777,8 @@ static ObjPtr<mirror::Class> GetClassLoaderClass(ClassLoaderContext::ClassLoader
return WellKnownClasses::dalvik_system_DelegateLastClassLoader.Get();
case ClassLoaderContext::kInMemoryDexClassLoader:
return WellKnownClasses::dalvik_system_InMemoryDexClassLoader.Get();
- case ClassLoaderContext::kInvalidClassLoader: break; // will fail after the switch.
+ case ClassLoaderContext::kInvalidClassLoader:
+ break; // will fail after the switch.
}
LOG(FATAL) << "Invalid class loader type " << type;
UNREACHABLE();
@@ -802,8 +796,7 @@ static ObjPtr<mirror::ClassLoader> CreateClassLoaderInternal(
VariableSizedHandleScope& map_scope,
std::map<std::string, Handle<mirror::ClassLoader>>& canonicalized_libraries,
bool add_compilation_sources,
- const std::vector<const DexFile*>& compilation_sources)
- REQUIRES_SHARED(Locks::mutator_lock_) {
+ const std::vector<const DexFile*>& compilation_sources) REQUIRES_SHARED(Locks::mutator_lock_) {
if (for_shared_library) {
// Check if the shared library has already been created.
auto search = canonicalized_libraries.find(FlattenClasspath(info.classpath));
@@ -816,7 +809,7 @@ static ObjPtr<mirror::ClassLoader> CreateClassLoaderInternal(
MutableHandle<mirror::ObjectArray<mirror::ClassLoader>> libraries(
hs.NewHandle<mirror::ObjectArray<mirror::ClassLoader>>(nullptr));
MutableHandle<mirror::ObjectArray<mirror::ClassLoader>> libraries_after(
- hs.NewHandle<mirror::ObjectArray<mirror::ClassLoader>>(nullptr));
+ hs.NewHandle<mirror::ObjectArray<mirror::ClassLoader>>(nullptr));
if (!info.shared_libraries.empty()) {
libraries.Assign(mirror::ObjectArray<mirror::ClassLoader>::Alloc(
@@ -826,15 +819,14 @@ static ObjPtr<mirror::ClassLoader> CreateClassLoaderInternal(
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(),
- /* for_shared_library= */ true,
- map_scope,
- canonicalized_libraries,
- /* add_compilation_sources= */ false,
- compilation_sources));
+ CreateClassLoaderInternal(self,
+ soa,
+ *info.shared_libraries[i].get(),
+ /* for_shared_library= */ true,
+ map_scope,
+ canonicalized_libraries,
+ /* add_compilation_sources= */ false,
+ compilation_sources));
}
}
@@ -846,50 +838,41 @@ static ObjPtr<mirror::ClassLoader> CreateClassLoaderInternal(
for (uint32_t i = 0; i < info.shared_libraries_after.size(); ++i) {
// We should only add the compilation sources to the first class loader.
libraries_after->Set(i,
- CreateClassLoaderInternal(
- self,
- soa,
- *info.shared_libraries_after[i].get(),
- /* for_shared_library= */ true,
- map_scope,
- canonicalized_libraries,
- /* add_compilation_sources= */ false,
- compilation_sources));
+ CreateClassLoaderInternal(self,
+ soa,
+ *info.shared_libraries_after[i].get(),
+ /* for_shared_library= */ true,
+ map_scope,
+ canonicalized_libraries,
+ /* add_compilation_sources= */ false,
+ compilation_sources));
}
}
MutableHandle<mirror::ClassLoader> parent = hs.NewHandle<mirror::ClassLoader>(nullptr);
if (info.parent != nullptr) {
// We should only add the compilation sources to the first class loader.
- parent.Assign(CreateClassLoaderInternal(
- self,
- soa,
- *info.parent.get(),
- /* for_shared_library= */ false,
- map_scope,
- canonicalized_libraries,
- /* add_compilation_sources= */ false,
- compilation_sources));
- }
- std::vector<const DexFile*> class_path_files = MakeNonOwningPointerVector(
- info.opened_dex_files);
+ parent.Assign(CreateClassLoaderInternal(self,
+ soa,
+ *info.parent.get(),
+ /* for_shared_library= */ false,
+ map_scope,
+ canonicalized_libraries,
+ /* 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());
+ class_path_files.insert(
+ class_path_files.end(), compilation_sources.begin(), compilation_sources.end());
}
Handle<mirror::Class> loader_class = hs.NewHandle<mirror::Class>(GetClassLoaderClass(info.type));
ObjPtr<mirror::ClassLoader> loader =
Runtime::Current()->GetClassLinker()->CreateWellKnownClassLoader(
- self,
- class_path_files,
- loader_class,
- parent,
- libraries,
- libraries_after);
+ self, class_path_files, loader_class, parent, libraries, libraries_after);
if (for_shared_library) {
canonicalized_libraries[FlattenClasspath(info.classpath)] =
map_scope.NewHandle<mirror::ClassLoader>(loader);
@@ -922,8 +905,7 @@ jobject ClassLoaderContext::CreateClassLoader(
/* add_compilation_sources= */ true,
compilation_sources);
// Make it a global ref and return.
- ScopedLocalRef<jobject> local_ref(
- soa.Env(), soa.Env()->AddLocalReference<jobject>(loader));
+ ScopedLocalRef<jobject> local_ref(soa.Env(), soa.Env()->AddLocalReference<jobject>(loader));
return soa.Env()->NewGlobalRef(local_ref.get());
}
@@ -969,9 +951,12 @@ std::vector<std::string> ClassLoaderContext::FlattenDexPaths() const {
const char* ClassLoaderContext::GetClassLoaderTypeName(ClassLoaderType type) {
switch (type) {
- case kPathClassLoader: return kPathClassLoaderString;
- case kDelegateLastClassLoader: return kDelegateLastClassLoaderString;
- case kInMemoryDexClassLoader: return kInMemoryDexClassLoaderString;
+ case kPathClassLoader:
+ return kPathClassLoaderString;
+ case kDelegateLastClassLoader:
+ return kDelegateLastClassLoaderString;
+ case kInMemoryDexClassLoader:
+ return kInMemoryDexClassLoaderString;
default:
LOG(FATAL) << "Invalid class loader type " << type;
UNREACHABLE();
@@ -989,7 +974,7 @@ void ClassLoaderContext::CheckDexFilesOpened(const std::string& calling_method)
static bool CollectDexFilesFromJavaDexFile(ObjPtr<mirror::Object> java_dex_file,
ArtField* const cookie_field,
std::vector<const DexFile*>* out_dex_files)
- REQUIRES_SHARED(Locks::mutator_lock_) {
+ REQUIRES_SHARED(Locks::mutator_lock_) {
if (java_dex_file == nullptr) {
return true;
}
@@ -1020,7 +1005,7 @@ static bool CollectDexFilesFromJavaDexFile(ObjPtr<mirror::Object> java_dex_file,
static bool CollectDexFilesFromSupportedClassLoader(Thread* self,
Handle<mirror::ClassLoader> class_loader,
std::vector<const DexFile*>* out_dex_files)
- REQUIRES_SHARED(Locks::mutator_lock_) {
+ REQUIRES_SHARED(Locks::mutator_lock_) {
CHECK(IsInstanceOfBaseDexClassLoader(class_loader));
// All supported class loaders inherit from BaseDexClassLoader.
@@ -1114,13 +1099,12 @@ static bool GetDexFilesFromDexElementsArray(
// This method is recursive (w.r.t. the class loader parent) and will stop once it reaches the
// BootClassLoader. Note that the class loader chain is expected to be short.
bool ClassLoaderContext::CreateInfoFromClassLoader(
- ScopedObjectAccessAlreadyRunnable& soa,
- Handle<mirror::ClassLoader> class_loader,
- Handle<mirror::ObjectArray<mirror::Object>> dex_elements,
- ClassLoaderInfo* child_info,
- bool is_shared_library,
- bool is_after)
- REQUIRES_SHARED(Locks::mutator_lock_) {
+ ScopedObjectAccessAlreadyRunnable& soa,
+ Handle<mirror::ClassLoader> class_loader,
+ Handle<mirror::ObjectArray<mirror::Object>> dex_elements,
+ ClassLoaderInfo* child_info,
+ bool is_shared_library,
+ bool is_after) REQUIRES_SHARED(Locks::mutator_lock_) {
if (ClassLinker::IsBootClassLoader(class_loader.Get())) {
// Nothing to do for the boot class loader as we don't add its dex files to the context.
return true;
@@ -1174,9 +1158,9 @@ bool ClassLoaderContext::CreateInfoFromClassLoader(
for (const DexFile* dex_file : dex_files_loaded) {
// Dex location of dex files loaded with InMemoryDexClassLoader is always bogus.
// Use a magic value for the classpath instead.
- info->classpath.push_back((type == kInMemoryDexClassLoader)
- ? kInMemoryDexClassLoaderDexLocationMagic
- : dex_file->GetLocation());
+ info->classpath.push_back((type == kInMemoryDexClassLoader) ?
+ kInMemoryDexClassLoaderDexLocationMagic :
+ dex_file->GetLocation());
info->checksums.push_back(dex_file->GetLocationChecksum());
info->opened_dex_files.emplace_back(dex_file);
}
@@ -1199,8 +1183,8 @@ bool ClassLoaderContext::CreateInfoFromClassLoader(
temp_loader,
null_dex_elements,
info,
- /*is_shared_library=*/ true,
- /*is_after=*/ false)) {
+ /*is_shared_library=*/true,
+ /*is_after=*/false)) {
return false;
}
}
@@ -1217,8 +1201,8 @@ bool ClassLoaderContext::CreateInfoFromClassLoader(
temp_loader,
null_dex_elements,
info,
- /*is_shared_library=*/ true,
- /*is_after=*/ true)) {
+ /*is_shared_library=*/true,
+ /*is_after=*/true)) {
return false;
}
}
@@ -1230,16 +1214,15 @@ bool ClassLoaderContext::CreateInfoFromClassLoader(
parent,
null_dex_elements,
info,
- /*is_shared_library=*/ false,
- /*is_after=*/ false)) {
+ /*is_shared_library=*/false,
+ /*is_after=*/false)) {
return false;
}
return true;
}
std::unique_ptr<ClassLoaderContext> ClassLoaderContext::CreateContextForClassLoader(
- jobject class_loader,
- jobjectArray dex_elements) {
+ jobject class_loader, jobjectArray dex_elements) {
ScopedTrace trace(__FUNCTION__);
if (class_loader == nullptr) {
@@ -1251,20 +1234,20 @@ std::unique_ptr<ClassLoaderContext> ClassLoaderContext::CreateContextForClassLoa
hs.NewHandle(soa.Decode<mirror::ClassLoader>(class_loader));
Handle<mirror::ObjectArray<mirror::Object>> h_dex_elements =
hs.NewHandle(soa.Decode<mirror::ObjectArray<mirror::Object>>(dex_elements));
- std::unique_ptr<ClassLoaderContext> result(new ClassLoaderContext(/*owns_the_dex_files=*/ false));
+ std::unique_ptr<ClassLoaderContext> result(new ClassLoaderContext(/*owns_the_dex_files=*/false));
if (!result->CreateInfoFromClassLoader(soa,
h_class_loader,
h_dex_elements,
nullptr,
- /*is_shared_library=*/ false,
- /*is_after=*/ false)) {
+ /*is_shared_library=*/false,
+ /*is_after=*/false)) {
return nullptr;
}
return result;
}
-std::map<std::string, std::string>
-ClassLoaderContext::EncodeClassPathContextsForClassLoader(jobject class_loader) {
+std::map<std::string, std::string> ClassLoaderContext::EncodeClassPathContextsForClassLoader(
+ jobject class_loader) {
std::unique_ptr<ClassLoaderContext> clc =
ClassLoaderContext::CreateContextForClassLoader(class_loader, nullptr);
if (clc != nullptr) {
@@ -1291,14 +1274,12 @@ ClassLoaderContext::EncodeClassPathContextsForClassLoader(jobject class_loader)
}
bool ClassLoaderContext::IsValidEncoding(const std::string& possible_encoded_class_loader_context) {
- return ClassLoaderContext::Create(possible_encoded_class_loader_context.c_str()) != nullptr
- || possible_encoded_class_loader_context == kUnsupportedClassLoaderContextEncoding;
+ return ClassLoaderContext::Create(possible_encoded_class_loader_context) != nullptr ||
+ possible_encoded_class_loader_context == kUnsupportedClassLoaderContextEncoding;
}
ClassLoaderContext::VerificationResult ClassLoaderContext::VerifyClassLoaderContextMatch(
- const std::string& context_spec,
- bool verify_names,
- bool verify_checksums) const {
+ const std::string& context_spec, bool verify_names, bool verify_checksums) const {
ScopedTrace trace(__FUNCTION__);
if (verify_names || verify_checksums) {
DCHECK(dex_files_state_ == kDexFilesChecksumsRead || dex_files_state_ == kDexFilesOpened)
@@ -1328,8 +1309,7 @@ static inline bool AbsolutePathHasRelativeSuffix(const std::string& path,
const std::string& suffix) {
DCHECK(IsAbsoluteLocation(path));
DCHECK(!IsAbsoluteLocation(suffix));
- return (path.size() > suffix.size()) &&
- (path[path.size() - suffix.size() - 1u] == '/') &&
+ return (path.size() > suffix.size()) && (path[path.size() - suffix.size() - 1u] == '/') &&
(std::string_view(path).substr(/*pos*/ path.size() - suffix.size()) == suffix);
}
@@ -1394,24 +1374,23 @@ static bool AreDexNameMatching(const std::string& actual_dex_name,
return dex_names_match;
}
-bool ClassLoaderContext::ClassLoaderInfoMatch(
- const ClassLoaderInfo& info,
- const ClassLoaderInfo& expected_info,
- const std::string& context_spec,
- bool verify_names,
- bool verify_checksums) const {
+bool ClassLoaderContext::ClassLoaderInfoMatch(const ClassLoaderInfo& info,
+ const ClassLoaderInfo& expected_info,
+ const std::string& context_spec,
+ bool verify_names,
+ bool verify_checksums) const {
if (info.type != expected_info.type) {
LOG(WARNING) << "ClassLoaderContext type mismatch"
- << ". expected=" << GetClassLoaderTypeName(expected_info.type)
- << ", found=" << GetClassLoaderTypeName(info.type)
- << " (" << context_spec << " | " << EncodeContextForOatFile("") << ")";
+ << ". expected=" << GetClassLoaderTypeName(expected_info.type)
+ << ", found=" << GetClassLoaderTypeName(info.type) << " (" << context_spec << " | "
+ << EncodeContextForOatFile("") << ")";
return false;
}
if (info.classpath.size() != expected_info.classpath.size()) {
LOG(WARNING) << "ClassLoaderContext classpath size mismatch"
- << ". expected=" << expected_info.classpath.size()
- << ", found=" << info.classpath.size()
- << " (" << context_spec << " | " << EncodeContextForOatFile("") << ")";
+ << ". expected=" << expected_info.classpath.size()
+ << ", found=" << info.classpath.size() << " (" << context_spec << " | "
+ << EncodeContextForOatFile("") << ")";
return false;
}
@@ -1427,9 +1406,9 @@ bool ClassLoaderContext::ClassLoaderInfoMatch(
// Compare the locations.
if (!dex_names_match) {
LOG(WARNING) << "ClassLoaderContext classpath element mismatch"
- << ". expected=" << expected_info.classpath[k]
- << ", found=" << info.classpath[k]
- << " (" << context_spec << " | " << EncodeContextForOatFile("") << ")";
+ << ". expected=" << expected_info.classpath[k]
+ << ", found=" << info.classpath[k] << " (" << context_spec << " | "
+ << EncodeContextForOatFile("") << ")";
return false;
}
@@ -1437,8 +1416,8 @@ bool ClassLoaderContext::ClassLoaderInfoMatch(
if (info.checksums[k] != expected_info.checksums[k]) {
LOG(WARNING) << "ClassLoaderContext classpath element checksum mismatch"
<< ". expected=" << expected_info.checksums[k]
- << ", found=" << info.checksums[k]
- << " (" << context_spec << " | " << EncodeContextForOatFile("") << ")";
+ << ", found=" << info.checksums[k] << " (" << context_spec << " | "
+ << EncodeContextForOatFile("") << ")";
return false;
}
}
@@ -1446,9 +1425,9 @@ bool ClassLoaderContext::ClassLoaderInfoMatch(
if (info.shared_libraries.size() != expected_info.shared_libraries.size()) {
LOG(WARNING) << "ClassLoaderContext shared library size mismatch. "
- << "Expected=" << expected_info.shared_libraries.size()
- << ", found=" << info.shared_libraries.size()
- << " (" << context_spec << " | " << EncodeContextForOatFile("") << ")";
+ << "Expected=" << expected_info.shared_libraries.size()
+ << ", found=" << info.shared_libraries.size() << " (" << context_spec << " | "
+ << EncodeContextForOatFile("") << ")";
return false;
}
for (size_t i = 0; i < info.shared_libraries.size(); ++i) {
@@ -1463,13 +1442,13 @@ bool ClassLoaderContext::ClassLoaderInfoMatch(
if (info.parent.get() == nullptr) {
if (expected_info.parent.get() != nullptr) {
LOG(WARNING) << "ClassLoaderContext parent mismatch. "
- << " (" << context_spec << " | " << EncodeContextForOatFile("") << ")";
+ << " (" << context_spec << " | " << EncodeContextForOatFile("") << ")";
return false;
}
return true;
} else if (expected_info.parent.get() == nullptr) {
LOG(WARNING) << "ClassLoaderContext parent mismatch. "
- << " (" << context_spec << " | " << EncodeContextForOatFile("") << ")";
+ << " (" << context_spec << " | " << EncodeContextForOatFile("") << ")";
return false;
} else {
return ClassLoaderInfoMatch(*info.parent.get(),
@@ -1499,8 +1478,8 @@ std::set<const DexFile*> ClassLoaderContext::CheckForDuplicateDexFiles(
ClassLoaderInfo* info = class_loader_chain_.get();
for (size_t k = 0; k < info->classpath.size(); k++) {
for (const DexFile* dex_file : dex_files_to_check) {
- if (info->checksums[k] == dex_file->GetLocationChecksum()
- && AreDexNameMatching(info->classpath[k], dex_file->GetLocation())) {
+ if (info->checksums[k] == dex_file->GetLocationChecksum() &&
+ AreDexNameMatching(info->classpath[k], dex_file->GetLocation())) {
result.insert(dex_file);
}
}