blob: c69c442f3e78a6d3dd87c63122fd873341876208 [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
Ian Rogers6d4d9fc2011-11-30 16:24:48 -080020#include <string>
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070021#include <utility>
22#include <vector>
23
Ian Rogerscaab8c42011-10-12 12:11:18 -070024#include "dex_cache.h"
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070025#include "dex_file.h"
Elliott Hughese5448b52012-01-18 16:44:06 -080026#include "gtest/gtest.h"
Brian Carlstrom7e93b502011-08-04 14:16:22 -070027#include "heap.h"
Brian Carlstrom7e93b502011-08-04 14:16:22 -070028#include "macros.h"
Elliott Hughes8daa0922011-09-11 13:46:25 -070029#include "mutex.h"
Brian Carlstrom58ae9412011-10-04 00:56:06 -070030#include "oat_file.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070031#include "object.h"
Elliott Hughesa0e18062012-04-13 15:59:59 -070032#include "safe_map.h"
Brian Carlstrom40381fb2011-10-19 14:13:40 -070033#include "stack_indirect_reference_table.h"
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070034
35namespace art {
36
Elliott Hughescf4c6c42011-09-01 15:16:42 -070037class ClassLoader;
Ian Rogers30fab402012-01-23 15:43:46 -080038class ImageSpace;
Elliott Hughescf4c6c42011-09-01 15:16:42 -070039class InternTable;
Brian Carlstromd1422f82011-09-28 11:37:09 -070040class ObjectLock;
Elliott Hughescf4c6c42011-09-01 15:16:42 -070041
Elliott Hughesa2155262011-11-16 16:26:58 -080042typedef bool (ClassVisitor)(Class* c, void* arg);
43
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070044class ClassLinker {
45 public:
Brian Carlstrom58ae9412011-10-04 00:56:06 -070046 // Creates the class linker by boot strapping from dex files.
Brian Carlstroma004aa92012-02-08 18:05:09 -080047 static ClassLinker* CreateFromCompiler(const std::vector<const DexFile*>& boot_class_path,
Ian Rogers00f7d0e2012-07-19 15:28:27 -070048 InternTable* intern_table)
49 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Brian Carlstrom58ae9412011-10-04 00:56:06 -070050
Brian Carlstroma004aa92012-02-08 18:05:09 -080051 // Creates the class linker from an image.
Ian Rogers00f7d0e2012-07-19 15:28:27 -070052 static ClassLinker* CreateFromImage(InternTable* intern_table)
53 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Carl Shapiro61e019d2011-07-14 16:53:09 -070054
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070055 ~ClassLinker();
Carl Shapiro565f5072011-07-10 13:39:43 -070056
Elliott Hughes64bf5a32011-09-20 14:43:12 -070057 // Finds a class by its descriptor, loading it if necessary.
Brian Carlstrom74eb46a2011-08-02 20:10:14 -070058 // If class_loader is null, searches boot_class_path_.
Ian Rogers00f7d0e2012-07-19 15:28:27 -070059 Class* FindClass(const char* descriptor, ClassLoader* class_loader)
60 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Brian Carlstromaded5f72011-10-07 17:15:04 -070061
Ian Rogers00f7d0e2012-07-19 15:28:27 -070062 Class* FindSystemClass(const char* descriptor)
63 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Brian Carlstromaded5f72011-10-07 17:15:04 -070064
65 // Define a new a class based on a ClassDef from a DexFile
Ian Rogers365c1022012-06-22 15:05:28 -070066 Class* DefineClass(const StringPiece& descriptor, ClassLoader* class_loader,
Ian Rogers00f7d0e2012-07-19 15:28:27 -070067 const DexFile& dex_file, const DexFile::ClassDef& dex_class_def)
68 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Elliott Hughes64bf5a32011-09-20 14:43:12 -070069
70 // Finds a class by its descriptor, returning NULL if it isn't wasn't loaded
71 // by the given 'class_loader'.
Ian Rogers00f7d0e2012-07-19 15:28:27 -070072 Class* LookupClass(const char* descriptor, const ClassLoader* class_loader)
73 LOCKS_EXCLUDED(GlobalSynchronization::classlinker_classes_lock_)
74 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070075
Elliott Hughes6fa602d2011-12-02 17:54:25 -080076 // Finds all the classes with the given descriptor, regardless of ClassLoader.
Ian Rogers00f7d0e2012-07-19 15:28:27 -070077 void LookupClasses(const char* descriptor, std::vector<Class*>& classes)
78 LOCKS_EXCLUDED(GlobalSynchronization::classlinker_classes_lock_)
79 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Elliott Hughes6fa602d2011-12-02 17:54:25 -080080
Ian Rogers00f7d0e2012-07-19 15:28:27 -070081 Class* FindPrimitiveClass(char type) SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Elliott Hughesd8ddfd52011-08-15 14:32:53 -070082
Brian Carlstromae826982011-11-09 01:33:42 -080083 // General class unloading is not supported, this is used to prune
84 // unwanted classes during image writing.
Ian Rogers00f7d0e2012-07-19 15:28:27 -070085 bool RemoveClass(const char* descriptor, const ClassLoader* class_loader)
86 LOCKS_EXCLUDED(GlobalSynchronization::classlinker_classes_lock_)
87 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Brian Carlstromae826982011-11-09 01:33:42 -080088
Ian Rogers00f7d0e2012-07-19 15:28:27 -070089 void DumpAllClasses(int flags) const
90 LOCKS_EXCLUDED(GlobalSynchronization::classlinker_classes_lock_)
91 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Elliott Hughes9d5ccec2011-09-19 13:19:50 -070092
Ian Rogers00f7d0e2012-07-19 15:28:27 -070093 void DumpForSigQuit(std::ostream& os) const
94 LOCKS_EXCLUDED(GlobalSynchronization::classlinker_classes_lock_);
Elliott Hughescac6cc72011-11-03 20:31:21 -070095
Ian Rogers00f7d0e2012-07-19 15:28:27 -070096 size_t NumLoadedClasses() const LOCKS_EXCLUDED(GlobalSynchronization::classlinker_classes_lock_);
Elliott Hughese27955c2011-08-26 15:21:24 -070097
Brian Carlstromb63ec392011-08-27 17:38:27 -070098 // Resolve a String with the given index from the DexFile, storing the
Brian Carlstromaded5f72011-10-07 17:15:04 -070099 // result in the DexCache. The referrer is used to identify the
100 // target DexCache and ClassLoader to use for resolution.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700101 String* ResolveString(uint32_t string_idx, const Method* referrer)
102 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_) {
Ian Rogerscaab8c42011-10-12 12:11:18 -0700103 String* resolved_string = referrer->GetDexCacheStrings()->Get(string_idx);
104 if (UNLIKELY(resolved_string == NULL)) {
105 Class* declaring_class = referrer->GetDeclaringClass();
106 DexCache* dex_cache = declaring_class->GetDexCache();
107 const DexFile& dex_file = FindDexFile(dex_cache);
108 resolved_string = ResolveString(dex_file, string_idx, dex_cache);
109 }
110 return resolved_string;
Brian Carlstromaded5f72011-10-07 17:15:04 -0700111 }
112
113 // Resolve a String with the given index from the DexFile, storing the
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700114 // result in the DexCache.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700115 String* ResolveString(const DexFile& dex_file, uint32_t string_idx, DexCache* dex_cache)
116 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700117
Brian Carlstromb63ec392011-08-27 17:38:27 -0700118 // Resolve a Type with the given index from the DexFile, storing the
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700119 // result in the DexCache. The referrer is used to identity the
120 // target DexCache and ClassLoader to use for resolution.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700121 Class* ResolveType(const DexFile& dex_file, uint16_t type_idx, const Class* referrer)
122 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_) {
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700123 return ResolveType(dex_file,
124 type_idx,
125 referrer->GetDexCache(),
126 referrer->GetClassLoader());
127 }
128
Brian Carlstromb63ec392011-08-27 17:38:27 -0700129 // Resolve a Type with the given index from the DexFile, storing the
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700130 // result in the DexCache. The referrer is used to identify the
Brian Carlstromb63ec392011-08-27 17:38:27 -0700131 // target DexCache and ClassLoader to use for resolution.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700132 Class* ResolveType(uint16_t type_idx, const Method* referrer)
133 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_) {
Ian Rogerscaab8c42011-10-12 12:11:18 -0700134 Class* resolved_type = referrer->GetDexCacheResolvedTypes()->Get(type_idx);
135 if (UNLIKELY(resolved_type == NULL)) {
136 Class* declaring_class = referrer->GetDeclaringClass();
137 DexCache* dex_cache = declaring_class->GetDexCache();
Ian Rogers365c1022012-06-22 15:05:28 -0700138 ClassLoader* class_loader = declaring_class->GetClassLoader();
Ian Rogerscaab8c42011-10-12 12:11:18 -0700139 const DexFile& dex_file = FindDexFile(dex_cache);
140 resolved_type = ResolveType(dex_file, type_idx, dex_cache, class_loader);
141 }
142 return resolved_type;
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700143 }
144
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700145 Class* ResolveType(uint16_t type_idx, const Field* referrer)
146 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_) {
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700147 Class* declaring_class = referrer->GetDeclaringClass();
148 DexCache* dex_cache = declaring_class->GetDexCache();
Ian Rogerscaab8c42011-10-12 12:11:18 -0700149 Class* resolved_type = dex_cache->GetResolvedType(type_idx);
150 if (UNLIKELY(resolved_type == NULL)) {
Ian Rogers365c1022012-06-22 15:05:28 -0700151 ClassLoader* class_loader = declaring_class->GetClassLoader();
Ian Rogerscaab8c42011-10-12 12:11:18 -0700152 const DexFile& dex_file = FindDexFile(dex_cache);
153 resolved_type = ResolveType(dex_file, type_idx, dex_cache, class_loader);
154 }
155 return resolved_type;
Brian Carlstromb63ec392011-08-27 17:38:27 -0700156 }
157
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700158 // Resolve a type with the given ID from the DexFile, storing the
159 // result in DexCache. The ClassLoader is used to search for the
160 // type, since it may be referenced from but not contained within
161 // the given DexFile.
162 Class* ResolveType(const DexFile& dex_file,
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800163 uint16_t type_idx,
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700164 DexCache* dex_cache,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700165 ClassLoader* class_loader)
166 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700167
168 // Resolve a method with a given ID from the DexFile, storing the
169 // result in DexCache. The ClassLinker and ClassLoader are used as
170 // in ResolveType. What is unique is the method type argument which
171 // is used to determine if this method is a direct, static, or
172 // virtual method.
173 Method* ResolveMethod(const DexFile& dex_file,
174 uint32_t method_idx,
175 DexCache* dex_cache,
Ian Rogers365c1022012-06-22 15:05:28 -0700176 ClassLoader* class_loader,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700177 bool is_direct)
178 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700179
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700180 Method* ResolveMethod(uint32_t method_idx, const Method* referrer, bool is_direct)
181 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_) {
Ian Rogers19846512012-02-24 11:42:47 -0800182 Method* resolved_method = referrer->GetDexCacheResolvedMethods()->Get(method_idx);
183 if (UNLIKELY(resolved_method == NULL || resolved_method->IsRuntimeMethod())) {
184 Class* declaring_class = referrer->GetDeclaringClass();
185 DexCache* dex_cache = declaring_class->GetDexCache();
Ian Rogers365c1022012-06-22 15:05:28 -0700186 ClassLoader* class_loader = declaring_class->GetClassLoader();
Ian Rogerscaab8c42011-10-12 12:11:18 -0700187 const DexFile& dex_file = FindDexFile(dex_cache);
188 resolved_method = ResolveMethod(dex_file, method_idx, dex_cache, class_loader, is_direct);
189 }
190 return resolved_method;
Brian Carlstrom16192862011-09-12 17:50:06 -0700191 }
192
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700193 Field* ResolveField(uint32_t field_idx, const Method* referrer, bool is_static)
194 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_) {
Ian Rogersb5d6a492012-02-14 04:00:51 -0800195 Field* resolved_field =
196 referrer->GetDeclaringClass()->GetDexCache()->GetResolvedField(field_idx);
Ian Rogerscaab8c42011-10-12 12:11:18 -0700197 if (UNLIKELY(resolved_field == NULL)) {
Ian Rogersb5d6a492012-02-14 04:00:51 -0800198 Class* declaring_class = referrer->GetDeclaringClass();
199 DexCache* dex_cache = declaring_class->GetDexCache();
Ian Rogers365c1022012-06-22 15:05:28 -0700200 ClassLoader* class_loader = declaring_class->GetClassLoader();
Ian Rogerscaab8c42011-10-12 12:11:18 -0700201 const DexFile& dex_file = FindDexFile(dex_cache);
202 resolved_field = ResolveField(dex_file, field_idx, dex_cache, class_loader, is_static);
203 }
204 return resolved_field;
Brian Carlstromb9edb842011-08-28 16:31:06 -0700205 }
206
Brian Carlstrom16192862011-09-12 17:50:06 -0700207 // Resolve a field with a given ID from the DexFile, storing the
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700208 // result in DexCache. The ClassLinker and ClassLoader are used as
209 // in ResolveType. What is unique is the is_static argument which is
210 // used to determine if we are resolving a static or non-static
211 // field.
212 Field* ResolveField(const DexFile& dex_file,
213 uint32_t field_idx,
214 DexCache* dex_cache,
Ian Rogers365c1022012-06-22 15:05:28 -0700215 ClassLoader* class_loader,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700216 bool is_static)
217 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700218
Ian Rogersb067ac22011-12-13 18:05:09 -0800219 // Resolve a field with a given ID from the DexFile, storing the
220 // result in DexCache. The ClassLinker and ClassLoader are used as
221 // in ResolveType. No is_static argument is provided so that Java
222 // field resolution semantics are followed.
223 Field* ResolveFieldJLS(const DexFile& dex_file,
224 uint32_t field_idx,
225 DexCache* dex_cache,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700226 ClassLoader* class_loader)
227 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Ian Rogersb067ac22011-12-13 18:05:09 -0800228
Ian Rogersad25ac52011-10-04 19:13:33 -0700229 // Get shorty from method index without resolution. Used to do handlerization.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700230 const char* MethodShorty(uint32_t method_idx, Method* referrer, uint32_t* length)
231 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Ian Rogersad25ac52011-10-04 19:13:33 -0700232
Elliott Hughesf4c21c92011-08-19 17:31:31 -0700233 // Returns true on success, false if there's an exception pending.
Brian Carlstrom25c33252011-09-18 15:58:35 -0700234 // can_run_clinit=false allows the compiler to attempt to init a class,
235 // given the restriction that no <clinit> execution is possible.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700236 bool EnsureInitialized(Class* c, bool can_run_clinit, bool can_init_fields)
237 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700238
Elliott Hughes2a20cfd2011-09-23 19:30:41 -0700239 // Initializes classes that have instances in the image but that have
240 // <clinit> methods so they could not be initialized by the compiler.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700241 void RunRootClinits() SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Elliott Hughes2a20cfd2011-09-23 19:30:41 -0700242
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700243 void RegisterDexFile(const DexFile& dex_file)
244 LOCKS_EXCLUDED(dex_lock_)
245 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
246 void RegisterDexFile(const DexFile& dex_file, SirtRef<DexCache>& dex_cache)
247 LOCKS_EXCLUDED(dex_lock_)
248 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700249
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700250 void RegisterOatFile(const OatFile& oat_file)
251 LOCKS_EXCLUDED(dex_lock_);
Brian Carlstrom866c8622012-01-06 16:35:13 -0800252
Brian Carlstrom8a487412011-08-29 20:08:52 -0700253 const std::vector<const DexFile*>& GetBootClassPath() {
254 return boot_class_path_;
255 }
256
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700257 void VisitClasses(ClassVisitor* visitor, void* arg) const
258 LOCKS_EXCLUDED(GlobalSynchronization::classlinker_classes_lock_);
259 // Less efficient variant of VisitClasses that doesn't hold the classlinker_classes_lock_
260 // when calling the visitor.
261 void VisitClassesWithoutClassesLock(ClassVisitor* visitor, void* arg) const
262 LOCKS_EXCLUDED(GlobalSynchronization::classlinker_classes_lock_);
Elliott Hughesa2155262011-11-16 16:26:58 -0800263
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700264 void VisitRoots(Heap::RootVisitor* visitor, void* arg) const
265 LOCKS_EXCLUDED(GlobalSynchronization::classlinker_classes_lock_, dex_lock_);
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700266
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700267 const DexFile& FindDexFile(const DexCache* dex_cache) const
268 LOCKS_EXCLUDED(dex_lock_)
269 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
270 DexCache* FindDexCache(const DexFile& dex_file) const
271 LOCKS_EXCLUDED(dex_lock_)
272 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
273 bool IsDexFileRegistered(const DexFile& dex_file) const
274 LOCKS_EXCLUDED(dex_lock_);
275 void FixupDexCaches(Method* resolution_method) const
276 LOCKS_EXCLUDED(dex_lock_)
277 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Brian Carlstrom1d9f52b2011-10-13 10:50:45 -0700278
jeffhao262bf462011-10-20 18:36:32 -0700279 // Generate an oat file from a dex file
Brian Carlstromd601af82012-01-06 10:15:19 -0800280 bool GenerateOatFile(const std::string& dex_filename,
281 int oat_fd,
282 const std::string& oat_cache_filename);
jeffhao262bf462011-10-20 18:36:32 -0700283
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700284 const OatFile* FindOatFileFromOatLocation(const std::string& location)
285 LOCKS_EXCLUDED(dex_lock_);
286
287 const OatFile* FindOatFileFromOatLocationLocked(const std::string& location)
288 EXCLUSIVE_LOCKS_REQUIRED(dex_lock_);
buzbeec143c552011-08-20 17:38:58 -0700289
Brian Carlstrom5b332c82012-02-01 15:02:31 -0800290 // Finds the oat file for a dex location, generating the oat file if
291 // it is missing or out of date. Returns the DexFile from within the
292 // created oat file.
293 const DexFile* FindOrCreateOatFileForDexLocation(const std::string& dex_location,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700294 const std::string& oat_location)
295 LOCKS_EXCLUDED(dex_lock_);
296 const DexFile* FindOrCreateOatFileForDexLocationLocked(const std::string& dex_location,
297 const std::string& oat_location)
298 EXCLUSIVE_LOCKS_REQUIRED(dex_lock_);
Brian Carlstrom5b332c82012-02-01 15:02:31 -0800299 // Find a DexFile within an OatFile given a DexFile location. Note
300 // that this returns null if the location checksum of the DexFile
301 // does not match the OatFile.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700302 const DexFile* FindDexFileInOatFileFromDexLocation(const std::string& location)
303 LOCKS_EXCLUDED(dex_lock_)
304 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Brian Carlstrom5b332c82012-02-01 15:02:31 -0800305
jeffhaof6174e82012-01-31 16:14:17 -0800306
Brian Carlstromafe25512012-06-27 17:02:58 -0700307 // Returns true if oat file contains the dex file with the given location and checksum
308 static bool VerifyOatFileChecksums(const OatFile* oat_file,
309 const std::string& dex_location,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700310 uint32_t dex_location_checksum)
311 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Brian Carlstromafe25512012-06-27 17:02:58 -0700312
Elliott Hughes418d20f2011-09-22 14:00:39 -0700313 // TODO: replace this with multiple methods that allocate the correct managed type.
Shih-wei Liao44175362011-08-28 16:59:17 -0700314 template <class T>
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700315 ObjectArray<T>* AllocObjectArray(size_t length)
316 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_) {
Shih-wei Liao44175362011-08-28 16:59:17 -0700317 return ObjectArray<T>::Alloc(GetClassRoot(kObjectArrayClass), length);
318 }
319
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700320 ObjectArray<Class>* AllocClassArray(size_t length)
321 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_) {
Elliott Hughes418d20f2011-09-22 14:00:39 -0700322 return ObjectArray<Class>::Alloc(GetClassRoot(kClassArrayClass), length);
323 }
324
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700325 ObjectArray<StackTraceElement>* AllocStackTraceElementArray(size_t length)
326 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Shih-wei Liao55df06b2011-08-26 14:39:27 -0700327
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700328 void VerifyClass(Class* klass) SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Elliott Hughes634eb2e2012-03-22 16:06:28 -0700329 bool VerifyClassUsingOatFile(const DexFile& dex_file, Class* klass,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700330 Class::Status& oat_file_class_status)
331 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
332 void ResolveClassExceptionHandlerTypes(const DexFile& dex_file, Class* klass)
333 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
334 void ResolveMethodExceptionHandlerTypes(const DexFile& dex_file, Method* klass)
335 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
jeffhao98eacac2011-09-14 16:11:53 -0700336
Jesse Wilson95caa792011-10-12 18:14:17 -0400337 Class* CreateProxyClass(String* name, ObjectArray<Class>* interfaces, ClassLoader* loader,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700338 ObjectArray<Method>* methods, ObjectArray<ObjectArray<Class> >* throws)
339 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
340 std::string GetDescriptorForProxy(const Class* proxy_class)
341 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
342 Method* FindMethodForProxy(const Class* proxy_class, const Method* proxy_method)
343 LOCKS_EXCLUDED(dex_lock_)
344 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Jesse Wilson95caa792011-10-12 18:14:17 -0400345
Ian Rogers19846512012-02-24 11:42:47 -0800346 // Get the oat code for a method when its class isn't yet initialized
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700347 const void* GetOatCodeFor(const Method* method)
348 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Ian Rogers19846512012-02-24 11:42:47 -0800349
Logan Chien0c717dd2012-03-28 18:31:07 +0800350 // Relocate the OatFiles (ELF images)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700351 void RelocateExecutable() LOCKS_EXCLUDED(dex_lock_);
Logan Chien0c717dd2012-03-28 18:31:07 +0800352
Brian Carlstrom47d237a2011-10-18 15:08:33 -0700353 pid_t GetClassesLockOwner(); // For SignalCatcher.
354 pid_t GetDexLockOwner(); // For SignalCatcher.
Brian Carlstrom24a3c2e2011-10-17 18:07:52 -0700355
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700356 private:
Elliott Hughes4dd9b4d2011-12-12 18:29:24 -0800357 explicit ClassLinker(InternTable*);
Carl Shapiro61e019d2011-07-14 16:53:09 -0700358
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700359 const OatFile::OatMethod GetOatMethodFor(const Method* method)
360 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
TDYa12785321912012-04-01 15:24:56 -0700361
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700362 // Initialize class linker by bootstraping from dex files
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700363 void InitFromCompiler(const std::vector<const DexFile*>& boot_class_path)
364 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Carl Shapiro61e019d2011-07-14 16:53:09 -0700365
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700366 // Initialize class linker from one or more images.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700367 void InitFromImage() SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
368 OatFile* OpenOat(const ImageSpace* space)
369 LOCKS_EXCLUDED(dex_lock_)
370 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
371 static void InitFromImageCallback(Object* obj, void* arg)
372 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Brian Carlstroma663ea52011-08-19 23:33:41 -0700373
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700374 void FinishInit() SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Brian Carlstroma663ea52011-08-19 23:33:41 -0700375
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700376 // For early bootstrapping by Init
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700377 Class* AllocClass(Class* java_lang_Class, size_t class_size)
378 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700379
380 // Alloc* convenience functions to avoid needing to pass in Class*
381 // values that are known to the ClassLinker such as
382 // kObjectArrayClass and kJavaLangString etc.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700383 Class* AllocClass(size_t class_size) SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
384 DexCache* AllocDexCache(const DexFile& dex_file)
385 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
386 Field* AllocField() SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
387 Method* AllocMethod() SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Ian Rogersbdb03912011-09-14 00:55:44 -0700388
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700389 InterfaceEntry* AllocInterfaceEntry(Class* interface)
390 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Ian Rogersbdb03912011-09-14 00:55:44 -0700391
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700392 Class* CreatePrimitiveClass(const char* descriptor, Primitive::Type type)
393 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_) {
Brian Carlstrom5b8e4c82011-09-18 01:38:59 -0700394 return InitializePrimitiveClass(AllocClass(sizeof(Class)), descriptor, type);
395 }
396 Class* InitializePrimitiveClass(Class* primitive_class,
397 const char* descriptor,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700398 Primitive::Type type)
399 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Brian Carlstrom5b8e4c82011-09-18 01:38:59 -0700400
Brian Carlstroma331b3c2011-07-18 17:47:56 -0700401
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700402 Class* CreateArrayClass(const std::string& descriptor, ClassLoader* class_loader)
403 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Brian Carlstroma331b3c2011-07-18 17:47:56 -0700404
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700405 void AppendToBootClassPath(const DexFile& dex_file)
406 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
407 void AppendToBootClassPath(const DexFile& dex_file, SirtRef<DexCache>& dex_cache)
408 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700409
Elliott Hughes5fe594f2011-09-08 12:33:17 -0700410 void ConstructFieldMap(const DexFile& dex_file, const DexFile::ClassDef& dex_class_def,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700411 Class* c, SafeMap<uint32_t, Field*>& field_map)
412 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Elliott Hughes5fe594f2011-09-08 12:33:17 -0700413
Brian Carlstrom4873d462011-08-21 15:23:39 -0700414 size_t SizeOfClass(const DexFile& dex_file,
415 const DexFile::ClassDef& dex_class_def);
416
Brian Carlstromf615a612011-07-23 12:50:34 -0700417 void LoadClass(const DexFile& dex_file,
418 const DexFile::ClassDef& dex_class_def,
Brian Carlstrom40381fb2011-10-19 14:13:40 -0700419 SirtRef<Class>& klass,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700420 ClassLoader* class_loader)
421 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700422
Ian Rogers0571d352011-11-03 19:51:38 -0700423 void LoadField(const DexFile& dex_file, const ClassDataItemIterator& it, SirtRef<Class>& klass,
Brian Carlstrom40381fb2011-10-19 14:13:40 -0700424 SirtRef<Field>& dst);
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700425
Ian Rogers0571d352011-11-03 19:51:38 -0700426 void LoadMethod(const DexFile& dex_file, const ClassDataItemIterator& dex_method,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700427 SirtRef<Class>& klass, SirtRef<Method>& dst)
428 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Brian Carlstrom934486c2011-07-12 23:42:50 -0700429
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700430 void FixupStaticTrampolines(Class* klass)
431 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Ian Rogers19846512012-02-24 11:42:47 -0800432
433 // Finds the associated oat class for a dex_file and descriptor
434 const OatFile::OatClass* GetOatClass(const DexFile& dex_file, const char* descriptor);
435
Brian Carlstrom07bb8552012-01-18 22:10:50 -0800436 // Attempts to insert a class into a class table. Returns NULL if
437 // the class was inserted, otherwise returns an existing class with
438 // the same descriptor and ClassLoader.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700439 Class* InsertClass(const StringPiece& descriptor, Class* klass, bool image_class)
440 LOCKS_EXCLUDED(GlobalSynchronization::classlinker_classes_lock_)
441 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Brian Carlstromaded5f72011-10-07 17:15:04 -0700442
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700443 void RegisterDexFileLocked(const DexFile& dex_file, SirtRef<DexCache>& dex_cache)
444 EXCLUSIVE_LOCKS_REQUIRED(dex_lock_)
445 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Elliott Hughesf8349362012-06-18 15:00:06 -0700446 bool IsDexFileRegisteredLocked(const DexFile& dex_file) const EXCLUSIVE_LOCKS_REQUIRED(dex_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700447 void RegisterOatFileLocked(const OatFile& oat_file) EXCLUSIVE_LOCKS_REQUIRED(dex_lock_)
448 EXCLUSIVE_LOCKS_REQUIRED(dex_lock_);
Brian Carlstromaded5f72011-10-07 17:15:04 -0700449
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700450 bool InitializeClass(Class* klass, bool can_run_clinit, bool can_init_statics)
451 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Brian Carlstromd1422f82011-09-28 11:37:09 -0700452 bool WaitForInitializeClass(Class* klass, Thread* self, ObjectLock& lock);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700453 bool ValidateSuperClassDescriptors(const Class* klass)
454 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
455 bool InitializeSuperClass(Class* klass, bool can_run_clinit, bool can_init_fields)
456 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Ian Rogers0045a292012-03-31 21:08:41 -0700457 // Initialize static fields, returns true if fields were initialized.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700458 bool InitializeStaticFields(Class* klass)
459 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700460
Ian Rogers595799e2012-01-11 17:32:51 -0800461 bool IsSameDescriptorInDifferentClassContexts(const char* descriptor,
462 const Class* klass1,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700463 const Class* klass2)
464 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700465
Ian Rogers595799e2012-01-11 17:32:51 -0800466 bool IsSameMethodSignatureInDifferentClassContexts(const Method* descriptor,
467 const Class* klass1,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700468 const Class* klass2)
469 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700470
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700471 bool LinkClass(SirtRef<Class>& klass, ObjectArray<Class>* interfaces)
472 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700473
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700474 bool LinkSuperClass(SirtRef<Class>& klass)
475 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700476
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700477 bool LoadSuperAndInterfaces(SirtRef<Class>& klass, const DexFile& dex_file)
478 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700479
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700480 bool LinkMethods(SirtRef<Class>& klass, ObjectArray<Class>* interfaces)
481 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700482
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700483 bool LinkVirtualMethods(SirtRef<Class>& klass)
484 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700485
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700486 bool LinkInterfaceMethods(SirtRef<Class>& klass, ObjectArray<Class>* interfaces)
487 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700488
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700489 bool LinkStaticFields(SirtRef<Class>& klass)
490 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
491 bool LinkInstanceFields(SirtRef<Class>& klass)
492 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
493 bool LinkFields(SirtRef<Class>& klass, bool is_static)
494 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700495
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700496
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700497 void CreateReferenceInstanceOffsets(SirtRef<Class>& klass)
498 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
499 void CreateReferenceStaticOffsets(SirtRef<Class>& klass)
500 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Brian Carlstrom40381fb2011-10-19 14:13:40 -0700501 void CreateReferenceOffsets(SirtRef<Class>& klass, bool is_static,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700502 uint32_t reference_offsets)
503 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700504
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700505 // For use by ImageWriter to find DexCaches for its roots
506 const std::vector<DexCache*>& GetDexCaches() {
507 return dex_caches_;
508 }
509
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700510 const OatFile* FindOpenedOatFileForDexFile(const DexFile& dex_file)
511 LOCKS_EXCLUDED(dex_lock_);
512 const OatFile* FindOpenedOatFileFromDexLocation(const std::string& dex_location)
513 EXCLUSIVE_LOCKS_REQUIRED(dex_lock_);
514 const OatFile* FindOpenedOatFileFromOatLocation(const std::string& oat_location)
515 EXCLUSIVE_LOCKS_REQUIRED(dex_lock_);
Brian Carlstromafe25512012-06-27 17:02:58 -0700516 const DexFile* VerifyAndOpenDexFileFromOatFile(const OatFile* oat_file,
517 const std::string& dex_location,
518 uint32_t dex_location_checksum)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700519 EXCLUSIVE_LOCKS_REQUIRED(dex_lock_)
520 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Brian Carlstromfad71432011-10-16 20:25:10 -0700521
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700522 Method* CreateProxyConstructor(SirtRef<Class>& klass, Class* proxy_class)
523 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
524 Method* CreateProxyMethod(SirtRef<Class>& klass, SirtRef<Method>& prototype)
525 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Jesse Wilson95caa792011-10-12 18:14:17 -0400526
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700527 std::vector<const DexFile*> boot_class_path_;
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700528
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700529 mutable Mutex dex_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
Elliott Hughesf8349362012-06-18 15:00:06 -0700530 std::vector<const DexFile*> dex_files_ GUARDED_BY(dex_lock_);
531 std::vector<DexCache*> dex_caches_ GUARDED_BY(dex_lock_);
532 std::vector<const OatFile*> oat_files_ GUARDED_BY(dex_lock_);
Brian Carlstrom47d237a2011-10-18 15:08:33 -0700533
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700534
Brian Carlstromaded5f72011-10-07 17:15:04 -0700535 // multimap from a string hash code of a class descriptor to
Brian Carlstrom9cff8e12011-08-18 16:47:29 -0700536 // Class* instances. Results should be compared for a matching
537 // Class::descriptor_ and Class::class_loader_.
Elliott Hughesf8349362012-06-18 15:00:06 -0700538 typedef std::multimap<size_t, Class*> Table;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700539 Table image_classes_ GUARDED_BY(GlobalSynchronization::classlinker_classes_lock_);
540 Table classes_ GUARDED_BY(GlobalSynchronization::classlinker_classes_lock_);
Elliott Hughesf8349362012-06-18 15:00:06 -0700541
542 Class* LookupClassLocked(const char* descriptor, const ClassLoader* class_loader,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700543 size_t hash, const Table& classes)
544 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_)
545 EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::classlinker_classes_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700546
Brian Carlstroma663ea52011-08-19 23:33:41 -0700547 // indexes into class_roots_.
548 // needs to be kept in sync with class_roots_descriptors_.
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700549 enum ClassRoot {
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700550 kJavaLangClass,
551 kJavaLangObject,
Elliott Hughes418d20f2011-09-22 14:00:39 -0700552 kClassArrayClass,
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700553 kObjectArrayClass,
554 kJavaLangString,
Elliott Hughesbf61ba32011-10-11 10:53:09 -0700555 kJavaLangRefReference,
Elliott Hughes80609252011-09-23 17:24:51 -0700556 kJavaLangReflectConstructor,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700557 kJavaLangReflectField,
558 kJavaLangReflectMethod,
Ian Rogers466bb252011-10-14 03:29:56 -0700559 kJavaLangReflectProxy,
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700560 kJavaLangClassLoader,
Ian Rogers5167c972012-02-03 10:41:20 -0800561 kJavaLangThrowable,
jeffhao8cd6dda2012-02-22 10:15:34 -0800562 kJavaLangClassNotFoundException,
Shih-wei Liao55df06b2011-08-26 14:39:27 -0700563 kJavaLangStackTraceElement,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700564 kPrimitiveBoolean,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700565 kPrimitiveByte,
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700566 kPrimitiveChar,
567 kPrimitiveDouble,
568 kPrimitiveFloat,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700569 kPrimitiveInt,
570 kPrimitiveLong,
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700571 kPrimitiveShort,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700572 kPrimitiveVoid,
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700573 kBooleanArrayClass,
574 kByteArrayClass,
575 kCharArrayClass,
576 kDoubleArrayClass,
577 kFloatArrayClass,
578 kIntArrayClass,
579 kLongArrayClass,
580 kShortArrayClass,
Shih-wei Liao55df06b2011-08-26 14:39:27 -0700581 kJavaLangStackTraceElementArrayClass,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700582 kClassRootsMax,
583 };
584 ObjectArray<Class>* class_roots_;
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700585
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700586 Class* GetClassRoot(ClassRoot class_root)
587 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_) {
Brian Carlstroma663ea52011-08-19 23:33:41 -0700588 DCHECK(class_roots_ != NULL);
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700589 Class* klass = class_roots_->Get(class_root);
590 DCHECK(klass != NULL);
591 return klass;
592 }
593
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700594 void SetClassRoot(ClassRoot class_root, Class* klass)
595 SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
Brian Carlstroma663ea52011-08-19 23:33:41 -0700596
Brian Carlstrom34f426c2011-10-04 12:58:02 -0700597 ObjectArray<Class>* GetClassRoots() {
598 DCHECK(class_roots_ != NULL);
599 return class_roots_;
600 }
601
Elliott Hughes418d20f2011-09-22 14:00:39 -0700602 static const char* class_roots_descriptors_[];
Brian Carlstroma663ea52011-08-19 23:33:41 -0700603
604 const char* GetClassRootDescriptor(ClassRoot class_root) {
605 const char* descriptor = class_roots_descriptors_[class_root];
606 CHECK(descriptor != NULL);
607 return descriptor;
608 }
609
Brian Carlstrom4b620ff2011-09-11 01:11:01 -0700610 ObjectArray<InterfaceEntry>* array_iftable_;
Carl Shapiro565f5072011-07-10 13:39:43 -0700611
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700612 bool init_done_;
613
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700614 InternTable* intern_table_;
615
Brian Carlstromf734cf52011-08-17 16:28:14 -0700616 friend class CommonTest;
Brian Carlstrom34f426c2011-10-04 12:58:02 -0700617 friend class ImageWriter; // for GetClassRoots
Brian Carlstromae826982011-11-09 01:33:42 -0800618 friend class ObjectTest;
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800619 FRIEND_TEST(ClassLinkerTest, ClassRootDescriptors);
Brian Carlstromae826982011-11-09 01:33:42 -0800620 FRIEND_TEST(DexCacheTest, Open);
621 FRIEND_TEST(ExceptionTest, FindExceptionHandler);
622 FRIEND_TEST(ObjectTest, AllocObjectArray);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700623 DISALLOW_COPY_AND_ASSIGN(ClassLinker);
624};
625
626} // namespace art
627
628#endif // ART_SRC_CLASS_LINKER_H_