blob: d0cc562ca57d189d3de531818e48d89844288357 [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
Elliott Hughes64bf5a32011-09-20 14:43:12 -070065 // Finds a class by its descriptor, loading it if necessary.
Brian Carlstrom74eb46a2011-08-02 20:10:14 -070066 // If class_loader is null, searches boot_class_path_.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080067 mirror::Class* FindClass(const char* descriptor, mirror::ClassLoader* class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -070068 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromaded5f72011-10-07 17:15:04 -070069
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080070 mirror::Class* FindSystemClass(const char* descriptor)
Ian Rogersb726dcb2012-09-05 08:57:23 -070071 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromaded5f72011-10-07 17:15:04 -070072
73 // Define a new a class based on a ClassDef from a DexFile
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080074 mirror::Class* DefineClass(const StringPiece& descriptor, mirror::ClassLoader* class_loader,
75 const DexFile& dex_file, const DexFile::ClassDef& dex_class_def)
Ian Rogersb726dcb2012-09-05 08:57:23 -070076 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes64bf5a32011-09-20 14:43:12 -070077
78 // Finds a class by its descriptor, returning NULL if it isn't wasn't loaded
79 // by the given 'class_loader'.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080080 mirror::Class* LookupClass(const char* descriptor, const mirror::ClassLoader* class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -070081 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
82 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070083
Elliott Hughes6fa602d2011-12-02 17:54:25 -080084 // Finds all the classes with the given descriptor, regardless of ClassLoader.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080085 void LookupClasses(const char* descriptor, std::vector<mirror::Class*>& classes)
Ian Rogersb726dcb2012-09-05 08:57:23 -070086 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
87 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes6fa602d2011-12-02 17:54:25 -080088
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080089 mirror::Class* FindPrimitiveClass(char type) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesd8ddfd52011-08-15 14:32:53 -070090
Brian Carlstromae826982011-11-09 01:33:42 -080091 // General class unloading is not supported, this is used to prune
92 // unwanted classes during image writing.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080093 bool RemoveClass(const char* descriptor, const mirror::ClassLoader* class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -070094 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
95 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromae826982011-11-09 01:33:42 -080096
Ian Rogers00f7d0e2012-07-19 15:28:27 -070097 void DumpAllClasses(int flags) const
Ian Rogersb726dcb2012-09-05 08:57:23 -070098 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
99 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes9d5ccec2011-09-19 13:19:50 -0700100
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700101 void DumpForSigQuit(std::ostream& os) const
Ian Rogersb726dcb2012-09-05 08:57:23 -0700102 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_);
Elliott Hughescac6cc72011-11-03 20:31:21 -0700103
Ian Rogersb726dcb2012-09-05 08:57:23 -0700104 size_t NumLoadedClasses() const LOCKS_EXCLUDED(Locks::classlinker_classes_lock_);
Elliott Hughese27955c2011-08-26 15:21:24 -0700105
Brian Carlstromb63ec392011-08-27 17:38:27 -0700106 // Resolve a String with the given index from the DexFile, storing the
Brian Carlstromaded5f72011-10-07 17:15:04 -0700107 // result in the DexCache. The referrer is used to identify the
108 // target DexCache and ClassLoader to use for resolution.
Brian Carlstromea46f952013-07-30 01:26:50 -0700109 mirror::String* ResolveString(uint32_t string_idx, const mirror::ArtMethod* referrer)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800110 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromaded5f72011-10-07 17:15:04 -0700111
112 // Resolve a String with the given index from the DexFile, storing the
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700113 // result in the DexCache.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800114 mirror::String* ResolveString(const DexFile& dex_file, uint32_t string_idx,
115 mirror::DexCache* dex_cache)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700116 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700117
Brian Carlstromb63ec392011-08-27 17:38:27 -0700118 // Resolve a Type with the given index from the DexFile, storing the
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700119 // result in the DexCache. The referrer is used to identity the
120 // target DexCache and ClassLoader to use for resolution.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800121 mirror::Class* ResolveType(const DexFile& dex_file, uint16_t type_idx,
122 const mirror::Class* referrer)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700123 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700124 return ResolveType(dex_file,
125 type_idx,
126 referrer->GetDexCache(),
127 referrer->GetClassLoader());
128 }
129
Brian Carlstromb63ec392011-08-27 17:38:27 -0700130 // Resolve a Type with the given index from the DexFile, storing the
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700131 // result in the DexCache. The referrer is used to identify the
Brian Carlstromb63ec392011-08-27 17:38:27 -0700132 // target DexCache and ClassLoader to use for resolution.
Brian Carlstromea46f952013-07-30 01:26:50 -0700133 mirror::Class* ResolveType(uint16_t type_idx, const mirror::ArtMethod* referrer)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800134 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700135
Brian Carlstromea46f952013-07-30 01:26:50 -0700136 mirror::Class* ResolveType(uint16_t type_idx, const mirror::ArtField* referrer)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800137 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromb63ec392011-08-27 17:38:27 -0700138
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700139 // Resolve a type with the given ID from the DexFile, storing the
140 // result in DexCache. The ClassLoader is used to search for the
141 // type, since it may be referenced from but not contained within
142 // the given DexFile.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800143 mirror::Class* ResolveType(const DexFile& dex_file,
144 uint16_t type_idx,
145 mirror::DexCache* dex_cache,
146 mirror::ClassLoader* class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700147 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700148
149 // Resolve a method with a given ID from the DexFile, storing the
150 // result in DexCache. The ClassLinker and ClassLoader are used as
151 // in ResolveType. What is unique is the method type argument which
152 // is used to determine if this method is a direct, static, or
153 // virtual method.
Brian Carlstromea46f952013-07-30 01:26:50 -0700154 mirror::ArtMethod* ResolveMethod(const DexFile& dex_file,
155 uint32_t method_idx,
156 mirror::DexCache* dex_cache,
157 mirror::ClassLoader* class_loader,
158 const mirror::ArtMethod* referrer,
159 InvokeType type)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700160 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700161
Brian Carlstromea46f952013-07-30 01:26:50 -0700162 mirror::ArtMethod* ResolveMethod(uint32_t method_idx, const mirror::ArtMethod* referrer,
163 InvokeType type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800164 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom16192862011-09-12 17:50:06 -0700165
Brian Carlstromea46f952013-07-30 01:26:50 -0700166 mirror::ArtField* ResolveField(uint32_t field_idx, const mirror::ArtMethod* referrer,
167 bool is_static)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800168 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromb9edb842011-08-28 16:31:06 -0700169
Brian Carlstrom16192862011-09-12 17:50:06 -0700170 // Resolve a field with a given ID from the DexFile, storing the
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700171 // result in DexCache. The ClassLinker and ClassLoader are used as
172 // in ResolveType. What is unique is the is_static argument which is
173 // used to determine if we are resolving a static or non-static
174 // field.
Brian Carlstromea46f952013-07-30 01:26:50 -0700175 mirror::ArtField* ResolveField(const DexFile& dex_file,
176 uint32_t field_idx,
177 mirror::DexCache* dex_cache,
178 mirror::ClassLoader* class_loader,
179 bool is_static)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700180 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700181
Ian Rogersb067ac22011-12-13 18:05:09 -0800182 // Resolve a field with a given ID from the DexFile, storing the
183 // result in DexCache. The ClassLinker and ClassLoader are used as
184 // in ResolveType. No is_static argument is provided so that Java
185 // field resolution semantics are followed.
Brian Carlstromea46f952013-07-30 01:26:50 -0700186 mirror::ArtField* ResolveFieldJLS(const DexFile& dex_file,
187 uint32_t field_idx,
188 mirror::DexCache* dex_cache,
189 mirror::ClassLoader* class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700190 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersb067ac22011-12-13 18:05:09 -0800191
Ian Rogersad25ac52011-10-04 19:13:33 -0700192 // Get shorty from method index without resolution. Used to do handlerization.
Brian Carlstromea46f952013-07-30 01:26:50 -0700193 const char* MethodShorty(uint32_t method_idx, mirror::ArtMethod* referrer, uint32_t* length)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700194 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersad25ac52011-10-04 19:13:33 -0700195
Elliott Hughesf4c21c92011-08-19 17:31:31 -0700196 // Returns true on success, false if there's an exception pending.
Brian Carlstrom25c33252011-09-18 15:58:35 -0700197 // can_run_clinit=false allows the compiler to attempt to init a class,
198 // given the restriction that no <clinit> execution is possible.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800199 bool EnsureInitialized(mirror::Class* c, bool can_run_clinit, bool can_init_fields)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700200 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700201
Elliott Hughes2a20cfd2011-09-23 19:30:41 -0700202 // Initializes classes that have instances in the image but that have
203 // <clinit> methods so they could not be initialized by the compiler.
Ian Rogersb726dcb2012-09-05 08:57:23 -0700204 void RunRootClinits() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes2a20cfd2011-09-23 19:30:41 -0700205
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700206 void RegisterDexFile(const DexFile& dex_file)
207 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700208 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800209 void RegisterDexFile(const DexFile& dex_file, SirtRef<mirror::DexCache>& dex_cache)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700210 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700211 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700212
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700213 void RegisterOatFile(const OatFile& oat_file)
214 LOCKS_EXCLUDED(dex_lock_);
Brian Carlstrom866c8622012-01-06 16:35:13 -0800215
Brian Carlstrom8a487412011-08-29 20:08:52 -0700216 const std::vector<const DexFile*>& GetBootClassPath() {
217 return boot_class_path_;
218 }
219
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700220 void VisitClasses(ClassVisitor* visitor, void* arg) const
Ian Rogersb726dcb2012-09-05 08:57:23 -0700221 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700222 // Less efficient variant of VisitClasses that doesn't hold the classlinker_classes_lock_
223 // when calling the visitor.
224 void VisitClassesWithoutClassesLock(ClassVisitor* visitor, void* arg) const
Ian Rogersb726dcb2012-09-05 08:57:23 -0700225 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_);
Elliott Hughesa2155262011-11-16 16:26:58 -0800226
Ian Rogers1d54e732013-05-02 21:10:01 -0700227 void VisitRoots(RootVisitor* visitor, void* arg, bool clean_dirty)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700228 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_, dex_lock_);
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700229
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800230 mirror::DexCache* FindDexCache(const DexFile& dex_file) const
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700231 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700232 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700233 bool IsDexFileRegistered(const DexFile& dex_file) const
234 LOCKS_EXCLUDED(dex_lock_);
Brian Carlstromea46f952013-07-30 01:26:50 -0700235 void FixupDexCaches(mirror::ArtMethod* resolution_method) const
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700236 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700237 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom1d9f52b2011-10-13 10:50:45 -0700238
jeffhao262bf462011-10-20 18:36:32 -0700239 // Generate an oat file from a dex file
Brian Carlstromd601af82012-01-06 10:15:19 -0800240 bool GenerateOatFile(const std::string& dex_filename,
241 int oat_fd,
242 const std::string& oat_cache_filename);
jeffhao262bf462011-10-20 18:36:32 -0700243
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700244 const OatFile* FindOatFileFromOatLocation(const std::string& location)
245 LOCKS_EXCLUDED(dex_lock_);
246
247 const OatFile* FindOatFileFromOatLocationLocked(const std::string& location)
Ian Rogers1bf8d4d2013-05-30 00:18:49 -0700248 SHARED_LOCKS_REQUIRED(dex_lock_);
buzbeec143c552011-08-20 17:38:58 -0700249
Brian Carlstrom5b332c82012-02-01 15:02:31 -0800250 // Finds the oat file for a dex location, generating the oat file if
251 // it is missing or out of date. Returns the DexFile from within the
252 // created oat file.
253 const DexFile* FindOrCreateOatFileForDexLocation(const std::string& dex_location,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700254 const std::string& oat_location)
Ian Rogers33e95662013-05-20 20:29:14 -0700255 LOCKS_EXCLUDED(dex_lock_)
256 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700257 const DexFile* FindOrCreateOatFileForDexLocationLocked(const std::string& dex_location,
258 const std::string& oat_location)
Ian Rogers33e95662013-05-20 20:29:14 -0700259 EXCLUSIVE_LOCKS_REQUIRED(dex_lock_)
260 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom5b332c82012-02-01 15:02:31 -0800261 // Find a DexFile within an OatFile given a DexFile location. Note
262 // that this returns null if the location checksum of the DexFile
263 // does not match the OatFile.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700264 const DexFile* FindDexFileInOatFileFromDexLocation(const std::string& location)
265 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700266 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom5b332c82012-02-01 15:02:31 -0800267
jeffhaof6174e82012-01-31 16:14:17 -0800268
Brian Carlstrom28db0122012-10-18 16:20:41 -0700269 // Returns true if oat file contains the dex file with the given location and checksum.
Brian Carlstromafe25512012-06-27 17:02:58 -0700270 static bool VerifyOatFileChecksums(const OatFile* oat_file,
271 const std::string& dex_location,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700272 uint32_t dex_location_checksum)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700273 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromafe25512012-06-27 17:02:58 -0700274
Elliott Hughes418d20f2011-09-22 14:00:39 -0700275 // TODO: replace this with multiple methods that allocate the correct managed type.
Shih-wei Liao44175362011-08-28 16:59:17 -0700276 template <class T>
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800277 mirror::ObjectArray<T>* AllocObjectArray(Thread* self, size_t length)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700278 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Shih-wei Liao55df06b2011-08-26 14:39:27 -0700279
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800280 mirror::ObjectArray<mirror::Class>* AllocClassArray(Thread* self, size_t length)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700281 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
jeffhao98eacac2011-09-14 16:11:53 -0700282
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800283 mirror::ObjectArray<mirror::String>* AllocStringArray(Thread* self, size_t length)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700284 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800285
Brian Carlstromea46f952013-07-30 01:26:50 -0700286 mirror::ObjectArray<mirror::ArtMethod>* AllocArtMethodArray(Thread* self, size_t length)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800287 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
288
289 mirror::IfTable* AllocIfTable(Thread* self, size_t ifcount)
290 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
291
Brian Carlstromea46f952013-07-30 01:26:50 -0700292 mirror::ObjectArray<mirror::ArtField>* AllocArtFieldArray(Thread* self, size_t length)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800293 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
294
295 mirror::ObjectArray<mirror::StackTraceElement>* AllocStackTraceElementArray(Thread* self,
296 size_t length)
297 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
298
299 void VerifyClass(mirror::Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
300 bool VerifyClassUsingOatFile(const DexFile& dex_file, mirror::Class* klass,
301 mirror::Class::Status& oat_file_class_status)
302 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
303 void ResolveClassExceptionHandlerTypes(const DexFile& dex_file, mirror::Class* klass)
304 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromea46f952013-07-30 01:26:50 -0700305 void ResolveMethodExceptionHandlerTypes(const DexFile& dex_file, mirror::ArtMethod* klass)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800306 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
307
308 mirror::Class* CreateProxyClass(mirror::String* name, mirror::ObjectArray<mirror::Class>* interfaces,
309 mirror::ClassLoader* loader,
Brian Carlstromea46f952013-07-30 01:26:50 -0700310 mirror::ObjectArray<mirror::ArtMethod>* methods,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800311 mirror::ObjectArray<mirror::ObjectArray<mirror::Class> >* throws)
312 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
313 std::string GetDescriptorForProxy(const mirror::Class* proxy_class)
314 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromea46f952013-07-30 01:26:50 -0700315 mirror::ArtMethod* FindMethodForProxy(const mirror::Class* proxy_class,
316 const mirror::ArtMethod* proxy_method)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700317 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700318 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jesse Wilson95caa792011-10-12 18:14:17 -0400319
Ian Rogers19846512012-02-24 11:42:47 -0800320 // Get the oat code for a method when its class isn't yet initialized
Brian Carlstromea46f952013-07-30 01:26:50 -0700321 const void* GetOatCodeFor(const mirror::ArtMethod* method)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700322 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers19846512012-02-24 11:42:47 -0800323
Mathieu Chartiere35517a2012-10-30 18:49:55 -0700324 // Get the oat code for a method from a method index.
Ian Rogers33e95662013-05-20 20:29:14 -0700325 const void* GetOatCodeFor(const DexFile& dex_file, uint32_t method_idx)
326 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartiere35517a2012-10-30 18:49:55 -0700327
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700328 pid_t GetClassesLockOwner(); // For SignalCatcher.
329 pid_t GetDexLockOwner(); // For SignalCatcher.
Brian Carlstrom24a3c2e2011-10-17 18:07:52 -0700330
Mathieu Chartier9ebae1f2012-10-15 17:38:16 -0700331 bool IsDirty() const {
332 return is_dirty_;
333 }
334
335 void Dirty() {
336 is_dirty_ = true;
337 }
338
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700339 const void* GetPortableResolutionTrampoline() const {
340 return portable_resolution_trampoline_;
341 }
342
343 const void* GetQuickResolutionTrampoline() const {
344 return quick_resolution_trampoline_;
345 }
346
Ian Rogers848871b2013-08-05 10:56:33 -0700347 InternTable* GetInternTable() const {
348 return intern_table_;
349 }
350
351 // Attempts to insert a class into a class table. Returns NULL if
352 // the class was inserted, otherwise returns an existing class with
353 // the same descriptor and ClassLoader.
354 mirror::Class* InsertClass(const StringPiece& descriptor, mirror::Class* klass, bool image_class)
355 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
356 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
357
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700358 private:
Elliott Hughes4dd9b4d2011-12-12 18:29:24 -0800359 explicit ClassLinker(InternTable*);
Carl Shapiro61e019d2011-07-14 16:53:09 -0700360
Brian Carlstromea46f952013-07-30 01:26:50 -0700361 const OatFile::OatMethod GetOatMethodFor(const mirror::ArtMethod* method)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700362 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
TDYa12785321912012-04-01 15:24:56 -0700363
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700364 // Initialize class linker by bootstraping from dex files
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700365 void InitFromCompiler(const std::vector<const DexFile*>& boot_class_path)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700366 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro61e019d2011-07-14 16:53:09 -0700367
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700368 // Initialize class linker from one or more images.
Ian Rogersb726dcb2012-09-05 08:57:23 -0700369 void InitFromImage() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom56d947f2013-07-15 13:14:23 -0700370 OatFile& GetImageOatFile(gc::space::ImageSpace* space)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700371 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700372 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstroma663ea52011-08-19 23:33:41 -0700373
Ian Rogersb726dcb2012-09-05 08:57:23 -0700374 void FinishInit() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstroma663ea52011-08-19 23:33:41 -0700375
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700376 // For early bootstrapping by Init
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800377 mirror::Class* AllocClass(Thread* self, mirror::Class* java_lang_Class, size_t class_size)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700378 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700379
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800380 // Alloc* convenience functions to avoid needing to pass in mirror::Class*
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700381 // values that are known to the ClassLinker such as
382 // kObjectArrayClass and kJavaLangString etc.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800383 mirror::Class* AllocClass(Thread* self, size_t class_size) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
384 mirror::DexCache* AllocDexCache(Thread* self, const DexFile& dex_file)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700385 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromea46f952013-07-30 01:26:50 -0700386 mirror::ArtField* AllocArtField(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
387 mirror::ArtMethod* AllocArtMethod(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersbdb03912011-09-14 00:55:44 -0700388
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800389 mirror::Class* CreatePrimitiveClass(Thread* self, Primitive::Type type)
390 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
391 mirror::Class* InitializePrimitiveClass(mirror::Class* primitive_class, Primitive::Type type)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700392 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom5b8e4c82011-09-18 01:38:59 -0700393
Brian Carlstroma331b3c2011-07-18 17:47:56 -0700394
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800395 mirror::Class* CreateArrayClass(const std::string& descriptor, mirror::ClassLoader* class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700396 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstroma331b3c2011-07-18 17:47:56 -0700397
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700398 void AppendToBootClassPath(const DexFile& dex_file)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700399 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800400 void AppendToBootClassPath(const DexFile& dex_file, SirtRef<mirror::DexCache>& dex_cache)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700401 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700402
Elliott Hughes5fe594f2011-09-08 12:33:17 -0700403 void ConstructFieldMap(const DexFile& dex_file, const DexFile::ClassDef& dex_class_def,
Brian Carlstromea46f952013-07-30 01:26:50 -0700404 mirror::Class* c, SafeMap<uint32_t, mirror::ArtField*>& field_map)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700405 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes5fe594f2011-09-08 12:33:17 -0700406
Brian Carlstrom4873d462011-08-21 15:23:39 -0700407 size_t SizeOfClass(const DexFile& dex_file,
408 const DexFile::ClassDef& dex_class_def);
409
Brian Carlstromf615a612011-07-23 12:50:34 -0700410 void LoadClass(const DexFile& dex_file,
411 const DexFile::ClassDef& dex_class_def,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800412 SirtRef<mirror::Class>& klass,
413 mirror::ClassLoader* class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700414 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700415
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800416 void LoadField(const DexFile& dex_file, const ClassDataItemIterator& it,
Brian Carlstromea46f952013-07-30 01:26:50 -0700417 SirtRef<mirror::Class>& klass, SirtRef<mirror::ArtField>& dst)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800418 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700419
Brian Carlstromea46f952013-07-30 01:26:50 -0700420 mirror::ArtMethod* LoadMethod(Thread* self, const DexFile& dex_file,
421 const ClassDataItemIterator& dex_method,
422 SirtRef<mirror::Class>& klass)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800423 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom934486c2011-07-12 23:42:50 -0700424
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800425 void FixupStaticTrampolines(mirror::Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers19846512012-02-24 11:42:47 -0800426
427 // Finds the associated oat class for a dex_file and descriptor
Ian Rogers33e95662013-05-20 20:29:14 -0700428 const OatFile::OatClass* GetOatClass(const DexFile& dex_file, const char* descriptor)
429 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers19846512012-02-24 11:42:47 -0800430
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800431 void RegisterDexFileLocked(const DexFile& dex_file, SirtRef<mirror::DexCache>& dex_cache)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700432 EXCLUSIVE_LOCKS_REQUIRED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700433 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers1bf8d4d2013-05-30 00:18:49 -0700434 bool IsDexFileRegisteredLocked(const DexFile& dex_file) const SHARED_LOCKS_REQUIRED(dex_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700435 void RegisterOatFileLocked(const OatFile& oat_file) EXCLUSIVE_LOCKS_REQUIRED(dex_lock_)
436 EXCLUSIVE_LOCKS_REQUIRED(dex_lock_);
Brian Carlstromaded5f72011-10-07 17:15:04 -0700437
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800438 bool InitializeClass(mirror::Class* klass, bool can_run_clinit, bool can_init_statics)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700439 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800440 bool WaitForInitializeClass(mirror::Class* klass, Thread* self, ObjectLock& lock);
441 bool ValidateSuperClassDescriptors(const mirror::Class* klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700442 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800443 bool InitializeSuperClass(mirror::Class* klass, bool can_run_clinit, bool can_init_fields)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700444 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers0045a292012-03-31 21:08:41 -0700445 // Initialize static fields, returns true if fields were initialized.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800446 bool InitializeStaticFields(mirror::Class* klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700447 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700448
Ian Rogers595799e2012-01-11 17:32:51 -0800449 bool IsSameDescriptorInDifferentClassContexts(const char* descriptor,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800450 const mirror::Class* klass1,
451 const mirror::Class* klass2)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700452 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700453
Brian Carlstromea46f952013-07-30 01:26:50 -0700454 bool IsSameMethodSignatureInDifferentClassContexts(const mirror::ArtMethod* method,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800455 const mirror::Class* klass1,
456 const mirror::Class* klass2)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700457 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700458
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800459 bool LinkClass(SirtRef<mirror::Class>& klass, mirror::ObjectArray<mirror::Class>* interfaces)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700460 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700461
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800462 bool LinkSuperClass(SirtRef<mirror::Class>& klass)
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 LoadSuperAndInterfaces(SirtRef<mirror::Class>& klass, const DexFile& dex_file)
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 LinkMethods(SirtRef<mirror::Class>& klass, mirror::ObjectArray<mirror::Class>* interfaces)
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 LinkVirtualMethods(SirtRef<mirror::Class>& klass)
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 LinkInterfaceMethods(SirtRef<mirror::Class>& klass,
475 mirror::ObjectArray<mirror::Class>* interfaces)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700476 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700477
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800478 bool LinkStaticFields(SirtRef<mirror::Class>& klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700479 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800480 bool LinkInstanceFields(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 LinkFields(SirtRef<mirror::Class>& klass, bool is_static)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700483 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700484
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700485
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800486 void CreateReferenceInstanceOffsets(SirtRef<mirror::Class>& klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700487 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800488 void CreateReferenceStaticOffsets(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 CreateReferenceOffsets(SirtRef<mirror::Class>& klass, bool is_static,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700491 uint32_t reference_offsets)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700492 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700493
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700494 // For use by ImageWriter to find DexCaches for its roots
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800495 const std::vector<mirror::DexCache*>& GetDexCaches() {
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700496 return dex_caches_;
497 }
498
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700499 const OatFile* FindOpenedOatFileForDexFile(const DexFile& dex_file)
Ian Rogers33e95662013-05-20 20:29:14 -0700500 LOCKS_EXCLUDED(dex_lock_)
501 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700502 const OatFile* FindOpenedOatFileFromDexLocation(const std::string& dex_location)
Ian Rogers1bf8d4d2013-05-30 00:18:49 -0700503 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_, dex_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700504 const OatFile* FindOpenedOatFileFromOatLocation(const std::string& oat_location)
Ian Rogers1bf8d4d2013-05-30 00:18:49 -0700505 SHARED_LOCKS_REQUIRED(dex_lock_);
Ian Rogerse3359f72013-06-11 15:14:11 -0700506 const DexFile* FindDexFileInOatLocation(const std::string& dex_location,
507 uint32_t dex_location_checksum,
508 const std::string& oat_location)
509 EXCLUSIVE_LOCKS_REQUIRED(dex_lock_)
510 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
511
Brian Carlstromafe25512012-06-27 17:02:58 -0700512 const DexFile* VerifyAndOpenDexFileFromOatFile(const OatFile* oat_file,
513 const std::string& dex_location,
514 uint32_t dex_location_checksum)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700515 EXCLUSIVE_LOCKS_REQUIRED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700516 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromfad71432011-10-16 20:25:10 -0700517
Brian Carlstromea46f952013-07-30 01:26:50 -0700518 mirror::ArtMethod* CreateProxyConstructor(Thread* self, SirtRef<mirror::Class>& klass,
519 mirror::Class* proxy_class)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700520 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromea46f952013-07-30 01:26:50 -0700521 mirror::ArtMethod* CreateProxyMethod(Thread* self, SirtRef<mirror::Class>& klass,
522 SirtRef<mirror::ArtMethod>& prototype)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700523 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jesse Wilson95caa792011-10-12 18:14:17 -0400524
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700525 std::vector<const DexFile*> boot_class_path_;
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700526
Ian Rogers1bf8d4d2013-05-30 00:18:49 -0700527 mutable ReaderWriterMutex dex_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800528 std::vector<mirror::DexCache*> dex_caches_ GUARDED_BY(dex_lock_);
Elliott Hughesf8349362012-06-18 15:00:06 -0700529 std::vector<const OatFile*> oat_files_ GUARDED_BY(dex_lock_);
Brian Carlstrom47d237a2011-10-18 15:08:33 -0700530
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700531
Brian Carlstromaded5f72011-10-07 17:15:04 -0700532 // multimap from a string hash code of a class descriptor to
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800533 // mirror::Class* instances. Results should be compared for a matching
Brian Carlstrom9cff8e12011-08-18 16:47:29 -0700534 // Class::descriptor_ and Class::class_loader_.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800535 typedef std::multimap<size_t, mirror::Class*> Table;
536 Table image_classes_ GUARDED_BY(Locks::classlinker_classes_lock_);
Ian Rogersb726dcb2012-09-05 08:57:23 -0700537 Table classes_ GUARDED_BY(Locks::classlinker_classes_lock_);
Elliott Hughesf8349362012-06-18 15:00:06 -0700538
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800539 mirror::Class* LookupClassLocked(const char* descriptor, const mirror::ClassLoader* class_loader,
540 size_t hash, const Table& classes)
Ian Rogers1bf8d4d2013-05-30 00:18:49 -0700541 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_, Locks::classlinker_classes_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700542
Brian Carlstroma663ea52011-08-19 23:33:41 -0700543 // indexes into class_roots_.
544 // needs to be kept in sync with class_roots_descriptors_.
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700545 enum ClassRoot {
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700546 kJavaLangClass,
547 kJavaLangObject,
Elliott Hughes418d20f2011-09-22 14:00:39 -0700548 kClassArrayClass,
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700549 kObjectArrayClass,
550 kJavaLangString,
Mathieu Chartier66f19252012-09-18 08:57:04 -0700551 kJavaLangDexCache,
Elliott Hughesbf61ba32011-10-11 10:53:09 -0700552 kJavaLangRefReference,
Brian Carlstromea46f952013-07-30 01:26:50 -0700553 kJavaLangReflectArtField,
554 kJavaLangReflectArtMethod,
Ian Rogers466bb252011-10-14 03:29:56 -0700555 kJavaLangReflectProxy,
Mathieu Chartier66f19252012-09-18 08:57:04 -0700556 kJavaLangStringArrayClass,
Brian Carlstromea46f952013-07-30 01:26:50 -0700557 kJavaLangReflectArtFieldArrayClass,
558 kJavaLangReflectArtMethodArrayClass,
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700559 kJavaLangClassLoader,
Ian Rogers5167c972012-02-03 10:41:20 -0800560 kJavaLangThrowable,
jeffhao8cd6dda2012-02-22 10:15:34 -0800561 kJavaLangClassNotFoundException,
Shih-wei Liao55df06b2011-08-26 14:39:27 -0700562 kJavaLangStackTraceElement,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700563 kPrimitiveBoolean,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700564 kPrimitiveByte,
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700565 kPrimitiveChar,
566 kPrimitiveDouble,
567 kPrimitiveFloat,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700568 kPrimitiveInt,
569 kPrimitiveLong,
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700570 kPrimitiveShort,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700571 kPrimitiveVoid,
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700572 kBooleanArrayClass,
573 kByteArrayClass,
574 kCharArrayClass,
575 kDoubleArrayClass,
576 kFloatArrayClass,
577 kIntArrayClass,
578 kLongArrayClass,
579 kShortArrayClass,
Shih-wei Liao55df06b2011-08-26 14:39:27 -0700580 kJavaLangStackTraceElementArrayClass,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700581 kClassRootsMax,
582 };
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800583 mirror::ObjectArray<mirror::Class>* class_roots_;
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700584
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800585 mirror::Class* GetClassRoot(ClassRoot class_root) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700586
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800587 void SetClassRoot(ClassRoot class_root, mirror::Class* klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700588 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstroma663ea52011-08-19 23:33:41 -0700589
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800590 mirror::ObjectArray<mirror::Class>* GetClassRoots() {
Brian Carlstrom34f426c2011-10-04 12:58:02 -0700591 DCHECK(class_roots_ != NULL);
592 return class_roots_;
593 }
594
Elliott Hughes418d20f2011-09-22 14:00:39 -0700595 static const char* class_roots_descriptors_[];
Brian Carlstroma663ea52011-08-19 23:33:41 -0700596
597 const char* GetClassRootDescriptor(ClassRoot class_root) {
598 const char* descriptor = class_roots_descriptors_[class_root];
599 CHECK(descriptor != NULL);
600 return descriptor;
601 }
602
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800603 mirror::IfTable* array_iftable_;
Carl Shapiro565f5072011-07-10 13:39:43 -0700604
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700605 bool init_done_;
Mathieu Chartier9ebae1f2012-10-15 17:38:16 -0700606 bool is_dirty_;
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700607
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700608 InternTable* intern_table_;
609
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700610 const void* portable_resolution_trampoline_;
611 const void* quick_resolution_trampoline_;
612
Brian Carlstrom34f426c2011-10-04 12:58:02 -0700613 friend class ImageWriter; // for GetClassRoots
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800614 FRIEND_TEST(ClassLinkerTest, ClassRootDescriptors);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800615 FRIEND_TEST(mirror::DexCacheTest, Open);
Brian Carlstromae826982011-11-09 01:33:42 -0800616 FRIEND_TEST(ExceptionTest, FindExceptionHandler);
617 FRIEND_TEST(ObjectTest, AllocObjectArray);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700618 DISALLOW_COPY_AND_ASSIGN(ClassLinker);
619};
620
621} // namespace art
622
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700623#endif // ART_RUNTIME_CLASS_LINKER_H_