blob: 05a809e524548234caf803518bee0e07b3679d22 [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
Mathieu Chartierbad02672014-08-25 13:08:22 -070024#include "base/allocator.h"
Mathieu Chartierc2e20622014-11-03 11:41:47 -080025#include "base/hash_set.h"
Elliott Hughes76160052012-12-12 16:31:20 -080026#include "base/macros.h"
Elliott Hughes76b61672012-12-12 17:47:30 -080027#include "base/mutex.h"
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070028#include "dex_file.h"
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -070029#include "gc_root.h"
Mathieu Chartier590fee92013-09-13 13:46:47 -070030#include "jni.h"
Brian Carlstrom58ae9412011-10-04 00:56:06 -070031#include "oat_file.h"
Mathieu Chartier83c8ee02014-01-28 14:50:23 -080032#include "object_callbacks.h"
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070033
34namespace art {
Mingyao Yang98d1cc82014-05-15 17:02:16 -070035
Ian Rogers1d54e732013-05-02 21:10:01 -070036namespace gc {
37namespace space {
38 class ImageSpace;
39} // namespace space
40} // namespace gc
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080041namespace mirror {
Ian Rogers33e95662013-05-20 20:29:14 -070042 class ClassLoader;
43 class DexCache;
Mathieu Chartiere401d142015-04-22 13:56:20 -070044 class DexCachePointerArray;
Ian Rogers33e95662013-05-20 20:29:14 -070045 class DexCacheTest_Open_Test;
46 class IfTable;
47 template<class T> class ObjectArray;
48 class StackTraceElement;
49} // namespace mirror
Ian Rogers1d54e732013-05-02 21:10:01 -070050
Andreas Gampe5a4b8a22014-09-11 08:30:08 -070051template<class T> class Handle;
Hiroshi Yamauchi679b1cf2015-05-21 12:05:27 -070052template<class T> class MutableHandle;
Elliott Hughescf4c6c42011-09-01 15:16:42 -070053class InternTable;
Mathieu Chartierc528dba2013-11-26 12:00:11 -080054template<class T> class ObjectLock;
Andreas Gampe7ba64962014-10-23 11:37:40 -070055class Runtime;
Mathieu Chartier2b7c4d12014-05-19 10:52:16 -070056class ScopedObjectAccessAlreadyRunnable;
Mathieu Chartier2d2621a2014-10-23 16:48:06 -070057template<size_t kNumReferences> class PACKED(4) StackHandleScope;
Elliott Hughescf4c6c42011-09-01 15:16:42 -070058
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080059typedef bool (ClassVisitor)(mirror::Class* c, void* arg);
Elliott Hughesa2155262011-11-16 16:26:58 -080060
Mathieu Chartier893263b2014-03-04 11:07:42 -080061enum VisitRootFlags : uint8_t;
62
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070063class ClassLinker {
64 public:
Ian Rogers6f3dbba2014-10-14 17:41:57 -070065 // Well known mirror::Class roots accessed via GetClassRoot.
66 enum ClassRoot {
67 kJavaLangClass,
68 kJavaLangObject,
69 kClassArrayClass,
70 kObjectArrayClass,
71 kJavaLangString,
72 kJavaLangDexCache,
73 kJavaLangRefReference,
Mathieu Chartierfc58af42015-04-16 18:00:39 -070074 kJavaLangReflectConstructor,
Mathieu Chartierdaaf3262015-03-24 13:30:28 -070075 kJavaLangReflectField,
Mathieu Chartierfc58af42015-04-16 18:00:39 -070076 kJavaLangReflectMethod,
Ian Rogers6f3dbba2014-10-14 17:41:57 -070077 kJavaLangReflectProxy,
78 kJavaLangStringArrayClass,
Mathieu Chartierfc58af42015-04-16 18:00:39 -070079 kJavaLangReflectConstructorArrayClass,
Mathieu Chartierdaaf3262015-03-24 13:30:28 -070080 kJavaLangReflectFieldArrayClass,
Mathieu Chartierfc58af42015-04-16 18:00:39 -070081 kJavaLangReflectMethodArrayClass,
Ian Rogers6f3dbba2014-10-14 17:41:57 -070082 kJavaLangClassLoader,
83 kJavaLangThrowable,
84 kJavaLangClassNotFoundException,
85 kJavaLangStackTraceElement,
86 kPrimitiveBoolean,
87 kPrimitiveByte,
88 kPrimitiveChar,
89 kPrimitiveDouble,
90 kPrimitiveFloat,
91 kPrimitiveInt,
92 kPrimitiveLong,
93 kPrimitiveShort,
94 kPrimitiveVoid,
95 kBooleanArrayClass,
96 kByteArrayClass,
97 kCharArrayClass,
98 kDoubleArrayClass,
99 kFloatArrayClass,
100 kIntArrayClass,
101 kLongArrayClass,
102 kShortArrayClass,
103 kJavaLangStackTraceElementArrayClass,
104 kClassRootsMax,
105 };
106
Mathieu Chartier590fee92013-09-13 13:46:47 -0700107 explicit ClassLinker(InternTable* intern_table);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700108 ~ClassLinker();
Carl Shapiro565f5072011-07-10 13:39:43 -0700109
Alex Light64ad14d2014-08-19 14:23:13 -0700110 // Initialize class linker by bootstraping from dex files.
Richard Uhlerfbef44d2014-12-23 09:48:51 -0800111 void InitWithoutImage(std::vector<std::unique_ptr<const DexFile>> boot_class_path)
Mathieu Chartier90443472015-07-16 20:32:27 -0700112 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!dex_lock_);
Mathieu Chartier590fee92013-09-13 13:46:47 -0700113
114 // Initialize class linker from one or more images.
Mathieu Chartier90443472015-07-16 20:32:27 -0700115 void InitFromImage() SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!dex_lock_);
Mathieu Chartier590fee92013-09-13 13:46:47 -0700116
Elliott Hughes64bf5a32011-09-20 14:43:12 -0700117 // Finds a class by its descriptor, loading it if necessary.
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700118 // If class_loader is null, searches boot_class_path_.
Ian Rogers98379392014-02-24 16:53:16 -0800119 mirror::Class* FindClass(Thread* self, const char* descriptor,
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700120 Handle<mirror::ClassLoader> class_loader)
Mathieu Chartier90443472015-07-16 20:32:27 -0700121 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!dex_lock_);
Brian Carlstromaded5f72011-10-07 17:15:04 -0700122
Andreas Gampef865ea92015-04-13 22:14:19 -0700123 // Finds a class in the path class loader, loading it if necessary without using JNI. Hash
124 // function is supposed to be ComputeModifiedUtf8Hash(descriptor). Returns true if the
125 // class-loader chain could be handled, false otherwise, i.e., a non-supported class-loader
126 // was encountered while walking the parent chain (currently only BootClassLoader and
127 // PathClassLoader are supported).
128 bool FindClassInPathClassLoader(ScopedObjectAccessAlreadyRunnable& soa,
129 Thread* self, const char* descriptor, size_t hash,
130 Handle<mirror::ClassLoader> class_loader,
131 mirror::Class** result)
Mathieu Chartier90443472015-07-16 20:32:27 -0700132 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!dex_lock_);
Mathieu Chartierab0ed822014-09-11 14:21:41 -0700133
Ian Rogers98379392014-02-24 16:53:16 -0800134 // Finds a class by its descriptor using the "system" class loader, ie by searching the
135 // boot_class_path_.
136 mirror::Class* FindSystemClass(Thread* self, const char* descriptor)
Mathieu Chartier90443472015-07-16 20:32:27 -0700137 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!dex_lock_);
Ian Rogers98379392014-02-24 16:53:16 -0800138
139 // Finds the array class given for the element class.
Mathieu Chartierb74cd292014-05-29 14:31:33 -0700140 mirror::Class* FindArrayClass(Thread* self, mirror::Class** element_class)
Mathieu Chartier90443472015-07-16 20:32:27 -0700141 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!dex_lock_);
Brian Carlstromaded5f72011-10-07 17:15:04 -0700142
Ian Rogers63557452014-06-04 16:57:15 -0700143 // Returns true if the class linker is initialized.
Ian Rogers7b078e82014-09-10 14:44:24 -0700144 bool IsInitialized() const {
145 return init_done_;
146 }
Mathieu Chartier590fee92013-09-13 13:46:47 -0700147
Brian Carlstromaded5f72011-10-07 17:15:04 -0700148 // Define a new a class based on a ClassDef from a DexFile
Mathieu Chartiere7c9a8c2014-11-06 16:35:45 -0800149 mirror::Class* DefineClass(Thread* self, const char* descriptor, size_t hash,
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700150 Handle<mirror::ClassLoader> class_loader,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800151 const DexFile& dex_file, const DexFile::ClassDef& dex_class_def)
Mathieu Chartier90443472015-07-16 20:32:27 -0700152 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!dex_lock_);
Elliott Hughes64bf5a32011-09-20 14:43:12 -0700153
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700154 // Finds a class by its descriptor, returning null if it isn't wasn't loaded
Elliott Hughes64bf5a32011-09-20 14:43:12 -0700155 // by the given 'class_loader'.
Mathieu Chartiere7c9a8c2014-11-06 16:35:45 -0800156 mirror::Class* LookupClass(Thread* self, const char* descriptor, size_t hash,
Mathieu Chartierc2e20622014-11-03 11:41:47 -0800157 mirror::ClassLoader* class_loader)
Mathieu Chartier90443472015-07-16 20:32:27 -0700158 REQUIRES(!Locks::classlinker_classes_lock_)
159 SHARED_REQUIRES(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700160
Elliott Hughes6fa602d2011-12-02 17:54:25 -0800161 // Finds all the classes with the given descriptor, regardless of ClassLoader.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800162 void LookupClasses(const char* descriptor, std::vector<mirror::Class*>& classes)
Mathieu Chartier90443472015-07-16 20:32:27 -0700163 REQUIRES(!Locks::classlinker_classes_lock_)
164 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes6fa602d2011-12-02 17:54:25 -0800165
Mathieu Chartier90443472015-07-16 20:32:27 -0700166 mirror::Class* FindPrimitiveClass(char type) SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700167
Brian Carlstromae826982011-11-09 01:33:42 -0800168 // General class unloading is not supported, this is used to prune
169 // unwanted classes during image writing.
Mathieu Chartierc2e20622014-11-03 11:41:47 -0800170 bool RemoveClass(const char* descriptor, mirror::ClassLoader* class_loader)
Mathieu Chartier90443472015-07-16 20:32:27 -0700171 REQUIRES(!Locks::classlinker_classes_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Brian Carlstromae826982011-11-09 01:33:42 -0800172
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700173 void DumpAllClasses(int flags)
Mathieu Chartier90443472015-07-16 20:32:27 -0700174 REQUIRES(!Locks::classlinker_classes_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes9d5ccec2011-09-19 13:19:50 -0700175
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700176 void DumpForSigQuit(std::ostream& os)
Mathieu Chartier90443472015-07-16 20:32:27 -0700177 REQUIRES(!Locks::classlinker_classes_lock_);
Elliott Hughescac6cc72011-11-03 20:31:21 -0700178
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700179 size_t NumLoadedClasses()
Mathieu Chartier90443472015-07-16 20:32:27 -0700180 REQUIRES(!Locks::classlinker_classes_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughese27955c2011-08-26 15:21:24 -0700181
Brian Carlstromb63ec392011-08-27 17:38:27 -0700182 // Resolve a String with the given index from the DexFile, storing the
Brian Carlstromaded5f72011-10-07 17:15:04 -0700183 // result in the DexCache. The referrer is used to identify the
184 // target DexCache and ClassLoader to use for resolution.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700185 mirror::String* ResolveString(uint32_t string_idx, ArtMethod* referrer)
Mathieu Chartier90443472015-07-16 20:32:27 -0700186 SHARED_REQUIRES(Locks::mutator_lock_);
Brian Carlstromaded5f72011-10-07 17:15:04 -0700187
188 // Resolve a String with the given index from the DexFile, storing the
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700189 // result in the DexCache.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800190 mirror::String* ResolveString(const DexFile& dex_file, uint32_t string_idx,
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700191 Handle<mirror::DexCache> dex_cache)
Mathieu Chartier90443472015-07-16 20:32:27 -0700192 SHARED_REQUIRES(Locks::mutator_lock_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700193
Brian Carlstromb63ec392011-08-27 17:38:27 -0700194 // Resolve a Type with the given index from the DexFile, storing the
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700195 // result in the DexCache. The referrer is used to identity the
196 // target DexCache and ClassLoader to use for resolution.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800197 mirror::Class* ResolveType(const DexFile& dex_file, uint16_t type_idx, mirror::Class* referrer)
Mathieu Chartier4e2cb092015-07-22 16:17:51 -0700198 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!dex_lock_, !Roles::uninterruptible_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700199
Brian Carlstromb63ec392011-08-27 17:38:27 -0700200 // Resolve a Type with the given index from the DexFile, storing the
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700201 // result in the DexCache. The referrer is used to identify the
Brian Carlstromb63ec392011-08-27 17:38:27 -0700202 // target DexCache and ClassLoader to use for resolution.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700203 mirror::Class* ResolveType(uint16_t type_idx, ArtMethod* referrer)
Mathieu Chartier4e2cb092015-07-22 16:17:51 -0700204 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!dex_lock_, !Roles::uninterruptible_);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700205
Mathieu Chartierc7853442015-03-27 14:35:38 -0700206 mirror::Class* ResolveType(uint16_t type_idx, ArtField* referrer)
Mathieu Chartier4e2cb092015-07-22 16:17:51 -0700207 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!dex_lock_, !Roles::uninterruptible_);
Brian Carlstromb63ec392011-08-27 17:38:27 -0700208
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700209 // Resolve a type with the given ID from the DexFile, storing the
210 // result in DexCache. The ClassLoader is used to search for the
211 // type, since it may be referenced from but not contained within
212 // the given DexFile.
Mathieu Chartier590fee92013-09-13 13:46:47 -0700213 mirror::Class* ResolveType(const DexFile& dex_file, uint16_t type_idx,
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700214 Handle<mirror::DexCache> dex_cache,
215 Handle<mirror::ClassLoader> class_loader)
Mathieu Chartier4e2cb092015-07-22 16:17:51 -0700216 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!dex_lock_, !Roles::uninterruptible_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700217
218 // Resolve a method with a given ID from the DexFile, storing the
219 // result in DexCache. The ClassLinker and ClassLoader are used as
220 // in ResolveType. What is unique is the method type argument which
221 // is used to determine if this method is a direct, static, or
222 // virtual method.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700223 ArtMethod* ResolveMethod(const DexFile& dex_file, uint32_t method_idx,
224 Handle<mirror::DexCache> dex_cache,
225 Handle<mirror::ClassLoader> class_loader, ArtMethod* referrer,
226 InvokeType type)
Mathieu Chartier4e2cb092015-07-22 16:17:51 -0700227 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!dex_lock_, !Roles::uninterruptible_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700228
Mathieu Chartiere401d142015-04-22 13:56:20 -0700229 ArtMethod* GetResolvedMethod(uint32_t method_idx, ArtMethod* referrer)
Mathieu Chartier90443472015-07-16 20:32:27 -0700230 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700231 ArtMethod* ResolveMethod(Thread* self, uint32_t method_idx, ArtMethod* referrer, InvokeType type)
Mathieu Chartier4e2cb092015-07-22 16:17:51 -0700232 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!dex_lock_, !Roles::uninterruptible_);
Brian Carlstrom16192862011-09-12 17:50:06 -0700233
Mathieu Chartierc7853442015-03-27 14:35:38 -0700234 ArtField* GetResolvedField(uint32_t field_idx, mirror::Class* field_declaring_class)
Mathieu Chartier90443472015-07-16 20:32:27 -0700235 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartierc7853442015-03-27 14:35:38 -0700236 ArtField* GetResolvedField(uint32_t field_idx, mirror::DexCache* dex_cache)
Mathieu Chartier90443472015-07-16 20:32:27 -0700237 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700238 ArtField* ResolveField(uint32_t field_idx, ArtMethod* referrer, bool is_static)
Mathieu Chartier4e2cb092015-07-22 16:17:51 -0700239 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!dex_lock_, !Roles::uninterruptible_);
Brian Carlstromb9edb842011-08-28 16:31:06 -0700240
Brian Carlstrom16192862011-09-12 17:50:06 -0700241 // Resolve a field with a given ID from the DexFile, storing the
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700242 // result in DexCache. The ClassLinker and ClassLoader are used as
243 // in ResolveType. What is unique is the is_static argument which is
244 // used to determine if we are resolving a static or non-static
245 // field.
Mathieu Chartier90443472015-07-16 20:32:27 -0700246 ArtField* ResolveField(const DexFile& dex_file, uint32_t field_idx,
247 Handle<mirror::DexCache> dex_cache,
248 Handle<mirror::ClassLoader> class_loader, bool is_static)
Mathieu Chartier4e2cb092015-07-22 16:17:51 -0700249 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!dex_lock_, !Roles::uninterruptible_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700250
Ian Rogersb067ac22011-12-13 18:05:09 -0800251 // Resolve a field with a given ID from the DexFile, storing the
252 // result in DexCache. The ClassLinker and ClassLoader are used as
253 // in ResolveType. No is_static argument is provided so that Java
254 // field resolution semantics are followed.
Mathieu Chartierc7853442015-03-27 14:35:38 -0700255 ArtField* ResolveFieldJLS(const DexFile& dex_file, uint32_t field_idx,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700256 Handle<mirror::DexCache> dex_cache,
257 Handle<mirror::ClassLoader> class_loader)
Mathieu Chartier4e2cb092015-07-22 16:17:51 -0700258 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!dex_lock_, !Roles::uninterruptible_);
Ian Rogersb067ac22011-12-13 18:05:09 -0800259
Ian Rogersad25ac52011-10-04 19:13:33 -0700260 // Get shorty from method index without resolution. Used to do handlerization.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700261 const char* MethodShorty(uint32_t method_idx, ArtMethod* referrer, uint32_t* length)
Mathieu Chartier90443472015-07-16 20:32:27 -0700262 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersad25ac52011-10-04 19:13:33 -0700263
Elliott Hughesf4c21c92011-08-19 17:31:31 -0700264 // Returns true on success, false if there's an exception pending.
Brian Carlstrom25c33252011-09-18 15:58:35 -0700265 // can_run_clinit=false allows the compiler to attempt to init a class,
266 // given the restriction that no <clinit> execution is possible.
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700267 bool EnsureInitialized(Thread* self, Handle<mirror::Class> c, bool can_init_fields,
Ian Rogers7b078e82014-09-10 14:44:24 -0700268 bool can_init_parents)
Mathieu Chartier4e2cb092015-07-22 16:17:51 -0700269 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!dex_lock_, !Roles::uninterruptible_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700270
Elliott Hughes2a20cfd2011-09-23 19:30:41 -0700271 // Initializes classes that have instances in the image but that have
272 // <clinit> methods so they could not be initialized by the compiler.
Mathieu Chartier4e2cb092015-07-22 16:17:51 -0700273 void RunRootClinits() SHARED_REQUIRES(Locks::mutator_lock_)
274 REQUIRES(!dex_lock_, !Roles::uninterruptible_);
Elliott Hughes2a20cfd2011-09-23 19:30:41 -0700275
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700276 void RegisterDexFile(const DexFile& dex_file)
Mathieu Chartier90443472015-07-16 20:32:27 -0700277 REQUIRES(!dex_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700278 void RegisterDexFile(const DexFile& dex_file, Handle<mirror::DexCache> dex_cache)
Mathieu Chartier90443472015-07-16 20:32:27 -0700279 REQUIRES(!dex_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700280
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700281 const OatFile* RegisterOatFile(const OatFile* oat_file)
Mathieu Chartier90443472015-07-16 20:32:27 -0700282 REQUIRES(!dex_lock_);
Brian Carlstrom866c8622012-01-06 16:35:13 -0800283
Brian Carlstrom8a487412011-08-29 20:08:52 -0700284 const std::vector<const DexFile*>& GetBootClassPath() {
285 return boot_class_path_;
286 }
287
Sebastien Hertz0de11332015-05-13 12:14:05 +0200288 // Returns the first non-image oat file in the class path.
289 const OatFile* GetPrimaryOatFile()
Mathieu Chartier90443472015-07-16 20:32:27 -0700290 REQUIRES(!dex_lock_);
Sebastien Hertz0de11332015-05-13 12:14:05 +0200291
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700292 void VisitClasses(ClassVisitor* visitor, void* arg)
Mathieu Chartier90443472015-07-16 20:32:27 -0700293 REQUIRES(!Locks::classlinker_classes_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersdbf3be02014-08-29 15:40:08 -0700294
295 // Less efficient variant of VisitClasses that copies the class_table_ into secondary storage
296 // so that it can visit individual classes without holding the doesn't hold the
297 // Locks::classlinker_classes_lock_. As the Locks::classlinker_classes_lock_ isn't held this code
298 // can race with insertion and deletion of classes while the visitor is being called.
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700299 void VisitClassesWithoutClassesLock(ClassVisitor* visitor, void* arg)
Mathieu Chartier90443472015-07-16 20:32:27 -0700300 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!dex_lock_);
Elliott Hughesa2155262011-11-16 16:26:58 -0800301
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -0700302 void VisitClassRoots(RootVisitor* visitor, VisitRootFlags flags)
Mathieu Chartier90443472015-07-16 20:32:27 -0700303 REQUIRES(!Locks::classlinker_classes_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -0700304 void VisitRoots(RootVisitor* visitor, VisitRootFlags flags)
Mathieu Chartier90443472015-07-16 20:32:27 -0700305 REQUIRES(!dex_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700306
Hiroshi Yamauchie9e3e692014-06-24 14:31:37 -0700307 mirror::DexCache* FindDexCache(const DexFile& dex_file)
Mathieu Chartier90443472015-07-16 20:32:27 -0700308 REQUIRES(!dex_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchie9e3e692014-06-24 14:31:37 -0700309 bool IsDexFileRegistered(const DexFile& dex_file)
Mathieu Chartier90443472015-07-16 20:32:27 -0700310 REQUIRES(!dex_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700311 void FixupDexCaches(ArtMethod* resolution_method)
Mathieu Chartier90443472015-07-16 20:32:27 -0700312 REQUIRES(!dex_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Brian Carlstrom1d9f52b2011-10-13 10:50:45 -0700313
Richard Uhler66d874d2015-01-15 09:37:19 -0800314 // Finds or creates the oat file holding dex_location. Then loads and returns
315 // all corresponding dex files (there may be more than one dex file loaded
316 // in the case of multidex).
317 // This may return the original, unquickened dex files if the oat file could
318 // not be generated.
319 //
320 // Returns an empty vector if the dex files could not be loaded. In this
321 // case, there will be at least one error message returned describing why no
322 // dex files could not be loaded. The 'error_msgs' argument must not be
323 // null, regardless of whether there is an error or not.
324 //
325 // This method should not be called with the mutator_lock_ held, because it
326 // could end up starving GC if we need to generate or relocate any oat
327 // files.
Mathieu Chartier90443472015-07-16 20:32:27 -0700328 std::vector<std::unique_ptr<const DexFile>> OpenDexFilesFromOat(
Richard Uhler66d874d2015-01-15 09:37:19 -0800329 const char* dex_location, const char* oat_location,
330 std::vector<std::string>* error_msgs)
Mathieu Chartier90443472015-07-16 20:32:27 -0700331 REQUIRES(!dex_lock_, !Locks::mutator_lock_);
jeffhaof6174e82012-01-31 16:14:17 -0800332
Ian Rogersc0542af2014-09-03 16:16:56 -0700333 // Allocate an instance of a java.lang.Object.
Mathieu Chartier4e2cb092015-07-22 16:17:51 -0700334 mirror::Object* AllocObject(Thread* self) SHARED_REQUIRES(Locks::mutator_lock_)
335 REQUIRES(!Roles::uninterruptible_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700336
Elliott Hughes418d20f2011-09-22 14:00:39 -0700337 // TODO: replace this with multiple methods that allocate the correct managed type.
Shih-wei Liao44175362011-08-28 16:59:17 -0700338 template <class T>
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800339 mirror::ObjectArray<T>* AllocObjectArray(Thread* self, size_t length)
Mathieu Chartier4e2cb092015-07-22 16:17:51 -0700340 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_);
Shih-wei Liao55df06b2011-08-26 14:39:27 -0700341
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800342 mirror::ObjectArray<mirror::Class>* AllocClassArray(Thread* self, size_t length)
Mathieu Chartier4e2cb092015-07-22 16:17:51 -0700343 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_);
jeffhao98eacac2011-09-14 16:11:53 -0700344
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800345 mirror::ObjectArray<mirror::String>* AllocStringArray(Thread* self, size_t length)
Mathieu Chartier4e2cb092015-07-22 16:17:51 -0700346 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_);
347
348 ArtField* AllocArtFieldArray(Thread* self, size_t length);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800349
Mathieu Chartiere401d142015-04-22 13:56:20 -0700350 ArtMethod* AllocArtMethodArray(Thread* self, size_t length);
351
352 mirror::PointerArray* AllocPointerArray(Thread* self, size_t length)
Mathieu Chartier4e2cb092015-07-22 16:17:51 -0700353 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800354
355 mirror::IfTable* AllocIfTable(Thread* self, size_t ifcount)
Mathieu Chartier4e2cb092015-07-22 16:17:51 -0700356 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800357
Mathieu Chartier4e2cb092015-07-22 16:17:51 -0700358 mirror::ObjectArray<mirror::StackTraceElement>* AllocStackTraceElementArray(
359 Thread* self, size_t length) SHARED_REQUIRES(Locks::mutator_lock_)
360 REQUIRES(!Roles::uninterruptible_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800361
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700362 void VerifyClass(Thread* self, Handle<mirror::Class> klass)
Mathieu Chartier90443472015-07-16 20:32:27 -0700363 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!dex_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800364 bool VerifyClassUsingOatFile(const DexFile& dex_file, mirror::Class* klass,
365 mirror::Class::Status& oat_file_class_status)
Mathieu Chartier90443472015-07-16 20:32:27 -0700366 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!dex_lock_);
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800367 void ResolveClassExceptionHandlerTypes(const DexFile& dex_file,
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700368 Handle<mirror::Class> klass)
Mathieu Chartier90443472015-07-16 20:32:27 -0700369 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!dex_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700370 void ResolveMethodExceptionHandlerTypes(const DexFile& dex_file, ArtMethod* klass)
Mathieu Chartier90443472015-07-16 20:32:27 -0700371 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!dex_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800372
Mathieu Chartier2b7c4d12014-05-19 10:52:16 -0700373 mirror::Class* CreateProxyClass(ScopedObjectAccessAlreadyRunnable& soa, jstring name,
374 jobjectArray interfaces, jobject loader, jobjectArray methods,
375 jobjectArray throws)
Mathieu Chartier90443472015-07-16 20:32:27 -0700376 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800377 std::string GetDescriptorForProxy(mirror::Class* proxy_class)
Mathieu Chartier90443472015-07-16 20:32:27 -0700378 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700379 ArtMethod* FindMethodForProxy(mirror::Class* proxy_class, ArtMethod* proxy_method)
Mathieu Chartier90443472015-07-16 20:32:27 -0700380 REQUIRES(!dex_lock_)
381 SHARED_REQUIRES(Locks::mutator_lock_);
Jesse Wilson95caa792011-10-12 18:14:17 -0400382
Ian Rogers19846512012-02-24 11:42:47 -0800383 // Get the oat code for a method when its class isn't yet initialized
Mathieu Chartiere401d142015-04-22 13:56:20 -0700384 const void* GetQuickOatCodeFor(ArtMethod* method)
Mathieu Chartier90443472015-07-16 20:32:27 -0700385 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers19846512012-02-24 11:42:47 -0800386
Mathieu Chartiere35517a2012-10-30 18:49:55 -0700387 // Get the oat code for a method from a method index.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700388 const void* GetQuickOatCodeFor(const DexFile& dex_file, uint16_t class_def_idx,
389 uint32_t method_idx)
Mathieu Chartier90443472015-07-16 20:32:27 -0700390 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere35517a2012-10-30 18:49:55 -0700391
Hiroshi Yamauchi9bdec882014-08-15 17:11:12 -0700392 // Get compiled code for a method, return null if no code
393 // exists. This is unlike Get..OatCodeFor which will return a bridge
394 // or interpreter entrypoint.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700395 const void* GetOatMethodQuickCodeFor(ArtMethod* method)
Mathieu Chartier90443472015-07-16 20:32:27 -0700396 SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchi9bdec882014-08-15 17:11:12 -0700397
Nicolas Geoffray9523a3e2015-07-17 11:51:28 +0000398 const OatFile::OatMethod FindOatMethodFor(ArtMethod* method, bool* found)
Mathieu Chartier90443472015-07-16 20:32:27 -0700399 SHARED_REQUIRES(Locks::mutator_lock_);
Nicolas Geoffray9523a3e2015-07-17 11:51:28 +0000400
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700401 pid_t GetClassesLockOwner(); // For SignalCatcher.
402 pid_t GetDexLockOwner(); // For SignalCatcher.
Brian Carlstrom24a3c2e2011-10-17 18:07:52 -0700403
Mathieu Chartier90443472015-07-16 20:32:27 -0700404 mirror::Class* GetClassRoot(ClassRoot class_root) SHARED_REQUIRES(Locks::mutator_lock_);
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700405
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700406 static const char* GetClassRootDescriptor(ClassRoot class_root);
Andreas Gampe2da88232014-02-27 12:26:20 -0800407
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700408 // Is the given entry point quick code to run the resolution stub?
409 bool IsQuickResolutionStub(const void* entry_point) const;
Jeff Hao88474b42013-10-23 16:24:40 -0700410
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700411 // Is the given entry point quick code to bridge into the interpreter?
412 bool IsQuickToInterpreterBridge(const void* entry_point) const;
413
414 // Is the given entry point quick code to run the generic JNI stub?
415 bool IsQuickGenericJniStub(const void* entry_point) const;
Vladimir Marko8a630572014-04-09 18:45:35 +0100416
Jeff Hao88474b42013-10-23 16:24:40 -0700417 InternTable* GetInternTable() const {
418 return intern_table_;
419 }
420
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700421 // Set the entrypoints up for method to the given code.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700422 void SetEntryPointsToCompiledCode(ArtMethod* method, const void* method_code) const
Mathieu Chartier90443472015-07-16 20:32:27 -0700423 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700424
425 // Set the entrypoints up for method to the enter the interpreter.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700426 void SetEntryPointsToInterpreter(ArtMethod* method) const
Mathieu Chartier90443472015-07-16 20:32:27 -0700427 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700428
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700429 // Attempts to insert a class into a class table. Returns null if
Ian Rogers848871b2013-08-05 10:56:33 -0700430 // the class was inserted, otherwise returns an existing class with
431 // the same descriptor and ClassLoader.
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700432 mirror::Class* InsertClass(const char* descriptor, mirror::Class* klass, size_t hash)
Mathieu Chartier90443472015-07-16 20:32:27 -0700433 REQUIRES(!Locks::classlinker_classes_lock_)
434 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers848871b2013-08-05 10:56:33 -0700435
Mathieu Chartier90443472015-07-16 20:32:27 -0700436 mirror::ObjectArray<mirror::Class>* GetClassRoots() SHARED_REQUIRES(Locks::mutator_lock_) {
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -0700437 mirror::ObjectArray<mirror::Class>* class_roots = class_roots_.Read();
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700438 DCHECK(class_roots != nullptr);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700439 return class_roots;
440 }
441
Mathieu Chartierc2e20622014-11-03 11:41:47 -0800442 // Move all of the image classes into the class table for faster lookups.
443 void MoveImageClassesToClassTable()
Mathieu Chartier90443472015-07-16 20:32:27 -0700444 REQUIRES(!Locks::classlinker_classes_lock_)
445 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartierc2e20622014-11-03 11:41:47 -0800446 // Move the class table to the pre-zygote table to reduce memory usage. This works by ensuring
447 // that no more classes are ever added to the pre zygote table which makes it that the pages
448 // always remain shared dirty instead of private dirty.
449 void MoveClassTableToPreZygote()
Mathieu Chartier90443472015-07-16 20:32:27 -0700450 REQUIRES(!Locks::classlinker_classes_lock_)
451 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartierc2e20622014-11-03 11:41:47 -0800452
Sebastien Hertz6963e442014-11-26 22:11:27 +0100453 // Returns true if the method can be called with its direct code pointer, false otherwise.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700454 bool MayBeCalledWithDirectCodePointer(ArtMethod* m)
Mathieu Chartier90443472015-07-16 20:32:27 -0700455 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!dex_lock_);
Sebastien Hertz6963e442014-11-26 22:11:27 +0100456
Andreas Gampe81c6f8d2015-03-25 17:19:53 -0700457 // Creates a GlobalRef PathClassLoader that can be used to load classes from the given dex files.
458 // Note: the objects are not completely set up. Do not use this outside of tests and the compiler.
459 jobject CreatePathClassLoader(Thread* self, std::vector<const DexFile*>& dex_files)
Mathieu Chartier90443472015-07-16 20:32:27 -0700460 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!dex_lock_);
Andreas Gampe81c6f8d2015-03-25 17:19:53 -0700461
Mathieu Chartiere401d142015-04-22 13:56:20 -0700462 size_t GetImagePointerSize() const {
463 DCHECK(ValidPointerSize(image_pointer_size_)) << image_pointer_size_;
464 return image_pointer_size_;
465 }
466
467 // Used by image writer for checking.
468 bool ClassInClassTable(mirror::Class* klass)
Mathieu Chartier90443472015-07-16 20:32:27 -0700469 REQUIRES(!Locks::classlinker_classes_lock_)
470 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiera89d7ed2014-12-05 10:57:13 -0800471
Mathieu Chartiere401d142015-04-22 13:56:20 -0700472 ArtMethod* CreateRuntimeMethod();
473
Andreas Gampe8ac75952015-06-02 21:01:45 -0700474 // Clear the ArrayClass cache. This is necessary when cleaning up for the image, as the cache
475 // entries are roots, but potentially not image classes.
Mathieu Chartier90443472015-07-16 20:32:27 -0700476 void DropFindArrayClassCache() SHARED_REQUIRES(Locks::mutator_lock_);
Andreas Gampe8ac75952015-06-02 21:01:45 -0700477
Mathieu Chartiere401d142015-04-22 13:56:20 -0700478 private:
Brian Carlstrom56d947f2013-07-15 13:14:23 -0700479 OatFile& GetImageOatFile(gc::space::ImageSpace* space)
Mathieu Chartier90443472015-07-16 20:32:27 -0700480 REQUIRES(!dex_lock_)
481 SHARED_REQUIRES(Locks::mutator_lock_);
Brian Carlstroma663ea52011-08-19 23:33:41 -0700482
Mathieu Chartier4e2cb092015-07-22 16:17:51 -0700483 void FinishInit(Thread* self) SHARED_REQUIRES(Locks::mutator_lock_)
484 REQUIRES(!dex_lock_, !Roles::uninterruptible_);
Brian Carlstroma663ea52011-08-19 23:33:41 -0700485
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700486 // For early bootstrapping by Init
Ian Rogers6fac4472014-02-25 17:01:10 -0800487 mirror::Class* AllocClass(Thread* self, mirror::Class* java_lang_Class, uint32_t class_size)
Mathieu Chartier4e2cb092015-07-22 16:17:51 -0700488 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_);
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700489
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800490 // Alloc* convenience functions to avoid needing to pass in mirror::Class*
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700491 // values that are known to the ClassLinker such as
492 // kObjectArrayClass and kJavaLangString etc.
Ian Rogers6fac4472014-02-25 17:01:10 -0800493 mirror::Class* AllocClass(Thread* self, uint32_t class_size)
Mathieu Chartier4e2cb092015-07-22 16:17:51 -0700494 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800495 mirror::DexCache* AllocDexCache(Thread* self, const DexFile& dex_file)
Mathieu Chartier4e2cb092015-07-22 16:17:51 -0700496 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_);
Ian Rogersbdb03912011-09-14 00:55:44 -0700497
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800498 mirror::Class* CreatePrimitiveClass(Thread* self, Primitive::Type type)
Mathieu Chartier4e2cb092015-07-22 16:17:51 -0700499 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800500 mirror::Class* InitializePrimitiveClass(mirror::Class* primitive_class, Primitive::Type type)
Mathieu Chartier4e2cb092015-07-22 16:17:51 -0700501 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_);
Brian Carlstroma331b3c2011-07-18 17:47:56 -0700502
Mathieu Chartiere7c9a8c2014-11-06 16:35:45 -0800503 mirror::Class* CreateArrayClass(Thread* self, const char* descriptor, size_t hash,
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700504 Handle<mirror::ClassLoader> class_loader)
Mathieu Chartier4e2cb092015-07-22 16:17:51 -0700505 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!dex_lock_, !Roles::uninterruptible_);
Brian Carlstroma331b3c2011-07-18 17:47:56 -0700506
Ian Rogers7b078e82014-09-10 14:44:24 -0700507 void AppendToBootClassPath(Thread* self, const DexFile& dex_file)
Mathieu Chartier90443472015-07-16 20:32:27 -0700508 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!dex_lock_);
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700509 void AppendToBootClassPath(const DexFile& dex_file, Handle<mirror::DexCache> dex_cache)
Mathieu Chartier90443472015-07-16 20:32:27 -0700510 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!dex_lock_);
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700511
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700512 // Precomputes size needed for Class, in the case of a non-temporary class this size must be
513 // sufficient to hold all static fields.
514 uint32_t SizeOfClassWithoutEmbeddedTables(const DexFile& dex_file,
515 const DexFile::ClassDef& dex_class_def);
Brian Carlstrom4873d462011-08-21 15:23:39 -0700516
Mathieu Chartierc7853442015-03-27 14:35:38 -0700517 // Setup the classloader, class def index, type idx so that we can insert this class in the class
518 // table.
519 void SetupClass(const DexFile& dex_file, const DexFile::ClassDef& dex_class_def,
520 Handle<mirror::Class> klass, mirror::ClassLoader* class_loader)
Mathieu Chartier90443472015-07-16 20:32:27 -0700521 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartierc7853442015-03-27 14:35:38 -0700522
Ian Rogers7b078e82014-09-10 14:44:24 -0700523 void LoadClass(Thread* self, const DexFile& dex_file, const DexFile::ClassDef& dex_class_def,
Mathieu Chartierc7853442015-03-27 14:35:38 -0700524 Handle<mirror::Class> klass)
Mathieu Chartier90443472015-07-16 20:32:27 -0700525 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers13735952014-10-08 12:43:28 -0700526 void LoadClassMembers(Thread* self, const DexFile& dex_file, const uint8_t* class_data,
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700527 Handle<mirror::Class> klass, const OatFile::OatClass* oat_class)
Mathieu Chartier90443472015-07-16 20:32:27 -0700528 SHARED_REQUIRES(Locks::mutator_lock_);
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700529
Mathieu Chartierc7853442015-03-27 14:35:38 -0700530 void LoadField(const ClassDataItemIterator& it, Handle<mirror::Class> klass,
531 ArtField* dst)
Mathieu Chartier90443472015-07-16 20:32:27 -0700532 SHARED_REQUIRES(Locks::mutator_lock_);
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700533
Mathieu Chartiere401d142015-04-22 13:56:20 -0700534 void LoadMethod(Thread* self, const DexFile& dex_file, const ClassDataItemIterator& it,
535 Handle<mirror::Class> klass, ArtMethod* dst)
Mathieu Chartier90443472015-07-16 20:32:27 -0700536 SHARED_REQUIRES(Locks::mutator_lock_);
Brian Carlstrom934486c2011-07-12 23:42:50 -0700537
Mathieu Chartier90443472015-07-16 20:32:27 -0700538 void FixupStaticTrampolines(mirror::Class* klass) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers19846512012-02-24 11:42:47 -0800539
Ian Rogers97b52f82014-08-14 11:34:07 -0700540 // Finds the associated oat class for a dex_file and descriptor. Returns an invalid OatClass on
541 // error and sets found to false.
542 OatFile::OatClass FindOatClass(const DexFile& dex_file, uint16_t class_def_idx, bool* found)
Mathieu Chartier90443472015-07-16 20:32:27 -0700543 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers19846512012-02-24 11:42:47 -0800544
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700545 void RegisterDexFileLocked(const DexFile& dex_file, Handle<mirror::DexCache> dex_cache)
Mathieu Chartier90443472015-07-16 20:32:27 -0700546 REQUIRES(dex_lock_)
547 SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchie9e3e692014-06-24 14:31:37 -0700548 bool IsDexFileRegisteredLocked(const DexFile& dex_file)
Mathieu Chartier90443472015-07-16 20:32:27 -0700549 SHARED_REQUIRES(dex_lock_, Locks::mutator_lock_);
Brian Carlstromaded5f72011-10-07 17:15:04 -0700550
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700551 bool InitializeClass(Thread* self, Handle<mirror::Class> klass, bool can_run_clinit,
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800552 bool can_init_parents)
Mathieu Chartier90443472015-07-16 20:32:27 -0700553 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!dex_lock_);
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700554 bool WaitForInitializeClass(Handle<mirror::Class> klass, Thread* self,
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800555 ObjectLock<mirror::Class>& lock);
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700556 bool ValidateSuperClassDescriptors(Handle<mirror::Class> klass)
Mathieu Chartier90443472015-07-16 20:32:27 -0700557 SHARED_REQUIRES(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700558
Ian Rogers98379392014-02-24 16:53:16 -0800559 bool IsSameDescriptorInDifferentClassContexts(Thread* self, const char* descriptor,
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700560 Handle<mirror::ClassLoader> class_loader1,
561 Handle<mirror::ClassLoader> class_loader2)
Mathieu Chartier90443472015-07-16 20:32:27 -0700562 SHARED_REQUIRES(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700563
Mathieu Chartiere401d142015-04-22 13:56:20 -0700564 bool IsSameMethodSignatureInDifferentClassContexts(Thread* self, ArtMethod* method,
565 mirror::Class* klass1, mirror::Class* klass2)
Mathieu Chartier90443472015-07-16 20:32:27 -0700566 SHARED_REQUIRES(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700567
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700568 bool LinkClass(Thread* self, const char* descriptor, Handle<mirror::Class> klass,
569 Handle<mirror::ObjectArray<mirror::Class>> interfaces,
Hiroshi Yamauchi679b1cf2015-05-21 12:05:27 -0700570 MutableHandle<mirror::Class>* h_new_class_out)
Mathieu Chartier90443472015-07-16 20:32:27 -0700571 SHARED_REQUIRES(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700572
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700573 bool LinkSuperClass(Handle<mirror::Class> klass)
Mathieu Chartier90443472015-07-16 20:32:27 -0700574 SHARED_REQUIRES(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700575
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700576 bool LoadSuperAndInterfaces(Handle<mirror::Class> klass, const DexFile& dex_file)
Mathieu Chartier90443472015-07-16 20:32:27 -0700577 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!dex_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700578
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700579 bool LinkMethods(Thread* self, Handle<mirror::Class> klass,
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700580 Handle<mirror::ObjectArray<mirror::Class>> interfaces,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700581 ArtMethod** out_imt)
Mathieu Chartier90443472015-07-16 20:32:27 -0700582 SHARED_REQUIRES(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700583
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700584 bool LinkVirtualMethods(Thread* self, Handle<mirror::Class> klass)
Mathieu Chartier90443472015-07-16 20:32:27 -0700585 SHARED_REQUIRES(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700586
Mathieu Chartiere401d142015-04-22 13:56:20 -0700587 bool LinkInterfaceMethods(Thread* self, Handle<mirror::Class> klass,
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700588 Handle<mirror::ObjectArray<mirror::Class>> interfaces,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700589 ArtMethod** out_imt)
Mathieu Chartier90443472015-07-16 20:32:27 -0700590 SHARED_REQUIRES(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700591
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700592 bool LinkStaticFields(Thread* self, Handle<mirror::Class> klass, size_t* class_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700593 SHARED_REQUIRES(Locks::mutator_lock_);
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700594 bool LinkInstanceFields(Thread* self, Handle<mirror::Class> klass)
Mathieu Chartier90443472015-07-16 20:32:27 -0700595 SHARED_REQUIRES(Locks::mutator_lock_);
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700596 bool LinkFields(Thread* self, Handle<mirror::Class> klass, bool is_static, size_t* class_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700597 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700598 void LinkCode(ArtMethod* method, const OatFile::OatClass* oat_class,
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700599 uint32_t class_def_method_index)
Mathieu Chartier90443472015-07-16 20:32:27 -0700600 SHARED_REQUIRES(Locks::mutator_lock_);
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700601 void CreateReferenceInstanceOffsets(Handle<mirror::Class> klass)
Mathieu Chartier90443472015-07-16 20:32:27 -0700602 SHARED_REQUIRES(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700603
Mathieu Chartiere401d142015-04-22 13:56:20 -0700604 void CheckProxyConstructor(ArtMethod* constructor) const
Mathieu Chartier90443472015-07-16 20:32:27 -0700605 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700606 void CheckProxyMethod(ArtMethod* method, ArtMethod* prototype) const
Mathieu Chartier90443472015-07-16 20:32:27 -0700607 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700608
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700609 // For use by ImageWriter to find DexCaches for its roots
Hiroshi Yamauchie9e3e692014-06-24 14:31:37 -0700610 ReaderWriterMutex* DexLock()
Mathieu Chartier90443472015-07-16 20:32:27 -0700611 SHARED_REQUIRES(Locks::mutator_lock_) LOCK_RETURNED(dex_lock_) {
Hiroshi Yamauchie9e3e692014-06-24 14:31:37 -0700612 return &dex_lock_;
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700613 }
Mathieu Chartier90443472015-07-16 20:32:27 -0700614 size_t GetDexCacheCount() SHARED_REQUIRES(Locks::mutator_lock_, dex_lock_) {
Hiroshi Yamauchie9e3e692014-06-24 14:31:37 -0700615 return dex_caches_.size();
616 }
Mathieu Chartier90443472015-07-16 20:32:27 -0700617 mirror::DexCache* GetDexCache(size_t idx) SHARED_REQUIRES(Locks::mutator_lock_, dex_lock_);
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700618
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700619 const OatFile* FindOpenedOatFileFromOatLocation(const std::string& oat_location)
Mathieu Chartier90443472015-07-16 20:32:27 -0700620 REQUIRES(!dex_lock_);
Andreas Gampe833a4852014-05-21 18:46:59 -0700621
Sebastien Hertz0de11332015-05-13 12:14:05 +0200622 // Returns the boot image oat file.
Mathieu Chartier90443472015-07-16 20:32:27 -0700623 const OatFile* GetBootOatFile() SHARED_REQUIRES(dex_lock_);
Sebastien Hertz0de11332015-05-13 12:14:05 +0200624
Mathieu Chartiere401d142015-04-22 13:56:20 -0700625 void CreateProxyConstructor(Handle<mirror::Class> klass, ArtMethod* out)
Mathieu Chartier90443472015-07-16 20:32:27 -0700626 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700627 void CreateProxyMethod(Handle<mirror::Class> klass, ArtMethod* prototype, ArtMethod* out)
Mathieu Chartier90443472015-07-16 20:32:27 -0700628 SHARED_REQUIRES(Locks::mutator_lock_);
Jesse Wilson95caa792011-10-12 18:14:17 -0400629
Andreas Gampe48498592014-09-10 19:48:05 -0700630 // Ensures that methods have the kAccPreverified bit set. We use the kAccPreverfied bit on the
631 // class access flags to determine whether this has been done before.
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700632 void EnsurePreverifiedMethods(Handle<mirror::Class> c)
Mathieu Chartier90443472015-07-16 20:32:27 -0700633 SHARED_REQUIRES(Locks::mutator_lock_);
Andreas Gampe48498592014-09-10 19:48:05 -0700634
Ian Rogersdbf3be02014-08-29 15:40:08 -0700635 mirror::Class* LookupClassFromTableLocked(const char* descriptor,
Mathieu Chartierc2e20622014-11-03 11:41:47 -0800636 mirror::ClassLoader* class_loader,
Ian Rogersdbf3be02014-08-29 15:40:08 -0700637 size_t hash)
Mathieu Chartier90443472015-07-16 20:32:27 -0700638 SHARED_REQUIRES(Locks::classlinker_classes_lock_, Locks::mutator_lock_);
Ian Rogersdbf3be02014-08-29 15:40:08 -0700639
640 mirror::Class* UpdateClass(const char* descriptor, mirror::Class* klass, size_t hash)
Mathieu Chartier90443472015-07-16 20:32:27 -0700641 REQUIRES(!Locks::classlinker_classes_lock_)
642 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersdbf3be02014-08-29 15:40:08 -0700643
Ian Rogersdbf3be02014-08-29 15:40:08 -0700644 mirror::Class* LookupClassFromImage(const char* descriptor)
Mathieu Chartier90443472015-07-16 20:32:27 -0700645 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersdbf3be02014-08-29 15:40:08 -0700646
647 // EnsureResolved is called to make sure that a class in the class_table_ has been resolved
648 // before returning it to the caller. Its the responsibility of the thread that placed the class
649 // in the table to make it resolved. The thread doing resolution must notify on the class' lock
650 // when resolution has occurred. This happens in mirror::Class::SetStatus. As resolution may
651 // retire a class, the version of the class in the table is returned and this may differ from
652 // the class passed in.
653 mirror::Class* EnsureResolved(Thread* self, const char* descriptor, mirror::Class* klass)
Mathieu Chartier90443472015-07-16 20:32:27 -0700654 WARN_UNUSED SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!dex_lock_);
Ian Rogersdbf3be02014-08-29 15:40:08 -0700655
656 void FixupTemporaryDeclaringClass(mirror::Class* temp_class, mirror::Class* new_class)
Mathieu Chartier90443472015-07-16 20:32:27 -0700657 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersdbf3be02014-08-29 15:40:08 -0700658
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700659 void SetClassRoot(ClassRoot class_root, mirror::Class* klass)
Mathieu Chartier90443472015-07-16 20:32:27 -0700660 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700661
662 // Return the quick generic JNI stub for testing.
663 const void* GetRuntimeQuickGenericJniStub() const;
664
Andreas Gampebfdcdc12015-04-22 18:10:36 -0700665 // Throw the class initialization failure recorded when first trying to initialize the given
666 // class.
667 // Note: Currently we only store the descriptor, so we cannot throw the exact throwable, only
668 // a recreation with a custom string.
Mathieu Chartier90443472015-07-16 20:32:27 -0700669 void ThrowEarlierClassFailure(mirror::Class* c) SHARED_REQUIRES(Locks::mutator_lock_)
670 REQUIRES(!dex_lock_);
Andreas Gampebfdcdc12015-04-22 18:10:36 -0700671
Andreas Gampeb9aec2c2015-04-23 22:23:47 -0700672 // Check for duplicate class definitions of the given oat file against all open oat files.
Mathieu Chartier90443472015-07-16 20:32:27 -0700673 bool HasCollisions(const OatFile* oat_file, std::string* error_msg) REQUIRES(!dex_lock_);
Andreas Gampeb9aec2c2015-04-23 22:23:47 -0700674
Mathieu Chartier90443472015-07-16 20:32:27 -0700675 bool HasInitWithString(Thread* self, const char* descriptor)
676 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!dex_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700677
678 bool CanWeInitializeClass(mirror::Class* klass, bool can_init_statics, bool can_init_parents)
Mathieu Chartier90443472015-07-16 20:32:27 -0700679 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700680
681 void UpdateClassVirtualMethods(mirror::Class* klass, ArtMethod* new_methods,
682 size_t new_num_methods)
Mathieu Chartier90443472015-07-16 20:32:27 -0700683 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!Locks::classlinker_classes_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700684
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700685 std::vector<const DexFile*> boot_class_path_;
Richard Uhlerfbef44d2014-12-23 09:48:51 -0800686 std::vector<std::unique_ptr<const DexFile>> opened_dex_files_;
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700687
Ian Rogers1bf8d4d2013-05-30 00:18:49 -0700688 mutable ReaderWriterMutex dex_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
Andreas Gampec8ccf682014-09-29 20:07:43 -0700689 std::vector<size_t> new_dex_cache_roots_ GUARDED_BY(dex_lock_);
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -0700690 std::vector<GcRoot<mirror::DexCache>> dex_caches_ GUARDED_BY(dex_lock_);
Elliott Hughesf8349362012-06-18 15:00:06 -0700691 std::vector<const OatFile*> oat_files_ GUARDED_BY(dex_lock_);
Brian Carlstrom47d237a2011-10-18 15:08:33 -0700692
Mathieu Chartierc2e20622014-11-03 11:41:47 -0800693 class ClassDescriptorHashEquals {
694 public:
695 // Same class loader and descriptor.
696 std::size_t operator()(const GcRoot<mirror::Class>& root) const NO_THREAD_SAFETY_ANALYSIS;
Mathieu Chartier47f867a2015-03-18 10:39:00 -0700697 bool operator()(const GcRoot<mirror::Class>& a, const GcRoot<mirror::Class>& b) const
Mathieu Chartierc2e20622014-11-03 11:41:47 -0800698 NO_THREAD_SAFETY_ANALYSIS;
699 // Same class loader and descriptor.
700 std::size_t operator()(const std::pair<const char*, mirror::ClassLoader*>& element) const
701 NO_THREAD_SAFETY_ANALYSIS;
702 bool operator()(const GcRoot<mirror::Class>& a,
Mathieu Chartier47f867a2015-03-18 10:39:00 -0700703 const std::pair<const char*, mirror::ClassLoader*>& b) const
Mathieu Chartierc2e20622014-11-03 11:41:47 -0800704 NO_THREAD_SAFETY_ANALYSIS;
705 // Same descriptor.
Mathieu Chartier47f867a2015-03-18 10:39:00 -0700706 bool operator()(const GcRoot<mirror::Class>& a, const char* descriptor) const
Mathieu Chartierc2e20622014-11-03 11:41:47 -0800707 NO_THREAD_SAFETY_ANALYSIS;
708 std::size_t operator()(const char* descriptor) const NO_THREAD_SAFETY_ANALYSIS;
709 };
710 class GcRootEmptyFn {
711 public:
712 void MakeEmpty(GcRoot<mirror::Class>& item) const {
713 item = GcRoot<mirror::Class>();
714 }
715 bool IsEmpty(const GcRoot<mirror::Class>& item) const {
716 return item.IsNull();
717 }
718 };
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700719
Mathieu Chartierc2e20622014-11-03 11:41:47 -0800720 // hash set which hashes class descriptor, and compares descriptors nad class loaders. Results
721 // should be compared for a matching Class descriptor and class loader.
722 typedef HashSet<GcRoot<mirror::Class>, GcRootEmptyFn, ClassDescriptorHashEquals,
723 ClassDescriptorHashEquals, TrackingAllocator<GcRoot<mirror::Class>, kAllocatorTagClassTable>>
724 Table;
Hiroshi Yamauchia91a4bc2014-06-13 16:44:55 -0700725 // This contains strong roots. To enable concurrent root scanning of
726 // the class table, be careful to use a read barrier when accessing this.
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700727 Table class_table_ GUARDED_BY(Locks::classlinker_classes_lock_);
Mathieu Chartierc2e20622014-11-03 11:41:47 -0800728 Table pre_zygote_class_table_ GUARDED_BY(Locks::classlinker_classes_lock_);
729 std::vector<GcRoot<mirror::Class>> new_class_roots_;
Elliott Hughesf8349362012-06-18 15:00:06 -0700730
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700731 // Do we need to search dex caches to find image classes?
732 bool dex_cache_image_class_lookup_required_;
733 // Number of times we've searched dex caches for a class. After a certain number of misses we move
734 // the classes into the class_table_ to avoid dex cache based searches.
Ian Rogers68b56852014-08-29 20:19:11 -0700735 Atomic<uint32_t> failed_dex_cache_class_lookups_;
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700736
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700737 // Well known mirror::Class roots.
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -0700738 GcRoot<mirror::ObjectArray<mirror::Class>> class_roots_;
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700739
Ian Rogers98379392014-02-24 16:53:16 -0800740 // The interface table used by all arrays.
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -0700741 GcRoot<mirror::IfTable> array_iftable_;
Carl Shapiro565f5072011-07-10 13:39:43 -0700742
Ian Rogers98379392014-02-24 16:53:16 -0800743 // A cache of the last FindArrayClass results. The cache serves to avoid creating array class
744 // descriptors for the sake of performing FindClass.
745 static constexpr size_t kFindArrayCacheSize = 16;
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -0700746 GcRoot<mirror::Class> find_array_class_cache_[kFindArrayCacheSize];
Ian Rogers98379392014-02-24 16:53:16 -0800747 size_t find_array_class_cache_next_victim_;
748
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700749 bool init_done_;
Mathieu Chartier893263b2014-03-04 11:07:42 -0800750 bool log_new_dex_caches_roots_ GUARDED_BY(dex_lock_);
751 bool log_new_class_table_roots_ GUARDED_BY(Locks::classlinker_classes_lock_);
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700752
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700753 InternTable* intern_table_;
754
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700755 // Trampolines within the image the bounce to runtime entrypoints. Done so that there is a single
756 // patch point within the image. TODO: make these proper relocations.
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700757 const void* quick_resolution_trampoline_;
Jeff Hao88474b42013-10-23 16:24:40 -0700758 const void* quick_imt_conflict_trampoline_;
Andreas Gampe2da88232014-02-27 12:26:20 -0800759 const void* quick_generic_jni_trampoline_;
Vladimir Marko8a630572014-04-09 18:45:35 +0100760 const void* quick_to_interpreter_bridge_trampoline_;
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700761
Mathieu Chartier2d721012014-11-10 11:08:06 -0800762 // Image pointer size.
763 size_t image_pointer_size_;
764
Brian Carlstrom34f426c2011-10-04 12:58:02 -0700765 friend class ImageWriter; // for GetClassRoots
Alex Lighta59dd802014-07-02 16:28:08 -0700766 friend class ImageDumper; // for FindOpenedOatFileFromOatLocation
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700767 friend class JniCompilerTest; // for GetRuntimeQuickGenericJniStub
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700768 ART_FRIEND_TEST(mirror::DexCacheTest, Open); // for AllocDexCache
769
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700770 DISALLOW_COPY_AND_ASSIGN(ClassLinker);
771};
772
773} // namespace art
774
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700775#endif // ART_RUNTIME_CLASS_LINKER_H_