blob: 939fa5546a66be9b5e7bfaabb6bf74b5beb38536 [file] [log] [blame]
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001// 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 Carlstrom7e49dca2011-07-22 18:07:34 -070010#include "dex_file.h"
Brian Carlstrom7e93b502011-08-04 14:16:22 -070011#include "heap.h"
Brian Carlstrom7e93b502011-08-04 14:16:22 -070012#include "macros.h"
Elliott Hughes8daa0922011-09-11 13:46:25 -070013#include "mutex.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070014#include "object.h"
Brian Carlstrom7e93b502011-08-04 14:16:22 -070015#include "unordered_map.h"
Brian Carlstroma663ea52011-08-19 23:33:41 -070016#include "unordered_set.h"
Brian Carlstrom7e93b502011-08-04 14:16:22 -070017
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070018#include "gtest/gtest.h"
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070019
20namespace art {
21
Elliott Hughescf4c6c42011-09-01 15:16:42 -070022class ClassLoader;
23class InternTable;
24
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070025class ClassLinker {
26 public:
Brian Carlstromc74255f2011-09-11 22:47:39 -070027 // Initializes the class linker using DexFiles and an optional an image.
Elliott Hughescf4c6c42011-09-01 15:16:42 -070028 static ClassLinker* Create(const std::vector<const DexFile*>& boot_class_path,
Brian Carlstrom69b15fb2011-09-03 12:25:21 -070029 const std::vector<const DexFile*>& class_path,
Brian Carlstromc74255f2011-09-11 22:47:39 -070030 InternTable* intern_table, bool image);
Carl Shapiro61e019d2011-07-14 16:53:09 -070031
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070032 ~ClassLinker();
Carl Shapiro565f5072011-07-10 13:39:43 -070033
Elliott Hughes64bf5a32011-09-20 14:43:12 -070034 // Finds a class by its descriptor, loading it if necessary.
Brian Carlstrom74eb46a2011-08-02 20:10:14 -070035 // If class_loader is null, searches boot_class_path_.
Elliott Hughes64bf5a32011-09-20 14:43:12 -070036 Class* FindClass(const StringPiece& descriptor, const ClassLoader* class_loader);
37
38 // Finds a class by its descriptor, returning NULL if it isn't wasn't loaded
39 // by the given 'class_loader'.
40 Class* LookupClass(const StringPiece& descriptor, const ClassLoader* class_loader);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070041
Elliott Hughesd8ddfd52011-08-15 14:32:53 -070042 Class* FindPrimitiveClass(char type);
43
Brian Carlstrom6cc18452011-07-18 15:10:33 -070044 Class* FindSystemClass(const StringPiece& descriptor) {
Brian Carlstrom74eb46a2011-08-02 20:10:14 -070045 return FindClass(descriptor, NULL);
Carl Shapiro565f5072011-07-10 13:39:43 -070046 }
47
Elliott Hughes9d5ccec2011-09-19 13:19:50 -070048 void DumpAllClasses(int flags) const;
49
Elliott Hughese27955c2011-08-26 15:21:24 -070050 size_t NumLoadedClasses() const;
51
Brian Carlstromb63ec392011-08-27 17:38:27 -070052 // Resolve a String with the given index from the DexFile, storing the
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070053 // result in the DexCache.
Ian Rogers0cfe1fb2011-08-26 03:29:44 -070054 String* ResolveString(const DexFile& dex_file, uint32_t string_idx, DexCache* dex_cache);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070055
Brian Carlstromb63ec392011-08-27 17:38:27 -070056 // Resolve a Type with the given index from the DexFile, storing the
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070057 // result in the DexCache. The referrer is used to identity the
58 // target DexCache and ClassLoader to use for resolution.
59 Class* ResolveType(const DexFile& dex_file,
60 uint32_t type_idx,
61 const Class* referrer) {
62 return ResolveType(dex_file,
63 type_idx,
64 referrer->GetDexCache(),
65 referrer->GetClassLoader());
66 }
67
Brian Carlstromb63ec392011-08-27 17:38:27 -070068 // Resolve a Type with the given index from the DexFile, storing the
Ian Rogers0cfe1fb2011-08-26 03:29:44 -070069 // result in the DexCache. The referrer is used to identify the
Brian Carlstromb63ec392011-08-27 17:38:27 -070070 // target DexCache and ClassLoader to use for resolution.
Brian Carlstromb9edb842011-08-28 16:31:06 -070071 Class* ResolveType(uint32_t type_idx, const Method* referrer) {
Brian Carlstromb63ec392011-08-27 17:38:27 -070072 Class* declaring_class = referrer->GetDeclaringClass();
73 DexCache* dex_cache = declaring_class->GetDexCache();
Ian Rogers0cfe1fb2011-08-26 03:29:44 -070074 // TODO: we could check for a dex cache hit here
75 const ClassLoader* class_loader = declaring_class->GetClassLoader();
76 const DexFile& dex_file = FindDexFile(dex_cache);
77 return ResolveType(dex_file, type_idx, dex_cache, class_loader);
78 }
79
80 Class* ResolveType(uint32_t type_idx, const Field* referrer) {
81 Class* declaring_class = referrer->GetDeclaringClass();
82 DexCache* dex_cache = declaring_class->GetDexCache();
83 // TODO: we could check for a dex cache hit here
Brian Carlstromb63ec392011-08-27 17:38:27 -070084 const ClassLoader* class_loader = declaring_class->GetClassLoader();
85 const DexFile& dex_file = FindDexFile(dex_cache);
86 return ResolveType(dex_file, type_idx, dex_cache, class_loader);
87 }
88
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070089 // Resolve a type with the given ID from the DexFile, storing the
90 // result in DexCache. The ClassLoader is used to search for the
91 // type, since it may be referenced from but not contained within
92 // the given DexFile.
93 Class* ResolveType(const DexFile& dex_file,
94 uint32_t type_idx,
95 DexCache* dex_cache,
96 const ClassLoader* class_loader);
97
Brian Carlstromb9edb842011-08-28 16:31:06 -070098 static StaticStorageBase* InitializeStaticStorageFromCode(uint32_t type_idx,
99 const Method* referrer);
Brian Carlstrom1caa2c22011-08-28 13:02:33 -0700100
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700101 // Resolve a method with a given ID from the DexFile, storing the
102 // result in DexCache. The ClassLinker and ClassLoader are used as
103 // in ResolveType. What is unique is the method type argument which
104 // is used to determine if this method is a direct, static, or
105 // virtual method.
106 Method* ResolveMethod(const DexFile& dex_file,
107 uint32_t method_idx,
108 DexCache* dex_cache,
109 const ClassLoader* class_loader,
Brian Carlstrom20cfffa2011-08-26 02:31:27 -0700110 bool is_direct);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700111
Brian Carlstrom16192862011-09-12 17:50:06 -0700112 Method* ResolveMethod(uint32_t method_idx, const Method* referrer, bool is_direct) {
113 Class* declaring_class = referrer->GetDeclaringClass();
114 DexCache* dex_cache = declaring_class->GetDexCache();
115 // TODO: we could check for a dex cache hit here
116 const ClassLoader* class_loader = declaring_class->GetClassLoader();
117 const DexFile& dex_file = FindDexFile(dex_cache);
118 return ResolveMethod(dex_file, method_idx, dex_cache, class_loader, is_direct);
119 }
120
Brian Carlstrom845490b2011-09-19 15:56:53 -0700121 Field* ResolveField(uint32_t field_idx, const Method* referrer, bool is_static) {
Brian Carlstromb9edb842011-08-28 16:31:06 -0700122 Class* declaring_class = referrer->GetDeclaringClass();
123 DexCache* dex_cache = declaring_class->GetDexCache();
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700124 // TODO: we could check for a dex cache hit here
Brian Carlstromb9edb842011-08-28 16:31:06 -0700125 const ClassLoader* class_loader = declaring_class->GetClassLoader();
126 const DexFile& dex_file = FindDexFile(dex_cache);
Brian Carlstrom845490b2011-09-19 15:56:53 -0700127 return ResolveField(dex_file, field_idx, dex_cache, class_loader, is_static);
Brian Carlstromb9edb842011-08-28 16:31:06 -0700128 }
129
Brian Carlstrom16192862011-09-12 17:50:06 -0700130 // Resolve a field with a given ID from the DexFile, storing the
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700131 // result in DexCache. The ClassLinker and ClassLoader are used as
132 // in ResolveType. What is unique is the is_static argument which is
133 // used to determine if we are resolving a static or non-static
134 // field.
135 Field* ResolveField(const DexFile& dex_file,
136 uint32_t field_idx,
137 DexCache* dex_cache,
138 const ClassLoader* class_loader,
139 bool is_static);
140
Elliott Hughesf4c21c92011-08-19 17:31:31 -0700141 // Returns true on success, false if there's an exception pending.
Brian Carlstrom25c33252011-09-18 15:58:35 -0700142 // can_run_clinit=false allows the compiler to attempt to init a class,
143 // given the restriction that no <clinit> execution is possible.
144 bool EnsureInitialized(Class* c, bool can_run_clinit);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700145
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700146 void RegisterDexFile(const DexFile& dex_file);
147 void RegisterDexFile(const DexFile& dex_file, DexCache* dex_cache);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700148
Brian Carlstrom8a487412011-08-29 20:08:52 -0700149 const std::vector<const DexFile*>& GetBootClassPath() {
150 return boot_class_path_;
151 }
152
Elliott Hughes410c0c82011-09-01 17:58:25 -0700153 void VisitRoots(Heap::RootVisitor* visitor, void* arg) const;
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700154
buzbeec143c552011-08-20 17:38:58 -0700155 const DexFile& FindDexFile(const DexCache* dex_cache) const;
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700156 DexCache* FindDexCache(const DexFile& dex_file) const;
buzbeec143c552011-08-20 17:38:58 -0700157
Shih-wei Liao44175362011-08-28 16:59:17 -0700158 template <class T>
159 ObjectArray<T>* AllocObjectArray(size_t length) {
160 return ObjectArray<T>::Alloc(GetClassRoot(kObjectArrayClass), length);
161 }
162
Shih-wei Liao55df06b2011-08-26 14:39:27 -0700163 ObjectArray<StackTraceElement>* AllocStackTraceElementArray(size_t length);
164
jeffhao98eacac2011-09-14 16:11:53 -0700165 void VerifyClass(Class* klass);
166
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700167 private:
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700168 ClassLinker(InternTable*);
Carl Shapiro61e019d2011-07-14 16:53:09 -0700169
Brian Carlstroma663ea52011-08-19 23:33:41 -0700170 // Initialize class linker from DexFile instances.
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700171 void Init(const std::vector<const DexFile*>& boot_class_path_,
172 const std::vector<const DexFile*>& class_path_);
Carl Shapiro61e019d2011-07-14 16:53:09 -0700173
Brian Carlstromc74255f2011-09-11 22:47:39 -0700174 // Initialize class linker from pre-initialized image.
175 void InitFromImage(const std::vector<const DexFile*>& boot_class_path_,
176 const std::vector<const DexFile*>& class_path_);
Brian Carlstrom78128a62011-09-15 17:21:19 -0700177 static void InitFromImageCallback(Object* obj, void* arg);
Brian Carlstromc74255f2011-09-11 22:47:39 -0700178 struct InitFromImageCallbackState;
Brian Carlstroma663ea52011-08-19 23:33:41 -0700179
180 void FinishInit();
181
Brian Carlstrom25c33252011-09-18 15:58:35 -0700182 bool InitializeClass(Class* klass, bool can_run_clinit);
Elliott Hughesf4c21c92011-08-19 17:31:31 -0700183
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700184 // For early bootstrapping by Init
Brian Carlstrom4873d462011-08-21 15:23:39 -0700185 Class* AllocClass(Class* java_lang_Class, size_t class_size);
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700186
187 // Alloc* convenience functions to avoid needing to pass in Class*
188 // values that are known to the ClassLinker such as
189 // kObjectArrayClass and kJavaLangString etc.
Brian Carlstrom4873d462011-08-21 15:23:39 -0700190 Class* AllocClass(size_t class_size);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700191 DexCache* AllocDexCache(const DexFile& dex_file);
Jesse Wilson35baaab2011-08-10 16:18:03 -0400192 Field* AllocField();
Ian Rogersbdb03912011-09-14 00:55:44 -0700193
194 // TODO: have no friends, we need this currently to create a special method
195 // to describe callee save registers for throwing exceptions
196 friend class Thread;
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700197 Method* AllocMethod();
Ian Rogersbdb03912011-09-14 00:55:44 -0700198
Brian Carlstrom9cc262e2011-08-28 12:45:30 -0700199 CodeAndDirectMethods* AllocCodeAndDirectMethods(size_t length);
Brian Carlstrom4b620ff2011-09-11 01:11:01 -0700200 InterfaceEntry* AllocInterfaceEntry(Class* interface);
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700201
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700202 Class* CreatePrimitiveClass(const char* descriptor,
Brian Carlstrom5b8e4c82011-09-18 01:38:59 -0700203 Class::PrimitiveType type) {
204 return InitializePrimitiveClass(AllocClass(sizeof(Class)), descriptor, type);
205 }
206 Class* InitializePrimitiveClass(Class* primitive_class,
207 const char* descriptor,
208 Class::PrimitiveType type);
209
Brian Carlstroma331b3c2011-07-18 17:47:56 -0700210
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700211 Class* CreateArrayClass(const StringPiece& descriptor,
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700212 const ClassLoader* class_loader);
Brian Carlstroma331b3c2011-07-18 17:47:56 -0700213
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700214 void AppendToBootClassPath(const DexFile& dex_file);
215 void AppendToBootClassPath(const DexFile& dex_file, DexCache* dex_cache);
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700216
Elliott Hughes5fe594f2011-09-08 12:33:17 -0700217 void ConstructFieldMap(const DexFile& dex_file, const DexFile::ClassDef& dex_class_def,
218 Class* c, std::map<int, Field*>& field_map);
219
Brian Carlstrom4873d462011-08-21 15:23:39 -0700220 size_t SizeOfClass(const DexFile& dex_file,
221 const DexFile::ClassDef& dex_class_def);
222
Brian Carlstromf615a612011-07-23 12:50:34 -0700223 void LoadClass(const DexFile& dex_file,
224 const DexFile::ClassDef& dex_class_def,
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700225 Class* klass,
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700226 const ClassLoader* class_loader);
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700227
Brian Carlstromf615a612011-07-23 12:50:34 -0700228 void LoadInterfaces(const DexFile& dex_file,
229 const DexFile::ClassDef& dex_class_def,
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700230 Class *klass);
231
Brian Carlstromf615a612011-07-23 12:50:34 -0700232 void LoadField(const DexFile& dex_file,
233 const DexFile::Field& dex_field,
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700234 Class* klass,
235 Field* dst);
236
Brian Carlstromf615a612011-07-23 12:50:34 -0700237 void LoadMethod(const DexFile& dex_file,
238 const DexFile::Method& dex_method,
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700239 Class* klass,
Brian Carlstrom1f870082011-08-23 16:02:11 -0700240 Method* dst);
Brian Carlstrom934486c2011-07-12 23:42:50 -0700241
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700242 // Inserts a class into the class table. Returns true if the class
243 // was inserted.
Brian Carlstrom9cff8e12011-08-18 16:47:29 -0700244 bool InsertClass(const StringPiece& descriptor, Class* klass);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700245
Brian Carlstrom25c33252011-09-18 15:58:35 -0700246 bool InitializeSuperClass(Class* klass, bool can_run_clinit);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700247
248 void InitializeStaticFields(Class* klass);
249
250 bool ValidateSuperClassDescriptors(const Class* klass);
251
252 bool HasSameDescriptorClasses(const char* descriptor,
253 const Class* klass1,
254 const Class* klass2);
255
256 bool HasSameMethodDescriptorClasses(const Method* descriptor,
257 const Class* klass1,
258 const Class* klass2);
259
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700260 bool LinkClass(Class* klass);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700261
262 bool LinkSuperClass(Class* klass);
263
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700264 bool LoadSuperAndInterfaces(Class* klass, const DexFile& dex_file);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700265
266 bool LinkMethods(Class* klass);
267
268 bool LinkVirtualMethods(Class* klass);
269
270 bool LinkInterfaceMethods(Class* klass);
271
Jesse Wilson7833bd22011-08-09 18:31:44 -0400272 bool LinkStaticFields(Class* klass);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700273 bool LinkInstanceFields(Class* klass);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700274 bool LinkFields(Class *klass, bool instance);
275
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700276
Brian Carlstrom4873d462011-08-21 15:23:39 -0700277 void CreateReferenceInstanceOffsets(Class* klass);
278 void CreateReferenceStaticOffsets(Class* klass);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700279 void CreateReferenceOffsets(Class *klass, bool instance,
280 uint32_t reference_offsets);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700281
Brian Carlstrom16192862011-09-12 17:50:06 -0700282 // lock to protect ClassLinker state
283 mutable Mutex lock_;
284
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700285 std::vector<const DexFile*> boot_class_path_;
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700286
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700287 std::vector<const DexFile*> dex_files_;
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700288 std::vector<DexCache*> dex_caches_;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700289
Brian Carlstrom9cff8e12011-08-18 16:47:29 -0700290 // multimap from a StringPiece hash code of a class descriptor to
291 // Class* instances. Results should be compared for a matching
292 // Class::descriptor_ and Class::class_loader_.
293 typedef std::tr1::unordered_multimap<size_t, Class*> Table;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700294 Table classes_;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700295
Brian Carlstroma663ea52011-08-19 23:33:41 -0700296 // indexes into class_roots_.
297 // needs to be kept in sync with class_roots_descriptors_.
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700298 enum ClassRoot {
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700299 kJavaLangClass,
300 kJavaLangObject,
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700301 kObjectArrayClass,
302 kJavaLangString,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700303 kJavaLangReflectField,
304 kJavaLangReflectMethod,
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700305 kJavaLangClassLoader,
306 kDalvikSystemBaseDexClassLoader,
307 kDalvikSystemPathClassLoader,
Shih-wei Liao55df06b2011-08-26 14:39:27 -0700308 kJavaLangStackTraceElement,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700309 kPrimitiveBoolean,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700310 kPrimitiveByte,
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700311 kPrimitiveChar,
312 kPrimitiveDouble,
313 kPrimitiveFloat,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700314 kPrimitiveInt,
315 kPrimitiveLong,
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700316 kPrimitiveShort,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700317 kPrimitiveVoid,
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700318 kBooleanArrayClass,
319 kByteArrayClass,
320 kCharArrayClass,
321 kDoubleArrayClass,
322 kFloatArrayClass,
323 kIntArrayClass,
324 kLongArrayClass,
325 kShortArrayClass,
Shih-wei Liao55df06b2011-08-26 14:39:27 -0700326 kJavaLangStackTraceElementArrayClass,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700327 kClassRootsMax,
328 };
329 ObjectArray<Class>* class_roots_;
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700330
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700331 Class* GetClassRoot(ClassRoot class_root) {
Brian Carlstroma663ea52011-08-19 23:33:41 -0700332 DCHECK(class_roots_ != NULL);
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700333 Class* klass = class_roots_->Get(class_root);
334 DCHECK(klass != NULL);
335 return klass;
336 }
337
Brian Carlstroma663ea52011-08-19 23:33:41 -0700338 void SetClassRoot(ClassRoot class_root, Class* klass) {
339 DCHECK(!init_done_);
340
341 DCHECK(klass != NULL);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700342 DCHECK(klass->GetClassLoader() == NULL);
343 DCHECK(klass->GetDescriptor() != NULL);
344 DCHECK(klass->GetDescriptor()->Equals(GetClassRootDescriptor(class_root)));
Brian Carlstroma663ea52011-08-19 23:33:41 -0700345
346 DCHECK(class_roots_ != NULL);
347 DCHECK(class_roots_->Get(class_root) == NULL);
348 class_roots_->Set(class_root, klass);
349 }
350
351 static const char* class_roots_descriptors_[kClassRootsMax];
352
353 const char* GetClassRootDescriptor(ClassRoot class_root) {
354 const char* descriptor = class_roots_descriptors_[class_root];
355 CHECK(descriptor != NULL);
356 return descriptor;
357 }
358
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700359 ObjectArray<Class>* array_interfaces_;
Brian Carlstrom4b620ff2011-09-11 01:11:01 -0700360 ObjectArray<InterfaceEntry>* array_iftable_;
Carl Shapiro565f5072011-07-10 13:39:43 -0700361
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700362 bool init_done_;
363
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700364 InternTable* intern_table_;
365
Brian Carlstromf734cf52011-08-17 16:28:14 -0700366 friend class CommonTest;
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700367 FRIEND_TEST(DexCacheTest, Open);
368 friend class ObjectTest;
369 FRIEND_TEST(ObjectTest, AllocObjectArray);
Shih-wei Liao1a18c8c2011-08-14 17:47:36 -0700370 FRIEND_TEST(ExceptionTest, FindExceptionHandler);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700371 DISALLOW_COPY_AND_ASSIGN(ClassLinker);
372};
373
374} // namespace art
375
376#endif // ART_SRC_CLASS_LINKER_H_