class_linker.h revision 8f3c9ae38df2460940a26dff889a84430b6c38d3
1/* 2 * Copyright (C) 2011 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#ifndef ART_RUNTIME_CLASS_LINKER_H_ 18#define ART_RUNTIME_CLASS_LINKER_H_ 19 20#include <string> 21#include <utility> 22#include <vector> 23 24#include "base/macros.h" 25#include "base/mutex.h" 26#include "dex_file.h" 27#include "gtest/gtest.h" 28#include "root_visitor.h" 29#include "oat_file.h" 30 31namespace art { 32namespace gc { 33namespace space { 34 class ImageSpace; 35} // namespace space 36} // namespace gc 37namespace mirror { 38 class ClassLoader; 39 class DexCache; 40 class DexCacheTest_Open_Test; 41 class IfTable; 42 template<class T> class ObjectArray; 43 class StackTraceElement; 44} // namespace mirror 45 46class InternTable; 47class ObjectLock; 48template<class T> class SirtRef; 49 50typedef bool (ClassVisitor)(mirror::Class* c, void* arg); 51 52class ClassLinker { 53 public: 54 // Creates the class linker by bootstrapping from dex files. 55 static ClassLinker* CreateFromCompiler(const std::vector<const DexFile*>& boot_class_path, 56 InternTable* intern_table) 57 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 58 59 // Creates the class linker from an image. 60 static ClassLinker* CreateFromImage(InternTable* intern_table) 61 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 62 63 ~ClassLinker(); 64 65 bool IsInBootClassPath(const char* descriptor); 66 67 // Finds a class by its descriptor, loading it if necessary. 68 // If class_loader is null, searches boot_class_path_. 69 mirror::Class* FindClass(const char* descriptor, mirror::ClassLoader* class_loader) 70 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 71 72 mirror::Class* FindSystemClass(const char* descriptor) 73 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 74 75 // Define a new a class based on a ClassDef from a DexFile 76 mirror::Class* DefineClass(const StringPiece& descriptor, mirror::ClassLoader* class_loader, 77 const DexFile& dex_file, const DexFile::ClassDef& dex_class_def) 78 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 79 80 // Finds a class by its descriptor, returning NULL if it isn't wasn't loaded 81 // by the given 'class_loader'. 82 mirror::Class* LookupClass(const char* descriptor, const mirror::ClassLoader* class_loader) 83 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_) 84 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 85 86 // Finds all the classes with the given descriptor, regardless of ClassLoader. 87 void LookupClasses(const char* descriptor, std::vector<mirror::Class*>& classes) 88 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_) 89 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 90 91 mirror::Class* FindPrimitiveClass(char type) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 92 93 // General class unloading is not supported, this is used to prune 94 // unwanted classes during image writing. 95 bool RemoveClass(const char* descriptor, const mirror::ClassLoader* class_loader) 96 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_) 97 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 98 99 void DumpAllClasses(int flags) const 100 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_) 101 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 102 103 void DumpForSigQuit(std::ostream& os) const 104 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_); 105 106 size_t NumLoadedClasses() const LOCKS_EXCLUDED(Locks::classlinker_classes_lock_); 107 108 // Resolve a String with the given index from the DexFile, storing the 109 // result in the DexCache. The referrer is used to identify the 110 // target DexCache and ClassLoader to use for resolution. 111 mirror::String* ResolveString(uint32_t string_idx, const mirror::ArtMethod* referrer) 112 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 113 114 // Resolve a String with the given index from the DexFile, storing the 115 // result in the DexCache. 116 mirror::String* ResolveString(const DexFile& dex_file, uint32_t string_idx, 117 mirror::DexCache* dex_cache) 118 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 119 120 // Resolve a Type with the given index from the DexFile, storing the 121 // result in the DexCache. The referrer is used to identity the 122 // target DexCache and ClassLoader to use for resolution. 123 mirror::Class* ResolveType(const DexFile& dex_file, uint16_t type_idx, 124 const mirror::Class* referrer) 125 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { 126 return ResolveType(dex_file, 127 type_idx, 128 referrer->GetDexCache(), 129 referrer->GetClassLoader()); 130 } 131 132 // Resolve a Type with the given index from the DexFile, storing the 133 // result in the DexCache. The referrer is used to identify the 134 // target DexCache and ClassLoader to use for resolution. 135 mirror::Class* ResolveType(uint16_t type_idx, const mirror::ArtMethod* referrer) 136 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 137 138 mirror::Class* ResolveType(uint16_t type_idx, const mirror::ArtField* referrer) 139 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 140 141 // Resolve a type with the given ID from the DexFile, storing the 142 // result in DexCache. The ClassLoader is used to search for the 143 // type, since it may be referenced from but not contained within 144 // the given DexFile. 145 mirror::Class* ResolveType(const DexFile& dex_file, 146 uint16_t type_idx, 147 mirror::DexCache* dex_cache, 148 mirror::ClassLoader* class_loader) 149 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 150 151 // Resolve a method with a given ID from the DexFile, storing the 152 // result in DexCache. The ClassLinker and ClassLoader are used as 153 // in ResolveType. What is unique is the method type argument which 154 // is used to determine if this method is a direct, static, or 155 // virtual method. 156 mirror::ArtMethod* ResolveMethod(const DexFile& dex_file, 157 uint32_t method_idx, 158 mirror::DexCache* dex_cache, 159 mirror::ClassLoader* class_loader, 160 const mirror::ArtMethod* referrer, 161 InvokeType type) 162 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 163 164 mirror::ArtMethod* ResolveMethod(uint32_t method_idx, const mirror::ArtMethod* referrer, 165 InvokeType type) 166 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 167 168 mirror::ArtField* ResolveField(uint32_t field_idx, const mirror::ArtMethod* referrer, 169 bool is_static) 170 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 171 172 // Resolve a field with a given ID from the DexFile, storing the 173 // result in DexCache. The ClassLinker and ClassLoader are used as 174 // in ResolveType. What is unique is the is_static argument which is 175 // used to determine if we are resolving a static or non-static 176 // field. 177 mirror::ArtField* ResolveField(const DexFile& dex_file, 178 uint32_t field_idx, 179 mirror::DexCache* dex_cache, 180 mirror::ClassLoader* class_loader, 181 bool is_static) 182 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 183 184 // Resolve a field with a given ID from the DexFile, storing the 185 // result in DexCache. The ClassLinker and ClassLoader are used as 186 // in ResolveType. No is_static argument is provided so that Java 187 // field resolution semantics are followed. 188 mirror::ArtField* ResolveFieldJLS(const DexFile& dex_file, 189 uint32_t field_idx, 190 mirror::DexCache* dex_cache, 191 mirror::ClassLoader* class_loader) 192 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 193 194 // Get shorty from method index without resolution. Used to do handlerization. 195 const char* MethodShorty(uint32_t method_idx, mirror::ArtMethod* referrer, uint32_t* length) 196 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 197 198 // Returns true on success, false if there's an exception pending. 199 // can_run_clinit=false allows the compiler to attempt to init a class, 200 // given the restriction that no <clinit> execution is possible. 201 bool EnsureInitialized(mirror::Class* c, bool can_run_clinit, bool can_init_fields) 202 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 203 204 // Initializes classes that have instances in the image but that have 205 // <clinit> methods so they could not be initialized by the compiler. 206 void RunRootClinits() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 207 208 void RegisterDexFile(const DexFile& dex_file) 209 LOCKS_EXCLUDED(dex_lock_) 210 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 211 void RegisterDexFile(const DexFile& dex_file, SirtRef<mirror::DexCache>& dex_cache) 212 LOCKS_EXCLUDED(dex_lock_) 213 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 214 215 void RegisterOatFile(const OatFile& oat_file) 216 LOCKS_EXCLUDED(dex_lock_); 217 218 const std::vector<const DexFile*>& GetBootClassPath() { 219 return boot_class_path_; 220 } 221 222 void VisitClasses(ClassVisitor* visitor, void* arg) const 223 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_); 224 // Less efficient variant of VisitClasses that doesn't hold the classlinker_classes_lock_ 225 // when calling the visitor. 226 void VisitClassesWithoutClassesLock(ClassVisitor* visitor, void* arg) const 227 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_); 228 229 void VisitRoots(RootVisitor* visitor, void* arg, bool clean_dirty) 230 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_, dex_lock_); 231 232 mirror::DexCache* FindDexCache(const DexFile& dex_file) const 233 LOCKS_EXCLUDED(dex_lock_) 234 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 235 bool IsDexFileRegistered(const DexFile& dex_file) const 236 LOCKS_EXCLUDED(dex_lock_); 237 void FixupDexCaches(mirror::ArtMethod* resolution_method) const 238 LOCKS_EXCLUDED(dex_lock_) 239 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 240 241 // Generate an oat file from a dex file 242 bool GenerateOatFile(const std::string& dex_filename, 243 int oat_fd, 244 const std::string& oat_cache_filename); 245 246 const OatFile* FindOatFileFromOatLocation(const std::string& location) 247 LOCKS_EXCLUDED(dex_lock_); 248 249 const OatFile* FindOatFileFromOatLocationLocked(const std::string& location) 250 SHARED_LOCKS_REQUIRED(dex_lock_); 251 252 // Finds the oat file for a dex location, generating the oat file if 253 // it is missing or out of date. Returns the DexFile from within the 254 // created oat file. 255 const DexFile* FindOrCreateOatFileForDexLocation(const std::string& dex_location, 256 const std::string& oat_location) 257 LOCKS_EXCLUDED(dex_lock_) 258 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 259 const DexFile* FindOrCreateOatFileForDexLocationLocked(const std::string& dex_location, 260 const std::string& oat_location) 261 EXCLUSIVE_LOCKS_REQUIRED(dex_lock_) 262 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 263 // Find a DexFile within an OatFile given a DexFile location. Note 264 // that this returns null if the location checksum of the DexFile 265 // does not match the OatFile. 266 const DexFile* FindDexFileInOatFileFromDexLocation(const std::string& location) 267 LOCKS_EXCLUDED(dex_lock_) 268 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 269 270 271 // Returns true if oat file contains the dex file with the given location and checksum. 272 static bool VerifyOatFileChecksums(const OatFile* oat_file, 273 const std::string& dex_location, 274 uint32_t dex_location_checksum) 275 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 276 277 // TODO: replace this with multiple methods that allocate the correct managed type. 278 template <class T> 279 mirror::ObjectArray<T>* AllocObjectArray(Thread* self, size_t length) 280 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 281 282 mirror::ObjectArray<mirror::Class>* AllocClassArray(Thread* self, size_t length) 283 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 284 285 mirror::ObjectArray<mirror::String>* AllocStringArray(Thread* self, size_t length) 286 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 287 288 mirror::ObjectArray<mirror::ArtMethod>* AllocArtMethodArray(Thread* self, size_t length) 289 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 290 291 mirror::IfTable* AllocIfTable(Thread* self, size_t ifcount) 292 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 293 294 mirror::ObjectArray<mirror::ArtField>* AllocArtFieldArray(Thread* self, size_t length) 295 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 296 297 mirror::ObjectArray<mirror::StackTraceElement>* AllocStackTraceElementArray(Thread* self, 298 size_t length) 299 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 300 301 void VerifyClass(mirror::Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 302 bool VerifyClassUsingOatFile(const DexFile& dex_file, mirror::Class* klass, 303 mirror::Class::Status& oat_file_class_status) 304 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 305 void ResolveClassExceptionHandlerTypes(const DexFile& dex_file, mirror::Class* klass) 306 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 307 void ResolveMethodExceptionHandlerTypes(const DexFile& dex_file, mirror::ArtMethod* klass) 308 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 309 310 mirror::Class* CreateProxyClass(mirror::String* name, mirror::ObjectArray<mirror::Class>* interfaces, 311 mirror::ClassLoader* loader, 312 mirror::ObjectArray<mirror::ArtMethod>* methods, 313 mirror::ObjectArray<mirror::ObjectArray<mirror::Class> >* throws) 314 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 315 std::string GetDescriptorForProxy(const mirror::Class* proxy_class) 316 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 317 mirror::ArtMethod* FindMethodForProxy(const mirror::Class* proxy_class, 318 const mirror::ArtMethod* proxy_method) 319 LOCKS_EXCLUDED(dex_lock_) 320 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 321 322 // Get the oat code for a method when its class isn't yet initialized 323 const void* GetOatCodeFor(const mirror::ArtMethod* method) 324 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 325 326 // Get the oat code for a method from a method index. 327 const void* GetOatCodeFor(const DexFile& dex_file, uint32_t method_idx) 328 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 329 330 pid_t GetClassesLockOwner(); // For SignalCatcher. 331 pid_t GetDexLockOwner(); // For SignalCatcher. 332 333 bool IsDirty() const { 334 return is_dirty_; 335 } 336 337 void Dirty() { 338 is_dirty_ = true; 339 } 340 341 const void* GetPortableResolutionTrampoline() const { 342 return portable_resolution_trampoline_; 343 } 344 345 const void* GetQuickResolutionTrampoline() const { 346 return quick_resolution_trampoline_; 347 } 348 349 InternTable* GetInternTable() const { 350 return intern_table_; 351 } 352 353 // Attempts to insert a class into a class table. Returns NULL if 354 // the class was inserted, otherwise returns an existing class with 355 // the same descriptor and ClassLoader. 356 mirror::Class* InsertClass(const StringPiece& descriptor, mirror::Class* klass, bool image_class) 357 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_) 358 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 359 360 private: 361 explicit ClassLinker(InternTable*); 362 363 const OatFile::OatMethod GetOatMethodFor(const mirror::ArtMethod* method) 364 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 365 366 // Initialize class linker by bootstraping from dex files 367 void InitFromCompiler(const std::vector<const DexFile*>& boot_class_path) 368 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 369 370 // Initialize class linker from one or more images. 371 void InitFromImage() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 372 OatFile& GetImageOatFile(gc::space::ImageSpace* space) 373 LOCKS_EXCLUDED(dex_lock_) 374 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 375 376 void FinishInit() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 377 378 // For early bootstrapping by Init 379 mirror::Class* AllocClass(Thread* self, mirror::Class* java_lang_Class, size_t class_size) 380 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 381 382 // Alloc* convenience functions to avoid needing to pass in mirror::Class* 383 // values that are known to the ClassLinker such as 384 // kObjectArrayClass and kJavaLangString etc. 385 mirror::Class* AllocClass(Thread* self, size_t class_size) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 386 mirror::DexCache* AllocDexCache(Thread* self, const DexFile& dex_file) 387 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 388 mirror::ArtField* AllocArtField(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 389 mirror::ArtMethod* AllocArtMethod(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 390 391 mirror::Class* CreatePrimitiveClass(Thread* self, Primitive::Type type) 392 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 393 mirror::Class* InitializePrimitiveClass(mirror::Class* primitive_class, Primitive::Type type) 394 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 395 396 397 mirror::Class* CreateArrayClass(const std::string& descriptor, mirror::ClassLoader* class_loader) 398 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 399 400 void AppendToBootClassPath(const DexFile& dex_file) 401 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 402 void AppendToBootClassPath(const DexFile& dex_file, SirtRef<mirror::DexCache>& dex_cache) 403 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 404 405 void ConstructFieldMap(const DexFile& dex_file, const DexFile::ClassDef& dex_class_def, 406 mirror::Class* c, SafeMap<uint32_t, mirror::ArtField*>& field_map) 407 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 408 409 size_t SizeOfClass(const DexFile& dex_file, 410 const DexFile::ClassDef& dex_class_def); 411 412 void LoadClass(const DexFile& dex_file, 413 const DexFile::ClassDef& dex_class_def, 414 SirtRef<mirror::Class>& klass, 415 mirror::ClassLoader* class_loader) 416 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 417 418 void LoadField(const DexFile& dex_file, const ClassDataItemIterator& it, 419 SirtRef<mirror::Class>& klass, SirtRef<mirror::ArtField>& dst) 420 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 421 422 mirror::ArtMethod* LoadMethod(Thread* self, const DexFile& dex_file, 423 const ClassDataItemIterator& dex_method, 424 SirtRef<mirror::Class>& klass) 425 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 426 427 void FixupStaticTrampolines(mirror::Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 428 429 // Finds the associated oat class for a dex_file and descriptor 430 const OatFile::OatClass* GetOatClass(const DexFile& dex_file, const char* descriptor) 431 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 432 433 void RegisterDexFileLocked(const DexFile& dex_file, SirtRef<mirror::DexCache>& dex_cache) 434 EXCLUSIVE_LOCKS_REQUIRED(dex_lock_) 435 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 436 bool IsDexFileRegisteredLocked(const DexFile& dex_file) const SHARED_LOCKS_REQUIRED(dex_lock_); 437 void RegisterOatFileLocked(const OatFile& oat_file) EXCLUSIVE_LOCKS_REQUIRED(dex_lock_) 438 EXCLUSIVE_LOCKS_REQUIRED(dex_lock_); 439 440 bool InitializeClass(mirror::Class* klass, bool can_run_clinit, bool can_init_parents) 441 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 442 bool WaitForInitializeClass(mirror::Class* klass, Thread* self, ObjectLock& lock); 443 bool ValidateSuperClassDescriptors(const mirror::Class* klass) 444 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 445 446 bool IsSameDescriptorInDifferentClassContexts(const char* descriptor, 447 const mirror::Class* klass1, 448 const mirror::Class* klass2) 449 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 450 451 bool IsSameMethodSignatureInDifferentClassContexts(const mirror::ArtMethod* method, 452 const mirror::Class* klass1, 453 const mirror::Class* klass2) 454 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 455 456 bool LinkClass(SirtRef<mirror::Class>& klass, mirror::ObjectArray<mirror::Class>* interfaces) 457 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 458 459 bool LinkSuperClass(SirtRef<mirror::Class>& klass) 460 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 461 462 bool LoadSuperAndInterfaces(SirtRef<mirror::Class>& klass, const DexFile& dex_file) 463 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 464 465 bool LinkMethods(SirtRef<mirror::Class>& klass, mirror::ObjectArray<mirror::Class>* interfaces) 466 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 467 468 bool LinkVirtualMethods(SirtRef<mirror::Class>& klass) 469 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 470 471 bool LinkInterfaceMethods(SirtRef<mirror::Class>& klass, 472 mirror::ObjectArray<mirror::Class>* interfaces) 473 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 474 475 bool LinkStaticFields(SirtRef<mirror::Class>& klass) 476 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 477 bool LinkInstanceFields(SirtRef<mirror::Class>& klass) 478 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 479 bool LinkFields(SirtRef<mirror::Class>& klass, bool is_static) 480 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 481 482 483 void CreateReferenceInstanceOffsets(SirtRef<mirror::Class>& klass) 484 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 485 void CreateReferenceStaticOffsets(SirtRef<mirror::Class>& klass) 486 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 487 void CreateReferenceOffsets(SirtRef<mirror::Class>& klass, bool is_static, 488 uint32_t reference_offsets) 489 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 490 491 // For use by ImageWriter to find DexCaches for its roots 492 const std::vector<mirror::DexCache*>& GetDexCaches() { 493 return dex_caches_; 494 } 495 496 const OatFile* FindOpenedOatFileForDexFile(const DexFile& dex_file) 497 LOCKS_EXCLUDED(dex_lock_) 498 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 499 const OatFile* FindOpenedOatFileFromDexLocation(const std::string& dex_location) 500 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_, dex_lock_); 501 const OatFile* FindOpenedOatFileFromOatLocation(const std::string& oat_location) 502 SHARED_LOCKS_REQUIRED(dex_lock_); 503 const DexFile* FindDexFileInOatLocation(const std::string& dex_location, 504 uint32_t dex_location_checksum, 505 const std::string& oat_location) 506 EXCLUSIVE_LOCKS_REQUIRED(dex_lock_) 507 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 508 509 const DexFile* VerifyAndOpenDexFileFromOatFile(const OatFile* oat_file, 510 const std::string& dex_location, 511 uint32_t dex_location_checksum) 512 EXCLUSIVE_LOCKS_REQUIRED(dex_lock_) 513 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 514 515 mirror::ArtMethod* CreateProxyConstructor(Thread* self, SirtRef<mirror::Class>& klass, 516 mirror::Class* proxy_class) 517 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 518 mirror::ArtMethod* CreateProxyMethod(Thread* self, SirtRef<mirror::Class>& klass, 519 SirtRef<mirror::ArtMethod>& prototype) 520 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 521 522 std::vector<const DexFile*> boot_class_path_; 523 524 mutable ReaderWriterMutex dex_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER; 525 std::vector<mirror::DexCache*> dex_caches_ GUARDED_BY(dex_lock_); 526 std::vector<const OatFile*> oat_files_ GUARDED_BY(dex_lock_); 527 528 529 // multimap from a string hash code of a class descriptor to 530 // mirror::Class* instances. Results should be compared for a matching 531 // Class::descriptor_ and Class::class_loader_. 532 typedef std::multimap<size_t, mirror::Class*> Table; 533 Table image_classes_ GUARDED_BY(Locks::classlinker_classes_lock_); 534 Table classes_ GUARDED_BY(Locks::classlinker_classes_lock_); 535 536 mirror::Class* LookupClassLocked(const char* descriptor, const mirror::ClassLoader* class_loader, 537 size_t hash, const Table& classes) 538 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_, Locks::classlinker_classes_lock_); 539 540 // indexes into class_roots_. 541 // needs to be kept in sync with class_roots_descriptors_. 542 enum ClassRoot { 543 kJavaLangClass, 544 kJavaLangObject, 545 kClassArrayClass, 546 kObjectArrayClass, 547 kJavaLangString, 548 kJavaLangDexCache, 549 kJavaLangRefReference, 550 kJavaLangReflectArtField, 551 kJavaLangReflectArtMethod, 552 kJavaLangReflectProxy, 553 kJavaLangStringArrayClass, 554 kJavaLangReflectArtFieldArrayClass, 555 kJavaLangReflectArtMethodArrayClass, 556 kJavaLangClassLoader, 557 kJavaLangThrowable, 558 kJavaLangClassNotFoundException, 559 kJavaLangStackTraceElement, 560 kPrimitiveBoolean, 561 kPrimitiveByte, 562 kPrimitiveChar, 563 kPrimitiveDouble, 564 kPrimitiveFloat, 565 kPrimitiveInt, 566 kPrimitiveLong, 567 kPrimitiveShort, 568 kPrimitiveVoid, 569 kBooleanArrayClass, 570 kByteArrayClass, 571 kCharArrayClass, 572 kDoubleArrayClass, 573 kFloatArrayClass, 574 kIntArrayClass, 575 kLongArrayClass, 576 kShortArrayClass, 577 kJavaLangStackTraceElementArrayClass, 578 kClassRootsMax, 579 }; 580 mirror::ObjectArray<mirror::Class>* class_roots_; 581 582 mirror::Class* GetClassRoot(ClassRoot class_root) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 583 584 void SetClassRoot(ClassRoot class_root, mirror::Class* klass) 585 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 586 587 mirror::ObjectArray<mirror::Class>* GetClassRoots() { 588 DCHECK(class_roots_ != NULL); 589 return class_roots_; 590 } 591 592 static const char* class_roots_descriptors_[]; 593 594 const char* GetClassRootDescriptor(ClassRoot class_root) { 595 const char* descriptor = class_roots_descriptors_[class_root]; 596 CHECK(descriptor != NULL); 597 return descriptor; 598 } 599 600 mirror::IfTable* array_iftable_; 601 602 bool init_done_; 603 bool is_dirty_; 604 605 InternTable* intern_table_; 606 607 const void* portable_resolution_trampoline_; 608 const void* quick_resolution_trampoline_; 609 610 friend class ImageWriter; // for GetClassRoots 611 FRIEND_TEST(ClassLinkerTest, ClassRootDescriptors); 612 FRIEND_TEST(mirror::DexCacheTest, Open); 613 FRIEND_TEST(ExceptionTest, FindExceptionHandler); 614 FRIEND_TEST(ObjectTest, AllocObjectArray); 615 DISALLOW_COPY_AND_ASSIGN(ClassLinker); 616}; 617 618} // namespace art 619 620#endif // ART_RUNTIME_CLASS_LINKER_H_ 621