blob: 7d7bf15ee03a36d73513178934d6db83c57dd7d8 [file] [log] [blame]
Elliott Hughes418d20f2011-09-22 14:00:39 -07001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070016
Brian Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_RUNTIME_CLASS_LINKER_H_
18#define ART_RUNTIME_CLASS_LINKER_H_
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070019
Ian Rogers6d4d9fc2011-11-30 16:24:48 -080020#include <string>
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070021#include <utility>
22#include <vector>
23
Elliott Hughes76160052012-12-12 16:31:20 -080024#include "base/macros.h"
Elliott Hughes76b61672012-12-12 17:47:30 -080025#include "base/mutex.h"
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070026#include "dex_file.h"
Elliott Hughese5448b52012-01-18 16:44:06 -080027#include "gtest/gtest.h"
Mathieu Chartier590fee92013-09-13 13:46:47 -070028#include "jni.h"
Brian Carlstrom58ae9412011-10-04 00:56:06 -070029#include "oat_file.h"
Mathieu Chartier83c8ee02014-01-28 14:50:23 -080030#include "object_callbacks.h"
Hiroshi Yamauchie9e3e692014-06-24 14:31:37 -070031#include "read_barrier.h"
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070032
33namespace art {
Ian Rogers1d54e732013-05-02 21:10:01 -070034namespace gc {
35namespace space {
36 class ImageSpace;
37} // namespace space
38} // namespace gc
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080039namespace mirror {
Ian Rogers33e95662013-05-20 20:29:14 -070040 class ClassLoader;
41 class DexCache;
42 class DexCacheTest_Open_Test;
43 class IfTable;
44 template<class T> class ObjectArray;
45 class StackTraceElement;
46} // namespace mirror
Ian Rogers1d54e732013-05-02 21:10:01 -070047
Elliott Hughescf4c6c42011-09-01 15:16:42 -070048class InternTable;
Mathieu Chartierc528dba2013-11-26 12:00:11 -080049template<class T> class ObjectLock;
Mathieu Chartier2b7c4d12014-05-19 10:52:16 -070050class ScopedObjectAccessAlreadyRunnable;
Mathieu Chartiereb8167a2014-05-07 15:43:14 -070051template<class T> class Handle;
Elliott Hughescf4c6c42011-09-01 15:16:42 -070052
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080053typedef bool (ClassVisitor)(mirror::Class* c, void* arg);
Elliott Hughesa2155262011-11-16 16:26:58 -080054
Mathieu Chartier893263b2014-03-04 11:07:42 -080055enum VisitRootFlags : uint8_t;
56
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070057class ClassLinker {
58 public:
Jeff Hao88474b42013-10-23 16:24:40 -070059 // Interface method table size. Increasing this value reduces the chance of two interface methods
60 // colliding in the interface method table but increases the size of classes that implement
61 // (non-marker) interfaces.
62 static constexpr size_t kImtSize = 64;
63
Mathieu Chartier590fee92013-09-13 13:46:47 -070064 explicit ClassLinker(InternTable* intern_table);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070065 ~ClassLinker();
Carl Shapiro565f5072011-07-10 13:39:43 -070066
Mathieu Chartier590fee92013-09-13 13:46:47 -070067 // Initialize class linker by bootstraping from dex files
68 void InitFromCompiler(const std::vector<const DexFile*>& boot_class_path)
69 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
70
71 // Initialize class linker from one or more images.
72 void InitFromImage() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
73
Ian Rogersbe7149f2013-08-20 09:29:39 -070074 bool IsInBootClassPath(const char* descriptor);
75
Elliott Hughes64bf5a32011-09-20 14:43:12 -070076 // Finds a class by its descriptor, loading it if necessary.
Brian Carlstrom74eb46a2011-08-02 20:10:14 -070077 // If class_loader is null, searches boot_class_path_.
Ian Rogers98379392014-02-24 16:53:16 -080078 mirror::Class* FindClass(Thread* self, const char* descriptor,
Mathieu Chartier0cd81352014-05-22 16:48:55 -070079 Handle<mirror::ClassLoader> class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -070080 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromaded5f72011-10-07 17:15:04 -070081
Ian Rogers98379392014-02-24 16:53:16 -080082 // Finds a class by its descriptor using the "system" class loader, ie by searching the
83 // boot_class_path_.
84 mirror::Class* FindSystemClass(Thread* self, const char* descriptor)
85 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
86
87 // Finds the array class given for the element class.
Mathieu Chartierb74cd292014-05-29 14:31:33 -070088 mirror::Class* FindArrayClass(Thread* self, mirror::Class** element_class)
Ian Rogersb726dcb2012-09-05 08:57:23 -070089 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromaded5f72011-10-07 17:15:04 -070090
Mathieu Chartier590fee92013-09-13 13:46:47 -070091 // Reutrns true if the class linker is initialized.
92 bool IsInitialized() const;
93
Brian Carlstromaded5f72011-10-07 17:15:04 -070094 // Define a new a class based on a ClassDef from a DexFile
Mathieu Chartierc528dba2013-11-26 12:00:11 -080095 mirror::Class* DefineClass(const char* descriptor,
Mathieu Chartier0cd81352014-05-22 16:48:55 -070096 Handle<mirror::ClassLoader> class_loader,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080097 const DexFile& dex_file, const DexFile::ClassDef& dex_class_def)
Ian Rogersb726dcb2012-09-05 08:57:23 -070098 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes64bf5a32011-09-20 14:43:12 -070099
100 // Finds a class by its descriptor, returning NULL if it isn't wasn't loaded
101 // by the given 'class_loader'.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800102 mirror::Class* LookupClass(const char* descriptor, const mirror::ClassLoader* class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700103 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
104 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700105
Elliott Hughes6fa602d2011-12-02 17:54:25 -0800106 // Finds all the classes with the given descriptor, regardless of ClassLoader.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800107 void LookupClasses(const char* descriptor, std::vector<mirror::Class*>& classes)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700108 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
109 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes6fa602d2011-12-02 17:54:25 -0800110
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800111 mirror::Class* FindPrimitiveClass(char type) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700112
Brian Carlstromae826982011-11-09 01:33:42 -0800113 // General class unloading is not supported, this is used to prune
114 // unwanted classes during image writing.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800115 bool RemoveClass(const char* descriptor, const mirror::ClassLoader* class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700116 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
117 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromae826982011-11-09 01:33:42 -0800118
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700119 void DumpAllClasses(int flags)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700120 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
121 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes9d5ccec2011-09-19 13:19:50 -0700122
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700123 void DumpForSigQuit(std::ostream& os)
124 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
125 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughescac6cc72011-11-03 20:31:21 -0700126
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700127 size_t NumLoadedClasses()
128 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
129 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughese27955c2011-08-26 15:21:24 -0700130
Brian Carlstromb63ec392011-08-27 17:38:27 -0700131 // Resolve a String with the given index from the DexFile, storing the
Brian Carlstromaded5f72011-10-07 17:15:04 -0700132 // result in the DexCache. The referrer is used to identify the
133 // target DexCache and ClassLoader to use for resolution.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800134 mirror::String* ResolveString(uint32_t string_idx, mirror::ArtMethod* referrer)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800135 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromaded5f72011-10-07 17:15:04 -0700136
137 // Resolve a String with the given index from the DexFile, storing the
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700138 // result in the DexCache.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800139 mirror::String* ResolveString(const DexFile& dex_file, uint32_t string_idx,
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700140 Handle<mirror::DexCache> dex_cache)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700141 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700142
Brian Carlstromb63ec392011-08-27 17:38:27 -0700143 // Resolve a Type with the given index from the DexFile, storing the
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700144 // result in the DexCache. The referrer is used to identity the
145 // target DexCache and ClassLoader to use for resolution.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800146 mirror::Class* ResolveType(const DexFile& dex_file, uint16_t type_idx, mirror::Class* referrer)
Mathieu Chartier590fee92013-09-13 13:46:47 -0700147 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700148
Brian Carlstromb63ec392011-08-27 17:38:27 -0700149 // Resolve a Type with the given index from the DexFile, storing the
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700150 // result in the DexCache. The referrer is used to identify the
Brian Carlstromb63ec392011-08-27 17:38:27 -0700151 // target DexCache and ClassLoader to use for resolution.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800152 mirror::Class* ResolveType(uint16_t type_idx, mirror::ArtMethod* referrer)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800153 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700154
Ian Rogersef7d42f2014-01-06 12:55:46 -0800155 mirror::Class* ResolveType(uint16_t type_idx, mirror::ArtField* referrer)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800156 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromb63ec392011-08-27 17:38:27 -0700157
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700158 // Resolve a type with the given ID from the DexFile, storing the
159 // result in DexCache. The ClassLoader is used to search for the
160 // type, since it may be referenced from but not contained within
161 // the given DexFile.
Mathieu Chartier590fee92013-09-13 13:46:47 -0700162 mirror::Class* ResolveType(const DexFile& dex_file, uint16_t type_idx,
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700163 Handle<mirror::DexCache> dex_cache,
164 Handle<mirror::ClassLoader> class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700165 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700166
167 // Resolve a method with a given ID from the DexFile, storing the
168 // result in DexCache. The ClassLinker and ClassLoader are used as
169 // in ResolveType. What is unique is the method type argument which
170 // is used to determine if this method is a direct, static, or
171 // virtual method.
Brian Carlstromea46f952013-07-30 01:26:50 -0700172 mirror::ArtMethod* ResolveMethod(const DexFile& dex_file,
173 uint32_t method_idx,
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700174 Handle<mirror::DexCache> dex_cache,
175 Handle<mirror::ClassLoader> class_loader,
176 Handle<mirror::ArtMethod> referrer,
Brian Carlstromea46f952013-07-30 01:26:50 -0700177 InvokeType type)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700178 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700179
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700180 mirror::ArtMethod* GetResolvedMethod(uint32_t method_idx, mirror::ArtMethod* referrer,
181 InvokeType type)
182 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
183 mirror::ArtMethod* ResolveMethod(Thread* self, uint32_t method_idx, mirror::ArtMethod** referrer,
Brian Carlstromea46f952013-07-30 01:26:50 -0700184 InvokeType type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800185 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom16192862011-09-12 17:50:06 -0700186
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700187 mirror::ArtField* GetResolvedField(uint32_t field_idx, mirror::Class* field_declaring_class)
188 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800189 mirror::ArtField* ResolveField(uint32_t field_idx, mirror::ArtMethod* referrer,
Brian Carlstromea46f952013-07-30 01:26:50 -0700190 bool is_static)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800191 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromb9edb842011-08-28 16:31:06 -0700192
Brian Carlstrom16192862011-09-12 17:50:06 -0700193 // Resolve a field with a given ID from the DexFile, storing the
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700194 // result in DexCache. The ClassLinker and ClassLoader are used as
195 // in ResolveType. What is unique is the is_static argument which is
196 // used to determine if we are resolving a static or non-static
197 // field.
Brian Carlstromea46f952013-07-30 01:26:50 -0700198 mirror::ArtField* ResolveField(const DexFile& dex_file,
199 uint32_t field_idx,
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700200 Handle<mirror::DexCache> dex_cache,
201 Handle<mirror::ClassLoader> class_loader,
Brian Carlstromea46f952013-07-30 01:26:50 -0700202 bool is_static)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700203 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700204
Ian Rogersb067ac22011-12-13 18:05:09 -0800205 // Resolve a field with a given ID from the DexFile, storing the
206 // result in DexCache. The ClassLinker and ClassLoader are used as
207 // in ResolveType. No is_static argument is provided so that Java
208 // field resolution semantics are followed.
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700209 mirror::ArtField* ResolveFieldJLS(const DexFile& dex_file, uint32_t field_idx,
210 Handle<mirror::DexCache> dex_cache,
211 Handle<mirror::ClassLoader> class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700212 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersb067ac22011-12-13 18:05:09 -0800213
Ian Rogersad25ac52011-10-04 19:13:33 -0700214 // Get shorty from method index without resolution. Used to do handlerization.
Brian Carlstromea46f952013-07-30 01:26:50 -0700215 const char* MethodShorty(uint32_t method_idx, mirror::ArtMethod* referrer, uint32_t* length)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700216 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersad25ac52011-10-04 19:13:33 -0700217
Elliott Hughesf4c21c92011-08-19 17:31:31 -0700218 // Returns true on success, false if there's an exception pending.
Brian Carlstrom25c33252011-09-18 15:58:35 -0700219 // can_run_clinit=false allows the compiler to attempt to init a class,
220 // given the restriction that no <clinit> execution is possible.
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700221 bool EnsureInitialized(Handle<mirror::Class> c, bool can_init_fields, bool can_init_parents)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700222 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700223
Elliott Hughes2a20cfd2011-09-23 19:30:41 -0700224 // Initializes classes that have instances in the image but that have
225 // <clinit> methods so they could not be initialized by the compiler.
Ian Rogersb726dcb2012-09-05 08:57:23 -0700226 void RunRootClinits() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes2a20cfd2011-09-23 19:30:41 -0700227
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700228 void RegisterDexFile(const DexFile& dex_file)
229 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700230 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700231 void RegisterDexFile(const DexFile& dex_file, Handle<mirror::DexCache> dex_cache)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700232 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700233 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700234
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700235 const OatFile* RegisterOatFile(const OatFile* oat_file)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700236 LOCKS_EXCLUDED(dex_lock_);
Brian Carlstrom866c8622012-01-06 16:35:13 -0800237
Brian Carlstrom8a487412011-08-29 20:08:52 -0700238 const std::vector<const DexFile*>& GetBootClassPath() {
239 return boot_class_path_;
240 }
241
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700242 void VisitClasses(ClassVisitor* visitor, void* arg)
243 LOCKS_EXCLUDED(dex_lock_)
244 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700245 // Less efficient variant of VisitClasses that doesn't hold the classlinker_classes_lock_
246 // when calling the visitor.
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700247 void VisitClassesWithoutClassesLock(ClassVisitor* visitor, void* arg)
248 LOCKS_EXCLUDED(dex_lock_)
249 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesa2155262011-11-16 16:26:58 -0800250
Mathieu Chartier52e4b432014-06-10 11:22:31 -0700251 void VisitClassRoots(RootCallback* callback, void* arg, VisitRootFlags flags)
252 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_);
Mathieu Chartier893263b2014-03-04 11:07:42 -0800253 void VisitRoots(RootCallback* callback, void* arg, VisitRootFlags flags)
Mathieu Chartier52e4b432014-06-10 11:22:31 -0700254 LOCKS_EXCLUDED(dex_lock_);
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700255
Hiroshi Yamauchie9e3e692014-06-24 14:31:37 -0700256 mirror::DexCache* FindDexCache(const DexFile& dex_file)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700257 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700258 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Hiroshi Yamauchie9e3e692014-06-24 14:31:37 -0700259 bool IsDexFileRegistered(const DexFile& dex_file)
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700260 LOCKS_EXCLUDED(dex_lock_) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Hiroshi Yamauchie9e3e692014-06-24 14:31:37 -0700261 void FixupDexCaches(mirror::ArtMethod* resolution_method)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700262 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700263 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom1d9f52b2011-10-13 10:50:45 -0700264
jeffhao262bf462011-10-20 18:36:32 -0700265 // Generate an oat file from a dex file
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700266 bool GenerateOatFile(const char* dex_filename,
Brian Carlstromd601af82012-01-06 10:15:19 -0800267 int oat_fd,
Vladimir Marko60836d52014-01-16 15:53:38 +0000268 const char* oat_cache_filename,
Ian Rogers719d1a32014-03-06 12:13:39 -0800269 std::string* error_msg)
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700270 LOCKS_EXCLUDED(Locks::mutator_lock_);
jeffhao262bf462011-10-20 18:36:32 -0700271
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700272 const OatFile* FindOatFileFromOatLocation(const std::string& location,
273 std::string* error_msg)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700274 LOCKS_EXCLUDED(dex_lock_);
275
Brian Carlstrom5b332c82012-02-01 15:02:31 -0800276 // Finds the oat file for a dex location, generating the oat file if
277 // it is missing or out of date. Returns the DexFile from within the
278 // created oat file.
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700279 const DexFile* FindOrCreateOatFileForDexLocation(const char* dex_location,
Brian Carlstrom756ee4e2013-10-03 15:46:12 -0700280 uint32_t dex_location_checksum,
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700281 const char* oat_location,
Andreas Gampe329d1882014-04-08 10:32:19 -0700282 std::vector<std::string>* error_msgs)
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700283 LOCKS_EXCLUDED(dex_lock_, Locks::mutator_lock_);
Brian Carlstrom5b332c82012-02-01 15:02:31 -0800284 // Find a DexFile within an OatFile given a DexFile location. Note
285 // that this returns null if the location checksum of the DexFile
286 // does not match the OatFile.
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700287 const DexFile* FindDexFileInOatFileFromDexLocation(const char* location,
Brian Carlstrom08cbf662013-12-10 16:52:57 -0800288 const uint32_t* const location_checksum,
Brian Carlstrom0e12bdc2014-05-14 17:44:28 -0700289 InstructionSet isa,
Andreas Gampe329d1882014-04-08 10:32:19 -0700290 std::vector<std::string>* error_msgs)
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700291 LOCKS_EXCLUDED(dex_lock_, Locks::mutator_lock_);
Brian Carlstrom5b332c82012-02-01 15:02:31 -0800292
jeffhaof6174e82012-01-31 16:14:17 -0800293
Brian Carlstrom28db0122012-10-18 16:20:41 -0700294 // Returns true if oat file contains the dex file with the given location and checksum.
Brian Carlstromafe25512012-06-27 17:02:58 -0700295 static bool VerifyOatFileChecksums(const OatFile* oat_file,
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700296 const char* dex_location,
297 uint32_t dex_location_checksum,
Brian Carlstrom2afe4942014-05-19 10:25:33 -0700298 InstructionSet instruction_set,
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700299 std::string* error_msg);
Brian Carlstromafe25512012-06-27 17:02:58 -0700300
Elliott Hughes418d20f2011-09-22 14:00:39 -0700301 // TODO: replace this with multiple methods that allocate the correct managed type.
Shih-wei Liao44175362011-08-28 16:59:17 -0700302 template <class T>
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800303 mirror::ObjectArray<T>* AllocObjectArray(Thread* self, size_t length)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700304 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Shih-wei Liao55df06b2011-08-26 14:39:27 -0700305
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800306 mirror::ObjectArray<mirror::Class>* AllocClassArray(Thread* self, size_t length)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700307 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
jeffhao98eacac2011-09-14 16:11:53 -0700308
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800309 mirror::ObjectArray<mirror::String>* AllocStringArray(Thread* self, size_t length)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700310 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800311
Brian Carlstromea46f952013-07-30 01:26:50 -0700312 mirror::ObjectArray<mirror::ArtMethod>* AllocArtMethodArray(Thread* self, size_t length)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800313 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
314
315 mirror::IfTable* AllocIfTable(Thread* self, size_t ifcount)
316 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
317
Brian Carlstromea46f952013-07-30 01:26:50 -0700318 mirror::ObjectArray<mirror::ArtField>* AllocArtFieldArray(Thread* self, size_t length)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800319 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
320
321 mirror::ObjectArray<mirror::StackTraceElement>* AllocStackTraceElementArray(Thread* self,
322 size_t length)
323 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
324
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700325 void VerifyClass(Handle<mirror::Class> klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800326 bool VerifyClassUsingOatFile(const DexFile& dex_file, mirror::Class* klass,
327 mirror::Class::Status& oat_file_class_status)
328 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800329 void ResolveClassExceptionHandlerTypes(const DexFile& dex_file,
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700330 Handle<mirror::Class> klass)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800331 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromea46f952013-07-30 01:26:50 -0700332 void ResolveMethodExceptionHandlerTypes(const DexFile& dex_file, mirror::ArtMethod* klass)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800333 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
334
Mathieu Chartier2b7c4d12014-05-19 10:52:16 -0700335 mirror::Class* CreateProxyClass(ScopedObjectAccessAlreadyRunnable& soa, jstring name,
336 jobjectArray interfaces, jobject loader, jobjectArray methods,
337 jobjectArray throws)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800338 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800339 std::string GetDescriptorForProxy(mirror::Class* proxy_class)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800340 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800341 mirror::ArtMethod* FindMethodForProxy(mirror::Class* proxy_class,
342 mirror::ArtMethod* proxy_method)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700343 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700344 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jesse Wilson95caa792011-10-12 18:14:17 -0400345
Ian Rogers19846512012-02-24 11:42:47 -0800346 // Get the oat code for a method when its class isn't yet initialized
Ian Rogersef7d42f2014-01-06 12:55:46 -0800347 const void* GetQuickOatCodeFor(mirror::ArtMethod* method)
348 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
349 const void* GetPortableOatCodeFor(mirror::ArtMethod* method, bool* have_portable_code)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700350 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers19846512012-02-24 11:42:47 -0800351
Mathieu Chartiere35517a2012-10-30 18:49:55 -0700352 // Get the oat code for a method from a method index.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800353 const void* GetQuickOatCodeFor(const DexFile& dex_file, uint16_t class_def_idx, uint32_t method_idx)
354 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
355 const void* GetPortableOatCodeFor(const DexFile& dex_file, uint16_t class_def_idx, uint32_t method_idx)
Ian Rogers33e95662013-05-20 20:29:14 -0700356 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartiere35517a2012-10-30 18:49:55 -0700357
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700358 pid_t GetClassesLockOwner(); // For SignalCatcher.
359 pid_t GetDexLockOwner(); // For SignalCatcher.
Brian Carlstrom24a3c2e2011-10-17 18:07:52 -0700360
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700361 const void* GetPortableResolutionTrampoline() const {
362 return portable_resolution_trampoline_;
363 }
364
Andreas Gampe2da88232014-02-27 12:26:20 -0800365 const void* GetQuickGenericJniTrampoline() const {
Dmitry Petrochenkof0972a42014-05-16 17:43:39 +0700366 return quick_generic_jni_trampoline_;
367 }
Andreas Gampe2da88232014-02-27 12:26:20 -0800368
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700369 const void* GetQuickResolutionTrampoline() const {
370 return quick_resolution_trampoline_;
371 }
372
Jeff Hao88474b42013-10-23 16:24:40 -0700373 const void* GetPortableImtConflictTrampoline() const {
374 return portable_imt_conflict_trampoline_;
375 }
376
377 const void* GetQuickImtConflictTrampoline() const {
378 return quick_imt_conflict_trampoline_;
379 }
380
Vladimir Marko8a630572014-04-09 18:45:35 +0100381 const void* GetQuickToInterpreterBridgeTrampoline() const {
382 return quick_to_interpreter_bridge_trampoline_;
383 }
384
Jeff Hao88474b42013-10-23 16:24:40 -0700385 InternTable* GetInternTable() const {
386 return intern_table_;
387 }
388
Ian Rogers848871b2013-08-05 10:56:33 -0700389 // Attempts to insert a class into a class table. Returns NULL if
390 // the class was inserted, otherwise returns an existing class with
391 // the same descriptor and ClassLoader.
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700392 mirror::Class* InsertClass(const char* descriptor, mirror::Class* klass, size_t hash)
Ian Rogers848871b2013-08-05 10:56:33 -0700393 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
394 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
395
Mathieu Chartier590fee92013-09-13 13:46:47 -0700396 // Special code to allocate an art method, use this instead of class->AllocObject.
397 mirror::ArtMethod* AllocArtMethod(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro61e019d2011-07-14 16:53:09 -0700398
Mathieu Chartier590fee92013-09-13 13:46:47 -0700399 private:
Ian Rogersef7d42f2014-01-06 12:55:46 -0800400 const OatFile::OatMethod GetOatMethodFor(mirror::ArtMethod* method)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700401 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
TDYa12785321912012-04-01 15:24:56 -0700402
Brian Carlstrom56d947f2013-07-15 13:14:23 -0700403 OatFile& GetImageOatFile(gc::space::ImageSpace* space)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700404 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700405 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstroma663ea52011-08-19 23:33:41 -0700406
Ian Rogers98379392014-02-24 16:53:16 -0800407 void FinishInit(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstroma663ea52011-08-19 23:33:41 -0700408
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700409 // For early bootstrapping by Init
Ian Rogers6fac4472014-02-25 17:01:10 -0800410 mirror::Class* AllocClass(Thread* self, mirror::Class* java_lang_Class, uint32_t class_size)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700411 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700412
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800413 // Alloc* convenience functions to avoid needing to pass in mirror::Class*
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700414 // values that are known to the ClassLinker such as
415 // kObjectArrayClass and kJavaLangString etc.
Ian Rogers6fac4472014-02-25 17:01:10 -0800416 mirror::Class* AllocClass(Thread* self, uint32_t class_size)
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800417 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800418 mirror::DexCache* AllocDexCache(Thread* self, const DexFile& dex_file)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700419 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromea46f952013-07-30 01:26:50 -0700420 mirror::ArtField* AllocArtField(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersbdb03912011-09-14 00:55:44 -0700421
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800422 mirror::Class* CreatePrimitiveClass(Thread* self, Primitive::Type type)
423 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
424 mirror::Class* InitializePrimitiveClass(mirror::Class* primitive_class, Primitive::Type type)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700425 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom5b8e4c82011-09-18 01:38:59 -0700426
Brian Carlstroma331b3c2011-07-18 17:47:56 -0700427
Ian Rogers98379392014-02-24 16:53:16 -0800428 mirror::Class* CreateArrayClass(Thread* self, const char* descriptor,
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700429 Handle<mirror::ClassLoader> class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700430 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstroma331b3c2011-07-18 17:47:56 -0700431
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700432 void AppendToBootClassPath(const DexFile& dex_file)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700433 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700434 void AppendToBootClassPath(const DexFile& dex_file, Handle<mirror::DexCache> dex_cache)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700435 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700436
Elliott Hughes5fe594f2011-09-08 12:33:17 -0700437 void ConstructFieldMap(const DexFile& dex_file, const DexFile::ClassDef& dex_class_def,
Brian Carlstromea46f952013-07-30 01:26:50 -0700438 mirror::Class* c, SafeMap<uint32_t, mirror::ArtField*>& field_map)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700439 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes5fe594f2011-09-08 12:33:17 -0700440
Ian Rogers6fac4472014-02-25 17:01:10 -0800441 uint32_t SizeOfClass(const DexFile& dex_file,
Brian Carlstrom4873d462011-08-21 15:23:39 -0700442 const DexFile::ClassDef& dex_class_def);
443
Brian Carlstromf615a612011-07-23 12:50:34 -0700444 void LoadClass(const DexFile& dex_file,
445 const DexFile::ClassDef& dex_class_def,
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700446 Handle<mirror::Class> klass,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800447 mirror::ClassLoader* class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700448 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Vladimir Markod3c5beb2014-04-11 16:32:51 +0100449 void LoadClassMembers(const DexFile& dex_file,
450 const byte* class_data,
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700451 Handle<mirror::Class> klass,
Vladimir Markod3c5beb2014-04-11 16:32:51 +0100452 mirror::ClassLoader* class_loader,
453 const OatFile::OatClass* oat_class)
454 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700455
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800456 void LoadField(const DexFile& dex_file, const ClassDataItemIterator& it,
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700457 Handle<mirror::Class> klass, Handle<mirror::ArtField> dst)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800458 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700459
Brian Carlstromea46f952013-07-30 01:26:50 -0700460 mirror::ArtMethod* LoadMethod(Thread* self, const DexFile& dex_file,
461 const ClassDataItemIterator& dex_method,
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700462 Handle<mirror::Class> klass)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800463 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom934486c2011-07-12 23:42:50 -0700464
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800465 void FixupStaticTrampolines(mirror::Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers19846512012-02-24 11:42:47 -0800466
467 // Finds the associated oat class for a dex_file and descriptor
Vladimir Markod3c5beb2014-04-11 16:32:51 +0100468 OatFile::OatClass GetOatClass(const DexFile& dex_file, uint16_t class_def_idx)
Ian Rogers33e95662013-05-20 20:29:14 -0700469 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers19846512012-02-24 11:42:47 -0800470
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700471 void RegisterDexFileLocked(const DexFile& dex_file, Handle<mirror::DexCache> dex_cache)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700472 EXCLUSIVE_LOCKS_REQUIRED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700473 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Hiroshi Yamauchie9e3e692014-06-24 14:31:37 -0700474 bool IsDexFileRegisteredLocked(const DexFile& dex_file)
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700475 SHARED_LOCKS_REQUIRED(dex_lock_, Locks::mutator_lock_);
Brian Carlstromaded5f72011-10-07 17:15:04 -0700476
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700477 bool InitializeClass(Handle<mirror::Class> klass, bool can_run_clinit,
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800478 bool can_init_parents)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700479 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700480 bool WaitForInitializeClass(Handle<mirror::Class> klass, Thread* self,
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800481 ObjectLock<mirror::Class>& lock);
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700482 bool ValidateSuperClassDescriptors(Handle<mirror::Class> klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700483 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700484
Ian Rogers98379392014-02-24 16:53:16 -0800485 bool IsSameDescriptorInDifferentClassContexts(Thread* self, const char* descriptor,
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700486 Handle<mirror::ClassLoader> class_loader1,
487 Handle<mirror::ClassLoader> class_loader2)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700488 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700489
Ian Rogers98379392014-02-24 16:53:16 -0800490 bool IsSameMethodSignatureInDifferentClassContexts(Thread* self, mirror::ArtMethod* method,
Ian Rogersef7d42f2014-01-06 12:55:46 -0800491 mirror::Class* klass1,
492 mirror::Class* klass2)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700493 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700494
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700495 bool LinkClass(Thread* self, Handle<mirror::Class> klass,
496 Handle<mirror::ObjectArray<mirror::Class>> interfaces)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700497 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700498
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700499 bool LinkSuperClass(Handle<mirror::Class> klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700500 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700501
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700502 bool LoadSuperAndInterfaces(Handle<mirror::Class> klass, const DexFile& dex_file)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700503 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700504
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700505 bool LinkMethods(Thread* self, Handle<mirror::Class> klass,
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700506 Handle<mirror::ObjectArray<mirror::Class>> interfaces)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700507 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700508
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700509 bool LinkVirtualMethods(Thread* self, Handle<mirror::Class> klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700510 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700511
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700512 bool LinkInterfaceMethods(Handle<mirror::Class> klass,
513 Handle<mirror::ObjectArray<mirror::Class>> interfaces)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700514 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700515
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700516 bool LinkStaticFields(Handle<mirror::Class> klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700517 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700518 bool LinkInstanceFields(Handle<mirror::Class> klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700519 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700520 bool LinkFields(Handle<mirror::Class> klass, bool is_static)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700521 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700522 void LinkCode(Handle<mirror::ArtMethod> method, const OatFile::OatClass* oat_class,
Dmitry Petrochenkof0972a42014-05-16 17:43:39 +0700523 const DexFile& dex_file, uint32_t dex_method_index, uint32_t method_index)
524 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700525
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700526
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700527 void CreateReferenceInstanceOffsets(Handle<mirror::Class> klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700528 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700529 void CreateReferenceStaticOffsets(Handle<mirror::Class> klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700530 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700531 void CreateReferenceOffsets(Handle<mirror::Class> klass, bool is_static,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700532 uint32_t reference_offsets)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700533 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700534
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700535 // For use by ImageWriter to find DexCaches for its roots
Hiroshi Yamauchie9e3e692014-06-24 14:31:37 -0700536 ReaderWriterMutex* DexLock()
537 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) LOCK_RETURNED(dex_lock_) {
538 return &dex_lock_;
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700539 }
Hiroshi Yamauchie9e3e692014-06-24 14:31:37 -0700540 size_t GetDexCacheCount() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_, dex_lock_) {
541 return dex_caches_.size();
542 }
543 mirror::DexCache* GetDexCache(size_t idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_, dex_lock_);
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700544
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700545 const OatFile* FindOpenedOatFileForDexFile(const DexFile& dex_file)
Ian Rogers33e95662013-05-20 20:29:14 -0700546 LOCKS_EXCLUDED(dex_lock_)
547 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700548 const OatFile* FindOpenedOatFileFromDexLocation(const char* dex_location,
Brian Carlstrom08cbf662013-12-10 16:52:57 -0800549 const uint32_t* const dex_location_checksum)
Ian Rogers719d1a32014-03-06 12:13:39 -0800550 LOCKS_EXCLUDED(dex_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700551 const OatFile* FindOpenedOatFileFromOatLocation(const std::string& oat_location)
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700552 LOCKS_EXCLUDED(dex_lock_);
553 const DexFile* FindDexFileInOatLocation(const char* dex_location,
Ian Rogerse3359f72013-06-11 15:14:11 -0700554 uint32_t dex_location_checksum,
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700555 const char* oat_location,
556 std::string* error_msg)
557 LOCKS_EXCLUDED(dex_lock_);
Ian Rogerse3359f72013-06-11 15:14:11 -0700558
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700559 const DexFile* VerifyAndOpenDexFileFromOatFile(const std::string& oat_file_location,
560 const char* dex_location,
561 std::string* error_msg,
562 bool* open_failed)
563 LOCKS_EXCLUDED(dex_lock_);
Brian Carlstromfad71432011-10-16 20:25:10 -0700564
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700565 mirror::ArtMethod* CreateProxyConstructor(Thread* self, Handle<mirror::Class> klass,
Brian Carlstromea46f952013-07-30 01:26:50 -0700566 mirror::Class* proxy_class)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700567 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700568 mirror::ArtMethod* CreateProxyMethod(Thread* self, Handle<mirror::Class> klass,
569 Handle<mirror::ArtMethod> prototype)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700570 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jesse Wilson95caa792011-10-12 18:14:17 -0400571
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700572 std::vector<const DexFile*> boot_class_path_;
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700573
Ian Rogers1bf8d4d2013-05-30 00:18:49 -0700574 mutable ReaderWriterMutex dex_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
Mathieu Chartier893263b2014-03-04 11:07:42 -0800575 std::vector<size_t> new_dex_cache_roots_ GUARDED_BY(dex_lock_);;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800576 std::vector<mirror::DexCache*> dex_caches_ GUARDED_BY(dex_lock_);
Elliott Hughesf8349362012-06-18 15:00:06 -0700577 std::vector<const OatFile*> oat_files_ GUARDED_BY(dex_lock_);
Brian Carlstrom47d237a2011-10-18 15:08:33 -0700578
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700579
Brian Carlstromaded5f72011-10-07 17:15:04 -0700580 // multimap from a string hash code of a class descriptor to
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800581 // mirror::Class* instances. Results should be compared for a matching
Brian Carlstrom9cff8e12011-08-18 16:47:29 -0700582 // Class::descriptor_ and Class::class_loader_.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800583 typedef std::multimap<size_t, mirror::Class*> Table;
Hiroshi Yamauchia91a4bc2014-06-13 16:44:55 -0700584 // This contains strong roots. To enable concurrent root scanning of
585 // the class table, be careful to use a read barrier when accessing this.
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700586 Table class_table_ GUARDED_BY(Locks::classlinker_classes_lock_);
Ian Rogers700a4022014-05-19 16:49:03 -0700587 std::vector<std::pair<size_t, mirror::Class*>> new_class_roots_;
Elliott Hughesf8349362012-06-18 15:00:06 -0700588
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700589 // Do we need to search dex caches to find image classes?
590 bool dex_cache_image_class_lookup_required_;
591 // Number of times we've searched dex caches for a class. After a certain number of misses we move
592 // the classes into the class_table_ to avoid dex cache based searches.
593 AtomicInteger failed_dex_cache_class_lookups_;
594
595 mirror::Class* LookupClassFromTableLocked(const char* descriptor,
596 const mirror::ClassLoader* class_loader,
597 size_t hash)
598 SHARED_LOCKS_REQUIRED(Locks::classlinker_classes_lock_, Locks::mutator_lock_);
599
600 void MoveImageClassesToClassTable() LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
601 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
602 mirror::Class* LookupClassFromImage(const char* descriptor)
603 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700604
Brian Carlstroma663ea52011-08-19 23:33:41 -0700605 // indexes into class_roots_.
606 // needs to be kept in sync with class_roots_descriptors_.
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700607 enum ClassRoot {
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700608 kJavaLangClass,
609 kJavaLangObject,
Elliott Hughes418d20f2011-09-22 14:00:39 -0700610 kClassArrayClass,
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700611 kObjectArrayClass,
612 kJavaLangString,
Mathieu Chartier66f19252012-09-18 08:57:04 -0700613 kJavaLangDexCache,
Elliott Hughesbf61ba32011-10-11 10:53:09 -0700614 kJavaLangRefReference,
Brian Carlstromea46f952013-07-30 01:26:50 -0700615 kJavaLangReflectArtField,
616 kJavaLangReflectArtMethod,
Ian Rogers466bb252011-10-14 03:29:56 -0700617 kJavaLangReflectProxy,
Mathieu Chartier66f19252012-09-18 08:57:04 -0700618 kJavaLangStringArrayClass,
Brian Carlstromea46f952013-07-30 01:26:50 -0700619 kJavaLangReflectArtFieldArrayClass,
620 kJavaLangReflectArtMethodArrayClass,
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700621 kJavaLangClassLoader,
Ian Rogers5167c972012-02-03 10:41:20 -0800622 kJavaLangThrowable,
jeffhao8cd6dda2012-02-22 10:15:34 -0800623 kJavaLangClassNotFoundException,
Shih-wei Liao55df06b2011-08-26 14:39:27 -0700624 kJavaLangStackTraceElement,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700625 kPrimitiveBoolean,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700626 kPrimitiveByte,
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700627 kPrimitiveChar,
628 kPrimitiveDouble,
629 kPrimitiveFloat,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700630 kPrimitiveInt,
631 kPrimitiveLong,
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700632 kPrimitiveShort,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700633 kPrimitiveVoid,
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700634 kBooleanArrayClass,
635 kByteArrayClass,
636 kCharArrayClass,
637 kDoubleArrayClass,
638 kFloatArrayClass,
639 kIntArrayClass,
640 kLongArrayClass,
641 kShortArrayClass,
Shih-wei Liao55df06b2011-08-26 14:39:27 -0700642 kJavaLangStackTraceElementArrayClass,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700643 kClassRootsMax,
644 };
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800645 mirror::ObjectArray<mirror::Class>* class_roots_;
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700646
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800647 mirror::Class* GetClassRoot(ClassRoot class_root) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700648
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800649 void SetClassRoot(ClassRoot class_root, mirror::Class* klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700650 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstroma663ea52011-08-19 23:33:41 -0700651
Hiroshi Yamauchie9e3e692014-06-24 14:31:37 -0700652 mirror::ObjectArray<mirror::Class>* GetClassRoots() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
653 mirror::ObjectArray<mirror::Class>* class_roots =
654 ReadBarrier::BarrierForRoot<mirror::ObjectArray<mirror::Class>, kWithReadBarrier>(
655 &class_roots_);
656 DCHECK(class_roots != NULL);
657 return class_roots;
Brian Carlstrom34f426c2011-10-04 12:58:02 -0700658 }
659
Elliott Hughes418d20f2011-09-22 14:00:39 -0700660 static const char* class_roots_descriptors_[];
Brian Carlstroma663ea52011-08-19 23:33:41 -0700661
662 const char* GetClassRootDescriptor(ClassRoot class_root) {
663 const char* descriptor = class_roots_descriptors_[class_root];
664 CHECK(descriptor != NULL);
665 return descriptor;
666 }
667
Ian Rogers98379392014-02-24 16:53:16 -0800668 // The interface table used by all arrays.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800669 mirror::IfTable* array_iftable_;
Carl Shapiro565f5072011-07-10 13:39:43 -0700670
Ian Rogers98379392014-02-24 16:53:16 -0800671 // A cache of the last FindArrayClass results. The cache serves to avoid creating array class
672 // descriptors for the sake of performing FindClass.
673 static constexpr size_t kFindArrayCacheSize = 16;
674 mirror::Class* find_array_class_cache_[kFindArrayCacheSize];
675 size_t find_array_class_cache_next_victim_;
676
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700677 bool init_done_;
Mathieu Chartier893263b2014-03-04 11:07:42 -0800678 bool log_new_dex_caches_roots_ GUARDED_BY(dex_lock_);
679 bool log_new_class_table_roots_ GUARDED_BY(Locks::classlinker_classes_lock_);
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700680
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700681 InternTable* intern_table_;
682
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700683 const void* portable_resolution_trampoline_;
684 const void* quick_resolution_trampoline_;
Jeff Hao88474b42013-10-23 16:24:40 -0700685 const void* portable_imt_conflict_trampoline_;
686 const void* quick_imt_conflict_trampoline_;
Andreas Gampe2da88232014-02-27 12:26:20 -0800687 const void* quick_generic_jni_trampoline_;
Vladimir Marko8a630572014-04-09 18:45:35 +0100688 const void* quick_to_interpreter_bridge_trampoline_;
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700689
Brian Carlstrom34f426c2011-10-04 12:58:02 -0700690 friend class ImageWriter; // for GetClassRoots
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800691 FRIEND_TEST(ClassLinkerTest, ClassRootDescriptors);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800692 FRIEND_TEST(mirror::DexCacheTest, Open);
Brian Carlstromae826982011-11-09 01:33:42 -0800693 FRIEND_TEST(ExceptionTest, FindExceptionHandler);
694 FRIEND_TEST(ObjectTest, AllocObjectArray);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700695 DISALLOW_COPY_AND_ASSIGN(ClassLinker);
696};
697
698} // namespace art
699
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700700#endif // ART_RUNTIME_CLASS_LINKER_H_