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