blob: 577fec2419b048fca9f1e0ae2d13ce8e5ed4270d [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
Fred Shih37f05ef2014-07-16 18:38:08 -070020#include <deque>
Ian Rogers6d4d9fc2011-11-30 16:24:48 -080021#include <string>
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070022#include <utility>
23#include <vector>
24
Mathieu Chartierbad02672014-08-25 13:08:22 -070025#include "base/allocator.h"
Mathieu Chartierc2e20622014-11-03 11:41:47 -080026#include "base/hash_set.h"
Elliott Hughes76160052012-12-12 16:31:20 -080027#include "base/macros.h"
Elliott Hughes76b61672012-12-12 17:47:30 -080028#include "base/mutex.h"
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070029#include "dex_file.h"
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -070030#include "gc_root.h"
Mathieu Chartier590fee92013-09-13 13:46:47 -070031#include "jni.h"
Brian Carlstrom58ae9412011-10-04 00:56:06 -070032#include "oat_file.h"
Mathieu Chartier83c8ee02014-01-28 14:50:23 -080033#include "object_callbacks.h"
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070034
35namespace art {
Mingyao Yang98d1cc82014-05-15 17:02:16 -070036
Ian Rogers1d54e732013-05-02 21:10:01 -070037namespace gc {
38namespace space {
39 class ImageSpace;
40} // namespace space
41} // namespace gc
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080042namespace mirror {
Ian Rogers33e95662013-05-20 20:29:14 -070043 class ClassLoader;
44 class DexCache;
45 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;
Elliott Hughescf4c6c42011-09-01 15:16:42 -070052class InternTable;
Mathieu Chartierc528dba2013-11-26 12:00:11 -080053template<class T> class ObjectLock;
Andreas Gampe7ba64962014-10-23 11:37:40 -070054class Runtime;
Mathieu Chartier2b7c4d12014-05-19 10:52:16 -070055class ScopedObjectAccessAlreadyRunnable;
Mathieu Chartier2d2621a2014-10-23 16:48:06 -070056template<size_t kNumReferences> class PACKED(4) StackHandleScope;
Elliott Hughescf4c6c42011-09-01 15:16:42 -070057
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080058typedef bool (ClassVisitor)(mirror::Class* c, void* arg);
Elliott Hughesa2155262011-11-16 16:26:58 -080059
Mathieu Chartier893263b2014-03-04 11:07:42 -080060enum VisitRootFlags : uint8_t;
61
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070062class ClassLinker {
63 public:
Ian Rogers6f3dbba2014-10-14 17:41:57 -070064 // Well known mirror::Class roots accessed via GetClassRoot.
65 enum ClassRoot {
66 kJavaLangClass,
67 kJavaLangObject,
68 kClassArrayClass,
69 kObjectArrayClass,
70 kJavaLangString,
71 kJavaLangDexCache,
72 kJavaLangRefReference,
73 kJavaLangReflectArtField,
74 kJavaLangReflectArtMethod,
Mathieu Chartierdaaf3262015-03-24 13:30:28 -070075 kJavaLangReflectField,
Ian Rogers6f3dbba2014-10-14 17:41:57 -070076 kJavaLangReflectProxy,
77 kJavaLangStringArrayClass,
78 kJavaLangReflectArtFieldArrayClass,
79 kJavaLangReflectArtMethodArrayClass,
Mathieu Chartierdaaf3262015-03-24 13:30:28 -070080 kJavaLangReflectFieldArrayClass,
Ian Rogers6f3dbba2014-10-14 17:41:57 -070081 kJavaLangClassLoader,
82 kJavaLangThrowable,
83 kJavaLangClassNotFoundException,
84 kJavaLangStackTraceElement,
85 kPrimitiveBoolean,
86 kPrimitiveByte,
87 kPrimitiveChar,
88 kPrimitiveDouble,
89 kPrimitiveFloat,
90 kPrimitiveInt,
91 kPrimitiveLong,
92 kPrimitiveShort,
93 kPrimitiveVoid,
94 kBooleanArrayClass,
95 kByteArrayClass,
96 kCharArrayClass,
97 kDoubleArrayClass,
98 kFloatArrayClass,
99 kIntArrayClass,
100 kLongArrayClass,
101 kShortArrayClass,
102 kJavaLangStackTraceElementArrayClass,
103 kClassRootsMax,
104 };
105
Mathieu Chartier590fee92013-09-13 13:46:47 -0700106 explicit ClassLinker(InternTable* intern_table);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700107 ~ClassLinker();
Carl Shapiro565f5072011-07-10 13:39:43 -0700108
Alex Light64ad14d2014-08-19 14:23:13 -0700109 // Initialize class linker by bootstraping from dex files.
Richard Uhlerfbef44d2014-12-23 09:48:51 -0800110 void InitWithoutImage(std::vector<std::unique_ptr<const DexFile>> boot_class_path)
Mathieu Chartier590fee92013-09-13 13:46:47 -0700111 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
112
113 // Initialize class linker from one or more images.
114 void InitFromImage() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
115
Elliott Hughes64bf5a32011-09-20 14:43:12 -0700116 // Finds a class by its descriptor, loading it if necessary.
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700117 // If class_loader is null, searches boot_class_path_.
Ian Rogers98379392014-02-24 16:53:16 -0800118 mirror::Class* FindClass(Thread* self, const char* descriptor,
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700119 Handle<mirror::ClassLoader> class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700120 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromaded5f72011-10-07 17:15:04 -0700121
Ian Rogers32427292014-11-19 14:05:21 -0800122 // Find a class in the path class loader, loading it if necessary without using JNI. Hash
123 // function is supposed to be ComputeModifiedUtf8Hash(descriptor).
Mathieu Chartierab0ed822014-09-11 14:21:41 -0700124 mirror::Class* FindClassInPathClassLoader(ScopedObjectAccessAlreadyRunnable& soa,
Mathieu Chartiere7c9a8c2014-11-06 16:35:45 -0800125 Thread* self, const char* descriptor, size_t hash,
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700126 Handle<mirror::ClassLoader> class_loader)
Mathieu Chartierab0ed822014-09-11 14:21:41 -0700127 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
128
Ian Rogers98379392014-02-24 16:53:16 -0800129 // Finds a class by its descriptor using the "system" class loader, ie by searching the
130 // boot_class_path_.
131 mirror::Class* FindSystemClass(Thread* self, const char* descriptor)
132 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
133
134 // Finds the array class given for the element class.
Mathieu Chartierb74cd292014-05-29 14:31:33 -0700135 mirror::Class* FindArrayClass(Thread* self, mirror::Class** element_class)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700136 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromaded5f72011-10-07 17:15:04 -0700137
Ian Rogers63557452014-06-04 16:57:15 -0700138 // Returns true if the class linker is initialized.
Ian Rogers7b078e82014-09-10 14:44:24 -0700139 bool IsInitialized() const {
140 return init_done_;
141 }
Mathieu Chartier590fee92013-09-13 13:46:47 -0700142
Brian Carlstromaded5f72011-10-07 17:15:04 -0700143 // Define a new a class based on a ClassDef from a DexFile
Mathieu Chartiere7c9a8c2014-11-06 16:35:45 -0800144 mirror::Class* DefineClass(Thread* self, const char* descriptor, size_t hash,
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700145 Handle<mirror::ClassLoader> class_loader,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800146 const DexFile& dex_file, const DexFile::ClassDef& dex_class_def)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700147 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes64bf5a32011-09-20 14:43:12 -0700148
149 // Finds a class by its descriptor, returning NULL if it isn't wasn't loaded
150 // by the given 'class_loader'.
Mathieu Chartiere7c9a8c2014-11-06 16:35:45 -0800151 mirror::Class* LookupClass(Thread* self, const char* descriptor, size_t hash,
Mathieu Chartierc2e20622014-11-03 11:41:47 -0800152 mirror::ClassLoader* class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700153 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
154 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700155
Elliott Hughes6fa602d2011-12-02 17:54:25 -0800156 // Finds all the classes with the given descriptor, regardless of ClassLoader.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800157 void LookupClasses(const char* descriptor, std::vector<mirror::Class*>& classes)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700158 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
159 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes6fa602d2011-12-02 17:54:25 -0800160
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800161 mirror::Class* FindPrimitiveClass(char type) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700162
Brian Carlstromae826982011-11-09 01:33:42 -0800163 // General class unloading is not supported, this is used to prune
164 // unwanted classes during image writing.
Mathieu Chartierc2e20622014-11-03 11:41:47 -0800165 bool RemoveClass(const char* descriptor, mirror::ClassLoader* class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700166 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
167 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromae826982011-11-09 01:33:42 -0800168
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700169 void DumpAllClasses(int flags)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700170 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
171 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes9d5ccec2011-09-19 13:19:50 -0700172
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700173 void DumpForSigQuit(std::ostream& os)
Ian Rogers7b078e82014-09-10 14:44:24 -0700174 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_);
Elliott Hughescac6cc72011-11-03 20:31:21 -0700175
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700176 size_t NumLoadedClasses()
177 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
178 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughese27955c2011-08-26 15:21:24 -0700179
Brian Carlstromb63ec392011-08-27 17:38:27 -0700180 // Resolve a String with the given index from the DexFile, storing the
Brian Carlstromaded5f72011-10-07 17:15:04 -0700181 // result in the DexCache. The referrer is used to identify the
182 // target DexCache and ClassLoader to use for resolution.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800183 mirror::String* ResolveString(uint32_t string_idx, mirror::ArtMethod* referrer)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800184 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromaded5f72011-10-07 17:15:04 -0700185
186 // Resolve a String with the given index from the DexFile, storing the
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700187 // result in the DexCache.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800188 mirror::String* ResolveString(const DexFile& dex_file, uint32_t string_idx,
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700189 Handle<mirror::DexCache> dex_cache)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700190 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700191
Brian Carlstromb63ec392011-08-27 17:38:27 -0700192 // Resolve a Type with the given index from the DexFile, storing the
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700193 // result in the DexCache. The referrer is used to identity the
194 // target DexCache and ClassLoader to use for resolution.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800195 mirror::Class* ResolveType(const DexFile& dex_file, uint16_t type_idx, mirror::Class* referrer)
Mathieu Chartier590fee92013-09-13 13:46:47 -0700196 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700197
Brian Carlstromb63ec392011-08-27 17:38:27 -0700198 // Resolve a Type with the given index from the DexFile, storing the
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700199 // result in the DexCache. The referrer is used to identify the
Brian Carlstromb63ec392011-08-27 17:38:27 -0700200 // target DexCache and ClassLoader to use for resolution.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800201 mirror::Class* ResolveType(uint16_t type_idx, mirror::ArtMethod* referrer)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800202 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700203
Ian Rogersef7d42f2014-01-06 12:55:46 -0800204 mirror::Class* ResolveType(uint16_t type_idx, mirror::ArtField* referrer)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800205 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromb63ec392011-08-27 17:38:27 -0700206
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700207 // Resolve a type with the given ID from the DexFile, storing the
208 // result in DexCache. The ClassLoader is used to search for the
209 // type, since it may be referenced from but not contained within
210 // the given DexFile.
Mathieu Chartier590fee92013-09-13 13:46:47 -0700211 mirror::Class* ResolveType(const DexFile& dex_file, uint16_t type_idx,
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700212 Handle<mirror::DexCache> dex_cache,
213 Handle<mirror::ClassLoader> class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700214 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700215
216 // Resolve a method with a given ID from the DexFile, storing the
217 // result in DexCache. The ClassLinker and ClassLoader are used as
218 // in ResolveType. What is unique is the method type argument which
219 // is used to determine if this method is a direct, static, or
220 // virtual method.
Brian Carlstromea46f952013-07-30 01:26:50 -0700221 mirror::ArtMethod* ResolveMethod(const DexFile& dex_file,
222 uint32_t method_idx,
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700223 Handle<mirror::DexCache> dex_cache,
224 Handle<mirror::ClassLoader> class_loader,
225 Handle<mirror::ArtMethod> referrer,
Brian Carlstromea46f952013-07-30 01:26:50 -0700226 InvokeType type)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700227 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700228
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700229 mirror::ArtMethod* GetResolvedMethod(uint32_t method_idx, mirror::ArtMethod* referrer)
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700230 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
231 mirror::ArtMethod* ResolveMethod(Thread* self, uint32_t method_idx, mirror::ArtMethod** referrer,
Brian Carlstromea46f952013-07-30 01:26:50 -0700232 InvokeType type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800233 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom16192862011-09-12 17:50:06 -0700234
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700235 mirror::ArtField* GetResolvedField(uint32_t field_idx, mirror::Class* field_declaring_class)
236 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800237 mirror::ArtField* ResolveField(uint32_t field_idx, mirror::ArtMethod* referrer,
Brian Carlstromea46f952013-07-30 01:26:50 -0700238 bool is_static)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800239 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
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.
Brian Carlstromea46f952013-07-30 01:26:50 -0700246 mirror::ArtField* ResolveField(const DexFile& dex_file,
247 uint32_t field_idx,
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700248 Handle<mirror::DexCache> dex_cache,
249 Handle<mirror::ClassLoader> class_loader,
Brian Carlstromea46f952013-07-30 01:26:50 -0700250 bool is_static)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700251 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700252
Ian Rogersb067ac22011-12-13 18:05:09 -0800253 // Resolve a field with a given ID from the DexFile, storing the
254 // result in DexCache. The ClassLinker and ClassLoader are used as
255 // in ResolveType. No is_static argument is provided so that Java
256 // field resolution semantics are followed.
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700257 mirror::ArtField* ResolveFieldJLS(const DexFile& dex_file, uint32_t field_idx,
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700258 Handle<mirror::DexCache> dex_cache,
259 Handle<mirror::ClassLoader> class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700260 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersb067ac22011-12-13 18:05:09 -0800261
Ian Rogersad25ac52011-10-04 19:13:33 -0700262 // Get shorty from method index without resolution. Used to do handlerization.
Brian Carlstromea46f952013-07-30 01:26:50 -0700263 const char* MethodShorty(uint32_t method_idx, mirror::ArtMethod* referrer, uint32_t* length)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700264 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersad25ac52011-10-04 19:13:33 -0700265
Elliott Hughesf4c21c92011-08-19 17:31:31 -0700266 // Returns true on success, false if there's an exception pending.
Brian Carlstrom25c33252011-09-18 15:58:35 -0700267 // can_run_clinit=false allows the compiler to attempt to init a class,
268 // given the restriction that no <clinit> execution is possible.
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700269 bool EnsureInitialized(Thread* self, Handle<mirror::Class> c, bool can_init_fields,
Ian Rogers7b078e82014-09-10 14:44:24 -0700270 bool can_init_parents)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700271 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700272
Elliott Hughes2a20cfd2011-09-23 19:30:41 -0700273 // Initializes classes that have instances in the image but that have
274 // <clinit> methods so they could not be initialized by the compiler.
Ian Rogersb726dcb2012-09-05 08:57:23 -0700275 void RunRootClinits() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes2a20cfd2011-09-23 19:30:41 -0700276
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700277 void RegisterDexFile(const DexFile& dex_file)
278 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700279 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700280 void RegisterDexFile(const DexFile& dex_file, Handle<mirror::DexCache> dex_cache)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700281 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700282 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700283
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700284 const OatFile* RegisterOatFile(const OatFile* oat_file)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700285 LOCKS_EXCLUDED(dex_lock_);
Brian Carlstrom866c8622012-01-06 16:35:13 -0800286
Brian Carlstrom8a487412011-08-29 20:08:52 -0700287 const std::vector<const DexFile*>& GetBootClassPath() {
288 return boot_class_path_;
289 }
290
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700291 void VisitClasses(ClassVisitor* visitor, void* arg)
Ian Rogersdbf3be02014-08-29 15:40:08 -0700292 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700293 SHARED_LOCKS_REQUIRED(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)
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700300 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesa2155262011-11-16 16:26:58 -0800301
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -0700302 void VisitClassRoots(RootVisitor* visitor, VisitRootFlags flags)
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -0700303 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
304 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -0700305 void VisitRoots(RootVisitor* visitor, VisitRootFlags flags)
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -0700306 LOCKS_EXCLUDED(dex_lock_)
307 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700308
Hiroshi Yamauchie9e3e692014-06-24 14:31:37 -0700309 mirror::DexCache* FindDexCache(const DexFile& dex_file)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700310 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700311 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Hiroshi Yamauchie9e3e692014-06-24 14:31:37 -0700312 bool IsDexFileRegistered(const DexFile& dex_file)
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700313 LOCKS_EXCLUDED(dex_lock_) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Hiroshi Yamauchie9e3e692014-06-24 14:31:37 -0700314 void FixupDexCaches(mirror::ArtMethod* resolution_method)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700315 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700316 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom1d9f52b2011-10-13 10:50:45 -0700317
Richard Uhler66d874d2015-01-15 09:37:19 -0800318 // Finds or creates the oat file holding dex_location. Then loads and returns
319 // all corresponding dex files (there may be more than one dex file loaded
320 // in the case of multidex).
321 // This may return the original, unquickened dex files if the oat file could
322 // not be generated.
323 //
324 // Returns an empty vector if the dex files could not be loaded. In this
325 // case, there will be at least one error message returned describing why no
326 // dex files could not be loaded. The 'error_msgs' argument must not be
327 // null, regardless of whether there is an error or not.
328 //
329 // This method should not be called with the mutator_lock_ held, because it
330 // could end up starving GC if we need to generate or relocate any oat
331 // files.
332 std::vector<std::unique_ptr<const DexFile>> OpenDexFilesFromOat(
333 const char* dex_location, const char* oat_location,
334 std::vector<std::string>* error_msgs)
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700335 LOCKS_EXCLUDED(dex_lock_, Locks::mutator_lock_);
jeffhaof6174e82012-01-31 16:14:17 -0800336
Ian Rogersc0542af2014-09-03 16:16:56 -0700337 // Allocate an instance of a java.lang.Object.
338 mirror::Object* AllocObject(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
339
Elliott Hughes418d20f2011-09-22 14:00:39 -0700340 // TODO: replace this with multiple methods that allocate the correct managed type.
Shih-wei Liao44175362011-08-28 16:59:17 -0700341 template <class T>
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800342 mirror::ObjectArray<T>* AllocObjectArray(Thread* self, size_t length)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700343 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Shih-wei Liao55df06b2011-08-26 14:39:27 -0700344
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800345 mirror::ObjectArray<mirror::Class>* AllocClassArray(Thread* self, size_t length)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700346 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
jeffhao98eacac2011-09-14 16:11:53 -0700347
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800348 mirror::ObjectArray<mirror::String>* AllocStringArray(Thread* self, size_t length)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700349 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800350
Brian Carlstromea46f952013-07-30 01:26:50 -0700351 mirror::ObjectArray<mirror::ArtMethod>* AllocArtMethodArray(Thread* self, size_t length)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800352 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
353
354 mirror::IfTable* AllocIfTable(Thread* self, size_t ifcount)
355 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
356
Brian Carlstromea46f952013-07-30 01:26:50 -0700357 mirror::ObjectArray<mirror::ArtField>* AllocArtFieldArray(Thread* self, size_t length)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800358 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
359
360 mirror::ObjectArray<mirror::StackTraceElement>* AllocStackTraceElementArray(Thread* self,
361 size_t length)
362 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
363
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700364 void VerifyClass(Thread* self, Handle<mirror::Class> klass)
Ian Rogers7b078e82014-09-10 14:44:24 -0700365 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800366 bool VerifyClassUsingOatFile(const DexFile& dex_file, mirror::Class* klass,
367 mirror::Class::Status& oat_file_class_status)
368 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800369 void ResolveClassExceptionHandlerTypes(const DexFile& dex_file,
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700370 Handle<mirror::Class> klass)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800371 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromea46f952013-07-30 01:26:50 -0700372 void ResolveMethodExceptionHandlerTypes(const DexFile& dex_file, mirror::ArtMethod* klass)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800373 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
374
Mathieu Chartier2b7c4d12014-05-19 10:52:16 -0700375 mirror::Class* CreateProxyClass(ScopedObjectAccessAlreadyRunnable& soa, jstring name,
376 jobjectArray interfaces, jobject loader, jobjectArray methods,
377 jobjectArray throws)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800378 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800379 std::string GetDescriptorForProxy(mirror::Class* proxy_class)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800380 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800381 mirror::ArtMethod* FindMethodForProxy(mirror::Class* proxy_class,
382 mirror::ArtMethod* proxy_method)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700383 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700384 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jesse Wilson95caa792011-10-12 18:14:17 -0400385
Ian Rogers19846512012-02-24 11:42:47 -0800386 // Get the oat code for a method when its class isn't yet initialized
Ian Rogersef7d42f2014-01-06 12:55:46 -0800387 const void* GetQuickOatCodeFor(mirror::ArtMethod* method)
388 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers19846512012-02-24 11:42:47 -0800389
Mathieu Chartiere35517a2012-10-30 18:49:55 -0700390 // Get the oat code for a method from a method index.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800391 const void* GetQuickOatCodeFor(const DexFile& dex_file, uint16_t class_def_idx, uint32_t method_idx)
392 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartiere35517a2012-10-30 18:49:55 -0700393
Hiroshi Yamauchi9bdec882014-08-15 17:11:12 -0700394 // Get compiled code for a method, return null if no code
395 // exists. This is unlike Get..OatCodeFor which will return a bridge
396 // or interpreter entrypoint.
397 const void* GetOatMethodQuickCodeFor(mirror::ArtMethod* method)
398 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Hiroshi Yamauchi9bdec882014-08-15 17:11:12 -0700399
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700400 pid_t GetClassesLockOwner(); // For SignalCatcher.
401 pid_t GetDexLockOwner(); // For SignalCatcher.
Brian Carlstrom24a3c2e2011-10-17 18:07:52 -0700402
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700403 mirror::Class* GetClassRoot(ClassRoot class_root) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700404
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700405 static const char* GetClassRootDescriptor(ClassRoot class_root);
Andreas Gampe2da88232014-02-27 12:26:20 -0800406
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700407 // Is the given entry point quick code to run the resolution stub?
408 bool IsQuickResolutionStub(const void* entry_point) const;
Jeff Hao88474b42013-10-23 16:24:40 -0700409
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700410 // Is the given entry point quick code to bridge into the interpreter?
411 bool IsQuickToInterpreterBridge(const void* entry_point) const;
412
413 // Is the given entry point quick code to run the generic JNI stub?
414 bool IsQuickGenericJniStub(const void* entry_point) const;
Vladimir Marko8a630572014-04-09 18:45:35 +0100415
Jeff Hao88474b42013-10-23 16:24:40 -0700416 InternTable* GetInternTable() const {
417 return intern_table_;
418 }
419
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700420 // Set the entrypoints up for method to the given code.
Elliott Hughes956af0f2014-12-11 14:34:28 -0800421 void SetEntryPointsToCompiledCode(mirror::ArtMethod* method, const void* method_code) const
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700422 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
423
424 // Set the entrypoints up for method to the enter the interpreter.
425 void SetEntryPointsToInterpreter(mirror::ArtMethod* method) const
426 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
427
Ian Rogers848871b2013-08-05 10:56:33 -0700428 // Attempts to insert a class into a class table. Returns NULL if
429 // the class was inserted, otherwise returns an existing class with
430 // the same descriptor and ClassLoader.
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700431 mirror::Class* InsertClass(const char* descriptor, mirror::Class* klass, size_t hash)
Ian Rogers848871b2013-08-05 10:56:33 -0700432 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
433 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
434
Mathieu Chartier590fee92013-09-13 13:46:47 -0700435 // Special code to allocate an art method, use this instead of class->AllocObject.
436 mirror::ArtMethod* AllocArtMethod(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro61e019d2011-07-14 16:53:09 -0700437
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700438 mirror::ObjectArray<mirror::Class>* GetClassRoots() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -0700439 mirror::ObjectArray<mirror::Class>* class_roots = class_roots_.Read();
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700440 DCHECK(class_roots != NULL);
441 return class_roots;
442 }
443
Mathieu Chartierc2e20622014-11-03 11:41:47 -0800444 // Move all of the image classes into the class table for faster lookups.
445 void MoveImageClassesToClassTable()
446 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
447 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
448 // Move the class table to the pre-zygote table to reduce memory usage. This works by ensuring
449 // that no more classes are ever added to the pre zygote table which makes it that the pages
450 // always remain shared dirty instead of private dirty.
451 void MoveClassTableToPreZygote()
452 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
453 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
454
Sebastien Hertz6963e442014-11-26 22:11:27 +0100455 // Returns true if the method can be called with its direct code pointer, false otherwise.
456 bool MayBeCalledWithDirectCodePointer(mirror::ArtMethod* m)
457 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
458
Andreas Gampe81c6f8d2015-03-25 17:19:53 -0700459 // Creates a GlobalRef PathClassLoader that can be used to load classes from the given dex files.
460 // Note: the objects are not completely set up. Do not use this outside of tests and the compiler.
461 jobject CreatePathClassLoader(Thread* self, std::vector<const DexFile*>& dex_files)
462 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
463
Mathieu Chartier590fee92013-09-13 13:46:47 -0700464 private:
Mathieu Chartiera89d7ed2014-12-05 10:57:13 -0800465 static void InitFromImageInterpretOnlyCallback(mirror::Object* obj, void* arg)
466 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
467
Ian Rogers97b52f82014-08-14 11:34:07 -0700468 const OatFile::OatMethod FindOatMethodFor(mirror::ArtMethod* method, bool* found)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700469 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
TDYa12785321912012-04-01 15:24:56 -0700470
Brian Carlstrom56d947f2013-07-15 13:14:23 -0700471 OatFile& GetImageOatFile(gc::space::ImageSpace* space)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700472 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700473 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstroma663ea52011-08-19 23:33:41 -0700474
Ian Rogers98379392014-02-24 16:53:16 -0800475 void FinishInit(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstroma663ea52011-08-19 23:33:41 -0700476
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700477 // For early bootstrapping by Init
Ian Rogers6fac4472014-02-25 17:01:10 -0800478 mirror::Class* AllocClass(Thread* self, mirror::Class* java_lang_Class, uint32_t class_size)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700479 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700480
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800481 // Alloc* convenience functions to avoid needing to pass in mirror::Class*
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700482 // values that are known to the ClassLinker such as
483 // kObjectArrayClass and kJavaLangString etc.
Ian Rogers6fac4472014-02-25 17:01:10 -0800484 mirror::Class* AllocClass(Thread* self, uint32_t class_size)
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800485 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800486 mirror::DexCache* AllocDexCache(Thread* self, const DexFile& dex_file)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700487 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromea46f952013-07-30 01:26:50 -0700488 mirror::ArtField* AllocArtField(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersbdb03912011-09-14 00:55:44 -0700489
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800490 mirror::Class* CreatePrimitiveClass(Thread* self, Primitive::Type type)
491 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
492 mirror::Class* InitializePrimitiveClass(mirror::Class* primitive_class, Primitive::Type type)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700493 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom5b8e4c82011-09-18 01:38:59 -0700494
Brian Carlstroma331b3c2011-07-18 17:47:56 -0700495
Mathieu Chartiere7c9a8c2014-11-06 16:35:45 -0800496 mirror::Class* CreateArrayClass(Thread* self, const char* descriptor, size_t hash,
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700497 Handle<mirror::ClassLoader> class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700498 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstroma331b3c2011-07-18 17:47:56 -0700499
Ian Rogers7b078e82014-09-10 14:44:24 -0700500 void AppendToBootClassPath(Thread* self, const DexFile& dex_file)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700501 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700502 void AppendToBootClassPath(const DexFile& dex_file, Handle<mirror::DexCache> dex_cache)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700503 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700504
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700505 // Precomputes size needed for Class, in the case of a non-temporary class this size must be
506 // sufficient to hold all static fields.
507 uint32_t SizeOfClassWithoutEmbeddedTables(const DexFile& dex_file,
508 const DexFile::ClassDef& dex_class_def);
Brian Carlstrom4873d462011-08-21 15:23:39 -0700509
Ian Rogers7b078e82014-09-10 14:44:24 -0700510 void LoadClass(Thread* self, const DexFile& dex_file, const DexFile::ClassDef& dex_class_def,
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700511 Handle<mirror::Class> klass, mirror::ClassLoader* class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700512 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers13735952014-10-08 12:43:28 -0700513 void LoadClassMembers(Thread* self, const DexFile& dex_file, const uint8_t* class_data,
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700514 Handle<mirror::Class> klass, const OatFile::OatClass* oat_class)
Vladimir Markod3c5beb2014-04-11 16:32:51 +0100515 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700516
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800517 void LoadField(const DexFile& dex_file, const ClassDataItemIterator& it,
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700518 Handle<mirror::Class> klass, Handle<mirror::ArtField> dst)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800519 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700520
Brian Carlstromea46f952013-07-30 01:26:50 -0700521 mirror::ArtMethod* LoadMethod(Thread* self, const DexFile& dex_file,
522 const ClassDataItemIterator& dex_method,
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700523 Handle<mirror::Class> klass)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800524 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom934486c2011-07-12 23:42:50 -0700525
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800526 void FixupStaticTrampolines(mirror::Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers19846512012-02-24 11:42:47 -0800527
Ian Rogers97b52f82014-08-14 11:34:07 -0700528 // Finds the associated oat class for a dex_file and descriptor. Returns an invalid OatClass on
529 // error and sets found to false.
530 OatFile::OatClass FindOatClass(const DexFile& dex_file, uint16_t class_def_idx, bool* found)
Ian Rogers33e95662013-05-20 20:29:14 -0700531 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers19846512012-02-24 11:42:47 -0800532
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700533 void RegisterDexFileLocked(const DexFile& dex_file, Handle<mirror::DexCache> dex_cache)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700534 EXCLUSIVE_LOCKS_REQUIRED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700535 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Hiroshi Yamauchie9e3e692014-06-24 14:31:37 -0700536 bool IsDexFileRegisteredLocked(const DexFile& dex_file)
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700537 SHARED_LOCKS_REQUIRED(dex_lock_, Locks::mutator_lock_);
Brian Carlstromaded5f72011-10-07 17:15:04 -0700538
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700539 bool InitializeClass(Thread* self, Handle<mirror::Class> klass, bool can_run_clinit,
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800540 bool can_init_parents)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700541 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700542 bool WaitForInitializeClass(Handle<mirror::Class> klass, Thread* self,
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800543 ObjectLock<mirror::Class>& lock);
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700544 bool ValidateSuperClassDescriptors(Handle<mirror::Class> klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700545 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700546
Ian Rogers98379392014-02-24 16:53:16 -0800547 bool IsSameDescriptorInDifferentClassContexts(Thread* self, const char* descriptor,
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700548 Handle<mirror::ClassLoader> class_loader1,
549 Handle<mirror::ClassLoader> class_loader2)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700550 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700551
Ian Rogers98379392014-02-24 16:53:16 -0800552 bool IsSameMethodSignatureInDifferentClassContexts(Thread* self, mirror::ArtMethod* method,
Ian Rogersef7d42f2014-01-06 12:55:46 -0800553 mirror::Class* klass1,
554 mirror::Class* klass2)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700555 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700556
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700557 bool LinkClass(Thread* self, const char* descriptor, Handle<mirror::Class> klass,
558 Handle<mirror::ObjectArray<mirror::Class>> interfaces,
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700559 mirror::Class** new_class)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700560 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700561
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700562 bool LinkSuperClass(Handle<mirror::Class> klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700563 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700564
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700565 bool LoadSuperAndInterfaces(Handle<mirror::Class> klass, const DexFile& dex_file)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700566 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700567
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700568 bool LinkMethods(Thread* self, Handle<mirror::Class> klass,
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700569 Handle<mirror::ObjectArray<mirror::Class>> interfaces,
570 StackHandleScope<mirror::Class::kImtSize>* out_imt)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700571 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700572
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700573 bool LinkVirtualMethods(Thread* self, Handle<mirror::Class> klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700574 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700575
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700576 bool LinkInterfaceMethods(Thread* const self, Handle<mirror::Class> klass,
577 Handle<mirror::ObjectArray<mirror::Class>> interfaces,
578 StackHandleScope<mirror::Class::kImtSize>* out_imt)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700579 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700580
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700581 bool LinkStaticFields(Thread* self, Handle<mirror::Class> klass, size_t* class_size)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700582 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700583 bool LinkInstanceFields(Thread* self, Handle<mirror::Class> klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700584 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700585 bool LinkFields(Thread* self, Handle<mirror::Class> klass, bool is_static, size_t* class_size)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700586 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700587 void LinkCode(Handle<mirror::ArtMethod> method, const OatFile::OatClass* oat_class,
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700588 uint32_t class_def_method_index)
Dmitry Petrochenkof0972a42014-05-16 17:43:39 +0700589 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700590 void CreateReferenceInstanceOffsets(Handle<mirror::Class> klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700591 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700592
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700593 // For use by ImageWriter to find DexCaches for its roots
Hiroshi Yamauchie9e3e692014-06-24 14:31:37 -0700594 ReaderWriterMutex* DexLock()
595 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) LOCK_RETURNED(dex_lock_) {
596 return &dex_lock_;
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700597 }
Hiroshi Yamauchie9e3e692014-06-24 14:31:37 -0700598 size_t GetDexCacheCount() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_, dex_lock_) {
599 return dex_caches_.size();
600 }
601 mirror::DexCache* GetDexCache(size_t idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_, dex_lock_);
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700602
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700603 const OatFile* FindOpenedOatFileFromOatLocation(const std::string& oat_location)
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700604 LOCKS_EXCLUDED(dex_lock_);
Andreas Gampe833a4852014-05-21 18:46:59 -0700605
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700606 mirror::ArtMethod* CreateProxyConstructor(Thread* self, Handle<mirror::Class> klass,
Brian Carlstromea46f952013-07-30 01:26:50 -0700607 mirror::Class* proxy_class)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700608 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700609 mirror::ArtMethod* CreateProxyMethod(Thread* self, Handle<mirror::Class> klass,
610 Handle<mirror::ArtMethod> prototype)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700611 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jesse Wilson95caa792011-10-12 18:14:17 -0400612
Andreas Gampe48498592014-09-10 19:48:05 -0700613 // Ensures that methods have the kAccPreverified bit set. We use the kAccPreverfied bit on the
614 // class access flags to determine whether this has been done before.
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700615 void EnsurePreverifiedMethods(Handle<mirror::Class> c)
Andreas Gampe48498592014-09-10 19:48:05 -0700616 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
617
Ian Rogersdbf3be02014-08-29 15:40:08 -0700618 mirror::Class* LookupClassFromTableLocked(const char* descriptor,
Mathieu Chartierc2e20622014-11-03 11:41:47 -0800619 mirror::ClassLoader* class_loader,
Ian Rogersdbf3be02014-08-29 15:40:08 -0700620 size_t hash)
621 SHARED_LOCKS_REQUIRED(Locks::classlinker_classes_lock_, Locks::mutator_lock_);
622
623 mirror::Class* UpdateClass(const char* descriptor, mirror::Class* klass, size_t hash)
624 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
625 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
626
Ian Rogersdbf3be02014-08-29 15:40:08 -0700627 mirror::Class* LookupClassFromImage(const char* descriptor)
628 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
629
630 // EnsureResolved is called to make sure that a class in the class_table_ has been resolved
631 // before returning it to the caller. Its the responsibility of the thread that placed the class
632 // in the table to make it resolved. The thread doing resolution must notify on the class' lock
633 // when resolution has occurred. This happens in mirror::Class::SetStatus. As resolution may
634 // retire a class, the version of the class in the table is returned and this may differ from
635 // the class passed in.
636 mirror::Class* EnsureResolved(Thread* self, const char* descriptor, mirror::Class* klass)
637 WARN_UNUSED SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
638
639 void FixupTemporaryDeclaringClass(mirror::Class* temp_class, mirror::Class* new_class)
640 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
641
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700642 void SetClassRoot(ClassRoot class_root, mirror::Class* klass)
643 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
644
645 // Return the quick generic JNI stub for testing.
646 const void* GetRuntimeQuickGenericJniStub() const;
647
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700648 std::vector<const DexFile*> boot_class_path_;
Richard Uhlerfbef44d2014-12-23 09:48:51 -0800649 std::vector<std::unique_ptr<const DexFile>> opened_dex_files_;
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700650
Ian Rogers1bf8d4d2013-05-30 00:18:49 -0700651 mutable ReaderWriterMutex dex_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
Andreas Gampec8ccf682014-09-29 20:07:43 -0700652 std::vector<size_t> new_dex_cache_roots_ GUARDED_BY(dex_lock_);
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -0700653 std::vector<GcRoot<mirror::DexCache>> dex_caches_ GUARDED_BY(dex_lock_);
Elliott Hughesf8349362012-06-18 15:00:06 -0700654 std::vector<const OatFile*> oat_files_ GUARDED_BY(dex_lock_);
Brian Carlstrom47d237a2011-10-18 15:08:33 -0700655
Mathieu Chartierc2e20622014-11-03 11:41:47 -0800656 class ClassDescriptorHashEquals {
657 public:
658 // Same class loader and descriptor.
659 std::size_t operator()(const GcRoot<mirror::Class>& root) const NO_THREAD_SAFETY_ANALYSIS;
Mathieu Chartier47f867a2015-03-18 10:39:00 -0700660 bool operator()(const GcRoot<mirror::Class>& a, const GcRoot<mirror::Class>& b) const
Mathieu Chartierc2e20622014-11-03 11:41:47 -0800661 NO_THREAD_SAFETY_ANALYSIS;
662 // Same class loader and descriptor.
663 std::size_t operator()(const std::pair<const char*, mirror::ClassLoader*>& element) const
664 NO_THREAD_SAFETY_ANALYSIS;
665 bool operator()(const GcRoot<mirror::Class>& a,
Mathieu Chartier47f867a2015-03-18 10:39:00 -0700666 const std::pair<const char*, mirror::ClassLoader*>& b) const
Mathieu Chartierc2e20622014-11-03 11:41:47 -0800667 NO_THREAD_SAFETY_ANALYSIS;
668 // Same descriptor.
Mathieu Chartier47f867a2015-03-18 10:39:00 -0700669 bool operator()(const GcRoot<mirror::Class>& a, const char* descriptor) const
Mathieu Chartierc2e20622014-11-03 11:41:47 -0800670 NO_THREAD_SAFETY_ANALYSIS;
671 std::size_t operator()(const char* descriptor) const NO_THREAD_SAFETY_ANALYSIS;
672 };
673 class GcRootEmptyFn {
674 public:
675 void MakeEmpty(GcRoot<mirror::Class>& item) const {
676 item = GcRoot<mirror::Class>();
677 }
678 bool IsEmpty(const GcRoot<mirror::Class>& item) const {
679 return item.IsNull();
680 }
681 };
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700682
Mathieu Chartierc2e20622014-11-03 11:41:47 -0800683 // hash set which hashes class descriptor, and compares descriptors nad class loaders. Results
684 // should be compared for a matching Class descriptor and class loader.
685 typedef HashSet<GcRoot<mirror::Class>, GcRootEmptyFn, ClassDescriptorHashEquals,
686 ClassDescriptorHashEquals, TrackingAllocator<GcRoot<mirror::Class>, kAllocatorTagClassTable>>
687 Table;
Hiroshi Yamauchia91a4bc2014-06-13 16:44:55 -0700688 // This contains strong roots. To enable concurrent root scanning of
689 // the class table, be careful to use a read barrier when accessing this.
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700690 Table class_table_ GUARDED_BY(Locks::classlinker_classes_lock_);
Mathieu Chartierc2e20622014-11-03 11:41:47 -0800691 Table pre_zygote_class_table_ GUARDED_BY(Locks::classlinker_classes_lock_);
692 std::vector<GcRoot<mirror::Class>> new_class_roots_;
Elliott Hughesf8349362012-06-18 15:00:06 -0700693
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700694 // Do we need to search dex caches to find image classes?
695 bool dex_cache_image_class_lookup_required_;
696 // Number of times we've searched dex caches for a class. After a certain number of misses we move
697 // the classes into the class_table_ to avoid dex cache based searches.
Ian Rogers68b56852014-08-29 20:19:11 -0700698 Atomic<uint32_t> failed_dex_cache_class_lookups_;
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700699
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700700 // Well known mirror::Class roots.
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -0700701 GcRoot<mirror::ObjectArray<mirror::Class>> class_roots_;
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700702
Ian Rogers98379392014-02-24 16:53:16 -0800703 // The interface table used by all arrays.
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -0700704 GcRoot<mirror::IfTable> array_iftable_;
Carl Shapiro565f5072011-07-10 13:39:43 -0700705
Ian Rogers98379392014-02-24 16:53:16 -0800706 // A cache of the last FindArrayClass results. The cache serves to avoid creating array class
707 // descriptors for the sake of performing FindClass.
708 static constexpr size_t kFindArrayCacheSize = 16;
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -0700709 GcRoot<mirror::Class> find_array_class_cache_[kFindArrayCacheSize];
Ian Rogers98379392014-02-24 16:53:16 -0800710 size_t find_array_class_cache_next_victim_;
711
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700712 bool init_done_;
Mathieu Chartier893263b2014-03-04 11:07:42 -0800713 bool log_new_dex_caches_roots_ GUARDED_BY(dex_lock_);
714 bool log_new_class_table_roots_ GUARDED_BY(Locks::classlinker_classes_lock_);
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700715
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700716 InternTable* intern_table_;
717
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700718 // Trampolines within the image the bounce to runtime entrypoints. Done so that there is a single
719 // patch point within the image. TODO: make these proper relocations.
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700720 const void* quick_resolution_trampoline_;
Jeff Hao88474b42013-10-23 16:24:40 -0700721 const void* quick_imt_conflict_trampoline_;
Andreas Gampe2da88232014-02-27 12:26:20 -0800722 const void* quick_generic_jni_trampoline_;
Vladimir Marko8a630572014-04-09 18:45:35 +0100723 const void* quick_to_interpreter_bridge_trampoline_;
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700724
Mathieu Chartier2d721012014-11-10 11:08:06 -0800725 // Image pointer size.
726 size_t image_pointer_size_;
727
Brian Carlstrom34f426c2011-10-04 12:58:02 -0700728 friend class ImageWriter; // for GetClassRoots
Alex Lighta59dd802014-07-02 16:28:08 -0700729 friend class ImageDumper; // for FindOpenedOatFileFromOatLocation
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700730 friend class JniCompilerTest; // for GetRuntimeQuickGenericJniStub
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700731 ART_FRIEND_TEST(mirror::DexCacheTest, Open); // for AllocDexCache
732
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700733 DISALLOW_COPY_AND_ASSIGN(ClassLinker);
734};
735
736} // namespace art
737
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700738#endif // ART_RUNTIME_CLASS_LINKER_H_