blob: 317490a9d576e29612264501830addf991c477d5 [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
Elliott Hughes2a20cfd2011-09-23 19:30:41 -0700160 // Initializes classes that have instances in the image but that have
161 // <clinit> methods so they could not be initialized by the compiler.
162 void RunRootClinits();
163
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700164 void RegisterDexFile(const DexFile& dex_file);
165 void RegisterDexFile(const DexFile& dex_file, DexCache* dex_cache);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700166
Brian Carlstrom8a487412011-08-29 20:08:52 -0700167 const std::vector<const DexFile*>& GetBootClassPath() {
168 return boot_class_path_;
169 }
170
Elliott Hughes410c0c82011-09-01 17:58:25 -0700171 void VisitRoots(Heap::RootVisitor* visitor, void* arg) const;
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700172
buzbeec143c552011-08-20 17:38:58 -0700173 const DexFile& FindDexFile(const DexCache* dex_cache) const;
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700174 DexCache* FindDexCache(const DexFile& dex_file) const;
buzbeec143c552011-08-20 17:38:58 -0700175
Elliott Hughes418d20f2011-09-22 14:00:39 -0700176 // TODO: replace this with multiple methods that allocate the correct managed type.
Shih-wei Liao44175362011-08-28 16:59:17 -0700177 template <class T>
178 ObjectArray<T>* AllocObjectArray(size_t length) {
179 return ObjectArray<T>::Alloc(GetClassRoot(kObjectArrayClass), length);
180 }
181
Elliott Hughes418d20f2011-09-22 14:00:39 -0700182 ObjectArray<Class>* AllocClassArray(size_t length) {
183 return ObjectArray<Class>::Alloc(GetClassRoot(kClassArrayClass), length);
184 }
185
Shih-wei Liao55df06b2011-08-26 14:39:27 -0700186 ObjectArray<StackTraceElement>* AllocStackTraceElementArray(size_t length);
187
jeffhao98eacac2011-09-14 16:11:53 -0700188 void VerifyClass(Class* klass);
189
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700190 private:
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700191 ClassLinker(InternTable*);
Carl Shapiro61e019d2011-07-14 16:53:09 -0700192
Brian Carlstroma663ea52011-08-19 23:33:41 -0700193 // Initialize class linker from DexFile instances.
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700194 void Init(const std::vector<const DexFile*>& boot_class_path_,
195 const std::vector<const DexFile*>& class_path_);
Carl Shapiro61e019d2011-07-14 16:53:09 -0700196
Brian Carlstromc74255f2011-09-11 22:47:39 -0700197 // Initialize class linker from pre-initialized image.
198 void InitFromImage(const std::vector<const DexFile*>& boot_class_path_,
199 const std::vector<const DexFile*>& class_path_);
Brian Carlstrom78128a62011-09-15 17:21:19 -0700200 static void InitFromImageCallback(Object* obj, void* arg);
Brian Carlstromc74255f2011-09-11 22:47:39 -0700201 struct InitFromImageCallbackState;
Brian Carlstroma663ea52011-08-19 23:33:41 -0700202
203 void FinishInit();
204
Brian Carlstrom25c33252011-09-18 15:58:35 -0700205 bool InitializeClass(Class* klass, bool can_run_clinit);
Elliott Hughesf4c21c92011-08-19 17:31:31 -0700206
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700207 // For early bootstrapping by Init
Brian Carlstrom4873d462011-08-21 15:23:39 -0700208 Class* AllocClass(Class* java_lang_Class, size_t class_size);
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700209
210 // Alloc* convenience functions to avoid needing to pass in Class*
211 // values that are known to the ClassLinker such as
212 // kObjectArrayClass and kJavaLangString etc.
Brian Carlstrom4873d462011-08-21 15:23:39 -0700213 Class* AllocClass(size_t class_size);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700214 DexCache* AllocDexCache(const DexFile& dex_file);
Jesse Wilson35baaab2011-08-10 16:18:03 -0400215 Field* AllocField();
Ian Rogersbdb03912011-09-14 00:55:44 -0700216
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700217 Method* AllocMethod();
Ian Rogersbdb03912011-09-14 00:55:44 -0700218
Brian Carlstrom9cc262e2011-08-28 12:45:30 -0700219 CodeAndDirectMethods* AllocCodeAndDirectMethods(size_t length);
Brian Carlstrom4b620ff2011-09-11 01:11:01 -0700220 InterfaceEntry* AllocInterfaceEntry(Class* interface);
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700221
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700222 Class* CreatePrimitiveClass(const char* descriptor,
Brian Carlstrom5b8e4c82011-09-18 01:38:59 -0700223 Class::PrimitiveType type) {
224 return InitializePrimitiveClass(AllocClass(sizeof(Class)), descriptor, type);
225 }
226 Class* InitializePrimitiveClass(Class* primitive_class,
227 const char* descriptor,
228 Class::PrimitiveType type);
229
Brian Carlstroma331b3c2011-07-18 17:47:56 -0700230
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700231 Class* CreateArrayClass(const StringPiece& descriptor,
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700232 const ClassLoader* class_loader);
Brian Carlstroma331b3c2011-07-18 17:47:56 -0700233
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700234 void AppendToBootClassPath(const DexFile& dex_file);
235 void AppendToBootClassPath(const DexFile& dex_file, DexCache* dex_cache);
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700236
Elliott Hughes5fe594f2011-09-08 12:33:17 -0700237 void ConstructFieldMap(const DexFile& dex_file, const DexFile::ClassDef& dex_class_def,
238 Class* c, std::map<int, Field*>& field_map);
239
Brian Carlstrom4873d462011-08-21 15:23:39 -0700240 size_t SizeOfClass(const DexFile& dex_file,
241 const DexFile::ClassDef& dex_class_def);
242
Brian Carlstromf615a612011-07-23 12:50:34 -0700243 void LoadClass(const DexFile& dex_file,
244 const DexFile::ClassDef& dex_class_def,
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700245 Class* klass,
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700246 const ClassLoader* class_loader);
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700247
Brian Carlstromf615a612011-07-23 12:50:34 -0700248 void LoadInterfaces(const DexFile& dex_file,
249 const DexFile::ClassDef& dex_class_def,
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700250 Class *klass);
251
Brian Carlstromf615a612011-07-23 12:50:34 -0700252 void LoadField(const DexFile& dex_file,
253 const DexFile::Field& dex_field,
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700254 Class* klass,
255 Field* dst);
256
Brian Carlstromf615a612011-07-23 12:50:34 -0700257 void LoadMethod(const DexFile& dex_file,
258 const DexFile::Method& dex_method,
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700259 Class* klass,
Brian Carlstrom1f870082011-08-23 16:02:11 -0700260 Method* dst);
Brian Carlstrom934486c2011-07-12 23:42:50 -0700261
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700262 // Inserts a class into the class table. Returns true if the class
263 // was inserted.
Brian Carlstrom9cff8e12011-08-18 16:47:29 -0700264 bool InsertClass(const StringPiece& descriptor, Class* klass);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700265
Brian Carlstrom25c33252011-09-18 15:58:35 -0700266 bool InitializeSuperClass(Class* klass, bool can_run_clinit);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700267
268 void InitializeStaticFields(Class* klass);
269
270 bool ValidateSuperClassDescriptors(const Class* klass);
271
272 bool HasSameDescriptorClasses(const char* descriptor,
273 const Class* klass1,
274 const Class* klass2);
275
276 bool HasSameMethodDescriptorClasses(const Method* descriptor,
277 const Class* klass1,
278 const Class* klass2);
279
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700280 bool LinkClass(Class* klass);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700281
282 bool LinkSuperClass(Class* klass);
283
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700284 bool LoadSuperAndInterfaces(Class* klass, const DexFile& dex_file);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700285
286 bool LinkMethods(Class* klass);
287
288 bool LinkVirtualMethods(Class* klass);
289
290 bool LinkInterfaceMethods(Class* klass);
291
Jesse Wilson7833bd22011-08-09 18:31:44 -0400292 bool LinkStaticFields(Class* klass);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700293 bool LinkInstanceFields(Class* klass);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700294 bool LinkFields(Class *klass, bool instance);
295
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700296
Brian Carlstrom4873d462011-08-21 15:23:39 -0700297 void CreateReferenceInstanceOffsets(Class* klass);
298 void CreateReferenceStaticOffsets(Class* klass);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700299 void CreateReferenceOffsets(Class *klass, bool instance,
300 uint32_t reference_offsets);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700301
Brian Carlstrom16192862011-09-12 17:50:06 -0700302 // lock to protect ClassLinker state
303 mutable Mutex lock_;
304
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700305 std::vector<const DexFile*> boot_class_path_;
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700306
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700307 std::vector<const DexFile*> dex_files_;
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700308 std::vector<DexCache*> dex_caches_;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700309
Brian Carlstrom9cff8e12011-08-18 16:47:29 -0700310 // multimap from a StringPiece hash code of a class descriptor to
311 // Class* instances. Results should be compared for a matching
312 // Class::descriptor_ and Class::class_loader_.
313 typedef std::tr1::unordered_multimap<size_t, Class*> Table;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700314 Table classes_;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700315
Brian Carlstroma663ea52011-08-19 23:33:41 -0700316 // indexes into class_roots_.
317 // needs to be kept in sync with class_roots_descriptors_.
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700318 enum ClassRoot {
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700319 kJavaLangClass,
320 kJavaLangObject,
Elliott Hughes418d20f2011-09-22 14:00:39 -0700321 kClassArrayClass,
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700322 kObjectArrayClass,
323 kJavaLangString,
Elliott Hughes80609252011-09-23 17:24:51 -0700324 kJavaLangReflectConstructor,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700325 kJavaLangReflectField,
326 kJavaLangReflectMethod,
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700327 kJavaLangClassLoader,
328 kDalvikSystemBaseDexClassLoader,
329 kDalvikSystemPathClassLoader,
Shih-wei Liao55df06b2011-08-26 14:39:27 -0700330 kJavaLangStackTraceElement,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700331 kPrimitiveBoolean,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700332 kPrimitiveByte,
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700333 kPrimitiveChar,
334 kPrimitiveDouble,
335 kPrimitiveFloat,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700336 kPrimitiveInt,
337 kPrimitiveLong,
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700338 kPrimitiveShort,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700339 kPrimitiveVoid,
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700340 kBooleanArrayClass,
341 kByteArrayClass,
342 kCharArrayClass,
343 kDoubleArrayClass,
344 kFloatArrayClass,
345 kIntArrayClass,
346 kLongArrayClass,
347 kShortArrayClass,
Shih-wei Liao55df06b2011-08-26 14:39:27 -0700348 kJavaLangStackTraceElementArrayClass,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700349 kClassRootsMax,
350 };
351 ObjectArray<Class>* class_roots_;
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700352
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700353 Class* GetClassRoot(ClassRoot class_root) {
Brian Carlstroma663ea52011-08-19 23:33:41 -0700354 DCHECK(class_roots_ != NULL);
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700355 Class* klass = class_roots_->Get(class_root);
356 DCHECK(klass != NULL);
357 return klass;
358 }
359
Brian Carlstroma663ea52011-08-19 23:33:41 -0700360 void SetClassRoot(ClassRoot class_root, Class* klass) {
361 DCHECK(!init_done_);
362
363 DCHECK(klass != NULL);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700364 DCHECK(klass->GetClassLoader() == NULL);
365 DCHECK(klass->GetDescriptor() != NULL);
366 DCHECK(klass->GetDescriptor()->Equals(GetClassRootDescriptor(class_root)));
Brian Carlstroma663ea52011-08-19 23:33:41 -0700367
368 DCHECK(class_roots_ != NULL);
369 DCHECK(class_roots_->Get(class_root) == NULL);
370 class_roots_->Set(class_root, klass);
371 }
372
Elliott Hughes418d20f2011-09-22 14:00:39 -0700373 static const char* class_roots_descriptors_[];
Brian Carlstroma663ea52011-08-19 23:33:41 -0700374
375 const char* GetClassRootDescriptor(ClassRoot class_root) {
376 const char* descriptor = class_roots_descriptors_[class_root];
377 CHECK(descriptor != NULL);
378 return descriptor;
379 }
380
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700381 ObjectArray<Class>* array_interfaces_;
Brian Carlstrom4b620ff2011-09-11 01:11:01 -0700382 ObjectArray<InterfaceEntry>* array_iftable_;
Carl Shapiro565f5072011-07-10 13:39:43 -0700383
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700384 bool init_done_;
385
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700386 InternTable* intern_table_;
387
Brian Carlstromf734cf52011-08-17 16:28:14 -0700388 friend class CommonTest;
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700389 FRIEND_TEST(DexCacheTest, Open);
390 friend class ObjectTest;
391 FRIEND_TEST(ObjectTest, AllocObjectArray);
Shih-wei Liao1a18c8c2011-08-14 17:47:36 -0700392 FRIEND_TEST(ExceptionTest, FindExceptionHandler);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700393 DISALLOW_COPY_AND_ASSIGN(ClassLinker);
394};
395
396} // namespace art
397
398#endif // ART_SRC_CLASS_LINKER_H_