blob: 747a6e405ca0fbdb5a063d956ef97e4cd44e6e92 [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 Carlstrom58ae9412011-10-04 00:56:06 -070028#include "oat_file.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070029#include "object.h"
Brian Carlstrom7e93b502011-08-04 14:16:22 -070030#include "unordered_map.h"
Brian Carlstroma663ea52011-08-19 23:33:41 -070031#include "unordered_set.h"
Brian Carlstrom7e93b502011-08-04 14:16:22 -070032
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070033#include "gtest/gtest.h"
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070034
35namespace art {
36
Elliott Hughescf4c6c42011-09-01 15:16:42 -070037class ClassLoader;
38class InternTable;
Brian Carlstromd1422f82011-09-28 11:37:09 -070039class ObjectLock;
Elliott Hughescf4c6c42011-09-01 15:16:42 -070040
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070041class ClassLinker {
42 public:
Brian Carlstrom58ae9412011-10-04 00:56:06 -070043 // Creates the class linker by boot strapping from dex files.
44 static ClassLinker* Create(const std::string& boot_class_path, InternTable* intern_table);
45
46 // Creates the class linker from one or more images.
47 static ClassLinker* Create(InternTable* intern_table);
Carl Shapiro61e019d2011-07-14 16:53:09 -070048
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070049 ~ClassLinker();
Carl Shapiro565f5072011-07-10 13:39:43 -070050
Elliott Hughes64bf5a32011-09-20 14:43:12 -070051 // Finds a class by its descriptor, loading it if necessary.
Brian Carlstrom74eb46a2011-08-02 20:10:14 -070052 // If class_loader is null, searches boot_class_path_.
Elliott Hughes64bf5a32011-09-20 14:43:12 -070053 Class* FindClass(const StringPiece& descriptor, const ClassLoader* class_loader);
54
55 // Finds a class by its descriptor, returning NULL if it isn't wasn't loaded
56 // by the given 'class_loader'.
57 Class* LookupClass(const StringPiece& descriptor, const ClassLoader* class_loader);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070058
Elliott Hughesd8ddfd52011-08-15 14:32:53 -070059 Class* FindPrimitiveClass(char type);
60
Brian Carlstrom6cc18452011-07-18 15:10:33 -070061 Class* FindSystemClass(const StringPiece& descriptor) {
Brian Carlstrom74eb46a2011-08-02 20:10:14 -070062 return FindClass(descriptor, NULL);
Carl Shapiro565f5072011-07-10 13:39:43 -070063 }
64
Elliott Hughes9d5ccec2011-09-19 13:19:50 -070065 void DumpAllClasses(int flags) const;
66
Elliott Hughese27955c2011-08-26 15:21:24 -070067 size_t NumLoadedClasses() const;
68
Brian Carlstromb63ec392011-08-27 17:38:27 -070069 // Resolve a String with the given index from the DexFile, storing the
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070070 // result in the DexCache.
Ian Rogers0cfe1fb2011-08-26 03:29:44 -070071 String* ResolveString(const DexFile& dex_file, uint32_t string_idx, DexCache* dex_cache);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070072
Brian Carlstromb63ec392011-08-27 17:38:27 -070073 // Resolve a Type with the given index from the DexFile, storing the
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070074 // result in the DexCache. The referrer is used to identity the
75 // target DexCache and ClassLoader to use for resolution.
76 Class* ResolveType(const DexFile& dex_file,
77 uint32_t type_idx,
78 const Class* referrer) {
79 return ResolveType(dex_file,
80 type_idx,
81 referrer->GetDexCache(),
82 referrer->GetClassLoader());
83 }
84
Brian Carlstromb63ec392011-08-27 17:38:27 -070085 // Resolve a Type with the given index from the DexFile, storing the
Ian Rogers0cfe1fb2011-08-26 03:29:44 -070086 // result in the DexCache. The referrer is used to identify the
Brian Carlstromb63ec392011-08-27 17:38:27 -070087 // target DexCache and ClassLoader to use for resolution.
Brian Carlstromb9edb842011-08-28 16:31:06 -070088 Class* ResolveType(uint32_t type_idx, const Method* referrer) {
Brian Carlstromb63ec392011-08-27 17:38:27 -070089 Class* declaring_class = referrer->GetDeclaringClass();
90 DexCache* dex_cache = declaring_class->GetDexCache();
Ian Rogers0cfe1fb2011-08-26 03:29:44 -070091 // TODO: we could check for a dex cache hit here
92 const ClassLoader* class_loader = declaring_class->GetClassLoader();
93 const DexFile& dex_file = FindDexFile(dex_cache);
94 return ResolveType(dex_file, type_idx, dex_cache, class_loader);
95 }
96
97 Class* ResolveType(uint32_t type_idx, const Field* referrer) {
98 Class* declaring_class = referrer->GetDeclaringClass();
99 DexCache* dex_cache = declaring_class->GetDexCache();
100 // TODO: we could check for a dex cache hit here
Brian Carlstromb63ec392011-08-27 17:38:27 -0700101 const ClassLoader* class_loader = declaring_class->GetClassLoader();
102 const DexFile& dex_file = FindDexFile(dex_cache);
103 return ResolveType(dex_file, type_idx, dex_cache, class_loader);
104 }
105
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700106 // Resolve a type with the given ID from the DexFile, storing the
107 // result in DexCache. The ClassLoader is used to search for the
108 // type, since it may be referenced from but not contained within
109 // the given DexFile.
110 Class* ResolveType(const DexFile& dex_file,
111 uint32_t type_idx,
112 DexCache* dex_cache,
113 const ClassLoader* class_loader);
114
Brian Carlstromb9edb842011-08-28 16:31:06 -0700115 static StaticStorageBase* InitializeStaticStorageFromCode(uint32_t type_idx,
116 const Method* referrer);
Brian Carlstrom1caa2c22011-08-28 13:02:33 -0700117
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700118 // Resolve a method with a given ID from the DexFile, storing the
119 // result in DexCache. The ClassLinker and ClassLoader are used as
120 // in ResolveType. What is unique is the method type argument which
121 // is used to determine if this method is a direct, static, or
122 // virtual method.
123 Method* ResolveMethod(const DexFile& dex_file,
124 uint32_t method_idx,
125 DexCache* dex_cache,
126 const ClassLoader* class_loader,
Brian Carlstrom20cfffa2011-08-26 02:31:27 -0700127 bool is_direct);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700128
Brian Carlstrom16192862011-09-12 17:50:06 -0700129 Method* ResolveMethod(uint32_t method_idx, const Method* referrer, bool is_direct) {
130 Class* declaring_class = referrer->GetDeclaringClass();
131 DexCache* dex_cache = declaring_class->GetDexCache();
132 // TODO: we could check for a dex cache hit here
133 const ClassLoader* class_loader = declaring_class->GetClassLoader();
134 const DexFile& dex_file = FindDexFile(dex_cache);
135 return ResolveMethod(dex_file, method_idx, dex_cache, class_loader, is_direct);
136 }
137
Brian Carlstrom845490b2011-09-19 15:56:53 -0700138 Field* ResolveField(uint32_t field_idx, const Method* referrer, bool is_static) {
Brian Carlstromb9edb842011-08-28 16:31:06 -0700139 Class* declaring_class = referrer->GetDeclaringClass();
140 DexCache* dex_cache = declaring_class->GetDexCache();
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700141 // TODO: we could check for a dex cache hit here
Brian Carlstromb9edb842011-08-28 16:31:06 -0700142 const ClassLoader* class_loader = declaring_class->GetClassLoader();
143 const DexFile& dex_file = FindDexFile(dex_cache);
Brian Carlstrom845490b2011-09-19 15:56:53 -0700144 return ResolveField(dex_file, field_idx, dex_cache, class_loader, is_static);
Brian Carlstromb9edb842011-08-28 16:31:06 -0700145 }
146
Brian Carlstrom16192862011-09-12 17:50:06 -0700147 // Resolve a field with a given ID from the DexFile, storing the
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700148 // result in DexCache. The ClassLinker and ClassLoader are used as
149 // in ResolveType. What is unique is the is_static argument which is
150 // used to determine if we are resolving a static or non-static
151 // field.
152 Field* ResolveField(const DexFile& dex_file,
153 uint32_t field_idx,
154 DexCache* dex_cache,
155 const ClassLoader* class_loader,
156 bool is_static);
157
Elliott Hughesf4c21c92011-08-19 17:31:31 -0700158 // Returns true on success, false if there's an exception pending.
Brian Carlstrom25c33252011-09-18 15:58:35 -0700159 // can_run_clinit=false allows the compiler to attempt to init a class,
160 // given the restriction that no <clinit> execution is possible.
161 bool EnsureInitialized(Class* c, bool can_run_clinit);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700162
Elliott Hughes2a20cfd2011-09-23 19:30:41 -0700163 // Initializes classes that have instances in the image but that have
164 // <clinit> methods so they could not be initialized by the compiler.
165 void RunRootClinits();
166
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700167 void RegisterDexFile(const DexFile& dex_file);
168 void RegisterDexFile(const DexFile& dex_file, DexCache* dex_cache);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700169
Brian Carlstrom8a487412011-08-29 20:08:52 -0700170 const std::vector<const DexFile*>& GetBootClassPath() {
171 return boot_class_path_;
172 }
173
Elliott Hughes410c0c82011-09-01 17:58:25 -0700174 void VisitRoots(Heap::RootVisitor* visitor, void* arg) const;
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700175
buzbeec143c552011-08-20 17:38:58 -0700176 const DexFile& FindDexFile(const DexCache* dex_cache) const;
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700177 DexCache* FindDexCache(const DexFile& dex_file) const;
buzbeec143c552011-08-20 17:38:58 -0700178
Elliott Hughes418d20f2011-09-22 14:00:39 -0700179 // TODO: replace this with multiple methods that allocate the correct managed type.
Shih-wei Liao44175362011-08-28 16:59:17 -0700180 template <class T>
181 ObjectArray<T>* AllocObjectArray(size_t length) {
182 return ObjectArray<T>::Alloc(GetClassRoot(kObjectArrayClass), length);
183 }
184
Elliott Hughes418d20f2011-09-22 14:00:39 -0700185 ObjectArray<Class>* AllocClassArray(size_t length) {
186 return ObjectArray<Class>::Alloc(GetClassRoot(kClassArrayClass), length);
187 }
188
Shih-wei Liao55df06b2011-08-26 14:39:27 -0700189 ObjectArray<StackTraceElement>* AllocStackTraceElementArray(size_t length);
190
jeffhao98eacac2011-09-14 16:11:53 -0700191 void VerifyClass(Class* klass);
192
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700193 private:
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700194 ClassLinker(InternTable*);
Carl Shapiro61e019d2011-07-14 16:53:09 -0700195
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700196 // Initialize class linker by bootstraping from dex files
197 void Init(const std::string& boot_class_path);
Carl Shapiro61e019d2011-07-14 16:53:09 -0700198
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700199 // Initialize class linker from one or more images.
200 void InitFromImage();
201 OatFile* OpenOat(const Space* space);
Brian Carlstrom78128a62011-09-15 17:21:19 -0700202 static void InitFromImageCallback(Object* obj, void* arg);
Brian Carlstromc74255f2011-09-11 22:47:39 -0700203 struct InitFromImageCallbackState;
Brian Carlstroma663ea52011-08-19 23:33:41 -0700204
205 void FinishInit();
206
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 Carlstromd1422f82011-09-28 11:37:09 -0700266 bool InitializeClass(Class* klass, bool can_run_clinit);
267 bool WaitForInitializeClass(Class* klass, Thread* self, ObjectLock& lock);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700268 bool ValidateSuperClassDescriptors(const Class* klass);
Brian Carlstromd1422f82011-09-28 11:37:09 -0700269 bool InitializeSuperClass(Class* klass, bool can_run_clinit);
270 void InitializeStaticFields(Class* klass);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700271
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 Carlstrom58ae9412011-10-04 00:56:06 -0700302 // For use by ImageWriter to find DexCaches for its roots
303 const std::vector<DexCache*>& GetDexCaches() {
304 return dex_caches_;
305 }
306
Brian Carlstrom16192862011-09-12 17:50:06 -0700307 // lock to protect ClassLinker state
308 mutable Mutex lock_;
309
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700310 std::vector<const OatFile*> oat_files_;
311
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700312 std::vector<const DexFile*> boot_class_path_;
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700313
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700314 std::vector<const DexFile*> dex_files_;
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700315 std::vector<DexCache*> dex_caches_;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700316
Brian Carlstrom9cff8e12011-08-18 16:47:29 -0700317 // multimap from a StringPiece hash code of a class descriptor to
318 // Class* instances. Results should be compared for a matching
319 // Class::descriptor_ and Class::class_loader_.
320 typedef std::tr1::unordered_multimap<size_t, Class*> Table;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700321 Table classes_;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700322
Brian Carlstroma663ea52011-08-19 23:33:41 -0700323 // indexes into class_roots_.
324 // needs to be kept in sync with class_roots_descriptors_.
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700325 enum ClassRoot {
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700326 kJavaLangClass,
327 kJavaLangObject,
Elliott Hughes418d20f2011-09-22 14:00:39 -0700328 kClassArrayClass,
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700329 kObjectArrayClass,
330 kJavaLangString,
Elliott Hughes80609252011-09-23 17:24:51 -0700331 kJavaLangReflectConstructor,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700332 kJavaLangReflectField,
333 kJavaLangReflectMethod,
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700334 kJavaLangClassLoader,
335 kDalvikSystemBaseDexClassLoader,
336 kDalvikSystemPathClassLoader,
Shih-wei Liao55df06b2011-08-26 14:39:27 -0700337 kJavaLangStackTraceElement,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700338 kPrimitiveBoolean,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700339 kPrimitiveByte,
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700340 kPrimitiveChar,
341 kPrimitiveDouble,
342 kPrimitiveFloat,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700343 kPrimitiveInt,
344 kPrimitiveLong,
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700345 kPrimitiveShort,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700346 kPrimitiveVoid,
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700347 kBooleanArrayClass,
348 kByteArrayClass,
349 kCharArrayClass,
350 kDoubleArrayClass,
351 kFloatArrayClass,
352 kIntArrayClass,
353 kLongArrayClass,
354 kShortArrayClass,
Shih-wei Liao55df06b2011-08-26 14:39:27 -0700355 kJavaLangStackTraceElementArrayClass,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700356 kClassRootsMax,
357 };
358 ObjectArray<Class>* class_roots_;
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700359
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700360 Class* GetClassRoot(ClassRoot class_root) {
Brian Carlstroma663ea52011-08-19 23:33:41 -0700361 DCHECK(class_roots_ != NULL);
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700362 Class* klass = class_roots_->Get(class_root);
363 DCHECK(klass != NULL);
364 return klass;
365 }
366
Brian Carlstroma663ea52011-08-19 23:33:41 -0700367 void SetClassRoot(ClassRoot class_root, Class* klass) {
368 DCHECK(!init_done_);
369
370 DCHECK(klass != NULL);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700371 DCHECK(klass->GetClassLoader() == NULL);
372 DCHECK(klass->GetDescriptor() != NULL);
373 DCHECK(klass->GetDescriptor()->Equals(GetClassRootDescriptor(class_root)));
Brian Carlstroma663ea52011-08-19 23:33:41 -0700374
375 DCHECK(class_roots_ != NULL);
376 DCHECK(class_roots_->Get(class_root) == NULL);
377 class_roots_->Set(class_root, klass);
378 }
379
Elliott Hughes418d20f2011-09-22 14:00:39 -0700380 static const char* class_roots_descriptors_[];
Brian Carlstroma663ea52011-08-19 23:33:41 -0700381
382 const char* GetClassRootDescriptor(ClassRoot class_root) {
383 const char* descriptor = class_roots_descriptors_[class_root];
384 CHECK(descriptor != NULL);
385 return descriptor;
386 }
387
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700388 ObjectArray<Class>* array_interfaces_;
Brian Carlstrom4b620ff2011-09-11 01:11:01 -0700389 ObjectArray<InterfaceEntry>* array_iftable_;
Carl Shapiro565f5072011-07-10 13:39:43 -0700390
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700391 bool init_done_;
392
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700393 InternTable* intern_table_;
394
Brian Carlstromf734cf52011-08-17 16:28:14 -0700395 friend class CommonTest;
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700396 FRIEND_TEST(DexCacheTest, Open);
397 friend class ObjectTest;
398 FRIEND_TEST(ObjectTest, AllocObjectArray);
Shih-wei Liao1a18c8c2011-08-14 17:47:36 -0700399 FRIEND_TEST(ExceptionTest, FindExceptionHandler);
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700400 friend class ImageWriter; // for GetDexCaches
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700401 DISALLOW_COPY_AND_ASSIGN(ClassLinker);
402};
403
404} // namespace art
405
406#endif // ART_SRC_CLASS_LINKER_H_