blob: 09736ce85004f08a45e3282f28bcdc074104aa50 [file] [log] [blame]
Elliott Hughes418d20f2011-09-22 14:00:39 -07001/*
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 */
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070016
17#ifndef ART_SRC_CLASS_LINKER_H_
18#define ART_SRC_CLASS_LINKER_H_
19
20#include <map>
21#include <utility>
22#include <vector>
23
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070024#include "dex_file.h"
Brian Carlstrom7e93b502011-08-04 14:16:22 -070025#include "heap.h"
Brian Carlstrom7e93b502011-08-04 14:16:22 -070026#include "macros.h"
Elliott Hughes8daa0922011-09-11 13:46:25 -070027#include "mutex.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070028#include "object.h"
Brian Carlstrom7e93b502011-08-04 14:16:22 -070029#include "unordered_map.h"
Brian Carlstroma663ea52011-08-19 23:33:41 -070030#include "unordered_set.h"
Brian Carlstrom7e93b502011-08-04 14:16:22 -070031
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070032#include "gtest/gtest.h"
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070033
34namespace art {
35
Elliott Hughescf4c6c42011-09-01 15:16:42 -070036class ClassLoader;
37class InternTable;
38
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070039class ClassLinker {
40 public:
Brian Carlstromc74255f2011-09-11 22:47:39 -070041 // Initializes the class linker using DexFiles and an optional an image.
Elliott Hughescf4c6c42011-09-01 15:16:42 -070042 static ClassLinker* Create(const std::vector<const DexFile*>& boot_class_path,
Brian Carlstrom69b15fb2011-09-03 12:25:21 -070043 const std::vector<const DexFile*>& class_path,
Brian Carlstromc74255f2011-09-11 22:47:39 -070044 InternTable* intern_table, bool image);
Carl Shapiro61e019d2011-07-14 16:53:09 -070045
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070046 ~ClassLinker();
Carl Shapiro565f5072011-07-10 13:39:43 -070047
Elliott Hughes64bf5a32011-09-20 14:43:12 -070048 // Finds a class by its descriptor, loading it if necessary.
Brian Carlstrom74eb46a2011-08-02 20:10:14 -070049 // If class_loader is null, searches boot_class_path_.
Elliott Hughes64bf5a32011-09-20 14:43:12 -070050 Class* FindClass(const StringPiece& descriptor, const ClassLoader* class_loader);
51
52 // Finds a class by its descriptor, returning NULL if it isn't wasn't loaded
53 // by the given 'class_loader'.
54 Class* LookupClass(const StringPiece& descriptor, const ClassLoader* class_loader);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070055
Elliott Hughesd8ddfd52011-08-15 14:32:53 -070056 Class* FindPrimitiveClass(char type);
57
Brian Carlstrom6cc18452011-07-18 15:10:33 -070058 Class* FindSystemClass(const StringPiece& descriptor) {
Brian Carlstrom74eb46a2011-08-02 20:10:14 -070059 return FindClass(descriptor, NULL);
Carl Shapiro565f5072011-07-10 13:39:43 -070060 }
61
Elliott Hughes9d5ccec2011-09-19 13:19:50 -070062 void DumpAllClasses(int flags) const;
63
Elliott Hughese27955c2011-08-26 15:21:24 -070064 size_t NumLoadedClasses() const;
65
Brian Carlstromb63ec392011-08-27 17:38:27 -070066 // Resolve a String with the given index from the DexFile, storing the
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070067 // result in the DexCache.
Ian Rogers0cfe1fb2011-08-26 03:29:44 -070068 String* ResolveString(const DexFile& dex_file, uint32_t string_idx, DexCache* dex_cache);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070069
Brian Carlstromb63ec392011-08-27 17:38:27 -070070 // Resolve a Type with the given index from the DexFile, storing the
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070071 // result in the DexCache. The referrer is used to identity the
72 // target DexCache and ClassLoader to use for resolution.
73 Class* ResolveType(const DexFile& dex_file,
74 uint32_t type_idx,
75 const Class* referrer) {
76 return ResolveType(dex_file,
77 type_idx,
78 referrer->GetDexCache(),
79 referrer->GetClassLoader());
80 }
81
Brian Carlstromb63ec392011-08-27 17:38:27 -070082 // Resolve a Type with the given index from the DexFile, storing the
Ian Rogers0cfe1fb2011-08-26 03:29:44 -070083 // result in the DexCache. The referrer is used to identify the
Brian Carlstromb63ec392011-08-27 17:38:27 -070084 // target DexCache and ClassLoader to use for resolution.
Brian Carlstromb9edb842011-08-28 16:31:06 -070085 Class* ResolveType(uint32_t type_idx, const Method* referrer) {
Brian Carlstromb63ec392011-08-27 17:38:27 -070086 Class* declaring_class = referrer->GetDeclaringClass();
87 DexCache* dex_cache = declaring_class->GetDexCache();
Ian Rogers0cfe1fb2011-08-26 03:29:44 -070088 // TODO: we could check for a dex cache hit here
89 const ClassLoader* class_loader = declaring_class->GetClassLoader();
90 const DexFile& dex_file = FindDexFile(dex_cache);
91 return ResolveType(dex_file, type_idx, dex_cache, class_loader);
92 }
93
94 Class* ResolveType(uint32_t type_idx, const Field* referrer) {
95 Class* declaring_class = referrer->GetDeclaringClass();
96 DexCache* dex_cache = declaring_class->GetDexCache();
97 // TODO: we could check for a dex cache hit here
Brian Carlstromb63ec392011-08-27 17:38:27 -070098 const ClassLoader* class_loader = declaring_class->GetClassLoader();
99 const DexFile& dex_file = FindDexFile(dex_cache);
100 return ResolveType(dex_file, type_idx, dex_cache, class_loader);
101 }
102
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700103 // Resolve a type with the given ID from the DexFile, storing the
104 // result in DexCache. The ClassLoader is used to search for the
105 // type, since it may be referenced from but not contained within
106 // the given DexFile.
107 Class* ResolveType(const DexFile& dex_file,
108 uint32_t type_idx,
109 DexCache* dex_cache,
110 const ClassLoader* class_loader);
111
Brian Carlstromb9edb842011-08-28 16:31:06 -0700112 static StaticStorageBase* InitializeStaticStorageFromCode(uint32_t type_idx,
113 const Method* referrer);
Brian Carlstrom1caa2c22011-08-28 13:02:33 -0700114
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700115 // Resolve a method with a given ID from the DexFile, storing the
116 // result in DexCache. The ClassLinker and ClassLoader are used as
117 // in ResolveType. What is unique is the method type argument which
118 // is used to determine if this method is a direct, static, or
119 // virtual method.
120 Method* ResolveMethod(const DexFile& dex_file,
121 uint32_t method_idx,
122 DexCache* dex_cache,
123 const ClassLoader* class_loader,
Brian Carlstrom20cfffa2011-08-26 02:31:27 -0700124 bool is_direct);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700125
Brian Carlstrom16192862011-09-12 17:50:06 -0700126 Method* ResolveMethod(uint32_t method_idx, const Method* referrer, bool is_direct) {
127 Class* declaring_class = referrer->GetDeclaringClass();
128 DexCache* dex_cache = declaring_class->GetDexCache();
129 // TODO: we could check for a dex cache hit here
130 const ClassLoader* class_loader = declaring_class->GetClassLoader();
131 const DexFile& dex_file = FindDexFile(dex_cache);
132 return ResolveMethod(dex_file, method_idx, dex_cache, class_loader, is_direct);
133 }
134
Brian Carlstrom845490b2011-09-19 15:56:53 -0700135 Field* ResolveField(uint32_t field_idx, const Method* referrer, bool is_static) {
Brian Carlstromb9edb842011-08-28 16:31:06 -0700136 Class* declaring_class = referrer->GetDeclaringClass();
137 DexCache* dex_cache = declaring_class->GetDexCache();
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700138 // TODO: we could check for a dex cache hit here
Brian Carlstromb9edb842011-08-28 16:31:06 -0700139 const ClassLoader* class_loader = declaring_class->GetClassLoader();
140 const DexFile& dex_file = FindDexFile(dex_cache);
Brian Carlstrom845490b2011-09-19 15:56:53 -0700141 return ResolveField(dex_file, field_idx, dex_cache, class_loader, is_static);
Brian Carlstromb9edb842011-08-28 16:31:06 -0700142 }
143
Brian Carlstrom16192862011-09-12 17:50:06 -0700144 // Resolve a field with a given ID from the DexFile, storing the
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700145 // result in DexCache. The ClassLinker and ClassLoader are used as
146 // in ResolveType. What is unique is the is_static argument which is
147 // used to determine if we are resolving a static or non-static
148 // field.
149 Field* ResolveField(const DexFile& dex_file,
150 uint32_t field_idx,
151 DexCache* dex_cache,
152 const ClassLoader* class_loader,
153 bool is_static);
154
Elliott Hughesf4c21c92011-08-19 17:31:31 -0700155 // Returns true on success, false if there's an exception pending.
Brian Carlstrom25c33252011-09-18 15:58:35 -0700156 // can_run_clinit=false allows the compiler to attempt to init a class,
157 // given the restriction that no <clinit> execution is possible.
158 bool EnsureInitialized(Class* c, bool can_run_clinit);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700159
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700160 void RegisterDexFile(const DexFile& dex_file);
161 void RegisterDexFile(const DexFile& dex_file, DexCache* dex_cache);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700162
Brian Carlstrom8a487412011-08-29 20:08:52 -0700163 const std::vector<const DexFile*>& GetBootClassPath() {
164 return boot_class_path_;
165 }
166
Elliott Hughes410c0c82011-09-01 17:58:25 -0700167 void VisitRoots(Heap::RootVisitor* visitor, void* arg) const;
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700168
buzbeec143c552011-08-20 17:38:58 -0700169 const DexFile& FindDexFile(const DexCache* dex_cache) const;
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700170 DexCache* FindDexCache(const DexFile& dex_file) const;
buzbeec143c552011-08-20 17:38:58 -0700171
Elliott Hughes418d20f2011-09-22 14:00:39 -0700172 // TODO: replace this with multiple methods that allocate the correct managed type.
Shih-wei Liao44175362011-08-28 16:59:17 -0700173 template <class T>
174 ObjectArray<T>* AllocObjectArray(size_t length) {
175 return ObjectArray<T>::Alloc(GetClassRoot(kObjectArrayClass), length);
176 }
177
Elliott Hughes418d20f2011-09-22 14:00:39 -0700178 ObjectArray<Class>* AllocClassArray(size_t length) {
179 return ObjectArray<Class>::Alloc(GetClassRoot(kClassArrayClass), length);
180 }
181
Shih-wei Liao55df06b2011-08-26 14:39:27 -0700182 ObjectArray<StackTraceElement>* AllocStackTraceElementArray(size_t length);
183
jeffhao98eacac2011-09-14 16:11:53 -0700184 void VerifyClass(Class* klass);
185
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700186 private:
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700187 ClassLinker(InternTable*);
Carl Shapiro61e019d2011-07-14 16:53:09 -0700188
Brian Carlstroma663ea52011-08-19 23:33:41 -0700189 // Initialize class linker from DexFile instances.
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700190 void Init(const std::vector<const DexFile*>& boot_class_path_,
191 const std::vector<const DexFile*>& class_path_);
Carl Shapiro61e019d2011-07-14 16:53:09 -0700192
Brian Carlstromc74255f2011-09-11 22:47:39 -0700193 // Initialize class linker from pre-initialized image.
194 void InitFromImage(const std::vector<const DexFile*>& boot_class_path_,
195 const std::vector<const DexFile*>& class_path_);
Brian Carlstrom78128a62011-09-15 17:21:19 -0700196 static void InitFromImageCallback(Object* obj, void* arg);
Brian Carlstromc74255f2011-09-11 22:47:39 -0700197 struct InitFromImageCallbackState;
Brian Carlstroma663ea52011-08-19 23:33:41 -0700198
199 void FinishInit();
200
Brian Carlstrom25c33252011-09-18 15:58:35 -0700201 bool InitializeClass(Class* klass, bool can_run_clinit);
Elliott Hughesf4c21c92011-08-19 17:31:31 -0700202
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700203 // For early bootstrapping by Init
Brian Carlstrom4873d462011-08-21 15:23:39 -0700204 Class* AllocClass(Class* java_lang_Class, size_t class_size);
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700205
206 // Alloc* convenience functions to avoid needing to pass in Class*
207 // values that are known to the ClassLinker such as
208 // kObjectArrayClass and kJavaLangString etc.
Brian Carlstrom4873d462011-08-21 15:23:39 -0700209 Class* AllocClass(size_t class_size);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700210 DexCache* AllocDexCache(const DexFile& dex_file);
Jesse Wilson35baaab2011-08-10 16:18:03 -0400211 Field* AllocField();
Ian Rogersbdb03912011-09-14 00:55:44 -0700212
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700213 Method* AllocMethod();
Ian Rogersbdb03912011-09-14 00:55:44 -0700214
Brian Carlstrom9cc262e2011-08-28 12:45:30 -0700215 CodeAndDirectMethods* AllocCodeAndDirectMethods(size_t length);
Brian Carlstrom4b620ff2011-09-11 01:11:01 -0700216 InterfaceEntry* AllocInterfaceEntry(Class* interface);
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700217
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700218 Class* CreatePrimitiveClass(const char* descriptor,
Brian Carlstrom5b8e4c82011-09-18 01:38:59 -0700219 Class::PrimitiveType type) {
220 return InitializePrimitiveClass(AllocClass(sizeof(Class)), descriptor, type);
221 }
222 Class* InitializePrimitiveClass(Class* primitive_class,
223 const char* descriptor,
224 Class::PrimitiveType type);
225
Brian Carlstroma331b3c2011-07-18 17:47:56 -0700226
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700227 Class* CreateArrayClass(const StringPiece& descriptor,
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700228 const ClassLoader* class_loader);
Brian Carlstroma331b3c2011-07-18 17:47:56 -0700229
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700230 void AppendToBootClassPath(const DexFile& dex_file);
231 void AppendToBootClassPath(const DexFile& dex_file, DexCache* dex_cache);
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700232
Elliott Hughes5fe594f2011-09-08 12:33:17 -0700233 void ConstructFieldMap(const DexFile& dex_file, const DexFile::ClassDef& dex_class_def,
234 Class* c, std::map<int, Field*>& field_map);
235
Brian Carlstrom4873d462011-08-21 15:23:39 -0700236 size_t SizeOfClass(const DexFile& dex_file,
237 const DexFile::ClassDef& dex_class_def);
238
Brian Carlstromf615a612011-07-23 12:50:34 -0700239 void LoadClass(const DexFile& dex_file,
240 const DexFile::ClassDef& dex_class_def,
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700241 Class* klass,
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700242 const ClassLoader* class_loader);
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700243
Brian Carlstromf615a612011-07-23 12:50:34 -0700244 void LoadInterfaces(const DexFile& dex_file,
245 const DexFile::ClassDef& dex_class_def,
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700246 Class *klass);
247
Brian Carlstromf615a612011-07-23 12:50:34 -0700248 void LoadField(const DexFile& dex_file,
249 const DexFile::Field& dex_field,
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700250 Class* klass,
251 Field* dst);
252
Brian Carlstromf615a612011-07-23 12:50:34 -0700253 void LoadMethod(const DexFile& dex_file,
254 const DexFile::Method& dex_method,
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700255 Class* klass,
Brian Carlstrom1f870082011-08-23 16:02:11 -0700256 Method* dst);
Brian Carlstrom934486c2011-07-12 23:42:50 -0700257
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700258 // Inserts a class into the class table. Returns true if the class
259 // was inserted.
Brian Carlstrom9cff8e12011-08-18 16:47:29 -0700260 bool InsertClass(const StringPiece& descriptor, Class* klass);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700261
Brian Carlstrom25c33252011-09-18 15:58:35 -0700262 bool InitializeSuperClass(Class* klass, bool can_run_clinit);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700263
264 void InitializeStaticFields(Class* klass);
265
266 bool ValidateSuperClassDescriptors(const Class* klass);
267
268 bool HasSameDescriptorClasses(const char* descriptor,
269 const Class* klass1,
270 const Class* klass2);
271
272 bool HasSameMethodDescriptorClasses(const Method* descriptor,
273 const Class* klass1,
274 const Class* klass2);
275
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700276 bool LinkClass(Class* klass);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700277
278 bool LinkSuperClass(Class* klass);
279
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700280 bool LoadSuperAndInterfaces(Class* klass, const DexFile& dex_file);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700281
282 bool LinkMethods(Class* klass);
283
284 bool LinkVirtualMethods(Class* klass);
285
286 bool LinkInterfaceMethods(Class* klass);
287
Jesse Wilson7833bd22011-08-09 18:31:44 -0400288 bool LinkStaticFields(Class* klass);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700289 bool LinkInstanceFields(Class* klass);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700290 bool LinkFields(Class *klass, bool instance);
291
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700292
Brian Carlstrom4873d462011-08-21 15:23:39 -0700293 void CreateReferenceInstanceOffsets(Class* klass);
294 void CreateReferenceStaticOffsets(Class* klass);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700295 void CreateReferenceOffsets(Class *klass, bool instance,
296 uint32_t reference_offsets);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700297
Brian Carlstrom16192862011-09-12 17:50:06 -0700298 // lock to protect ClassLinker state
299 mutable Mutex lock_;
300
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700301 std::vector<const DexFile*> boot_class_path_;
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700302
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700303 std::vector<const DexFile*> dex_files_;
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700304 std::vector<DexCache*> dex_caches_;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700305
Brian Carlstrom9cff8e12011-08-18 16:47:29 -0700306 // multimap from a StringPiece hash code of a class descriptor to
307 // Class* instances. Results should be compared for a matching
308 // Class::descriptor_ and Class::class_loader_.
309 typedef std::tr1::unordered_multimap<size_t, Class*> Table;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700310 Table classes_;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700311
Brian Carlstroma663ea52011-08-19 23:33:41 -0700312 // indexes into class_roots_.
313 // needs to be kept in sync with class_roots_descriptors_.
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700314 enum ClassRoot {
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700315 kJavaLangClass,
316 kJavaLangObject,
Elliott Hughes418d20f2011-09-22 14:00:39 -0700317 kClassArrayClass,
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700318 kObjectArrayClass,
319 kJavaLangString,
Elliott Hughes80609252011-09-23 17:24:51 -0700320 kJavaLangReflectConstructor,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700321 kJavaLangReflectField,
322 kJavaLangReflectMethod,
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700323 kJavaLangClassLoader,
324 kDalvikSystemBaseDexClassLoader,
325 kDalvikSystemPathClassLoader,
Shih-wei Liao55df06b2011-08-26 14:39:27 -0700326 kJavaLangStackTraceElement,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700327 kPrimitiveBoolean,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700328 kPrimitiveByte,
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700329 kPrimitiveChar,
330 kPrimitiveDouble,
331 kPrimitiveFloat,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700332 kPrimitiveInt,
333 kPrimitiveLong,
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700334 kPrimitiveShort,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700335 kPrimitiveVoid,
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700336 kBooleanArrayClass,
337 kByteArrayClass,
338 kCharArrayClass,
339 kDoubleArrayClass,
340 kFloatArrayClass,
341 kIntArrayClass,
342 kLongArrayClass,
343 kShortArrayClass,
Shih-wei Liao55df06b2011-08-26 14:39:27 -0700344 kJavaLangStackTraceElementArrayClass,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700345 kClassRootsMax,
346 };
347 ObjectArray<Class>* class_roots_;
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700348
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700349 Class* GetClassRoot(ClassRoot class_root) {
Brian Carlstroma663ea52011-08-19 23:33:41 -0700350 DCHECK(class_roots_ != NULL);
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700351 Class* klass = class_roots_->Get(class_root);
352 DCHECK(klass != NULL);
353 return klass;
354 }
355
Brian Carlstroma663ea52011-08-19 23:33:41 -0700356 void SetClassRoot(ClassRoot class_root, Class* klass) {
357 DCHECK(!init_done_);
358
359 DCHECK(klass != NULL);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700360 DCHECK(klass->GetClassLoader() == NULL);
361 DCHECK(klass->GetDescriptor() != NULL);
362 DCHECK(klass->GetDescriptor()->Equals(GetClassRootDescriptor(class_root)));
Brian Carlstroma663ea52011-08-19 23:33:41 -0700363
364 DCHECK(class_roots_ != NULL);
365 DCHECK(class_roots_->Get(class_root) == NULL);
366 class_roots_->Set(class_root, klass);
367 }
368
Elliott Hughes418d20f2011-09-22 14:00:39 -0700369 static const char* class_roots_descriptors_[];
Brian Carlstroma663ea52011-08-19 23:33:41 -0700370
371 const char* GetClassRootDescriptor(ClassRoot class_root) {
372 const char* descriptor = class_roots_descriptors_[class_root];
373 CHECK(descriptor != NULL);
374 return descriptor;
375 }
376
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700377 ObjectArray<Class>* array_interfaces_;
Brian Carlstrom4b620ff2011-09-11 01:11:01 -0700378 ObjectArray<InterfaceEntry>* array_iftable_;
Carl Shapiro565f5072011-07-10 13:39:43 -0700379
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700380 bool init_done_;
381
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700382 InternTable* intern_table_;
383
Brian Carlstromf734cf52011-08-17 16:28:14 -0700384 friend class CommonTest;
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700385 FRIEND_TEST(DexCacheTest, Open);
386 friend class ObjectTest;
387 FRIEND_TEST(ObjectTest, AllocObjectArray);
Shih-wei Liao1a18c8c2011-08-14 17:47:36 -0700388 FRIEND_TEST(ExceptionTest, FindExceptionHandler);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700389 DISALLOW_COPY_AND_ASSIGN(ClassLinker);
390};
391
392} // namespace art
393
394#endif // ART_SRC_CLASS_LINKER_H_