blob: 88dbb9c44e7b4026bcca537e0fa6360e17cffe3e [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"
Mathieu Chartier590fee92013-09-13 13:46:47 -070028#include "jni.h"
Brian Carlstrom58ae9412011-10-04 00:56:06 -070029#include "oat_file.h"
Mathieu Chartier83c8ee02014-01-28 14:50:23 -080030#include "object_callbacks.h"
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070031
32namespace art {
Ian Rogers1d54e732013-05-02 21:10:01 -070033namespace gc {
34namespace space {
35 class ImageSpace;
36} // namespace space
37} // namespace gc
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080038namespace mirror {
Ian Rogers33e95662013-05-20 20:29:14 -070039 class ClassLoader;
40 class DexCache;
41 class DexCacheTest_Open_Test;
42 class IfTable;
43 template<class T> class ObjectArray;
44 class StackTraceElement;
45} // namespace mirror
Ian Rogers1d54e732013-05-02 21:10:01 -070046
Elliott Hughescf4c6c42011-09-01 15:16:42 -070047class InternTable;
Mathieu Chartierc528dba2013-11-26 12:00:11 -080048template<class T> class ObjectLock;
Mathieu Chartier590fee92013-09-13 13:46:47 -070049class ScopedObjectAccess;
Ian Rogers1f539342012-10-03 21:09:42 -070050template<class T> class SirtRef;
Elliott Hughescf4c6c42011-09-01 15:16:42 -070051
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080052typedef bool (ClassVisitor)(mirror::Class* c, void* arg);
Elliott Hughesa2155262011-11-16 16:26:58 -080053
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070054class ClassLinker {
55 public:
Jeff Hao88474b42013-10-23 16:24:40 -070056 // Interface method table size. Increasing this value reduces the chance of two interface methods
57 // colliding in the interface method table but increases the size of classes that implement
58 // (non-marker) interfaces.
59 static constexpr size_t kImtSize = 64;
60
Mathieu Chartier590fee92013-09-13 13:46:47 -070061 explicit ClassLinker(InternTable* intern_table);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070062 ~ClassLinker();
Carl Shapiro565f5072011-07-10 13:39:43 -070063
Mathieu Chartier590fee92013-09-13 13:46:47 -070064 // Initialize class linker by bootstraping from dex files
65 void InitFromCompiler(const std::vector<const DexFile*>& boot_class_path)
66 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
67
68 // Initialize class linker from one or more images.
69 void InitFromImage() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
70
Ian Rogersbe7149f2013-08-20 09:29:39 -070071 bool IsInBootClassPath(const char* descriptor);
72
Elliott Hughes64bf5a32011-09-20 14:43:12 -070073 // Finds a class by its descriptor, loading it if necessary.
Brian Carlstrom74eb46a2011-08-02 20:10:14 -070074 // If class_loader is null, searches boot_class_path_.
Ian Rogers98379392014-02-24 16:53:16 -080075 mirror::Class* FindClass(Thread* self, const char* descriptor,
76 const SirtRef<mirror::ClassLoader>& class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -070077 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromaded5f72011-10-07 17:15:04 -070078
Ian Rogers98379392014-02-24 16:53:16 -080079 // Finds a class by its descriptor using the "system" class loader, ie by searching the
80 // boot_class_path_.
81 mirror::Class* FindSystemClass(Thread* self, const char* descriptor)
82 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
83
84 // Finds the array class given for the element class.
85 mirror::Class* FindArrayClass(Thread* self, mirror::Class* element_class)
Ian Rogersb726dcb2012-09-05 08:57:23 -070086 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromaded5f72011-10-07 17:15:04 -070087
Mathieu Chartier590fee92013-09-13 13:46:47 -070088 // Reutrns true if the class linker is initialized.
89 bool IsInitialized() const;
90
Brian Carlstromaded5f72011-10-07 17:15:04 -070091 // Define a new a class based on a ClassDef from a DexFile
Mathieu Chartierc528dba2013-11-26 12:00:11 -080092 mirror::Class* DefineClass(const char* descriptor,
93 const SirtRef<mirror::ClassLoader>& class_loader,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080094 const DexFile& dex_file, const DexFile::ClassDef& dex_class_def)
Ian Rogersb726dcb2012-09-05 08:57:23 -070095 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes64bf5a32011-09-20 14:43:12 -070096
97 // Finds a class by its descriptor, returning NULL if it isn't wasn't loaded
98 // by the given 'class_loader'.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080099 mirror::Class* LookupClass(const char* descriptor, const mirror::ClassLoader* class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700100 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
101 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700102
Elliott Hughes6fa602d2011-12-02 17:54:25 -0800103 // Finds all the classes with the given descriptor, regardless of ClassLoader.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800104 void LookupClasses(const char* descriptor, std::vector<mirror::Class*>& classes)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700105 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
106 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes6fa602d2011-12-02 17:54:25 -0800107
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800108 mirror::Class* FindPrimitiveClass(char type) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700109
Brian Carlstromae826982011-11-09 01:33:42 -0800110 // General class unloading is not supported, this is used to prune
111 // unwanted classes during image writing.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800112 bool RemoveClass(const char* descriptor, const mirror::ClassLoader* class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700113 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
114 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromae826982011-11-09 01:33:42 -0800115
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700116 void DumpAllClasses(int flags)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700117 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
118 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes9d5ccec2011-09-19 13:19:50 -0700119
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700120 void DumpForSigQuit(std::ostream& os)
121 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
122 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughescac6cc72011-11-03 20:31:21 -0700123
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700124 size_t NumLoadedClasses()
125 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
126 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughese27955c2011-08-26 15:21:24 -0700127
Brian Carlstromb63ec392011-08-27 17:38:27 -0700128 // Resolve a String with the given index from the DexFile, storing the
Brian Carlstromaded5f72011-10-07 17:15:04 -0700129 // result in the DexCache. The referrer is used to identify the
130 // target DexCache and ClassLoader to use for resolution.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800131 mirror::String* ResolveString(uint32_t string_idx, mirror::ArtMethod* referrer)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800132 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromaded5f72011-10-07 17:15:04 -0700133
134 // Resolve a String with the given index from the DexFile, storing the
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700135 // result in the DexCache.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800136 mirror::String* ResolveString(const DexFile& dex_file, uint32_t string_idx,
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800137 const SirtRef<mirror::DexCache>& dex_cache)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700138 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700139
Brian Carlstromb63ec392011-08-27 17:38:27 -0700140 // Resolve a Type with the given index from the DexFile, storing the
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700141 // result in the DexCache. The referrer is used to identity the
142 // target DexCache and ClassLoader to use for resolution.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800143 mirror::Class* ResolveType(const DexFile& dex_file, uint16_t type_idx, mirror::Class* referrer)
Mathieu Chartier590fee92013-09-13 13:46:47 -0700144 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700145
Brian Carlstromb63ec392011-08-27 17:38:27 -0700146 // Resolve a Type with the given index from the DexFile, storing the
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700147 // result in the DexCache. The referrer is used to identify the
Brian Carlstromb63ec392011-08-27 17:38:27 -0700148 // target DexCache and ClassLoader to use for resolution.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800149 mirror::Class* ResolveType(uint16_t type_idx, mirror::ArtMethod* referrer)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800150 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700151
Ian Rogersef7d42f2014-01-06 12:55:46 -0800152 mirror::Class* ResolveType(uint16_t type_idx, mirror::ArtField* referrer)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800153 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromb63ec392011-08-27 17:38:27 -0700154
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700155 // Resolve a type with the given ID from the DexFile, storing the
156 // result in DexCache. The ClassLoader is used to search for the
157 // type, since it may be referenced from but not contained within
158 // the given DexFile.
Mathieu Chartier590fee92013-09-13 13:46:47 -0700159 mirror::Class* ResolveType(const DexFile& dex_file, uint16_t type_idx,
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800160 const SirtRef<mirror::DexCache>& dex_cache,
161 const SirtRef<mirror::ClassLoader>& class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700162 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700163
164 // Resolve a method with a given ID from the DexFile, storing the
165 // result in DexCache. The ClassLinker and ClassLoader are used as
166 // in ResolveType. What is unique is the method type argument which
167 // is used to determine if this method is a direct, static, or
168 // virtual method.
Brian Carlstromea46f952013-07-30 01:26:50 -0700169 mirror::ArtMethod* ResolveMethod(const DexFile& dex_file,
170 uint32_t method_idx,
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800171 const SirtRef<mirror::DexCache>& dex_cache,
172 const SirtRef<mirror::ClassLoader>& class_loader,
Ian Rogersef7d42f2014-01-06 12:55:46 -0800173 mirror::ArtMethod* referrer,
Brian Carlstromea46f952013-07-30 01:26:50 -0700174 InvokeType type)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700175 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700176
Ian Rogersef7d42f2014-01-06 12:55:46 -0800177 mirror::ArtMethod* ResolveMethod(uint32_t method_idx, mirror::ArtMethod* referrer,
Brian Carlstromea46f952013-07-30 01:26:50 -0700178 InvokeType type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800179 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom16192862011-09-12 17:50:06 -0700180
Ian Rogersef7d42f2014-01-06 12:55:46 -0800181 mirror::ArtField* ResolveField(uint32_t field_idx, mirror::ArtMethod* referrer,
Brian Carlstromea46f952013-07-30 01:26:50 -0700182 bool is_static)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800183 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromb9edb842011-08-28 16:31:06 -0700184
Brian Carlstrom16192862011-09-12 17:50:06 -0700185 // Resolve a field with a given ID from the DexFile, storing the
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700186 // result in DexCache. The ClassLinker and ClassLoader are used as
187 // in ResolveType. What is unique is the is_static argument which is
188 // used to determine if we are resolving a static or non-static
189 // field.
Brian Carlstromea46f952013-07-30 01:26:50 -0700190 mirror::ArtField* ResolveField(const DexFile& dex_file,
191 uint32_t field_idx,
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800192 const SirtRef<mirror::DexCache>& dex_cache,
193 const SirtRef<mirror::ClassLoader>& class_loader,
Brian Carlstromea46f952013-07-30 01:26:50 -0700194 bool is_static)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700195 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700196
Ian Rogersb067ac22011-12-13 18:05:09 -0800197 // Resolve a field with a given ID from the DexFile, storing the
198 // result in DexCache. The ClassLinker and ClassLoader are used as
199 // in ResolveType. No is_static argument is provided so that Java
200 // field resolution semantics are followed.
Brian Carlstromea46f952013-07-30 01:26:50 -0700201 mirror::ArtField* ResolveFieldJLS(const DexFile& dex_file,
202 uint32_t field_idx,
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800203 const SirtRef<mirror::DexCache>& dex_cache,
204 const SirtRef<mirror::ClassLoader>& class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700205 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersb067ac22011-12-13 18:05:09 -0800206
Ian Rogersad25ac52011-10-04 19:13:33 -0700207 // Get shorty from method index without resolution. Used to do handlerization.
Brian Carlstromea46f952013-07-30 01:26:50 -0700208 const char* MethodShorty(uint32_t method_idx, mirror::ArtMethod* referrer, uint32_t* length)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700209 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersad25ac52011-10-04 19:13:33 -0700210
Elliott Hughesf4c21c92011-08-19 17:31:31 -0700211 // Returns true on success, false if there's an exception pending.
Brian Carlstrom25c33252011-09-18 15:58:35 -0700212 // can_run_clinit=false allows the compiler to attempt to init a class,
213 // given the restriction that no <clinit> execution is possible.
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800214 bool EnsureInitialized(const SirtRef<mirror::Class>& c,
215 bool can_init_fields, bool can_init_parents)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700216 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700217
Elliott Hughes2a20cfd2011-09-23 19:30:41 -0700218 // Initializes classes that have instances in the image but that have
219 // <clinit> methods so they could not be initialized by the compiler.
Ian Rogersb726dcb2012-09-05 08:57:23 -0700220 void RunRootClinits() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes2a20cfd2011-09-23 19:30:41 -0700221
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700222 void RegisterDexFile(const DexFile& dex_file)
223 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700224 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800225 void RegisterDexFile(const DexFile& dex_file, const SirtRef<mirror::DexCache>& dex_cache)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700226 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700227 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700228
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700229 const OatFile* RegisterOatFile(const OatFile* oat_file)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700230 LOCKS_EXCLUDED(dex_lock_);
Brian Carlstrom866c8622012-01-06 16:35:13 -0800231
Brian Carlstrom8a487412011-08-29 20:08:52 -0700232 const std::vector<const DexFile*>& GetBootClassPath() {
233 return boot_class_path_;
234 }
235
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700236 void VisitClasses(ClassVisitor* visitor, void* arg)
237 LOCKS_EXCLUDED(dex_lock_)
238 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700239 // Less efficient variant of VisitClasses that doesn't hold the classlinker_classes_lock_
240 // when calling the visitor.
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700241 void VisitClassesWithoutClassesLock(ClassVisitor* visitor, void* arg)
242 LOCKS_EXCLUDED(dex_lock_)
243 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesa2155262011-11-16 16:26:58 -0800244
Mathieu Chartier83c8ee02014-01-28 14:50:23 -0800245 void VisitRoots(RootCallback* callback, void* arg, bool only_dirty, bool clean_dirty)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700246 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_, dex_lock_);
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700247
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800248 mirror::DexCache* FindDexCache(const DexFile& dex_file) const
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700249 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700250 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700251 bool IsDexFileRegistered(const DexFile& dex_file) const
252 LOCKS_EXCLUDED(dex_lock_);
Brian Carlstromea46f952013-07-30 01:26:50 -0700253 void FixupDexCaches(mirror::ArtMethod* resolution_method) const
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700254 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700255 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom1d9f52b2011-10-13 10:50:45 -0700256
jeffhao262bf462011-10-20 18:36:32 -0700257 // Generate an oat file from a dex file
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700258 bool GenerateOatFile(const char* dex_filename,
Brian Carlstromd601af82012-01-06 10:15:19 -0800259 int oat_fd,
Vladimir Marko60836d52014-01-16 15:53:38 +0000260 const char* oat_cache_filename,
261 std::string* error_msg);
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700262 LOCKS_EXCLUDED(Locks::mutator_lock_);
jeffhao262bf462011-10-20 18:36:32 -0700263
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700264 const OatFile* FindOatFileFromOatLocation(const std::string& location,
265 std::string* error_msg)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700266 LOCKS_EXCLUDED(dex_lock_);
267
Brian Carlstrom5b332c82012-02-01 15:02:31 -0800268 // Finds the oat file for a dex location, generating the oat file if
269 // it is missing or out of date. Returns the DexFile from within the
270 // created oat file.
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700271 const DexFile* FindOrCreateOatFileForDexLocation(const char* dex_location,
Brian Carlstrom756ee4e2013-10-03 15:46:12 -0700272 uint32_t dex_location_checksum,
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700273 const char* oat_location,
274 std::string* error_msg)
275 LOCKS_EXCLUDED(dex_lock_, Locks::mutator_lock_);
Brian Carlstrom5b332c82012-02-01 15:02:31 -0800276 // Find a DexFile within an OatFile given a DexFile location. Note
277 // that this returns null if the location checksum of the DexFile
278 // does not match the OatFile.
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700279 const DexFile* FindDexFileInOatFileFromDexLocation(const char* location,
Brian Carlstrom08cbf662013-12-10 16:52:57 -0800280 const uint32_t* const location_checksum,
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700281 std::string* error_msg)
282 LOCKS_EXCLUDED(dex_lock_, Locks::mutator_lock_);
Brian Carlstrom5b332c82012-02-01 15:02:31 -0800283
jeffhaof6174e82012-01-31 16:14:17 -0800284
Brian Carlstrom28db0122012-10-18 16:20:41 -0700285 // Returns true if oat file contains the dex file with the given location and checksum.
Brian Carlstromafe25512012-06-27 17:02:58 -0700286 static bool VerifyOatFileChecksums(const OatFile* oat_file,
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700287 const char* dex_location,
288 uint32_t dex_location_checksum,
289 std::string* error_msg);
Brian Carlstromafe25512012-06-27 17:02:58 -0700290
Elliott Hughes418d20f2011-09-22 14:00:39 -0700291 // TODO: replace this with multiple methods that allocate the correct managed type.
Shih-wei Liao44175362011-08-28 16:59:17 -0700292 template <class T>
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800293 mirror::ObjectArray<T>* AllocObjectArray(Thread* self, size_t length)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700294 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Shih-wei Liao55df06b2011-08-26 14:39:27 -0700295
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800296 mirror::ObjectArray<mirror::Class>* AllocClassArray(Thread* self, size_t length)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700297 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
jeffhao98eacac2011-09-14 16:11:53 -0700298
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800299 mirror::ObjectArray<mirror::String>* AllocStringArray(Thread* self, size_t length)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700300 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800301
Brian Carlstromea46f952013-07-30 01:26:50 -0700302 mirror::ObjectArray<mirror::ArtMethod>* AllocArtMethodArray(Thread* self, size_t length)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800303 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
304
305 mirror::IfTable* AllocIfTable(Thread* self, size_t ifcount)
306 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
307
Brian Carlstromea46f952013-07-30 01:26:50 -0700308 mirror::ObjectArray<mirror::ArtField>* AllocArtFieldArray(Thread* self, size_t length)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800309 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
310
311 mirror::ObjectArray<mirror::StackTraceElement>* AllocStackTraceElementArray(Thread* self,
312 size_t length)
313 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
314
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800315 void VerifyClass(const SirtRef<mirror::Class>& klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800316 bool VerifyClassUsingOatFile(const DexFile& dex_file, mirror::Class* klass,
317 mirror::Class::Status& oat_file_class_status)
318 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800319 void ResolveClassExceptionHandlerTypes(const DexFile& dex_file,
320 const SirtRef<mirror::Class>& klass)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800321 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromea46f952013-07-30 01:26:50 -0700322 void ResolveMethodExceptionHandlerTypes(const DexFile& dex_file, mirror::ArtMethod* klass)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800323 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
324
Mathieu Chartier590fee92013-09-13 13:46:47 -0700325 mirror::Class* CreateProxyClass(ScopedObjectAccess& soa, jstring name, jobjectArray interfaces,
326 jobject loader, jobjectArray methods, jobjectArray throws)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800327 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800328 std::string GetDescriptorForProxy(mirror::Class* proxy_class)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800329 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800330 mirror::ArtMethod* FindMethodForProxy(mirror::Class* proxy_class,
331 mirror::ArtMethod* proxy_method)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700332 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700333 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jesse Wilson95caa792011-10-12 18:14:17 -0400334
Ian Rogers19846512012-02-24 11:42:47 -0800335 // Get the oat code for a method when its class isn't yet initialized
Ian Rogersef7d42f2014-01-06 12:55:46 -0800336 const void* GetQuickOatCodeFor(mirror::ArtMethod* method)
337 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
338 const void* GetPortableOatCodeFor(mirror::ArtMethod* method, bool* have_portable_code)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700339 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers19846512012-02-24 11:42:47 -0800340
Mathieu Chartiere35517a2012-10-30 18:49:55 -0700341 // Get the oat code for a method from a method index.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800342 const void* GetQuickOatCodeFor(const DexFile& dex_file, uint16_t class_def_idx, uint32_t method_idx)
343 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
344 const void* GetPortableOatCodeFor(const DexFile& dex_file, uint16_t class_def_idx, uint32_t method_idx)
Ian Rogers33e95662013-05-20 20:29:14 -0700345 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartiere35517a2012-10-30 18:49:55 -0700346
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700347 pid_t GetClassesLockOwner(); // For SignalCatcher.
348 pid_t GetDexLockOwner(); // For SignalCatcher.
Brian Carlstrom24a3c2e2011-10-17 18:07:52 -0700349
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700350 const void* GetPortableResolutionTrampoline() const {
351 return portable_resolution_trampoline_;
352 }
353
354 const void* GetQuickResolutionTrampoline() const {
355 return quick_resolution_trampoline_;
356 }
357
Jeff Hao88474b42013-10-23 16:24:40 -0700358 const void* GetPortableImtConflictTrampoline() const {
359 return portable_imt_conflict_trampoline_;
360 }
361
362 const void* GetQuickImtConflictTrampoline() const {
363 return quick_imt_conflict_trampoline_;
364 }
365
366 InternTable* GetInternTable() const {
367 return intern_table_;
368 }
369
Ian Rogers848871b2013-08-05 10:56:33 -0700370 // Attempts to insert a class into a class table. Returns NULL if
371 // the class was inserted, otherwise returns an existing class with
372 // the same descriptor and ClassLoader.
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700373 mirror::Class* InsertClass(const char* descriptor, mirror::Class* klass, size_t hash)
Ian Rogers848871b2013-08-05 10:56:33 -0700374 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
375 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
376
Mathieu Chartier590fee92013-09-13 13:46:47 -0700377 // Special code to allocate an art method, use this instead of class->AllocObject.
378 mirror::ArtMethod* AllocArtMethod(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro61e019d2011-07-14 16:53:09 -0700379
Mathieu Chartier590fee92013-09-13 13:46:47 -0700380 private:
Ian Rogersef7d42f2014-01-06 12:55:46 -0800381 const OatFile::OatMethod GetOatMethodFor(mirror::ArtMethod* method)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700382 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
TDYa12785321912012-04-01 15:24:56 -0700383
Brian Carlstrom56d947f2013-07-15 13:14:23 -0700384 OatFile& GetImageOatFile(gc::space::ImageSpace* space)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700385 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700386 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstroma663ea52011-08-19 23:33:41 -0700387
Ian Rogers98379392014-02-24 16:53:16 -0800388 void FinishInit(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstroma663ea52011-08-19 23:33:41 -0700389
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700390 // For early bootstrapping by Init
Ian Rogers6fac4472014-02-25 17:01:10 -0800391 mirror::Class* AllocClass(Thread* self, mirror::Class* java_lang_Class, uint32_t class_size)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700392 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700393
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800394 // Alloc* convenience functions to avoid needing to pass in mirror::Class*
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700395 // values that are known to the ClassLinker such as
396 // kObjectArrayClass and kJavaLangString etc.
Ian Rogers6fac4472014-02-25 17:01:10 -0800397 mirror::Class* AllocClass(Thread* self, uint32_t class_size)
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800398 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800399 mirror::DexCache* AllocDexCache(Thread* self, const DexFile& dex_file)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700400 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromea46f952013-07-30 01:26:50 -0700401 mirror::ArtField* AllocArtField(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersbdb03912011-09-14 00:55:44 -0700402
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800403 mirror::Class* CreatePrimitiveClass(Thread* self, Primitive::Type type)
404 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
405 mirror::Class* InitializePrimitiveClass(mirror::Class* primitive_class, Primitive::Type type)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700406 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom5b8e4c82011-09-18 01:38:59 -0700407
Brian Carlstroma331b3c2011-07-18 17:47:56 -0700408
Ian Rogers98379392014-02-24 16:53:16 -0800409 mirror::Class* CreateArrayClass(Thread* self, const char* descriptor,
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800410 const SirtRef<mirror::ClassLoader>& class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700411 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstroma331b3c2011-07-18 17:47:56 -0700412
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700413 void AppendToBootClassPath(const DexFile& dex_file)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700414 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800415 void AppendToBootClassPath(const DexFile& dex_file, const SirtRef<mirror::DexCache>& dex_cache)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700416 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700417
Elliott Hughes5fe594f2011-09-08 12:33:17 -0700418 void ConstructFieldMap(const DexFile& dex_file, const DexFile::ClassDef& dex_class_def,
Brian Carlstromea46f952013-07-30 01:26:50 -0700419 mirror::Class* c, SafeMap<uint32_t, mirror::ArtField*>& field_map)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700420 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes5fe594f2011-09-08 12:33:17 -0700421
Ian Rogers6fac4472014-02-25 17:01:10 -0800422 uint32_t SizeOfClass(const DexFile& dex_file,
Brian Carlstrom4873d462011-08-21 15:23:39 -0700423 const DexFile::ClassDef& dex_class_def);
424
Brian Carlstromf615a612011-07-23 12:50:34 -0700425 void LoadClass(const DexFile& dex_file,
426 const DexFile::ClassDef& dex_class_def,
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800427 const SirtRef<mirror::Class>& klass,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800428 mirror::ClassLoader* class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700429 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700430
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800431 void LoadField(const DexFile& dex_file, const ClassDataItemIterator& it,
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800432 const SirtRef<mirror::Class>& klass, const SirtRef<mirror::ArtField>& dst)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800433 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700434
Brian Carlstromea46f952013-07-30 01:26:50 -0700435 mirror::ArtMethod* LoadMethod(Thread* self, const DexFile& dex_file,
436 const ClassDataItemIterator& dex_method,
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800437 const SirtRef<mirror::Class>& klass)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800438 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom934486c2011-07-12 23:42:50 -0700439
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800440 void FixupStaticTrampolines(mirror::Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers19846512012-02-24 11:42:47 -0800441
442 // Finds the associated oat class for a dex_file and descriptor
Ian Rogersee39a102013-09-19 02:56:49 -0700443 const OatFile::OatClass* GetOatClass(const DexFile& dex_file, uint16_t class_def_idx)
Ian Rogers33e95662013-05-20 20:29:14 -0700444 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers19846512012-02-24 11:42:47 -0800445
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800446 void RegisterDexFileLocked(const DexFile& dex_file, const SirtRef<mirror::DexCache>& dex_cache)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700447 EXCLUSIVE_LOCKS_REQUIRED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700448 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers1bf8d4d2013-05-30 00:18:49 -0700449 bool IsDexFileRegisteredLocked(const DexFile& dex_file) const SHARED_LOCKS_REQUIRED(dex_lock_);
Brian Carlstromaded5f72011-10-07 17:15:04 -0700450
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800451 bool InitializeClass(const SirtRef<mirror::Class>& klass, bool can_run_clinit,
452 bool can_init_parents)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700453 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800454 bool WaitForInitializeClass(const SirtRef<mirror::Class>& klass, Thread* self,
455 ObjectLock<mirror::Class>& lock);
456 bool ValidateSuperClassDescriptors(const SirtRef<mirror::Class>& klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700457 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700458
Ian Rogers98379392014-02-24 16:53:16 -0800459 bool IsSameDescriptorInDifferentClassContexts(Thread* self, const char* descriptor,
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800460 SirtRef<mirror::ClassLoader>& class_loader1,
461 SirtRef<mirror::ClassLoader>& class_loader2)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700462 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700463
Ian Rogers98379392014-02-24 16:53:16 -0800464 bool IsSameMethodSignatureInDifferentClassContexts(Thread* self, mirror::ArtMethod* method,
Ian Rogersef7d42f2014-01-06 12:55:46 -0800465 mirror::Class* klass1,
466 mirror::Class* klass2)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700467 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700468
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800469 bool LinkClass(Thread* self, const SirtRef<mirror::Class>& klass,
470 const SirtRef<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
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800473 bool LinkSuperClass(const 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
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800476 bool LoadSuperAndInterfaces(const SirtRef<mirror::Class>& klass, const DexFile& dex_file)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700477 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700478
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800479 bool LinkMethods(const SirtRef<mirror::Class>& klass,
480 const SirtRef<mirror::ObjectArray<mirror::Class> >& interfaces)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700481 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700482
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800483 bool LinkVirtualMethods(const SirtRef<mirror::Class>& klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700484 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700485
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800486 bool LinkInterfaceMethods(const SirtRef<mirror::Class>& klass,
487 const SirtRef<mirror::ObjectArray<mirror::Class> >& interfaces)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700488 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700489
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800490 bool LinkStaticFields(const SirtRef<mirror::Class>& klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700491 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800492 bool LinkInstanceFields(const SirtRef<mirror::Class>& klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700493 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800494 bool LinkFields(const SirtRef<mirror::Class>& klass, bool is_static)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700495 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700496
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700497
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800498 void CreateReferenceInstanceOffsets(const SirtRef<mirror::Class>& klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700499 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800500 void CreateReferenceStaticOffsets(const SirtRef<mirror::Class>& klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700501 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800502 void CreateReferenceOffsets(const SirtRef<mirror::Class>& klass, bool is_static,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700503 uint32_t reference_offsets)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700504 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700505
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700506 // For use by ImageWriter to find DexCaches for its roots
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800507 const std::vector<mirror::DexCache*>& GetDexCaches() {
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700508 return dex_caches_;
509 }
510
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700511 const OatFile* FindOpenedOatFileForDexFile(const DexFile& dex_file)
Ian Rogers33e95662013-05-20 20:29:14 -0700512 LOCKS_EXCLUDED(dex_lock_)
513 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700514 const OatFile* FindOpenedOatFileFromDexLocation(const char* dex_location,
Brian Carlstrom08cbf662013-12-10 16:52:57 -0800515 const uint32_t* const dex_location_checksum)
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700516 LOCKS_EXCLUDED(dex_lock);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700517 const OatFile* FindOpenedOatFileFromOatLocation(const std::string& oat_location)
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700518 LOCKS_EXCLUDED(dex_lock_);
519 const DexFile* FindDexFileInOatLocation(const char* dex_location,
Ian Rogerse3359f72013-06-11 15:14:11 -0700520 uint32_t dex_location_checksum,
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700521 const char* oat_location,
522 std::string* error_msg)
523 LOCKS_EXCLUDED(dex_lock_);
Ian Rogerse3359f72013-06-11 15:14:11 -0700524
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700525 const DexFile* VerifyAndOpenDexFileFromOatFile(const std::string& oat_file_location,
526 const char* dex_location,
527 std::string* error_msg,
528 bool* open_failed)
529 LOCKS_EXCLUDED(dex_lock_);
Brian Carlstromfad71432011-10-16 20:25:10 -0700530
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800531 mirror::ArtMethod* CreateProxyConstructor(Thread* self, const SirtRef<mirror::Class>& klass,
Brian Carlstromea46f952013-07-30 01:26:50 -0700532 mirror::Class* proxy_class)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700533 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800534 mirror::ArtMethod* CreateProxyMethod(Thread* self, const SirtRef<mirror::Class>& klass,
535 const SirtRef<mirror::ArtMethod>& prototype)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700536 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jesse Wilson95caa792011-10-12 18:14:17 -0400537
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700538 std::vector<const DexFile*> boot_class_path_;
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700539
Ian Rogers1bf8d4d2013-05-30 00:18:49 -0700540 mutable ReaderWriterMutex dex_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800541 std::vector<mirror::DexCache*> dex_caches_ GUARDED_BY(dex_lock_);
Elliott Hughesf8349362012-06-18 15:00:06 -0700542 std::vector<const OatFile*> oat_files_ GUARDED_BY(dex_lock_);
Brian Carlstrom47d237a2011-10-18 15:08:33 -0700543
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700544
Brian Carlstromaded5f72011-10-07 17:15:04 -0700545 // multimap from a string hash code of a class descriptor to
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800546 // mirror::Class* instances. Results should be compared for a matching
Brian Carlstrom9cff8e12011-08-18 16:47:29 -0700547 // Class::descriptor_ and Class::class_loader_.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800548 typedef std::multimap<size_t, mirror::Class*> Table;
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700549 Table class_table_ GUARDED_BY(Locks::classlinker_classes_lock_);
Elliott Hughesf8349362012-06-18 15:00:06 -0700550
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700551 // Do we need to search dex caches to find image classes?
552 bool dex_cache_image_class_lookup_required_;
553 // Number of times we've searched dex caches for a class. After a certain number of misses we move
554 // the classes into the class_table_ to avoid dex cache based searches.
555 AtomicInteger failed_dex_cache_class_lookups_;
556
557 mirror::Class* LookupClassFromTableLocked(const char* descriptor,
558 const mirror::ClassLoader* class_loader,
559 size_t hash)
560 SHARED_LOCKS_REQUIRED(Locks::classlinker_classes_lock_, Locks::mutator_lock_);
561
562 void MoveImageClassesToClassTable() LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
563 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
564 mirror::Class* LookupClassFromImage(const char* descriptor)
565 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700566
Brian Carlstroma663ea52011-08-19 23:33:41 -0700567 // indexes into class_roots_.
568 // needs to be kept in sync with class_roots_descriptors_.
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700569 enum ClassRoot {
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700570 kJavaLangClass,
571 kJavaLangObject,
Elliott Hughes418d20f2011-09-22 14:00:39 -0700572 kClassArrayClass,
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700573 kObjectArrayClass,
574 kJavaLangString,
Mathieu Chartier66f19252012-09-18 08:57:04 -0700575 kJavaLangDexCache,
Elliott Hughesbf61ba32011-10-11 10:53:09 -0700576 kJavaLangRefReference,
Brian Carlstromea46f952013-07-30 01:26:50 -0700577 kJavaLangReflectArtField,
578 kJavaLangReflectArtMethod,
Ian Rogers466bb252011-10-14 03:29:56 -0700579 kJavaLangReflectProxy,
Mathieu Chartier66f19252012-09-18 08:57:04 -0700580 kJavaLangStringArrayClass,
Brian Carlstromea46f952013-07-30 01:26:50 -0700581 kJavaLangReflectArtFieldArrayClass,
582 kJavaLangReflectArtMethodArrayClass,
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700583 kJavaLangClassLoader,
Ian Rogers5167c972012-02-03 10:41:20 -0800584 kJavaLangThrowable,
jeffhao8cd6dda2012-02-22 10:15:34 -0800585 kJavaLangClassNotFoundException,
Shih-wei Liao55df06b2011-08-26 14:39:27 -0700586 kJavaLangStackTraceElement,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700587 kPrimitiveBoolean,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700588 kPrimitiveByte,
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700589 kPrimitiveChar,
590 kPrimitiveDouble,
591 kPrimitiveFloat,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700592 kPrimitiveInt,
593 kPrimitiveLong,
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700594 kPrimitiveShort,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700595 kPrimitiveVoid,
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700596 kBooleanArrayClass,
597 kByteArrayClass,
598 kCharArrayClass,
599 kDoubleArrayClass,
600 kFloatArrayClass,
601 kIntArrayClass,
602 kLongArrayClass,
603 kShortArrayClass,
Shih-wei Liao55df06b2011-08-26 14:39:27 -0700604 kJavaLangStackTraceElementArrayClass,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700605 kClassRootsMax,
606 };
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800607 mirror::ObjectArray<mirror::Class>* class_roots_;
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700608
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800609 mirror::Class* GetClassRoot(ClassRoot class_root) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700610
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800611 void SetClassRoot(ClassRoot class_root, mirror::Class* klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700612 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstroma663ea52011-08-19 23:33:41 -0700613
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800614 mirror::ObjectArray<mirror::Class>* GetClassRoots() {
Brian Carlstrom34f426c2011-10-04 12:58:02 -0700615 DCHECK(class_roots_ != NULL);
616 return class_roots_;
617 }
618
Elliott Hughes418d20f2011-09-22 14:00:39 -0700619 static const char* class_roots_descriptors_[];
Brian Carlstroma663ea52011-08-19 23:33:41 -0700620
621 const char* GetClassRootDescriptor(ClassRoot class_root) {
622 const char* descriptor = class_roots_descriptors_[class_root];
623 CHECK(descriptor != NULL);
624 return descriptor;
625 }
626
Ian Rogers98379392014-02-24 16:53:16 -0800627 // The interface table used by all arrays.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800628 mirror::IfTable* array_iftable_;
Carl Shapiro565f5072011-07-10 13:39:43 -0700629
Ian Rogers98379392014-02-24 16:53:16 -0800630 // A cache of the last FindArrayClass results. The cache serves to avoid creating array class
631 // descriptors for the sake of performing FindClass.
632 static constexpr size_t kFindArrayCacheSize = 16;
633 mirror::Class* find_array_class_cache_[kFindArrayCacheSize];
634 size_t find_array_class_cache_next_victim_;
635
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700636 bool init_done_;
Mathieu Chartierc4621982013-09-16 19:43:47 -0700637 bool dex_caches_dirty_ GUARDED_BY(dex_lock_);
638 bool class_table_dirty_ GUARDED_BY(Locks::classlinker_classes_lock_);
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700639
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700640 InternTable* intern_table_;
641
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700642 const void* portable_resolution_trampoline_;
643 const void* quick_resolution_trampoline_;
Jeff Hao88474b42013-10-23 16:24:40 -0700644 const void* portable_imt_conflict_trampoline_;
645 const void* quick_imt_conflict_trampoline_;
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700646
Brian Carlstrom34f426c2011-10-04 12:58:02 -0700647 friend class ImageWriter; // for GetClassRoots
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800648 FRIEND_TEST(ClassLinkerTest, ClassRootDescriptors);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800649 FRIEND_TEST(mirror::DexCacheTest, Open);
Brian Carlstromae826982011-11-09 01:33:42 -0800650 FRIEND_TEST(ExceptionTest, FindExceptionHandler);
651 FRIEND_TEST(ObjectTest, AllocObjectArray);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700652 DISALLOW_COPY_AND_ASSIGN(ClassLinker);
653};
654
655} // namespace art
656
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700657#endif // ART_RUNTIME_CLASS_LINKER_H_