Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 1 | // Copyright 2011 Google Inc. All Rights Reserved. |
| 2 | |
| 3 | #ifndef ART_SRC_CLASS_LINKER_H_ |
| 4 | #define ART_SRC_CLASS_LINKER_H_ |
| 5 | |
| 6 | #include <map> |
| 7 | #include <utility> |
| 8 | #include <vector> |
| 9 | |
| 10 | #include "src/macros.h" |
| 11 | #include "src/thread.h" |
| 12 | #include "src/object.h" |
| 13 | |
| 14 | namespace art { |
| 15 | |
| 16 | class ClassLinker { |
| 17 | public: |
Carl Shapiro | 565f507 | 2011-07-10 13:39:43 -0700 | [diff] [blame] | 18 | // Initializes the class linker. |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame^] | 19 | static ClassLinker* Create(); |
| 20 | |
| 21 | ~ClassLinker() {} |
Carl Shapiro | 565f507 | 2011-07-10 13:39:43 -0700 | [diff] [blame] | 22 | |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 23 | // Finds a class by its descriptor name. |
| 24 | Class* FindClass(const char* descriptor, |
| 25 | Object* class_loader, |
| 26 | DexFile* dex_file); |
| 27 | |
Carl Shapiro | 565f507 | 2011-07-10 13:39:43 -0700 | [diff] [blame] | 28 | Class* FindSystemClass(const char* descriptor) { |
| 29 | return FindClass(descriptor, NULL, NULL); |
| 30 | } |
| 31 | |
Brian Carlstrom | 934486c | 2011-07-12 23:42:50 -0700 | [diff] [blame] | 32 | bool LoadClass(const char* descriptor, Class* klass); |
| 33 | |
| 34 | bool LoadClass(const RawDexFile::ClassDef& class_def, Class* klass); |
| 35 | |
Carl Shapiro | 565f507 | 2011-07-10 13:39:43 -0700 | [diff] [blame] | 36 | Class* FindPrimitiveClass(JType type); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 37 | |
| 38 | bool InitializeClass(Class* klass); |
| 39 | |
| 40 | Class* LookupClass(const char* descriptor, Object* class_loader); |
| 41 | |
Carl Shapiro | 5fafe2b | 2011-07-09 15:34:41 -0700 | [diff] [blame] | 42 | Class* ResolveClass(const Class* referring, uint32_t class_idx); |
| 43 | |
| 44 | String* ResolveString(const Class* referring, uint32_t string_idx); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 45 | |
| 46 | DexFile* FindInClassPath(const char* descriptor); |
| 47 | |
| 48 | void AppendToClassPath(DexFile* dex_file); |
| 49 | |
| 50 | private: |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame^] | 51 | ClassLinker() {} |
| 52 | |
| 53 | void Init(); |
| 54 | |
Carl Shapiro | 565f507 | 2011-07-10 13:39:43 -0700 | [diff] [blame] | 55 | Class* CreatePrimitiveClass(JType type, const char* descriptor); |
| 56 | |
Brian Carlstrom | 934486c | 2011-07-12 23:42:50 -0700 | [diff] [blame] | 57 | void LoadInterfaces(const RawDexFile::ClassDef& class_def, Class *klass); |
| 58 | |
| 59 | void LoadField(Class* klass, const RawDexFile::Field& src, Field* dst); |
| 60 | |
| 61 | void LoadMethod(Class* klass, const RawDexFile::Method& src, Method* dst); |
| 62 | |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 63 | // Inserts a class into the class table. Returns true if the class |
| 64 | // was inserted. |
| 65 | bool InsertClass(Class* klass); |
| 66 | |
| 67 | bool InitializeSuperClass(Class* klass); |
| 68 | |
| 69 | void InitializeStaticFields(Class* klass); |
| 70 | |
| 71 | bool ValidateSuperClassDescriptors(const Class* klass); |
| 72 | |
| 73 | bool HasSameDescriptorClasses(const char* descriptor, |
| 74 | const Class* klass1, |
| 75 | const Class* klass2); |
| 76 | |
| 77 | bool HasSameMethodDescriptorClasses(const Method* descriptor, |
| 78 | const Class* klass1, |
| 79 | const Class* klass2); |
| 80 | |
| 81 | bool LinkClass(Class* klass); |
| 82 | |
| 83 | bool LinkSuperClass(Class* klass); |
| 84 | |
| 85 | bool LinkInterfaces(Class* klass); |
| 86 | |
| 87 | bool LinkMethods(Class* klass); |
| 88 | |
| 89 | bool LinkVirtualMethods(Class* klass); |
| 90 | |
| 91 | bool LinkInterfaceMethods(Class* klass); |
| 92 | |
| 93 | void LinkAbstractMethods(Class* klass); |
| 94 | |
| 95 | bool LinkInstanceFields(Class* klass); |
| 96 | |
| 97 | void CreateReferenceOffsets(Class* klass); |
| 98 | |
| 99 | std::vector<DexFile*> class_path_; |
| 100 | |
| 101 | // TODO: multimap |
| 102 | typedef std::map<const char*, Class*, CStringLt> Table; |
| 103 | |
| 104 | Table classes_; |
| 105 | |
| 106 | Mutex* classes_lock_; |
| 107 | |
| 108 | // TODO: classpath |
| 109 | |
Carl Shapiro | 565f507 | 2011-07-10 13:39:43 -0700 | [diff] [blame] | 110 | Class* primitive_boolean_; |
| 111 | Class* primitive_char_; |
| 112 | Class* primitive_float_; |
| 113 | Class* primitive_double_; |
| 114 | Class* primitive_byte_; |
| 115 | Class* primitive_short_; |
| 116 | Class* primitive_int_; |
| 117 | Class* primitive_long_; |
| 118 | Class* primitive_void_; |
| 119 | |
Brian Carlstrom | 934486c | 2011-07-12 23:42:50 -0700 | [diff] [blame] | 120 | Class* java_lang_Object_; |
Carl Shapiro | 565f507 | 2011-07-10 13:39:43 -0700 | [diff] [blame] | 121 | Class* java_lang_Class_; |
| 122 | |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 123 | DISALLOW_COPY_AND_ASSIGN(ClassLinker); |
| 124 | }; |
| 125 | |
| 126 | } // namespace art |
| 127 | |
| 128 | #endif // ART_SRC_CLASS_LINKER_H_ |