blob: a3a1adf8397122b068a5f890913e75ae7c5acd05 [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
Andreas Gampe49b74a82019-01-07 10:19:49 -080020#include <list>
Vladimir Marko86c87522020-05-11 16:55:55 +010021#include <map>
Mathieu Chartierc5dd3192015-12-09 16:38:30 -080022#include <set>
Ian Rogers6d4d9fc2011-11-30 16:24:48 -080023#include <string>
Nicolas Geoffray4ac0e152019-09-18 06:14:50 +000024#include <type_traits>
David Srbecky6fbcc292021-02-23 01:05:32 +000025#include <unordered_map>
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070026#include <utility>
27#include <vector>
28
Andreas Gampe542451c2016-07-26 09:02:02 -070029#include "base/enums.h"
Vladimir Marko782fb712020-12-23 12:47:31 +000030#include "base/hash_map.h"
Vladimir Markobf121912019-06-04 13:49:05 +010031#include "base/intrusive_forward_list.h"
Andreas Gampe7fbc4a52018-11-28 08:26:47 -080032#include "base/locks.h"
Elliott Hughes76160052012-12-12 16:31:20 -080033#include "base/macros.h"
Santiago Aboy Solanes970ba212021-10-21 10:52:47 +010034#include "base/mutex.h"
Mathieu Chartier1f1cb9f2018-06-04 09:22:46 -070035#include "dex/class_accessor.h"
David Sehr9e734c72018-01-04 17:56:19 -080036#include "dex/dex_file_types.h"
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -070037#include "gc_root.h"
Andreas Gampe0f01b582017-01-18 15:22:37 -080038#include "handle.h"
Mathieu Chartier590fee92013-09-13 13:46:47 -070039#include "jni.h"
Vladimir Marko97d7e1c2016-10-04 14:44:28 +010040#include "mirror/class.h"
Vladimir Marko43354742021-02-03 15:37:01 +000041#include "mirror/object.h"
Santiago Aboy Solanes970ba212021-10-21 10:52:47 +010042#include "oat_file.h"
Andreas Gampe6d7abbd2017-04-24 13:19:09 -070043#include "verifier/verifier_enums.h"
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070044
45namespace art {
Mingyao Yang98d1cc82014-05-15 17:02:16 -070046
Vladimir Marko86c87522020-05-11 16:55:55 +010047class ArtField;
48class ArtMethod;
49class ClassHierarchyAnalysis;
50enum class ClassRoot : uint32_t;
51class ClassTable;
52class DexFile;
53template<class T> class Handle;
54class ImtConflictTable;
55template<typename T> class LengthPrefixedArray;
56template<class T> class MutableHandle;
57class InternTable;
58class LinearAlloc;
59class OatFile;
60template<class T> class ObjectLock;
61class Runtime;
62class ScopedObjectAccessAlreadyRunnable;
Calin Juravle33787682019-07-26 14:27:18 -070063class SdkChecker;
Vladimir Marko86c87522020-05-11 16:55:55 +010064template<size_t kNumReferences> class PACKED(4) StackHandleScope;
65class Thread;
66
67enum VisitRootFlags : uint8_t;
68
Andreas Gampe3f1dcd32018-12-28 09:39:56 -080069namespace dex {
70struct ClassDef;
Andreas Gampe62629592019-01-03 16:08:31 -080071struct MethodHandleItem;
Andreas Gampe3f1dcd32018-12-28 09:39:56 -080072} // namespace dex
73
Ian Rogers1d54e732013-05-02 21:10:01 -070074namespace gc {
75namespace space {
Igor Murashkin2ffb7032017-11-08 13:35:21 -080076class ImageSpace;
Ian Rogers1d54e732013-05-02 21:10:01 -070077} // namespace space
78} // namespace gc
Vladimir Marko74527972016-11-29 15:57:32 +000079
80namespace linker {
Igor Murashkin2ffb7032017-11-08 13:35:21 -080081struct CompilationHelper;
82class ImageWriter;
83class OatWriter;
Vladimir Marko74527972016-11-29 15:57:32 +000084} // namespace linker
85
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080086namespace mirror {
Igor Murashkin2ffb7032017-11-08 13:35:21 -080087class ClassLoader;
88class DexCache;
89class DexCachePointerArray;
90class DexCacheMethodHandlesTest_Open_Test;
91class DexCacheTest_Open_Test;
92class IfTable;
93class MethodHandle;
94class MethodHandlesLookup;
95class MethodType;
96template<class T> class ObjectArray;
97class StackTraceElement;
Ian Rogers33e95662013-05-20 20:29:14 -070098} // namespace mirror
Ian Rogers1d54e732013-05-02 21:10:01 -070099
Nicolas Geoffray5b0b2e12021-03-19 14:48:40 +0000100namespace verifier {
101class VerifierDeps;
102}
103
Mathieu Chartier1aa8ec22016-02-01 10:34:47 -0800104class ClassVisitor {
105 public:
106 virtual ~ClassVisitor() {}
107 // Return true to continue visiting.
Mathieu Chartier28357fa2016-10-18 16:27:40 -0700108 virtual bool operator()(ObjPtr<mirror::Class> klass) = 0;
Mathieu Chartier1aa8ec22016-02-01 10:34:47 -0800109};
110
Alex Light3f0dca12020-01-27 17:20:28 -0800111template <typename Func>
112class ClassFuncVisitor final : public ClassVisitor {
113 public:
114 explicit ClassFuncVisitor(Func func) : func_(func) {}
115 bool operator()(ObjPtr<mirror::Class> klass) override REQUIRES_SHARED(Locks::mutator_lock_) {
116 return func_(klass);
117 }
118
119 private:
120 Func func_;
121};
122
Mathieu Chartier9b1c71e2015-09-02 18:51:54 -0700123class ClassLoaderVisitor {
124 public:
125 virtual ~ClassLoaderVisitor() {}
Mathieu Chartier28357fa2016-10-18 16:27:40 -0700126 virtual void Visit(ObjPtr<mirror::ClassLoader> class_loader)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700127 REQUIRES_SHARED(Locks::classlinker_classes_lock_, Locks::mutator_lock_) = 0;
Mathieu Chartier9b1c71e2015-09-02 18:51:54 -0700128};
129
Alex Lightabd8f052019-12-06 10:49:17 -0800130template <typename Func>
131class ClassLoaderFuncVisitor final : public ClassLoaderVisitor {
132 public:
133 explicit ClassLoaderFuncVisitor(Func func) : func_(func) {}
134 void Visit(ObjPtr<mirror::ClassLoader> cl) override REQUIRES_SHARED(Locks::mutator_lock_) {
135 func_(cl);
136 }
137
138 private:
139 Func func_;
140};
141
Alexey Grebenkin252a4e42018-04-02 18:18:01 +0300142class AllocatorVisitor {
143 public:
144 virtual ~AllocatorVisitor() {}
145 // Return true to continue visiting.
146 virtual bool Visit(LinearAlloc* alloc)
147 REQUIRES_SHARED(Locks::classlinker_classes_lock_, Locks::mutator_lock_) = 0;
148};
149
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700150class ClassLinker {
151 public:
Chris Wailes55c880e2018-10-24 13:10:35 -0700152 static constexpr bool kAppImageMayContainStrings = true;
Mathieu Chartier0933cc52018-03-23 14:25:08 -0700153
Andreas Gampe87658f32019-04-18 18:39:02 +0000154 explicit ClassLinker(InternTable* intern_table,
155 bool fast_class_not_found_exceptions = true);
Chang Xing605fe242017-07-20 15:57:21 -0700156 virtual ~ClassLinker();
Carl Shapiro565f5072011-07-10 13:39:43 -0700157
Alex Light64ad14d2014-08-19 14:23:13 -0700158 // Initialize class linker by bootstraping from dex files.
Andreas Gampe3db9c5d2015-11-17 11:52:46 -0800159 bool InitWithoutImage(std::vector<std::unique_ptr<const DexFile>> boot_class_path,
160 std::string* error_msg)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700161 REQUIRES_SHARED(Locks::mutator_lock_)
Andreas Gampecc1b5352016-12-01 16:58:38 -0800162 REQUIRES(!Locks::dex_lock_);
Mathieu Chartier590fee92013-09-13 13:46:47 -0700163
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800164 // Initialize class linker from one or more boot images.
165 bool InitFromBootImage(std::string* error_msg)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700166 REQUIRES_SHARED(Locks::mutator_lock_)
Andreas Gampecc1b5352016-12-01 16:58:38 -0800167 REQUIRES(!Locks::dex_lock_);
Mathieu Chartier590fee92013-09-13 13:46:47 -0700168
Vladimir Marko0ace5632018-12-14 11:11:47 +0000169 // Add boot class path dex files that were not included in the boot image.
170 // ClassLinker takes ownership of these dex files.
171 void AddExtraBootDexFiles(Thread* self,
172 std::vector<std::unique_ptr<const DexFile>>&& additional_dex_files)
173 REQUIRES_SHARED(Locks::mutator_lock_);
174
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800175 // Add an image space to the class linker, may fix up classloader fields and dex cache fields.
176 // The dex files that were newly opened for the space are placed in the out argument
177 // out_dex_files. Returns true if the operation succeeded.
178 // The space must be already added to the heap before calling AddImageSpace since we need to
179 // properly handle read barriers and object marking.
180 bool AddImageSpace(gc::space::ImageSpace* space,
181 Handle<mirror::ClassLoader> class_loader,
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800182 std::vector<std::unique_ptr<const DexFile>>* out_dex_files,
183 std::string* error_msg)
Andreas Gampecc1b5352016-12-01 16:58:38 -0800184 REQUIRES(!Locks::dex_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700185 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800186
Mathieu Chartier0b4cbd02016-03-08 16:49:58 -0800187 bool OpenImageDexFiles(gc::space::ImageSpace* space,
188 std::vector<std::unique_ptr<const DexFile>>* out_dex_files,
189 std::string* error_msg)
Andreas Gampecc1b5352016-12-01 16:58:38 -0800190 REQUIRES(!Locks::dex_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700191 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier0b4cbd02016-03-08 16:49:58 -0800192
Elliott Hughes64bf5a32011-09-20 14:43:12 -0700193 // Finds a class by its descriptor, loading it if necessary.
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700194 // If class_loader is null, searches boot_class_path_.
Vladimir Markoa8bba7d2018-05-30 15:18:48 +0100195 ObjPtr<mirror::Class> FindClass(Thread* self,
196 const char* descriptor,
197 Handle<mirror::ClassLoader> class_loader)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700198 REQUIRES_SHARED(Locks::mutator_lock_)
Andreas Gampecc1b5352016-12-01 16:58:38 -0800199 REQUIRES(!Locks::dex_lock_);
Brian Carlstromaded5f72011-10-07 17:15:04 -0700200
Ian Rogers98379392014-02-24 16:53:16 -0800201 // Finds a class by its descriptor using the "system" class loader, ie by searching the
202 // boot_class_path_.
Vladimir Markoa8bba7d2018-05-30 15:18:48 +0100203 ObjPtr<mirror::Class> FindSystemClass(Thread* self, const char* descriptor)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700204 REQUIRES_SHARED(Locks::mutator_lock_)
Andreas Gampec6ea7d02017-02-01 16:46:28 -0800205 REQUIRES(!Locks::dex_lock_) {
206 return FindClass(self, descriptor, ScopedNullHandle<mirror::ClassLoader>());
207 }
Ian Rogers98379392014-02-24 16:53:16 -0800208
209 // Finds the array class given for the element class.
Vladimir Markobcf17522018-06-01 13:14:32 +0100210 ObjPtr<mirror::Class> FindArrayClass(Thread* self, ObjPtr<mirror::Class> element_class)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700211 REQUIRES_SHARED(Locks::mutator_lock_)
Andreas Gampecc1b5352016-12-01 16:58:38 -0800212 REQUIRES(!Locks::dex_lock_);
Brian Carlstromaded5f72011-10-07 17:15:04 -0700213
Ian Rogers63557452014-06-04 16:57:15 -0700214 // Returns true if the class linker is initialized.
Ian Rogers7b078e82014-09-10 14:44:24 -0700215 bool IsInitialized() const {
216 return init_done_;
217 }
Mathieu Chartier590fee92013-09-13 13:46:47 -0700218
Brian Carlstromaded5f72011-10-07 17:15:04 -0700219 // Define a new a class based on a ClassDef from a DexFile
Vladimir Markoa8bba7d2018-05-30 15:18:48 +0100220 ObjPtr<mirror::Class> DefineClass(Thread* self,
221 const char* descriptor,
222 size_t hash,
223 Handle<mirror::ClassLoader> class_loader,
224 const DexFile& dex_file,
Andreas Gampe3f1dcd32018-12-28 09:39:56 -0800225 const dex::ClassDef& dex_class_def)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700226 REQUIRES_SHARED(Locks::mutator_lock_)
Andreas Gampecc1b5352016-12-01 16:58:38 -0800227 REQUIRES(!Locks::dex_lock_);
Elliott Hughes64bf5a32011-09-20 14:43:12 -0700228
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700229 // Finds a class by its descriptor, returning null if it isn't wasn't loaded
Elliott Hughes64bf5a32011-09-20 14:43:12 -0700230 // by the given 'class_loader'.
Vladimir Markoa8bba7d2018-05-30 15:18:48 +0100231 ObjPtr<mirror::Class> LookupClass(Thread* self,
232 const char* descriptor,
233 ObjPtr<mirror::ClassLoader> class_loader)
Mathieu Chartier90443472015-07-16 20:32:27 -0700234 REQUIRES(!Locks::classlinker_classes_lock_)
Andreas Gampe2ff3b972017-06-05 18:14:53 -0700235 REQUIRES_SHARED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700236
Elliott Hughes6fa602d2011-12-02 17:54:25 -0800237 // Finds all the classes with the given descriptor, regardless of ClassLoader.
Mathieu Chartier28357fa2016-10-18 16:27:40 -0700238 void LookupClasses(const char* descriptor, std::vector<ObjPtr<mirror::Class>>& classes)
Mathieu Chartier90443472015-07-16 20:32:27 -0700239 REQUIRES(!Locks::classlinker_classes_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700240 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes6fa602d2011-12-02 17:54:25 -0800241
Vladimir Marko9186b182018-11-06 14:55:54 +0000242 ObjPtr<mirror::Class> LookupPrimitiveClass(char type) REQUIRES_SHARED(Locks::mutator_lock_);
Vladimir Markoa8bba7d2018-05-30 15:18:48 +0100243 ObjPtr<mirror::Class> FindPrimitiveClass(char type) REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700244
Mathieu Chartierc77f3ab2015-09-03 19:41:50 -0700245 void DumpForSigQuit(std::ostream& os) REQUIRES(!Locks::classlinker_classes_lock_);
Elliott Hughescac6cc72011-11-03 20:31:21 -0700246
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700247 size_t NumLoadedClasses()
Mathieu Chartierc77f3ab2015-09-03 19:41:50 -0700248 REQUIRES(!Locks::classlinker_classes_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700249 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughese27955c2011-08-26 15:21:24 -0700250
Vladimir Marko18090d12018-06-01 16:53:12 +0100251 // Resolve a String with the given index from the DexFile associated with the given `referrer`,
252 // storing the result in the DexCache. The `referrer` is used to identify the target DexCache
253 // to use for resolution.
254 ObjPtr<mirror::String> ResolveString(dex::StringIndex string_idx,
255 ArtField* referrer)
256 REQUIRES_SHARED(Locks::mutator_lock_);
257 ObjPtr<mirror::String> ResolveString(dex::StringIndex string_idx,
258 ArtMethod* referrer)
259 REQUIRES_SHARED(Locks::mutator_lock_);
260
Vladimir Markoa64b52d2017-12-08 16:27:49 +0000261 // Resolve a String with the given index from the DexFile associated with the given DexCache,
262 // storing the result in the DexCache.
263 ObjPtr<mirror::String> ResolveString(dex::StringIndex string_idx,
Vladimir Marko28e012a2017-12-07 11:22:59 +0000264 Handle<mirror::DexCache> dex_cache)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700265 REQUIRES_SHARED(Locks::mutator_lock_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700266
Vladimir Markoa64b52d2017-12-08 16:27:49 +0000267 // Find a String with the given index from the DexFile associated with the given DexCache,
268 // storing the result in the DexCache if found. Return null if not found.
269 ObjPtr<mirror::String> LookupString(dex::StringIndex string_idx,
Vladimir Marko28e012a2017-12-07 11:22:59 +0000270 ObjPtr<mirror::DexCache> dex_cache)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700271 REQUIRES_SHARED(Locks::mutator_lock_);
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000272
Vladimir Marko666ee3d2017-12-11 18:37:36 +0000273 // Resolve a Type with the given index from the DexFile associated with the given `referrer`,
274 // storing the result in the DexCache. The `referrer` is used to identify the target DexCache
275 // and ClassLoader to use for resolution.
276 ObjPtr<mirror::Class> ResolveType(dex::TypeIndex type_idx, ObjPtr<mirror::Class> referrer)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700277 REQUIRES_SHARED(Locks::mutator_lock_)
Andreas Gampecc1b5352016-12-01 16:58:38 -0800278 REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_);
Vladimir Marko09c5ca42018-05-31 15:15:31 +0100279 ObjPtr<mirror::Class> ResolveType(dex::TypeIndex type_idx, ArtField* referrer)
280 REQUIRES_SHARED(Locks::mutator_lock_)
281 REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_);
Vladimir Marko28e012a2017-12-07 11:22:59 +0000282 ObjPtr<mirror::Class> ResolveType(dex::TypeIndex type_idx, ArtMethod* referrer)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700283 REQUIRES_SHARED(Locks::mutator_lock_)
Andreas Gampecc1b5352016-12-01 16:58:38 -0800284 REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700285
Vladimir Marko666ee3d2017-12-11 18:37:36 +0000286 // Resolve a type with the given index from the DexFile associated with the given DexCache
287 // and ClassLoader, storing the result in DexCache. The ClassLoader is used to search for
288 // the type, since it may be referenced from but not contained within the DexFile.
289 ObjPtr<mirror::Class> ResolveType(dex::TypeIndex type_idx,
Vladimir Marko28e012a2017-12-07 11:22:59 +0000290 Handle<mirror::DexCache> dex_cache,
291 Handle<mirror::ClassLoader> class_loader)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700292 REQUIRES_SHARED(Locks::mutator_lock_)
Andreas Gampecc1b5352016-12-01 16:58:38 -0800293 REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700294
Vladimir Marko666ee3d2017-12-11 18:37:36 +0000295 // Look up a resolved type with the given index from the DexFile associated with the given
296 // `referrer`, storing the result in the DexCache. The `referrer` is used to identify the
297 // target DexCache and ClassLoader to use for lookup.
298 ObjPtr<mirror::Class> LookupResolvedType(dex::TypeIndex type_idx,
299 ObjPtr<mirror::Class> referrer)
300 REQUIRES_SHARED(Locks::mutator_lock_);
Vladimir Marko09c5ca42018-05-31 15:15:31 +0100301 ObjPtr<mirror::Class> LookupResolvedType(dex::TypeIndex type_idx, ArtField* referrer)
302 REQUIRES_SHARED(Locks::mutator_lock_);
Vladimir Marko666ee3d2017-12-11 18:37:36 +0000303 ObjPtr<mirror::Class> LookupResolvedType(dex::TypeIndex type_idx, ArtMethod* referrer)
304 REQUIRES_SHARED(Locks::mutator_lock_);
305
306 // Look up a resolved type with the given index from the DexFile associated with the given
307 // DexCache and ClassLoader. The ClassLoader is used to search for the type, since it may
308 // be referenced from but not contained within the DexFile.
309 ObjPtr<mirror::Class> LookupResolvedType(dex::TypeIndex type_idx,
310 ObjPtr<mirror::DexCache> dex_cache,
311 ObjPtr<mirror::ClassLoader> class_loader)
312 REQUIRES_SHARED(Locks::mutator_lock_);
313
Vladimir Markoc63d9672021-03-31 15:50:39 +0100314 // Look up a resolved type with the given descriptor associated with the given ClassLoader.
315 ObjPtr<mirror::Class> LookupResolvedType(const char* descriptor,
316 ObjPtr<mirror::ClassLoader> class_loader)
317 REQUIRES_SHARED(Locks::mutator_lock_);
318
Andreas Gampe42ef8ab2015-12-03 17:27:32 -0800319 // Determine whether a dex cache result should be trusted, or an IncompatibleClassChangeError
Vladimir Markoba118822017-06-12 15:41:56 +0100320 // check and IllegalAccessError check should be performed even after a hit.
321 enum class ResolveMode { // private.
322 kNoChecks,
323 kCheckICCEAndIAE
Andreas Gampe42ef8ab2015-12-03 17:27:32 -0800324 };
325
Vladimir Marko07bfbac2017-07-06 14:55:02 +0100326 // Look up a previously resolved method with the given index.
327 ArtMethod* LookupResolvedMethod(uint32_t method_idx,
328 ObjPtr<mirror::DexCache> dex_cache,
329 ObjPtr<mirror::ClassLoader> class_loader)
330 REQUIRES_SHARED(Locks::mutator_lock_);
331
Nicolas Geoffrayea179f42018-02-08 22:30:18 +0000332 // Find a method with the given index from class `klass`, and update the dex cache.
333 ArtMethod* FindResolvedMethod(ObjPtr<mirror::Class> klass,
334 ObjPtr<mirror::DexCache> dex_cache,
335 ObjPtr<mirror::ClassLoader> class_loader,
336 uint32_t method_idx)
337 REQUIRES_SHARED(Locks::mutator_lock_);
338
David Brazdil4525e0b2018-04-05 16:57:32 +0100339 // Find a method using the wrong lookup mechanism. If `klass` is an interface,
340 // search for a class method. If it is a class, search for an interface method.
341 // This is useful when throwing IncompatibleClassChangeError.
342 ArtMethod* FindIncompatibleMethod(ObjPtr<mirror::Class> klass,
343 ObjPtr<mirror::DexCache> dex_cache,
344 ObjPtr<mirror::ClassLoader> class_loader,
345 uint32_t method_idx)
346 REQUIRES_SHARED(Locks::mutator_lock_);
347
Vladimir Marko89011192017-12-11 13:45:05 +0000348 // Resolve a method with a given ID from the DexFile associated with the given DexCache
349 // and ClassLoader, storing the result in DexCache. The ClassLinker and ClassLoader are
350 // used as in ResolveType. What is unique is the method type argument which is used to
351 // determine if this method is a direct, static, or virtual method.
Andreas Gampe42ef8ab2015-12-03 17:27:32 -0800352 template <ResolveMode kResolveMode>
Vladimir Marko89011192017-12-11 13:45:05 +0000353 ArtMethod* ResolveMethod(uint32_t method_idx,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700354 Handle<mirror::DexCache> dex_cache,
Mathieu Chartierc77f3ab2015-09-03 19:41:50 -0700355 Handle<mirror::ClassLoader> class_loader,
356 ArtMethod* referrer,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700357 InvokeType type)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700358 REQUIRES_SHARED(Locks::mutator_lock_)
Andreas Gampecc1b5352016-12-01 16:58:38 -0800359 REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700360
Vladimir Markoba118822017-06-12 15:41:56 +0100361 template <InvokeType type, ResolveMode kResolveMode>
Mathieu Chartiere401d142015-04-22 13:56:20 -0700362 ArtMethod* GetResolvedMethod(uint32_t method_idx, ArtMethod* referrer)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700363 REQUIRES_SHARED(Locks::mutator_lock_);
Alex Lightfedd91d2016-01-07 14:49:16 -0800364
Andreas Gampe42ef8ab2015-12-03 17:27:32 -0800365 template <ResolveMode kResolveMode>
David Srbecky9cc67b12018-10-25 10:10:35 +0000366 ArtMethod* ResolveMethod(Thread* self, uint32_t method_idx, ArtMethod* referrer, InvokeType type)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700367 REQUIRES_SHARED(Locks::mutator_lock_)
Andreas Gampecc1b5352016-12-01 16:58:38 -0800368 REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_);
Vladimir Marko89011192017-12-11 13:45:05 +0000369 ArtMethod* ResolveMethodWithoutInvokeType(uint32_t method_idx,
Jeff Hao0042c6d2015-07-29 20:14:10 -0700370 Handle<mirror::DexCache> dex_cache,
371 Handle<mirror::ClassLoader> class_loader)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700372 REQUIRES_SHARED(Locks::mutator_lock_)
Andreas Gampecc1b5352016-12-01 16:58:38 -0800373 REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_);
Brian Carlstrom16192862011-09-12 17:50:06 -0700374
Vladimir Markof44d36c2017-03-14 14:18:46 +0000375 ArtField* LookupResolvedField(uint32_t field_idx, ArtMethod* referrer, bool is_static)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700376 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700377 ArtField* ResolveField(uint32_t field_idx, ArtMethod* referrer, bool is_static)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700378 REQUIRES_SHARED(Locks::mutator_lock_)
Andreas Gampecc1b5352016-12-01 16:58:38 -0800379 REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_);
Brian Carlstromb9edb842011-08-28 16:31:06 -0700380
Vladimir Markoe11dd502017-12-08 14:09:45 +0000381 // Resolve a field with a given ID from the DexFile associated with the given DexCache
382 // and ClassLoader, storing the result in DexCache. The ClassLinker and ClassLoader
383 // are used as in ResolveType. What is unique is the is_static argument which is used
384 // to determine if we are resolving a static or non-static field.
385 ArtField* ResolveField(uint32_t field_idx,
Mathieu Chartier90443472015-07-16 20:32:27 -0700386 Handle<mirror::DexCache> dex_cache,
Vladimir Markoe11dd502017-12-08 14:09:45 +0000387 Handle<mirror::ClassLoader> class_loader,
388 bool is_static)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700389 REQUIRES_SHARED(Locks::mutator_lock_)
Andreas Gampecc1b5352016-12-01 16:58:38 -0800390 REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700391
Vladimir Markoe11dd502017-12-08 14:09:45 +0000392 // Resolve a field with a given ID from the DexFile associated with the given DexCache
393 // and ClassLoader, storing the result in DexCache. The ClassLinker and ClassLoader
394 // are used as in ResolveType. No is_static argument is provided so that Java
Ian Rogersb067ac22011-12-13 18:05:09 -0800395 // field resolution semantics are followed.
Vladimir Markoe11dd502017-12-08 14:09:45 +0000396 ArtField* ResolveFieldJLS(uint32_t field_idx,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700397 Handle<mirror::DexCache> dex_cache,
398 Handle<mirror::ClassLoader> class_loader)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700399 REQUIRES_SHARED(Locks::mutator_lock_)
Andreas Gampecc1b5352016-12-01 16:58:38 -0800400 REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_);
Ian Rogersb067ac22011-12-13 18:05:09 -0800401
David Brazdil1ab0fa82018-05-04 11:28:03 +0100402 // Find a field with a given ID from the DexFile associated with the given DexCache
403 // and ClassLoader, storing the result in DexCache. The declaring class is assumed
404 // to have been already resolved into `klass`. The `is_static` argument is used to
405 // determine if we are resolving a static or non-static field.
406 ArtField* FindResolvedField(ObjPtr<mirror::Class> klass,
407 ObjPtr<mirror::DexCache> dex_cache,
408 ObjPtr<mirror::ClassLoader> class_loader,
409 uint32_t field_idx,
410 bool is_static)
411 REQUIRES_SHARED(Locks::mutator_lock_);
412
413 // Find a field with a given ID from the DexFile associated with the given DexCache
414 // and ClassLoader, storing the result in DexCache. The declaring class is assumed
415 // to have been already resolved into `klass`. No is_static argument is provided
416 // so that Java field resolution semantics are followed.
417 ArtField* FindResolvedFieldJLS(ObjPtr<mirror::Class> klass,
418 ObjPtr<mirror::DexCache> dex_cache,
419 ObjPtr<mirror::ClassLoader> class_loader,
420 uint32_t field_idx)
421 REQUIRES_SHARED(Locks::mutator_lock_);
422
Vladimir Markoaf940202017-12-08 15:01:18 +0000423 // Resolve a method type with a given ID from the DexFile associated with a given DexCache
424 // and ClassLoader, storing the result in the DexCache.
425 ObjPtr<mirror::MethodType> ResolveMethodType(Thread* self,
Orion Hodson06d10a72018-05-14 08:53:38 +0100426 dex::ProtoIndex proto_idx,
Vladimir Markoaf940202017-12-08 15:01:18 +0000427 Handle<mirror::DexCache> dex_cache,
428 Handle<mirror::ClassLoader> class_loader)
Narayan Kamath25352fc2016-08-03 12:46:58 +0100429 REQUIRES_SHARED(Locks::mutator_lock_)
Andreas Gampecc1b5352016-12-01 16:58:38 -0800430 REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_);
Ian Rogersad25ac52011-10-04 19:13:33 -0700431
Vladimir Markoaf940202017-12-08 15:01:18 +0000432 ObjPtr<mirror::MethodType> ResolveMethodType(Thread* self,
Orion Hodson06d10a72018-05-14 08:53:38 +0100433 dex::ProtoIndex proto_idx,
Vladimir Markoaf940202017-12-08 15:01:18 +0000434 ArtMethod* referrer)
Orion Hodson2e599942017-09-22 16:17:41 +0100435 REQUIRES_SHARED(Locks::mutator_lock_);
436
Orion Hodsonc069a302017-01-18 09:23:12 +0000437 // Resolve a method handle with a given ID from the DexFile. The
438 // result is not cached in the DexCache as the instance will only be
439 // used once in most circumstances.
Vladimir Markoaf940202017-12-08 15:01:18 +0000440 ObjPtr<mirror::MethodHandle> ResolveMethodHandle(Thread* self,
441 uint32_t method_handle_idx,
442 ArtMethod* referrer)
Orion Hodsonc069a302017-01-18 09:23:12 +0000443 REQUIRES_SHARED(Locks::mutator_lock_);
444
Elliott Hughesf4c21c92011-08-19 17:31:31 -0700445 // Returns true on success, false if there's an exception pending.
Brian Carlstrom25c33252011-09-18 15:58:35 -0700446 // can_run_clinit=false allows the compiler to attempt to init a class,
447 // given the restriction that no <clinit> execution is possible.
Mathieu Chartierc77f3ab2015-09-03 19:41:50 -0700448 bool EnsureInitialized(Thread* self,
449 Handle<mirror::Class> c,
450 bool can_init_fields,
Ian Rogers7b078e82014-09-10 14:44:24 -0700451 bool can_init_parents)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700452 REQUIRES_SHARED(Locks::mutator_lock_)
Andreas Gampecc1b5352016-12-01 16:58:38 -0800453 REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700454
Elliott Hughes2a20cfd2011-09-23 19:30:41 -0700455 // Initializes classes that have instances in the image but that have
456 // <clinit> methods so they could not be initialized by the compiler.
Vladimir Markodcfcce42018-06-27 10:00:28 +0000457 void RunRootClinits(Thread* self)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700458 REQUIRES_SHARED(Locks::mutator_lock_)
Andreas Gampecc1b5352016-12-01 16:58:38 -0800459 REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_);
Elliott Hughes2a20cfd2011-09-23 19:30:41 -0700460
Alex Light07f06212017-06-01 14:01:43 -0700461 // Directly register an already existing dex cache. RegisterDexFile should be preferred since that
462 // reduplicates DexCaches when possible. The DexCache given to this function must already be fully
463 // initialized and not already registered.
464 void RegisterExistingDexCache(ObjPtr<mirror::DexCache> cache,
465 ObjPtr<mirror::ClassLoader> class_loader)
466 REQUIRES(!Locks::dex_lock_)
467 REQUIRES_SHARED(Locks::mutator_lock_);
Vladimir Markocd556b02017-02-03 11:47:34 +0000468 ObjPtr<mirror::DexCache> RegisterDexFile(const DexFile& dex_file,
469 ObjPtr<mirror::ClassLoader> class_loader)
Andreas Gampecc1b5352016-12-01 16:58:38 -0800470 REQUIRES(!Locks::dex_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700471 REQUIRES_SHARED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700472
Brian Carlstrom8a487412011-08-29 20:08:52 -0700473 const std::vector<const DexFile*>& GetBootClassPath() {
474 return boot_class_path_;
475 }
476
Mathieu Chartiere0671ce2015-07-28 17:23:28 -0700477 void VisitClasses(ClassVisitor* visitor)
Mathieu Chartierc77f3ab2015-09-03 19:41:50 -0700478 REQUIRES(!Locks::classlinker_classes_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700479 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersdbf3be02014-08-29 15:40:08 -0700480
481 // Less efficient variant of VisitClasses that copies the class_table_ into secondary storage
482 // so that it can visit individual classes without holding the doesn't hold the
483 // Locks::classlinker_classes_lock_. As the Locks::classlinker_classes_lock_ isn't held this code
484 // can race with insertion and deletion of classes while the visitor is being called.
Mathieu Chartiere0671ce2015-07-28 17:23:28 -0700485 void VisitClassesWithoutClassesLock(ClassVisitor* visitor)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700486 REQUIRES_SHARED(Locks::mutator_lock_)
Andreas Gampecc1b5352016-12-01 16:58:38 -0800487 REQUIRES(!Locks::dex_lock_);
Elliott Hughesa2155262011-11-16 16:26:58 -0800488
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -0700489 void VisitClassRoots(RootVisitor* visitor, VisitRootFlags flags)
Andreas Gamped98b4ed2016-11-04 20:27:24 -0700490 REQUIRES(!Locks::classlinker_classes_lock_, !Locks::trace_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700491 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -0700492 void VisitRoots(RootVisitor* visitor, VisitRootFlags flags)
Andreas Gampecc1b5352016-12-01 16:58:38 -0800493 REQUIRES(!Locks::dex_lock_, !Locks::classlinker_classes_lock_, !Locks::trace_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700494 REQUIRES_SHARED(Locks::mutator_lock_);
Alex Lightabd8f052019-12-06 10:49:17 -0800495 // Visits all dex-files accessible by any class-loader or the BCP.
496 template<typename Visitor>
497 void VisitKnownDexFiles(Thread* self, Visitor visitor) REQUIRES(Locks::mutator_lock_);
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700498
Vladimir Markocd556b02017-02-03 11:47:34 +0000499 bool IsDexFileRegistered(Thread* self, const DexFile& dex_file)
500 REQUIRES(!Locks::dex_lock_)
501 REQUIRES_SHARED(Locks::mutator_lock_);
502 ObjPtr<mirror::DexCache> FindDexCache(Thread* self, const DexFile& dex_file)
503 REQUIRES(!Locks::dex_lock_)
504 REQUIRES_SHARED(Locks::mutator_lock_);
Santiago Aboy Solanes4b8ea5d2021-11-19 10:14:54 +0000505 ObjPtr<mirror::DexCache> FindDexCache(Thread* self, const OatDexFile& oat_dex_file)
Santiago Aboy Solanes970ba212021-10-21 10:52:47 +0100506 REQUIRES(!Locks::dex_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Vladimir Markocd556b02017-02-03 11:47:34 +0000507 ClassTable* FindClassTable(Thread* self, ObjPtr<mirror::DexCache> dex_cache)
Andreas Gampecc1b5352016-12-01 16:58:38 -0800508 REQUIRES(!Locks::dex_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700509 REQUIRES_SHARED(Locks::mutator_lock_);
Brian Carlstrom1d9f52b2011-10-13 10:50:45 -0700510
Mathieu Chartier951ec2c2015-09-22 08:50:05 -0700511 LengthPrefixedArray<ArtField>* AllocArtFieldArray(Thread* self,
512 LinearAlloc* allocator,
513 size_t length);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800514
Mathieu Chartier951ec2c2015-09-22 08:50:05 -0700515 LengthPrefixedArray<ArtMethod>* AllocArtMethodArray(Thread* self,
516 LinearAlloc* allocator,
517 size_t length);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700518
Nicolas Geoffray4ac0e152019-09-18 06:14:50 +0000519 // Convenience AllocClass() overload that uses mirror::Class::InitializeClassVisitor
520 // for the class initialization and uses the `java_lang_Class` from class roots
521 // instead of an explicit argument.
522 ObjPtr<mirror::Class> AllocClass(Thread* self, uint32_t class_size)
523 REQUIRES_SHARED(Locks::mutator_lock_)
524 REQUIRES(!Roles::uninterruptible_);
525
526 // Setup the classloader, class def index, type idx so that we can insert this class in the class
527 // table.
528 void SetupClass(const DexFile& dex_file,
529 const dex::ClassDef& dex_class_def,
530 Handle<mirror::Class> klass,
531 ObjPtr<mirror::ClassLoader> class_loader)
532 REQUIRES_SHARED(Locks::mutator_lock_);
533
534 void LoadClass(Thread* self,
535 const DexFile& dex_file,
536 const dex::ClassDef& dex_class_def,
537 Handle<mirror::Class> klass)
538 REQUIRES_SHARED(Locks::mutator_lock_);
539
540 // Link the class and place it into the class-table using the given descriptor. NB if the
541 // descriptor is null the class will not be placed in any class-table. This is useful implementing
542 // obsolete classes and should not be used otherwise.
543 bool LinkClass(Thread* self,
544 const char* descriptor,
545 Handle<mirror::Class> klass,
546 Handle<mirror::ObjectArray<mirror::Class>> interfaces,
547 MutableHandle<mirror::Class>* h_new_class_out)
548 REQUIRES_SHARED(Locks::mutator_lock_)
549 REQUIRES(!Locks::classlinker_classes_lock_);
550
Vladimir Markobcf17522018-06-01 13:14:32 +0100551 ObjPtr<mirror::PointerArray> AllocPointerArray(Thread* self, size_t length)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700552 REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartierc77f3ab2015-09-03 19:41:50 -0700553 REQUIRES(!Roles::uninterruptible_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800554
Vladimir Markobcf17522018-06-01 13:14:32 +0100555 ObjPtr<mirror::ObjectArray<mirror::StackTraceElement>> AllocStackTraceElementArray(Thread* self,
556 size_t length)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700557 REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartierc77f3ab2015-09-03 19:41:50 -0700558 REQUIRES(!Roles::uninterruptible_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800559
Andreas Gampe6d7abbd2017-04-24 13:19:09 -0700560 verifier::FailureKind VerifyClass(
Nicolas Geoffray08025182016-10-25 17:20:18 +0100561 Thread* self,
Nicolas Geoffray5b0b2e12021-03-19 14:48:40 +0000562 verifier::VerifierDeps* verifier_deps,
Nicolas Geoffray08025182016-10-25 17:20:18 +0100563 Handle<mirror::Class> klass,
564 verifier::HardFailLogMode log_level = verifier::HardFailLogMode::kLogNone)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700565 REQUIRES_SHARED(Locks::mutator_lock_)
Andreas Gampecc1b5352016-12-01 16:58:38 -0800566 REQUIRES(!Locks::dex_lock_);
Nicolas Geoffray6df45112021-02-07 21:51:58 +0000567 bool VerifyClassUsingOatFile(Thread* self,
568 const DexFile& dex_file,
569 Handle<mirror::Class> klass,
Vladimir Marko2c64a832018-01-04 11:31:56 +0000570 ClassStatus& oat_file_class_status)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700571 REQUIRES_SHARED(Locks::mutator_lock_)
Andreas Gampecc1b5352016-12-01 16:58:38 -0800572 REQUIRES(!Locks::dex_lock_);
Alex Light5a559862016-01-29 12:24:48 -0800573 void ResolveClassExceptionHandlerTypes(Handle<mirror::Class> klass)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700574 REQUIRES_SHARED(Locks::mutator_lock_)
Andreas Gampecc1b5352016-12-01 16:58:38 -0800575 REQUIRES(!Locks::dex_lock_);
Alex Light5a559862016-01-29 12:24:48 -0800576 void ResolveMethodExceptionHandlerTypes(ArtMethod* klass)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700577 REQUIRES_SHARED(Locks::mutator_lock_)
Andreas Gampecc1b5352016-12-01 16:58:38 -0800578 REQUIRES(!Locks::dex_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800579
Vladimir Markoa8bba7d2018-05-30 15:18:48 +0100580 ObjPtr<mirror::Class> CreateProxyClass(ScopedObjectAccessAlreadyRunnable& soa,
581 jstring name,
582 jobjectArray interfaces,
583 jobject loader,
584 jobjectArray methods,
585 jobjectArray throws)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700586 REQUIRES_SHARED(Locks::mutator_lock_);
Jesse Wilson95caa792011-10-12 18:14:17 -0400587
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700588 pid_t GetClassesLockOwner(); // For SignalCatcher.
589 pid_t GetDexLockOwner(); // For SignalCatcher.
Brian Carlstrom24a3c2e2011-10-17 18:07:52 -0700590
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700591 // Is the given entry point quick code to run the resolution stub?
592 bool IsQuickResolutionStub(const void* entry_point) const;
Jeff Hao88474b42013-10-23 16:24:40 -0700593
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700594 // Is the given entry point quick code to bridge into the interpreter?
595 bool IsQuickToInterpreterBridge(const void* entry_point) const;
596
597 // Is the given entry point quick code to run the generic JNI stub?
598 bool IsQuickGenericJniStub(const void* entry_point) const;
Vladimir Marko8a630572014-04-09 18:45:35 +0100599
David Sehra49e0532017-08-25 08:05:29 -0700600 // Is the given entry point the JNI dlsym lookup stub?
601 bool IsJniDlsymLookupStub(const void* entry_point) const;
602
Vladimir Markofa458ac2020-02-12 14:08:07 +0000603 // Is the given entry point the JNI dlsym lookup critical stub?
604 bool IsJniDlsymLookupCriticalStub(const void* entry_point) const;
605
Nicolas Geoffrayc39af942021-01-25 08:43:57 +0000606 // Is the given entry point the nterp trampoline?
607 bool IsNterpTrampoline(const void* entry_point) const {
608 return nterp_trampoline_ == entry_point;
609 }
610
Vladimir Marko97d7e1c2016-10-04 14:44:28 +0100611 const void* GetQuickToInterpreterBridgeTrampoline() const {
612 return quick_to_interpreter_bridge_trampoline_;
613 }
614
Jeff Hao88474b42013-10-23 16:24:40 -0700615 InternTable* GetInternTable() const {
616 return intern_table_;
617 }
618
Alex Lightdb01a092017-04-03 15:39:55 -0700619 // Set the entrypoints up for an obsolete method.
620 void SetEntryPointsForObsoleteMethod(ArtMethod* method) const
621 REQUIRES_SHARED(Locks::mutator_lock_);
622
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700623 // Attempts to insert a class into a class table. Returns null if
Ian Rogers848871b2013-08-05 10:56:33 -0700624 // the class was inserted, otherwise returns an existing class with
625 // the same descriptor and ClassLoader.
Vladimir Markoa8bba7d2018-05-30 15:18:48 +0100626 ObjPtr<mirror::Class> InsertClass(const char* descriptor,
627 ObjPtr<mirror::Class> klass,
628 size_t hash)
Mathieu Chartier90443472015-07-16 20:32:27 -0700629 REQUIRES(!Locks::classlinker_classes_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700630 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers848871b2013-08-05 10:56:33 -0700631
Vladimir Marko1998cd02017-01-13 13:02:58 +0000632 // Add an oat file with .bss GC roots to be visited again at the end of GC
633 // for collector types that need it.
634 void WriteBarrierForBootOatFileBssRoots(const OatFile* oat_file)
635 REQUIRES(!Locks::classlinker_classes_lock_)
636 REQUIRES_SHARED(Locks::mutator_lock_);
637
Vladimir Markob4eb1b12018-05-24 11:09:38 +0100638 template <ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampe88dbad32018-06-26 19:54:12 -0700639 ObjPtr<mirror::ObjectArray<mirror::Class>> GetClassRoots() REQUIRES_SHARED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700640
Mathieu Chartierc2e20622014-11-03 11:41:47 -0800641 // Move the class table to the pre-zygote table to reduce memory usage. This works by ensuring
642 // that no more classes are ever added to the pre zygote table which makes it that the pages
643 // always remain shared dirty instead of private dirty.
644 void MoveClassTableToPreZygote()
Mathieu Chartier90443472015-07-16 20:32:27 -0700645 REQUIRES(!Locks::classlinker_classes_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700646 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartierc2e20622014-11-03 11:41:47 -0800647
Calin Juravle7865ac72017-06-28 11:03:12 -0700648 // Creates a GlobalRef PathClassLoader or DelegateLastClassLoader (specified by loader_class)
649 // that can be used to load classes from the given dex files. The parent of the class loader
650 // will be set to `parent_loader`. If `parent_loader` is null the parent will be
651 // the boot class loader.
652 // If class_loader points to a different class than PathClassLoader or DelegateLastClassLoader
653 // this method will abort.
Andreas Gampe81c6f8d2015-03-25 17:19:53 -0700654 // Note: the objects are not completely set up. Do not use this outside of tests and the compiler.
Calin Juravle7865ac72017-06-28 11:03:12 -0700655 jobject CreateWellKnownClassLoader(Thread* self,
656 const std::vector<const DexFile*>& dex_files,
657 jclass loader_class,
Nicolas Geoffraye1672732018-11-30 01:09:49 +0000658 jobject parent_loader,
Brad Stenning9c924e82021-10-11 19:09:00 -0700659 jobject shared_libraries = nullptr,
660 jobject shared_libraries_after = nullptr)
Calin Juravle7865ac72017-06-28 11:03:12 -0700661 REQUIRES_SHARED(Locks::mutator_lock_)
662 REQUIRES(!Locks::dex_lock_);
663
664 // Calls CreateWellKnownClassLoader(self,
665 // dex_files,
666 // WellKnownClasses::dalvik_system_PathClassLoader,
667 // nullptr)
Jeff Haof0192c82016-03-28 20:39:50 -0700668 jobject CreatePathClassLoader(Thread* self, const std::vector<const DexFile*>& dex_files)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700669 REQUIRES_SHARED(Locks::mutator_lock_)
Andreas Gampecc1b5352016-12-01 16:58:38 -0800670 REQUIRES(!Locks::dex_lock_);
Andreas Gampe81c6f8d2015-03-25 17:19:53 -0700671
Nicolas Geoffray6b9fd8c2018-11-16 10:25:42 +0000672 // Non-GlobalRef version of CreateWellKnownClassLoader
673 ObjPtr<mirror::ClassLoader> CreateWellKnownClassLoader(
674 Thread* self,
675 const std::vector<const DexFile*>& dex_files,
676 Handle<mirror::Class> loader_class,
Nicolas Geoffraye1672732018-11-30 01:09:49 +0000677 Handle<mirror::ClassLoader> parent_loader,
Brad Stenning9c924e82021-10-11 19:09:00 -0700678 Handle<mirror::ObjectArray<mirror::ClassLoader>> shared_libraries,
679 Handle<mirror::ObjectArray<mirror::ClassLoader>> shared_libraries_after)
Nicolas Geoffray6b9fd8c2018-11-16 10:25:42 +0000680 REQUIRES_SHARED(Locks::mutator_lock_)
681 REQUIRES(!Locks::dex_lock_);
682
Andreas Gampe542451c2016-07-26 09:02:02 -0700683 PointerSize GetImagePointerSize() const {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700684 return image_pointer_size_;
685 }
686
Andreas Gampe8ac75952015-06-02 21:01:45 -0700687 // Clear the ArrayClass cache. This is necessary when cleaning up for the image, as the cache
688 // entries are roots, but potentially not image classes.
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700689 void DropFindArrayClassCache() REQUIRES_SHARED(Locks::mutator_lock_);
Andreas Gampe8ac75952015-06-02 21:01:45 -0700690
Mathieu Chartier951ec2c2015-09-22 08:50:05 -0700691 // Clean up class loaders, this needs to happen after JNI weak globals are cleared.
692 void CleanupClassLoaders()
Mathieu Chartier00310e02015-10-17 12:46:42 -0700693 REQUIRES(!Locks::classlinker_classes_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700694 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier951ec2c2015-09-22 08:50:05 -0700695
Mathieu Chartier32cc9ee2015-10-15 09:19:15 -0700696 // Unlike GetOrCreateAllocatorForClassLoader, GetAllocatorForClassLoader asserts that the
697 // allocator for this class loader is already created.
Mathieu Chartier28357fa2016-10-18 16:27:40 -0700698 LinearAlloc* GetAllocatorForClassLoader(ObjPtr<mirror::ClassLoader> class_loader)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700699 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier951ec2c2015-09-22 08:50:05 -0700700
Mathieu Chartierd57d4542015-10-14 10:55:30 -0700701 // Return the linear alloc for a class loader if it is already allocated, otherwise allocate and
702 // set it. TODO: Consider using a lock other than classlinker_classes_lock_.
Mathieu Chartier28357fa2016-10-18 16:27:40 -0700703 LinearAlloc* GetOrCreateAllocatorForClassLoader(ObjPtr<mirror::ClassLoader> class_loader)
Mathieu Chartier00310e02015-10-17 12:46:42 -0700704 REQUIRES(!Locks::classlinker_classes_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700705 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier00310e02015-10-17 12:46:42 -0700706
Mathieu Chartier6d25cf62016-04-12 16:54:48 -0700707 // May be called with null class_loader due to legacy code. b/27954959
Mathieu Chartierbc5a7952016-10-17 15:46:31 -0700708 void InsertDexFileInToClassLoader(ObjPtr<mirror::Object> dex_file,
709 ObjPtr<mirror::ClassLoader> class_loader)
Mathieu Chartier00310e02015-10-17 12:46:42 -0700710 REQUIRES(!Locks::classlinker_classes_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700711 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartierd57d4542015-10-14 10:55:30 -0700712
Jeff Haof0192c82016-03-28 20:39:50 -0700713 static bool IsBootClassLoader(ScopedObjectAccessAlreadyRunnable& soa,
Mathieu Chartier28357fa2016-10-18 16:27:40 -0700714 ObjPtr<mirror::ClassLoader> class_loader)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700715 REQUIRES_SHARED(Locks::mutator_lock_);
Jeff Haof0192c82016-03-28 20:39:50 -0700716
Mathieu Chartier28357fa2016-10-18 16:27:40 -0700717 ArtMethod* AddMethodToConflictTable(ObjPtr<mirror::Class> klass,
Mathieu Chartier7f98c9a2016-04-14 10:49:19 -0700718 ArtMethod* conflict_method,
719 ArtMethod* interface_method,
Nicolas Geoffray47213e42020-12-30 15:12:00 +0000720 ArtMethod* method)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700721 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier7f98c9a2016-04-14 10:49:19 -0700722
Mathieu Chartiere42888f2016-04-14 10:49:19 -0700723 // Create a conflict table with a specified capacity.
724 ImtConflictTable* CreateImtConflictTable(size_t count, LinearAlloc* linear_alloc);
725
726 // Static version for when the class linker is not yet created.
727 static ImtConflictTable* CreateImtConflictTable(size_t count,
728 LinearAlloc* linear_alloc,
Andreas Gampe542451c2016-07-26 09:02:02 -0700729 PointerSize pointer_size);
Mathieu Chartiere42888f2016-04-14 10:49:19 -0700730
731
732 // Create the IMT and conflict tables for a class.
Mathieu Chartier28357fa2016-10-18 16:27:40 -0700733 void FillIMTAndConflictTables(ObjPtr<mirror::Class> klass) REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartiere42888f2016-04-14 10:49:19 -0700734
Mathieu Chartier72041a02017-07-14 18:23:25 -0700735 // Visit all of the class tables. This is used by dex2oat to allow pruning dex caches.
736 template <class Visitor>
737 void VisitClassTables(const Visitor& visitor)
Mathieu Chartier696632e2016-06-03 17:47:32 -0700738 REQUIRES(!Locks::classlinker_classes_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700739 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartiere42888f2016-04-14 10:49:19 -0700740
Alexey Grebenkin252a4e42018-04-02 18:18:01 +0300741 // Visit all of the allocators that belong to classloaders except boot classloader.
742 // This is used by 616-cha-unloading test to confirm memory reuse.
743 void VisitAllocators(AllocatorVisitor* visitor) const
744 REQUIRES_SHARED(Locks::classlinker_classes_lock_, Locks::mutator_lock_);
745
Jeff Haoc92a7a12016-06-06 11:09:20 -0700746 // Throw the class initialization failure recorded when first trying to initialize the given
747 // class.
Andreas Gampe7b3063b2019-01-07 14:12:52 -0800748 void ThrowEarlierClassFailure(ObjPtr<mirror::Class> c,
749 bool wrap_in_no_class_def = false,
750 bool log = false)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700751 REQUIRES_SHARED(Locks::mutator_lock_)
Andreas Gampecc1b5352016-12-01 16:58:38 -0800752 REQUIRES(!Locks::dex_lock_);
Jeff Haoc92a7a12016-06-06 11:09:20 -0700753
Mathieu Chartier65975772016-08-05 10:46:36 -0700754 // Get the actual holding class for a copied method. Pretty slow, don't call often.
Vladimir Markoa8bba7d2018-05-30 15:18:48 +0100755 ObjPtr<mirror::Class> GetHoldingClassOfCopiedMethod(ArtMethod* method)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700756 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier65975772016-08-05 10:46:36 -0700757
Andreas Gampe70f16392017-01-16 14:20:10 -0800758 // Returns null if not found.
Andreas Gampe2af99022017-04-25 08:32:59 -0700759 // This returns a pointer to the class-table, without requiring any locking - including the
760 // boot class-table. It is the caller's responsibility to access this under lock, if required.
Andreas Gampe70f16392017-01-16 14:20:10 -0800761 ClassTable* ClassTableForClassLoader(ObjPtr<mirror::ClassLoader> class_loader)
Andreas Gampe2af99022017-04-25 08:32:59 -0700762 REQUIRES_SHARED(Locks::mutator_lock_)
763 NO_THREAD_SAFETY_ANALYSIS;
Andreas Gampe70f16392017-01-16 14:20:10 -0800764
Mathieu Chartier0a19e212019-11-27 14:35:24 -0800765 void AppendToBootClassPath(Thread* self, const DexFile* dex_file)
Andreas Gampece7732b2017-01-17 15:50:26 -0800766 REQUIRES_SHARED(Locks::mutator_lock_)
767 REQUIRES(!Locks::dex_lock_);
768
Nicolas Geoffray7913cf32022-02-16 09:28:21 +0000769 void AppendToBootClassPath(const DexFile* dex_file, ObjPtr<mirror::DexCache> dex_cache)
770 REQUIRES_SHARED(Locks::mutator_lock_)
771 REQUIRES(!Locks::dex_lock_);
772
Mathieu Chartier06bed302017-07-13 13:23:18 -0700773 // Visit all of the class loaders in the class linker.
774 void VisitClassLoaders(ClassLoaderVisitor* visitor) const
775 REQUIRES_SHARED(Locks::classlinker_classes_lock_, Locks::mutator_lock_);
776
Jeff Hao0cb17282017-07-12 14:51:49 -0700777 // Checks that a class and its superclass from another class loader have the same virtual methods.
778 bool ValidateSuperClassDescriptors(Handle<mirror::Class> klass)
779 REQUIRES_SHARED(Locks::mutator_lock_);
780
Andreas Gampec1ac9ee2017-07-24 22:35:49 -0700781 ClassHierarchyAnalysis* GetClassHierarchyAnalysis() {
782 return cha_.get();
783 }
784
Vladimir Markobf121912019-06-04 13:49:05 +0100785 void MakeInitializedClassesVisiblyInitialized(Thread* self, bool wait);
786
Vladimir Marko86c87522020-05-11 16:55:55 +0100787 // Registers the native method and returns the new entry point. NB The returned entry point
788 // might be different from the native_method argument if some MethodCallback modifies it.
789 const void* RegisterNative(Thread* self, ArtMethod* method, const void* native_method)
Nicolas Geoffrayd0f099e2022-03-09 16:22:34 +0000790 REQUIRES_SHARED(Locks::mutator_lock_);
Vladimir Marko86c87522020-05-11 16:55:55 +0100791
792 // Unregister native code for a method.
793 void UnregisterNative(Thread* self, ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_);
794
795 // Get the registered native method entrypoint, if any, otherwise null.
796 const void* GetRegisteredNative(Thread* self, ArtMethod* method)
797 REQUIRES_SHARED(Locks::mutator_lock_)
798 REQUIRES(!critical_native_code_with_clinit_check_lock_);
799
Hiroshi Yamauchi04302db2015-11-11 23:45:34 -0800800 struct DexCacheData {
Vladimir Markocd556b02017-02-03 11:47:34 +0000801 // Construct an invalid data object.
David Srbecky6fbcc292021-02-23 01:05:32 +0000802 DexCacheData() : weak_root(nullptr), class_table(nullptr) {
803 static std::atomic_uint64_t s_registration_count(0);
804 registration_index = s_registration_count.fetch_add(1, std::memory_order_seq_cst);
Vladimir Markocd556b02017-02-03 11:47:34 +0000805 }
David Srbecky6fbcc292021-02-23 01:05:32 +0000806 DexCacheData(DexCacheData&&) = default;
Vladimir Markocd556b02017-02-03 11:47:34 +0000807
Hiroshi Yamauchi04302db2015-11-11 23:45:34 -0800808 // Weak root to the DexCache. Note: Do not decode this unnecessarily or else class unloading may
809 // not work properly.
810 jweak weak_root;
Vladimir Markocd556b02017-02-03 11:47:34 +0000811 // Identify the associated class loader's class table. This is used to make sure that
812 // the Java call to native DexCache.setResolvedType() inserts the resolved type in that
813 // class table. It is also used to make sure we don't register the same dex cache with
814 // multiple class loaders.
815 ClassTable* class_table;
David Srbecky6fbcc292021-02-23 01:05:32 +0000816 // Monotonically increasing integer which records the order in which DexFiles were registered.
817 // Used only to preserve determinism when creating compiled image.
818 uint64_t registration_index;
819
820 private:
821 DISALLOW_COPY_AND_ASSIGN(DexCacheData);
Hiroshi Yamauchi04302db2015-11-11 23:45:34 -0800822 };
823
Alex Lightfb119572019-09-18 15:04:53 -0700824 // Forces a class to be marked as initialized without actually running initializers. Should only
825 // be used by plugin code when creating new classes directly.
826 void ForceClassInitialized(Thread* self, Handle<mirror::Class> klass)
827 REQUIRES_SHARED(Locks::mutator_lock_)
828 REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_);
829
Calin Juravle33787682019-07-26 14:27:18 -0700830 // Verifies if the method is accesible according to the SdkChecker (if installed).
Calin Juravle2c2724c2021-01-14 19:54:23 -0800831 virtual bool DenyAccessBasedOnPublicSdk(ArtMethod* art_method) const
Calin Juravle33787682019-07-26 14:27:18 -0700832 REQUIRES_SHARED(Locks::mutator_lock_);
833 // Verifies if the field is accesible according to the SdkChecker (if installed).
Calin Juravle2c2724c2021-01-14 19:54:23 -0800834 virtual bool DenyAccessBasedOnPublicSdk(ArtField* art_field) const
Calin Juravle33787682019-07-26 14:27:18 -0700835 REQUIRES_SHARED(Locks::mutator_lock_);
836 // Verifies if the descriptor is accesible according to the SdkChecker (if installed).
Calin Juravle2c2724c2021-01-14 19:54:23 -0800837 virtual bool DenyAccessBasedOnPublicSdk(const char* type_descriptor) const;
838 // Enable or disable public sdk checks.
839 virtual void SetEnablePublicSdkChecks(bool enabled);
Guo Li1ee02902022-07-13 15:57:31 +0800840 void RemoveDexFromCaches(const DexFile& dex_file);
Calin Juravle33787682019-07-26 14:27:18 -0700841
Chang Xing605fe242017-07-20 15:57:21 -0700842 protected:
843 virtual bool InitializeClass(Thread* self,
844 Handle<mirror::Class> klass,
845 bool can_run_clinit,
846 bool can_init_parents)
847 REQUIRES_SHARED(Locks::mutator_lock_)
848 REQUIRES(!Locks::dex_lock_);
849
Mathieu Chartier9e050df2017-08-09 10:05:47 -0700850 virtual verifier::FailureKind PerformClassVerification(Thread* self,
Nicolas Geoffray5b0b2e12021-03-19 14:48:40 +0000851 verifier::VerifierDeps* verifier_deps,
Mathieu Chartier9e050df2017-08-09 10:05:47 -0700852 Handle<mirror::Class> klass,
853 verifier::HardFailLogMode log_level,
854 std::string* error_msg)
855 REQUIRES_SHARED(Locks::mutator_lock_);
856
Chang Xing0c2c2222017-08-04 14:36:17 -0700857 virtual bool CanAllocClass() REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::dex_lock_) {
858 return true;
859 }
860
Mathieu Chartier951ec2c2015-09-22 08:50:05 -0700861 private:
Vladimir Marko42bee502021-01-28 14:58:35 +0000862 class LinkFieldsHelper;
Vladimir Markob91402f2021-12-21 15:55:06 +0000863 template <PointerSize kPointerSize>
Vladimir Markobc893672021-11-10 15:25:46 +0000864 class LinkMethodsHelper;
Vladimir Markobf121912019-06-04 13:49:05 +0100865 class VisiblyInitializedCallback;
Vladimir Marko921094a2017-01-12 18:37:06 +0000866
Mathieu Chartier951ec2c2015-09-22 08:50:05 -0700867 struct ClassLoaderData {
Mathieu Chartierc3fcd412015-09-25 16:54:59 -0700868 jweak weak_root; // Weak root to enable class unloading.
Mathieu Chartier951ec2c2015-09-22 08:50:05 -0700869 ClassTable* class_table;
870 LinearAlloc* allocator;
871 };
872
Vladimir Markobf121912019-06-04 13:49:05 +0100873 void VisiblyInitializedCallbackDone(Thread* self, VisiblyInitializedCallback* callback);
874 VisiblyInitializedCallback* MarkClassInitialized(Thread* self, Handle<mirror::Class> klass)
875 REQUIRES_SHARED(Locks::mutator_lock_);
876
Alex Lightf1f10492015-10-07 16:08:36 -0700877 // Ensures that the supertype of 'klass' ('supertype') is verified. Returns false and throws
878 // appropriate exceptions if verification failed hard. Returns true for successful verification or
879 // soft-failures.
880 bool AttemptSupertypeVerification(Thread* self,
Nicolas Geoffray5b0b2e12021-03-19 14:48:40 +0000881 verifier::VerifierDeps* verifier_deps,
Alex Lightf1f10492015-10-07 16:08:36 -0700882 Handle<mirror::Class> klass,
883 Handle<mirror::Class> supertype)
Andreas Gampecc1b5352016-12-01 16:58:38 -0800884 REQUIRES(!Locks::dex_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700885 REQUIRES_SHARED(Locks::mutator_lock_);
Alex Lightf1f10492015-10-07 16:08:36 -0700886
Alexey Grebenkinbe4c2bd2018-02-01 19:09:59 +0300887 void DeleteClassLoader(Thread* self, const ClassLoaderData& data, bool cleanup_cha)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700888 REQUIRES_SHARED(Locks::mutator_lock_);
Nicolas Geoffray1dad3f62015-10-23 14:59:54 +0100889
Mathieu Chartiere0671ce2015-07-28 17:23:28 -0700890 void VisitClassesInternal(ClassVisitor* visitor)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700891 REQUIRES_SHARED(Locks::classlinker_classes_lock_, Locks::mutator_lock_);
Mathieu Chartiercc5ebdf2015-07-27 11:19:43 -0700892
893 // Returns the number of zygote and image classes.
Mathieu Chartier6b069532015-08-05 15:08:12 -0700894 size_t NumZygoteClasses() const
895 REQUIRES(Locks::classlinker_classes_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700896 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartiercc5ebdf2015-07-27 11:19:43 -0700897
898 // Returns the number of non zygote nor image classes.
Mathieu Chartier6b069532015-08-05 15:08:12 -0700899 size_t NumNonZygoteClasses() const
900 REQUIRES(Locks::classlinker_classes_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700901 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartiercc5ebdf2015-07-27 11:19:43 -0700902
Mathieu Chartierc77f3ab2015-09-03 19:41:50 -0700903 void FinishInit(Thread* self)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700904 REQUIRES_SHARED(Locks::mutator_lock_)
Andreas Gampecc1b5352016-12-01 16:58:38 -0800905 REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_);
Brian Carlstroma663ea52011-08-19 23:33:41 -0700906
Roland Levillain0e840272018-08-23 19:55:30 +0100907 // If we do not allow moving classes (`art::kMovingClass` is false) or if
908 // parameter `kMovable` is false (or both), the class object is allocated in
909 // the non-moving space.
Vladimir Marko70e2a762019-07-12 16:49:00 +0100910 template <bool kMovable = true, class PreFenceVisitor>
911 ObjPtr<mirror::Class> AllocClass(Thread* self,
912 ObjPtr<mirror::Class> java_lang_Class,
913 uint32_t class_size,
914 const PreFenceVisitor& pre_fence_visitor)
915 REQUIRES_SHARED(Locks::mutator_lock_)
916 REQUIRES(!Roles::uninterruptible_);
917
918 // Convenience AllocClass() overload that uses mirror::Class::InitializeClassVisitor
919 // for the class initialization.
Roland Levillain0e840272018-08-23 19:55:30 +0100920 template <bool kMovable = true>
Vladimir Markoa8bba7d2018-05-30 15:18:48 +0100921 ObjPtr<mirror::Class> AllocClass(Thread* self,
922 ObjPtr<mirror::Class> java_lang_Class,
923 uint32_t class_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700924 REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartierc77f3ab2015-09-03 19:41:50 -0700925 REQUIRES(!Roles::uninterruptible_);
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700926
Vladimir Marko70e2a762019-07-12 16:49:00 +0100927 // Allocate a primitive array class and store it in appropriate class root.
928 void AllocPrimitiveArrayClass(Thread* self,
929 ClassRoot primitive_root,
930 ClassRoot array_root)
931 REQUIRES_SHARED(Locks::mutator_lock_)
932 REQUIRES(!Roles::uninterruptible_);
933
934 // Finish setup of an array class.
935 void FinishArrayClassSetup(ObjPtr<mirror::Class> array_class)
936 REQUIRES_SHARED(Locks::mutator_lock_)
937 REQUIRES(!Roles::uninterruptible_);
938
939 // Finish setup of a core array class (Object[], Class[], String[] and
940 // primitive arrays) and insert it into the class table.
941 void FinishCoreArrayClassSetup(ClassRoot array_root)
Roland Levillain0e840272018-08-23 19:55:30 +0100942 REQUIRES_SHARED(Locks::mutator_lock_)
943 REQUIRES(!Roles::uninterruptible_);
944
David Srbecky86d6cd52020-12-02 18:13:10 +0000945 ObjPtr<mirror::DexCache> AllocDexCache(Thread* self, const DexFile& dex_file)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700946 REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartierc77f3ab2015-09-03 19:41:50 -0700947 REQUIRES(!Roles::uninterruptible_);
Ian Rogersbdb03912011-09-14 00:55:44 -0700948
Mathieu Chartier6c60d842016-09-15 10:24:43 -0700949 // Used for tests and AppendToBootClassPath.
Vladimir Markobcf17522018-06-01 13:14:32 +0100950 ObjPtr<mirror::DexCache> AllocAndInitializeDexCache(Thread* self,
951 const DexFile& dex_file,
David Srbecky33df0e32021-09-30 14:36:32 +0000952 ObjPtr<mirror::ClassLoader> class_loader)
Mathieu Chartier6c60d842016-09-15 10:24:43 -0700953 REQUIRES_SHARED(Locks::mutator_lock_)
Andreas Gampecc1b5352016-12-01 16:58:38 -0800954 REQUIRES(!Locks::dex_lock_)
Mathieu Chartier6c60d842016-09-15 10:24:43 -0700955 REQUIRES(!Roles::uninterruptible_);
956
Vladimir Marko70e2a762019-07-12 16:49:00 +0100957 // Create a primitive class and store it in the appropriate class root.
958 void CreatePrimitiveClass(Thread* self, Primitive::Type type, ClassRoot primitive_root)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700959 REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartierc77f3ab2015-09-03 19:41:50 -0700960 REQUIRES(!Roles::uninterruptible_);
Brian Carlstroma331b3c2011-07-18 17:47:56 -0700961
Vladimir Markoa8bba7d2018-05-30 15:18:48 +0100962 ObjPtr<mirror::Class> CreateArrayClass(Thread* self,
963 const char* descriptor,
964 size_t hash,
965 Handle<mirror::ClassLoader> class_loader)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700966 REQUIRES_SHARED(Locks::mutator_lock_)
Andreas Gampecc1b5352016-12-01 16:58:38 -0800967 REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_);
Brian Carlstroma331b3c2011-07-18 17:47:56 -0700968
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700969 // Precomputes size needed for Class, in the case of a non-temporary class this size must be
970 // sufficient to hold all static fields.
971 uint32_t SizeOfClassWithoutEmbeddedTables(const DexFile& dex_file,
Andreas Gampe3f1dcd32018-12-28 09:39:56 -0800972 const dex::ClassDef& dex_class_def);
Brian Carlstrom4873d462011-08-21 15:23:39 -0700973
Mathieu Chartier1f1cb9f2018-06-04 09:22:46 -0700974 void LoadField(const ClassAccessor::Field& field, Handle<mirror::Class> klass, ArtField* dst)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700975 REQUIRES_SHARED(Locks::mutator_lock_);
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700976
Mathieu Chartier268764d2016-09-13 12:09:38 -0700977 void LoadMethod(const DexFile& dex_file,
Mathieu Chartier1f1cb9f2018-06-04 09:22:46 -0700978 const ClassAccessor::Method& method,
Vladimir Marko05f1a5b2022-03-09 14:20:15 +0000979 ObjPtr<mirror::Class> klass,
Mathieu Chartier1f1cb9f2018-06-04 09:22:46 -0700980 ArtMethod* dst)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700981 REQUIRES_SHARED(Locks::mutator_lock_);
Brian Carlstrom934486c2011-07-12 23:42:50 -0700982
Vladimir Marko86c87522020-05-11 16:55:55 +0100983 void FixupStaticTrampolines(Thread* self, ObjPtr<mirror::Class> klass)
984 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers19846512012-02-24 11:42:47 -0800985
Nicolas Geoffray7d8d8ff2016-11-02 12:38:05 +0000986 // Finds a class in a Path- or DexClassLoader, loading it if necessary without using JNI. Hash
Andreas Gampe34ee6842014-12-02 15:43:52 -0800987 // function is supposed to be ComputeModifiedUtf8Hash(descriptor). Returns true if the
988 // class-loader chain could be handled, false otherwise, i.e., a non-supported class-loader
989 // was encountered while walking the parent chain (currently only BootClassLoader and
990 // PathClassLoader are supported).
Nicolas Geoffray7d8d8ff2016-11-02 12:38:05 +0000991 bool FindClassInBaseDexClassLoader(ScopedObjectAccessAlreadyRunnable& soa,
992 Thread* self,
993 const char* descriptor,
994 size_t hash,
995 Handle<mirror::ClassLoader> class_loader,
Vladimir Markobcf17522018-06-01 13:14:32 +0100996 /*out*/ ObjPtr<mirror::Class>* result)
Andreas Gampe34ee6842014-12-02 15:43:52 -0800997 REQUIRES_SHARED(Locks::mutator_lock_)
Andreas Gampecc1b5352016-12-01 16:58:38 -0800998 REQUIRES(!Locks::dex_lock_);
Andreas Gampe34ee6842014-12-02 15:43:52 -0800999
Nicolas Geoffray80a560c2018-10-26 13:48:51 +01001000 bool FindClassInSharedLibraries(ScopedObjectAccessAlreadyRunnable& soa,
1001 Thread* self,
1002 const char* descriptor,
1003 size_t hash,
1004 Handle<mirror::ClassLoader> class_loader,
1005 /*out*/ ObjPtr<mirror::Class>* result)
1006 REQUIRES_SHARED(Locks::mutator_lock_)
1007 REQUIRES(!Locks::dex_lock_);
1008
Brad Stenning9c924e82021-10-11 19:09:00 -07001009 bool FindClassInSharedLibrariesHelper(ScopedObjectAccessAlreadyRunnable& soa,
1010 Thread* self,
1011 const char* descriptor,
1012 size_t hash,
1013 Handle<mirror::ClassLoader> class_loader,
1014 ArtField* field,
1015 /*out*/ ObjPtr<mirror::Class>* result)
1016 REQUIRES_SHARED(Locks::mutator_lock_)
1017 REQUIRES(!Locks::dex_lock_);
1018
1019 bool FindClassInSharedLibrariesAfter(ScopedObjectAccessAlreadyRunnable& soa,
1020 Thread* self,
1021 const char* descriptor,
1022 size_t hash,
1023 Handle<mirror::ClassLoader> class_loader,
1024 /*out*/ ObjPtr<mirror::Class>* result)
1025 REQUIRES_SHARED(Locks::mutator_lock_)
1026 REQUIRES(!Locks::dex_lock_);
1027
Calin Juravle415dc3d2017-06-28 11:03:12 -07001028 // Finds the class in the classpath of the given class loader. It only searches the class loader
1029 // dex files and does not recurse into its parent.
1030 // The method checks that the provided class loader is either a PathClassLoader or a
1031 // DexClassLoader.
Nicolas Geoffraye8445e52021-09-23 14:10:05 +01001032 // If the class is found the method updates `result`.
1033 // The method always returns true, to notify to the caller a
1034 // BaseDexClassLoader has a known lookup.
1035 bool FindClassInBaseDexClassLoaderClassPath(
Calin Juravle415dc3d2017-06-28 11:03:12 -07001036 ScopedObjectAccessAlreadyRunnable& soa,
1037 const char* descriptor,
1038 size_t hash,
Nicolas Geoffraye8445e52021-09-23 14:10:05 +01001039 Handle<mirror::ClassLoader> class_loader,
1040 /*out*/ ObjPtr<mirror::Class>* result)
Calin Juravle415dc3d2017-06-28 11:03:12 -07001041 REQUIRES_SHARED(Locks::mutator_lock_)
1042 REQUIRES(!Locks::dex_lock_);
1043
1044 // Finds the class in the boot class loader.
Nicolas Geoffraye8445e52021-09-23 14:10:05 +01001045 // If the class is found the method updates `result`.
1046 // The method always returns true, to notify to the caller the
1047 // boot class loader has a known lookup.
1048 bool FindClassInBootClassLoaderClassPath(Thread* self,
1049 const char* descriptor,
1050 size_t hash,
1051 /*out*/ ObjPtr<mirror::Class>* result)
Calin Juravle415dc3d2017-06-28 11:03:12 -07001052 REQUIRES_SHARED(Locks::mutator_lock_)
1053 REQUIRES(!Locks::dex_lock_);
1054
Vladimir Marko666ee3d2017-12-11 18:37:36 +00001055 // Implementation of LookupResolvedType() called when the type was not found in the dex cache.
1056 ObjPtr<mirror::Class> DoLookupResolvedType(dex::TypeIndex type_idx,
Vladimir Marko09c5ca42018-05-31 15:15:31 +01001057 ObjPtr<mirror::Class> referrer)
1058 REQUIRES_SHARED(Locks::mutator_lock_);
1059 ObjPtr<mirror::Class> DoLookupResolvedType(dex::TypeIndex type_idx,
Vladimir Marko666ee3d2017-12-11 18:37:36 +00001060 ObjPtr<mirror::DexCache> dex_cache,
1061 ObjPtr<mirror::ClassLoader> class_loader)
1062 REQUIRES_SHARED(Locks::mutator_lock_);
1063
Vladimir Marko18090d12018-06-01 16:53:12 +01001064 // Implementation of ResolveString() called when the string was not found in the dex cache.
1065 ObjPtr<mirror::String> DoResolveString(dex::StringIndex string_idx,
1066 ObjPtr<mirror::DexCache> dex_cache)
1067 REQUIRES_SHARED(Locks::mutator_lock_);
1068 ObjPtr<mirror::String> DoResolveString(dex::StringIndex string_idx,
1069 Handle<mirror::DexCache> dex_cache)
1070 REQUIRES_SHARED(Locks::mutator_lock_);
1071
1072 // Implementation of LookupString() called when the string was not found in the dex cache.
1073 ObjPtr<mirror::String> DoLookupString(dex::StringIndex string_idx,
1074 ObjPtr<mirror::DexCache> dex_cache)
1075 REQUIRES_SHARED(Locks::mutator_lock_);
1076
Andreas Gampeb0625e02019-05-01 12:43:31 -07001077 // Implementation of ResolveType() called when the type was not found in the dex cache. May be
1078 // used with ArtField*, ArtMethod* or ObjPtr<Class>.
1079 template <typename RefType>
1080 ObjPtr<mirror::Class> DoResolveType(dex::TypeIndex type_idx, RefType referrer)
Vladimir Marko09c5ca42018-05-31 15:15:31 +01001081 REQUIRES_SHARED(Locks::mutator_lock_)
1082 REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_);
1083 ObjPtr<mirror::Class> DoResolveType(dex::TypeIndex type_idx,
Vladimir Marko666ee3d2017-12-11 18:37:36 +00001084 Handle<mirror::DexCache> dex_cache,
1085 Handle<mirror::ClassLoader> class_loader)
1086 REQUIRES_SHARED(Locks::mutator_lock_)
1087 REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_);
1088
Andreas Gampe34ee6842014-12-02 15:43:52 -08001089 // Finds a class by its descriptor, returning NULL if it isn't wasn't loaded
1090 // by the given 'class_loader'. Uses the provided hash for the descriptor.
Vladimir Markoa8bba7d2018-05-30 15:18:48 +01001091 ObjPtr<mirror::Class> LookupClass(Thread* self,
1092 const char* descriptor,
1093 size_t hash,
1094 ObjPtr<mirror::ClassLoader> class_loader)
Andreas Gampe34ee6842014-12-02 15:43:52 -08001095 REQUIRES(!Locks::classlinker_classes_lock_)
1096 REQUIRES_SHARED(Locks::mutator_lock_);
1097
Vladimir Markof44d36c2017-03-14 14:18:46 +00001098 // Find a field by its field index.
1099 ArtField* LookupResolvedField(uint32_t field_idx,
1100 ObjPtr<mirror::DexCache> dex_cache,
1101 ObjPtr<mirror::ClassLoader> class_loader,
1102 bool is_static)
1103 REQUIRES_SHARED(Locks::mutator_lock_);
1104
Vladimir Markocd556b02017-02-03 11:47:34 +00001105 void RegisterDexFileLocked(const DexFile& dex_file,
1106 ObjPtr<mirror::DexCache> dex_cache,
1107 ObjPtr<mirror::ClassLoader> class_loader)
Andreas Gampecc1b5352016-12-01 16:58:38 -08001108 REQUIRES(Locks::dex_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001109 REQUIRES_SHARED(Locks::mutator_lock_);
Alex Light725da8f2020-02-19 14:46:33 -08001110 const DexCacheData* FindDexCacheDataLocked(const DexFile& dex_file)
Santiago Aboy Solanes970ba212021-10-21 10:52:47 +01001111 REQUIRES_SHARED(Locks::dex_lock_);
Santiago Aboy Solanes4b8ea5d2021-11-19 10:14:54 +00001112 const DexCacheData* FindDexCacheDataLocked(const OatDexFile& oat_dex_file)
Santiago Aboy Solanes970ba212021-10-21 10:52:47 +01001113 REQUIRES_SHARED(Locks::dex_lock_);
Alex Light725da8f2020-02-19 14:46:33 -08001114 static ObjPtr<mirror::DexCache> DecodeDexCacheLocked(Thread* self, const DexCacheData* data)
1115 REQUIRES_SHARED(Locks::dex_lock_, Locks::mutator_lock_);
1116 bool IsSameClassLoader(ObjPtr<mirror::DexCache> dex_cache,
1117 const DexCacheData* data,
1118 ObjPtr<mirror::ClassLoader> class_loader)
1119 REQUIRES_SHARED(Locks::dex_lock_, Locks::mutator_lock_);
Brian Carlstromaded5f72011-10-07 17:15:04 -07001120
Alex Lighteb7c1442015-08-31 13:17:42 -07001121 bool InitializeDefaultInterfaceRecursive(Thread* self,
1122 Handle<mirror::Class> klass,
1123 bool can_run_clinit,
1124 bool can_init_parents)
Andreas Gampecc1b5352016-12-01 16:58:38 -08001125 REQUIRES(!Locks::dex_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001126 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartierc77f3ab2015-09-03 19:41:50 -07001127 bool WaitForInitializeClass(Handle<mirror::Class> klass,
1128 Thread* self,
Igor Murashkinb1d8c312015-08-04 11:18:43 -07001129 ObjectLock<mirror::Class>& lock);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001130
Mathieu Chartierc77f3ab2015-09-03 19:41:50 -07001131 bool IsSameDescriptorInDifferentClassContexts(Thread* self,
1132 const char* descriptor,
Andreas Gampe5a4b8a22014-09-11 08:30:08 -07001133 Handle<mirror::ClassLoader> class_loader1,
1134 Handle<mirror::ClassLoader> class_loader2)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001135 REQUIRES_SHARED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001136
Mathieu Chartierc77f3ab2015-09-03 19:41:50 -07001137 bool IsSameMethodSignatureInDifferentClassContexts(Thread* self,
1138 ArtMethod* method,
Mathieu Chartier28357fa2016-10-18 16:27:40 -07001139 ObjPtr<mirror::Class> klass1,
1140 ObjPtr<mirror::Class> klass2)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001141 REQUIRES_SHARED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001142
Andreas Gampe5a4b8a22014-09-11 08:30:08 -07001143 bool LinkSuperClass(Handle<mirror::Class> klass)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001144 REQUIRES_SHARED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001145
Andreas Gampe5a4b8a22014-09-11 08:30:08 -07001146 bool LoadSuperAndInterfaces(Handle<mirror::Class> klass, const DexFile& dex_file)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001147 REQUIRES_SHARED(Locks::mutator_lock_)
Andreas Gampecc1b5352016-12-01 16:58:38 -08001148 REQUIRES(!Locks::dex_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001149
Mathieu Chartiercc5ebdf2015-07-27 11:19:43 -07001150 bool LinkMethods(Thread* self,
1151 Handle<mirror::Class> klass,
Mathieu Chartier2d2621a2014-10-23 16:48:06 -07001152 Handle<mirror::ObjectArray<mirror::Class>> interfaces,
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +00001153 bool* out_new_conflict,
Igor Murashkinb1d8c312015-08-04 11:18:43 -07001154 ArtMethod** out_imt)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001155 REQUIRES_SHARED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001156
Vladimir Marko5aead702019-03-27 11:00:36 +00001157 ObjPtr<mirror::MethodHandle> ResolveMethodHandleForField(
1158 Thread* self,
1159 const dex::MethodHandleItem& method_handle,
1160 ArtMethod* referrer) REQUIRES_SHARED(Locks::mutator_lock_);
Orion Hodsonf8db2c32017-07-07 20:07:12 +01001161
Vladimir Marko5aead702019-03-27 11:00:36 +00001162 ObjPtr<mirror::MethodHandle> ResolveMethodHandleForMethod(
1163 Thread* self,
1164 const dex::MethodHandleItem& method_handle,
1165 ArtMethod* referrer) REQUIRES_SHARED(Locks::mutator_lock_);
Orion Hodsonf8db2c32017-07-07 20:07:12 +01001166
Igor Murashkinb1d8c312015-08-04 11:18:43 -07001167 bool LinkStaticFields(Thread* self, Handle<mirror::Class> klass, size_t* class_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001168 REQUIRES_SHARED(Locks::mutator_lock_);
Andreas Gampe5a4b8a22014-09-11 08:30:08 -07001169 bool LinkInstanceFields(Thread* self, Handle<mirror::Class> klass)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001170 REQUIRES_SHARED(Locks::mutator_lock_);
Andreas Gampe5a4b8a22014-09-11 08:30:08 -07001171 void CreateReferenceInstanceOffsets(Handle<mirror::Class> klass)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001172 REQUIRES_SHARED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001173
Mathieu Chartiere401d142015-04-22 13:56:20 -07001174 void CheckProxyConstructor(ArtMethod* constructor) const
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001175 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -07001176 void CheckProxyMethod(ArtMethod* method, ArtMethod* prototype) const
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001177 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -07001178
Andreas Gampecc1b5352016-12-01 16:58:38 -08001179 size_t GetDexCacheCount() REQUIRES_SHARED(Locks::mutator_lock_, Locks::dex_lock_) {
Hiroshi Yamauchie9e3e692014-06-24 14:31:37 -07001180 return dex_caches_.size();
1181 }
David Srbecky6fbcc292021-02-23 01:05:32 +00001182 const std::unordered_map<const DexFile*, DexCacheData>& GetDexCachesData()
Andreas Gampecc1b5352016-12-01 16:58:38 -08001183 REQUIRES_SHARED(Locks::mutator_lock_, Locks::dex_lock_) {
Mathieu Chartier673ed3d2015-08-28 14:56:43 -07001184 return dex_caches_;
1185 }
Brian Carlstrom58ae9412011-10-04 00:56:06 -07001186
Mathieu Chartiere401d142015-04-22 13:56:20 -07001187 void CreateProxyConstructor(Handle<mirror::Class> klass, ArtMethod* out)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001188 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -07001189 void CreateProxyMethod(Handle<mirror::Class> klass, ArtMethod* prototype, ArtMethod* out)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001190 REQUIRES_SHARED(Locks::mutator_lock_);
Jesse Wilson95caa792011-10-12 18:14:17 -04001191
Mathieu Chartier5b830502016-03-02 10:30:23 -08001192 // Register a class loader and create its class table and allocator. Should not be called if
1193 // these are already created.
Mathieu Chartier28357fa2016-10-18 16:27:40 -07001194 void RegisterClassLoader(ObjPtr<mirror::ClassLoader> class_loader)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001195 REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartier5b830502016-03-02 10:30:23 -08001196 REQUIRES(Locks::classlinker_classes_lock_);
1197
Nicolas Geoffray3a090922015-11-24 09:17:30 +00001198 // Insert a new class table if not found.
Mathieu Chartier28357fa2016-10-18 16:27:40 -07001199 ClassTable* InsertClassTableForClassLoader(ObjPtr<mirror::ClassLoader> class_loader)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001200 REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartierc77f3ab2015-09-03 19:41:50 -07001201 REQUIRES(Locks::classlinker_classes_lock_);
Mathieu Chartiercc5ebdf2015-07-27 11:19:43 -07001202
Ian Rogersdbf3be02014-08-29 15:40:08 -07001203 // EnsureResolved is called to make sure that a class in the class_table_ has been resolved
1204 // before returning it to the caller. Its the responsibility of the thread that placed the class
1205 // in the table to make it resolved. The thread doing resolution must notify on the class' lock
1206 // when resolution has occurred. This happens in mirror::Class::SetStatus. As resolution may
1207 // retire a class, the version of the class in the table is returned and this may differ from
1208 // the class passed in.
Vladimir Markoa8bba7d2018-05-30 15:18:48 +01001209 ObjPtr<mirror::Class> EnsureResolved(Thread* self,
1210 const char* descriptor,
1211 ObjPtr<mirror::Class> klass)
Mathieu Chartierc77f3ab2015-09-03 19:41:50 -07001212 WARN_UNUSED
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001213 REQUIRES_SHARED(Locks::mutator_lock_)
Andreas Gampecc1b5352016-12-01 16:58:38 -08001214 REQUIRES(!Locks::dex_lock_);
Ian Rogersdbf3be02014-08-29 15:40:08 -07001215
Mathieu Chartier28357fa2016-10-18 16:27:40 -07001216 void FixupTemporaryDeclaringClass(ObjPtr<mirror::Class> temp_class,
1217 ObjPtr<mirror::Class> new_class)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001218 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersdbf3be02014-08-29 15:40:08 -07001219
Mathieu Chartier28357fa2016-10-18 16:27:40 -07001220 void SetClassRoot(ClassRoot class_root, ObjPtr<mirror::Class> klass)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001221 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001222
1223 // Return the quick generic JNI stub for testing.
1224 const void* GetRuntimeQuickGenericJniStub() const;
1225
Mathieu Chartier28357fa2016-10-18 16:27:40 -07001226 bool CanWeInitializeClass(ObjPtr<mirror::Class> klass,
1227 bool can_init_statics,
1228 bool can_init_parents)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001229 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -07001230
Mathieu Chartier28357fa2016-10-18 16:27:40 -07001231 void UpdateClassMethods(ObjPtr<mirror::Class> klass,
Alex Lighte64300b2015-12-15 15:02:47 -08001232 LengthPrefixedArray<ArtMethod>* new_methods)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001233 REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartier54d220e2015-07-30 16:20:06 -07001234 REQUIRES(!Locks::classlinker_classes_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -07001235
Andreas Gampe7ba5a672016-02-04 21:45:01 -08001236 // Check that c1 == FindSystemClass(self, descriptor). Abort with class dumps otherwise.
1237 void CheckSystemClass(Thread* self, Handle<mirror::Class> c1, const char* descriptor)
Andreas Gampecc1b5352016-12-01 16:58:38 -08001238 REQUIRES(!Locks::dex_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001239 REQUIRES_SHARED(Locks::mutator_lock_);
Andreas Gampe7ba5a672016-02-04 21:45:01 -08001240
Mathieu Chartier7f98c9a2016-04-14 10:49:19 -07001241 // Sets imt_ref appropriately for LinkInterfaceMethods.
1242 // If there is no method in the imt location of imt_ref it will store the given method there.
1243 // Otherwise it will set the conflict method which will figure out which method to use during
1244 // runtime.
1245 void SetIMTRef(ArtMethod* unimplemented_method,
1246 ArtMethod* imt_conflict_method,
1247 ArtMethod* current_method,
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +00001248 /*out*/bool* new_conflict,
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001249 /*out*/ArtMethod** imt_ref) REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier7f98c9a2016-04-14 10:49:19 -07001250
Mathieu Chartier28357fa2016-10-18 16:27:40 -07001251 void FillIMTFromIfTable(ObjPtr<mirror::IfTable> if_table,
Mathieu Chartiere42888f2016-04-14 10:49:19 -07001252 ArtMethod* unimplemented_method,
1253 ArtMethod* imt_conflict_method,
Mathieu Chartier28357fa2016-10-18 16:27:40 -07001254 ObjPtr<mirror::Class> klass,
Mathieu Chartiere42888f2016-04-14 10:49:19 -07001255 bool create_conflict_tables,
1256 bool ignore_copied_methods,
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +00001257 /*out*/bool* new_conflict,
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001258 /*out*/ArtMethod** imt) REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier7f98c9a2016-04-14 10:49:19 -07001259
Vladimir Markoba118822017-06-12 15:41:56 +01001260 // Check invoke type against the referenced class. Throws IncompatibleClassChangeError
1261 // (if `kThrowOnError`) and returns true on mismatch (kInterface on a non-interface class,
1262 // kVirtual on interface, kDefault on interface for dex files not supporting default methods),
1263 // otherwise returns false.
1264 template <bool kThrowOnError, typename ClassGetter>
1265 static bool CheckInvokeClassMismatch(ObjPtr<mirror::DexCache> dex_cache,
1266 InvokeType type,
1267 ClassGetter class_getter)
1268 REQUIRES_SHARED(Locks::mutator_lock_);
1269 // Helper that feeds the above function with `ClassGetter` doing `LookupResolvedType()`.
1270 template <bool kThrow>
1271 bool CheckInvokeClassMismatch(ObjPtr<mirror::DexCache> dex_cache,
1272 InvokeType type,
1273 uint32_t method_idx,
1274 ObjPtr<mirror::ClassLoader> class_loader)
1275 REQUIRES_SHARED(Locks::mutator_lock_);
1276
Vladimir Marko02610552018-06-04 14:38:00 +01001277 ObjPtr<mirror::IfTable> GetArrayIfTable() REQUIRES_SHARED(Locks::mutator_lock_);
1278
Brian Carlstrom4a96b602011-07-26 16:40:23 -07001279 std::vector<const DexFile*> boot_class_path_;
Mathieu Chartierfbc31082016-01-24 11:59:56 -08001280 std::vector<std::unique_ptr<const DexFile>> boot_dex_files_;
Brian Carlstrom578bbdc2011-07-21 14:07:47 -07001281
Hiroshi Yamauchi04302db2015-11-11 23:45:34 -08001282 // JNI weak globals and side data to allow dex caches to get unloaded. We lazily delete weak
1283 // globals when we register new dex files.
David Srbecky6fbcc292021-02-23 01:05:32 +00001284 std::unordered_map<const DexFile*, DexCacheData> dex_caches_ GUARDED_BY(Locks::dex_lock_);
Brian Carlstrom47d237a2011-10-18 15:08:33 -07001285
Mathieu Chartier9b1c71e2015-09-02 18:51:54 -07001286 // This contains the class loaders which have class tables. It is populated by
Mathieu Chartier951ec2c2015-09-22 08:50:05 -07001287 // InsertClassTableForClassLoader.
1288 std::list<ClassLoaderData> class_loaders_
Mathieu Chartier6b069532015-08-05 15:08:12 -07001289 GUARDED_BY(Locks::classlinker_classes_lock_);
1290
1291 // Boot class path table. Since the class loader for this is null.
Andreas Gampe2af99022017-04-25 08:32:59 -07001292 std::unique_ptr<ClassTable> boot_class_table_ GUARDED_BY(Locks::classlinker_classes_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001293
Mathieu Chartiercc5ebdf2015-07-27 11:19:43 -07001294 // New class roots, only used by CMS since the GC needs to mark these in the pause.
1295 std::vector<GcRoot<mirror::Class>> new_class_roots_ GUARDED_BY(Locks::classlinker_classes_lock_);
Elliott Hughesf8349362012-06-18 15:00:06 -07001296
Vladimir Marko1998cd02017-01-13 13:02:58 +00001297 // Boot image oat files with new .bss GC roots to be visited in the pause by CMS.
1298 std::vector<const OatFile*> new_bss_roots_boot_oat_files_
1299 GUARDED_BY(Locks::classlinker_classes_lock_);
1300
Ian Rogers7dfb28c2013-08-22 08:18:36 -07001301 // Number of times we've searched dex caches for a class. After a certain number of misses we move
1302 // the classes into the class_table_ to avoid dex cache based searches.
Ian Rogers68b56852014-08-29 20:19:11 -07001303 Atomic<uint32_t> failed_dex_cache_class_lookups_;
Ian Rogers7dfb28c2013-08-22 08:18:36 -07001304
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001305 // Well known mirror::Class roots.
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -07001306 GcRoot<mirror::ObjectArray<mirror::Class>> class_roots_;
Brian Carlstrom913af1b2011-07-23 21:41:13 -07001307
Vladimir Marko43354742021-02-03 15:37:01 +00001308 // Method hashes for virtual methods from java.lang.Object used
1309 // to avoid recalculating them for each class we link.
1310 uint32_t object_virtual_method_hashes_[mirror::Object::kVTableLength];
1311
Ian Rogers98379392014-02-24 16:53:16 -08001312 // A cache of the last FindArrayClass results. The cache serves to avoid creating array class
1313 // descriptors for the sake of performing FindClass.
1314 static constexpr size_t kFindArrayCacheSize = 16;
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -07001315 GcRoot<mirror::Class> find_array_class_cache_[kFindArrayCacheSize];
Ian Rogers98379392014-02-24 16:53:16 -08001316 size_t find_array_class_cache_next_victim_;
1317
Brian Carlstrom75cb3b42011-07-28 02:13:36 -07001318 bool init_done_;
Vladimir Marko1998cd02017-01-13 13:02:58 +00001319 bool log_new_roots_ GUARDED_BY(Locks::classlinker_classes_lock_);
Brian Carlstrom75cb3b42011-07-28 02:13:36 -07001320
Elliott Hughescf4c6c42011-09-01 15:16:42 -07001321 InternTable* intern_table_;
1322
Andreas Gampe87658f32019-04-18 18:39:02 +00001323 const bool fast_class_not_found_exceptions_;
1324
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001325 // Trampolines within the image the bounce to runtime entrypoints. Done so that there is a single
1326 // patch point within the image. TODO: make these proper relocations.
Vladimir Marko7dac8642019-11-06 17:09:30 +00001327 const void* jni_dlsym_lookup_trampoline_;
Vladimir Markofa458ac2020-02-12 14:08:07 +00001328 const void* jni_dlsym_lookup_critical_trampoline_;
Jeff Hao0aba0ba2013-06-03 14:49:28 -07001329 const void* quick_resolution_trampoline_;
Jeff Hao88474b42013-10-23 16:24:40 -07001330 const void* quick_imt_conflict_trampoline_;
Andreas Gampe2da88232014-02-27 12:26:20 -08001331 const void* quick_generic_jni_trampoline_;
Vladimir Marko8a630572014-04-09 18:45:35 +01001332 const void* quick_to_interpreter_bridge_trampoline_;
Nicolas Geoffrayc39af942021-01-25 08:43:57 +00001333 const void* nterp_trampoline_;
Jeff Hao0aba0ba2013-06-03 14:49:28 -07001334
Mathieu Chartier2d721012014-11-10 11:08:06 -08001335 // Image pointer size.
Andreas Gampe542451c2016-07-26 09:02:02 -07001336 PointerSize image_pointer_size_;
Mathieu Chartier2d721012014-11-10 11:08:06 -08001337
Vladimir Markobf121912019-06-04 13:49:05 +01001338 // Classes to transition from ClassStatus::kInitialized to ClassStatus::kVisiblyInitialized.
1339 Mutex visibly_initialized_callback_lock_;
1340 std::unique_ptr<VisiblyInitializedCallback> visibly_initialized_callback_
1341 GUARDED_BY(visibly_initialized_callback_lock_);
1342 IntrusiveForwardList<VisiblyInitializedCallback> running_visibly_initialized_callbacks_
1343 GUARDED_BY(visibly_initialized_callback_lock_);
1344
Vladimir Marko86c87522020-05-11 16:55:55 +01001345 // Registered native code for @CriticalNative methods of classes that are not visibly
1346 // initialized. These code pointers cannot be stored in ArtMethod as that would risk
1347 // skipping the class initialization check for direct calls from compiled code.
1348 Mutex critical_native_code_with_clinit_check_lock_;
1349 std::map<ArtMethod*, void*> critical_native_code_with_clinit_check_
1350 GUARDED_BY(critical_native_code_with_clinit_check_lock_);
1351
Andreas Gampec1ac9ee2017-07-24 22:35:49 -07001352 std::unique_ptr<ClassHierarchyAnalysis> cha_;
1353
Mathieu Chartier65975772016-08-05 10:46:36 -07001354 class FindVirtualMethodHolderVisitor;
Andreas Gampe2af99022017-04-25 08:32:59 -07001355
Mathieu Chartier74ccee62018-10-10 10:30:29 -07001356 friend class AppImageLoadingHelper;
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -07001357 friend class ImageDumper; // for DexLock
Vladimir Marko74527972016-11-29 15:57:32 +00001358 friend struct linker::CompilationHelper; // For Compile in ImageTest.
1359 friend class linker::ImageWriter; // for GetClassRoots
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001360 friend class JniCompilerTest; // for GetRuntimeQuickGenericJniStub
Andreas Gampe5f4a09a2015-09-28 13:16:33 -07001361 friend class JniInternalTest; // for GetRuntimeQuickGenericJniStub
Andreas Gampe2af99022017-04-25 08:32:59 -07001362 friend class VMClassLoader; // for LookupClass and FindClassInBaseDexClassLoader.
Mathieu Chartier76172162016-01-26 14:54:06 -08001363 ART_FRIEND_TEST(ClassLinkerTest, RegisterDexFileName); // for DexLock, and RegisterDexFileLocked
Narayan Kamath25352fc2016-08-03 12:46:58 +01001364 ART_FRIEND_TEST(mirror::DexCacheMethodHandlesTest, Open); // for AllocDexCache
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001365 ART_FRIEND_TEST(mirror::DexCacheTest, Open); // for AllocDexCache
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001366 DISALLOW_COPY_AND_ASSIGN(ClassLinker);
1367};
1368
Andreas Gampe0f01b582017-01-18 15:22:37 -08001369class ClassLoadCallback {
1370 public:
1371 virtual ~ClassLoadCallback() {}
1372
Alex Light270db1c2019-12-03 12:20:01 +00001373 // Called immediately before beginning class-definition and immediately before returning from it.
1374 virtual void BeginDefineClass() REQUIRES_SHARED(Locks::mutator_lock_) {}
1375 virtual void EndDefineClass() REQUIRES_SHARED(Locks::mutator_lock_) {}
1376
Alex Lightb0f11922017-01-23 14:25:17 -08001377 // If set we will replace initial_class_def & initial_dex_file with the final versions. The
1378 // callback author is responsible for ensuring these are allocated in such a way they can be
1379 // cleaned up if another transformation occurs. Note that both must be set or null/unchanged on
1380 // return.
1381 // Note: the class may be temporary, in which case a following ClassPrepare event will be a
1382 // different object. It is the listener's responsibility to handle this.
1383 // Note: This callback is rarely useful so a default implementation has been given that does
1384 // nothing.
1385 virtual void ClassPreDefine(const char* descriptor ATTRIBUTE_UNUSED,
1386 Handle<mirror::Class> klass ATTRIBUTE_UNUSED,
1387 Handle<mirror::ClassLoader> class_loader ATTRIBUTE_UNUSED,
1388 const DexFile& initial_dex_file ATTRIBUTE_UNUSED,
Andreas Gampe3f1dcd32018-12-28 09:39:56 -08001389 const dex::ClassDef& initial_class_def ATTRIBUTE_UNUSED,
Alex Lightb0f11922017-01-23 14:25:17 -08001390 /*out*/DexFile const** final_dex_file ATTRIBUTE_UNUSED,
Andreas Gampe3f1dcd32018-12-28 09:39:56 -08001391 /*out*/dex::ClassDef const** final_class_def ATTRIBUTE_UNUSED)
Alex Lightb0f11922017-01-23 14:25:17 -08001392 REQUIRES_SHARED(Locks::mutator_lock_) {}
1393
Andreas Gampe0f01b582017-01-18 15:22:37 -08001394 // A class has been loaded.
1395 // Note: the class may be temporary, in which case a following ClassPrepare event will be a
1396 // different object. It is the listener's responsibility to handle this.
1397 virtual void ClassLoad(Handle<mirror::Class> klass) REQUIRES_SHARED(Locks::mutator_lock_) = 0;
1398
1399 // A class has been prepared, i.e., resolved. As the ClassLoad event might have been for a
1400 // temporary class, provide both the former and the current class.
1401 virtual void ClassPrepare(Handle<mirror::Class> temp_klass,
1402 Handle<mirror::Class> klass) REQUIRES_SHARED(Locks::mutator_lock_) = 0;
1403};
1404
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001405} // namespace art
1406
Brian Carlstromfc0e3212013-07-17 14:40:12 -07001407#endif // ART_RUNTIME_CLASS_LINKER_H_