blob: 624b7cecec3ab573ece1adbb6f20631597dc5117 [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 Rogers2dd0e2c2013-01-24 12:42:14 -080076 mirror::Class* DefineClass(const StringPiece& descriptor, mirror::ClassLoader* class_loader,
77 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 Rogers00f7d0e2012-07-19 15:28:27 -070099 void DumpAllClasses(int flags) const
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 Rogers00f7d0e2012-07-19 15:28:27 -0700103 void DumpForSigQuit(std::ostream& os) const
Ian Rogersb726dcb2012-09-05 08:57:23 -0700104 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_);
Elliott Hughescac6cc72011-11-03 20:31:21 -0700105
Ian Rogersb726dcb2012-09-05 08:57:23 -0700106 size_t NumLoadedClasses() const LOCKS_EXCLUDED(Locks::classlinker_classes_lock_);
Elliott Hughese27955c2011-08-26 15:21:24 -0700107
Brian Carlstromb63ec392011-08-27 17:38:27 -0700108 // Resolve a String with the given index from the DexFile, storing the
Brian Carlstromaded5f72011-10-07 17:15:04 -0700109 // result in the DexCache. The referrer is used to identify the
110 // target DexCache and ClassLoader to use for resolution.
Brian Carlstromea46f952013-07-30 01:26:50 -0700111 mirror::String* ResolveString(uint32_t string_idx, const mirror::ArtMethod* referrer)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800112 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromaded5f72011-10-07 17:15:04 -0700113
114 // Resolve a String with the given index from the DexFile, storing the
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700115 // result in the DexCache.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800116 mirror::String* ResolveString(const DexFile& dex_file, uint32_t string_idx,
117 mirror::DexCache* dex_cache)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700118 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700119
Brian Carlstromb63ec392011-08-27 17:38:27 -0700120 // Resolve a Type with the given index from the DexFile, storing the
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700121 // result in the DexCache. The referrer is used to identity the
122 // target DexCache and ClassLoader to use for resolution.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800123 mirror::Class* ResolveType(const DexFile& dex_file, uint16_t type_idx,
124 const mirror::Class* referrer)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700125 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700126 return ResolveType(dex_file,
127 type_idx,
128 referrer->GetDexCache(),
129 referrer->GetClassLoader());
130 }
131
Brian Carlstromb63ec392011-08-27 17:38:27 -0700132 // Resolve a Type with the given index from the DexFile, storing the
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700133 // result in the DexCache. The referrer is used to identify the
Brian Carlstromb63ec392011-08-27 17:38:27 -0700134 // target DexCache and ClassLoader to use for resolution.
Brian Carlstromea46f952013-07-30 01:26:50 -0700135 mirror::Class* ResolveType(uint16_t type_idx, const mirror::ArtMethod* referrer)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800136 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700137
Brian Carlstromea46f952013-07-30 01:26:50 -0700138 mirror::Class* ResolveType(uint16_t type_idx, const mirror::ArtField* referrer)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800139 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromb63ec392011-08-27 17:38:27 -0700140
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700141 // Resolve a type with the given ID from the DexFile, storing the
142 // result in DexCache. The ClassLoader is used to search for the
143 // type, since it may be referenced from but not contained within
144 // the given DexFile.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800145 mirror::Class* ResolveType(const DexFile& dex_file,
146 uint16_t type_idx,
147 mirror::DexCache* dex_cache,
148 mirror::ClassLoader* class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700149 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700150
151 // Resolve a method with a given ID from the DexFile, storing the
152 // result in DexCache. The ClassLinker and ClassLoader are used as
153 // in ResolveType. What is unique is the method type argument which
154 // is used to determine if this method is a direct, static, or
155 // virtual method.
Brian Carlstromea46f952013-07-30 01:26:50 -0700156 mirror::ArtMethod* ResolveMethod(const DexFile& dex_file,
157 uint32_t method_idx,
158 mirror::DexCache* dex_cache,
159 mirror::ClassLoader* class_loader,
160 const mirror::ArtMethod* referrer,
161 InvokeType type)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700162 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700163
Brian Carlstromea46f952013-07-30 01:26:50 -0700164 mirror::ArtMethod* ResolveMethod(uint32_t method_idx, const mirror::ArtMethod* referrer,
165 InvokeType type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800166 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom16192862011-09-12 17:50:06 -0700167
Brian Carlstromea46f952013-07-30 01:26:50 -0700168 mirror::ArtField* ResolveField(uint32_t field_idx, const mirror::ArtMethod* referrer,
169 bool is_static)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800170 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromb9edb842011-08-28 16:31:06 -0700171
Brian Carlstrom16192862011-09-12 17:50:06 -0700172 // Resolve a field with a given ID from the DexFile, storing the
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700173 // result in DexCache. The ClassLinker and ClassLoader are used as
174 // in ResolveType. What is unique is the is_static argument which is
175 // used to determine if we are resolving a static or non-static
176 // field.
Brian Carlstromea46f952013-07-30 01:26:50 -0700177 mirror::ArtField* ResolveField(const DexFile& dex_file,
178 uint32_t field_idx,
179 mirror::DexCache* dex_cache,
180 mirror::ClassLoader* class_loader,
181 bool is_static)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700182 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700183
Ian Rogersb067ac22011-12-13 18:05:09 -0800184 // Resolve a field with a given ID from the DexFile, storing the
185 // result in DexCache. The ClassLinker and ClassLoader are used as
186 // in ResolveType. No is_static argument is provided so that Java
187 // field resolution semantics are followed.
Brian Carlstromea46f952013-07-30 01:26:50 -0700188 mirror::ArtField* ResolveFieldJLS(const DexFile& dex_file,
189 uint32_t field_idx,
190 mirror::DexCache* dex_cache,
191 mirror::ClassLoader* class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700192 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersb067ac22011-12-13 18:05:09 -0800193
Ian Rogersad25ac52011-10-04 19:13:33 -0700194 // Get shorty from method index without resolution. Used to do handlerization.
Brian Carlstromea46f952013-07-30 01:26:50 -0700195 const char* MethodShorty(uint32_t method_idx, mirror::ArtMethod* referrer, uint32_t* length)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700196 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersad25ac52011-10-04 19:13:33 -0700197
Elliott Hughesf4c21c92011-08-19 17:31:31 -0700198 // Returns true on success, false if there's an exception pending.
Brian Carlstrom25c33252011-09-18 15:58:35 -0700199 // can_run_clinit=false allows the compiler to attempt to init a class,
200 // given the restriction that no <clinit> execution is possible.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800201 bool EnsureInitialized(mirror::Class* c, bool can_run_clinit, bool can_init_fields)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700202 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700203
Elliott Hughes2a20cfd2011-09-23 19:30:41 -0700204 // Initializes classes that have instances in the image but that have
205 // <clinit> methods so they could not be initialized by the compiler.
Ian Rogersb726dcb2012-09-05 08:57:23 -0700206 void RunRootClinits() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes2a20cfd2011-09-23 19:30:41 -0700207
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700208 void RegisterDexFile(const DexFile& dex_file)
209 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700210 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800211 void RegisterDexFile(const DexFile& dex_file, SirtRef<mirror::DexCache>& dex_cache)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700212 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700213 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700214
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700215 void RegisterOatFile(const OatFile& oat_file)
216 LOCKS_EXCLUDED(dex_lock_);
Brian Carlstrom866c8622012-01-06 16:35:13 -0800217
Brian Carlstrom8a487412011-08-29 20:08:52 -0700218 const std::vector<const DexFile*>& GetBootClassPath() {
219 return boot_class_path_;
220 }
221
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700222 void VisitClasses(ClassVisitor* visitor, void* arg) const
Ian Rogersb726dcb2012-09-05 08:57:23 -0700223 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700224 // Less efficient variant of VisitClasses that doesn't hold the classlinker_classes_lock_
225 // when calling the visitor.
226 void VisitClassesWithoutClassesLock(ClassVisitor* visitor, void* arg) const
Ian Rogersb726dcb2012-09-05 08:57:23 -0700227 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_);
Elliott Hughesa2155262011-11-16 16:26:58 -0800228
Ian Rogers1d54e732013-05-02 21:10:01 -0700229 void VisitRoots(RootVisitor* visitor, void* arg, bool clean_dirty)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700230 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_, dex_lock_);
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700231
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800232 mirror::DexCache* FindDexCache(const DexFile& dex_file) const
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700233 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700234 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700235 bool IsDexFileRegistered(const DexFile& dex_file) const
236 LOCKS_EXCLUDED(dex_lock_);
Brian Carlstromea46f952013-07-30 01:26:50 -0700237 void FixupDexCaches(mirror::ArtMethod* resolution_method) 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_);
Brian Carlstrom1d9f52b2011-10-13 10:50:45 -0700240
jeffhao262bf462011-10-20 18:36:32 -0700241 // Generate an oat file from a dex file
Brian Carlstromd601af82012-01-06 10:15:19 -0800242 bool GenerateOatFile(const std::string& dex_filename,
243 int oat_fd,
244 const std::string& oat_cache_filename);
jeffhao262bf462011-10-20 18:36:32 -0700245
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700246 const OatFile* FindOatFileFromOatLocation(const std::string& location)
247 LOCKS_EXCLUDED(dex_lock_);
248
249 const OatFile* FindOatFileFromOatLocationLocked(const std::string& location)
Ian Rogers1bf8d4d2013-05-30 00:18:49 -0700250 SHARED_LOCKS_REQUIRED(dex_lock_);
buzbeec143c552011-08-20 17:38:58 -0700251
Brian Carlstrom5b332c82012-02-01 15:02:31 -0800252 // Finds the oat file for a dex location, generating the oat file if
253 // it is missing or out of date. Returns the DexFile from within the
254 // created oat file.
255 const DexFile* FindOrCreateOatFileForDexLocation(const std::string& dex_location,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700256 const std::string& oat_location)
Ian Rogers33e95662013-05-20 20:29:14 -0700257 LOCKS_EXCLUDED(dex_lock_)
258 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700259 const DexFile* FindOrCreateOatFileForDexLocationLocked(const std::string& dex_location,
260 const std::string& oat_location)
Ian Rogers33e95662013-05-20 20:29:14 -0700261 EXCLUSIVE_LOCKS_REQUIRED(dex_lock_)
262 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom5b332c82012-02-01 15:02:31 -0800263 // Find a DexFile within an OatFile given a DexFile location. Note
264 // that this returns null if the location checksum of the DexFile
265 // does not match the OatFile.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700266 const DexFile* FindDexFileInOatFileFromDexLocation(const std::string& location)
267 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700268 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom5b332c82012-02-01 15:02:31 -0800269
jeffhaof6174e82012-01-31 16:14:17 -0800270
Brian Carlstrom28db0122012-10-18 16:20:41 -0700271 // Returns true if oat file contains the dex file with the given location and checksum.
Brian Carlstromafe25512012-06-27 17:02:58 -0700272 static bool VerifyOatFileChecksums(const OatFile* oat_file,
273 const std::string& dex_location,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700274 uint32_t dex_location_checksum)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700275 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromafe25512012-06-27 17:02:58 -0700276
Elliott Hughes418d20f2011-09-22 14:00:39 -0700277 // TODO: replace this with multiple methods that allocate the correct managed type.
Shih-wei Liao44175362011-08-28 16:59:17 -0700278 template <class T>
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800279 mirror::ObjectArray<T>* AllocObjectArray(Thread* self, size_t length)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700280 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Shih-wei Liao55df06b2011-08-26 14:39:27 -0700281
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800282 mirror::ObjectArray<mirror::Class>* AllocClassArray(Thread* self, size_t length)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700283 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
jeffhao98eacac2011-09-14 16:11:53 -0700284
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800285 mirror::ObjectArray<mirror::String>* AllocStringArray(Thread* self, size_t length)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700286 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800287
Brian Carlstromea46f952013-07-30 01:26:50 -0700288 mirror::ObjectArray<mirror::ArtMethod>* AllocArtMethodArray(Thread* self, size_t length)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800289 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
290
291 mirror::IfTable* AllocIfTable(Thread* self, size_t ifcount)
292 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
293
Brian Carlstromea46f952013-07-30 01:26:50 -0700294 mirror::ObjectArray<mirror::ArtField>* AllocArtFieldArray(Thread* self, size_t length)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800295 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
296
297 mirror::ObjectArray<mirror::StackTraceElement>* AllocStackTraceElementArray(Thread* self,
298 size_t length)
299 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
300
301 void VerifyClass(mirror::Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
302 bool VerifyClassUsingOatFile(const DexFile& dex_file, mirror::Class* klass,
303 mirror::Class::Status& oat_file_class_status)
304 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
305 void ResolveClassExceptionHandlerTypes(const DexFile& dex_file, mirror::Class* klass)
306 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromea46f952013-07-30 01:26:50 -0700307 void ResolveMethodExceptionHandlerTypes(const DexFile& dex_file, mirror::ArtMethod* klass)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800308 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
309
310 mirror::Class* CreateProxyClass(mirror::String* name, mirror::ObjectArray<mirror::Class>* interfaces,
311 mirror::ClassLoader* loader,
Brian Carlstromea46f952013-07-30 01:26:50 -0700312 mirror::ObjectArray<mirror::ArtMethod>* methods,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800313 mirror::ObjectArray<mirror::ObjectArray<mirror::Class> >* throws)
314 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
315 std::string GetDescriptorForProxy(const mirror::Class* proxy_class)
316 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromea46f952013-07-30 01:26:50 -0700317 mirror::ArtMethod* FindMethodForProxy(const mirror::Class* proxy_class,
318 const mirror::ArtMethod* proxy_method)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700319 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700320 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jesse Wilson95caa792011-10-12 18:14:17 -0400321
Ian Rogers19846512012-02-24 11:42:47 -0800322 // Get the oat code for a method when its class isn't yet initialized
Brian Carlstromea46f952013-07-30 01:26:50 -0700323 const void* GetOatCodeFor(const mirror::ArtMethod* method)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700324 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers19846512012-02-24 11:42:47 -0800325
Mathieu Chartiere35517a2012-10-30 18:49:55 -0700326 // Get the oat code for a method from a method index.
Ian Rogers33e95662013-05-20 20:29:14 -0700327 const void* GetOatCodeFor(const DexFile& dex_file, uint32_t method_idx)
328 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartiere35517a2012-10-30 18:49:55 -0700329
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700330 pid_t GetClassesLockOwner(); // For SignalCatcher.
331 pid_t GetDexLockOwner(); // For SignalCatcher.
Brian Carlstrom24a3c2e2011-10-17 18:07:52 -0700332
Mathieu Chartier9ebae1f2012-10-15 17:38:16 -0700333 bool IsDirty() const {
334 return is_dirty_;
335 }
336
337 void Dirty() {
338 is_dirty_ = true;
339 }
340
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700341 const void* GetPortableResolutionTrampoline() const {
342 return portable_resolution_trampoline_;
343 }
344
345 const void* GetQuickResolutionTrampoline() const {
346 return quick_resolution_trampoline_;
347 }
348
Ian Rogers848871b2013-08-05 10:56:33 -0700349 InternTable* GetInternTable() const {
350 return intern_table_;
351 }
352
353 // Attempts to insert a class into a class table. Returns NULL if
354 // the class was inserted, otherwise returns an existing class with
355 // the same descriptor and ClassLoader.
356 mirror::Class* InsertClass(const StringPiece& descriptor, mirror::Class* klass, bool image_class)
357 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
358 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
359
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700360 private:
Elliott Hughes4dd9b4d2011-12-12 18:29:24 -0800361 explicit ClassLinker(InternTable*);
Carl Shapiro61e019d2011-07-14 16:53:09 -0700362
Brian Carlstromea46f952013-07-30 01:26:50 -0700363 const OatFile::OatMethod GetOatMethodFor(const mirror::ArtMethod* method)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700364 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
TDYa12785321912012-04-01 15:24:56 -0700365
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700366 // Initialize class linker by bootstraping from dex files
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700367 void InitFromCompiler(const std::vector<const DexFile*>& boot_class_path)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700368 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro61e019d2011-07-14 16:53:09 -0700369
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700370 // Initialize class linker from one or more images.
Ian Rogersb726dcb2012-09-05 08:57:23 -0700371 void InitFromImage() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom56d947f2013-07-15 13:14:23 -0700372 OatFile& GetImageOatFile(gc::space::ImageSpace* space)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700373 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700374 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstroma663ea52011-08-19 23:33:41 -0700375
Ian Rogersb726dcb2012-09-05 08:57:23 -0700376 void FinishInit() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstroma663ea52011-08-19 23:33:41 -0700377
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700378 // For early bootstrapping by Init
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800379 mirror::Class* AllocClass(Thread* self, mirror::Class* java_lang_Class, size_t class_size)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700380 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700381
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800382 // Alloc* convenience functions to avoid needing to pass in mirror::Class*
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700383 // values that are known to the ClassLinker such as
384 // kObjectArrayClass and kJavaLangString etc.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800385 mirror::Class* AllocClass(Thread* self, size_t class_size) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
386 mirror::DexCache* AllocDexCache(Thread* self, const DexFile& dex_file)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700387 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromea46f952013-07-30 01:26:50 -0700388 mirror::ArtField* AllocArtField(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
389 mirror::ArtMethod* AllocArtMethod(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersbdb03912011-09-14 00:55:44 -0700390
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800391 mirror::Class* CreatePrimitiveClass(Thread* self, Primitive::Type type)
392 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
393 mirror::Class* InitializePrimitiveClass(mirror::Class* primitive_class, Primitive::Type type)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700394 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom5b8e4c82011-09-18 01:38:59 -0700395
Brian Carlstroma331b3c2011-07-18 17:47:56 -0700396
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800397 mirror::Class* CreateArrayClass(const std::string& descriptor, mirror::ClassLoader* class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700398 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstroma331b3c2011-07-18 17:47:56 -0700399
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700400 void AppendToBootClassPath(const DexFile& dex_file)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700401 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800402 void AppendToBootClassPath(const DexFile& dex_file, SirtRef<mirror::DexCache>& dex_cache)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700403 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700404
Elliott Hughes5fe594f2011-09-08 12:33:17 -0700405 void ConstructFieldMap(const DexFile& dex_file, const DexFile::ClassDef& dex_class_def,
Brian Carlstromea46f952013-07-30 01:26:50 -0700406 mirror::Class* c, SafeMap<uint32_t, mirror::ArtField*>& field_map)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700407 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes5fe594f2011-09-08 12:33:17 -0700408
Brian Carlstrom4873d462011-08-21 15:23:39 -0700409 size_t SizeOfClass(const DexFile& dex_file,
410 const DexFile::ClassDef& dex_class_def);
411
Brian Carlstromf615a612011-07-23 12:50:34 -0700412 void LoadClass(const DexFile& dex_file,
413 const DexFile::ClassDef& dex_class_def,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800414 SirtRef<mirror::Class>& klass,
415 mirror::ClassLoader* class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700416 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700417
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800418 void LoadField(const DexFile& dex_file, const ClassDataItemIterator& it,
Brian Carlstromea46f952013-07-30 01:26:50 -0700419 SirtRef<mirror::Class>& klass, SirtRef<mirror::ArtField>& dst)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800420 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700421
Brian Carlstromea46f952013-07-30 01:26:50 -0700422 mirror::ArtMethod* LoadMethod(Thread* self, const DexFile& dex_file,
423 const ClassDataItemIterator& dex_method,
424 SirtRef<mirror::Class>& klass)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800425 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom934486c2011-07-12 23:42:50 -0700426
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800427 void FixupStaticTrampolines(mirror::Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers19846512012-02-24 11:42:47 -0800428
429 // Finds the associated oat class for a dex_file and descriptor
Ian Rogers33e95662013-05-20 20:29:14 -0700430 const OatFile::OatClass* GetOatClass(const DexFile& dex_file, const char* descriptor)
431 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers19846512012-02-24 11:42:47 -0800432
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800433 void RegisterDexFileLocked(const DexFile& dex_file, SirtRef<mirror::DexCache>& dex_cache)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700434 EXCLUSIVE_LOCKS_REQUIRED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700435 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers1bf8d4d2013-05-30 00:18:49 -0700436 bool IsDexFileRegisteredLocked(const DexFile& dex_file) const SHARED_LOCKS_REQUIRED(dex_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700437 void RegisterOatFileLocked(const OatFile& oat_file) EXCLUSIVE_LOCKS_REQUIRED(dex_lock_)
438 EXCLUSIVE_LOCKS_REQUIRED(dex_lock_);
Brian Carlstromaded5f72011-10-07 17:15:04 -0700439
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800440 bool InitializeClass(mirror::Class* klass, bool can_run_clinit, bool can_init_statics)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700441 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800442 bool WaitForInitializeClass(mirror::Class* klass, Thread* self, ObjectLock& lock);
443 bool ValidateSuperClassDescriptors(const mirror::Class* klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700444 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800445 bool InitializeSuperClass(mirror::Class* klass, bool can_run_clinit, bool can_init_fields)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700446 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers0045a292012-03-31 21:08:41 -0700447 // Initialize static fields, returns true if fields were initialized.
Ian Rogerse6bb3b22013-08-19 21:51:45 -0700448 bool InitializeStaticFields(mirror::Class* klass, bool can_init_statics)
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 Rogers2dd0e2c2013-01-24 12:42:14 -0800461 bool LinkClass(SirtRef<mirror::Class>& klass, mirror::ObjectArray<mirror::Class>* interfaces)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700462 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700463
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800464 bool LinkSuperClass(SirtRef<mirror::Class>& klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700465 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700466
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800467 bool LoadSuperAndInterfaces(SirtRef<mirror::Class>& klass, const DexFile& dex_file)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700468 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700469
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800470 bool LinkMethods(SirtRef<mirror::Class>& klass, 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 LinkVirtualMethods(SirtRef<mirror::Class>& klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700474 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700475
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800476 bool LinkInterfaceMethods(SirtRef<mirror::Class>& klass,
477 mirror::ObjectArray<mirror::Class>* interfaces)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700478 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700479
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800480 bool LinkStaticFields(SirtRef<mirror::Class>& klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700481 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800482 bool LinkInstanceFields(SirtRef<mirror::Class>& klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700483 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800484 bool LinkFields(SirtRef<mirror::Class>& klass, bool is_static)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700485 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700486
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700487
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800488 void CreateReferenceInstanceOffsets(SirtRef<mirror::Class>& klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700489 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800490 void CreateReferenceStaticOffsets(SirtRef<mirror::Class>& klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700491 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800492 void CreateReferenceOffsets(SirtRef<mirror::Class>& klass, bool is_static,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700493 uint32_t reference_offsets)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700494 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700495
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700496 // For use by ImageWriter to find DexCaches for its roots
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800497 const std::vector<mirror::DexCache*>& GetDexCaches() {
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700498 return dex_caches_;
499 }
500
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700501 const OatFile* FindOpenedOatFileForDexFile(const DexFile& dex_file)
Ian Rogers33e95662013-05-20 20:29:14 -0700502 LOCKS_EXCLUDED(dex_lock_)
503 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700504 const OatFile* FindOpenedOatFileFromDexLocation(const std::string& dex_location)
Ian Rogers1bf8d4d2013-05-30 00:18:49 -0700505 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_, dex_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700506 const OatFile* FindOpenedOatFileFromOatLocation(const std::string& oat_location)
Ian Rogers1bf8d4d2013-05-30 00:18:49 -0700507 SHARED_LOCKS_REQUIRED(dex_lock_);
Ian Rogerse3359f72013-06-11 15:14:11 -0700508 const DexFile* FindDexFileInOatLocation(const std::string& dex_location,
509 uint32_t dex_location_checksum,
510 const std::string& oat_location)
511 EXCLUSIVE_LOCKS_REQUIRED(dex_lock_)
512 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
513
Brian Carlstromafe25512012-06-27 17:02:58 -0700514 const DexFile* VerifyAndOpenDexFileFromOatFile(const OatFile* oat_file,
515 const std::string& dex_location,
516 uint32_t dex_location_checksum)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700517 EXCLUSIVE_LOCKS_REQUIRED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700518 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromfad71432011-10-16 20:25:10 -0700519
Brian Carlstromea46f952013-07-30 01:26:50 -0700520 mirror::ArtMethod* CreateProxyConstructor(Thread* self, SirtRef<mirror::Class>& klass,
521 mirror::Class* proxy_class)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700522 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromea46f952013-07-30 01:26:50 -0700523 mirror::ArtMethod* CreateProxyMethod(Thread* self, SirtRef<mirror::Class>& klass,
524 SirtRef<mirror::ArtMethod>& prototype)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700525 SHARED_LOCKS_REQUIRED(Locks::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 Rogers1bf8d4d2013-05-30 00:18:49 -0700529 mutable ReaderWriterMutex dex_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800530 std::vector<mirror::DexCache*> dex_caches_ GUARDED_BY(dex_lock_);
Elliott Hughesf8349362012-06-18 15:00:06 -0700531 std::vector<const OatFile*> oat_files_ GUARDED_BY(dex_lock_);
Brian Carlstrom47d237a2011-10-18 15:08:33 -0700532
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700533
Brian Carlstromaded5f72011-10-07 17:15:04 -0700534 // multimap from a string hash code of a class descriptor to
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800535 // mirror::Class* instances. Results should be compared for a matching
Brian Carlstrom9cff8e12011-08-18 16:47:29 -0700536 // Class::descriptor_ and Class::class_loader_.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800537 typedef std::multimap<size_t, mirror::Class*> Table;
538 Table image_classes_ GUARDED_BY(Locks::classlinker_classes_lock_);
Ian Rogersb726dcb2012-09-05 08:57:23 -0700539 Table classes_ GUARDED_BY(Locks::classlinker_classes_lock_);
Elliott Hughesf8349362012-06-18 15:00:06 -0700540
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800541 mirror::Class* LookupClassLocked(const char* descriptor, const mirror::ClassLoader* class_loader,
542 size_t hash, const Table& classes)
Ian Rogers1bf8d4d2013-05-30 00:18:49 -0700543 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_, Locks::classlinker_classes_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700544
Brian Carlstroma663ea52011-08-19 23:33:41 -0700545 // indexes into class_roots_.
546 // needs to be kept in sync with class_roots_descriptors_.
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700547 enum ClassRoot {
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700548 kJavaLangClass,
549 kJavaLangObject,
Elliott Hughes418d20f2011-09-22 14:00:39 -0700550 kClassArrayClass,
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700551 kObjectArrayClass,
552 kJavaLangString,
Mathieu Chartier66f19252012-09-18 08:57:04 -0700553 kJavaLangDexCache,
Elliott Hughesbf61ba32011-10-11 10:53:09 -0700554 kJavaLangRefReference,
Brian Carlstromea46f952013-07-30 01:26:50 -0700555 kJavaLangReflectArtField,
556 kJavaLangReflectArtMethod,
Ian Rogers466bb252011-10-14 03:29:56 -0700557 kJavaLangReflectProxy,
Mathieu Chartier66f19252012-09-18 08:57:04 -0700558 kJavaLangStringArrayClass,
Brian Carlstromea46f952013-07-30 01:26:50 -0700559 kJavaLangReflectArtFieldArrayClass,
560 kJavaLangReflectArtMethodArrayClass,
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700561 kJavaLangClassLoader,
Ian Rogers5167c972012-02-03 10:41:20 -0800562 kJavaLangThrowable,
jeffhao8cd6dda2012-02-22 10:15:34 -0800563 kJavaLangClassNotFoundException,
Shih-wei Liao55df06b2011-08-26 14:39:27 -0700564 kJavaLangStackTraceElement,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700565 kPrimitiveBoolean,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700566 kPrimitiveByte,
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700567 kPrimitiveChar,
568 kPrimitiveDouble,
569 kPrimitiveFloat,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700570 kPrimitiveInt,
571 kPrimitiveLong,
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700572 kPrimitiveShort,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700573 kPrimitiveVoid,
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700574 kBooleanArrayClass,
575 kByteArrayClass,
576 kCharArrayClass,
577 kDoubleArrayClass,
578 kFloatArrayClass,
579 kIntArrayClass,
580 kLongArrayClass,
581 kShortArrayClass,
Shih-wei Liao55df06b2011-08-26 14:39:27 -0700582 kJavaLangStackTraceElementArrayClass,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700583 kClassRootsMax,
584 };
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800585 mirror::ObjectArray<mirror::Class>* class_roots_;
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700586
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800587 mirror::Class* GetClassRoot(ClassRoot class_root) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700588
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800589 void SetClassRoot(ClassRoot class_root, mirror::Class* klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700590 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstroma663ea52011-08-19 23:33:41 -0700591
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800592 mirror::ObjectArray<mirror::Class>* GetClassRoots() {
Brian Carlstrom34f426c2011-10-04 12:58:02 -0700593 DCHECK(class_roots_ != NULL);
594 return class_roots_;
595 }
596
Elliott Hughes418d20f2011-09-22 14:00:39 -0700597 static const char* class_roots_descriptors_[];
Brian Carlstroma663ea52011-08-19 23:33:41 -0700598
599 const char* GetClassRootDescriptor(ClassRoot class_root) {
600 const char* descriptor = class_roots_descriptors_[class_root];
601 CHECK(descriptor != NULL);
602 return descriptor;
603 }
604
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800605 mirror::IfTable* array_iftable_;
Carl Shapiro565f5072011-07-10 13:39:43 -0700606
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700607 bool init_done_;
Mathieu Chartier9ebae1f2012-10-15 17:38:16 -0700608 bool is_dirty_;
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700609
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700610 InternTable* intern_table_;
611
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700612 const void* portable_resolution_trampoline_;
613 const void* quick_resolution_trampoline_;
614
Brian Carlstrom34f426c2011-10-04 12:58:02 -0700615 friend class ImageWriter; // for GetClassRoots
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800616 FRIEND_TEST(ClassLinkerTest, ClassRootDescriptors);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800617 FRIEND_TEST(mirror::DexCacheTest, Open);
Brian Carlstromae826982011-11-09 01:33:42 -0800618 FRIEND_TEST(ExceptionTest, FindExceptionHandler);
619 FRIEND_TEST(ObjectTest, AllocObjectArray);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700620 DISALLOW_COPY_AND_ASSIGN(ClassLinker);
621};
622
623} // namespace art
624
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700625#endif // ART_RUNTIME_CLASS_LINKER_H_