blob: 20efbb43a9ff1d1e12f9449bcc178eb345708546 [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
Brian Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_RUNTIME_CLASS_LINKER_H_
18#define ART_RUNTIME_CLASS_LINKER_H_
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070019
Ian Rogers6d4d9fc2011-11-30 16:24:48 -080020#include <string>
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070021#include <utility>
22#include <vector>
23
Elliott Hughes76160052012-12-12 16:31:20 -080024#include "base/macros.h"
Elliott Hughes76b61672012-12-12 17:47:30 -080025#include "base/mutex.h"
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070026#include "dex_file.h"
Elliott Hughese5448b52012-01-18 16:44:06 -080027#include "gtest/gtest.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080028#include "root_visitor.h"
Brian Carlstrom58ae9412011-10-04 00:56:06 -070029#include "oat_file.h"
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070030
31namespace art {
Ian Rogers1d54e732013-05-02 21:10:01 -070032namespace gc {
33namespace space {
34 class ImageSpace;
35} // namespace space
36} // namespace gc
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080037namespace mirror {
Ian Rogers33e95662013-05-20 20:29:14 -070038 class ClassLoader;
39 class DexCache;
40 class DexCacheTest_Open_Test;
41 class IfTable;
42 template<class T> class ObjectArray;
43 class StackTraceElement;
44} // namespace mirror
Ian Rogers1d54e732013-05-02 21:10:01 -070045
Elliott Hughescf4c6c42011-09-01 15:16:42 -070046class InternTable;
Brian Carlstromd1422f82011-09-28 11:37:09 -070047class ObjectLock;
Ian Rogers1f539342012-10-03 21:09:42 -070048template<class T> class SirtRef;
Elliott Hughescf4c6c42011-09-01 15:16:42 -070049
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080050typedef bool (ClassVisitor)(mirror::Class* c, void* arg);
Elliott Hughesa2155262011-11-16 16:26:58 -080051
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070052class ClassLinker {
53 public:
Ian Rogers1f539342012-10-03 21:09:42 -070054 // Creates the class linker by bootstrapping from dex files.
Brian Carlstroma004aa92012-02-08 18:05:09 -080055 static ClassLinker* CreateFromCompiler(const std::vector<const DexFile*>& boot_class_path,
Ian Rogers00f7d0e2012-07-19 15:28:27 -070056 InternTable* intern_table)
Ian Rogersb726dcb2012-09-05 08:57:23 -070057 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom58ae9412011-10-04 00:56:06 -070058
Brian Carlstroma004aa92012-02-08 18:05:09 -080059 // Creates the class linker from an image.
Ian Rogers00f7d0e2012-07-19 15:28:27 -070060 static ClassLinker* CreateFromImage(InternTable* intern_table)
Ian Rogersb726dcb2012-09-05 08:57:23 -070061 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro61e019d2011-07-14 16:53:09 -070062
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070063 ~ClassLinker();
Carl Shapiro565f5072011-07-10 13:39:43 -070064
Ian Rogersbe7149f2013-08-20 09:29:39 -070065 bool IsInBootClassPath(const char* descriptor);
66
Elliott Hughes64bf5a32011-09-20 14:43:12 -070067 // Finds a class by its descriptor, loading it if necessary.
Brian Carlstrom74eb46a2011-08-02 20:10:14 -070068 // If class_loader is null, searches boot_class_path_.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080069 mirror::Class* FindClass(const char* descriptor, mirror::ClassLoader* class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -070070 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromaded5f72011-10-07 17:15:04 -070071
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080072 mirror::Class* FindSystemClass(const char* descriptor)
Ian Rogersb726dcb2012-09-05 08:57:23 -070073 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromaded5f72011-10-07 17:15:04 -070074
75 // Define a new a class based on a ClassDef from a DexFile
Ian Rogers7dfb28c2013-08-22 08:18:36 -070076 mirror::Class* DefineClass(const char* descriptor, mirror::ClassLoader* class_loader,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080077 const DexFile& dex_file, const DexFile::ClassDef& dex_class_def)
Ian Rogersb726dcb2012-09-05 08:57:23 -070078 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes64bf5a32011-09-20 14:43:12 -070079
80 // Finds a class by its descriptor, returning NULL if it isn't wasn't loaded
81 // by the given 'class_loader'.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080082 mirror::Class* LookupClass(const char* descriptor, const mirror::ClassLoader* class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -070083 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
84 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070085
Elliott Hughes6fa602d2011-12-02 17:54:25 -080086 // Finds all the classes with the given descriptor, regardless of ClassLoader.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080087 void LookupClasses(const char* descriptor, std::vector<mirror::Class*>& classes)
Ian Rogersb726dcb2012-09-05 08:57:23 -070088 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
89 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes6fa602d2011-12-02 17:54:25 -080090
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080091 mirror::Class* FindPrimitiveClass(char type) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesd8ddfd52011-08-15 14:32:53 -070092
Brian Carlstromae826982011-11-09 01:33:42 -080093 // General class unloading is not supported, this is used to prune
94 // unwanted classes during image writing.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080095 bool RemoveClass(const char* descriptor, const mirror::ClassLoader* class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -070096 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
97 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromae826982011-11-09 01:33:42 -080098
Ian Rogers7dfb28c2013-08-22 08:18:36 -070099 void DumpAllClasses(int flags)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700100 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
101 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes9d5ccec2011-09-19 13:19:50 -0700102
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700103 void DumpForSigQuit(std::ostream& os)
104 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
105 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughescac6cc72011-11-03 20:31:21 -0700106
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700107 size_t NumLoadedClasses()
108 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
109 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughese27955c2011-08-26 15:21:24 -0700110
Brian Carlstromb63ec392011-08-27 17:38:27 -0700111 // Resolve a String with the given index from the DexFile, storing the
Brian Carlstromaded5f72011-10-07 17:15:04 -0700112 // result in the DexCache. The referrer is used to identify the
113 // target DexCache and ClassLoader to use for resolution.
Brian Carlstromea46f952013-07-30 01:26:50 -0700114 mirror::String* ResolveString(uint32_t string_idx, const mirror::ArtMethod* referrer)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800115 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromaded5f72011-10-07 17:15:04 -0700116
117 // Resolve a String with the given index from the DexFile, storing the
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700118 // result in the DexCache.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800119 mirror::String* ResolveString(const DexFile& dex_file, uint32_t string_idx,
120 mirror::DexCache* dex_cache)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700121 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700122
Brian Carlstromb63ec392011-08-27 17:38:27 -0700123 // Resolve a Type with the given index from the DexFile, storing the
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700124 // result in the DexCache. The referrer is used to identity the
125 // target DexCache and ClassLoader to use for resolution.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800126 mirror::Class* ResolveType(const DexFile& dex_file, uint16_t type_idx,
127 const mirror::Class* referrer)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700128 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700129 return ResolveType(dex_file,
130 type_idx,
131 referrer->GetDexCache(),
132 referrer->GetClassLoader());
133 }
134
Brian Carlstromb63ec392011-08-27 17:38:27 -0700135 // Resolve a Type with the given index from the DexFile, storing the
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700136 // result in the DexCache. The referrer is used to identify the
Brian Carlstromb63ec392011-08-27 17:38:27 -0700137 // target DexCache and ClassLoader to use for resolution.
Brian Carlstromea46f952013-07-30 01:26:50 -0700138 mirror::Class* ResolveType(uint16_t type_idx, const mirror::ArtMethod* referrer)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800139 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700140
Brian Carlstromea46f952013-07-30 01:26:50 -0700141 mirror::Class* ResolveType(uint16_t type_idx, const mirror::ArtField* referrer)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800142 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromb63ec392011-08-27 17:38:27 -0700143
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700144 // Resolve a type with the given ID from the DexFile, storing the
145 // result in DexCache. The ClassLoader is used to search for the
146 // type, since it may be referenced from but not contained within
147 // the given DexFile.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800148 mirror::Class* ResolveType(const DexFile& dex_file,
149 uint16_t type_idx,
150 mirror::DexCache* dex_cache,
151 mirror::ClassLoader* class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700152 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700153
154 // Resolve a method with a given ID from the DexFile, storing the
155 // result in DexCache. The ClassLinker and ClassLoader are used as
156 // in ResolveType. What is unique is the method type argument which
157 // is used to determine if this method is a direct, static, or
158 // virtual method.
Brian Carlstromea46f952013-07-30 01:26:50 -0700159 mirror::ArtMethod* ResolveMethod(const DexFile& dex_file,
160 uint32_t method_idx,
161 mirror::DexCache* dex_cache,
162 mirror::ClassLoader* class_loader,
163 const mirror::ArtMethod* referrer,
164 InvokeType type)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700165 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700166
Brian Carlstromea46f952013-07-30 01:26:50 -0700167 mirror::ArtMethod* ResolveMethod(uint32_t method_idx, const mirror::ArtMethod* referrer,
168 InvokeType type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800169 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom16192862011-09-12 17:50:06 -0700170
Brian Carlstromea46f952013-07-30 01:26:50 -0700171 mirror::ArtField* ResolveField(uint32_t field_idx, const mirror::ArtMethod* referrer,
172 bool is_static)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800173 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromb9edb842011-08-28 16:31:06 -0700174
Brian Carlstrom16192862011-09-12 17:50:06 -0700175 // Resolve a field with a given ID from the DexFile, storing the
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700176 // result in DexCache. The ClassLinker and ClassLoader are used as
177 // in ResolveType. What is unique is the is_static argument which is
178 // used to determine if we are resolving a static or non-static
179 // field.
Brian Carlstromea46f952013-07-30 01:26:50 -0700180 mirror::ArtField* ResolveField(const DexFile& dex_file,
181 uint32_t field_idx,
182 mirror::DexCache* dex_cache,
183 mirror::ClassLoader* class_loader,
184 bool is_static)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700185 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700186
Ian Rogersb067ac22011-12-13 18:05:09 -0800187 // Resolve a field with a given ID from the DexFile, storing the
188 // result in DexCache. The ClassLinker and ClassLoader are used as
189 // in ResolveType. No is_static argument is provided so that Java
190 // field resolution semantics are followed.
Brian Carlstromea46f952013-07-30 01:26:50 -0700191 mirror::ArtField* ResolveFieldJLS(const DexFile& dex_file,
192 uint32_t field_idx,
193 mirror::DexCache* dex_cache,
194 mirror::ClassLoader* class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700195 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersb067ac22011-12-13 18:05:09 -0800196
Ian Rogersad25ac52011-10-04 19:13:33 -0700197 // Get shorty from method index without resolution. Used to do handlerization.
Brian Carlstromea46f952013-07-30 01:26:50 -0700198 const char* MethodShorty(uint32_t method_idx, mirror::ArtMethod* referrer, uint32_t* length)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700199 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersad25ac52011-10-04 19:13:33 -0700200
Elliott Hughesf4c21c92011-08-19 17:31:31 -0700201 // Returns true on success, false if there's an exception pending.
Brian Carlstrom25c33252011-09-18 15:58:35 -0700202 // can_run_clinit=false allows the compiler to attempt to init a class,
203 // given the restriction that no <clinit> execution is possible.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800204 bool EnsureInitialized(mirror::Class* c, bool can_run_clinit, bool can_init_fields)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700205 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700206
Elliott Hughes2a20cfd2011-09-23 19:30:41 -0700207 // Initializes classes that have instances in the image but that have
208 // <clinit> methods so they could not be initialized by the compiler.
Ian Rogersb726dcb2012-09-05 08:57:23 -0700209 void RunRootClinits() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes2a20cfd2011-09-23 19:30:41 -0700210
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700211 void RegisterDexFile(const DexFile& dex_file)
212 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700213 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800214 void RegisterDexFile(const DexFile& dex_file, SirtRef<mirror::DexCache>& dex_cache)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700215 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700216 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700217
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700218 void RegisterOatFile(const OatFile& oat_file)
219 LOCKS_EXCLUDED(dex_lock_);
Brian Carlstrom866c8622012-01-06 16:35:13 -0800220
Brian Carlstrom8a487412011-08-29 20:08:52 -0700221 const std::vector<const DexFile*>& GetBootClassPath() {
222 return boot_class_path_;
223 }
224
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700225 void VisitClasses(ClassVisitor* visitor, void* arg)
226 LOCKS_EXCLUDED(dex_lock_)
227 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700228 // Less efficient variant of VisitClasses that doesn't hold the classlinker_classes_lock_
229 // when calling the visitor.
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700230 void VisitClassesWithoutClassesLock(ClassVisitor* visitor, void* arg)
231 LOCKS_EXCLUDED(dex_lock_)
232 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesa2155262011-11-16 16:26:58 -0800233
Mathieu Chartierc4621982013-09-16 19:43:47 -0700234 void VisitRoots(RootVisitor* visitor, void* arg, bool only_dirty, bool clean_dirty)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700235 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_, dex_lock_);
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700236
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800237 mirror::DexCache* FindDexCache(const DexFile& dex_file) const
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700238 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700239 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700240 bool IsDexFileRegistered(const DexFile& dex_file) const
241 LOCKS_EXCLUDED(dex_lock_);
Brian Carlstromea46f952013-07-30 01:26:50 -0700242 void FixupDexCaches(mirror::ArtMethod* resolution_method) const
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700243 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700244 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom1d9f52b2011-10-13 10:50:45 -0700245
jeffhao262bf462011-10-20 18:36:32 -0700246 // Generate an oat file from a dex file
Brian Carlstromd601af82012-01-06 10:15:19 -0800247 bool GenerateOatFile(const std::string& dex_filename,
248 int oat_fd,
249 const std::string& oat_cache_filename);
jeffhao262bf462011-10-20 18:36:32 -0700250
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700251 const OatFile* FindOatFileFromOatLocation(const std::string& location)
252 LOCKS_EXCLUDED(dex_lock_);
253
254 const OatFile* FindOatFileFromOatLocationLocked(const std::string& location)
Ian Rogers1bf8d4d2013-05-30 00:18:49 -0700255 SHARED_LOCKS_REQUIRED(dex_lock_);
buzbeec143c552011-08-20 17:38:58 -0700256
Brian Carlstrom5b332c82012-02-01 15:02:31 -0800257 // Finds the oat file for a dex location, generating the oat file if
258 // it is missing or out of date. Returns the DexFile from within the
259 // created oat file.
260 const DexFile* FindOrCreateOatFileForDexLocation(const std::string& dex_location,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700261 const std::string& oat_location)
Ian Rogers33e95662013-05-20 20:29:14 -0700262 LOCKS_EXCLUDED(dex_lock_)
263 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700264 const DexFile* FindOrCreateOatFileForDexLocationLocked(const std::string& dex_location,
265 const std::string& oat_location)
Ian Rogers33e95662013-05-20 20:29:14 -0700266 EXCLUSIVE_LOCKS_REQUIRED(dex_lock_)
267 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom5b332c82012-02-01 15:02:31 -0800268 // Find a DexFile within an OatFile given a DexFile location. Note
269 // that this returns null if the location checksum of the DexFile
270 // does not match the OatFile.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700271 const DexFile* FindDexFileInOatFileFromDexLocation(const std::string& location)
272 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700273 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom5b332c82012-02-01 15:02:31 -0800274
jeffhaof6174e82012-01-31 16:14:17 -0800275
Brian Carlstrom28db0122012-10-18 16:20:41 -0700276 // Returns true if oat file contains the dex file with the given location and checksum.
Brian Carlstromafe25512012-06-27 17:02:58 -0700277 static bool VerifyOatFileChecksums(const OatFile* oat_file,
278 const std::string& dex_location,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700279 uint32_t dex_location_checksum)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700280 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromafe25512012-06-27 17:02:58 -0700281
Elliott Hughes418d20f2011-09-22 14:00:39 -0700282 // TODO: replace this with multiple methods that allocate the correct managed type.
Shih-wei Liao44175362011-08-28 16:59:17 -0700283 template <class T>
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800284 mirror::ObjectArray<T>* AllocObjectArray(Thread* self, size_t length)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700285 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Shih-wei Liao55df06b2011-08-26 14:39:27 -0700286
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800287 mirror::ObjectArray<mirror::Class>* AllocClassArray(Thread* self, size_t length)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700288 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
jeffhao98eacac2011-09-14 16:11:53 -0700289
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800290 mirror::ObjectArray<mirror::String>* AllocStringArray(Thread* self, size_t length)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700291 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800292
Brian Carlstromea46f952013-07-30 01:26:50 -0700293 mirror::ObjectArray<mirror::ArtMethod>* AllocArtMethodArray(Thread* self, size_t length)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800294 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
295
296 mirror::IfTable* AllocIfTable(Thread* self, size_t ifcount)
297 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
298
Brian Carlstromea46f952013-07-30 01:26:50 -0700299 mirror::ObjectArray<mirror::ArtField>* AllocArtFieldArray(Thread* self, size_t length)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800300 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
301
302 mirror::ObjectArray<mirror::StackTraceElement>* AllocStackTraceElementArray(Thread* self,
303 size_t length)
304 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
305
306 void VerifyClass(mirror::Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
307 bool VerifyClassUsingOatFile(const DexFile& dex_file, mirror::Class* klass,
308 mirror::Class::Status& oat_file_class_status)
309 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
310 void ResolveClassExceptionHandlerTypes(const DexFile& dex_file, mirror::Class* klass)
311 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromea46f952013-07-30 01:26:50 -0700312 void ResolveMethodExceptionHandlerTypes(const DexFile& dex_file, mirror::ArtMethod* klass)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800313 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
314
315 mirror::Class* CreateProxyClass(mirror::String* name, mirror::ObjectArray<mirror::Class>* interfaces,
316 mirror::ClassLoader* loader,
Brian Carlstromea46f952013-07-30 01:26:50 -0700317 mirror::ObjectArray<mirror::ArtMethod>* methods,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800318 mirror::ObjectArray<mirror::ObjectArray<mirror::Class> >* throws)
319 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
320 std::string GetDescriptorForProxy(const mirror::Class* proxy_class)
321 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromea46f952013-07-30 01:26:50 -0700322 mirror::ArtMethod* FindMethodForProxy(const mirror::Class* proxy_class,
323 const mirror::ArtMethod* proxy_method)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700324 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700325 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jesse Wilson95caa792011-10-12 18:14:17 -0400326
Ian Rogers19846512012-02-24 11:42:47 -0800327 // Get the oat code for a method when its class isn't yet initialized
Brian Carlstromea46f952013-07-30 01:26:50 -0700328 const void* GetOatCodeFor(const mirror::ArtMethod* method)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700329 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers19846512012-02-24 11:42:47 -0800330
Mathieu Chartiere35517a2012-10-30 18:49:55 -0700331 // Get the oat code for a method from a method index.
Ian Rogers33e95662013-05-20 20:29:14 -0700332 const void* GetOatCodeFor(const DexFile& dex_file, uint32_t method_idx)
333 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartiere35517a2012-10-30 18:49:55 -0700334
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700335 pid_t GetClassesLockOwner(); // For SignalCatcher.
336 pid_t GetDexLockOwner(); // For SignalCatcher.
Brian Carlstrom24a3c2e2011-10-17 18:07:52 -0700337
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700338 const void* GetPortableResolutionTrampoline() const {
339 return portable_resolution_trampoline_;
340 }
341
342 const void* GetQuickResolutionTrampoline() const {
343 return quick_resolution_trampoline_;
344 }
345
Ian Rogers848871b2013-08-05 10:56:33 -0700346 InternTable* GetInternTable() const {
347 return intern_table_;
348 }
349
350 // Attempts to insert a class into a class table. Returns NULL if
351 // the class was inserted, otherwise returns an existing class with
352 // the same descriptor and ClassLoader.
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700353 mirror::Class* InsertClass(const char* descriptor, mirror::Class* klass, size_t hash)
Ian Rogers848871b2013-08-05 10:56:33 -0700354 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
355 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
356
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700357 private:
Elliott Hughes4dd9b4d2011-12-12 18:29:24 -0800358 explicit ClassLinker(InternTable*);
Carl Shapiro61e019d2011-07-14 16:53:09 -0700359
Brian Carlstromea46f952013-07-30 01:26:50 -0700360 const OatFile::OatMethod GetOatMethodFor(const mirror::ArtMethod* method)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700361 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
TDYa12785321912012-04-01 15:24:56 -0700362
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700363 // Initialize class linker by bootstraping from dex files
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700364 void InitFromCompiler(const std::vector<const DexFile*>& boot_class_path)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700365 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro61e019d2011-07-14 16:53:09 -0700366
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700367 // Initialize class linker from one or more images.
Ian Rogersb726dcb2012-09-05 08:57:23 -0700368 void InitFromImage() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom56d947f2013-07-15 13:14:23 -0700369 OatFile& GetImageOatFile(gc::space::ImageSpace* space)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700370 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700371 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstroma663ea52011-08-19 23:33:41 -0700372
Ian Rogersb726dcb2012-09-05 08:57:23 -0700373 void FinishInit() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstroma663ea52011-08-19 23:33:41 -0700374
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700375 // For early bootstrapping by Init
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800376 mirror::Class* AllocClass(Thread* self, mirror::Class* java_lang_Class, size_t class_size)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700377 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700378
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800379 // Alloc* convenience functions to avoid needing to pass in mirror::Class*
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700380 // values that are known to the ClassLinker such as
381 // kObjectArrayClass and kJavaLangString etc.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800382 mirror::Class* AllocClass(Thread* self, size_t class_size) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
383 mirror::DexCache* AllocDexCache(Thread* self, const DexFile& dex_file)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700384 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromea46f952013-07-30 01:26:50 -0700385 mirror::ArtField* AllocArtField(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
386 mirror::ArtMethod* AllocArtMethod(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersbdb03912011-09-14 00:55:44 -0700387
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800388 mirror::Class* CreatePrimitiveClass(Thread* self, Primitive::Type type)
389 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
390 mirror::Class* InitializePrimitiveClass(mirror::Class* primitive_class, Primitive::Type type)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700391 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom5b8e4c82011-09-18 01:38:59 -0700392
Brian Carlstroma331b3c2011-07-18 17:47:56 -0700393
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700394 mirror::Class* CreateArrayClass(const char* descriptor, mirror::ClassLoader* class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700395 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstroma331b3c2011-07-18 17:47:56 -0700396
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700397 void AppendToBootClassPath(const DexFile& dex_file)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700398 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800399 void AppendToBootClassPath(const DexFile& dex_file, SirtRef<mirror::DexCache>& dex_cache)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700400 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700401
Elliott Hughes5fe594f2011-09-08 12:33:17 -0700402 void ConstructFieldMap(const DexFile& dex_file, const DexFile::ClassDef& dex_class_def,
Brian Carlstromea46f952013-07-30 01:26:50 -0700403 mirror::Class* c, SafeMap<uint32_t, mirror::ArtField*>& field_map)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700404 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes5fe594f2011-09-08 12:33:17 -0700405
Brian Carlstrom4873d462011-08-21 15:23:39 -0700406 size_t SizeOfClass(const DexFile& dex_file,
407 const DexFile::ClassDef& dex_class_def);
408
Brian Carlstromf615a612011-07-23 12:50:34 -0700409 void LoadClass(const DexFile& dex_file,
410 const DexFile::ClassDef& dex_class_def,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800411 SirtRef<mirror::Class>& klass,
412 mirror::ClassLoader* class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700413 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700414
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800415 void LoadField(const DexFile& dex_file, const ClassDataItemIterator& it,
Brian Carlstromea46f952013-07-30 01:26:50 -0700416 SirtRef<mirror::Class>& klass, SirtRef<mirror::ArtField>& dst)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800417 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700418
Brian Carlstromea46f952013-07-30 01:26:50 -0700419 mirror::ArtMethod* LoadMethod(Thread* self, const DexFile& dex_file,
420 const ClassDataItemIterator& dex_method,
421 SirtRef<mirror::Class>& klass)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800422 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom934486c2011-07-12 23:42:50 -0700423
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800424 void FixupStaticTrampolines(mirror::Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers19846512012-02-24 11:42:47 -0800425
426 // Finds the associated oat class for a dex_file and descriptor
Ian Rogers33e95662013-05-20 20:29:14 -0700427 const OatFile::OatClass* GetOatClass(const DexFile& dex_file, const char* descriptor)
428 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers19846512012-02-24 11:42:47 -0800429
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800430 void RegisterDexFileLocked(const DexFile& dex_file, SirtRef<mirror::DexCache>& dex_cache)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700431 EXCLUSIVE_LOCKS_REQUIRED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700432 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers1bf8d4d2013-05-30 00:18:49 -0700433 bool IsDexFileRegisteredLocked(const DexFile& dex_file) const SHARED_LOCKS_REQUIRED(dex_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700434 void RegisterOatFileLocked(const OatFile& oat_file) EXCLUSIVE_LOCKS_REQUIRED(dex_lock_)
435 EXCLUSIVE_LOCKS_REQUIRED(dex_lock_);
Brian Carlstromaded5f72011-10-07 17:15:04 -0700436
Ian Rogers8f3c9ae2013-08-20 17:26:41 -0700437 bool InitializeClass(mirror::Class* klass, bool can_run_clinit, bool can_init_parents)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700438 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800439 bool WaitForInitializeClass(mirror::Class* klass, Thread* self, ObjectLock& lock);
440 bool ValidateSuperClassDescriptors(const mirror::Class* klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700441 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700442
Ian Rogers595799e2012-01-11 17:32:51 -0800443 bool IsSameDescriptorInDifferentClassContexts(const char* descriptor,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800444 const mirror::Class* klass1,
445 const mirror::Class* klass2)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700446 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700447
Brian Carlstromea46f952013-07-30 01:26:50 -0700448 bool IsSameMethodSignatureInDifferentClassContexts(const mirror::ArtMethod* method,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800449 const mirror::Class* klass1,
450 const mirror::Class* klass2)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700451 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700452
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700453 bool LinkClass(SirtRef<mirror::Class>& klass, mirror::ObjectArray<mirror::Class>* interfaces,
454 Thread* self)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700455 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700456
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800457 bool LinkSuperClass(SirtRef<mirror::Class>& klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700458 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700459
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800460 bool LoadSuperAndInterfaces(SirtRef<mirror::Class>& klass, const DexFile& dex_file)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700461 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700462
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800463 bool LinkMethods(SirtRef<mirror::Class>& klass, mirror::ObjectArray<mirror::Class>* interfaces)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700464 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700465
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800466 bool LinkVirtualMethods(SirtRef<mirror::Class>& klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700467 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700468
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800469 bool LinkInterfaceMethods(SirtRef<mirror::Class>& klass,
470 mirror::ObjectArray<mirror::Class>* interfaces)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700471 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700472
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800473 bool LinkStaticFields(SirtRef<mirror::Class>& klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700474 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800475 bool LinkInstanceFields(SirtRef<mirror::Class>& klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700476 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800477 bool LinkFields(SirtRef<mirror::Class>& klass, bool is_static)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700478 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700479
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700480
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800481 void CreateReferenceInstanceOffsets(SirtRef<mirror::Class>& klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700482 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800483 void CreateReferenceStaticOffsets(SirtRef<mirror::Class>& klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700484 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800485 void CreateReferenceOffsets(SirtRef<mirror::Class>& klass, bool is_static,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700486 uint32_t reference_offsets)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700487 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700488
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700489 // For use by ImageWriter to find DexCaches for its roots
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800490 const std::vector<mirror::DexCache*>& GetDexCaches() {
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700491 return dex_caches_;
492 }
493
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700494 const OatFile* FindOpenedOatFileForDexFile(const DexFile& dex_file)
Ian Rogers33e95662013-05-20 20:29:14 -0700495 LOCKS_EXCLUDED(dex_lock_)
496 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700497 const OatFile* FindOpenedOatFileFromDexLocation(const std::string& dex_location)
Ian Rogers1bf8d4d2013-05-30 00:18:49 -0700498 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_, dex_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700499 const OatFile* FindOpenedOatFileFromOatLocation(const std::string& oat_location)
Ian Rogers1bf8d4d2013-05-30 00:18:49 -0700500 SHARED_LOCKS_REQUIRED(dex_lock_);
Ian Rogerse3359f72013-06-11 15:14:11 -0700501 const DexFile* FindDexFileInOatLocation(const std::string& dex_location,
502 uint32_t dex_location_checksum,
503 const std::string& oat_location)
504 EXCLUSIVE_LOCKS_REQUIRED(dex_lock_)
505 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
506
Brian Carlstromafe25512012-06-27 17:02:58 -0700507 const DexFile* VerifyAndOpenDexFileFromOatFile(const OatFile* oat_file,
508 const std::string& dex_location,
509 uint32_t dex_location_checksum)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700510 EXCLUSIVE_LOCKS_REQUIRED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700511 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromfad71432011-10-16 20:25:10 -0700512
Brian Carlstromea46f952013-07-30 01:26:50 -0700513 mirror::ArtMethod* CreateProxyConstructor(Thread* self, SirtRef<mirror::Class>& klass,
514 mirror::Class* proxy_class)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700515 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromea46f952013-07-30 01:26:50 -0700516 mirror::ArtMethod* CreateProxyMethod(Thread* self, SirtRef<mirror::Class>& klass,
517 SirtRef<mirror::ArtMethod>& prototype)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700518 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jesse Wilson95caa792011-10-12 18:14:17 -0400519
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700520 std::vector<const DexFile*> boot_class_path_;
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700521
Ian Rogers1bf8d4d2013-05-30 00:18:49 -0700522 mutable ReaderWriterMutex dex_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800523 std::vector<mirror::DexCache*> dex_caches_ GUARDED_BY(dex_lock_);
Elliott Hughesf8349362012-06-18 15:00:06 -0700524 std::vector<const OatFile*> oat_files_ GUARDED_BY(dex_lock_);
Brian Carlstrom47d237a2011-10-18 15:08:33 -0700525
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700526
Brian Carlstromaded5f72011-10-07 17:15:04 -0700527 // multimap from a string hash code of a class descriptor to
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800528 // mirror::Class* instances. Results should be compared for a matching
Brian Carlstrom9cff8e12011-08-18 16:47:29 -0700529 // Class::descriptor_ and Class::class_loader_.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800530 typedef std::multimap<size_t, mirror::Class*> Table;
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700531 Table class_table_ GUARDED_BY(Locks::classlinker_classes_lock_);
Elliott Hughesf8349362012-06-18 15:00:06 -0700532
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700533 // Do we need to search dex caches to find image classes?
534 bool dex_cache_image_class_lookup_required_;
535 // Number of times we've searched dex caches for a class. After a certain number of misses we move
536 // the classes into the class_table_ to avoid dex cache based searches.
537 AtomicInteger failed_dex_cache_class_lookups_;
538
539 mirror::Class* LookupClassFromTableLocked(const char* descriptor,
540 const mirror::ClassLoader* class_loader,
541 size_t hash)
542 SHARED_LOCKS_REQUIRED(Locks::classlinker_classes_lock_, Locks::mutator_lock_);
543
544 void MoveImageClassesToClassTable() LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
545 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
546 mirror::Class* LookupClassFromImage(const char* descriptor)
547 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700548
Brian Carlstroma663ea52011-08-19 23:33:41 -0700549 // indexes into class_roots_.
550 // needs to be kept in sync with class_roots_descriptors_.
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700551 enum ClassRoot {
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700552 kJavaLangClass,
553 kJavaLangObject,
Elliott Hughes418d20f2011-09-22 14:00:39 -0700554 kClassArrayClass,
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700555 kObjectArrayClass,
556 kJavaLangString,
Mathieu Chartier66f19252012-09-18 08:57:04 -0700557 kJavaLangDexCache,
Elliott Hughesbf61ba32011-10-11 10:53:09 -0700558 kJavaLangRefReference,
Brian Carlstromea46f952013-07-30 01:26:50 -0700559 kJavaLangReflectArtField,
560 kJavaLangReflectArtMethod,
Ian Rogers466bb252011-10-14 03:29:56 -0700561 kJavaLangReflectProxy,
Mathieu Chartier66f19252012-09-18 08:57:04 -0700562 kJavaLangStringArrayClass,
Brian Carlstromea46f952013-07-30 01:26:50 -0700563 kJavaLangReflectArtFieldArrayClass,
564 kJavaLangReflectArtMethodArrayClass,
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700565 kJavaLangClassLoader,
Ian Rogers5167c972012-02-03 10:41:20 -0800566 kJavaLangThrowable,
jeffhao8cd6dda2012-02-22 10:15:34 -0800567 kJavaLangClassNotFoundException,
Shih-wei Liao55df06b2011-08-26 14:39:27 -0700568 kJavaLangStackTraceElement,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700569 kPrimitiveBoolean,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700570 kPrimitiveByte,
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700571 kPrimitiveChar,
572 kPrimitiveDouble,
573 kPrimitiveFloat,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700574 kPrimitiveInt,
575 kPrimitiveLong,
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700576 kPrimitiveShort,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700577 kPrimitiveVoid,
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700578 kBooleanArrayClass,
579 kByteArrayClass,
580 kCharArrayClass,
581 kDoubleArrayClass,
582 kFloatArrayClass,
583 kIntArrayClass,
584 kLongArrayClass,
585 kShortArrayClass,
Shih-wei Liao55df06b2011-08-26 14:39:27 -0700586 kJavaLangStackTraceElementArrayClass,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700587 kClassRootsMax,
588 };
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800589 mirror::ObjectArray<mirror::Class>* class_roots_;
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700590
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800591 mirror::Class* GetClassRoot(ClassRoot class_root) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700592
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800593 void SetClassRoot(ClassRoot class_root, mirror::Class* klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700594 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstroma663ea52011-08-19 23:33:41 -0700595
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800596 mirror::ObjectArray<mirror::Class>* GetClassRoots() {
Brian Carlstrom34f426c2011-10-04 12:58:02 -0700597 DCHECK(class_roots_ != NULL);
598 return class_roots_;
599 }
600
Elliott Hughes418d20f2011-09-22 14:00:39 -0700601 static const char* class_roots_descriptors_[];
Brian Carlstroma663ea52011-08-19 23:33:41 -0700602
603 const char* GetClassRootDescriptor(ClassRoot class_root) {
604 const char* descriptor = class_roots_descriptors_[class_root];
605 CHECK(descriptor != NULL);
606 return descriptor;
607 }
608
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800609 mirror::IfTable* array_iftable_;
Carl Shapiro565f5072011-07-10 13:39:43 -0700610
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700611 bool init_done_;
Mathieu Chartierc4621982013-09-16 19:43:47 -0700612 bool dex_caches_dirty_ GUARDED_BY(dex_lock_);
613 bool class_table_dirty_ GUARDED_BY(Locks::classlinker_classes_lock_);
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700614
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700615 InternTable* intern_table_;
616
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700617 const void* portable_resolution_trampoline_;
618 const void* quick_resolution_trampoline_;
619
Brian Carlstrom34f426c2011-10-04 12:58:02 -0700620 friend class ImageWriter; // for GetClassRoots
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800621 FRIEND_TEST(ClassLinkerTest, ClassRootDescriptors);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800622 FRIEND_TEST(mirror::DexCacheTest, Open);
Brian Carlstromae826982011-11-09 01:33:42 -0800623 FRIEND_TEST(ExceptionTest, FindExceptionHandler);
624 FRIEND_TEST(ObjectTest, AllocObjectArray);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700625 DISALLOW_COPY_AND_ASSIGN(ClassLinker);
626};
627
628} // namespace art
629
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700630#endif // ART_RUNTIME_CLASS_LINKER_H_