blob: 67bb35ca0387b2d8a5723542d19ac8a375ddbe94 [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_.
Brian Carlstromaded5f72011-10-07 17:15:04 -070053 Class* FindClass(const std::string& descriptor, const ClassLoader* class_loader);
54
55 Class* FindSystemClass(const std::string& descriptor) {
56 return FindClass(descriptor, NULL);
57 }
58
59 // Define a new a class based on a ClassDef from a DexFile
60 Class* DefineClass(const std::string& descriptor, const ClassLoader* class_loader,
61 const DexFile& dex_file, const DexFile::ClassDef& dex_class_def);
Elliott Hughes64bf5a32011-09-20 14:43:12 -070062
63 // Finds a class by its descriptor, returning NULL if it isn't wasn't loaded
64 // by the given 'class_loader'.
Brian Carlstromaded5f72011-10-07 17:15:04 -070065 Class* LookupClass(const std::string& descriptor, const ClassLoader* class_loader);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070066
Elliott Hughesd8ddfd52011-08-15 14:32:53 -070067 Class* FindPrimitiveClass(char type);
68
Elliott Hughes9d5ccec2011-09-19 13:19:50 -070069 void DumpAllClasses(int flags) const;
70
Elliott Hughese27955c2011-08-26 15:21:24 -070071 size_t NumLoadedClasses() const;
72
Brian Carlstromb63ec392011-08-27 17:38:27 -070073 // Resolve a String with the given index from the DexFile, storing the
Brian Carlstromaded5f72011-10-07 17:15:04 -070074 // result in the DexCache. The referrer is used to identify the
75 // target DexCache and ClassLoader to use for resolution.
76 String* ResolveString(uint32_t string_idx, const Method* referrer) {
77 Class* declaring_class = referrer->GetDeclaringClass();
78 DexCache* dex_cache = declaring_class->GetDexCache();
79 // TODO: we could check for a dex cache hit here
80 const DexFile& dex_file = FindDexFile(dex_cache);
81 return ResolveString(dex_file, string_idx, dex_cache);
82 }
83
84 // Resolve a String with the given index from the DexFile, storing the
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070085 // result in the DexCache.
Ian Rogers0cfe1fb2011-08-26 03:29:44 -070086 String* ResolveString(const DexFile& dex_file, uint32_t string_idx, DexCache* dex_cache);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070087
Brian Carlstromb63ec392011-08-27 17:38:27 -070088 // Resolve a Type with the given index from the DexFile, storing the
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070089 // result in the DexCache. The referrer is used to identity the
90 // target DexCache and ClassLoader to use for resolution.
91 Class* ResolveType(const DexFile& dex_file,
92 uint32_t type_idx,
93 const Class* referrer) {
94 return ResolveType(dex_file,
95 type_idx,
96 referrer->GetDexCache(),
97 referrer->GetClassLoader());
98 }
99
Brian Carlstromb63ec392011-08-27 17:38:27 -0700100 // Resolve a Type with the given index from the DexFile, storing the
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700101 // result in the DexCache. The referrer is used to identify the
Brian Carlstromb63ec392011-08-27 17:38:27 -0700102 // target DexCache and ClassLoader to use for resolution.
Brian Carlstromb9edb842011-08-28 16:31:06 -0700103 Class* ResolveType(uint32_t type_idx, const Method* referrer) {
Brian Carlstromb63ec392011-08-27 17:38:27 -0700104 Class* declaring_class = referrer->GetDeclaringClass();
105 DexCache* dex_cache = declaring_class->GetDexCache();
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700106 // TODO: we could check for a dex cache hit here
107 const ClassLoader* class_loader = declaring_class->GetClassLoader();
108 const DexFile& dex_file = FindDexFile(dex_cache);
109 return ResolveType(dex_file, type_idx, dex_cache, class_loader);
110 }
111
112 Class* ResolveType(uint32_t type_idx, const Field* referrer) {
113 Class* declaring_class = referrer->GetDeclaringClass();
114 DexCache* dex_cache = declaring_class->GetDexCache();
115 // TODO: we could check for a dex cache hit here
Brian Carlstromb63ec392011-08-27 17:38:27 -0700116 const ClassLoader* class_loader = declaring_class->GetClassLoader();
117 const DexFile& dex_file = FindDexFile(dex_cache);
118 return ResolveType(dex_file, type_idx, dex_cache, class_loader);
119 }
120
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700121 // Resolve a type with the given ID from the DexFile, storing the
122 // result in DexCache. The ClassLoader is used to search for the
123 // type, since it may be referenced from but not contained within
124 // the given DexFile.
125 Class* ResolveType(const DexFile& dex_file,
126 uint32_t type_idx,
127 DexCache* dex_cache,
128 const ClassLoader* class_loader);
129
130 // Resolve a method with a given ID from the DexFile, storing the
131 // result in DexCache. The ClassLinker and ClassLoader are used as
132 // in ResolveType. What is unique is the method type argument which
133 // is used to determine if this method is a direct, static, or
134 // virtual method.
135 Method* ResolveMethod(const DexFile& dex_file,
136 uint32_t method_idx,
137 DexCache* dex_cache,
138 const ClassLoader* class_loader,
Brian Carlstrom20cfffa2011-08-26 02:31:27 -0700139 bool is_direct);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700140
Brian Carlstrom16192862011-09-12 17:50:06 -0700141 Method* ResolveMethod(uint32_t method_idx, const Method* referrer, bool is_direct) {
142 Class* declaring_class = referrer->GetDeclaringClass();
143 DexCache* dex_cache = declaring_class->GetDexCache();
144 // TODO: we could check for a dex cache hit here
145 const ClassLoader* class_loader = declaring_class->GetClassLoader();
146 const DexFile& dex_file = FindDexFile(dex_cache);
147 return ResolveMethod(dex_file, method_idx, dex_cache, class_loader, is_direct);
148 }
149
Brian Carlstrom845490b2011-09-19 15:56:53 -0700150 Field* ResolveField(uint32_t field_idx, const Method* referrer, bool is_static) {
Brian Carlstromb9edb842011-08-28 16:31:06 -0700151 Class* declaring_class = referrer->GetDeclaringClass();
152 DexCache* dex_cache = declaring_class->GetDexCache();
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700153 // TODO: we could check for a dex cache hit here
Brian Carlstromb9edb842011-08-28 16:31:06 -0700154 const ClassLoader* class_loader = declaring_class->GetClassLoader();
155 const DexFile& dex_file = FindDexFile(dex_cache);
Brian Carlstrom845490b2011-09-19 15:56:53 -0700156 return ResolveField(dex_file, field_idx, dex_cache, class_loader, is_static);
Brian Carlstromb9edb842011-08-28 16:31:06 -0700157 }
158
Brian Carlstrom16192862011-09-12 17:50:06 -0700159 // Resolve a field with a given ID from the DexFile, storing the
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700160 // result in DexCache. The ClassLinker and ClassLoader are used as
161 // in ResolveType. What is unique is the is_static argument which is
162 // used to determine if we are resolving a static or non-static
163 // field.
164 Field* ResolveField(const DexFile& dex_file,
165 uint32_t field_idx,
166 DexCache* dex_cache,
167 const ClassLoader* class_loader,
168 bool is_static);
169
Ian Rogersad25ac52011-10-04 19:13:33 -0700170 // Get shorty from method index without resolution. Used to do handlerization.
171 const char* MethodShorty(uint32_t method_idx, Method* referrer);
172
Elliott Hughesf4c21c92011-08-19 17:31:31 -0700173 // Returns true on success, false if there's an exception pending.
Brian Carlstrom25c33252011-09-18 15:58:35 -0700174 // can_run_clinit=false allows the compiler to attempt to init a class,
175 // given the restriction that no <clinit> execution is possible.
176 bool EnsureInitialized(Class* c, bool can_run_clinit);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700177
Elliott Hughes2a20cfd2011-09-23 19:30:41 -0700178 // Initializes classes that have instances in the image but that have
179 // <clinit> methods so they could not be initialized by the compiler.
180 void RunRootClinits();
181
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700182 void RegisterDexFile(const DexFile& dex_file);
183 void RegisterDexFile(const DexFile& dex_file, DexCache* dex_cache);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700184
Brian Carlstrom8a487412011-08-29 20:08:52 -0700185 const std::vector<const DexFile*>& GetBootClassPath() {
186 return boot_class_path_;
187 }
188
Elliott Hughes410c0c82011-09-01 17:58:25 -0700189 void VisitRoots(Heap::RootVisitor* visitor, void* arg) const;
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700190
buzbeec143c552011-08-20 17:38:58 -0700191 const DexFile& FindDexFile(const DexCache* dex_cache) const;
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700192 DexCache* FindDexCache(const DexFile& dex_file) const;
Brian Carlstromaded5f72011-10-07 17:15:04 -0700193 bool IsDexFileRegistered(const DexFile& dex_file) const;
194 const OatFile* FindOatFile(const std::string& location);
buzbeec143c552011-08-20 17:38:58 -0700195
Elliott Hughes418d20f2011-09-22 14:00:39 -0700196 // TODO: replace this with multiple methods that allocate the correct managed type.
Shih-wei Liao44175362011-08-28 16:59:17 -0700197 template <class T>
198 ObjectArray<T>* AllocObjectArray(size_t length) {
199 return ObjectArray<T>::Alloc(GetClassRoot(kObjectArrayClass), length);
200 }
201
Elliott Hughes418d20f2011-09-22 14:00:39 -0700202 ObjectArray<Class>* AllocClassArray(size_t length) {
203 return ObjectArray<Class>::Alloc(GetClassRoot(kClassArrayClass), length);
204 }
205
Shih-wei Liao55df06b2011-08-26 14:39:27 -0700206 ObjectArray<StackTraceElement>* AllocStackTraceElementArray(size_t length);
207
jeffhao98eacac2011-09-14 16:11:53 -0700208 void VerifyClass(Class* klass);
209
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700210 private:
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700211 ClassLinker(InternTable*);
Carl Shapiro61e019d2011-07-14 16:53:09 -0700212
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700213 // Initialize class linker by bootstraping from dex files
214 void Init(const std::string& boot_class_path);
Carl Shapiro61e019d2011-07-14 16:53:09 -0700215
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700216 // Initialize class linker from one or more images.
217 void InitFromImage();
218 OatFile* OpenOat(const Space* space);
Brian Carlstrom78128a62011-09-15 17:21:19 -0700219 static void InitFromImageCallback(Object* obj, void* arg);
Brian Carlstromc74255f2011-09-11 22:47:39 -0700220 struct InitFromImageCallbackState;
Brian Carlstroma663ea52011-08-19 23:33:41 -0700221
222 void FinishInit();
223
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700224 // For early bootstrapping by Init
Brian Carlstrom4873d462011-08-21 15:23:39 -0700225 Class* AllocClass(Class* java_lang_Class, size_t class_size);
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700226
227 // Alloc* convenience functions to avoid needing to pass in Class*
228 // values that are known to the ClassLinker such as
229 // kObjectArrayClass and kJavaLangString etc.
Brian Carlstrom4873d462011-08-21 15:23:39 -0700230 Class* AllocClass(size_t class_size);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700231 DexCache* AllocDexCache(const DexFile& dex_file);
Jesse Wilson35baaab2011-08-10 16:18:03 -0400232 Field* AllocField();
Ian Rogersbdb03912011-09-14 00:55:44 -0700233
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700234 Method* AllocMethod();
Ian Rogersbdb03912011-09-14 00:55:44 -0700235
Brian Carlstrom9cc262e2011-08-28 12:45:30 -0700236 CodeAndDirectMethods* AllocCodeAndDirectMethods(size_t length);
Brian Carlstrom4b620ff2011-09-11 01:11:01 -0700237 InterfaceEntry* AllocInterfaceEntry(Class* interface);
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700238
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700239 Class* CreatePrimitiveClass(const char* descriptor,
Brian Carlstrom5b8e4c82011-09-18 01:38:59 -0700240 Class::PrimitiveType type) {
241 return InitializePrimitiveClass(AllocClass(sizeof(Class)), descriptor, type);
242 }
243 Class* InitializePrimitiveClass(Class* primitive_class,
244 const char* descriptor,
245 Class::PrimitiveType type);
246
Brian Carlstroma331b3c2011-07-18 17:47:56 -0700247
Brian Carlstromaded5f72011-10-07 17:15:04 -0700248 Class* CreateArrayClass(const std::string& descriptor,
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700249 const ClassLoader* class_loader);
Brian Carlstroma331b3c2011-07-18 17:47:56 -0700250
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700251 void AppendToBootClassPath(const DexFile& dex_file);
252 void AppendToBootClassPath(const DexFile& dex_file, DexCache* dex_cache);
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700253
Elliott Hughes5fe594f2011-09-08 12:33:17 -0700254 void ConstructFieldMap(const DexFile& dex_file, const DexFile::ClassDef& dex_class_def,
255 Class* c, std::map<int, Field*>& field_map);
256
Brian Carlstrom4873d462011-08-21 15:23:39 -0700257 size_t SizeOfClass(const DexFile& dex_file,
258 const DexFile::ClassDef& dex_class_def);
259
Brian Carlstromf615a612011-07-23 12:50:34 -0700260 void LoadClass(const DexFile& dex_file,
261 const DexFile::ClassDef& dex_class_def,
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700262 Class* klass,
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700263 const ClassLoader* class_loader);
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700264
Brian Carlstromf615a612011-07-23 12:50:34 -0700265 void LoadInterfaces(const DexFile& dex_file,
266 const DexFile::ClassDef& dex_class_def,
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700267 Class *klass);
268
Brian Carlstromf615a612011-07-23 12:50:34 -0700269 void LoadField(const DexFile& dex_file,
270 const DexFile::Field& dex_field,
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700271 Class* klass,
272 Field* dst);
273
Brian Carlstromf615a612011-07-23 12:50:34 -0700274 void LoadMethod(const DexFile& dex_file,
275 const DexFile::Method& dex_method,
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700276 Class* klass,
Brian Carlstrom1f870082011-08-23 16:02:11 -0700277 Method* dst);
Brian Carlstrom934486c2011-07-12 23:42:50 -0700278
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700279 // Inserts a class into the class table. Returns true if the class
280 // was inserted.
Brian Carlstromaded5f72011-10-07 17:15:04 -0700281 bool InsertClass(const std::string& descriptor, Class* klass);
282
283 void RegisterDexFileLocked(const DexFile& dex_file, DexCache* dex_cache);
284 bool IsDexFileRegisteredLocked(const DexFile& dex_file) const;
285
286 // Find, possibily opening, an OatFile corresponding to a DexFile
287 const OatFile* FindOatFile(const DexFile& dex_file);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700288
Brian Carlstromd1422f82011-09-28 11:37:09 -0700289 bool InitializeClass(Class* klass, bool can_run_clinit);
290 bool WaitForInitializeClass(Class* klass, Thread* self, ObjectLock& lock);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700291 bool ValidateSuperClassDescriptors(const Class* klass);
Brian Carlstromd1422f82011-09-28 11:37:09 -0700292 bool InitializeSuperClass(Class* klass, bool can_run_clinit);
293 void InitializeStaticFields(Class* klass);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700294
295 bool HasSameDescriptorClasses(const char* descriptor,
296 const Class* klass1,
297 const Class* klass2);
298
299 bool HasSameMethodDescriptorClasses(const Method* descriptor,
300 const Class* klass1,
301 const Class* klass2);
302
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700303 bool LinkClass(Class* klass);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700304
305 bool LinkSuperClass(Class* klass);
306
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700307 bool LoadSuperAndInterfaces(Class* klass, const DexFile& dex_file);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700308
309 bool LinkMethods(Class* klass);
310
311 bool LinkVirtualMethods(Class* klass);
312
313 bool LinkInterfaceMethods(Class* klass);
314
Jesse Wilson7833bd22011-08-09 18:31:44 -0400315 bool LinkStaticFields(Class* klass);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700316 bool LinkInstanceFields(Class* klass);
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700317 bool LinkFields(Class *klass, bool is_static);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700318
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700319
Brian Carlstrom4873d462011-08-21 15:23:39 -0700320 void CreateReferenceInstanceOffsets(Class* klass);
321 void CreateReferenceStaticOffsets(Class* klass);
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700322 void CreateReferenceOffsets(Class *klass, bool is_static,
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700323 uint32_t reference_offsets);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700324
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700325 // For use by ImageWriter to find DexCaches for its roots
326 const std::vector<DexCache*>& GetDexCaches() {
327 return dex_caches_;
328 }
329
Brian Carlstrom16192862011-09-12 17:50:06 -0700330 // lock to protect ClassLinker state
331 mutable Mutex lock_;
332
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700333 std::vector<const OatFile*> oat_files_;
334
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700335 std::vector<const DexFile*> boot_class_path_;
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700336
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700337 std::vector<const DexFile*> dex_files_;
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700338 std::vector<DexCache*> dex_caches_;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700339
Brian Carlstromaded5f72011-10-07 17:15:04 -0700340 // multimap from a string hash code of a class descriptor to
Brian Carlstrom9cff8e12011-08-18 16:47:29 -0700341 // Class* instances. Results should be compared for a matching
342 // Class::descriptor_ and Class::class_loader_.
343 typedef std::tr1::unordered_multimap<size_t, Class*> Table;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700344 Table classes_;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700345
Brian Carlstroma663ea52011-08-19 23:33:41 -0700346 // indexes into class_roots_.
347 // needs to be kept in sync with class_roots_descriptors_.
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700348 enum ClassRoot {
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700349 kJavaLangClass,
350 kJavaLangObject,
Elliott Hughes418d20f2011-09-22 14:00:39 -0700351 kClassArrayClass,
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700352 kObjectArrayClass,
353 kJavaLangString,
Elliott Hughes80609252011-09-23 17:24:51 -0700354 kJavaLangReflectConstructor,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700355 kJavaLangReflectField,
356 kJavaLangReflectMethod,
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700357 kJavaLangClassLoader,
358 kDalvikSystemBaseDexClassLoader,
359 kDalvikSystemPathClassLoader,
Shih-wei Liao55df06b2011-08-26 14:39:27 -0700360 kJavaLangStackTraceElement,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700361 kPrimitiveBoolean,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700362 kPrimitiveByte,
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700363 kPrimitiveChar,
364 kPrimitiveDouble,
365 kPrimitiveFloat,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700366 kPrimitiveInt,
367 kPrimitiveLong,
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700368 kPrimitiveShort,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700369 kPrimitiveVoid,
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700370 kBooleanArrayClass,
371 kByteArrayClass,
372 kCharArrayClass,
373 kDoubleArrayClass,
374 kFloatArrayClass,
375 kIntArrayClass,
376 kLongArrayClass,
377 kShortArrayClass,
Shih-wei Liao55df06b2011-08-26 14:39:27 -0700378 kJavaLangStackTraceElementArrayClass,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700379 kClassRootsMax,
380 };
381 ObjectArray<Class>* class_roots_;
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700382
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700383 Class* GetClassRoot(ClassRoot class_root) {
Brian Carlstroma663ea52011-08-19 23:33:41 -0700384 DCHECK(class_roots_ != NULL);
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700385 Class* klass = class_roots_->Get(class_root);
386 DCHECK(klass != NULL);
387 return klass;
388 }
389
Brian Carlstroma663ea52011-08-19 23:33:41 -0700390 void SetClassRoot(ClassRoot class_root, Class* klass) {
391 DCHECK(!init_done_);
392
393 DCHECK(klass != NULL);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700394 DCHECK(klass->GetClassLoader() == NULL);
395 DCHECK(klass->GetDescriptor() != NULL);
396 DCHECK(klass->GetDescriptor()->Equals(GetClassRootDescriptor(class_root)));
Brian Carlstroma663ea52011-08-19 23:33:41 -0700397
398 DCHECK(class_roots_ != NULL);
399 DCHECK(class_roots_->Get(class_root) == NULL);
400 class_roots_->Set(class_root, klass);
401 }
402
Brian Carlstrom34f426c2011-10-04 12:58:02 -0700403 ObjectArray<Class>* GetClassRoots() {
404 DCHECK(class_roots_ != NULL);
405 return class_roots_;
406 }
407
Elliott Hughes418d20f2011-09-22 14:00:39 -0700408 static const char* class_roots_descriptors_[];
Brian Carlstroma663ea52011-08-19 23:33:41 -0700409
410 const char* GetClassRootDescriptor(ClassRoot class_root) {
411 const char* descriptor = class_roots_descriptors_[class_root];
412 CHECK(descriptor != NULL);
413 return descriptor;
414 }
415
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700416 ObjectArray<Class>* array_interfaces_;
Brian Carlstrom4b620ff2011-09-11 01:11:01 -0700417 ObjectArray<InterfaceEntry>* array_iftable_;
Carl Shapiro565f5072011-07-10 13:39:43 -0700418
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700419 bool init_done_;
420
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700421 InternTable* intern_table_;
422
Brian Carlstromf734cf52011-08-17 16:28:14 -0700423 friend class CommonTest;
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700424 FRIEND_TEST(DexCacheTest, Open);
425 friend class ObjectTest;
426 FRIEND_TEST(ObjectTest, AllocObjectArray);
Shih-wei Liao1a18c8c2011-08-14 17:47:36 -0700427 FRIEND_TEST(ExceptionTest, FindExceptionHandler);
Brian Carlstrom34f426c2011-10-04 12:58:02 -0700428 friend class ImageWriter; // for GetClassRoots
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700429 DISALLOW_COPY_AND_ASSIGN(ClassLinker);
430};
431
432} // namespace art
433
434#endif // ART_SRC_CLASS_LINKER_H_