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 | |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 10 | #include "dex_file.h" |
Brian Carlstrom | 7e93b50 | 2011-08-04 14:16:22 -0700 | [diff] [blame] | 11 | #include "heap.h" |
| 12 | #include "intern_table.h" |
| 13 | #include "macros.h" |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 14 | #include "object.h" |
Brian Carlstrom | 7e93b50 | 2011-08-04 14:16:22 -0700 | [diff] [blame] | 15 | #include "thread.h" |
| 16 | #include "unordered_map.h" |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 17 | #include "unordered_set.h" |
Brian Carlstrom | 7e93b50 | 2011-08-04 14:16:22 -0700 | [diff] [blame] | 18 | |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 19 | #include "gtest/gtest.h" |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 20 | |
| 21 | namespace art { |
| 22 | |
| 23 | class ClassLinker { |
| 24 | public: |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 25 | // Initializes the class linker using DexFile and an optional boot Space. |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame^] | 26 | static ClassLinker* Create(const std::vector<const DexFile*>& boot_class_path, Space* boot_space); |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 27 | |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame^] | 28 | ~ClassLinker(); |
Carl Shapiro | 565f507 | 2011-07-10 13:39:43 -0700 | [diff] [blame] | 29 | |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 30 | // Finds a class by its descriptor name. |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 31 | // If class_loader is null, searches boot_class_path_. |
Brian Carlstrom | 6cc1845 | 2011-07-18 15:10:33 -0700 | [diff] [blame] | 32 | Class* FindClass(const StringPiece& descriptor, |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame^] | 33 | const ClassLoader* class_loader); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 34 | |
Elliott Hughes | d8ddfd5 | 2011-08-15 14:32:53 -0700 | [diff] [blame] | 35 | Class* FindPrimitiveClass(char type); |
| 36 | |
Brian Carlstrom | 6cc1845 | 2011-07-18 15:10:33 -0700 | [diff] [blame] | 37 | Class* FindSystemClass(const StringPiece& descriptor) { |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 38 | return FindClass(descriptor, NULL); |
Carl Shapiro | 565f507 | 2011-07-10 13:39:43 -0700 | [diff] [blame] | 39 | } |
| 40 | |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame^] | 41 | // Resolve a String with the given ID from the DexFile, storing the |
| 42 | // result in the DexCache. |
| 43 | String* ResolveString(const DexFile& dex_file, |
| 44 | uint32_t string_idx, |
| 45 | DexCache* dex_cache); |
| 46 | |
| 47 | // Resolve a Type with the given ID from the DexFile, storing the |
| 48 | // result in the DexCache. The referrer is used to identity the |
| 49 | // target DexCache and ClassLoader to use for resolution. |
| 50 | Class* ResolveType(const DexFile& dex_file, |
| 51 | uint32_t type_idx, |
| 52 | const Class* referrer) { |
| 53 | return ResolveType(dex_file, |
| 54 | type_idx, |
| 55 | referrer->GetDexCache(), |
| 56 | referrer->GetClassLoader()); |
| 57 | } |
| 58 | |
| 59 | // Resolve a type with the given ID from the DexFile, storing the |
| 60 | // result in DexCache. The ClassLoader is used to search for the |
| 61 | // type, since it may be referenced from but not contained within |
| 62 | // the given DexFile. |
| 63 | Class* ResolveType(const DexFile& dex_file, |
| 64 | uint32_t type_idx, |
| 65 | DexCache* dex_cache, |
| 66 | const ClassLoader* class_loader); |
| 67 | |
| 68 | // Resolve a method with a given ID from the DexFile, storing the |
| 69 | // result in DexCache. The ClassLinker and ClassLoader are used as |
| 70 | // in ResolveType. What is unique is the method type argument which |
| 71 | // is used to determine if this method is a direct, static, or |
| 72 | // virtual method. |
| 73 | Method* ResolveMethod(const DexFile& dex_file, |
| 74 | uint32_t method_idx, |
| 75 | DexCache* dex_cache, |
| 76 | const ClassLoader* class_loader, |
| 77 | /*MethodType*/ int method_type); |
| 78 | |
| 79 | // Resolve a method with a given ID from the DexFile, storing the |
| 80 | // result in DexCache. The ClassLinker and ClassLoader are used as |
| 81 | // in ResolveType. What is unique is the is_static argument which is |
| 82 | // used to determine if we are resolving a static or non-static |
| 83 | // field. |
| 84 | Field* ResolveField(const DexFile& dex_file, |
| 85 | uint32_t field_idx, |
| 86 | DexCache* dex_cache, |
| 87 | const ClassLoader* class_loader, |
| 88 | bool is_static); |
| 89 | |
Elliott Hughes | f4c21c9 | 2011-08-19 17:31:31 -0700 | [diff] [blame] | 90 | // Returns true on success, false if there's an exception pending. |
| 91 | bool EnsureInitialized(Class* c); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 92 | |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame^] | 93 | void RegisterDexFile(const DexFile& dex_file); |
| 94 | void RegisterDexFile(const DexFile& dex_file, DexCache* dex_cache); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 95 | |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 96 | const InternTable& GetInternTable() { |
| 97 | return intern_table_; |
| 98 | } |
| 99 | |
| 100 | void VisitRoots(Heap::RootVistor* root_visitor, void* arg) const; |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 101 | |
buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 102 | const DexFile& FindDexFile(const DexCache* dex_cache) const; |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame^] | 103 | DexCache* FindDexCache(const DexFile& dex_file) const; |
buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 104 | |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 105 | private: |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame^] | 106 | ClassLinker(); |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 107 | |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 108 | // Initialize class linker from DexFile instances. |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame^] | 109 | void Init(const std::vector<const DexFile*>& boot_class_path_); |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 110 | |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 111 | // Initialize class linker from pre-initialized space. |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame^] | 112 | void Init(const std::vector<const DexFile*>& boot_class_path_, Space* space); |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 113 | static void InitCallback(Object* obj, void *arg); |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 114 | struct InitCallbackState; |
| 115 | |
| 116 | void FinishInit(); |
| 117 | |
Elliott Hughes | f4c21c9 | 2011-08-19 17:31:31 -0700 | [diff] [blame] | 118 | bool InitializeClass(Class* klass); |
| 119 | |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 120 | // For early bootstrapping by Init |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 121 | Class* AllocClass(Class* java_lang_Class, size_t class_size); |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 122 | |
| 123 | // Alloc* convenience functions to avoid needing to pass in Class* |
| 124 | // values that are known to the ClassLinker such as |
| 125 | // kObjectArrayClass and kJavaLangString etc. |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 126 | Class* AllocClass(size_t class_size); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame^] | 127 | DexCache* AllocDexCache(const DexFile& dex_file); |
Jesse Wilson | 35baaab | 2011-08-10 16:18:03 -0400 | [diff] [blame] | 128 | Field* AllocField(); |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 129 | Method* AllocMethod(); |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 130 | template <class T> |
| 131 | ObjectArray<T>* AllocObjectArray(size_t length) { |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 132 | return ObjectArray<T>::Alloc(GetClassRoot(kObjectArrayClass), length); |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 133 | } |
| 134 | |
Brian Carlstrom | 9cff8e1 | 2011-08-18 16:47:29 -0700 | [diff] [blame] | 135 | Class* CreatePrimitiveClass(const char* descriptor); |
Brian Carlstrom | a331b3c | 2011-07-18 17:47:56 -0700 | [diff] [blame] | 136 | |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 137 | Class* CreateArrayClass(const StringPiece& descriptor, |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame^] | 138 | const ClassLoader* class_loader); |
Brian Carlstrom | a331b3c | 2011-07-18 17:47:56 -0700 | [diff] [blame] | 139 | |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame^] | 140 | void AppendToBootClassPath(const DexFile& dex_file); |
| 141 | void AppendToBootClassPath(const DexFile& dex_file, DexCache* dex_cache); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 142 | |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 143 | size_t SizeOfClass(const DexFile& dex_file, |
| 144 | const DexFile::ClassDef& dex_class_def); |
| 145 | |
Brian Carlstrom | f615a61 | 2011-07-23 12:50:34 -0700 | [diff] [blame] | 146 | void LoadClass(const DexFile& dex_file, |
| 147 | const DexFile::ClassDef& dex_class_def, |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 148 | Class* klass, |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame^] | 149 | const ClassLoader* class_loader); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 150 | |
Brian Carlstrom | f615a61 | 2011-07-23 12:50:34 -0700 | [diff] [blame] | 151 | void LoadInterfaces(const DexFile& dex_file, |
| 152 | const DexFile::ClassDef& dex_class_def, |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 153 | Class *klass); |
| 154 | |
Brian Carlstrom | f615a61 | 2011-07-23 12:50:34 -0700 | [diff] [blame] | 155 | void LoadField(const DexFile& dex_file, |
| 156 | const DexFile::Field& dex_field, |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 157 | Class* klass, |
| 158 | Field* dst); |
| 159 | |
Brian Carlstrom | f615a61 | 2011-07-23 12:50:34 -0700 | [diff] [blame] | 160 | void LoadMethod(const DexFile& dex_file, |
| 161 | const DexFile::Method& dex_method, |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 162 | Class* klass, |
| 163 | Method* dst); |
Brian Carlstrom | 934486c | 2011-07-12 23:42:50 -0700 | [diff] [blame] | 164 | |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame^] | 165 | Class* LookupClass(const StringPiece& descriptor, const ClassLoader* class_loader); |
Brian Carlstrom | 7e93b50 | 2011-08-04 14:16:22 -0700 | [diff] [blame] | 166 | |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 167 | // Inserts a class into the class table. Returns true if the class |
| 168 | // was inserted. |
Brian Carlstrom | 9cff8e1 | 2011-08-18 16:47:29 -0700 | [diff] [blame] | 169 | bool InsertClass(const StringPiece& descriptor, Class* klass); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 170 | |
| 171 | bool InitializeSuperClass(Class* klass); |
| 172 | |
| 173 | void InitializeStaticFields(Class* klass); |
| 174 | |
| 175 | bool ValidateSuperClassDescriptors(const Class* klass); |
| 176 | |
| 177 | bool HasSameDescriptorClasses(const char* descriptor, |
| 178 | const Class* klass1, |
| 179 | const Class* klass2); |
| 180 | |
| 181 | bool HasSameMethodDescriptorClasses(const Method* descriptor, |
| 182 | const Class* klass1, |
| 183 | const Class* klass2); |
| 184 | |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 185 | bool LinkClass(Class* klass, const DexFile& dex_file); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 186 | |
| 187 | bool LinkSuperClass(Class* klass); |
| 188 | |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 189 | bool LoadSuperAndInterfaces(Class* klass, const DexFile& dex_file); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 190 | |
| 191 | bool LinkMethods(Class* klass); |
| 192 | |
| 193 | bool LinkVirtualMethods(Class* klass); |
| 194 | |
| 195 | bool LinkInterfaceMethods(Class* klass); |
| 196 | |
| 197 | void LinkAbstractMethods(Class* klass); |
| 198 | |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 199 | bool LinkStaticFields(Class* klass); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 200 | bool LinkInstanceFields(Class* klass); |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 201 | bool LinkFields(size_t field_offset, |
| 202 | size_t& num_reference_fields, |
| 203 | size_t num_fields, |
| 204 | ObjectArray<Field>* fields, |
| 205 | size_t& size); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 206 | |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 207 | void CreateReferenceInstanceOffsets(Class* klass); |
| 208 | void CreateReferenceStaticOffsets(Class* klass); |
| 209 | void CreateReferenceOffsets(uint32_t& reference_offsets, |
| 210 | size_t num_reference_fields, |
| 211 | const ObjectArray<Field>* fields); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 212 | |
Brian Carlstrom | 4a96b60 | 2011-07-26 16:40:23 -0700 | [diff] [blame] | 213 | std::vector<const DexFile*> boot_class_path_; |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 214 | |
Brian Carlstrom | 4a96b60 | 2011-07-26 16:40:23 -0700 | [diff] [blame] | 215 | std::vector<const DexFile*> dex_files_; |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 216 | |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 217 | std::vector<DexCache*> dex_caches_; |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 218 | |
Brian Carlstrom | 9cff8e1 | 2011-08-18 16:47:29 -0700 | [diff] [blame] | 219 | // multimap from a StringPiece hash code of a class descriptor to |
| 220 | // Class* instances. Results should be compared for a matching |
| 221 | // Class::descriptor_ and Class::class_loader_. |
| 222 | typedef std::tr1::unordered_multimap<size_t, Class*> Table; |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 223 | Table classes_; |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 224 | Mutex* classes_lock_; |
| 225 | |
Brian Carlstrom | 7e93b50 | 2011-08-04 14:16:22 -0700 | [diff] [blame] | 226 | InternTable intern_table_; |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 227 | |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 228 | // indexes into class_roots_. |
| 229 | // needs to be kept in sync with class_roots_descriptors_. |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 230 | enum ClassRoot { |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 231 | kJavaLangClass, |
| 232 | kJavaLangObject, |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 233 | kObjectArrayClass, |
| 234 | kJavaLangString, |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 235 | kJavaLangReflectField, |
| 236 | kJavaLangReflectMethod, |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 237 | kJavaLangClassLoader, |
| 238 | kDalvikSystemBaseDexClassLoader, |
| 239 | kDalvikSystemPathClassLoader, |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 240 | kPrimitiveBoolean, |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 241 | kPrimitiveByte, |
Elliott Hughes | d8ddfd5 | 2011-08-15 14:32:53 -0700 | [diff] [blame] | 242 | kPrimitiveChar, |
| 243 | kPrimitiveDouble, |
| 244 | kPrimitiveFloat, |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 245 | kPrimitiveInt, |
| 246 | kPrimitiveLong, |
Elliott Hughes | d8ddfd5 | 2011-08-15 14:32:53 -0700 | [diff] [blame] | 247 | kPrimitiveShort, |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 248 | kPrimitiveVoid, |
Elliott Hughes | d8ddfd5 | 2011-08-15 14:32:53 -0700 | [diff] [blame] | 249 | kBooleanArrayClass, |
| 250 | kByteArrayClass, |
| 251 | kCharArrayClass, |
| 252 | kDoubleArrayClass, |
| 253 | kFloatArrayClass, |
| 254 | kIntArrayClass, |
| 255 | kLongArrayClass, |
| 256 | kShortArrayClass, |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 257 | kClassRootsMax, |
| 258 | }; |
| 259 | ObjectArray<Class>* class_roots_; |
Brian Carlstrom | 913af1b | 2011-07-23 21:41:13 -0700 | [diff] [blame] | 260 | |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 261 | Class* GetClassRoot(ClassRoot class_root) { |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 262 | DCHECK(class_roots_ != NULL); |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 263 | Class* klass = class_roots_->Get(class_root); |
| 264 | DCHECK(klass != NULL); |
| 265 | return klass; |
| 266 | } |
| 267 | |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 268 | void SetClassRoot(ClassRoot class_root, Class* klass) { |
| 269 | DCHECK(!init_done_); |
| 270 | |
| 271 | DCHECK(klass != NULL); |
| 272 | DCHECK(klass->class_loader_ == NULL); |
| 273 | DCHECK(klass->descriptor_ != NULL); |
| 274 | DCHECK(klass->descriptor_->Equals(GetClassRootDescriptor(class_root))); |
| 275 | |
| 276 | DCHECK(class_roots_ != NULL); |
| 277 | DCHECK(class_roots_->Get(class_root) == NULL); |
| 278 | class_roots_->Set(class_root, klass); |
| 279 | } |
| 280 | |
| 281 | static const char* class_roots_descriptors_[kClassRootsMax]; |
| 282 | |
| 283 | const char* GetClassRootDescriptor(ClassRoot class_root) { |
| 284 | const char* descriptor = class_roots_descriptors_[class_root]; |
| 285 | CHECK(descriptor != NULL); |
| 286 | return descriptor; |
| 287 | } |
| 288 | |
Brian Carlstrom | 4a96b60 | 2011-07-26 16:40:23 -0700 | [diff] [blame] | 289 | ObjectArray<Class>* array_interfaces_; |
Brian Carlstrom | 913af1b | 2011-07-23 21:41:13 -0700 | [diff] [blame] | 290 | InterfaceEntry* array_iftable_; |
Carl Shapiro | 565f507 | 2011-07-10 13:39:43 -0700 | [diff] [blame] | 291 | |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 292 | bool init_done_; |
| 293 | |
Brian Carlstrom | f734cf5 | 2011-08-17 16:28:14 -0700 | [diff] [blame] | 294 | friend class CommonTest; |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 295 | FRIEND_TEST(DexCacheTest, Open); |
| 296 | friend class ObjectTest; |
| 297 | FRIEND_TEST(ObjectTest, AllocObjectArray); |
Shih-wei Liao | 1a18c8c | 2011-08-14 17:47:36 -0700 | [diff] [blame] | 298 | FRIEND_TEST(ExceptionTest, FindExceptionHandler); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 299 | DISALLOW_COPY_AND_ASSIGN(ClassLinker); |
| 300 | }; |
| 301 | |
| 302 | } // namespace art |
| 303 | |
| 304 | #endif // ART_SRC_CLASS_LINKER_H_ |