blob: 75eefc9e17a40f84531a161294edf8bfe6168c5d [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
Ian Rogersad25ac52011-10-04 19:13:33 -0700158 // Get shorty from method index without resolution. Used to do handlerization.
159 const char* MethodShorty(uint32_t method_idx, Method* referrer);
160
Elliott Hughesf4c21c92011-08-19 17:31:31 -0700161 // Returns true on success, false if there's an exception pending.
Brian Carlstrom25c33252011-09-18 15:58:35 -0700162 // can_run_clinit=false allows the compiler to attempt to init a class,
163 // given the restriction that no <clinit> execution is possible.
164 bool EnsureInitialized(Class* c, bool can_run_clinit);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700165
Elliott Hughes2a20cfd2011-09-23 19:30:41 -0700166 // Initializes classes that have instances in the image but that have
167 // <clinit> methods so they could not be initialized by the compiler.
168 void RunRootClinits();
169
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700170 void RegisterDexFile(const DexFile& dex_file);
171 void RegisterDexFile(const DexFile& dex_file, DexCache* dex_cache);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700172
Brian Carlstrom8a487412011-08-29 20:08:52 -0700173 const std::vector<const DexFile*>& GetBootClassPath() {
174 return boot_class_path_;
175 }
176
Elliott Hughes410c0c82011-09-01 17:58:25 -0700177 void VisitRoots(Heap::RootVisitor* visitor, void* arg) const;
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700178
buzbeec143c552011-08-20 17:38:58 -0700179 const DexFile& FindDexFile(const DexCache* dex_cache) const;
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700180 DexCache* FindDexCache(const DexFile& dex_file) const;
buzbeec143c552011-08-20 17:38:58 -0700181
Elliott Hughes418d20f2011-09-22 14:00:39 -0700182 // TODO: replace this with multiple methods that allocate the correct managed type.
Shih-wei Liao44175362011-08-28 16:59:17 -0700183 template <class T>
184 ObjectArray<T>* AllocObjectArray(size_t length) {
185 return ObjectArray<T>::Alloc(GetClassRoot(kObjectArrayClass), length);
186 }
187
Elliott Hughes418d20f2011-09-22 14:00:39 -0700188 ObjectArray<Class>* AllocClassArray(size_t length) {
189 return ObjectArray<Class>::Alloc(GetClassRoot(kClassArrayClass), length);
190 }
191
Shih-wei Liao55df06b2011-08-26 14:39:27 -0700192 ObjectArray<StackTraceElement>* AllocStackTraceElementArray(size_t length);
193
jeffhao98eacac2011-09-14 16:11:53 -0700194 void VerifyClass(Class* klass);
195
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700196 private:
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700197 ClassLinker(InternTable*);
Carl Shapiro61e019d2011-07-14 16:53:09 -0700198
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700199 // Initialize class linker by bootstraping from dex files
200 void Init(const std::string& boot_class_path);
Carl Shapiro61e019d2011-07-14 16:53:09 -0700201
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700202 // Initialize class linker from one or more images.
203 void InitFromImage();
204 OatFile* OpenOat(const Space* space);
Brian Carlstrom78128a62011-09-15 17:21:19 -0700205 static void InitFromImageCallback(Object* obj, void* arg);
Brian Carlstromc74255f2011-09-11 22:47:39 -0700206 struct InitFromImageCallbackState;
Brian Carlstroma663ea52011-08-19 23:33:41 -0700207
208 void FinishInit();
209
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700210 // For early bootstrapping by Init
Brian Carlstrom4873d462011-08-21 15:23:39 -0700211 Class* AllocClass(Class* java_lang_Class, size_t class_size);
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700212
213 // Alloc* convenience functions to avoid needing to pass in Class*
214 // values that are known to the ClassLinker such as
215 // kObjectArrayClass and kJavaLangString etc.
Brian Carlstrom4873d462011-08-21 15:23:39 -0700216 Class* AllocClass(size_t class_size);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700217 DexCache* AllocDexCache(const DexFile& dex_file);
Jesse Wilson35baaab2011-08-10 16:18:03 -0400218 Field* AllocField();
Ian Rogersbdb03912011-09-14 00:55:44 -0700219
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700220 Method* AllocMethod();
Ian Rogersbdb03912011-09-14 00:55:44 -0700221
Brian Carlstrom9cc262e2011-08-28 12:45:30 -0700222 CodeAndDirectMethods* AllocCodeAndDirectMethods(size_t length);
Brian Carlstrom4b620ff2011-09-11 01:11:01 -0700223 InterfaceEntry* AllocInterfaceEntry(Class* interface);
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700224
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700225 Class* CreatePrimitiveClass(const char* descriptor,
Brian Carlstrom5b8e4c82011-09-18 01:38:59 -0700226 Class::PrimitiveType type) {
227 return InitializePrimitiveClass(AllocClass(sizeof(Class)), descriptor, type);
228 }
229 Class* InitializePrimitiveClass(Class* primitive_class,
230 const char* descriptor,
231 Class::PrimitiveType type);
232
Brian Carlstroma331b3c2011-07-18 17:47:56 -0700233
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700234 Class* CreateArrayClass(const StringPiece& descriptor,
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700235 const ClassLoader* class_loader);
Brian Carlstroma331b3c2011-07-18 17:47:56 -0700236
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700237 void AppendToBootClassPath(const DexFile& dex_file);
238 void AppendToBootClassPath(const DexFile& dex_file, DexCache* dex_cache);
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700239
Elliott Hughes5fe594f2011-09-08 12:33:17 -0700240 void ConstructFieldMap(const DexFile& dex_file, const DexFile::ClassDef& dex_class_def,
241 Class* c, std::map<int, Field*>& field_map);
242
Brian Carlstrom4873d462011-08-21 15:23:39 -0700243 size_t SizeOfClass(const DexFile& dex_file,
244 const DexFile::ClassDef& dex_class_def);
245
Brian Carlstromf615a612011-07-23 12:50:34 -0700246 void LoadClass(const DexFile& dex_file,
247 const DexFile::ClassDef& dex_class_def,
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700248 Class* klass,
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700249 const ClassLoader* class_loader);
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700250
Brian Carlstromf615a612011-07-23 12:50:34 -0700251 void LoadInterfaces(const DexFile& dex_file,
252 const DexFile::ClassDef& dex_class_def,
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700253 Class *klass);
254
Brian Carlstromf615a612011-07-23 12:50:34 -0700255 void LoadField(const DexFile& dex_file,
256 const DexFile::Field& dex_field,
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700257 Class* klass,
258 Field* dst);
259
Brian Carlstromf615a612011-07-23 12:50:34 -0700260 void LoadMethod(const DexFile& dex_file,
261 const DexFile::Method& dex_method,
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700262 Class* klass,
Brian Carlstrom1f870082011-08-23 16:02:11 -0700263 Method* dst);
Brian Carlstrom934486c2011-07-12 23:42:50 -0700264
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700265 // Inserts a class into the class table. Returns true if the class
266 // was inserted.
Brian Carlstrom9cff8e12011-08-18 16:47:29 -0700267 bool InsertClass(const StringPiece& descriptor, Class* klass);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700268
Brian Carlstromd1422f82011-09-28 11:37:09 -0700269 bool InitializeClass(Class* klass, bool can_run_clinit);
270 bool WaitForInitializeClass(Class* klass, Thread* self, ObjectLock& lock);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700271 bool ValidateSuperClassDescriptors(const Class* klass);
Brian Carlstromd1422f82011-09-28 11:37:09 -0700272 bool InitializeSuperClass(Class* klass, bool can_run_clinit);
273 void InitializeStaticFields(Class* klass);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700274
275 bool HasSameDescriptorClasses(const char* descriptor,
276 const Class* klass1,
277 const Class* klass2);
278
279 bool HasSameMethodDescriptorClasses(const Method* descriptor,
280 const Class* klass1,
281 const Class* klass2);
282
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700283 bool LinkClass(Class* klass);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700284
285 bool LinkSuperClass(Class* klass);
286
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700287 bool LoadSuperAndInterfaces(Class* klass, const DexFile& dex_file);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700288
289 bool LinkMethods(Class* klass);
290
291 bool LinkVirtualMethods(Class* klass);
292
293 bool LinkInterfaceMethods(Class* klass);
294
Jesse Wilson7833bd22011-08-09 18:31:44 -0400295 bool LinkStaticFields(Class* klass);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700296 bool LinkInstanceFields(Class* klass);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700297 bool LinkFields(Class *klass, bool instance);
298
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700299
Brian Carlstrom4873d462011-08-21 15:23:39 -0700300 void CreateReferenceInstanceOffsets(Class* klass);
301 void CreateReferenceStaticOffsets(Class* klass);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700302 void CreateReferenceOffsets(Class *klass, bool instance,
303 uint32_t reference_offsets);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700304
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700305 // For use by ImageWriter to find DexCaches for its roots
306 const std::vector<DexCache*>& GetDexCaches() {
307 return dex_caches_;
308 }
309
Brian Carlstrom16192862011-09-12 17:50:06 -0700310 // lock to protect ClassLinker state
311 mutable Mutex lock_;
312
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700313 std::vector<const OatFile*> oat_files_;
314
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700315 std::vector<const DexFile*> boot_class_path_;
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700316
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700317 std::vector<const DexFile*> dex_files_;
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700318 std::vector<DexCache*> dex_caches_;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700319
Brian Carlstrom9cff8e12011-08-18 16:47:29 -0700320 // multimap from a StringPiece hash code of a class descriptor to
321 // Class* instances. Results should be compared for a matching
322 // Class::descriptor_ and Class::class_loader_.
323 typedef std::tr1::unordered_multimap<size_t, Class*> Table;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700324 Table classes_;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700325
Brian Carlstroma663ea52011-08-19 23:33:41 -0700326 // indexes into class_roots_.
327 // needs to be kept in sync with class_roots_descriptors_.
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700328 enum ClassRoot {
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700329 kJavaLangClass,
330 kJavaLangObject,
Elliott Hughes418d20f2011-09-22 14:00:39 -0700331 kClassArrayClass,
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700332 kObjectArrayClass,
333 kJavaLangString,
Elliott Hughes80609252011-09-23 17:24:51 -0700334 kJavaLangReflectConstructor,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700335 kJavaLangReflectField,
336 kJavaLangReflectMethod,
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700337 kJavaLangClassLoader,
338 kDalvikSystemBaseDexClassLoader,
339 kDalvikSystemPathClassLoader,
Shih-wei Liao55df06b2011-08-26 14:39:27 -0700340 kJavaLangStackTraceElement,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700341 kPrimitiveBoolean,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700342 kPrimitiveByte,
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700343 kPrimitiveChar,
344 kPrimitiveDouble,
345 kPrimitiveFloat,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700346 kPrimitiveInt,
347 kPrimitiveLong,
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700348 kPrimitiveShort,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700349 kPrimitiveVoid,
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700350 kBooleanArrayClass,
351 kByteArrayClass,
352 kCharArrayClass,
353 kDoubleArrayClass,
354 kFloatArrayClass,
355 kIntArrayClass,
356 kLongArrayClass,
357 kShortArrayClass,
Shih-wei Liao55df06b2011-08-26 14:39:27 -0700358 kJavaLangStackTraceElementArrayClass,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700359 kClassRootsMax,
360 };
361 ObjectArray<Class>* class_roots_;
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700362
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700363 Class* GetClassRoot(ClassRoot class_root) {
Brian Carlstroma663ea52011-08-19 23:33:41 -0700364 DCHECK(class_roots_ != NULL);
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700365 Class* klass = class_roots_->Get(class_root);
366 DCHECK(klass != NULL);
367 return klass;
368 }
369
Brian Carlstroma663ea52011-08-19 23:33:41 -0700370 void SetClassRoot(ClassRoot class_root, Class* klass) {
371 DCHECK(!init_done_);
372
373 DCHECK(klass != NULL);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700374 DCHECK(klass->GetClassLoader() == NULL);
375 DCHECK(klass->GetDescriptor() != NULL);
376 DCHECK(klass->GetDescriptor()->Equals(GetClassRootDescriptor(class_root)));
Brian Carlstroma663ea52011-08-19 23:33:41 -0700377
378 DCHECK(class_roots_ != NULL);
379 DCHECK(class_roots_->Get(class_root) == NULL);
380 class_roots_->Set(class_root, klass);
381 }
382
Brian Carlstrom34f426c2011-10-04 12:58:02 -0700383 ObjectArray<Class>* GetClassRoots() {
384 DCHECK(class_roots_ != NULL);
385 return class_roots_;
386 }
387
Elliott Hughes418d20f2011-09-22 14:00:39 -0700388 static const char* class_roots_descriptors_[];
Brian Carlstroma663ea52011-08-19 23:33:41 -0700389
390 const char* GetClassRootDescriptor(ClassRoot class_root) {
391 const char* descriptor = class_roots_descriptors_[class_root];
392 CHECK(descriptor != NULL);
393 return descriptor;
394 }
395
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700396 ObjectArray<Class>* array_interfaces_;
Brian Carlstrom4b620ff2011-09-11 01:11:01 -0700397 ObjectArray<InterfaceEntry>* array_iftable_;
Carl Shapiro565f5072011-07-10 13:39:43 -0700398
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700399 bool init_done_;
400
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700401 InternTable* intern_table_;
402
Brian Carlstromf734cf52011-08-17 16:28:14 -0700403 friend class CommonTest;
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700404 FRIEND_TEST(DexCacheTest, Open);
405 friend class ObjectTest;
406 FRIEND_TEST(ObjectTest, AllocObjectArray);
Shih-wei Liao1a18c8c2011-08-14 17:47:36 -0700407 FRIEND_TEST(ExceptionTest, FindExceptionHandler);
Brian Carlstrom34f426c2011-10-04 12:58:02 -0700408 friend class ImageWriter; // for GetClassRoots
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700409 DISALLOW_COPY_AND_ASSIGN(ClassLinker);
410};
411
412} // namespace art
413
414#endif // ART_SRC_CLASS_LINKER_H_