blob: 473370d90f0c740dc82a9a017fbb9544aa252849 [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:
Jeff Hao88474b42013-10-23 16:24:40 -070054 // Interface method table size. Increasing this value reduces the chance of two interface methods
55 // colliding in the interface method table but increases the size of classes that implement
56 // (non-marker) interfaces.
57 static constexpr size_t kImtSize = 64;
58
Ian Rogers1f539342012-10-03 21:09:42 -070059 // Creates the class linker by bootstrapping from dex files.
Brian Carlstroma004aa92012-02-08 18:05:09 -080060 static ClassLinker* CreateFromCompiler(const std::vector<const DexFile*>& boot_class_path,
Ian Rogers00f7d0e2012-07-19 15:28:27 -070061 InternTable* intern_table)
Ian Rogersb726dcb2012-09-05 08:57:23 -070062 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom58ae9412011-10-04 00:56:06 -070063
Brian Carlstroma004aa92012-02-08 18:05:09 -080064 // Creates the class linker from an image.
Ian Rogers00f7d0e2012-07-19 15:28:27 -070065 static ClassLinker* CreateFromImage(InternTable* intern_table)
Ian Rogersb726dcb2012-09-05 08:57:23 -070066 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro61e019d2011-07-14 16:53:09 -070067
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070068 ~ClassLinker();
Carl Shapiro565f5072011-07-10 13:39:43 -070069
Ian Rogersbe7149f2013-08-20 09:29:39 -070070 bool IsInBootClassPath(const char* descriptor);
71
Elliott Hughes64bf5a32011-09-20 14:43:12 -070072 // Finds a class by its descriptor, loading it if necessary.
Brian Carlstrom74eb46a2011-08-02 20:10:14 -070073 // If class_loader is null, searches boot_class_path_.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080074 mirror::Class* FindClass(const char* descriptor, mirror::ClassLoader* class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -070075 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromaded5f72011-10-07 17:15:04 -070076
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080077 mirror::Class* FindSystemClass(const char* descriptor)
Ian Rogersb726dcb2012-09-05 08:57:23 -070078 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromaded5f72011-10-07 17:15:04 -070079
80 // Define a new a class based on a ClassDef from a DexFile
Ian Rogers7dfb28c2013-08-22 08:18:36 -070081 mirror::Class* DefineClass(const char* descriptor, mirror::ClassLoader* class_loader,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080082 const DexFile& dex_file, const DexFile::ClassDef& dex_class_def)
Ian Rogersb726dcb2012-09-05 08:57:23 -070083 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes64bf5a32011-09-20 14:43:12 -070084
85 // Finds a class by its descriptor, returning NULL if it isn't wasn't loaded
86 // by the given 'class_loader'.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080087 mirror::Class* LookupClass(const char* descriptor, const mirror::ClassLoader* class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -070088 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
89 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070090
Elliott Hughes6fa602d2011-12-02 17:54:25 -080091 // Finds all the classes with the given descriptor, regardless of ClassLoader.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080092 void LookupClasses(const char* descriptor, std::vector<mirror::Class*>& classes)
Ian Rogersb726dcb2012-09-05 08:57:23 -070093 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
94 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes6fa602d2011-12-02 17:54:25 -080095
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080096 mirror::Class* FindPrimitiveClass(char type) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesd8ddfd52011-08-15 14:32:53 -070097
Brian Carlstromae826982011-11-09 01:33:42 -080098 // General class unloading is not supported, this is used to prune
99 // unwanted classes during image writing.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800100 bool RemoveClass(const char* descriptor, const mirror::ClassLoader* class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700101 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
102 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromae826982011-11-09 01:33:42 -0800103
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700104 void DumpAllClasses(int flags)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700105 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
106 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes9d5ccec2011-09-19 13:19:50 -0700107
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700108 void DumpForSigQuit(std::ostream& os)
109 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
110 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughescac6cc72011-11-03 20:31:21 -0700111
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700112 size_t NumLoadedClasses()
113 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
114 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughese27955c2011-08-26 15:21:24 -0700115
Brian Carlstromb63ec392011-08-27 17:38:27 -0700116 // Resolve a String with the given index from the DexFile, storing the
Brian Carlstromaded5f72011-10-07 17:15:04 -0700117 // result in the DexCache. The referrer is used to identify the
118 // target DexCache and ClassLoader to use for resolution.
Brian Carlstromea46f952013-07-30 01:26:50 -0700119 mirror::String* ResolveString(uint32_t string_idx, const mirror::ArtMethod* referrer)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800120 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromaded5f72011-10-07 17:15:04 -0700121
122 // Resolve a String with the given index from the DexFile, storing the
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700123 // result in the DexCache.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800124 mirror::String* ResolveString(const DexFile& dex_file, uint32_t string_idx,
125 mirror::DexCache* dex_cache)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700126 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700127
Brian Carlstromb63ec392011-08-27 17:38:27 -0700128 // Resolve a Type with the given index from the DexFile, storing the
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700129 // result in the DexCache. The referrer is used to identity the
130 // target DexCache and ClassLoader to use for resolution.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800131 mirror::Class* ResolveType(const DexFile& dex_file, uint16_t type_idx,
132 const mirror::Class* referrer)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700133 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700134 return ResolveType(dex_file,
135 type_idx,
136 referrer->GetDexCache(),
137 referrer->GetClassLoader());
138 }
139
Brian Carlstromb63ec392011-08-27 17:38:27 -0700140 // Resolve a Type with the given index from the DexFile, storing the
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700141 // result in the DexCache. The referrer is used to identify the
Brian Carlstromb63ec392011-08-27 17:38:27 -0700142 // target DexCache and ClassLoader to use for resolution.
Brian Carlstromea46f952013-07-30 01:26:50 -0700143 mirror::Class* ResolveType(uint16_t type_idx, const mirror::ArtMethod* referrer)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800144 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700145
Brian Carlstromea46f952013-07-30 01:26:50 -0700146 mirror::Class* ResolveType(uint16_t type_idx, const mirror::ArtField* referrer)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800147 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromb63ec392011-08-27 17:38:27 -0700148
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700149 // Resolve a type with the given ID from the DexFile, storing the
150 // result in DexCache. The ClassLoader is used to search for the
151 // type, since it may be referenced from but not contained within
152 // the given DexFile.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800153 mirror::Class* ResolveType(const DexFile& dex_file,
154 uint16_t type_idx,
155 mirror::DexCache* dex_cache,
156 mirror::ClassLoader* class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700157 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700158
159 // Resolve a method with a given ID from the DexFile, storing the
160 // result in DexCache. The ClassLinker and ClassLoader are used as
161 // in ResolveType. What is unique is the method type argument which
162 // is used to determine if this method is a direct, static, or
163 // virtual method.
Brian Carlstromea46f952013-07-30 01:26:50 -0700164 mirror::ArtMethod* ResolveMethod(const DexFile& dex_file,
165 uint32_t method_idx,
166 mirror::DexCache* dex_cache,
167 mirror::ClassLoader* class_loader,
168 const mirror::ArtMethod* referrer,
169 InvokeType type)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700170 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700171
Brian Carlstromea46f952013-07-30 01:26:50 -0700172 mirror::ArtMethod* ResolveMethod(uint32_t method_idx, const mirror::ArtMethod* referrer,
173 InvokeType type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800174 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom16192862011-09-12 17:50:06 -0700175
Brian Carlstromea46f952013-07-30 01:26:50 -0700176 mirror::ArtField* ResolveField(uint32_t field_idx, const mirror::ArtMethod* referrer,
177 bool is_static)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800178 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromb9edb842011-08-28 16:31:06 -0700179
Brian Carlstrom16192862011-09-12 17:50:06 -0700180 // Resolve a field with a given ID from the DexFile, storing the
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700181 // result in DexCache. The ClassLinker and ClassLoader are used as
182 // in ResolveType. What is unique is the is_static argument which is
183 // used to determine if we are resolving a static or non-static
184 // field.
Brian Carlstromea46f952013-07-30 01:26:50 -0700185 mirror::ArtField* ResolveField(const DexFile& dex_file,
186 uint32_t field_idx,
187 mirror::DexCache* dex_cache,
188 mirror::ClassLoader* class_loader,
189 bool is_static)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700190 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700191
Ian Rogersb067ac22011-12-13 18:05:09 -0800192 // Resolve a field with a given ID from the DexFile, storing the
193 // result in DexCache. The ClassLinker and ClassLoader are used as
194 // in ResolveType. No is_static argument is provided so that Java
195 // field resolution semantics are followed.
Brian Carlstromea46f952013-07-30 01:26:50 -0700196 mirror::ArtField* ResolveFieldJLS(const DexFile& dex_file,
197 uint32_t field_idx,
198 mirror::DexCache* dex_cache,
199 mirror::ClassLoader* class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700200 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersb067ac22011-12-13 18:05:09 -0800201
Ian Rogersad25ac52011-10-04 19:13:33 -0700202 // Get shorty from method index without resolution. Used to do handlerization.
Brian Carlstromea46f952013-07-30 01:26:50 -0700203 const char* MethodShorty(uint32_t method_idx, mirror::ArtMethod* referrer, uint32_t* length)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700204 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersad25ac52011-10-04 19:13:33 -0700205
Elliott Hughesf4c21c92011-08-19 17:31:31 -0700206 // Returns true on success, false if there's an exception pending.
Brian Carlstrom25c33252011-09-18 15:58:35 -0700207 // can_run_clinit=false allows the compiler to attempt to init a class,
208 // given the restriction that no <clinit> execution is possible.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800209 bool EnsureInitialized(mirror::Class* c, bool can_run_clinit, bool can_init_fields)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700210 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700211
Elliott Hughes2a20cfd2011-09-23 19:30:41 -0700212 // Initializes classes that have instances in the image but that have
213 // <clinit> methods so they could not be initialized by the compiler.
Ian Rogersb726dcb2012-09-05 08:57:23 -0700214 void RunRootClinits() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes2a20cfd2011-09-23 19:30:41 -0700215
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700216 void RegisterDexFile(const DexFile& dex_file)
217 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700218 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800219 void RegisterDexFile(const DexFile& dex_file, SirtRef<mirror::DexCache>& dex_cache)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700220 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700221 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700222
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700223 const OatFile* RegisterOatFile(const OatFile* oat_file)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700224 LOCKS_EXCLUDED(dex_lock_);
Brian Carlstrom866c8622012-01-06 16:35:13 -0800225
Brian Carlstrom8a487412011-08-29 20:08:52 -0700226 const std::vector<const DexFile*>& GetBootClassPath() {
227 return boot_class_path_;
228 }
229
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700230 void VisitClasses(ClassVisitor* visitor, void* arg)
231 LOCKS_EXCLUDED(dex_lock_)
232 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700233 // Less efficient variant of VisitClasses that doesn't hold the classlinker_classes_lock_
234 // when calling the visitor.
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700235 void VisitClassesWithoutClassesLock(ClassVisitor* visitor, void* arg)
236 LOCKS_EXCLUDED(dex_lock_)
237 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesa2155262011-11-16 16:26:58 -0800238
Mathieu Chartierc4621982013-09-16 19:43:47 -0700239 void VisitRoots(RootVisitor* visitor, void* arg, bool only_dirty, bool clean_dirty)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700240 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_, dex_lock_);
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700241
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800242 mirror::DexCache* FindDexCache(const DexFile& dex_file) 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_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700245 bool IsDexFileRegistered(const DexFile& dex_file) const
246 LOCKS_EXCLUDED(dex_lock_);
Brian Carlstromea46f952013-07-30 01:26:50 -0700247 void FixupDexCaches(mirror::ArtMethod* resolution_method) const
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700248 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700249 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom1d9f52b2011-10-13 10:50:45 -0700250
jeffhao262bf462011-10-20 18:36:32 -0700251 // Generate an oat file from a dex file
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700252 bool GenerateOatFile(const char* dex_filename,
Brian Carlstromd601af82012-01-06 10:15:19 -0800253 int oat_fd,
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700254 const char* oat_cache_filename);
255 LOCKS_EXCLUDED(Locks::mutator_lock_);
jeffhao262bf462011-10-20 18:36:32 -0700256
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700257 const OatFile* FindOatFileFromOatLocation(const std::string& location,
258 std::string* error_msg)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700259 LOCKS_EXCLUDED(dex_lock_);
260
Brian Carlstrom5b332c82012-02-01 15:02:31 -0800261 // Finds the oat file for a dex location, generating the oat file if
262 // it is missing or out of date. Returns the DexFile from within the
263 // created oat file.
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700264 const DexFile* FindOrCreateOatFileForDexLocation(const char* dex_location,
Brian Carlstrom756ee4e2013-10-03 15:46:12 -0700265 uint32_t dex_location_checksum,
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700266 const char* oat_location,
267 std::string* error_msg)
268 LOCKS_EXCLUDED(dex_lock_, Locks::mutator_lock_);
Brian Carlstrom5b332c82012-02-01 15:02:31 -0800269 // Find a DexFile within an OatFile given a DexFile location. Note
270 // that this returns null if the location checksum of the DexFile
271 // does not match the OatFile.
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700272 const DexFile* FindDexFileInOatFileFromDexLocation(const char* location,
273 uint32_t location_checksum,
274 std::string* error_msg)
275 LOCKS_EXCLUDED(dex_lock_, Locks::mutator_lock_);
Brian Carlstrom5b332c82012-02-01 15:02:31 -0800276
jeffhaof6174e82012-01-31 16:14:17 -0800277
Brian Carlstrom28db0122012-10-18 16:20:41 -0700278 // Returns true if oat file contains the dex file with the given location and checksum.
Brian Carlstromafe25512012-06-27 17:02:58 -0700279 static bool VerifyOatFileChecksums(const OatFile* oat_file,
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700280 const char* dex_location,
281 uint32_t dex_location_checksum,
282 std::string* error_msg);
Brian Carlstromafe25512012-06-27 17:02:58 -0700283
Elliott Hughes418d20f2011-09-22 14:00:39 -0700284 // TODO: replace this with multiple methods that allocate the correct managed type.
Shih-wei Liao44175362011-08-28 16:59:17 -0700285 template <class T>
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800286 mirror::ObjectArray<T>* AllocObjectArray(Thread* self, size_t length)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700287 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Shih-wei Liao55df06b2011-08-26 14:39:27 -0700288
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800289 mirror::ObjectArray<mirror::Class>* AllocClassArray(Thread* self, size_t length)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700290 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
jeffhao98eacac2011-09-14 16:11:53 -0700291
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800292 mirror::ObjectArray<mirror::String>* AllocStringArray(Thread* self, size_t length)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700293 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800294
Brian Carlstromea46f952013-07-30 01:26:50 -0700295 mirror::ObjectArray<mirror::ArtMethod>* AllocArtMethodArray(Thread* self, size_t length)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800296 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
297
298 mirror::IfTable* AllocIfTable(Thread* self, size_t ifcount)
299 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
300
Brian Carlstromea46f952013-07-30 01:26:50 -0700301 mirror::ObjectArray<mirror::ArtField>* AllocArtFieldArray(Thread* self, size_t length)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800302 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
303
304 mirror::ObjectArray<mirror::StackTraceElement>* AllocStackTraceElementArray(Thread* self,
305 size_t length)
306 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
307
308 void VerifyClass(mirror::Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
309 bool VerifyClassUsingOatFile(const DexFile& dex_file, mirror::Class* klass,
310 mirror::Class::Status& oat_file_class_status)
311 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
312 void ResolveClassExceptionHandlerTypes(const DexFile& dex_file, mirror::Class* klass)
313 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromea46f952013-07-30 01:26:50 -0700314 void ResolveMethodExceptionHandlerTypes(const DexFile& dex_file, mirror::ArtMethod* klass)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800315 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
316
317 mirror::Class* CreateProxyClass(mirror::String* name, mirror::ObjectArray<mirror::Class>* interfaces,
318 mirror::ClassLoader* loader,
Brian Carlstromea46f952013-07-30 01:26:50 -0700319 mirror::ObjectArray<mirror::ArtMethod>* methods,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800320 mirror::ObjectArray<mirror::ObjectArray<mirror::Class> >* throws)
321 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
322 std::string GetDescriptorForProxy(const mirror::Class* proxy_class)
323 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromea46f952013-07-30 01:26:50 -0700324 mirror::ArtMethod* FindMethodForProxy(const mirror::Class* proxy_class,
325 const mirror::ArtMethod* proxy_method)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700326 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700327 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jesse Wilson95caa792011-10-12 18:14:17 -0400328
Ian Rogers19846512012-02-24 11:42:47 -0800329 // Get the oat code for a method when its class isn't yet initialized
Brian Carlstromea46f952013-07-30 01:26:50 -0700330 const void* GetOatCodeFor(const mirror::ArtMethod* method)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700331 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers19846512012-02-24 11:42:47 -0800332
Mathieu Chartiere35517a2012-10-30 18:49:55 -0700333 // Get the oat code for a method from a method index.
Ian Rogersee39a102013-09-19 02:56:49 -0700334 const void* GetOatCodeFor(const DexFile& dex_file, uint16_t class_def_idx, uint32_t method_idx)
Ian Rogers33e95662013-05-20 20:29:14 -0700335 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartiere35517a2012-10-30 18:49:55 -0700336
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700337 pid_t GetClassesLockOwner(); // For SignalCatcher.
338 pid_t GetDexLockOwner(); // For SignalCatcher.
Brian Carlstrom24a3c2e2011-10-17 18:07:52 -0700339
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700340 const void* GetPortableResolutionTrampoline() const {
341 return portable_resolution_trampoline_;
342 }
343
344 const void* GetQuickResolutionTrampoline() const {
345 return quick_resolution_trampoline_;
346 }
347
Jeff Hao88474b42013-10-23 16:24:40 -0700348 const void* GetPortableImtConflictTrampoline() const {
349 return portable_imt_conflict_trampoline_;
350 }
351
352 const void* GetQuickImtConflictTrampoline() const {
353 return quick_imt_conflict_trampoline_;
354 }
355
356 InternTable* GetInternTable() const {
357 return intern_table_;
358 }
359
Ian Rogers848871b2013-08-05 10:56:33 -0700360 // Attempts to insert a class into a class table. Returns NULL if
361 // the class was inserted, otherwise returns an existing class with
362 // the same descriptor and ClassLoader.
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700363 mirror::Class* InsertClass(const char* descriptor, mirror::Class* klass, size_t hash)
Ian Rogers848871b2013-08-05 10:56:33 -0700364 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
365 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
366
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700367 private:
Elliott Hughes4dd9b4d2011-12-12 18:29:24 -0800368 explicit ClassLinker(InternTable*);
Carl Shapiro61e019d2011-07-14 16:53:09 -0700369
Brian Carlstromea46f952013-07-30 01:26:50 -0700370 const OatFile::OatMethod GetOatMethodFor(const mirror::ArtMethod* method)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700371 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
TDYa12785321912012-04-01 15:24:56 -0700372
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700373 // Initialize class linker by bootstraping from dex files
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700374 void InitFromCompiler(const std::vector<const DexFile*>& boot_class_path)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700375 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro61e019d2011-07-14 16:53:09 -0700376
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700377 // Initialize class linker from one or more images.
Ian Rogersb726dcb2012-09-05 08:57:23 -0700378 void InitFromImage() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom56d947f2013-07-15 13:14:23 -0700379 OatFile& GetImageOatFile(gc::space::ImageSpace* space)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700380 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700381 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstroma663ea52011-08-19 23:33:41 -0700382
Ian Rogersb726dcb2012-09-05 08:57:23 -0700383 void FinishInit() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstroma663ea52011-08-19 23:33:41 -0700384
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700385 // For early bootstrapping by Init
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800386 mirror::Class* AllocClass(Thread* self, mirror::Class* java_lang_Class, size_t class_size)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700387 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700388
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800389 // Alloc* convenience functions to avoid needing to pass in mirror::Class*
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700390 // values that are known to the ClassLinker such as
391 // kObjectArrayClass and kJavaLangString etc.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800392 mirror::Class* AllocClass(Thread* self, size_t class_size) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
393 mirror::DexCache* AllocDexCache(Thread* self, const DexFile& dex_file)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700394 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromea46f952013-07-30 01:26:50 -0700395 mirror::ArtField* AllocArtField(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
396 mirror::ArtMethod* AllocArtMethod(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersbdb03912011-09-14 00:55:44 -0700397
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800398 mirror::Class* CreatePrimitiveClass(Thread* self, Primitive::Type type)
399 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
400 mirror::Class* InitializePrimitiveClass(mirror::Class* primitive_class, Primitive::Type type)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700401 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom5b8e4c82011-09-18 01:38:59 -0700402
Brian Carlstroma331b3c2011-07-18 17:47:56 -0700403
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700404 mirror::Class* CreateArrayClass(const char* descriptor, mirror::ClassLoader* class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700405 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstroma331b3c2011-07-18 17:47:56 -0700406
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700407 void AppendToBootClassPath(const DexFile& dex_file)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700408 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800409 void AppendToBootClassPath(const DexFile& dex_file, SirtRef<mirror::DexCache>& dex_cache)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700410 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700411
Elliott Hughes5fe594f2011-09-08 12:33:17 -0700412 void ConstructFieldMap(const DexFile& dex_file, const DexFile::ClassDef& dex_class_def,
Brian Carlstromea46f952013-07-30 01:26:50 -0700413 mirror::Class* c, SafeMap<uint32_t, mirror::ArtField*>& field_map)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700414 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes5fe594f2011-09-08 12:33:17 -0700415
Brian Carlstrom4873d462011-08-21 15:23:39 -0700416 size_t SizeOfClass(const DexFile& dex_file,
417 const DexFile::ClassDef& dex_class_def);
418
Brian Carlstromf615a612011-07-23 12:50:34 -0700419 void LoadClass(const DexFile& dex_file,
420 const DexFile::ClassDef& dex_class_def,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800421 SirtRef<mirror::Class>& klass,
422 mirror::ClassLoader* class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700423 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700424
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800425 void LoadField(const DexFile& dex_file, const ClassDataItemIterator& it,
Brian Carlstromea46f952013-07-30 01:26:50 -0700426 SirtRef<mirror::Class>& klass, SirtRef<mirror::ArtField>& dst)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800427 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700428
Brian Carlstromea46f952013-07-30 01:26:50 -0700429 mirror::ArtMethod* LoadMethod(Thread* self, const DexFile& dex_file,
430 const ClassDataItemIterator& dex_method,
431 SirtRef<mirror::Class>& klass)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800432 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom934486c2011-07-12 23:42:50 -0700433
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800434 void FixupStaticTrampolines(mirror::Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers19846512012-02-24 11:42:47 -0800435
436 // Finds the associated oat class for a dex_file and descriptor
Ian Rogersee39a102013-09-19 02:56:49 -0700437 const OatFile::OatClass* GetOatClass(const DexFile& dex_file, uint16_t class_def_idx)
Ian Rogers33e95662013-05-20 20:29:14 -0700438 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers19846512012-02-24 11:42:47 -0800439
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800440 void RegisterDexFileLocked(const DexFile& dex_file, SirtRef<mirror::DexCache>& dex_cache)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700441 EXCLUSIVE_LOCKS_REQUIRED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700442 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers1bf8d4d2013-05-30 00:18:49 -0700443 bool IsDexFileRegisteredLocked(const DexFile& dex_file) const SHARED_LOCKS_REQUIRED(dex_lock_);
Brian Carlstromaded5f72011-10-07 17:15:04 -0700444
Ian Rogers8f3c9ae2013-08-20 17:26:41 -0700445 bool InitializeClass(mirror::Class* klass, bool can_run_clinit, bool can_init_parents)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700446 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800447 bool WaitForInitializeClass(mirror::Class* klass, Thread* self, ObjectLock& lock);
448 bool ValidateSuperClassDescriptors(const mirror::Class* klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700449 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700450
Ian Rogers595799e2012-01-11 17:32:51 -0800451 bool IsSameDescriptorInDifferentClassContexts(const char* descriptor,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800452 const mirror::Class* klass1,
453 const mirror::Class* klass2)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700454 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700455
Brian Carlstromea46f952013-07-30 01:26:50 -0700456 bool IsSameMethodSignatureInDifferentClassContexts(const mirror::ArtMethod* method,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800457 const mirror::Class* klass1,
458 const mirror::Class* klass2)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700459 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700460
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700461 bool LinkClass(SirtRef<mirror::Class>& klass, mirror::ObjectArray<mirror::Class>* interfaces,
462 Thread* self)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700463 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700464
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800465 bool LinkSuperClass(SirtRef<mirror::Class>& klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700466 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700467
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800468 bool LoadSuperAndInterfaces(SirtRef<mirror::Class>& klass, const DexFile& dex_file)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700469 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700470
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800471 bool LinkMethods(SirtRef<mirror::Class>& klass, mirror::ObjectArray<mirror::Class>* interfaces)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700472 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700473
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800474 bool LinkVirtualMethods(SirtRef<mirror::Class>& klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700475 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700476
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800477 bool LinkInterfaceMethods(SirtRef<mirror::Class>& klass,
478 mirror::ObjectArray<mirror::Class>* interfaces)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700479 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700480
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800481 bool LinkStaticFields(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 bool LinkInstanceFields(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 bool LinkFields(SirtRef<mirror::Class>& klass, bool is_static)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700486 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700487
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700488
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800489 void CreateReferenceInstanceOffsets(SirtRef<mirror::Class>& klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700490 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800491 void CreateReferenceStaticOffsets(SirtRef<mirror::Class>& klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700492 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800493 void CreateReferenceOffsets(SirtRef<mirror::Class>& klass, bool is_static,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700494 uint32_t reference_offsets)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700495 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700496
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700497 // For use by ImageWriter to find DexCaches for its roots
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800498 const std::vector<mirror::DexCache*>& GetDexCaches() {
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700499 return dex_caches_;
500 }
501
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700502 const OatFile* FindOpenedOatFileForDexFile(const DexFile& dex_file)
Ian Rogers33e95662013-05-20 20:29:14 -0700503 LOCKS_EXCLUDED(dex_lock_)
504 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700505 const OatFile* FindOpenedOatFileFromDexLocation(const char* dex_location,
Brian Carlstrom756ee4e2013-10-03 15:46:12 -0700506 uint32_t dex_location_checksum)
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700507 LOCKS_EXCLUDED(dex_lock);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700508 const OatFile* FindOpenedOatFileFromOatLocation(const std::string& oat_location)
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700509 LOCKS_EXCLUDED(dex_lock_);
510 const DexFile* FindDexFileInOatLocation(const char* dex_location,
Ian Rogerse3359f72013-06-11 15:14:11 -0700511 uint32_t dex_location_checksum,
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700512 const char* oat_location,
513 std::string* error_msg)
514 LOCKS_EXCLUDED(dex_lock_);
Ian Rogerse3359f72013-06-11 15:14:11 -0700515
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700516 const DexFile* VerifyAndOpenDexFileFromOatFile(const std::string& oat_file_location,
517 const char* dex_location,
518 std::string* error_msg,
519 bool* open_failed)
520 LOCKS_EXCLUDED(dex_lock_);
Brian Carlstromfad71432011-10-16 20:25:10 -0700521
Brian Carlstromea46f952013-07-30 01:26:50 -0700522 mirror::ArtMethod* CreateProxyConstructor(Thread* self, SirtRef<mirror::Class>& klass,
523 mirror::Class* proxy_class)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700524 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromea46f952013-07-30 01:26:50 -0700525 mirror::ArtMethod* CreateProxyMethod(Thread* self, SirtRef<mirror::Class>& klass,
526 SirtRef<mirror::ArtMethod>& prototype)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700527 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jesse Wilson95caa792011-10-12 18:14:17 -0400528
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700529 std::vector<const DexFile*> boot_class_path_;
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700530
Ian Rogers1bf8d4d2013-05-30 00:18:49 -0700531 mutable ReaderWriterMutex dex_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800532 std::vector<mirror::DexCache*> dex_caches_ GUARDED_BY(dex_lock_);
Elliott Hughesf8349362012-06-18 15:00:06 -0700533 std::vector<const OatFile*> oat_files_ GUARDED_BY(dex_lock_);
Brian Carlstrom47d237a2011-10-18 15:08:33 -0700534
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700535
Brian Carlstromaded5f72011-10-07 17:15:04 -0700536 // multimap from a string hash code of a class descriptor to
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800537 // mirror::Class* instances. Results should be compared for a matching
Brian Carlstrom9cff8e12011-08-18 16:47:29 -0700538 // Class::descriptor_ and Class::class_loader_.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800539 typedef std::multimap<size_t, mirror::Class*> Table;
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700540 Table class_table_ GUARDED_BY(Locks::classlinker_classes_lock_);
Elliott Hughesf8349362012-06-18 15:00:06 -0700541
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700542 // Do we need to search dex caches to find image classes?
543 bool dex_cache_image_class_lookup_required_;
544 // Number of times we've searched dex caches for a class. After a certain number of misses we move
545 // the classes into the class_table_ to avoid dex cache based searches.
546 AtomicInteger failed_dex_cache_class_lookups_;
547
548 mirror::Class* LookupClassFromTableLocked(const char* descriptor,
549 const mirror::ClassLoader* class_loader,
550 size_t hash)
551 SHARED_LOCKS_REQUIRED(Locks::classlinker_classes_lock_, Locks::mutator_lock_);
552
553 void MoveImageClassesToClassTable() LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
554 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
555 mirror::Class* LookupClassFromImage(const char* descriptor)
556 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700557
Brian Carlstroma663ea52011-08-19 23:33:41 -0700558 // indexes into class_roots_.
559 // needs to be kept in sync with class_roots_descriptors_.
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700560 enum ClassRoot {
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700561 kJavaLangClass,
562 kJavaLangObject,
Elliott Hughes418d20f2011-09-22 14:00:39 -0700563 kClassArrayClass,
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700564 kObjectArrayClass,
565 kJavaLangString,
Mathieu Chartier66f19252012-09-18 08:57:04 -0700566 kJavaLangDexCache,
Elliott Hughesbf61ba32011-10-11 10:53:09 -0700567 kJavaLangRefReference,
Brian Carlstromea46f952013-07-30 01:26:50 -0700568 kJavaLangReflectArtField,
569 kJavaLangReflectArtMethod,
Ian Rogers466bb252011-10-14 03:29:56 -0700570 kJavaLangReflectProxy,
Mathieu Chartier66f19252012-09-18 08:57:04 -0700571 kJavaLangStringArrayClass,
Brian Carlstromea46f952013-07-30 01:26:50 -0700572 kJavaLangReflectArtFieldArrayClass,
573 kJavaLangReflectArtMethodArrayClass,
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700574 kJavaLangClassLoader,
Ian Rogers5167c972012-02-03 10:41:20 -0800575 kJavaLangThrowable,
jeffhao8cd6dda2012-02-22 10:15:34 -0800576 kJavaLangClassNotFoundException,
Shih-wei Liao55df06b2011-08-26 14:39:27 -0700577 kJavaLangStackTraceElement,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700578 kPrimitiveBoolean,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700579 kPrimitiveByte,
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700580 kPrimitiveChar,
581 kPrimitiveDouble,
582 kPrimitiveFloat,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700583 kPrimitiveInt,
584 kPrimitiveLong,
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700585 kPrimitiveShort,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700586 kPrimitiveVoid,
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700587 kBooleanArrayClass,
588 kByteArrayClass,
589 kCharArrayClass,
590 kDoubleArrayClass,
591 kFloatArrayClass,
592 kIntArrayClass,
593 kLongArrayClass,
594 kShortArrayClass,
Shih-wei Liao55df06b2011-08-26 14:39:27 -0700595 kJavaLangStackTraceElementArrayClass,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700596 kClassRootsMax,
597 };
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800598 mirror::ObjectArray<mirror::Class>* class_roots_;
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700599
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800600 mirror::Class* GetClassRoot(ClassRoot class_root) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700601
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800602 void SetClassRoot(ClassRoot class_root, mirror::Class* klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700603 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstroma663ea52011-08-19 23:33:41 -0700604
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800605 mirror::ObjectArray<mirror::Class>* GetClassRoots() {
Brian Carlstrom34f426c2011-10-04 12:58:02 -0700606 DCHECK(class_roots_ != NULL);
607 return class_roots_;
608 }
609
Elliott Hughes418d20f2011-09-22 14:00:39 -0700610 static const char* class_roots_descriptors_[];
Brian Carlstroma663ea52011-08-19 23:33:41 -0700611
612 const char* GetClassRootDescriptor(ClassRoot class_root) {
613 const char* descriptor = class_roots_descriptors_[class_root];
614 CHECK(descriptor != NULL);
615 return descriptor;
616 }
617
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800618 mirror::IfTable* array_iftable_;
Carl Shapiro565f5072011-07-10 13:39:43 -0700619
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700620 bool init_done_;
Mathieu Chartierc4621982013-09-16 19:43:47 -0700621 bool dex_caches_dirty_ GUARDED_BY(dex_lock_);
622 bool class_table_dirty_ GUARDED_BY(Locks::classlinker_classes_lock_);
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700623
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700624 InternTable* intern_table_;
625
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700626 const void* portable_resolution_trampoline_;
627 const void* quick_resolution_trampoline_;
Jeff Hao88474b42013-10-23 16:24:40 -0700628 const void* portable_imt_conflict_trampoline_;
629 const void* quick_imt_conflict_trampoline_;
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700630
Brian Carlstrom34f426c2011-10-04 12:58:02 -0700631 friend class ImageWriter; // for GetClassRoots
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800632 FRIEND_TEST(ClassLinkerTest, ClassRootDescriptors);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800633 FRIEND_TEST(mirror::DexCacheTest, Open);
Brian Carlstromae826982011-11-09 01:33:42 -0800634 FRIEND_TEST(ExceptionTest, FindExceptionHandler);
635 FRIEND_TEST(ObjectTest, AllocObjectArray);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700636 DISALLOW_COPY_AND_ASSIGN(ClassLinker);
637};
638
639} // namespace art
640
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700641#endif // ART_RUNTIME_CLASS_LINKER_H_