blob: 54f1f3dac830652aed6687fb5da6c98cdb2938a7 [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"
Igor Murashkinbc1d78d2015-07-30 16:39:45 -070028#include "base/out_fwd.h"
Mathieu Chartiercc5ebdf2015-07-27 11:19:43 -070029#include "class_table.h"
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070030#include "dex_file.h"
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -070031#include "gc_root.h"
Mathieu Chartier590fee92013-09-13 13:46:47 -070032#include "jni.h"
Brian Carlstrom58ae9412011-10-04 00:56:06 -070033#include "oat_file.h"
Mathieu Chartier83c8ee02014-01-28 14:50:23 -080034#include "object_callbacks.h"
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070035
36namespace art {
Mingyao Yang98d1cc82014-05-15 17:02:16 -070037
Ian Rogers1d54e732013-05-02 21:10:01 -070038namespace gc {
39namespace space {
40 class ImageSpace;
41} // namespace space
42} // namespace gc
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080043namespace mirror {
Ian Rogers33e95662013-05-20 20:29:14 -070044 class ClassLoader;
45 class DexCache;
Mathieu Chartiere401d142015-04-22 13:56:20 -070046 class DexCachePointerArray;
Ian Rogers33e95662013-05-20 20:29:14 -070047 class DexCacheTest_Open_Test;
48 class IfTable;
49 template<class T> class ObjectArray;
50 class StackTraceElement;
51} // namespace mirror
Ian Rogers1d54e732013-05-02 21:10:01 -070052
Andreas Gampe5a4b8a22014-09-11 08:30:08 -070053template<class T> class Handle;
Hiroshi Yamauchi679b1cf2015-05-21 12:05:27 -070054template<class T> class MutableHandle;
Elliott Hughescf4c6c42011-09-01 15:16:42 -070055class InternTable;
Mathieu Chartierc528dba2013-11-26 12:00:11 -080056template<class T> class ObjectLock;
Andreas Gampe7ba64962014-10-23 11:37:40 -070057class Runtime;
Mathieu Chartier2b7c4d12014-05-19 10:52:16 -070058class ScopedObjectAccessAlreadyRunnable;
Mathieu Chartier2d2621a2014-10-23 16:48:06 -070059template<size_t kNumReferences> class PACKED(4) StackHandleScope;
Elliott Hughescf4c6c42011-09-01 15:16:42 -070060
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)
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700112 SHARED_REQUIRES(Locks::mutator_lock_)
113 REQUIRES(!dex_lock_);
Mathieu Chartier590fee92013-09-13 13:46:47 -0700114
115 // Initialize class linker from one or more images.
Mathieu Chartier90443472015-07-16 20:32:27 -0700116 void InitFromImage() SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!dex_lock_);
Mathieu Chartier590fee92013-09-13 13:46:47 -0700117
Elliott Hughes64bf5a32011-09-20 14:43:12 -0700118 // Finds a class by its descriptor, loading it if necessary.
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700119 // If class_loader is null, searches boot_class_path_.
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700120 mirror::Class* FindClass(Thread* self,
121 const char* descriptor,
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700122 Handle<mirror::ClassLoader> class_loader)
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700123 SHARED_REQUIRES(Locks::mutator_lock_)
124 REQUIRES(!dex_lock_);
Brian Carlstromaded5f72011-10-07 17:15:04 -0700125
Andreas Gampef865ea92015-04-13 22:14:19 -0700126 // Finds a class in the path class loader, loading it if necessary without using JNI. Hash
127 // function is supposed to be ComputeModifiedUtf8Hash(descriptor). Returns true if the
128 // class-loader chain could be handled, false otherwise, i.e., a non-supported class-loader
129 // was encountered while walking the parent chain (currently only BootClassLoader and
130 // PathClassLoader are supported).
131 bool FindClassInPathClassLoader(ScopedObjectAccessAlreadyRunnable& soa,
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700132 Thread* self,
133 const char* descriptor,
134 size_t hash,
Andreas Gampef865ea92015-04-13 22:14:19 -0700135 Handle<mirror::ClassLoader> class_loader,
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700136 out<mirror::Class*> result)
137 SHARED_REQUIRES(Locks::mutator_lock_)
138 REQUIRES(!dex_lock_);
Mathieu Chartierab0ed822014-09-11 14:21:41 -0700139
Ian Rogers98379392014-02-24 16:53:16 -0800140 // Finds a class by its descriptor using the "system" class loader, ie by searching the
141 // boot_class_path_.
142 mirror::Class* FindSystemClass(Thread* self, const char* descriptor)
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700143 SHARED_REQUIRES(Locks::mutator_lock_)
144 REQUIRES(!dex_lock_);
Ian Rogers98379392014-02-24 16:53:16 -0800145
146 // Finds the array class given for the element class.
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700147 mirror::Class* FindArrayClass(Thread* self, /* in parameter */ mirror::Class** element_class)
148 SHARED_REQUIRES(Locks::mutator_lock_)
149 REQUIRES(!dex_lock_);
Brian Carlstromaded5f72011-10-07 17:15:04 -0700150
Ian Rogers63557452014-06-04 16:57:15 -0700151 // Returns true if the class linker is initialized.
Ian Rogers7b078e82014-09-10 14:44:24 -0700152 bool IsInitialized() const {
153 return init_done_;
154 }
Mathieu Chartier590fee92013-09-13 13:46:47 -0700155
Brian Carlstromaded5f72011-10-07 17:15:04 -0700156 // Define a new a class based on a ClassDef from a DexFile
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700157 mirror::Class* DefineClass(Thread* self,
158 const char* descriptor,
159 size_t hash,
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700160 Handle<mirror::ClassLoader> class_loader,
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700161 const DexFile& dex_file,
162 const DexFile::ClassDef& dex_class_def)
163 SHARED_REQUIRES(Locks::mutator_lock_)
164 REQUIRES(!dex_lock_);
Elliott Hughes64bf5a32011-09-20 14:43:12 -0700165
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700166 // Finds a class by its descriptor, returning null if it isn't wasn't loaded
Elliott Hughes64bf5a32011-09-20 14:43:12 -0700167 // by the given 'class_loader'.
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700168 mirror::Class* LookupClass(Thread* self,
169 const char* descriptor,
170 size_t hash,
171 mirror::ClassLoader*
172 class_loader)
Mathieu Chartier90443472015-07-16 20:32:27 -0700173 REQUIRES(!Locks::classlinker_classes_lock_)
174 SHARED_REQUIRES(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700175
Elliott Hughes6fa602d2011-12-02 17:54:25 -0800176 // Finds all the classes with the given descriptor, regardless of ClassLoader.
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700177 void LookupClasses(const char* descriptor, out<std::vector<mirror::Class*>> classes)
Mathieu Chartier90443472015-07-16 20:32:27 -0700178 REQUIRES(!Locks::classlinker_classes_lock_)
179 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes6fa602d2011-12-02 17:54:25 -0800180
Mathieu Chartier90443472015-07-16 20:32:27 -0700181 mirror::Class* FindPrimitiveClass(char type) SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700182
Brian Carlstromae826982011-11-09 01:33:42 -0800183 // General class unloading is not supported, this is used to prune
184 // unwanted classes during image writing.
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700185 bool RemoveClass(const char* descriptor,
186 mirror::ClassLoader* class_loader)
187 REQUIRES(!Locks::classlinker_classes_lock_)
188 SHARED_REQUIRES(Locks::mutator_lock_);
Brian Carlstromae826982011-11-09 01:33:42 -0800189
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700190 void DumpAllClasses(int flags)
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700191 REQUIRES(!Locks::classlinker_classes_lock_)
192 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes9d5ccec2011-09-19 13:19:50 -0700193
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700194 void DumpForSigQuit(std::ostream& os)
Mathieu Chartier90443472015-07-16 20:32:27 -0700195 REQUIRES(!Locks::classlinker_classes_lock_);
Elliott Hughescac6cc72011-11-03 20:31:21 -0700196
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700197 size_t NumLoadedClasses()
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700198 REQUIRES(!Locks::classlinker_classes_lock_)
199 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughese27955c2011-08-26 15:21:24 -0700200
Brian Carlstromb63ec392011-08-27 17:38:27 -0700201 // Resolve a String with the given index from the DexFile, storing the
Brian Carlstromaded5f72011-10-07 17:15:04 -0700202 // result in the DexCache. The referrer is used to identify the
203 // target DexCache and ClassLoader to use for resolution.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700204 mirror::String* ResolveString(uint32_t string_idx, ArtMethod* referrer)
Mathieu Chartier90443472015-07-16 20:32:27 -0700205 SHARED_REQUIRES(Locks::mutator_lock_);
Brian Carlstromaded5f72011-10-07 17:15:04 -0700206
207 // Resolve a String with the given index from the DexFile, storing the
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700208 // result in the DexCache.
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700209 mirror::String* ResolveString(const DexFile& dex_file,
210 uint32_t string_idx,
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700211 Handle<mirror::DexCache> dex_cache)
Mathieu Chartier90443472015-07-16 20:32:27 -0700212 SHARED_REQUIRES(Locks::mutator_lock_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700213
Brian Carlstromb63ec392011-08-27 17:38:27 -0700214 // Resolve a Type with the given index from the DexFile, storing the
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700215 // result in the DexCache. The referrer is used to identity the
216 // target DexCache and ClassLoader to use for resolution.
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700217 mirror::Class* ResolveType(const DexFile& dex_file,
218 uint16_t type_idx,
219 mirror::Class* referrer)
220 SHARED_REQUIRES(Locks::mutator_lock_)
221 REQUIRES(!dex_lock_, !Roles::uninterruptible_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700222
Brian Carlstromb63ec392011-08-27 17:38:27 -0700223 // Resolve a Type with the given index from the DexFile, storing the
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700224 // result in the DexCache. The referrer is used to identify the
Brian Carlstromb63ec392011-08-27 17:38:27 -0700225 // target DexCache and ClassLoader to use for resolution.
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700226 mirror::Class* ResolveType(uint16_t type_idx,
227 ArtMethod* referrer)
228 SHARED_REQUIRES(Locks::mutator_lock_)
229 REQUIRES(!dex_lock_, !Roles::uninterruptible_);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700230
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700231 mirror::Class* ResolveType(uint16_t type_idx,
232 ArtField* referrer)
233 SHARED_REQUIRES(Locks::mutator_lock_)
234 REQUIRES(!dex_lock_, !Roles::uninterruptible_);
Brian Carlstromb63ec392011-08-27 17:38:27 -0700235
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700236 // Resolve a type with the given ID from the DexFile, storing the
237 // result in DexCache. The ClassLoader is used to search for the
238 // type, since it may be referenced from but not contained within
239 // the given DexFile.
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700240 mirror::Class* ResolveType(const DexFile& dex_file,
241 uint16_t type_idx,
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700242 Handle<mirror::DexCache> dex_cache,
243 Handle<mirror::ClassLoader> class_loader)
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700244 SHARED_REQUIRES(Locks::mutator_lock_)
245 REQUIRES(!dex_lock_, !Roles::uninterruptible_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700246
247 // Resolve a method with a given ID from the DexFile, storing the
248 // result in DexCache. The ClassLinker and ClassLoader are used as
249 // in ResolveType. What is unique is the method type argument which
250 // is used to determine if this method is a direct, static, or
251 // virtual method.
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700252 ArtMethod* ResolveMethod(const DexFile& dex_file,
253 uint32_t method_idx,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700254 Handle<mirror::DexCache> dex_cache,
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700255 Handle<mirror::ClassLoader> class_loader,
256 ArtMethod* referrer,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700257 InvokeType type)
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700258 SHARED_REQUIRES(Locks::mutator_lock_)
259 REQUIRES(!dex_lock_, !Roles::uninterruptible_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700260
Mathieu Chartiere401d142015-04-22 13:56:20 -0700261 ArtMethod* GetResolvedMethod(uint32_t method_idx, ArtMethod* referrer)
Mathieu Chartier90443472015-07-16 20:32:27 -0700262 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700263 ArtMethod* ResolveMethod(Thread* self, uint32_t method_idx, ArtMethod* referrer, InvokeType type)
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700264 SHARED_REQUIRES(Locks::mutator_lock_)
265 REQUIRES(!dex_lock_, !Roles::uninterruptible_);
Brian Carlstrom16192862011-09-12 17:50:06 -0700266
Mathieu Chartierc7853442015-03-27 14:35:38 -0700267 ArtField* GetResolvedField(uint32_t field_idx, mirror::Class* field_declaring_class)
Mathieu Chartier90443472015-07-16 20:32:27 -0700268 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartierc7853442015-03-27 14:35:38 -0700269 ArtField* GetResolvedField(uint32_t field_idx, mirror::DexCache* dex_cache)
Mathieu Chartier90443472015-07-16 20:32:27 -0700270 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700271 ArtField* ResolveField(uint32_t field_idx, ArtMethod* referrer, bool is_static)
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700272 SHARED_REQUIRES(Locks::mutator_lock_)
273 REQUIRES(!dex_lock_, !Roles::uninterruptible_);
Brian Carlstromb9edb842011-08-28 16:31:06 -0700274
Brian Carlstrom16192862011-09-12 17:50:06 -0700275 // Resolve a field with a given ID from the DexFile, storing the
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700276 // result in DexCache. The ClassLinker and ClassLoader are used as
277 // in ResolveType. What is unique is the is_static argument which is
278 // used to determine if we are resolving a static or non-static
279 // field.
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700280 ArtField* ResolveField(const DexFile& dex_file,
281 uint32_t field_idx,
Mathieu Chartier90443472015-07-16 20:32:27 -0700282 Handle<mirror::DexCache> dex_cache,
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700283 Handle<mirror::ClassLoader> class_loader,
284 bool is_static)
285 SHARED_REQUIRES(Locks::mutator_lock_)
286 REQUIRES(!dex_lock_, !Roles::uninterruptible_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700287
Ian Rogersb067ac22011-12-13 18:05:09 -0800288 // Resolve a field with a given ID from the DexFile, storing the
289 // result in DexCache. The ClassLinker and ClassLoader are used as
290 // in ResolveType. No is_static argument is provided so that Java
291 // field resolution semantics are followed.
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700292 ArtField* ResolveFieldJLS(const DexFile& dex_file,
293 uint32_t field_idx,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700294 Handle<mirror::DexCache> dex_cache,
295 Handle<mirror::ClassLoader> class_loader)
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700296 SHARED_REQUIRES(Locks::mutator_lock_)
297 REQUIRES(!dex_lock_, !Roles::uninterruptible_);
Ian Rogersb067ac22011-12-13 18:05:09 -0800298
Ian Rogersad25ac52011-10-04 19:13:33 -0700299 // Get shorty from method index without resolution. Used to do handlerization.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700300 const char* MethodShorty(uint32_t method_idx, ArtMethod* referrer, uint32_t* length)
Mathieu Chartier90443472015-07-16 20:32:27 -0700301 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersad25ac52011-10-04 19:13:33 -0700302
Elliott Hughesf4c21c92011-08-19 17:31:31 -0700303 // Returns true on success, false if there's an exception pending.
Brian Carlstrom25c33252011-09-18 15:58:35 -0700304 // can_run_clinit=false allows the compiler to attempt to init a class,
305 // given the restriction that no <clinit> execution is possible.
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700306 bool EnsureInitialized(Thread* self,
307 Handle<mirror::Class> c,
308 bool can_init_fields,
Ian Rogers7b078e82014-09-10 14:44:24 -0700309 bool can_init_parents)
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700310 SHARED_REQUIRES(Locks::mutator_lock_)
311 REQUIRES(!dex_lock_, !Roles::uninterruptible_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700312
Elliott Hughes2a20cfd2011-09-23 19:30:41 -0700313 // Initializes classes that have instances in the image but that have
314 // <clinit> methods so they could not be initialized by the compiler.
Mathieu Chartier4e2cb092015-07-22 16:17:51 -0700315 void RunRootClinits() SHARED_REQUIRES(Locks::mutator_lock_)
316 REQUIRES(!dex_lock_, !Roles::uninterruptible_);
Elliott Hughes2a20cfd2011-09-23 19:30:41 -0700317
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700318 void RegisterDexFile(const DexFile& dex_file)
Mathieu Chartier90443472015-07-16 20:32:27 -0700319 REQUIRES(!dex_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700320 void RegisterDexFile(const DexFile& dex_file, Handle<mirror::DexCache> dex_cache)
Mathieu Chartier90443472015-07-16 20:32:27 -0700321 REQUIRES(!dex_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700322
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700323 const OatFile* RegisterOatFile(const OatFile* oat_file)
Mathieu Chartier90443472015-07-16 20:32:27 -0700324 REQUIRES(!dex_lock_);
Brian Carlstrom866c8622012-01-06 16:35:13 -0800325
Brian Carlstrom8a487412011-08-29 20:08:52 -0700326 const std::vector<const DexFile*>& GetBootClassPath() {
327 return boot_class_path_;
328 }
329
Sebastien Hertz0de11332015-05-13 12:14:05 +0200330 // Returns the first non-image oat file in the class path.
331 const OatFile* GetPrimaryOatFile()
Mathieu Chartier90443472015-07-16 20:32:27 -0700332 REQUIRES(!dex_lock_);
Sebastien Hertz0de11332015-05-13 12:14:05 +0200333
Mathieu Chartiere0671ce2015-07-28 17:23:28 -0700334 void VisitClasses(ClassVisitor* visitor)
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700335 REQUIRES(!Locks::classlinker_classes_lock_)
336 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersdbf3be02014-08-29 15:40:08 -0700337
338 // Less efficient variant of VisitClasses that copies the class_table_ into secondary storage
339 // so that it can visit individual classes without holding the doesn't hold the
340 // Locks::classlinker_classes_lock_. As the Locks::classlinker_classes_lock_ isn't held this code
341 // can race with insertion and deletion of classes while the visitor is being called.
Mathieu Chartiere0671ce2015-07-28 17:23:28 -0700342 void VisitClassesWithoutClassesLock(ClassVisitor* visitor)
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700343 SHARED_REQUIRES(Locks::mutator_lock_)
344 REQUIRES(!dex_lock_);
Elliott Hughesa2155262011-11-16 16:26:58 -0800345
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -0700346 void VisitClassRoots(RootVisitor* visitor, VisitRootFlags flags)
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700347 REQUIRES(!Locks::classlinker_classes_lock_)
348 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -0700349 void VisitRoots(RootVisitor* visitor, VisitRootFlags flags)
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700350 REQUIRES(!dex_lock_)
351 SHARED_REQUIRES(Locks::mutator_lock_);
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700352
Hiroshi Yamauchie9e3e692014-06-24 14:31:37 -0700353 mirror::DexCache* FindDexCache(const DexFile& dex_file)
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700354 REQUIRES(!dex_lock_)
355 SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchie9e3e692014-06-24 14:31:37 -0700356 bool IsDexFileRegistered(const DexFile& dex_file)
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700357 REQUIRES(!dex_lock_)
358 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700359 void FixupDexCaches(ArtMethod* resolution_method)
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700360 REQUIRES(!dex_lock_)
361 SHARED_REQUIRES(Locks::mutator_lock_);
Brian Carlstrom1d9f52b2011-10-13 10:50:45 -0700362
Richard Uhler66d874d2015-01-15 09:37:19 -0800363 // Finds or creates the oat file holding dex_location. Then loads and returns
364 // all corresponding dex files (there may be more than one dex file loaded
365 // in the case of multidex).
366 // This may return the original, unquickened dex files if the oat file could
367 // not be generated.
368 //
369 // Returns an empty vector if the dex files could not be loaded. In this
370 // case, there will be at least one error message returned describing why no
371 // dex files could not be loaded. The 'error_msgs' argument must not be
372 // null, regardless of whether there is an error or not.
373 //
374 // This method should not be called with the mutator_lock_ held, because it
375 // could end up starving GC if we need to generate or relocate any oat
376 // files.
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700377 std::vector<std::unique_ptr<const DexFile>> OpenDexFilesFromOat(const char* dex_location,
378 const char* oat_location,
379 out<std::vector<std::string>>
380 error_msgs)
Mathieu Chartier90443472015-07-16 20:32:27 -0700381 REQUIRES(!dex_lock_, !Locks::mutator_lock_);
jeffhaof6174e82012-01-31 16:14:17 -0800382
Ian Rogersc0542af2014-09-03 16:16:56 -0700383 // Allocate an instance of a java.lang.Object.
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700384 mirror::Object* AllocObject(Thread* self)
385 SHARED_REQUIRES(Locks::mutator_lock_)
Mathieu Chartier4e2cb092015-07-22 16:17:51 -0700386 REQUIRES(!Roles::uninterruptible_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700387
Elliott Hughes418d20f2011-09-22 14:00:39 -0700388 // TODO: replace this with multiple methods that allocate the correct managed type.
Shih-wei Liao44175362011-08-28 16:59:17 -0700389 template <class T>
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800390 mirror::ObjectArray<T>* AllocObjectArray(Thread* self, size_t length)
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700391 SHARED_REQUIRES(Locks::mutator_lock_)
392 REQUIRES(!Roles::uninterruptible_);
Shih-wei Liao55df06b2011-08-26 14:39:27 -0700393
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800394 mirror::ObjectArray<mirror::Class>* AllocClassArray(Thread* self, size_t length)
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700395 SHARED_REQUIRES(Locks::mutator_lock_)
396 REQUIRES(!Roles::uninterruptible_);
jeffhao98eacac2011-09-14 16:11:53 -0700397
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800398 mirror::ObjectArray<mirror::String>* AllocStringArray(Thread* self, size_t length)
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700399 SHARED_REQUIRES(Locks::mutator_lock_)
400 REQUIRES(!Roles::uninterruptible_);
Mathieu Chartier4e2cb092015-07-22 16:17:51 -0700401
402 ArtField* AllocArtFieldArray(Thread* self, size_t length);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800403
Mathieu Chartiere401d142015-04-22 13:56:20 -0700404 ArtMethod* AllocArtMethodArray(Thread* self, size_t length);
405
406 mirror::PointerArray* AllocPointerArray(Thread* self, size_t length)
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700407 SHARED_REQUIRES(Locks::mutator_lock_)
408 REQUIRES(!Roles::uninterruptible_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800409
410 mirror::IfTable* AllocIfTable(Thread* self, size_t ifcount)
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700411 SHARED_REQUIRES(Locks::mutator_lock_)
412 REQUIRES(!Roles::uninterruptible_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800413
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700414 mirror::ObjectArray<mirror::StackTraceElement>* AllocStackTraceElementArray(Thread* self,
415 size_t length)
416 SHARED_REQUIRES(Locks::mutator_lock_)
417 REQUIRES(!Roles::uninterruptible_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800418
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700419 void VerifyClass(Thread* self, Handle<mirror::Class> klass)
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700420 SHARED_REQUIRES(Locks::mutator_lock_)
421 REQUIRES(!dex_lock_);
422 bool VerifyClassUsingOatFile(const DexFile& dex_file,
423 mirror::Class* klass,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800424 mirror::Class::Status& oat_file_class_status)
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700425 SHARED_REQUIRES(Locks::mutator_lock_)
426 REQUIRES(!dex_lock_);
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800427 void ResolveClassExceptionHandlerTypes(const DexFile& dex_file,
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700428 Handle<mirror::Class> klass)
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700429 SHARED_REQUIRES(Locks::mutator_lock_)
430 REQUIRES(!dex_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700431 void ResolveMethodExceptionHandlerTypes(const DexFile& dex_file, ArtMethod* klass)
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700432 SHARED_REQUIRES(Locks::mutator_lock_)
433 REQUIRES(!dex_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800434
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700435 mirror::Class* CreateProxyClass(ScopedObjectAccessAlreadyRunnable& soa,
436 jstring name,
437 jobjectArray interfaces,
438 jobject loader,
439 jobjectArray methods,
Mathieu Chartier2b7c4d12014-05-19 10:52:16 -0700440 jobjectArray throws)
Mathieu Chartier90443472015-07-16 20:32:27 -0700441 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800442 std::string GetDescriptorForProxy(mirror::Class* proxy_class)
Mathieu Chartier90443472015-07-16 20:32:27 -0700443 SHARED_REQUIRES(Locks::mutator_lock_);
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700444 ArtMethod* FindMethodForProxy(mirror::Class* proxy_class,
445 ArtMethod* proxy_method)
Mathieu Chartier90443472015-07-16 20:32:27 -0700446 REQUIRES(!dex_lock_)
447 SHARED_REQUIRES(Locks::mutator_lock_);
Jesse Wilson95caa792011-10-12 18:14:17 -0400448
Ian Rogers19846512012-02-24 11:42:47 -0800449 // Get the oat code for a method when its class isn't yet initialized
Mathieu Chartiere401d142015-04-22 13:56:20 -0700450 const void* GetQuickOatCodeFor(ArtMethod* method)
Mathieu Chartier90443472015-07-16 20:32:27 -0700451 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers19846512012-02-24 11:42:47 -0800452
Mathieu Chartiere35517a2012-10-30 18:49:55 -0700453 // Get the oat code for a method from a method index.
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700454 const void* GetQuickOatCodeFor(const DexFile& dex_file,
455 uint16_t class_def_idx,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700456 uint32_t method_idx)
Mathieu Chartier90443472015-07-16 20:32:27 -0700457 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere35517a2012-10-30 18:49:55 -0700458
Hiroshi Yamauchi9bdec882014-08-15 17:11:12 -0700459 // Get compiled code for a method, return null if no code
460 // exists. This is unlike Get..OatCodeFor which will return a bridge
461 // or interpreter entrypoint.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700462 const void* GetOatMethodQuickCodeFor(ArtMethod* method)
Mathieu Chartier90443472015-07-16 20:32:27 -0700463 SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchi9bdec882014-08-15 17:11:12 -0700464
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700465 const OatFile::OatMethod FindOatMethodFor(ArtMethod* method, out<bool> found)
Mathieu Chartier90443472015-07-16 20:32:27 -0700466 SHARED_REQUIRES(Locks::mutator_lock_);
Nicolas Geoffray9523a3e2015-07-17 11:51:28 +0000467
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700468 pid_t GetClassesLockOwner(); // For SignalCatcher.
469 pid_t GetDexLockOwner(); // For SignalCatcher.
Brian Carlstrom24a3c2e2011-10-17 18:07:52 -0700470
Mathieu Chartier90443472015-07-16 20:32:27 -0700471 mirror::Class* GetClassRoot(ClassRoot class_root) SHARED_REQUIRES(Locks::mutator_lock_);
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700472
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700473 static const char* GetClassRootDescriptor(ClassRoot class_root);
Andreas Gampe2da88232014-02-27 12:26:20 -0800474
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700475 // Is the given entry point quick code to run the resolution stub?
476 bool IsQuickResolutionStub(const void* entry_point) const;
Jeff Hao88474b42013-10-23 16:24:40 -0700477
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700478 // Is the given entry point quick code to bridge into the interpreter?
479 bool IsQuickToInterpreterBridge(const void* entry_point) const;
480
481 // Is the given entry point quick code to run the generic JNI stub?
482 bool IsQuickGenericJniStub(const void* entry_point) const;
Vladimir Marko8a630572014-04-09 18:45:35 +0100483
Jeff Hao88474b42013-10-23 16:24:40 -0700484 InternTable* GetInternTable() const {
485 return intern_table_;
486 }
487
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700488 // Set the entrypoints up for method to the given code.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700489 void SetEntryPointsToCompiledCode(ArtMethod* method, const void* method_code) const
Mathieu Chartier90443472015-07-16 20:32:27 -0700490 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700491
492 // Set the entrypoints up for method to the enter the interpreter.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700493 void SetEntryPointsToInterpreter(ArtMethod* method) const
Mathieu Chartier90443472015-07-16 20:32:27 -0700494 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700495
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700496 // Attempts to insert a class into a class table. Returns null if
Ian Rogers848871b2013-08-05 10:56:33 -0700497 // the class was inserted, otherwise returns an existing class with
498 // the same descriptor and ClassLoader.
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700499 mirror::Class* InsertClass(const char* descriptor, mirror::Class* klass, size_t hash)
Mathieu Chartier90443472015-07-16 20:32:27 -0700500 REQUIRES(!Locks::classlinker_classes_lock_)
501 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers848871b2013-08-05 10:56:33 -0700502
Mathieu Chartier90443472015-07-16 20:32:27 -0700503 mirror::ObjectArray<mirror::Class>* GetClassRoots() SHARED_REQUIRES(Locks::mutator_lock_) {
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -0700504 mirror::ObjectArray<mirror::Class>* class_roots = class_roots_.Read();
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700505 DCHECK(class_roots != nullptr);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700506 return class_roots;
507 }
508
Mathieu Chartierc2e20622014-11-03 11:41:47 -0800509 // Move all of the image classes into the class table for faster lookups.
510 void MoveImageClassesToClassTable()
Mathieu Chartier90443472015-07-16 20:32:27 -0700511 REQUIRES(!Locks::classlinker_classes_lock_)
512 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartierc2e20622014-11-03 11:41:47 -0800513 // Move the class table to the pre-zygote table to reduce memory usage. This works by ensuring
514 // that no more classes are ever added to the pre zygote table which makes it that the pages
515 // always remain shared dirty instead of private dirty.
516 void MoveClassTableToPreZygote()
Mathieu Chartier90443472015-07-16 20:32:27 -0700517 REQUIRES(!Locks::classlinker_classes_lock_)
518 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartierc2e20622014-11-03 11:41:47 -0800519
Sebastien Hertz6963e442014-11-26 22:11:27 +0100520 // Returns true if the method can be called with its direct code pointer, false otherwise.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700521 bool MayBeCalledWithDirectCodePointer(ArtMethod* m)
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700522 SHARED_REQUIRES(Locks::mutator_lock_)
523 REQUIRES(!dex_lock_);
Sebastien Hertz6963e442014-11-26 22:11:27 +0100524
Andreas Gampe81c6f8d2015-03-25 17:19:53 -0700525 // Creates a GlobalRef PathClassLoader that can be used to load classes from the given dex files.
526 // Note: the objects are not completely set up. Do not use this outside of tests and the compiler.
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700527 jobject CreatePathClassLoader(Thread* self, const std::vector<const DexFile*>& dex_files)
528 SHARED_REQUIRES(Locks::mutator_lock_)
529 REQUIRES(!dex_lock_);
Andreas Gampe81c6f8d2015-03-25 17:19:53 -0700530
Mathieu Chartiere401d142015-04-22 13:56:20 -0700531 size_t GetImagePointerSize() const {
532 DCHECK(ValidPointerSize(image_pointer_size_)) << image_pointer_size_;
533 return image_pointer_size_;
534 }
535
536 // Used by image writer for checking.
537 bool ClassInClassTable(mirror::Class* klass)
Mathieu Chartier90443472015-07-16 20:32:27 -0700538 REQUIRES(!Locks::classlinker_classes_lock_)
539 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiera89d7ed2014-12-05 10:57:13 -0800540
Mathieu Chartiere401d142015-04-22 13:56:20 -0700541 ArtMethod* CreateRuntimeMethod();
542
Andreas Gampe8ac75952015-06-02 21:01:45 -0700543 // Clear the ArrayClass cache. This is necessary when cleaning up for the image, as the cache
544 // entries are roots, but potentially not image classes.
Mathieu Chartier90443472015-07-16 20:32:27 -0700545 void DropFindArrayClassCache() SHARED_REQUIRES(Locks::mutator_lock_);
Andreas Gampe8ac75952015-06-02 21:01:45 -0700546
Mathieu Chartiere401d142015-04-22 13:56:20 -0700547 private:
Mathieu Chartiercc5ebdf2015-07-27 11:19:43 -0700548 class CompareClassLoaderGcRoot {
549 public:
550 bool operator()(const GcRoot<mirror::ClassLoader>& a, const GcRoot<mirror::ClassLoader>& b)
551 const SHARED_REQUIRES(Locks::mutator_lock_) {
552 return a.Read() < b.Read();
553 }
554 };
555
556 typedef SafeMap<GcRoot<mirror::ClassLoader>, ClassTable*, CompareClassLoaderGcRoot>
557 ClassLoaderClassTable;
558
Mathieu Chartiere0671ce2015-07-28 17:23:28 -0700559 void VisitClassesInternal(ClassVisitor* visitor)
Mathieu Chartiercc5ebdf2015-07-27 11:19:43 -0700560 REQUIRES(Locks::classlinker_classes_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
561
562 // Returns the number of zygote and image classes.
563 size_t NumZygoteClasses() const REQUIRES(Locks::classlinker_classes_lock_);
564
565 // Returns the number of non zygote nor image classes.
566 size_t NumNonZygoteClasses() const REQUIRES(Locks::classlinker_classes_lock_);
567
Brian Carlstrom56d947f2013-07-15 13:14:23 -0700568 OatFile& GetImageOatFile(gc::space::ImageSpace* space)
Mathieu Chartiercc5ebdf2015-07-27 11:19:43 -0700569 REQUIRES(!dex_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Brian Carlstroma663ea52011-08-19 23:33:41 -0700570
Mathieu Chartier4e2cb092015-07-22 16:17:51 -0700571 void FinishInit(Thread* self) SHARED_REQUIRES(Locks::mutator_lock_)
572 REQUIRES(!dex_lock_, !Roles::uninterruptible_);
Brian Carlstroma663ea52011-08-19 23:33:41 -0700573
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700574 // For early bootstrapping by Init
Ian Rogers6fac4472014-02-25 17:01:10 -0800575 mirror::Class* AllocClass(Thread* self, mirror::Class* java_lang_Class, uint32_t class_size)
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700576 SHARED_REQUIRES(Locks::mutator_lock_)
577 REQUIRES(!Roles::uninterruptible_);
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700578
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800579 // Alloc* convenience functions to avoid needing to pass in mirror::Class*
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700580 // values that are known to the ClassLinker such as
581 // kObjectArrayClass and kJavaLangString etc.
Ian Rogers6fac4472014-02-25 17:01:10 -0800582 mirror::Class* AllocClass(Thread* self, uint32_t class_size)
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700583 SHARED_REQUIRES(Locks::mutator_lock_)
584 REQUIRES(!Roles::uninterruptible_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800585 mirror::DexCache* AllocDexCache(Thread* self, const DexFile& dex_file)
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700586 SHARED_REQUIRES(Locks::mutator_lock_)
587 REQUIRES(!Roles::uninterruptible_);
Ian Rogersbdb03912011-09-14 00:55:44 -0700588
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800589 mirror::Class* CreatePrimitiveClass(Thread* self, Primitive::Type type)
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700590 SHARED_REQUIRES(Locks::mutator_lock_)
591 REQUIRES(!Roles::uninterruptible_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800592 mirror::Class* InitializePrimitiveClass(mirror::Class* primitive_class, Primitive::Type type)
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700593 SHARED_REQUIRES(Locks::mutator_lock_)
594 REQUIRES(!Roles::uninterruptible_);
Brian Carlstroma331b3c2011-07-18 17:47:56 -0700595
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700596 mirror::Class* CreateArrayClass(Thread* self,
597 const char* descriptor,
598 size_t hash,
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700599 Handle<mirror::ClassLoader> class_loader)
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700600 SHARED_REQUIRES(Locks::mutator_lock_)
601 REQUIRES(!dex_lock_, !Roles::uninterruptible_);
Brian Carlstroma331b3c2011-07-18 17:47:56 -0700602
Ian Rogers7b078e82014-09-10 14:44:24 -0700603 void AppendToBootClassPath(Thread* self, const DexFile& dex_file)
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700604 SHARED_REQUIRES(Locks::mutator_lock_)
605 REQUIRES(!dex_lock_);
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700606 void AppendToBootClassPath(const DexFile& dex_file, Handle<mirror::DexCache> dex_cache)
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700607 SHARED_REQUIRES(Locks::mutator_lock_)
608 REQUIRES(!dex_lock_);
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700609
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700610 // Precomputes size needed for Class, in the case of a non-temporary class this size must be
611 // sufficient to hold all static fields.
612 uint32_t SizeOfClassWithoutEmbeddedTables(const DexFile& dex_file,
613 const DexFile::ClassDef& dex_class_def);
Brian Carlstrom4873d462011-08-21 15:23:39 -0700614
Mathieu Chartierc7853442015-03-27 14:35:38 -0700615 // Setup the classloader, class def index, type idx so that we can insert this class in the class
616 // table.
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700617 void SetupClass(const DexFile& dex_file,
618 const DexFile::ClassDef& dex_class_def,
619 Handle<mirror::Class> klass,
620 mirror::ClassLoader* class_loader)
Mathieu Chartier90443472015-07-16 20:32:27 -0700621 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartierc7853442015-03-27 14:35:38 -0700622
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700623 void LoadClass(Thread* self,
624 const DexFile& dex_file,
625 const DexFile::ClassDef& dex_class_def,
Mathieu Chartierc7853442015-03-27 14:35:38 -0700626 Handle<mirror::Class> klass)
Mathieu Chartier90443472015-07-16 20:32:27 -0700627 SHARED_REQUIRES(Locks::mutator_lock_);
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700628 void LoadClassMembers(Thread* self,
629 const DexFile& dex_file,
630 const uint8_t* class_data,
631 Handle<mirror::Class> klass,
632 const OatFile::OatClass* oat_class)
Mathieu Chartier90443472015-07-16 20:32:27 -0700633 SHARED_REQUIRES(Locks::mutator_lock_);
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700634
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700635 void LoadField(const ClassDataItemIterator& it,
636 Handle<mirror::Class> klass,
Mathieu Chartierc7853442015-03-27 14:35:38 -0700637 ArtField* dst)
Mathieu Chartier90443472015-07-16 20:32:27 -0700638 SHARED_REQUIRES(Locks::mutator_lock_);
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700639
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700640 void LoadMethod(Thread* self,
641 const DexFile& dex_file,
642 const ClassDataItemIterator& it,
643 Handle<mirror::Class> klass,
644 ArtMethod* dst)
Mathieu Chartier90443472015-07-16 20:32:27 -0700645 SHARED_REQUIRES(Locks::mutator_lock_);
Brian Carlstrom934486c2011-07-12 23:42:50 -0700646
Mathieu Chartier90443472015-07-16 20:32:27 -0700647 void FixupStaticTrampolines(mirror::Class* klass) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers19846512012-02-24 11:42:47 -0800648
Ian Rogers97b52f82014-08-14 11:34:07 -0700649 // Finds the associated oat class for a dex_file and descriptor. Returns an invalid OatClass on
650 // error and sets found to false.
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700651 OatFile::OatClass FindOatClass(const DexFile& dex_file, uint16_t class_def_idx, out<bool> found)
Mathieu Chartier90443472015-07-16 20:32:27 -0700652 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers19846512012-02-24 11:42:47 -0800653
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700654 void RegisterDexFileLocked(const DexFile& dex_file, Handle<mirror::DexCache> dex_cache)
Mathieu Chartiercc5ebdf2015-07-27 11:19:43 -0700655 REQUIRES(dex_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchie9e3e692014-06-24 14:31:37 -0700656 bool IsDexFileRegisteredLocked(const DexFile& dex_file)
Mathieu Chartier90443472015-07-16 20:32:27 -0700657 SHARED_REQUIRES(dex_lock_, Locks::mutator_lock_);
Brian Carlstromaded5f72011-10-07 17:15:04 -0700658
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700659 bool InitializeClass(Thread* self,
660 Handle<mirror::Class> klass,
661 bool can_run_clinit,
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800662 bool can_init_parents)
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700663 SHARED_REQUIRES(Locks::mutator_lock_)
664 REQUIRES(!dex_lock_);
665 bool WaitForInitializeClass(Handle<mirror::Class> klass,
666 Thread* self,
667 ObjectLock<mirror::Class>* lock);
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700668 bool ValidateSuperClassDescriptors(Handle<mirror::Class> klass)
Mathieu Chartier90443472015-07-16 20:32:27 -0700669 SHARED_REQUIRES(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700670
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700671 bool IsSameDescriptorInDifferentClassContexts(Thread* self,
672 const char* descriptor,
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700673 Handle<mirror::ClassLoader> class_loader1,
674 Handle<mirror::ClassLoader> class_loader2)
Mathieu Chartier90443472015-07-16 20:32:27 -0700675 SHARED_REQUIRES(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700676
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700677 bool IsSameMethodSignatureInDifferentClassContexts(Thread* self,
678 ArtMethod* method,
679 mirror::Class* klass1,
680 mirror::Class* klass2)
Mathieu Chartier90443472015-07-16 20:32:27 -0700681 SHARED_REQUIRES(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700682
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700683 bool LinkClass(Thread* self,
684 const char* descriptor,
685 Handle<mirror::Class> klass,
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700686 Handle<mirror::ObjectArray<mirror::Class>> interfaces,
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700687 out<MutableHandle<mirror::Class>> h_new_class_out)
688 SHARED_REQUIRES(Locks::mutator_lock_)
689 REQUIRES(!Locks::classlinker_classes_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700690
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700691 bool LinkSuperClass(Handle<mirror::Class> klass)
Mathieu Chartier90443472015-07-16 20:32:27 -0700692 SHARED_REQUIRES(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700693
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700694 bool LoadSuperAndInterfaces(Handle<mirror::Class> klass, const DexFile& dex_file)
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700695 SHARED_REQUIRES(Locks::mutator_lock_)
696 REQUIRES(!dex_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700697
Mathieu Chartiercc5ebdf2015-07-27 11:19:43 -0700698 bool LinkMethods(Thread* self,
699 Handle<mirror::Class> klass,
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700700 Handle<mirror::ObjectArray<mirror::Class>> interfaces,
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700701 out<ArtMethod* [mirror::Class::kImtSize]> out_imt)
Mathieu Chartier90443472015-07-16 20:32:27 -0700702 SHARED_REQUIRES(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700703
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700704 bool LinkVirtualMethods(Thread* self, Handle<mirror::Class> klass)
Mathieu Chartier90443472015-07-16 20:32:27 -0700705 SHARED_REQUIRES(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700706
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700707 bool LinkInterfaceMethods(Thread* self,
708 Handle<mirror::Class> klass,
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700709 Handle<mirror::ObjectArray<mirror::Class>> interfaces,
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700710 out<ArtMethod* [mirror::Class::kImtSize]> out_imt)
Mathieu Chartier90443472015-07-16 20:32:27 -0700711 SHARED_REQUIRES(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700712
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700713 bool LinkStaticFields(Thread* self,
714 Handle<mirror::Class> klass,
715 out<size_t> class_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700716 SHARED_REQUIRES(Locks::mutator_lock_);
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700717 bool LinkInstanceFields(Thread* self, Handle<mirror::Class> klass)
Mathieu Chartier90443472015-07-16 20:32:27 -0700718 SHARED_REQUIRES(Locks::mutator_lock_);
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700719 bool LinkFields(Thread* self, Handle<mirror::Class> klass, bool is_static, out<size_t> class_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700720 SHARED_REQUIRES(Locks::mutator_lock_);
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700721 void LinkCode(ArtMethod* method,
722 const OatFile::OatClass* oat_class,
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700723 uint32_t class_def_method_index)
Mathieu Chartier90443472015-07-16 20:32:27 -0700724 SHARED_REQUIRES(Locks::mutator_lock_);
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700725 void CreateReferenceInstanceOffsets(Handle<mirror::Class> klass)
Mathieu Chartier90443472015-07-16 20:32:27 -0700726 SHARED_REQUIRES(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700727
Mathieu Chartiere401d142015-04-22 13:56:20 -0700728 void CheckProxyConstructor(ArtMethod* constructor) const
Mathieu Chartier90443472015-07-16 20:32:27 -0700729 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700730 void CheckProxyMethod(ArtMethod* method, ArtMethod* prototype) const
Mathieu Chartier90443472015-07-16 20:32:27 -0700731 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700732
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700733 // For use by ImageWriter to find DexCaches for its roots
Hiroshi Yamauchie9e3e692014-06-24 14:31:37 -0700734 ReaderWriterMutex* DexLock()
Mathieu Chartier90443472015-07-16 20:32:27 -0700735 SHARED_REQUIRES(Locks::mutator_lock_) LOCK_RETURNED(dex_lock_) {
Hiroshi Yamauchie9e3e692014-06-24 14:31:37 -0700736 return &dex_lock_;
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700737 }
Mathieu Chartier90443472015-07-16 20:32:27 -0700738 size_t GetDexCacheCount() SHARED_REQUIRES(Locks::mutator_lock_, dex_lock_) {
Hiroshi Yamauchie9e3e692014-06-24 14:31:37 -0700739 return dex_caches_.size();
740 }
Mathieu Chartier90443472015-07-16 20:32:27 -0700741 mirror::DexCache* GetDexCache(size_t idx) SHARED_REQUIRES(Locks::mutator_lock_, dex_lock_);
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700742
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700743 const OatFile* FindOpenedOatFileFromOatLocation(const std::string& oat_location)
Mathieu Chartier90443472015-07-16 20:32:27 -0700744 REQUIRES(!dex_lock_);
Andreas Gampe833a4852014-05-21 18:46:59 -0700745
Sebastien Hertz0de11332015-05-13 12:14:05 +0200746 // Returns the boot image oat file.
Mathieu Chartier90443472015-07-16 20:32:27 -0700747 const OatFile* GetBootOatFile() SHARED_REQUIRES(dex_lock_);
Sebastien Hertz0de11332015-05-13 12:14:05 +0200748
Mathieu Chartiere401d142015-04-22 13:56:20 -0700749 void CreateProxyConstructor(Handle<mirror::Class> klass, ArtMethod* out)
Mathieu Chartier90443472015-07-16 20:32:27 -0700750 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700751 void CreateProxyMethod(Handle<mirror::Class> klass, ArtMethod* prototype, ArtMethod* out)
Mathieu Chartier90443472015-07-16 20:32:27 -0700752 SHARED_REQUIRES(Locks::mutator_lock_);
Jesse Wilson95caa792011-10-12 18:14:17 -0400753
Andreas Gampe48498592014-09-10 19:48:05 -0700754 // Ensures that methods have the kAccPreverified bit set. We use the kAccPreverfied bit on the
755 // class access flags to determine whether this has been done before.
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700756 void EnsurePreverifiedMethods(Handle<mirror::Class> c)
Mathieu Chartier90443472015-07-16 20:32:27 -0700757 SHARED_REQUIRES(Locks::mutator_lock_);
Andreas Gampe48498592014-09-10 19:48:05 -0700758
Ian Rogersdbf3be02014-08-29 15:40:08 -0700759 mirror::Class* LookupClassFromImage(const char* descriptor)
Mathieu Chartier90443472015-07-16 20:32:27 -0700760 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersdbf3be02014-08-29 15:40:08 -0700761
Mathieu Chartiercc5ebdf2015-07-27 11:19:43 -0700762 // Returns null if not found.
763 ClassTable* ClassTableForClassLoader(mirror::ClassLoader* class_loader)
764 SHARED_REQUIRES(Locks::mutator_lock_, Locks::classlinker_classes_lock_);
765 // Insert a new class table if not found.
766 ClassTable* InsertClassTableForClassLoader(mirror::ClassLoader* class_loader)
767 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(Locks::classlinker_classes_lock_);
768
Ian Rogersdbf3be02014-08-29 15:40:08 -0700769 // EnsureResolved is called to make sure that a class in the class_table_ has been resolved
770 // before returning it to the caller. Its the responsibility of the thread that placed the class
771 // in the table to make it resolved. The thread doing resolution must notify on the class' lock
772 // when resolution has occurred. This happens in mirror::Class::SetStatus. As resolution may
773 // retire a class, the version of the class in the table is returned and this may differ from
774 // the class passed in.
775 mirror::Class* EnsureResolved(Thread* self, const char* descriptor, mirror::Class* klass)
Mathieu Chartier90443472015-07-16 20:32:27 -0700776 WARN_UNUSED SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!dex_lock_);
Ian Rogersdbf3be02014-08-29 15:40:08 -0700777
778 void FixupTemporaryDeclaringClass(mirror::Class* temp_class, mirror::Class* new_class)
Mathieu Chartier90443472015-07-16 20:32:27 -0700779 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersdbf3be02014-08-29 15:40:08 -0700780
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700781 void SetClassRoot(ClassRoot class_root, mirror::Class* klass)
Mathieu Chartier90443472015-07-16 20:32:27 -0700782 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700783
784 // Return the quick generic JNI stub for testing.
785 const void* GetRuntimeQuickGenericJniStub() const;
786
Andreas Gampebfdcdc12015-04-22 18:10:36 -0700787 // Throw the class initialization failure recorded when first trying to initialize the given
788 // class.
789 // Note: Currently we only store the descriptor, so we cannot throw the exact throwable, only
790 // a recreation with a custom string.
Mathieu Chartier90443472015-07-16 20:32:27 -0700791 void ThrowEarlierClassFailure(mirror::Class* c) SHARED_REQUIRES(Locks::mutator_lock_)
792 REQUIRES(!dex_lock_);
Andreas Gampebfdcdc12015-04-22 18:10:36 -0700793
Andreas Gampeb9aec2c2015-04-23 22:23:47 -0700794 // Check for duplicate class definitions of the given oat file against all open oat files.
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700795 bool HasCollisions(const OatFile* oat_file, out<std::string> error_msg) REQUIRES(!dex_lock_);
Andreas Gampeb9aec2c2015-04-23 22:23:47 -0700796
Mathieu Chartier90443472015-07-16 20:32:27 -0700797 bool HasInitWithString(Thread* self, const char* descriptor)
798 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!dex_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700799
800 bool CanWeInitializeClass(mirror::Class* klass, bool can_init_statics, bool can_init_parents)
Mathieu Chartier90443472015-07-16 20:32:27 -0700801 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700802
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700803 void UpdateClassVirtualMethods(mirror::Class* klass,
804 ArtMethod* new_methods,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700805 size_t new_num_methods)
Igor Murashkinbc1d78d2015-07-30 16:39:45 -0700806 SHARED_REQUIRES(Locks::mutator_lock_)
807 REQUIRES(!Locks::classlinker_classes_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700808
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700809 std::vector<const DexFile*> boot_class_path_;
Richard Uhlerfbef44d2014-12-23 09:48:51 -0800810 std::vector<std::unique_ptr<const DexFile>> opened_dex_files_;
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700811
Ian Rogers1bf8d4d2013-05-30 00:18:49 -0700812 mutable ReaderWriterMutex dex_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
Andreas Gampec8ccf682014-09-29 20:07:43 -0700813 std::vector<size_t> new_dex_cache_roots_ GUARDED_BY(dex_lock_);
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -0700814 std::vector<GcRoot<mirror::DexCache>> dex_caches_ GUARDED_BY(dex_lock_);
Elliott Hughesf8349362012-06-18 15:00:06 -0700815 std::vector<const OatFile*> oat_files_ GUARDED_BY(dex_lock_);
Brian Carlstrom47d237a2011-10-18 15:08:33 -0700816
Mathieu Chartiercc5ebdf2015-07-27 11:19:43 -0700817 // This contains strong roots. To enable concurrent root scanning of the class table.
818 ClassLoaderClassTable classes_ GUARDED_BY(Locks::classlinker_classes_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700819
Mathieu Chartiercc5ebdf2015-07-27 11:19:43 -0700820 // New class roots, only used by CMS since the GC needs to mark these in the pause.
821 std::vector<GcRoot<mirror::Class>> new_class_roots_ GUARDED_BY(Locks::classlinker_classes_lock_);
Elliott Hughesf8349362012-06-18 15:00:06 -0700822
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700823 // Do we need to search dex caches to find image classes?
824 bool dex_cache_image_class_lookup_required_;
825 // Number of times we've searched dex caches for a class. After a certain number of misses we move
826 // the classes into the class_table_ to avoid dex cache based searches.
Ian Rogers68b56852014-08-29 20:19:11 -0700827 Atomic<uint32_t> failed_dex_cache_class_lookups_;
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700828
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700829 // Well known mirror::Class roots.
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -0700830 GcRoot<mirror::ObjectArray<mirror::Class>> class_roots_;
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700831
Ian Rogers98379392014-02-24 16:53:16 -0800832 // The interface table used by all arrays.
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -0700833 GcRoot<mirror::IfTable> array_iftable_;
Carl Shapiro565f5072011-07-10 13:39:43 -0700834
Ian Rogers98379392014-02-24 16:53:16 -0800835 // A cache of the last FindArrayClass results. The cache serves to avoid creating array class
836 // descriptors for the sake of performing FindClass.
837 static constexpr size_t kFindArrayCacheSize = 16;
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -0700838 GcRoot<mirror::Class> find_array_class_cache_[kFindArrayCacheSize];
Ian Rogers98379392014-02-24 16:53:16 -0800839 size_t find_array_class_cache_next_victim_;
840
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700841 bool init_done_;
Mathieu Chartier893263b2014-03-04 11:07:42 -0800842 bool log_new_dex_caches_roots_ GUARDED_BY(dex_lock_);
843 bool log_new_class_table_roots_ GUARDED_BY(Locks::classlinker_classes_lock_);
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700844
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700845 InternTable* intern_table_;
846
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700847 // Trampolines within the image the bounce to runtime entrypoints. Done so that there is a single
848 // patch point within the image. TODO: make these proper relocations.
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700849 const void* quick_resolution_trampoline_;
Jeff Hao88474b42013-10-23 16:24:40 -0700850 const void* quick_imt_conflict_trampoline_;
Andreas Gampe2da88232014-02-27 12:26:20 -0800851 const void* quick_generic_jni_trampoline_;
Vladimir Marko8a630572014-04-09 18:45:35 +0100852 const void* quick_to_interpreter_bridge_trampoline_;
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700853
Mathieu Chartier2d721012014-11-10 11:08:06 -0800854 // Image pointer size.
855 size_t image_pointer_size_;
856
Brian Carlstrom34f426c2011-10-04 12:58:02 -0700857 friend class ImageWriter; // for GetClassRoots
Alex Lighta59dd802014-07-02 16:28:08 -0700858 friend class ImageDumper; // for FindOpenedOatFileFromOatLocation
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700859 friend class JniCompilerTest; // for GetRuntimeQuickGenericJniStub
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700860 ART_FRIEND_TEST(mirror::DexCacheTest, Open); // for AllocDexCache
861
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700862 DISALLOW_COPY_AND_ASSIGN(ClassLinker);
863};
864
865} // namespace art
866
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700867#endif // ART_RUNTIME_CLASS_LINKER_H_