diff options
| author | 2019-03-27 09:56:45 +0000 | |
|---|---|---|
| committer | 2019-04-01 10:26:42 +0000 | |
| commit | 93d339d9b2949ca85d031bb9ebb7a0612b095fa8 (patch) | |
| tree | d0793a9fe9df196398ca523c4a57a0ed18f107e4 /runtime/class_loader_context.cc | |
| parent | bdc93b47e2e7e8f17413669e03bc461d259d16f6 (diff) | |
Revert^2: InMemoryDexClassLoader in ClassLoaderContext follow-up
Address follow-up comments on Ic64065819018a1e56dee0f65405d26beb8fd7bbd.
In particular, the classpath elements of IMC are replaced with
"<unknown>" magic value to make it clear that the dex location is bogus,
and a clarifying comment is added.
Previously this CL would fail on target because IMC classpath was not
being replaced with "<unknown>" and context matching failed. This was
only a problem on target because
OatFile::ResolveRelativeEncodedDexLocation ignores non-absolute
locations on host.
This reverts commit 93d99f3665cbd890509f4c707e1a62c5f26d320e.
Test: m test-art-gtest-class_loader_context_test
Bug: 72131483
Change-Id: I27cbfa69c24d412cc1b6bcce88218cc95e324ef5
Diffstat (limited to 'runtime/class_loader_context.cc')
| -rw-r--r-- | runtime/class_loader_context.cc | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/runtime/class_loader_context.cc b/runtime/class_loader_context.cc index 428bf30500..2b62d59118 100644 --- a/runtime/class_loader_context.cc +++ b/runtime/class_loader_context.cc @@ -54,6 +54,7 @@ static constexpr char kClassLoaderSharedLibrarySeparator = '#'; static constexpr char kClassLoaderSeparator = ';'; static constexpr char kClasspathSeparator = ':'; static constexpr char kDexFileChecksumSeparator = '*'; +static constexpr char kInMemoryDexClassLoaderDexLocationMagic[] = "<unknown>"; ClassLoaderContext::ClassLoaderContext() : special_shared_library_(false), @@ -170,6 +171,8 @@ std::unique_ptr<ClassLoaderContext::ClassLoaderInfo> ClassLoaderContext::ParseCl // Checksums are not provided and dex locations themselves have no meaning // (although we keep them in the spec to simplify parsing). Treat this as // an unknown class loader. + // We can hit this case if dex2oat is invoked with a spec containing IMC. + // Because the dex file data is only available at runtime, we cannot proceed. return nullptr; } } @@ -198,6 +201,7 @@ std::unique_ptr<ClassLoaderContext::ClassLoaderInfo> ClassLoaderContext::ParseCl std::unique_ptr<ClassLoaderInfo> info(new ClassLoaderInfo(class_loader_type)); if (!parse_checksums) { + DCHECK(class_loader_type != kInMemoryDexClassLoader); Split(classpath, kClasspathSeparator, &info->classpath); } else { std::vector<std::string> classpath_elements; @@ -212,6 +216,10 @@ std::unique_ptr<ClassLoaderContext::ClassLoaderInfo> ClassLoaderContext::ParseCl if (!android::base::ParseUint(dex_file_with_checksum[1].c_str(), &checksum)) { return nullptr; } + if ((class_loader_type == kInMemoryDexClassLoader) && + (dex_file_with_checksum[0] != kInMemoryDexClassLoaderDexLocationMagic)) { + return nullptr; + } info->classpath.push_back(dex_file_with_checksum[0]); info->checksums.push_back(checksum); @@ -417,6 +425,8 @@ bool ClassLoaderContext::OpenDexFiles(InstructionSet isa, while (!work_list.empty()) { ClassLoaderInfo* info = work_list.back(); work_list.pop_back(); + DCHECK(info->type != kInMemoryDexClassLoader) << __FUNCTION__ << " not supported for IMC"; + size_t opened_dex_files_index = info->opened_dex_files.size(); for (const std::string& cp_elem : info->classpath) { // If path is relative, append it to the provided base directory. @@ -625,8 +635,10 @@ void ClassLoaderContext::EncodeContextInternal(const ClassLoaderInfo& info, if (k > 0) { out << kClasspathSeparator; } - // Find paths that were relative and convert them back from absolute. - if (!base_dir.empty() && location.substr(0, base_dir.length()) == base_dir) { + if (info.type == kInMemoryDexClassLoader) { + out << kInMemoryDexClassLoaderDexLocationMagic; + } 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 { out << location.c_str(); @@ -1051,7 +1063,11 @@ bool ClassLoaderContext::CreateInfoFromClassLoader( // Now that `info` is in the chain, populate dex files. for (const DexFile* dex_file : dex_files_loaded) { - info->classpath.push_back(dex_file->GetLocation()); + // 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->checksums.push_back(dex_file->GetLocationChecksum()); info->opened_dex_files.emplace_back(dex_file); } |