diff options
author | 2017-08-03 17:07:13 +0000 | |
---|---|---|
committer | 2017-08-03 17:07:13 +0000 | |
commit | cda934e3f8c24d76cc3b1b64e24dd9b865cb500f (patch) | |
tree | ab8b7b8539a7f3fafc56a42242bf88ac3653441a /runtime/class_loader_context.cc | |
parent | 9a19be9c170e094c3e5ef991d018b476008112c5 (diff) | |
parent | 84f82b9972ec29bd05b1575ae6d638255be2f285 (diff) |
Merge changes Iba4cb348,I51c43230,Iae90c4a1,Ica43ee8a
* changes:
Stop using the runtime classpath in dex2oat
Do not pass --runtime-arg -classpath in dex2oat_test
Do not pass --runtime-arg -classpath to dex2oat in dex fuzz
Pass the class loader context to dex2oat when optimizing at runtime
Diffstat (limited to 'runtime/class_loader_context.cc')
-rw-r--r-- | runtime/class_loader_context.cc | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/runtime/class_loader_context.cc b/runtime/class_loader_context.cc index 92d0f8d5ae..e7051b35d8 100644 --- a/runtime/class_loader_context.cc +++ b/runtime/class_loader_context.cc @@ -68,6 +68,10 @@ ClassLoaderContext::~ClassLoaderContext() { } } +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()); if (result->Parse(spec)) { @@ -263,7 +267,16 @@ bool ClassLoaderContext::RemoveLocationsFromClassPaths( return removed_locations; } +std::string ClassLoaderContext::EncodeContextForDex2oat(const std::string& base_dir) const { + return EncodeContext(base_dir, /*for_dex2oat*/ true); +} + std::string ClassLoaderContext::EncodeContextForOatFile(const std::string& base_dir) const { + return EncodeContext(base_dir, /*for_dex2oat*/ false); +} + +std::string ClassLoaderContext::EncodeContext(const std::string& base_dir, + bool for_dex2oat) const { CheckDexFilesOpened("EncodeContextForOatFile"); if (special_shared_library_) { return OatFile::kSpecialSharedLibrary; @@ -286,8 +299,17 @@ std::string ClassLoaderContext::EncodeContextForOatFile(const std::string& base_ } out << GetClassLoaderTypeName(info.type); out << kClassLoaderOpeningMark; + std::set<std::string> seen_locations; for (size_t k = 0; k < info.opened_dex_files.size(); k++) { const std::unique_ptr<const DexFile>& dex_file = info.opened_dex_files[k]; + 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(dex_file->GetBaseLocation()).second; + if (!new_insert) { + continue; + } + } const std::string& location = dex_file->GetLocation(); if (k > 0) { out << kClasspathSeparator; @@ -298,8 +320,11 @@ std::string ClassLoaderContext::EncodeContextForOatFile(const std::string& base_ } else { out << dex_file->GetLocation().c_str(); } - out << kDexFileChecksumSeparator; - out << dex_file->GetLocationChecksum(); + // dex2oat does not need the checksums. + if (!for_dex2oat) { + out << kDexFileChecksumSeparator; + out << dex_file->GetLocationChecksum(); + } } out << kClassLoaderClosingMark; } @@ -593,7 +618,7 @@ std::unique_ptr<ClassLoaderContext> ClassLoaderContext::CreateContextForClassLoa } } -bool ClassLoaderContext::VerifyClassLoaderContextMatch(const std::string& context_spec) { +bool ClassLoaderContext::VerifyClassLoaderContextMatch(const std::string& context_spec) const { ClassLoaderContext expected_context; if (!expected_context.Parse(context_spec, /*parse_checksums*/ true)) { LOG(WARNING) << "Invalid class loader context: " << context_spec; |