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