Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "class_loader_context.h" |
| 18 | |
Andreas Gampe | f941170 | 2018-09-06 17:16:57 -0700 | [diff] [blame] | 19 | #include <android-base/parseint.h> |
Nicolas Geoffray | cb2e1dd | 2018-11-20 11:15:13 +0000 | [diff] [blame] | 20 | #include <android-base/strings.h> |
Andreas Gampe | f941170 | 2018-09-06 17:16:57 -0700 | [diff] [blame] | 21 | |
Calin Juravle | 57d0acc | 2017-07-11 17:41:30 -0700 | [diff] [blame] | 22 | #include "art_field-inl.h" |
Vladimir Marko | 78baed5 | 2018-10-11 10:44:58 +0100 | [diff] [blame] | 23 | #include "base/casts.h" |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 24 | #include "base/dchecked_vector.h" |
| 25 | #include "base/stl_util.h" |
| 26 | #include "class_linker.h" |
Calin Juravle | 57d0acc | 2017-07-11 17:41:30 -0700 | [diff] [blame] | 27 | #include "class_loader_utils.h" |
Nicolas Geoffray | 6b9fd8c | 2018-11-16 10:25:42 +0000 | [diff] [blame] | 28 | #include "class_root.h" |
David Sehr | 013fd80 | 2018-01-11 22:55:24 -0800 | [diff] [blame] | 29 | #include "dex/art_dex_file_loader.h" |
David Sehr | 9e734c7 | 2018-01-04 17:56:19 -0800 | [diff] [blame] | 30 | #include "dex/dex_file.h" |
| 31 | #include "dex/dex_file_loader.h" |
Calin Juravle | 57d0acc | 2017-07-11 17:41:30 -0700 | [diff] [blame] | 32 | #include "handle_scope-inl.h" |
Vladimir Marko | a3ad0cd | 2018-05-04 10:06:38 +0100 | [diff] [blame] | 33 | #include "jni/jni_internal.h" |
Nicolas Geoffray | 6b9fd8c | 2018-11-16 10:25:42 +0000 | [diff] [blame] | 34 | #include "mirror/object_array-alloc-inl.h" |
| 35 | #include "nativehelper/scoped_local_ref.h" |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 36 | #include "oat_file_assistant.h" |
Calin Juravle | 57d0acc | 2017-07-11 17:41:30 -0700 | [diff] [blame] | 37 | #include "obj_ptr-inl.h" |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 38 | #include "runtime.h" |
| 39 | #include "scoped_thread_state_change-inl.h" |
| 40 | #include "thread.h" |
Calin Juravle | 57d0acc | 2017-07-11 17:41:30 -0700 | [diff] [blame] | 41 | #include "well_known_classes.h" |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 42 | |
| 43 | namespace art { |
| 44 | |
| 45 | static constexpr char kPathClassLoaderString[] = "PCL"; |
| 46 | static constexpr char kDelegateLastClassLoaderString[] = "DLC"; |
David Brazdil | 1a9ac53 | 2019-03-05 11:57:13 +0000 | [diff] [blame] | 47 | static constexpr char kInMemoryDexClassLoaderString[] = "IMC"; |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 48 | static constexpr char kClassLoaderOpeningMark = '['; |
| 49 | static constexpr char kClassLoaderClosingMark = ']'; |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 50 | static constexpr char kClassLoaderSharedLibraryOpeningMark = '{'; |
| 51 | static constexpr char kClassLoaderSharedLibraryClosingMark = '}'; |
| 52 | static constexpr char kClassLoaderSharedLibrarySeparator = '#'; |
Calin Juravle | 7b0648a | 2017-07-07 18:40:50 -0700 | [diff] [blame] | 53 | static constexpr char kClassLoaderSeparator = ';'; |
| 54 | static constexpr char kClasspathSeparator = ':'; |
| 55 | static constexpr char kDexFileChecksumSeparator = '*'; |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 56 | |
| 57 | ClassLoaderContext::ClassLoaderContext() |
| 58 | : special_shared_library_(false), |
| 59 | dex_files_open_attempted_(false), |
Calin Juravle | 57d0acc | 2017-07-11 17:41:30 -0700 | [diff] [blame] | 60 | dex_files_open_result_(false), |
Calin Juravle | 41acdc1 | 2017-07-18 17:45:32 -0700 | [diff] [blame] | 61 | owns_the_dex_files_(true) {} |
Calin Juravle | 57d0acc | 2017-07-11 17:41:30 -0700 | [diff] [blame] | 62 | |
| 63 | ClassLoaderContext::ClassLoaderContext(bool owns_the_dex_files) |
| 64 | : special_shared_library_(false), |
| 65 | dex_files_open_attempted_(true), |
| 66 | dex_files_open_result_(true), |
| 67 | owns_the_dex_files_(owns_the_dex_files) {} |
| 68 | |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 69 | // Utility method to add parent and shared libraries of `info` into |
| 70 | // the `work_list`. |
| 71 | static void AddToWorkList( |
| 72 | ClassLoaderContext::ClassLoaderInfo* info, |
| 73 | std::vector<ClassLoaderContext::ClassLoaderInfo*>& work_list) { |
| 74 | if (info->parent != nullptr) { |
| 75 | work_list.push_back(info->parent.get()); |
| 76 | } |
| 77 | for (size_t i = 0; i < info->shared_libraries.size(); ++i) { |
| 78 | work_list.push_back(info->shared_libraries[i].get()); |
| 79 | } |
| 80 | } |
| 81 | |
Calin Juravle | 57d0acc | 2017-07-11 17:41:30 -0700 | [diff] [blame] | 82 | ClassLoaderContext::~ClassLoaderContext() { |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 83 | if (!owns_the_dex_files_ && class_loader_chain_ != nullptr) { |
Calin Juravle | 57d0acc | 2017-07-11 17:41:30 -0700 | [diff] [blame] | 84 | // If the context does not own the dex/oat files release the unique pointers to |
| 85 | // make sure we do not de-allocate them. |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 86 | std::vector<ClassLoaderInfo*> work_list; |
| 87 | work_list.push_back(class_loader_chain_.get()); |
| 88 | while (!work_list.empty()) { |
| 89 | ClassLoaderInfo* info = work_list.back(); |
| 90 | work_list.pop_back(); |
| 91 | for (std::unique_ptr<OatFile>& oat_file : info->opened_oat_files) { |
Andreas Gampe | afaf7f8 | 2018-10-16 11:32:38 -0700 | [diff] [blame] | 92 | oat_file.release(); // NOLINT b/117926937 |
Calin Juravle | 57d0acc | 2017-07-11 17:41:30 -0700 | [diff] [blame] | 93 | } |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 94 | for (std::unique_ptr<const DexFile>& dex_file : info->opened_dex_files) { |
Andreas Gampe | afaf7f8 | 2018-10-16 11:32:38 -0700 | [diff] [blame] | 95 | dex_file.release(); // NOLINT b/117926937 |
Calin Juravle | 57d0acc | 2017-07-11 17:41:30 -0700 | [diff] [blame] | 96 | } |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 97 | AddToWorkList(info, work_list); |
Calin Juravle | 57d0acc | 2017-07-11 17:41:30 -0700 | [diff] [blame] | 98 | } |
| 99 | } |
| 100 | } |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 101 | |
Calin Juravle | 1991589 | 2017-08-03 17:10:36 +0000 | [diff] [blame] | 102 | std::unique_ptr<ClassLoaderContext> ClassLoaderContext::Default() { |
| 103 | return Create(""); |
| 104 | } |
| 105 | |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 106 | std::unique_ptr<ClassLoaderContext> ClassLoaderContext::Create(const std::string& spec) { |
| 107 | std::unique_ptr<ClassLoaderContext> result(new ClassLoaderContext()); |
| 108 | if (result->Parse(spec)) { |
| 109 | return result; |
| 110 | } else { |
| 111 | return nullptr; |
| 112 | } |
| 113 | } |
| 114 | |
Nicolas Geoffray | f378fff | 2018-11-19 12:52:26 +0000 | [diff] [blame] | 115 | static size_t FindMatchingSharedLibraryCloseMarker(const std::string& spec, |
| 116 | size_t shared_library_open_index) { |
| 117 | // Counter of opened shared library marker we've encountered so far. |
| 118 | uint32_t counter = 1; |
| 119 | // The index at which we're operating in the loop. |
| 120 | uint32_t string_index = shared_library_open_index + 1; |
| 121 | size_t shared_library_close = std::string::npos; |
| 122 | while (counter != 0) { |
| 123 | shared_library_close = |
| 124 | spec.find_first_of(kClassLoaderSharedLibraryClosingMark, string_index); |
| 125 | size_t shared_library_open = |
| 126 | spec.find_first_of(kClassLoaderSharedLibraryOpeningMark, string_index); |
| 127 | if (shared_library_close == std::string::npos) { |
| 128 | // No matching closing marker. Return an error. |
| 129 | break; |
| 130 | } |
| 131 | |
| 132 | if ((shared_library_open == std::string::npos) || |
| 133 | (shared_library_close < shared_library_open)) { |
| 134 | // We have seen a closing marker. Decrement the counter. |
| 135 | --counter; |
| 136 | // Move the search index forward. |
| 137 | string_index = shared_library_close + 1; |
| 138 | } else { |
| 139 | // New nested opening marker. Increment the counter and move the search |
| 140 | // index after the marker. |
| 141 | ++counter; |
| 142 | string_index = shared_library_open + 1; |
| 143 | } |
| 144 | } |
| 145 | return shared_library_close; |
| 146 | } |
| 147 | |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 148 | // The expected format is: |
| 149 | // "ClassLoaderType1[ClasspathElem1*Checksum1:ClasspathElem2*Checksum2...]{ClassLoaderType2[...]}". |
Calin Juravle | 7b0648a | 2017-07-07 18:40:50 -0700 | [diff] [blame] | 150 | // The checksum part of the format is expected only if parse_cheksums is true. |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 151 | std::unique_ptr<ClassLoaderContext::ClassLoaderInfo> ClassLoaderContext::ParseClassLoaderSpec( |
| 152 | const std::string& class_loader_spec, |
| 153 | bool parse_checksums) { |
| 154 | ClassLoaderType class_loader_type = ExtractClassLoaderType(class_loader_spec); |
| 155 | if (class_loader_type == kInvalidClassLoader) { |
| 156 | return nullptr; |
| 157 | } |
David Brazdil | 1a9ac53 | 2019-03-05 11:57:13 +0000 | [diff] [blame] | 158 | |
| 159 | // InMemoryDexClassLoader's dex location is always bogus. Special-case it. |
| 160 | if (class_loader_type == kInMemoryDexClassLoader) { |
| 161 | if (parse_checksums) { |
| 162 | // Make sure that OpenDexFiles() will never be attempted on this context |
| 163 | // because the dex locations of IMC do not correspond to real files. |
| 164 | CHECK(!dex_files_open_attempted_ || !dex_files_open_result_) |
| 165 | << "Parsing spec not supported when context created from a ClassLoader object"; |
| 166 | dex_files_open_attempted_ = true; |
| 167 | dex_files_open_result_ = false; |
| 168 | } else { |
| 169 | // Checksums are not provided and dex locations themselves have no meaning |
| 170 | // (although we keep them in the spec to simplify parsing). Treat this as |
| 171 | // an unknown class loader. |
| 172 | return nullptr; |
| 173 | } |
| 174 | } |
| 175 | |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 176 | const char* class_loader_type_str = GetClassLoaderTypeName(class_loader_type); |
| 177 | size_t type_str_size = strlen(class_loader_type_str); |
| 178 | |
| 179 | CHECK_EQ(0, class_loader_spec.compare(0, type_str_size, class_loader_type_str)); |
| 180 | |
| 181 | // Check the opening and closing markers. |
| 182 | if (class_loader_spec[type_str_size] != kClassLoaderOpeningMark) { |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 183 | return nullptr; |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 184 | } |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 185 | if ((class_loader_spec[class_loader_spec.length() - 1] != kClassLoaderClosingMark) && |
| 186 | (class_loader_spec[class_loader_spec.length() - 1] != kClassLoaderSharedLibraryClosingMark)) { |
| 187 | return nullptr; |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 188 | } |
| 189 | |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 190 | size_t closing_index = class_loader_spec.find_first_of(kClassLoaderClosingMark); |
| 191 | |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 192 | // At this point we know the format is ok; continue and extract the classpath. |
| 193 | // Note that class loaders with an empty class path are allowed. |
| 194 | std::string classpath = class_loader_spec.substr(type_str_size + 1, |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 195 | closing_index - type_str_size - 1); |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 196 | |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 197 | std::unique_ptr<ClassLoaderInfo> info(new ClassLoaderInfo(class_loader_type)); |
Calin Juravle | 7b0648a | 2017-07-07 18:40:50 -0700 | [diff] [blame] | 198 | |
| 199 | if (!parse_checksums) { |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 200 | Split(classpath, kClasspathSeparator, &info->classpath); |
Calin Juravle | 7b0648a | 2017-07-07 18:40:50 -0700 | [diff] [blame] | 201 | } else { |
| 202 | std::vector<std::string> classpath_elements; |
| 203 | Split(classpath, kClasspathSeparator, &classpath_elements); |
| 204 | for (const std::string& element : classpath_elements) { |
| 205 | std::vector<std::string> dex_file_with_checksum; |
| 206 | Split(element, kDexFileChecksumSeparator, &dex_file_with_checksum); |
| 207 | if (dex_file_with_checksum.size() != 2) { |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 208 | return nullptr; |
Calin Juravle | 7b0648a | 2017-07-07 18:40:50 -0700 | [diff] [blame] | 209 | } |
| 210 | uint32_t checksum = 0; |
Tom Cherry | 7bc8e8f | 2018-10-05 14:34:13 -0700 | [diff] [blame] | 211 | if (!android::base::ParseUint(dex_file_with_checksum[1].c_str(), &checksum)) { |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 212 | return nullptr; |
Calin Juravle | 7b0648a | 2017-07-07 18:40:50 -0700 | [diff] [blame] | 213 | } |
David Brazdil | 1a9ac53 | 2019-03-05 11:57:13 +0000 | [diff] [blame] | 214 | |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 215 | info->classpath.push_back(dex_file_with_checksum[0]); |
| 216 | info->checksums.push_back(checksum); |
Calin Juravle | 7b0648a | 2017-07-07 18:40:50 -0700 | [diff] [blame] | 217 | } |
| 218 | } |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 219 | |
Nicolas Geoffray | f378fff | 2018-11-19 12:52:26 +0000 | [diff] [blame] | 220 | if ((class_loader_spec[class_loader_spec.length() - 1] == kClassLoaderSharedLibraryClosingMark) && |
| 221 | (class_loader_spec[class_loader_spec.length() - 2] != kClassLoaderSharedLibraryOpeningMark)) { |
| 222 | // Non-empty list of shared libraries. |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 223 | size_t start_index = class_loader_spec.find_first_of(kClassLoaderSharedLibraryOpeningMark); |
| 224 | if (start_index == std::string::npos) { |
| 225 | return nullptr; |
| 226 | } |
| 227 | std::string shared_libraries_spec = |
| 228 | class_loader_spec.substr(start_index + 1, class_loader_spec.length() - start_index - 2); |
| 229 | std::vector<std::string> shared_libraries; |
Nicolas Geoffray | f378fff | 2018-11-19 12:52:26 +0000 | [diff] [blame] | 230 | size_t cursor = 0; |
| 231 | while (cursor != shared_libraries_spec.length()) { |
| 232 | size_t shared_library_separator = |
| 233 | shared_libraries_spec.find_first_of(kClassLoaderSharedLibrarySeparator, cursor); |
| 234 | size_t shared_library_open = |
| 235 | shared_libraries_spec.find_first_of(kClassLoaderSharedLibraryOpeningMark, cursor); |
| 236 | std::string shared_library_spec; |
| 237 | if (shared_library_separator == std::string::npos) { |
| 238 | // Only one shared library, for example: |
| 239 | // PCL[...] |
| 240 | shared_library_spec = |
| 241 | shared_libraries_spec.substr(cursor, shared_libraries_spec.length() - cursor); |
| 242 | cursor = shared_libraries_spec.length(); |
| 243 | } else if ((shared_library_open == std::string::npos) || |
| 244 | (shared_library_open > shared_library_separator)) { |
| 245 | // We found a shared library without nested shared libraries, for example: |
| 246 | // PCL[...]#PCL[...]{...} |
| 247 | shared_library_spec = |
| 248 | shared_libraries_spec.substr(cursor, shared_library_separator - cursor); |
| 249 | cursor = shared_library_separator + 1; |
| 250 | } else { |
| 251 | // The shared library contains nested shared libraries. Find the matching closing shared |
| 252 | // marker for it. |
| 253 | size_t closing_marker = |
| 254 | FindMatchingSharedLibraryCloseMarker(shared_libraries_spec, shared_library_open); |
| 255 | if (closing_marker == std::string::npos) { |
| 256 | // No matching closing marker, return an error. |
| 257 | return nullptr; |
| 258 | } |
| 259 | shared_library_spec = shared_libraries_spec.substr(cursor, closing_marker + 1 - cursor); |
| 260 | cursor = closing_marker + 1; |
| 261 | if (cursor != shared_libraries_spec.length() && |
| 262 | shared_libraries_spec[cursor] == kClassLoaderSharedLibrarySeparator) { |
| 263 | // Pass the shared library separator marker. |
| 264 | ++cursor; |
| 265 | } |
| 266 | } |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 267 | std::unique_ptr<ClassLoaderInfo> shared_library( |
| 268 | ParseInternal(shared_library_spec, parse_checksums)); |
| 269 | if (shared_library == nullptr) { |
| 270 | return nullptr; |
| 271 | } |
| 272 | info->shared_libraries.push_back(std::move(shared_library)); |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | return info; |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | // Extracts the class loader type from the given spec. |
| 280 | // Return ClassLoaderContext::kInvalidClassLoader if the class loader type is not |
| 281 | // recognized. |
| 282 | ClassLoaderContext::ClassLoaderType |
| 283 | ClassLoaderContext::ExtractClassLoaderType(const std::string& class_loader_spec) { |
David Brazdil | 1a9ac53 | 2019-03-05 11:57:13 +0000 | [diff] [blame] | 284 | const ClassLoaderType kValidTypes[] = { kPathClassLoader, |
| 285 | kDelegateLastClassLoader, |
| 286 | kInMemoryDexClassLoader }; |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 287 | for (const ClassLoaderType& type : kValidTypes) { |
| 288 | const char* type_str = GetClassLoaderTypeName(type); |
| 289 | if (class_loader_spec.compare(0, strlen(type_str), type_str) == 0) { |
| 290 | return type; |
| 291 | } |
| 292 | } |
| 293 | return kInvalidClassLoader; |
| 294 | } |
| 295 | |
| 296 | // The format: ClassLoaderType1[ClasspathElem1:ClasspathElem2...];ClassLoaderType2[...]... |
| 297 | // ClassLoaderType is either "PCL" (PathClassLoader) or "DLC" (DelegateLastClassLoader). |
| 298 | // ClasspathElem is the path of dex/jar/apk file. |
Calin Juravle | 7b0648a | 2017-07-07 18:40:50 -0700 | [diff] [blame] | 299 | bool ClassLoaderContext::Parse(const std::string& spec, bool parse_checksums) { |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 300 | if (spec.empty()) { |
Calin Juravle | 1a509c8 | 2017-07-24 16:51:21 -0700 | [diff] [blame] | 301 | // By default we load the dex files in a PathClassLoader. |
| 302 | // So an empty spec is equivalent to an empty PathClassLoader (this happens when running |
| 303 | // tests) |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 304 | class_loader_chain_.reset(new ClassLoaderInfo(kPathClassLoader)); |
Calin Juravle | 7b0648a | 2017-07-07 18:40:50 -0700 | [diff] [blame] | 305 | return true; |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 306 | } |
Calin Juravle | 7b0648a | 2017-07-07 18:40:50 -0700 | [diff] [blame] | 307 | |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 308 | // Stop early if we detect the special shared library, which may be passed as the classpath |
| 309 | // for dex2oat when we want to skip the shared libraries check. |
| 310 | if (spec == OatFile::kSpecialSharedLibrary) { |
| 311 | LOG(INFO) << "The ClassLoaderContext is a special shared library."; |
| 312 | special_shared_library_ = true; |
| 313 | return true; |
| 314 | } |
| 315 | |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 316 | CHECK(class_loader_chain_ == nullptr); |
| 317 | class_loader_chain_.reset(ParseInternal(spec, parse_checksums)); |
| 318 | return class_loader_chain_ != nullptr; |
| 319 | } |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 320 | |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 321 | ClassLoaderContext::ClassLoaderInfo* ClassLoaderContext::ParseInternal( |
| 322 | const std::string& spec, bool parse_checksums) { |
| 323 | CHECK(!spec.empty()); |
| 324 | CHECK_NE(spec, OatFile::kSpecialSharedLibrary); |
| 325 | std::string remaining = spec; |
| 326 | std::unique_ptr<ClassLoaderInfo> first(nullptr); |
| 327 | ClassLoaderInfo* previous_iteration = nullptr; |
| 328 | while (!remaining.empty()) { |
| 329 | std::string class_loader_spec; |
| 330 | size_t first_class_loader_separator = remaining.find_first_of(kClassLoaderSeparator); |
| 331 | size_t first_shared_library_open = |
| 332 | remaining.find_first_of(kClassLoaderSharedLibraryOpeningMark); |
| 333 | if (first_class_loader_separator == std::string::npos) { |
| 334 | // Only one class loader, for example: |
| 335 | // PCL[...] |
| 336 | class_loader_spec = remaining; |
| 337 | remaining = ""; |
| 338 | } else if ((first_shared_library_open == std::string::npos) || |
| 339 | (first_shared_library_open > first_class_loader_separator)) { |
| 340 | // We found a class loader spec without shared libraries, for example: |
| 341 | // PCL[...];PCL[...]{...} |
| 342 | class_loader_spec = remaining.substr(0, first_class_loader_separator); |
| 343 | remaining = remaining.substr(first_class_loader_separator + 1, |
| 344 | remaining.size() - first_class_loader_separator - 1); |
| 345 | } else { |
| 346 | // The class loader spec contains shared libraries. Find the matching closing |
| 347 | // shared library marker for it. |
| 348 | |
Nicolas Geoffray | f378fff | 2018-11-19 12:52:26 +0000 | [diff] [blame] | 349 | uint32_t shared_library_close = |
| 350 | FindMatchingSharedLibraryCloseMarker(remaining, first_shared_library_open); |
| 351 | if (shared_library_close == std::string::npos) { |
| 352 | LOG(ERROR) << "Invalid class loader spec: " << class_loader_spec; |
| 353 | return nullptr; |
| 354 | } |
| 355 | class_loader_spec = remaining.substr(0, shared_library_close + 1); |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 356 | |
Nicolas Geoffray | f378fff | 2018-11-19 12:52:26 +0000 | [diff] [blame] | 357 | // Compute the remaining string to analyze. |
| 358 | if (remaining.size() == shared_library_close + 1) { |
| 359 | remaining = ""; |
| 360 | } else if ((remaining.size() == shared_library_close + 2) || |
| 361 | (remaining.at(shared_library_close + 1) != kClassLoaderSeparator)) { |
| 362 | LOG(ERROR) << "Invalid class loader spec: " << class_loader_spec; |
| 363 | return nullptr; |
| 364 | } else { |
| 365 | remaining = remaining.substr(shared_library_close + 2, |
| 366 | remaining.size() - shared_library_close - 2); |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 367 | } |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 368 | } |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 369 | |
| 370 | std::unique_ptr<ClassLoaderInfo> info = |
| 371 | ParseClassLoaderSpec(class_loader_spec, parse_checksums); |
| 372 | if (info == nullptr) { |
| 373 | LOG(ERROR) << "Invalid class loader spec: " << class_loader_spec; |
| 374 | return nullptr; |
| 375 | } |
| 376 | if (first == nullptr) { |
Andreas Gampe | 41c911f | 2018-11-19 11:34:16 -0800 | [diff] [blame] | 377 | first = std::move(info); |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 378 | previous_iteration = first.get(); |
| 379 | } else { |
| 380 | CHECK(previous_iteration != nullptr); |
Andreas Gampe | 41c911f | 2018-11-19 11:34:16 -0800 | [diff] [blame] | 381 | previous_iteration->parent = std::move(info); |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 382 | previous_iteration = previous_iteration->parent.get(); |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 383 | } |
| 384 | } |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 385 | return first.release(); |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | // Opens requested class path files and appends them to opened_dex_files. If the dex files have |
| 389 | // been stripped, this opens them from their oat files (which get added to opened_oat_files). |
David Brazdil | 8982186 | 2019-03-19 13:57:43 +0000 | [diff] [blame] | 390 | bool ClassLoaderContext::OpenDexFiles(InstructionSet isa, |
| 391 | const std::string& classpath_dir, |
| 392 | const std::vector<int>& fds) { |
Calin Juravle | c5b215f | 2017-09-12 14:49:37 -0700 | [diff] [blame] | 393 | if (dex_files_open_attempted_) { |
| 394 | // Do not attempt to re-open the files if we already tried. |
| 395 | return dex_files_open_result_; |
| 396 | } |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 397 | |
| 398 | dex_files_open_attempted_ = true; |
| 399 | // Assume we can open all dex files. If not, we will set this to false as we go. |
| 400 | dex_files_open_result_ = true; |
| 401 | |
| 402 | if (special_shared_library_) { |
| 403 | // Nothing to open if the context is a special shared library. |
| 404 | return true; |
| 405 | } |
| 406 | |
| 407 | // Note that we try to open all dex files even if some fail. |
| 408 | // We may get resource-only apks which we cannot load. |
| 409 | // TODO(calin): Refine the dex opening interface to be able to tell if an archive contains |
| 410 | // no dex files. So that we can distinguish the real failures... |
David Sehr | 013fd80 | 2018-01-11 22:55:24 -0800 | [diff] [blame] | 411 | const ArtDexFileLoader dex_file_loader; |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 412 | std::vector<ClassLoaderInfo*> work_list; |
Nicolas Geoffray | 9893c47 | 2018-11-13 15:39:53 +0000 | [diff] [blame] | 413 | CHECK(class_loader_chain_ != nullptr); |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 414 | work_list.push_back(class_loader_chain_.get()); |
David Brazdil | 8982186 | 2019-03-19 13:57:43 +0000 | [diff] [blame] | 415 | size_t dex_file_index = 0; |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 416 | while (!work_list.empty()) { |
| 417 | ClassLoaderInfo* info = work_list.back(); |
| 418 | work_list.pop_back(); |
| 419 | size_t opened_dex_files_index = info->opened_dex_files.size(); |
| 420 | for (const std::string& cp_elem : info->classpath) { |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 421 | // If path is relative, append it to the provided base directory. |
Calin Juravle | 92003fe | 2017-09-06 02:22:57 +0000 | [diff] [blame] | 422 | std::string location = cp_elem; |
| 423 | if (location[0] != '/' && !classpath_dir.empty()) { |
Nicolas Geoffray | 06ffecf | 2017-11-14 10:31:54 +0000 | [diff] [blame] | 424 | location = classpath_dir + (classpath_dir.back() == '/' ? "" : "/") + location; |
Calin Juravle | 821a259 | 2017-08-11 14:33:38 -0700 | [diff] [blame] | 425 | } |
| 426 | |
David Brazdil | 8982186 | 2019-03-19 13:57:43 +0000 | [diff] [blame] | 427 | // If file descriptors were provided for the class loader context dex paths, |
| 428 | // get the descriptor which correponds to this dex path. We assume the `fds` |
| 429 | // vector follows the same order as a flattened class loader context. |
| 430 | int fd = -1; |
| 431 | if (!fds.empty()) { |
| 432 | if (dex_file_index >= fds.size()) { |
| 433 | LOG(WARNING) << "Number of FDs is smaller than number of dex files in the context"; |
| 434 | dex_files_open_result_ = false; |
| 435 | return false; |
| 436 | } |
| 437 | |
| 438 | fd = fds[dex_file_index++]; |
| 439 | DCHECK_GE(fd, 0); |
| 440 | } |
| 441 | |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 442 | std::string error_msg; |
| 443 | // When opening the dex files from the context we expect their checksum to match their |
| 444 | // contents. So pass true to verify_checksum. |
David Brazdil | 8982186 | 2019-03-19 13:57:43 +0000 | [diff] [blame] | 445 | if (fd < 0) { |
| 446 | if (!dex_file_loader.Open(location.c_str(), |
| 447 | location.c_str(), |
| 448 | Runtime::Current()->IsVerificationEnabled(), |
| 449 | /*verify_checksum=*/ true, |
| 450 | &error_msg, |
| 451 | &info->opened_dex_files)) { |
| 452 | // If we fail to open the dex file because it's been stripped, try to |
| 453 | // open the dex file from its corresponding oat file. |
| 454 | // This could happen when we need to recompile a pre-build whose dex |
| 455 | // code has been stripped (for example, if the pre-build is only |
| 456 | // quicken and we want to re-compile it speed-profile). |
| 457 | // TODO(calin): Use the vdex directly instead of going through the oat file. |
| 458 | OatFileAssistant oat_file_assistant(location.c_str(), isa, false); |
| 459 | std::unique_ptr<OatFile> oat_file(oat_file_assistant.GetBestOatFile()); |
| 460 | std::vector<std::unique_ptr<const DexFile>> oat_dex_files; |
| 461 | if (oat_file != nullptr && |
| 462 | OatFileAssistant::LoadDexFiles(*oat_file, location, &oat_dex_files)) { |
| 463 | info->opened_oat_files.push_back(std::move(oat_file)); |
| 464 | info->opened_dex_files.insert(info->opened_dex_files.end(), |
| 465 | std::make_move_iterator(oat_dex_files.begin()), |
| 466 | std::make_move_iterator(oat_dex_files.end())); |
| 467 | } else { |
| 468 | LOG(WARNING) << "Could not open dex files from location: " << location; |
| 469 | dex_files_open_result_ = false; |
| 470 | } |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 471 | } |
David Brazdil | 8982186 | 2019-03-19 13:57:43 +0000 | [diff] [blame] | 472 | } else if (!dex_file_loader.Open(fd, |
| 473 | location.c_str(), |
| 474 | Runtime::Current()->IsVerificationEnabled(), |
| 475 | /*verify_checksum=*/ true, |
| 476 | &error_msg, |
| 477 | &info->opened_dex_files)) { |
| 478 | LOG(WARNING) << "Could not open dex files from fd " << fd << " for location: " << location; |
| 479 | dex_files_open_result_ = false; |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 480 | } |
| 481 | } |
Calin Juravle | c5b215f | 2017-09-12 14:49:37 -0700 | [diff] [blame] | 482 | |
| 483 | // We finished opening the dex files from the classpath. |
| 484 | // Now update the classpath and the checksum with the locations of the dex files. |
| 485 | // |
| 486 | // We do this because initially the classpath contains the paths of the dex files; and |
| 487 | // some of them might be multi-dexes. So in order to have a consistent view we replace all the |
| 488 | // file paths with the actual dex locations being loaded. |
| 489 | // This will allow the context to VerifyClassLoaderContextMatch which expects or multidex |
| 490 | // location in the class paths. |
| 491 | // Note that this will also remove the paths that could not be opened. |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 492 | info->original_classpath = std::move(info->classpath); |
| 493 | info->classpath.clear(); |
| 494 | info->checksums.clear(); |
| 495 | for (size_t k = opened_dex_files_index; k < info->opened_dex_files.size(); k++) { |
| 496 | std::unique_ptr<const DexFile>& dex = info->opened_dex_files[k]; |
| 497 | info->classpath.push_back(dex->GetLocation()); |
| 498 | info->checksums.push_back(dex->GetLocationChecksum()); |
Calin Juravle | c5b215f | 2017-09-12 14:49:37 -0700 | [diff] [blame] | 499 | } |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 500 | AddToWorkList(info, work_list); |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 501 | } |
| 502 | |
David Brazdil | 8982186 | 2019-03-19 13:57:43 +0000 | [diff] [blame] | 503 | // Check that if file descriptors were provided, there were exactly as many |
| 504 | // as we have encountered while iterating over this class loader context. |
| 505 | if (dex_file_index != fds.size()) { |
| 506 | LOG(WARNING) << fds.size() << " FDs provided but only " << dex_file_index |
| 507 | << " dex files are in the class loader context"; |
| 508 | dex_files_open_result_ = false; |
| 509 | } |
| 510 | |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 511 | return dex_files_open_result_; |
| 512 | } |
| 513 | |
| 514 | bool ClassLoaderContext::RemoveLocationsFromClassPaths( |
| 515 | const dchecked_vector<std::string>& locations) { |
| 516 | CHECK(!dex_files_open_attempted_) |
| 517 | << "RemoveLocationsFromClasspaths cannot be call after OpenDexFiles"; |
| 518 | |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 519 | if (class_loader_chain_ == nullptr) { |
| 520 | return false; |
| 521 | } |
| 522 | |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 523 | std::set<std::string> canonical_locations; |
| 524 | for (const std::string& location : locations) { |
Mathieu Chartier | 79c87da | 2017-10-10 11:54:29 -0700 | [diff] [blame] | 525 | canonical_locations.insert(DexFileLoader::GetDexCanonicalLocation(location.c_str())); |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 526 | } |
| 527 | bool removed_locations = false; |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 528 | std::vector<ClassLoaderInfo*> work_list; |
| 529 | work_list.push_back(class_loader_chain_.get()); |
| 530 | while (!work_list.empty()) { |
| 531 | ClassLoaderInfo* info = work_list.back(); |
| 532 | work_list.pop_back(); |
| 533 | size_t initial_size = info->classpath.size(); |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 534 | auto kept_it = std::remove_if( |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 535 | info->classpath.begin(), |
| 536 | info->classpath.end(), |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 537 | [canonical_locations](const std::string& location) { |
| 538 | return ContainsElement(canonical_locations, |
Mathieu Chartier | 79c87da | 2017-10-10 11:54:29 -0700 | [diff] [blame] | 539 | DexFileLoader::GetDexCanonicalLocation(location.c_str())); |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 540 | }); |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 541 | info->classpath.erase(kept_it, info->classpath.end()); |
| 542 | if (initial_size != info->classpath.size()) { |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 543 | removed_locations = true; |
| 544 | } |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 545 | AddToWorkList(info, work_list); |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 546 | } |
| 547 | return removed_locations; |
| 548 | } |
| 549 | |
Calin Juravle | 27e0d1f | 2017-07-26 00:16:07 -0700 | [diff] [blame] | 550 | std::string ClassLoaderContext::EncodeContextForDex2oat(const std::string& base_dir) const { |
Andreas Gampe | 98ea9d9 | 2018-10-19 14:06:15 -0700 | [diff] [blame] | 551 | return EncodeContext(base_dir, /*for_dex2oat=*/ true, /*stored_context=*/ nullptr); |
Calin Juravle | 27e0d1f | 2017-07-26 00:16:07 -0700 | [diff] [blame] | 552 | } |
| 553 | |
Mathieu Chartier | c444077 | 2018-04-16 14:40:56 -0700 | [diff] [blame] | 554 | std::string ClassLoaderContext::EncodeContextForOatFile(const std::string& base_dir, |
| 555 | ClassLoaderContext* stored_context) const { |
Andreas Gampe | 98ea9d9 | 2018-10-19 14:06:15 -0700 | [diff] [blame] | 556 | return EncodeContext(base_dir, /*for_dex2oat=*/ false, stored_context); |
Calin Juravle | 27e0d1f | 2017-07-26 00:16:07 -0700 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | std::string ClassLoaderContext::EncodeContext(const std::string& base_dir, |
Mathieu Chartier | c444077 | 2018-04-16 14:40:56 -0700 | [diff] [blame] | 560 | bool for_dex2oat, |
| 561 | ClassLoaderContext* stored_context) const { |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 562 | CheckDexFilesOpened("EncodeContextForOatFile"); |
| 563 | if (special_shared_library_) { |
| 564 | return OatFile::kSpecialSharedLibrary; |
| 565 | } |
| 566 | |
Mathieu Chartier | c444077 | 2018-04-16 14:40:56 -0700 | [diff] [blame] | 567 | if (stored_context != nullptr) { |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 568 | DCHECK_EQ(GetParentChainSize(), stored_context->GetParentChainSize()); |
Mathieu Chartier | c444077 | 2018-04-16 14:40:56 -0700 | [diff] [blame] | 569 | } |
| 570 | |
Calin Juravle | 7b0648a | 2017-07-07 18:40:50 -0700 | [diff] [blame] | 571 | std::ostringstream out; |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 572 | if (class_loader_chain_ == nullptr) { |
Calin Juravle | 1a509c8 | 2017-07-24 16:51:21 -0700 | [diff] [blame] | 573 | // We can get in this situation if the context was created with a class path containing the |
| 574 | // source dex files which were later removed (happens during run-tests). |
| 575 | out << GetClassLoaderTypeName(kPathClassLoader) |
| 576 | << kClassLoaderOpeningMark |
| 577 | << kClassLoaderClosingMark; |
| 578 | return out.str(); |
| 579 | } |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 580 | |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 581 | EncodeContextInternal( |
| 582 | *class_loader_chain_, |
| 583 | base_dir, |
| 584 | for_dex2oat, |
| 585 | (stored_context == nullptr ? nullptr : stored_context->class_loader_chain_.get()), |
| 586 | out); |
Calin Juravle | 7b0648a | 2017-07-07 18:40:50 -0700 | [diff] [blame] | 587 | return out.str(); |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 588 | } |
| 589 | |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 590 | void ClassLoaderContext::EncodeContextInternal(const ClassLoaderInfo& info, |
| 591 | const std::string& base_dir, |
| 592 | bool for_dex2oat, |
| 593 | ClassLoaderInfo* stored_info, |
| 594 | std::ostringstream& out) const { |
| 595 | out << GetClassLoaderTypeName(info.type); |
| 596 | out << kClassLoaderOpeningMark; |
| 597 | std::set<std::string> seen_locations; |
| 598 | SafeMap<std::string, std::string> remap; |
| 599 | if (stored_info != nullptr) { |
| 600 | for (size_t k = 0; k < info.original_classpath.size(); ++k) { |
| 601 | // Note that we don't care if the same name appears twice. |
| 602 | remap.Put(info.original_classpath[k], stored_info->classpath[k]); |
| 603 | } |
| 604 | } |
| 605 | for (size_t k = 0; k < info.opened_dex_files.size(); k++) { |
| 606 | const std::unique_ptr<const DexFile>& dex_file = info.opened_dex_files[k]; |
| 607 | if (for_dex2oat) { |
| 608 | // dex2oat only needs the base location. It cannot accept multidex locations. |
| 609 | // So ensure we only add each file once. |
| 610 | bool new_insert = seen_locations.insert( |
| 611 | DexFileLoader::GetBaseLocation(dex_file->GetLocation())).second; |
| 612 | if (!new_insert) { |
| 613 | continue; |
| 614 | } |
| 615 | } |
| 616 | std::string location = dex_file->GetLocation(); |
| 617 | // If there is a stored class loader remap, fix up the multidex strings. |
| 618 | if (!remap.empty()) { |
| 619 | std::string base_dex_location = DexFileLoader::GetBaseLocation(location); |
| 620 | auto it = remap.find(base_dex_location); |
| 621 | CHECK(it != remap.end()) << base_dex_location; |
| 622 | location = it->second + DexFileLoader::GetMultiDexSuffix(location); |
| 623 | } |
| 624 | if (k > 0) { |
| 625 | out << kClasspathSeparator; |
| 626 | } |
Nicolas Geoffray | 93d99f3 | 2019-03-27 08:56:02 +0000 | [diff] [blame] | 627 | // Find paths that were relative and convert them back from absolute. |
| 628 | if (!base_dir.empty() && location.substr(0, base_dir.length()) == base_dir) { |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 629 | out << location.substr(base_dir.length() + 1).c_str(); |
| 630 | } else { |
| 631 | out << location.c_str(); |
| 632 | } |
| 633 | // dex2oat does not need the checksums. |
| 634 | if (!for_dex2oat) { |
| 635 | out << kDexFileChecksumSeparator; |
| 636 | out << dex_file->GetLocationChecksum(); |
| 637 | } |
| 638 | } |
| 639 | out << kClassLoaderClosingMark; |
| 640 | |
| 641 | if (!info.shared_libraries.empty()) { |
| 642 | out << kClassLoaderSharedLibraryOpeningMark; |
| 643 | for (uint32_t i = 0; i < info.shared_libraries.size(); ++i) { |
| 644 | if (i > 0) { |
| 645 | out << kClassLoaderSharedLibrarySeparator; |
| 646 | } |
| 647 | EncodeContextInternal( |
| 648 | *info.shared_libraries[i].get(), |
| 649 | base_dir, |
| 650 | for_dex2oat, |
| 651 | (stored_info == nullptr ? nullptr : stored_info->shared_libraries[i].get()), |
| 652 | out); |
| 653 | } |
| 654 | out << kClassLoaderSharedLibraryClosingMark; |
| 655 | } |
| 656 | if (info.parent != nullptr) { |
| 657 | out << kClassLoaderSeparator; |
| 658 | EncodeContextInternal( |
| 659 | *info.parent.get(), |
| 660 | base_dir, |
| 661 | for_dex2oat, |
| 662 | (stored_info == nullptr ? nullptr : stored_info->parent.get()), |
| 663 | out); |
| 664 | } |
| 665 | } |
| 666 | |
| 667 | // Returns the WellKnownClass for the given class loader type. |
| 668 | static jclass GetClassLoaderClass(ClassLoaderContext::ClassLoaderType type) { |
| 669 | switch (type) { |
| 670 | case ClassLoaderContext::kPathClassLoader: |
| 671 | return WellKnownClasses::dalvik_system_PathClassLoader; |
| 672 | case ClassLoaderContext::kDelegateLastClassLoader: |
| 673 | return WellKnownClasses::dalvik_system_DelegateLastClassLoader; |
David Brazdil | 1a9ac53 | 2019-03-05 11:57:13 +0000 | [diff] [blame] | 674 | case ClassLoaderContext::kInMemoryDexClassLoader: |
| 675 | return WellKnownClasses::dalvik_system_InMemoryDexClassLoader; |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 676 | case ClassLoaderContext::kInvalidClassLoader: break; // will fail after the switch. |
| 677 | } |
| 678 | LOG(FATAL) << "Invalid class loader type " << type; |
| 679 | UNREACHABLE(); |
| 680 | } |
| 681 | |
Nicolas Geoffray | cb2e1dd | 2018-11-20 11:15:13 +0000 | [diff] [blame] | 682 | static std::string FlattenClasspath(const std::vector<std::string>& classpath) { |
| 683 | return android::base::Join(classpath, ':'); |
| 684 | } |
| 685 | |
Nicolas Geoffray | 6b9fd8c | 2018-11-16 10:25:42 +0000 | [diff] [blame] | 686 | static ObjPtr<mirror::ClassLoader> CreateClassLoaderInternal( |
| 687 | Thread* self, |
| 688 | ScopedObjectAccess& soa, |
| 689 | const ClassLoaderContext::ClassLoaderInfo& info, |
Nicolas Geoffray | cb2e1dd | 2018-11-20 11:15:13 +0000 | [diff] [blame] | 690 | bool for_shared_library, |
| 691 | VariableSizedHandleScope& map_scope, |
| 692 | std::map<std::string, Handle<mirror::ClassLoader>>& canonicalized_libraries, |
Nicolas Geoffray | 6b9fd8c | 2018-11-16 10:25:42 +0000 | [diff] [blame] | 693 | bool add_compilation_sources, |
| 694 | const std::vector<const DexFile*>& compilation_sources) |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 695 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Nicolas Geoffray | cb2e1dd | 2018-11-20 11:15:13 +0000 | [diff] [blame] | 696 | if (for_shared_library) { |
| 697 | // Check if the shared library has already been created. |
| 698 | auto search = canonicalized_libraries.find(FlattenClasspath(info.classpath)); |
| 699 | if (search != canonicalized_libraries.end()) { |
| 700 | return search->second.Get(); |
| 701 | } |
| 702 | } |
| 703 | |
Nicolas Geoffray | 6b9fd8c | 2018-11-16 10:25:42 +0000 | [diff] [blame] | 704 | StackHandleScope<3> hs(self); |
| 705 | MutableHandle<mirror::ObjectArray<mirror::ClassLoader>> libraries( |
| 706 | hs.NewHandle<mirror::ObjectArray<mirror::ClassLoader>>(nullptr)); |
| 707 | |
| 708 | if (!info.shared_libraries.empty()) { |
| 709 | libraries.Assign(mirror::ObjectArray<mirror::ClassLoader>::Alloc( |
| 710 | self, |
| 711 | GetClassRoot<mirror::ObjectArray<mirror::ClassLoader>>(), |
| 712 | info.shared_libraries.size())); |
| 713 | for (uint32_t i = 0; i < info.shared_libraries.size(); ++i) { |
| 714 | // We should only add the compilation sources to the first class loader. |
| 715 | libraries->Set(i, |
| 716 | CreateClassLoaderInternal( |
| 717 | self, |
| 718 | soa, |
| 719 | *info.shared_libraries[i].get(), |
Nicolas Geoffray | cb2e1dd | 2018-11-20 11:15:13 +0000 | [diff] [blame] | 720 | /* for_shared_library= */ true, |
| 721 | map_scope, |
| 722 | canonicalized_libraries, |
Nicolas Geoffray | 6b9fd8c | 2018-11-16 10:25:42 +0000 | [diff] [blame] | 723 | /* add_compilation_sources= */ false, |
| 724 | compilation_sources)); |
| 725 | } |
| 726 | } |
| 727 | |
| 728 | MutableHandle<mirror::ClassLoader> parent = hs.NewHandle<mirror::ClassLoader>(nullptr); |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 729 | if (info.parent != nullptr) { |
Nicolas Geoffray | 6b9fd8c | 2018-11-16 10:25:42 +0000 | [diff] [blame] | 730 | // We should only add the compilation sources to the first class loader. |
| 731 | parent.Assign(CreateClassLoaderInternal( |
Nicolas Geoffray | cb2e1dd | 2018-11-20 11:15:13 +0000 | [diff] [blame] | 732 | self, |
| 733 | soa, |
| 734 | *info.parent.get(), |
| 735 | /* for_shared_library= */ false, |
| 736 | map_scope, |
| 737 | canonicalized_libraries, |
| 738 | /* add_compilation_sources= */ false, |
| 739 | compilation_sources)); |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 740 | } |
| 741 | std::vector<const DexFile*> class_path_files = MakeNonOwningPointerVector( |
| 742 | info.opened_dex_files); |
Nicolas Geoffray | 6b9fd8c | 2018-11-16 10:25:42 +0000 | [diff] [blame] | 743 | if (add_compilation_sources) { |
| 744 | // For the first class loader, its classpath comes first, followed by compilation sources. |
| 745 | // This ensures that whenever we need to resolve classes from it the classpath elements |
| 746 | // come first. |
| 747 | class_path_files.insert(class_path_files.end(), |
| 748 | compilation_sources.begin(), |
| 749 | compilation_sources.end()); |
| 750 | } |
| 751 | Handle<mirror::Class> loader_class = hs.NewHandle<mirror::Class>( |
| 752 | soa.Decode<mirror::Class>(GetClassLoaderClass(info.type))); |
Nicolas Geoffray | cb2e1dd | 2018-11-20 11:15:13 +0000 | [diff] [blame] | 753 | ObjPtr<mirror::ClassLoader> loader = |
| 754 | Runtime::Current()->GetClassLinker()->CreateWellKnownClassLoader( |
| 755 | self, |
| 756 | class_path_files, |
| 757 | loader_class, |
Nicolas Geoffray | e167273 | 2018-11-30 01:09:49 +0000 | [diff] [blame] | 758 | parent, |
| 759 | libraries); |
Nicolas Geoffray | cb2e1dd | 2018-11-20 11:15:13 +0000 | [diff] [blame] | 760 | if (for_shared_library) { |
| 761 | canonicalized_libraries[FlattenClasspath(info.classpath)] = |
| 762 | map_scope.NewHandle<mirror::ClassLoader>(loader); |
| 763 | } |
| 764 | return loader; |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 765 | } |
| 766 | |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 767 | jobject ClassLoaderContext::CreateClassLoader( |
| 768 | const std::vector<const DexFile*>& compilation_sources) const { |
| 769 | CheckDexFilesOpened("CreateClassLoader"); |
| 770 | |
| 771 | Thread* self = Thread::Current(); |
| 772 | ScopedObjectAccess soa(self); |
| 773 | |
Calin Juravle | c79470d | 2017-07-12 17:37:42 -0700 | [diff] [blame] | 774 | ClassLinker* const class_linker = Runtime::Current()->GetClassLinker(); |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 775 | |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 776 | if (class_loader_chain_ == nullptr) { |
Nicolas Geoffray | 6b9fd8c | 2018-11-16 10:25:42 +0000 | [diff] [blame] | 777 | CHECK(special_shared_library_); |
Calin Juravle | c79470d | 2017-07-12 17:37:42 -0700 | [diff] [blame] | 778 | return class_linker->CreatePathClassLoader(self, compilation_sources); |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 779 | } |
| 780 | |
Nicolas Geoffray | cb2e1dd | 2018-11-20 11:15:13 +0000 | [diff] [blame] | 781 | // Create a map of canonicalized shared libraries. As we're holding objects, |
| 782 | // we're creating a variable size handle scope to put handles in the map. |
| 783 | VariableSizedHandleScope map_scope(self); |
| 784 | std::map<std::string, Handle<mirror::ClassLoader>> canonicalized_libraries; |
| 785 | |
| 786 | // Create the class loader. |
Nicolas Geoffray | 6b9fd8c | 2018-11-16 10:25:42 +0000 | [diff] [blame] | 787 | ObjPtr<mirror::ClassLoader> loader = |
| 788 | CreateClassLoaderInternal(self, |
| 789 | soa, |
| 790 | *class_loader_chain_.get(), |
Nicolas Geoffray | cb2e1dd | 2018-11-20 11:15:13 +0000 | [diff] [blame] | 791 | /* for_shared_library= */ false, |
| 792 | map_scope, |
| 793 | canonicalized_libraries, |
Nicolas Geoffray | 6b9fd8c | 2018-11-16 10:25:42 +0000 | [diff] [blame] | 794 | /* add_compilation_sources= */ true, |
| 795 | compilation_sources); |
| 796 | // Make it a global ref and return. |
| 797 | ScopedLocalRef<jobject> local_ref( |
| 798 | soa.Env(), soa.Env()->AddLocalReference<jobject>(loader)); |
| 799 | return soa.Env()->NewGlobalRef(local_ref.get()); |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 800 | } |
| 801 | |
| 802 | std::vector<const DexFile*> ClassLoaderContext::FlattenOpenedDexFiles() const { |
| 803 | CheckDexFilesOpened("FlattenOpenedDexFiles"); |
| 804 | |
| 805 | std::vector<const DexFile*> result; |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 806 | if (class_loader_chain_ == nullptr) { |
| 807 | return result; |
| 808 | } |
| 809 | std::vector<ClassLoaderInfo*> work_list; |
| 810 | work_list.push_back(class_loader_chain_.get()); |
| 811 | while (!work_list.empty()) { |
| 812 | ClassLoaderInfo* info = work_list.back(); |
| 813 | work_list.pop_back(); |
| 814 | for (const std::unique_ptr<const DexFile>& dex_file : info->opened_dex_files) { |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 815 | result.push_back(dex_file.get()); |
| 816 | } |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 817 | AddToWorkList(info, work_list); |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 818 | } |
| 819 | return result; |
| 820 | } |
| 821 | |
David Brazdil | 8982186 | 2019-03-19 13:57:43 +0000 | [diff] [blame] | 822 | std::string ClassLoaderContext::FlattenDexPaths() const { |
| 823 | if (class_loader_chain_ == nullptr) { |
| 824 | return ""; |
| 825 | } |
| 826 | |
| 827 | std::vector<std::string> result; |
| 828 | std::vector<ClassLoaderInfo*> work_list; |
| 829 | work_list.push_back(class_loader_chain_.get()); |
| 830 | while (!work_list.empty()) { |
| 831 | ClassLoaderInfo* info = work_list.back(); |
| 832 | work_list.pop_back(); |
| 833 | for (const std::string& dex_path : info->classpath) { |
| 834 | result.push_back(dex_path); |
| 835 | } |
| 836 | AddToWorkList(info, work_list); |
| 837 | } |
| 838 | return FlattenClasspath(result); |
| 839 | } |
| 840 | |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 841 | const char* ClassLoaderContext::GetClassLoaderTypeName(ClassLoaderType type) { |
| 842 | switch (type) { |
| 843 | case kPathClassLoader: return kPathClassLoaderString; |
| 844 | case kDelegateLastClassLoader: return kDelegateLastClassLoaderString; |
David Brazdil | 1a9ac53 | 2019-03-05 11:57:13 +0000 | [diff] [blame] | 845 | case kInMemoryDexClassLoader: return kInMemoryDexClassLoaderString; |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 846 | default: |
| 847 | LOG(FATAL) << "Invalid class loader type " << type; |
| 848 | UNREACHABLE(); |
| 849 | } |
| 850 | } |
| 851 | |
| 852 | void ClassLoaderContext::CheckDexFilesOpened(const std::string& calling_method) const { |
| 853 | CHECK(dex_files_open_attempted_) |
| 854 | << "Dex files were not successfully opened before the call to " << calling_method |
| 855 | << "attempt=" << dex_files_open_attempted_ << ", result=" << dex_files_open_result_; |
| 856 | } |
Calin Juravle | 7b0648a | 2017-07-07 18:40:50 -0700 | [diff] [blame] | 857 | |
Calin Juravle | 57d0acc | 2017-07-11 17:41:30 -0700 | [diff] [blame] | 858 | // Collects the dex files from the give Java dex_file object. Only the dex files with |
| 859 | // at least 1 class are collected. If a null java_dex_file is passed this method does nothing. |
| 860 | static bool CollectDexFilesFromJavaDexFile(ObjPtr<mirror::Object> java_dex_file, |
| 861 | ArtField* const cookie_field, |
| 862 | std::vector<const DexFile*>* out_dex_files) |
| 863 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 864 | if (java_dex_file == nullptr) { |
| 865 | return true; |
| 866 | } |
| 867 | // On the Java side, the dex files are stored in the cookie field. |
| 868 | mirror::LongArray* long_array = cookie_field->GetObject(java_dex_file)->AsLongArray(); |
| 869 | if (long_array == nullptr) { |
| 870 | // This should never happen so log a warning. |
| 871 | LOG(ERROR) << "Unexpected null cookie"; |
| 872 | return false; |
| 873 | } |
| 874 | int32_t long_array_size = long_array->GetLength(); |
| 875 | // Index 0 from the long array stores the oat file. The dex files start at index 1. |
| 876 | for (int32_t j = 1; j < long_array_size; ++j) { |
Vladimir Marko | 78baed5 | 2018-10-11 10:44:58 +0100 | [diff] [blame] | 877 | const DexFile* cp_dex_file = |
| 878 | reinterpret_cast64<const DexFile*>(long_array->GetWithoutChecks(j)); |
Calin Juravle | 57d0acc | 2017-07-11 17:41:30 -0700 | [diff] [blame] | 879 | if (cp_dex_file != nullptr && cp_dex_file->NumClassDefs() > 0) { |
| 880 | // TODO(calin): It's unclear why the dex files with no classes are skipped here and when |
| 881 | // cp_dex_file can be null. |
| 882 | out_dex_files->push_back(cp_dex_file); |
| 883 | } |
| 884 | } |
| 885 | return true; |
| 886 | } |
| 887 | |
| 888 | // Collects all the dex files loaded by the given class loader. |
| 889 | // Returns true for success or false if an unexpected state is discovered (e.g. a null dex cookie, |
| 890 | // a null list of dex elements or a null dex element). |
| 891 | static bool CollectDexFilesFromSupportedClassLoader(ScopedObjectAccessAlreadyRunnable& soa, |
| 892 | Handle<mirror::ClassLoader> class_loader, |
| 893 | std::vector<const DexFile*>* out_dex_files) |
| 894 | REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 1a9ac53 | 2019-03-05 11:57:13 +0000 | [diff] [blame] | 895 | CHECK(IsPathOrDexClassLoader(soa, class_loader) || |
| 896 | IsDelegateLastClassLoader(soa, class_loader) || |
| 897 | IsInMemoryDexClassLoader(soa, class_loader)); |
Calin Juravle | 57d0acc | 2017-07-11 17:41:30 -0700 | [diff] [blame] | 898 | |
| 899 | // All supported class loaders inherit from BaseDexClassLoader. |
| 900 | // We need to get the DexPathList and loop through it. |
| 901 | ArtField* const cookie_field = |
| 902 | jni::DecodeArtField(WellKnownClasses::dalvik_system_DexFile_cookie); |
| 903 | ArtField* const dex_file_field = |
| 904 | jni::DecodeArtField(WellKnownClasses::dalvik_system_DexPathList__Element_dexFile); |
| 905 | ObjPtr<mirror::Object> dex_path_list = |
| 906 | jni::DecodeArtField(WellKnownClasses::dalvik_system_BaseDexClassLoader_pathList)-> |
| 907 | GetObject(class_loader.Get()); |
| 908 | CHECK(cookie_field != nullptr); |
| 909 | CHECK(dex_file_field != nullptr); |
| 910 | if (dex_path_list == nullptr) { |
| 911 | // This may be null if the current class loader is under construction and it does not |
| 912 | // have its fields setup yet. |
| 913 | return true; |
| 914 | } |
| 915 | // DexPathList has an array dexElements of Elements[] which each contain a dex file. |
| 916 | ObjPtr<mirror::Object> dex_elements_obj = |
| 917 | jni::DecodeArtField(WellKnownClasses::dalvik_system_DexPathList_dexElements)-> |
| 918 | GetObject(dex_path_list); |
| 919 | // Loop through each dalvik.system.DexPathList$Element's dalvik.system.DexFile and look |
| 920 | // at the mCookie which is a DexFile vector. |
| 921 | if (dex_elements_obj == nullptr) { |
| 922 | // TODO(calin): It's unclear if we should just assert here. For now be prepared for the worse |
| 923 | // and assume we have no elements. |
| 924 | return true; |
| 925 | } else { |
| 926 | StackHandleScope<1> hs(soa.Self()); |
| 927 | Handle<mirror::ObjectArray<mirror::Object>> dex_elements( |
| 928 | hs.NewHandle(dex_elements_obj->AsObjectArray<mirror::Object>())); |
| 929 | for (int32_t i = 0; i < dex_elements->GetLength(); ++i) { |
Vladimir Marko | 423bebb | 2019-03-26 15:17:21 +0000 | [diff] [blame] | 930 | ObjPtr<mirror::Object> element = dex_elements->GetWithoutChecks(i); |
Calin Juravle | 57d0acc | 2017-07-11 17:41:30 -0700 | [diff] [blame] | 931 | if (element == nullptr) { |
| 932 | // Should never happen, log an error and break. |
| 933 | // TODO(calin): It's unclear if we should just assert here. |
| 934 | // This code was propagated to oat_file_manager from the class linker where it would |
| 935 | // throw a NPE. For now, return false which will mark this class loader as unsupported. |
| 936 | LOG(ERROR) << "Unexpected null in the dex element list"; |
| 937 | return false; |
| 938 | } |
| 939 | ObjPtr<mirror::Object> dex_file = dex_file_field->GetObject(element); |
| 940 | if (!CollectDexFilesFromJavaDexFile(dex_file, cookie_field, out_dex_files)) { |
| 941 | return false; |
| 942 | } |
| 943 | } |
| 944 | } |
| 945 | |
| 946 | return true; |
| 947 | } |
| 948 | |
| 949 | static bool GetDexFilesFromDexElementsArray( |
| 950 | ScopedObjectAccessAlreadyRunnable& soa, |
| 951 | Handle<mirror::ObjectArray<mirror::Object>> dex_elements, |
| 952 | std::vector<const DexFile*>* out_dex_files) REQUIRES_SHARED(Locks::mutator_lock_) { |
| 953 | DCHECK(dex_elements != nullptr); |
| 954 | |
| 955 | ArtField* const cookie_field = |
| 956 | jni::DecodeArtField(WellKnownClasses::dalvik_system_DexFile_cookie); |
| 957 | ArtField* const dex_file_field = |
| 958 | jni::DecodeArtField(WellKnownClasses::dalvik_system_DexPathList__Element_dexFile); |
| 959 | ObjPtr<mirror::Class> const element_class = soa.Decode<mirror::Class>( |
| 960 | WellKnownClasses::dalvik_system_DexPathList__Element); |
| 961 | ObjPtr<mirror::Class> const dexfile_class = soa.Decode<mirror::Class>( |
| 962 | WellKnownClasses::dalvik_system_DexFile); |
| 963 | |
| 964 | for (int32_t i = 0; i < dex_elements->GetLength(); ++i) { |
Vladimir Marko | 423bebb | 2019-03-26 15:17:21 +0000 | [diff] [blame] | 965 | ObjPtr<mirror::Object> element = dex_elements->GetWithoutChecks(i); |
Calin Juravle | 57d0acc | 2017-07-11 17:41:30 -0700 | [diff] [blame] | 966 | // We can hit a null element here because this is invoked with a partially filled dex_elements |
| 967 | // array from DexPathList. DexPathList will open each dex sequentially, each time passing the |
| 968 | // list of dex files which were opened before. |
| 969 | if (element == nullptr) { |
| 970 | continue; |
| 971 | } |
| 972 | |
| 973 | // We support this being dalvik.system.DexPathList$Element and dalvik.system.DexFile. |
| 974 | // TODO(calin): Code caried over oat_file_manager: supporting both classes seem to be |
| 975 | // a historical glitch. All the java code opens dex files using an array of Elements. |
| 976 | ObjPtr<mirror::Object> dex_file; |
| 977 | if (element_class == element->GetClass()) { |
| 978 | dex_file = dex_file_field->GetObject(element); |
| 979 | } else if (dexfile_class == element->GetClass()) { |
| 980 | dex_file = element; |
| 981 | } else { |
| 982 | LOG(ERROR) << "Unsupported element in dex_elements: " |
| 983 | << mirror::Class::PrettyClass(element->GetClass()); |
| 984 | return false; |
| 985 | } |
| 986 | |
| 987 | if (!CollectDexFilesFromJavaDexFile(dex_file, cookie_field, out_dex_files)) { |
| 988 | return false; |
| 989 | } |
| 990 | } |
| 991 | return true; |
| 992 | } |
| 993 | |
| 994 | // Adds the `class_loader` info to the `context`. |
| 995 | // The dex file present in `dex_elements` array (if not null) will be added at the end of |
| 996 | // the classpath. |
| 997 | // This method is recursive (w.r.t. the class loader parent) and will stop once it reaches the |
| 998 | // BootClassLoader. Note that the class loader chain is expected to be short. |
Nicolas Geoffray | e167273 | 2018-11-30 01:09:49 +0000 | [diff] [blame] | 999 | bool ClassLoaderContext::CreateInfoFromClassLoader( |
Calin Juravle | 57d0acc | 2017-07-11 17:41:30 -0700 | [diff] [blame] | 1000 | ScopedObjectAccessAlreadyRunnable& soa, |
| 1001 | Handle<mirror::ClassLoader> class_loader, |
Nicolas Geoffray | e167273 | 2018-11-30 01:09:49 +0000 | [diff] [blame] | 1002 | Handle<mirror::ObjectArray<mirror::Object>> dex_elements, |
| 1003 | ClassLoaderInfo* child_info, |
| 1004 | bool is_shared_library) |
Calin Juravle | 57d0acc | 2017-07-11 17:41:30 -0700 | [diff] [blame] | 1005 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 1006 | if (ClassLinker::IsBootClassLoader(soa, class_loader.Get())) { |
| 1007 | // Nothing to do for the boot class loader as we don't add its dex files to the context. |
| 1008 | return true; |
| 1009 | } |
| 1010 | |
| 1011 | ClassLoaderContext::ClassLoaderType type; |
| 1012 | if (IsPathOrDexClassLoader(soa, class_loader)) { |
| 1013 | type = kPathClassLoader; |
| 1014 | } else if (IsDelegateLastClassLoader(soa, class_loader)) { |
| 1015 | type = kDelegateLastClassLoader; |
David Brazdil | 1a9ac53 | 2019-03-05 11:57:13 +0000 | [diff] [blame] | 1016 | } else if (IsInMemoryDexClassLoader(soa, class_loader)) { |
| 1017 | type = kInMemoryDexClassLoader; |
Calin Juravle | 57d0acc | 2017-07-11 17:41:30 -0700 | [diff] [blame] | 1018 | } else { |
| 1019 | LOG(WARNING) << "Unsupported class loader"; |
| 1020 | return false; |
| 1021 | } |
| 1022 | |
| 1023 | // Inspect the class loader for its dex files. |
| 1024 | std::vector<const DexFile*> dex_files_loaded; |
| 1025 | CollectDexFilesFromSupportedClassLoader(soa, class_loader, &dex_files_loaded); |
| 1026 | |
| 1027 | // If we have a dex_elements array extract its dex elements now. |
| 1028 | // This is used in two situations: |
| 1029 | // 1) when a new ClassLoader is created DexPathList will open each dex file sequentially |
| 1030 | // passing the list of already open dex files each time. This ensures that we see the |
| 1031 | // correct context even if the ClassLoader under construction is not fully build. |
| 1032 | // 2) when apk splits are loaded on the fly, the framework will load their dex files by |
| 1033 | // appending them to the current class loader. When the new code paths are loaded in |
| 1034 | // BaseDexClassLoader, the paths already present in the class loader will be passed |
| 1035 | // in the dex_elements array. |
| 1036 | if (dex_elements != nullptr) { |
| 1037 | GetDexFilesFromDexElementsArray(soa, dex_elements, &dex_files_loaded); |
| 1038 | } |
| 1039 | |
Nicolas Geoffray | 1717a49 | 2018-11-30 01:02:50 +0000 | [diff] [blame] | 1040 | ClassLoaderInfo* info = new ClassLoaderContext::ClassLoaderInfo(type); |
Nicolas Geoffray | e167273 | 2018-11-30 01:09:49 +0000 | [diff] [blame] | 1041 | // Attach the `ClassLoaderInfo` now, before populating dex files, as only the |
| 1042 | // `ClassLoaderContext` knows whether these dex files should be deleted or not. |
| 1043 | if (child_info == nullptr) { |
Nicolas Geoffray | 1717a49 | 2018-11-30 01:02:50 +0000 | [diff] [blame] | 1044 | class_loader_chain_.reset(info); |
Nicolas Geoffray | e167273 | 2018-11-30 01:09:49 +0000 | [diff] [blame] | 1045 | } else if (is_shared_library) { |
| 1046 | child_info->shared_libraries.push_back(std::unique_ptr<ClassLoaderInfo>(info)); |
Nicolas Geoffray | 1717a49 | 2018-11-30 01:02:50 +0000 | [diff] [blame] | 1047 | } else { |
Nicolas Geoffray | e167273 | 2018-11-30 01:09:49 +0000 | [diff] [blame] | 1048 | child_info->parent.reset(info); |
Nicolas Geoffray | 1717a49 | 2018-11-30 01:02:50 +0000 | [diff] [blame] | 1049 | } |
| 1050 | |
Nicolas Geoffray | e167273 | 2018-11-30 01:09:49 +0000 | [diff] [blame] | 1051 | // Now that `info` is in the chain, populate dex files. |
Calin Juravle | 57d0acc | 2017-07-11 17:41:30 -0700 | [diff] [blame] | 1052 | for (const DexFile* dex_file : dex_files_loaded) { |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 1053 | info->classpath.push_back(dex_file->GetLocation()); |
| 1054 | info->checksums.push_back(dex_file->GetLocationChecksum()); |
| 1055 | info->opened_dex_files.emplace_back(dex_file); |
Calin Juravle | 57d0acc | 2017-07-11 17:41:30 -0700 | [diff] [blame] | 1056 | } |
| 1057 | |
Calin Juravle | 57d0acc | 2017-07-11 17:41:30 -0700 | [diff] [blame] | 1058 | // Note that dex_elements array is null here. The elements are considered to be part of the |
| 1059 | // current class loader and are not passed to the parents. |
| 1060 | ScopedNullHandle<mirror::ObjectArray<mirror::Object>> null_dex_elements; |
Nicolas Geoffray | e167273 | 2018-11-30 01:09:49 +0000 | [diff] [blame] | 1061 | |
| 1062 | // Add the shared libraries. |
| 1063 | StackHandleScope<3> hs(Thread::Current()); |
| 1064 | ArtField* field = |
| 1065 | jni::DecodeArtField(WellKnownClasses::dalvik_system_BaseDexClassLoader_sharedLibraryLoaders); |
| 1066 | ObjPtr<mirror::Object> raw_shared_libraries = field->GetObject(class_loader.Get()); |
| 1067 | if (raw_shared_libraries != nullptr) { |
| 1068 | Handle<mirror::ObjectArray<mirror::ClassLoader>> shared_libraries = |
| 1069 | hs.NewHandle(raw_shared_libraries->AsObjectArray<mirror::ClassLoader>()); |
| 1070 | MutableHandle<mirror::ClassLoader> temp_loader = hs.NewHandle<mirror::ClassLoader>(nullptr); |
| 1071 | for (int32_t i = 0; i < shared_libraries->GetLength(); ++i) { |
| 1072 | temp_loader.Assign(shared_libraries->Get(i)); |
| 1073 | if (!CreateInfoFromClassLoader( |
| 1074 | soa, temp_loader, null_dex_elements, info, /*is_shared_library=*/ true)) { |
| 1075 | return false; |
| 1076 | } |
| 1077 | } |
| 1078 | } |
| 1079 | |
| 1080 | // We created the ClassLoaderInfo for the current loader. Move on to its parent. |
| 1081 | Handle<mirror::ClassLoader> parent = hs.NewHandle(class_loader->GetParent()); |
| 1082 | if (!CreateInfoFromClassLoader( |
| 1083 | soa, parent, null_dex_elements, info, /*is_shared_library=*/ false)) { |
| 1084 | return false; |
| 1085 | } |
| 1086 | return true; |
Calin Juravle | 57d0acc | 2017-07-11 17:41:30 -0700 | [diff] [blame] | 1087 | } |
| 1088 | |
| 1089 | std::unique_ptr<ClassLoaderContext> ClassLoaderContext::CreateContextForClassLoader( |
| 1090 | jobject class_loader, |
| 1091 | jobjectArray dex_elements) { |
Calin Juravle | 3f91864 | 2017-07-11 19:04:20 -0700 | [diff] [blame] | 1092 | CHECK(class_loader != nullptr); |
| 1093 | |
Calin Juravle | 57d0acc | 2017-07-11 17:41:30 -0700 | [diff] [blame] | 1094 | ScopedObjectAccess soa(Thread::Current()); |
| 1095 | StackHandleScope<2> hs(soa.Self()); |
| 1096 | Handle<mirror::ClassLoader> h_class_loader = |
| 1097 | hs.NewHandle(soa.Decode<mirror::ClassLoader>(class_loader)); |
| 1098 | Handle<mirror::ObjectArray<mirror::Object>> h_dex_elements = |
| 1099 | hs.NewHandle(soa.Decode<mirror::ObjectArray<mirror::Object>>(dex_elements)); |
Nicolas Geoffray | 1717a49 | 2018-11-30 01:02:50 +0000 | [diff] [blame] | 1100 | std::unique_ptr<ClassLoaderContext> result(new ClassLoaderContext(/*owns_the_dex_files=*/ false)); |
Nicolas Geoffray | e167273 | 2018-11-30 01:09:49 +0000 | [diff] [blame] | 1101 | if (!result->CreateInfoFromClassLoader( |
| 1102 | soa, h_class_loader, h_dex_elements, nullptr, /*is_shared_library=*/ false)) { |
Calin Juravle | 57d0acc | 2017-07-11 17:41:30 -0700 | [diff] [blame] | 1103 | return nullptr; |
| 1104 | } |
Nicolas Geoffray | e167273 | 2018-11-30 01:09:49 +0000 | [diff] [blame] | 1105 | return result; |
Calin Juravle | 57d0acc | 2017-07-11 17:41:30 -0700 | [diff] [blame] | 1106 | } |
| 1107 | |
Calin Juravle | 1e96a5d | 2017-09-05 17:10:48 -0700 | [diff] [blame] | 1108 | static bool IsAbsoluteLocation(const std::string& location) { |
| 1109 | return !location.empty() && location[0] == '/'; |
| 1110 | } |
| 1111 | |
Mathieu Chartier | adc9086 | 2018-05-11 13:03:06 -0700 | [diff] [blame] | 1112 | ClassLoaderContext::VerificationResult ClassLoaderContext::VerifyClassLoaderContextMatch( |
| 1113 | const std::string& context_spec, |
| 1114 | bool verify_names, |
| 1115 | bool verify_checksums) const { |
Mathieu Chartier | f5abfc4 | 2018-03-23 21:51:54 -0700 | [diff] [blame] | 1116 | if (verify_names || verify_checksums) { |
| 1117 | DCHECK(dex_files_open_attempted_); |
| 1118 | DCHECK(dex_files_open_result_); |
| 1119 | } |
Calin Juravle | c5b215f | 2017-09-12 14:49:37 -0700 | [diff] [blame] | 1120 | |
Calin Juravle | 3f91864 | 2017-07-11 19:04:20 -0700 | [diff] [blame] | 1121 | ClassLoaderContext expected_context; |
Mathieu Chartier | f5abfc4 | 2018-03-23 21:51:54 -0700 | [diff] [blame] | 1122 | if (!expected_context.Parse(context_spec, verify_checksums)) { |
Calin Juravle | 3f91864 | 2017-07-11 19:04:20 -0700 | [diff] [blame] | 1123 | LOG(WARNING) << "Invalid class loader context: " << context_spec; |
Mathieu Chartier | adc9086 | 2018-05-11 13:03:06 -0700 | [diff] [blame] | 1124 | return VerificationResult::kMismatch; |
Calin Juravle | 3f91864 | 2017-07-11 19:04:20 -0700 | [diff] [blame] | 1125 | } |
| 1126 | |
Calin Juravle | c5b215f | 2017-09-12 14:49:37 -0700 | [diff] [blame] | 1127 | // Special shared library contexts always match. They essentially instruct the runtime |
| 1128 | // to ignore the class path check because the oat file is known to be loaded in different |
| 1129 | // contexts. OatFileManager will further verify if the oat file can be loaded based on the |
| 1130 | // collision check. |
Mathieu Chartier | adc9086 | 2018-05-11 13:03:06 -0700 | [diff] [blame] | 1131 | if (expected_context.special_shared_library_) { |
| 1132 | // Special case where we are the only entry in the class path. |
Nicolas Geoffray | 9893c47 | 2018-11-13 15:39:53 +0000 | [diff] [blame] | 1133 | if (class_loader_chain_ != nullptr && |
| 1134 | class_loader_chain_->parent == nullptr && |
| 1135 | class_loader_chain_->classpath.size() == 0) { |
Mathieu Chartier | adc9086 | 2018-05-11 13:03:06 -0700 | [diff] [blame] | 1136 | return VerificationResult::kVerifies; |
| 1137 | } |
| 1138 | return VerificationResult::kForcedToSkipChecks; |
| 1139 | } else if (special_shared_library_) { |
| 1140 | return VerificationResult::kForcedToSkipChecks; |
Calin Juravle | 3f91864 | 2017-07-11 19:04:20 -0700 | [diff] [blame] | 1141 | } |
| 1142 | |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 1143 | ClassLoaderInfo* info = class_loader_chain_.get(); |
| 1144 | ClassLoaderInfo* expected = expected_context.class_loader_chain_.get(); |
| 1145 | CHECK(info != nullptr); |
| 1146 | CHECK(expected != nullptr); |
| 1147 | if (!ClassLoaderInfoMatch(*info, *expected, context_spec, verify_names, verify_checksums)) { |
Mathieu Chartier | adc9086 | 2018-05-11 13:03:06 -0700 | [diff] [blame] | 1148 | return VerificationResult::kMismatch; |
Calin Juravle | 3f91864 | 2017-07-11 19:04:20 -0700 | [diff] [blame] | 1149 | } |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 1150 | return VerificationResult::kVerifies; |
| 1151 | } |
Calin Juravle | 3f91864 | 2017-07-11 19:04:20 -0700 | [diff] [blame] | 1152 | |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 1153 | bool ClassLoaderContext::ClassLoaderInfoMatch( |
| 1154 | const ClassLoaderInfo& info, |
| 1155 | const ClassLoaderInfo& expected_info, |
| 1156 | const std::string& context_spec, |
| 1157 | bool verify_names, |
| 1158 | bool verify_checksums) const { |
| 1159 | if (info.type != expected_info.type) { |
| 1160 | LOG(WARNING) << "ClassLoaderContext type mismatch" |
| 1161 | << ". expected=" << GetClassLoaderTypeName(expected_info.type) |
| 1162 | << ", found=" << GetClassLoaderTypeName(info.type) |
| 1163 | << " (" << context_spec << " | " << EncodeContextForOatFile("") << ")"; |
| 1164 | return false; |
| 1165 | } |
| 1166 | if (info.classpath.size() != expected_info.classpath.size()) { |
| 1167 | LOG(WARNING) << "ClassLoaderContext classpath size mismatch" |
| 1168 | << ". expected=" << expected_info.classpath.size() |
| 1169 | << ", found=" << info.classpath.size() |
Andreas Gampe | 7d0f81c | 2017-07-25 18:25:41 -0700 | [diff] [blame] | 1170 | << " (" << context_spec << " | " << EncodeContextForOatFile("") << ")"; |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 1171 | return false; |
| 1172 | } |
Calin Juravle | 3f91864 | 2017-07-11 19:04:20 -0700 | [diff] [blame] | 1173 | |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 1174 | if (verify_checksums) { |
| 1175 | DCHECK_EQ(info.classpath.size(), info.checksums.size()); |
| 1176 | DCHECK_EQ(expected_info.classpath.size(), expected_info.checksums.size()); |
| 1177 | } |
Mathieu Chartier | f5abfc4 | 2018-03-23 21:51:54 -0700 | [diff] [blame] | 1178 | |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 1179 | if (verify_names) { |
Calin Juravle | 3f91864 | 2017-07-11 19:04:20 -0700 | [diff] [blame] | 1180 | for (size_t k = 0; k < info.classpath.size(); k++) { |
Calin Juravle | 1e96a5d | 2017-09-05 17:10:48 -0700 | [diff] [blame] | 1181 | // Compute the dex location that must be compared. |
| 1182 | // We shouldn't do a naive comparison `info.classpath[k] == expected_info.classpath[k]` |
| 1183 | // because even if they refer to the same file, one could be encoded as a relative location |
| 1184 | // and the other as an absolute one. |
| 1185 | bool is_dex_name_absolute = IsAbsoluteLocation(info.classpath[k]); |
| 1186 | bool is_expected_dex_name_absolute = IsAbsoluteLocation(expected_info.classpath[k]); |
| 1187 | std::string dex_name; |
| 1188 | std::string expected_dex_name; |
| 1189 | |
| 1190 | if (is_dex_name_absolute == is_expected_dex_name_absolute) { |
| 1191 | // If both locations are absolute or relative then compare them as they are. |
| 1192 | // This is usually the case for: shared libraries and secondary dex files. |
| 1193 | dex_name = info.classpath[k]; |
| 1194 | expected_dex_name = expected_info.classpath[k]; |
| 1195 | } else if (is_dex_name_absolute) { |
| 1196 | // The runtime name is absolute but the compiled name (the expected one) is relative. |
| 1197 | // This is the case for split apks which depend on base or on other splits. |
| 1198 | dex_name = info.classpath[k]; |
| 1199 | expected_dex_name = OatFile::ResolveRelativeEncodedDexLocation( |
| 1200 | info.classpath[k].c_str(), expected_info.classpath[k]); |
Calin Juravle | 92003fe | 2017-09-06 02:22:57 +0000 | [diff] [blame] | 1201 | } else if (is_expected_dex_name_absolute) { |
Calin Juravle | 1e96a5d | 2017-09-05 17:10:48 -0700 | [diff] [blame] | 1202 | // The runtime name is relative but the compiled name is absolute. |
| 1203 | // There is no expected use case that would end up here as dex files are always loaded |
| 1204 | // with their absolute location. However, be tolerant and do the best effort (in case |
| 1205 | // there are unexpected new use case...). |
Calin Juravle | 1e96a5d | 2017-09-05 17:10:48 -0700 | [diff] [blame] | 1206 | dex_name = OatFile::ResolveRelativeEncodedDexLocation( |
| 1207 | expected_info.classpath[k].c_str(), info.classpath[k]); |
| 1208 | expected_dex_name = expected_info.classpath[k]; |
Calin Juravle | 92003fe | 2017-09-06 02:22:57 +0000 | [diff] [blame] | 1209 | } else { |
| 1210 | // Both locations are relative. In this case there's not much we can be sure about |
| 1211 | // except that the names are the same. The checksum will ensure that the files are |
| 1212 | // are same. This should not happen outside testing and manual invocations. |
| 1213 | dex_name = info.classpath[k]; |
| 1214 | expected_dex_name = expected_info.classpath[k]; |
Calin Juravle | 1e96a5d | 2017-09-05 17:10:48 -0700 | [diff] [blame] | 1215 | } |
| 1216 | |
| 1217 | // Compare the locations. |
| 1218 | if (dex_name != expected_dex_name) { |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 1219 | LOG(WARNING) << "ClassLoaderContext classpath element mismatch" |
Calin Juravle | 3f91864 | 2017-07-11 19:04:20 -0700 | [diff] [blame] | 1220 | << ". expected=" << expected_info.classpath[k] |
Andreas Gampe | 7d0f81c | 2017-07-25 18:25:41 -0700 | [diff] [blame] | 1221 | << ", found=" << info.classpath[k] |
| 1222 | << " (" << context_spec << " | " << EncodeContextForOatFile("") << ")"; |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 1223 | return false; |
Calin Juravle | 3f91864 | 2017-07-11 19:04:20 -0700 | [diff] [blame] | 1224 | } |
Calin Juravle | 1e96a5d | 2017-09-05 17:10:48 -0700 | [diff] [blame] | 1225 | |
| 1226 | // Compare the checksums. |
Calin Juravle | 3f91864 | 2017-07-11 19:04:20 -0700 | [diff] [blame] | 1227 | if (info.checksums[k] != expected_info.checksums[k]) { |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 1228 | LOG(WARNING) << "ClassLoaderContext classpath element checksum mismatch" |
Calin Juravle | 1e96a5d | 2017-09-05 17:10:48 -0700 | [diff] [blame] | 1229 | << ". expected=" << expected_info.checksums[k] |
| 1230 | << ", found=" << info.checksums[k] |
| 1231 | << " (" << context_spec << " | " << EncodeContextForOatFile("") << ")"; |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 1232 | return false; |
Calin Juravle | 3f91864 | 2017-07-11 19:04:20 -0700 | [diff] [blame] | 1233 | } |
| 1234 | } |
| 1235 | } |
Calin Juravle | 3f91864 | 2017-07-11 19:04:20 -0700 | [diff] [blame] | 1236 | |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 1237 | if (info.shared_libraries.size() != expected_info.shared_libraries.size()) { |
| 1238 | LOG(WARNING) << "ClassLoaderContext shared library size mismatch. " |
Nicolas Geoffray | e167273 | 2018-11-30 01:09:49 +0000 | [diff] [blame] | 1239 | << "Expected=" << expected_info.shared_libraries.size() |
| 1240 | << ", found=" << info.shared_libraries.size() |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 1241 | << " (" << context_spec << " | " << EncodeContextForOatFile("") << ")"; |
| 1242 | return false; |
Calin Juravle | c79470d | 2017-07-12 17:37:42 -0700 | [diff] [blame] | 1243 | } |
Nicolas Geoffray | 06af3b4 | 2018-10-29 10:39:04 +0000 | [diff] [blame] | 1244 | for (size_t i = 0; i < info.shared_libraries.size(); ++i) { |
| 1245 | if (!ClassLoaderInfoMatch(*info.shared_libraries[i].get(), |
| 1246 | *expected_info.shared_libraries[i].get(), |
| 1247 | context_spec, |
| 1248 | verify_names, |
| 1249 | verify_checksums)) { |
| 1250 | return false; |
| 1251 | } |
| 1252 | } |
| 1253 | if (info.parent.get() == nullptr) { |
| 1254 | if (expected_info.parent.get() != nullptr) { |
| 1255 | LOG(WARNING) << "ClassLoaderContext parent mismatch. " |
| 1256 | << " (" << context_spec << " | " << EncodeContextForOatFile("") << ")"; |
| 1257 | return false; |
| 1258 | } |
| 1259 | return true; |
| 1260 | } else if (expected_info.parent.get() == nullptr) { |
| 1261 | LOG(WARNING) << "ClassLoaderContext parent mismatch. " |
| 1262 | << " (" << context_spec << " | " << EncodeContextForOatFile("") << ")"; |
| 1263 | return false; |
| 1264 | } else { |
| 1265 | return ClassLoaderInfoMatch(*info.parent.get(), |
| 1266 | *expected_info.parent.get(), |
| 1267 | context_spec, |
| 1268 | verify_names, |
| 1269 | verify_checksums); |
| 1270 | } |
Calin Juravle | c79470d | 2017-07-12 17:37:42 -0700 | [diff] [blame] | 1271 | } |
| 1272 | |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 1273 | } // namespace art |