blob: c89fedf53e722e973e973afbc7d3360781fdf34c [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"
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070031
32namespace art {
Ian Rogers1d54e732013-05-02 21:10:01 -070033namespace gc {
34namespace space {
35 class ImageSpace;
36} // namespace space
37} // namespace gc
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080038namespace mirror {
Ian Rogers33e95662013-05-20 20:29:14 -070039 class ClassLoader;
40 class DexCache;
41 class DexCacheTest_Open_Test;
42 class IfTable;
43 template<class T> class ObjectArray;
44 class StackTraceElement;
45} // namespace mirror
Ian Rogers1d54e732013-05-02 21:10:01 -070046
Elliott Hughescf4c6c42011-09-01 15:16:42 -070047class InternTable;
Mathieu Chartierc528dba2013-11-26 12:00:11 -080048template<class T> class ObjectLock;
Mathieu Chartier590fee92013-09-13 13:46:47 -070049class ScopedObjectAccess;
Mathieu Chartiereb8167a2014-05-07 15:43:14 -070050template<class T> class Handle;
Elliott Hughescf4c6c42011-09-01 15:16:42 -070051
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080052typedef bool (ClassVisitor)(mirror::Class* c, void* arg);
Elliott Hughesa2155262011-11-16 16:26:58 -080053
Mathieu Chartier893263b2014-03-04 11:07:42 -080054enum VisitRootFlags : uint8_t;
55
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070056class ClassLinker {
57 public:
Jeff Hao88474b42013-10-23 16:24:40 -070058 // Interface method table size. Increasing this value reduces the chance of two interface methods
59 // colliding in the interface method table but increases the size of classes that implement
60 // (non-marker) interfaces.
61 static constexpr size_t kImtSize = 64;
62
Mathieu Chartier590fee92013-09-13 13:46:47 -070063 explicit ClassLinker(InternTable* intern_table);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070064 ~ClassLinker();
Carl Shapiro565f5072011-07-10 13:39:43 -070065
Mathieu Chartier590fee92013-09-13 13:46:47 -070066 // Initialize class linker by bootstraping from dex files
67 void InitFromCompiler(const std::vector<const DexFile*>& boot_class_path)
68 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
69
70 // Initialize class linker from one or more images.
71 void InitFromImage() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
72
Ian Rogersbe7149f2013-08-20 09:29:39 -070073 bool IsInBootClassPath(const char* descriptor);
74
Elliott Hughes64bf5a32011-09-20 14:43:12 -070075 // Finds a class by its descriptor, loading it if necessary.
Brian Carlstrom74eb46a2011-08-02 20:10:14 -070076 // If class_loader is null, searches boot_class_path_.
Ian Rogers98379392014-02-24 16:53:16 -080077 mirror::Class* FindClass(Thread* self, const char* descriptor,
Mathieu Chartiereb8167a2014-05-07 15:43:14 -070078 const Handle<mirror::ClassLoader>& class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -070079 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromaded5f72011-10-07 17:15:04 -070080
Ian Rogers98379392014-02-24 16:53:16 -080081 // Finds a class by its descriptor using the "system" class loader, ie by searching the
82 // boot_class_path_.
83 mirror::Class* FindSystemClass(Thread* self, const char* descriptor)
84 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
85
86 // Finds the array class given for the element class.
87 mirror::Class* FindArrayClass(Thread* self, mirror::Class* element_class)
Ian Rogersb726dcb2012-09-05 08:57:23 -070088 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromaded5f72011-10-07 17:15:04 -070089
Mathieu Chartier590fee92013-09-13 13:46:47 -070090 // Reutrns true if the class linker is initialized.
91 bool IsInitialized() const;
92
Brian Carlstromaded5f72011-10-07 17:15:04 -070093 // Define a new a class based on a ClassDef from a DexFile
Mathieu Chartierc528dba2013-11-26 12:00:11 -080094 mirror::Class* DefineClass(const char* descriptor,
Mathieu Chartiereb8167a2014-05-07 15:43:14 -070095 const Handle<mirror::ClassLoader>& class_loader,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080096 const DexFile& dex_file, const DexFile::ClassDef& dex_class_def)
Ian Rogersb726dcb2012-09-05 08:57:23 -070097 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes64bf5a32011-09-20 14:43:12 -070098
99 // Finds a class by its descriptor, returning NULL if it isn't wasn't loaded
100 // by the given 'class_loader'.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800101 mirror::Class* LookupClass(const char* descriptor, const mirror::ClassLoader* class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700102 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
103 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700104
Elliott Hughes6fa602d2011-12-02 17:54:25 -0800105 // Finds all the classes with the given descriptor, regardless of ClassLoader.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800106 void LookupClasses(const char* descriptor, std::vector<mirror::Class*>& classes)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700107 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
108 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes6fa602d2011-12-02 17:54:25 -0800109
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800110 mirror::Class* FindPrimitiveClass(char type) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700111
Brian Carlstromae826982011-11-09 01:33:42 -0800112 // General class unloading is not supported, this is used to prune
113 // unwanted classes during image writing.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800114 bool RemoveClass(const char* descriptor, const mirror::ClassLoader* class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700115 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
116 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromae826982011-11-09 01:33:42 -0800117
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700118 void DumpAllClasses(int flags)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700119 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
120 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes9d5ccec2011-09-19 13:19:50 -0700121
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700122 void DumpForSigQuit(std::ostream& os)
123 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
124 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughescac6cc72011-11-03 20:31:21 -0700125
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700126 size_t NumLoadedClasses()
127 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
128 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughese27955c2011-08-26 15:21:24 -0700129
Brian Carlstromb63ec392011-08-27 17:38:27 -0700130 // Resolve a String with the given index from the DexFile, storing the
Brian Carlstromaded5f72011-10-07 17:15:04 -0700131 // result in the DexCache. The referrer is used to identify the
132 // target DexCache and ClassLoader to use for resolution.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800133 mirror::String* ResolveString(uint32_t string_idx, mirror::ArtMethod* referrer)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800134 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromaded5f72011-10-07 17:15:04 -0700135
136 // Resolve a String with the given index from the DexFile, storing the
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700137 // result in the DexCache.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800138 mirror::String* ResolveString(const DexFile& dex_file, uint32_t string_idx,
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700139 const Handle<mirror::DexCache>& dex_cache)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700140 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700141
Brian Carlstromb63ec392011-08-27 17:38:27 -0700142 // Resolve a Type with the given index from the DexFile, storing the
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700143 // result in the DexCache. The referrer is used to identity the
144 // target DexCache and ClassLoader to use for resolution.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800145 mirror::Class* ResolveType(const DexFile& dex_file, uint16_t type_idx, mirror::Class* referrer)
Mathieu Chartier590fee92013-09-13 13:46:47 -0700146 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700147
Brian Carlstromb63ec392011-08-27 17:38:27 -0700148 // Resolve a Type with the given index from the DexFile, storing the
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700149 // result in the DexCache. The referrer is used to identify the
Brian Carlstromb63ec392011-08-27 17:38:27 -0700150 // target DexCache and ClassLoader to use for resolution.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800151 mirror::Class* ResolveType(uint16_t type_idx, mirror::ArtMethod* referrer)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800152 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700153
Ian Rogersef7d42f2014-01-06 12:55:46 -0800154 mirror::Class* ResolveType(uint16_t type_idx, mirror::ArtField* referrer)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800155 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromb63ec392011-08-27 17:38:27 -0700156
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700157 // Resolve a type with the given ID from the DexFile, storing the
158 // result in DexCache. The ClassLoader is used to search for the
159 // type, since it may be referenced from but not contained within
160 // the given DexFile.
Mathieu Chartier590fee92013-09-13 13:46:47 -0700161 mirror::Class* ResolveType(const DexFile& dex_file, uint16_t type_idx,
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700162 const Handle<mirror::DexCache>& dex_cache,
163 const Handle<mirror::ClassLoader>& class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700164 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700165
166 // Resolve a method with a given ID from the DexFile, storing the
167 // result in DexCache. The ClassLinker and ClassLoader are used as
168 // in ResolveType. What is unique is the method type argument which
169 // is used to determine if this method is a direct, static, or
170 // virtual method.
Brian Carlstromea46f952013-07-30 01:26:50 -0700171 mirror::ArtMethod* ResolveMethod(const DexFile& dex_file,
172 uint32_t method_idx,
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700173 const Handle<mirror::DexCache>& dex_cache,
174 const Handle<mirror::ClassLoader>& class_loader,
Ian Rogersef7d42f2014-01-06 12:55:46 -0800175 mirror::ArtMethod* referrer,
Brian Carlstromea46f952013-07-30 01:26:50 -0700176 InvokeType type)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700177 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700178
Ian Rogersef7d42f2014-01-06 12:55:46 -0800179 mirror::ArtMethod* ResolveMethod(uint32_t method_idx, mirror::ArtMethod* referrer,
Brian Carlstromea46f952013-07-30 01:26:50 -0700180 InvokeType type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800181 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom16192862011-09-12 17:50:06 -0700182
Ian Rogersef7d42f2014-01-06 12:55:46 -0800183 mirror::ArtField* ResolveField(uint32_t field_idx, mirror::ArtMethod* referrer,
Brian Carlstromea46f952013-07-30 01:26:50 -0700184 bool is_static)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800185 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromb9edb842011-08-28 16:31:06 -0700186
Brian Carlstrom16192862011-09-12 17:50:06 -0700187 // Resolve a field with a given ID from the DexFile, storing the
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700188 // result in DexCache. The ClassLinker and ClassLoader are used as
189 // in ResolveType. What is unique is the is_static argument which is
190 // used to determine if we are resolving a static or non-static
191 // field.
Brian Carlstromea46f952013-07-30 01:26:50 -0700192 mirror::ArtField* ResolveField(const DexFile& dex_file,
193 uint32_t field_idx,
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700194 const Handle<mirror::DexCache>& dex_cache,
195 const Handle<mirror::ClassLoader>& class_loader,
Brian Carlstromea46f952013-07-30 01:26:50 -0700196 bool is_static)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700197 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700198
Ian Rogersb067ac22011-12-13 18:05:09 -0800199 // Resolve a field with a given ID from the DexFile, storing the
200 // result in DexCache. The ClassLinker and ClassLoader are used as
201 // in ResolveType. No is_static argument is provided so that Java
202 // field resolution semantics are followed.
Brian Carlstromea46f952013-07-30 01:26:50 -0700203 mirror::ArtField* ResolveFieldJLS(const DexFile& dex_file,
204 uint32_t field_idx,
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700205 const Handle<mirror::DexCache>& dex_cache,
206 const Handle<mirror::ClassLoader>& class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700207 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersb067ac22011-12-13 18:05:09 -0800208
Ian Rogersad25ac52011-10-04 19:13:33 -0700209 // Get shorty from method index without resolution. Used to do handlerization.
Brian Carlstromea46f952013-07-30 01:26:50 -0700210 const char* MethodShorty(uint32_t method_idx, mirror::ArtMethod* referrer, uint32_t* length)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700211 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersad25ac52011-10-04 19:13:33 -0700212
Elliott Hughesf4c21c92011-08-19 17:31:31 -0700213 // Returns true on success, false if there's an exception pending.
Brian Carlstrom25c33252011-09-18 15:58:35 -0700214 // can_run_clinit=false allows the compiler to attempt to init a class,
215 // given the restriction that no <clinit> execution is possible.
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700216 bool EnsureInitialized(const Handle<mirror::Class>& c,
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800217 bool can_init_fields, bool can_init_parents)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700218 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700219
Elliott Hughes2a20cfd2011-09-23 19:30:41 -0700220 // Initializes classes that have instances in the image but that have
221 // <clinit> methods so they could not be initialized by the compiler.
Ian Rogersb726dcb2012-09-05 08:57:23 -0700222 void RunRootClinits() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes2a20cfd2011-09-23 19:30:41 -0700223
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700224 void RegisterDexFile(const DexFile& dex_file)
225 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700226 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700227 void RegisterDexFile(const DexFile& dex_file, const Handle<mirror::DexCache>& dex_cache)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700228 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700229 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700230
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700231 const OatFile* RegisterOatFile(const OatFile* oat_file)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700232 LOCKS_EXCLUDED(dex_lock_);
Brian Carlstrom866c8622012-01-06 16:35:13 -0800233
Brian Carlstrom8a487412011-08-29 20:08:52 -0700234 const std::vector<const DexFile*>& GetBootClassPath() {
235 return boot_class_path_;
236 }
237
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700238 void VisitClasses(ClassVisitor* visitor, void* arg)
239 LOCKS_EXCLUDED(dex_lock_)
240 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700241 // Less efficient variant of VisitClasses that doesn't hold the classlinker_classes_lock_
242 // when calling the visitor.
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700243 void VisitClassesWithoutClassesLock(ClassVisitor* visitor, void* arg)
244 LOCKS_EXCLUDED(dex_lock_)
245 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesa2155262011-11-16 16:26:58 -0800246
Mathieu Chartier893263b2014-03-04 11:07:42 -0800247 void VisitRoots(RootCallback* callback, void* arg, VisitRootFlags flags)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700248 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_, dex_lock_);
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700249
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800250 mirror::DexCache* FindDexCache(const DexFile& dex_file) const
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700251 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700252 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700253 bool IsDexFileRegistered(const DexFile& dex_file) const
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700254 LOCKS_EXCLUDED(dex_lock_) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromea46f952013-07-30 01:26:50 -0700255 void FixupDexCaches(mirror::ArtMethod* resolution_method) const
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700256 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700257 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom1d9f52b2011-10-13 10:50:45 -0700258
jeffhao262bf462011-10-20 18:36:32 -0700259 // Generate an oat file from a dex file
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700260 bool GenerateOatFile(const char* dex_filename,
Brian Carlstromd601af82012-01-06 10:15:19 -0800261 int oat_fd,
Vladimir Marko60836d52014-01-16 15:53:38 +0000262 const char* oat_cache_filename,
Ian Rogers719d1a32014-03-06 12:13:39 -0800263 std::string* error_msg)
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700264 LOCKS_EXCLUDED(Locks::mutator_lock_);
jeffhao262bf462011-10-20 18:36:32 -0700265
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700266 const OatFile* FindOatFileFromOatLocation(const std::string& location,
267 std::string* error_msg)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700268 LOCKS_EXCLUDED(dex_lock_);
269
Brian Carlstrom5b332c82012-02-01 15:02:31 -0800270 // Finds the oat file for a dex location, generating the oat file if
271 // it is missing or out of date. Returns the DexFile from within the
272 // created oat file.
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700273 const DexFile* FindOrCreateOatFileForDexLocation(const char* dex_location,
Brian Carlstrom756ee4e2013-10-03 15:46:12 -0700274 uint32_t dex_location_checksum,
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700275 const char* oat_location,
Andreas Gampe329d1882014-04-08 10:32:19 -0700276 std::vector<std::string>* error_msgs)
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700277 LOCKS_EXCLUDED(dex_lock_, Locks::mutator_lock_);
Brian Carlstrom5b332c82012-02-01 15:02:31 -0800278 // Find a DexFile within an OatFile given a DexFile location. Note
279 // that this returns null if the location checksum of the DexFile
280 // does not match the OatFile.
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700281 const DexFile* FindDexFileInOatFileFromDexLocation(const char* location,
Brian Carlstrom08cbf662013-12-10 16:52:57 -0800282 const uint32_t* const location_checksum,
Brian Carlstrom0e12bdc2014-05-14 17:44:28 -0700283 InstructionSet isa,
Andreas Gampe329d1882014-04-08 10:32:19 -0700284 std::vector<std::string>* error_msgs)
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700285 LOCKS_EXCLUDED(dex_lock_, Locks::mutator_lock_);
Brian Carlstrom5b332c82012-02-01 15:02:31 -0800286
jeffhaof6174e82012-01-31 16:14:17 -0800287
Brian Carlstrom28db0122012-10-18 16:20:41 -0700288 // Returns true if oat file contains the dex file with the given location and checksum.
Brian Carlstromafe25512012-06-27 17:02:58 -0700289 static bool VerifyOatFileChecksums(const OatFile* oat_file,
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700290 const char* dex_location,
291 uint32_t dex_location_checksum,
Brian Carlstrom2afe4942014-05-19 10:25:33 -0700292 InstructionSet instruction_set,
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700293 std::string* error_msg);
Brian Carlstromafe25512012-06-27 17:02:58 -0700294
Elliott Hughes418d20f2011-09-22 14:00:39 -0700295 // TODO: replace this with multiple methods that allocate the correct managed type.
Shih-wei Liao44175362011-08-28 16:59:17 -0700296 template <class T>
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800297 mirror::ObjectArray<T>* AllocObjectArray(Thread* self, size_t length)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700298 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Shih-wei Liao55df06b2011-08-26 14:39:27 -0700299
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800300 mirror::ObjectArray<mirror::Class>* AllocClassArray(Thread* self, size_t length)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700301 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
jeffhao98eacac2011-09-14 16:11:53 -0700302
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800303 mirror::ObjectArray<mirror::String>* AllocStringArray(Thread* self, size_t length)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700304 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800305
Brian Carlstromea46f952013-07-30 01:26:50 -0700306 mirror::ObjectArray<mirror::ArtMethod>* AllocArtMethodArray(Thread* self, size_t length)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800307 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
308
309 mirror::IfTable* AllocIfTable(Thread* self, size_t ifcount)
310 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
311
Brian Carlstromea46f952013-07-30 01:26:50 -0700312 mirror::ObjectArray<mirror::ArtField>* AllocArtFieldArray(Thread* self, size_t length)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800313 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
314
315 mirror::ObjectArray<mirror::StackTraceElement>* AllocStackTraceElementArray(Thread* self,
316 size_t length)
317 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
318
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700319 void VerifyClass(const Handle<mirror::Class>& klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800320 bool VerifyClassUsingOatFile(const DexFile& dex_file, mirror::Class* klass,
321 mirror::Class::Status& oat_file_class_status)
322 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800323 void ResolveClassExceptionHandlerTypes(const DexFile& dex_file,
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700324 const Handle<mirror::Class>& klass)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800325 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromea46f952013-07-30 01:26:50 -0700326 void ResolveMethodExceptionHandlerTypes(const DexFile& dex_file, mirror::ArtMethod* klass)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800327 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
328
Mathieu Chartier590fee92013-09-13 13:46:47 -0700329 mirror::Class* CreateProxyClass(ScopedObjectAccess& soa, jstring name, jobjectArray interfaces,
330 jobject loader, jobjectArray methods, jobjectArray throws)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800331 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800332 std::string GetDescriptorForProxy(mirror::Class* proxy_class)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800333 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800334 mirror::ArtMethod* FindMethodForProxy(mirror::Class* proxy_class,
335 mirror::ArtMethod* proxy_method)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700336 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700337 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jesse Wilson95caa792011-10-12 18:14:17 -0400338
Ian Rogers19846512012-02-24 11:42:47 -0800339 // Get the oat code for a method when its class isn't yet initialized
Ian Rogersef7d42f2014-01-06 12:55:46 -0800340 const void* GetQuickOatCodeFor(mirror::ArtMethod* method)
341 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
342 const void* GetPortableOatCodeFor(mirror::ArtMethod* method, bool* have_portable_code)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700343 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers19846512012-02-24 11:42:47 -0800344
Mathieu Chartiere35517a2012-10-30 18:49:55 -0700345 // Get the oat code for a method from a method index.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800346 const void* GetQuickOatCodeFor(const DexFile& dex_file, uint16_t class_def_idx, uint32_t method_idx)
347 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
348 const void* GetPortableOatCodeFor(const DexFile& dex_file, uint16_t class_def_idx, uint32_t method_idx)
Ian Rogers33e95662013-05-20 20:29:14 -0700349 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartiere35517a2012-10-30 18:49:55 -0700350
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700351 pid_t GetClassesLockOwner(); // For SignalCatcher.
352 pid_t GetDexLockOwner(); // For SignalCatcher.
Brian Carlstrom24a3c2e2011-10-17 18:07:52 -0700353
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700354 const void* GetPortableResolutionTrampoline() const {
355 return portable_resolution_trampoline_;
356 }
357
Andreas Gampe2da88232014-02-27 12:26:20 -0800358 const void* GetQuickGenericJniTrampoline() const {
Dmitry Petrochenkof0972a42014-05-16 17:43:39 +0700359 return quick_generic_jni_trampoline_;
360 }
Andreas Gampe2da88232014-02-27 12:26:20 -0800361
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700362 const void* GetQuickResolutionTrampoline() const {
363 return quick_resolution_trampoline_;
364 }
365
Jeff Hao88474b42013-10-23 16:24:40 -0700366 const void* GetPortableImtConflictTrampoline() const {
367 return portable_imt_conflict_trampoline_;
368 }
369
370 const void* GetQuickImtConflictTrampoline() const {
371 return quick_imt_conflict_trampoline_;
372 }
373
Vladimir Marko8a630572014-04-09 18:45:35 +0100374 const void* GetQuickToInterpreterBridgeTrampoline() const {
375 return quick_to_interpreter_bridge_trampoline_;
376 }
377
Jeff Hao88474b42013-10-23 16:24:40 -0700378 InternTable* GetInternTable() const {
379 return intern_table_;
380 }
381
Ian Rogers848871b2013-08-05 10:56:33 -0700382 // Attempts to insert a class into a class table. Returns NULL if
383 // the class was inserted, otherwise returns an existing class with
384 // the same descriptor and ClassLoader.
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700385 mirror::Class* InsertClass(const char* descriptor, mirror::Class* klass, size_t hash)
Ian Rogers848871b2013-08-05 10:56:33 -0700386 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
387 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
388
Mathieu Chartier590fee92013-09-13 13:46:47 -0700389 // Special code to allocate an art method, use this instead of class->AllocObject.
390 mirror::ArtMethod* AllocArtMethod(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro61e019d2011-07-14 16:53:09 -0700391
Mathieu Chartier590fee92013-09-13 13:46:47 -0700392 private:
Ian Rogersef7d42f2014-01-06 12:55:46 -0800393 const OatFile::OatMethod GetOatMethodFor(mirror::ArtMethod* method)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700394 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
TDYa12785321912012-04-01 15:24:56 -0700395
Brian Carlstrom56d947f2013-07-15 13:14:23 -0700396 OatFile& GetImageOatFile(gc::space::ImageSpace* space)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700397 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700398 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstroma663ea52011-08-19 23:33:41 -0700399
Ian Rogers98379392014-02-24 16:53:16 -0800400 void FinishInit(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstroma663ea52011-08-19 23:33:41 -0700401
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700402 // For early bootstrapping by Init
Ian Rogers6fac4472014-02-25 17:01:10 -0800403 mirror::Class* AllocClass(Thread* self, mirror::Class* java_lang_Class, uint32_t class_size)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700404 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700405
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800406 // Alloc* convenience functions to avoid needing to pass in mirror::Class*
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700407 // values that are known to the ClassLinker such as
408 // kObjectArrayClass and kJavaLangString etc.
Ian Rogers6fac4472014-02-25 17:01:10 -0800409 mirror::Class* AllocClass(Thread* self, uint32_t class_size)
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800410 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800411 mirror::DexCache* AllocDexCache(Thread* self, const DexFile& dex_file)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700412 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromea46f952013-07-30 01:26:50 -0700413 mirror::ArtField* AllocArtField(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersbdb03912011-09-14 00:55:44 -0700414
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800415 mirror::Class* CreatePrimitiveClass(Thread* self, Primitive::Type type)
416 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
417 mirror::Class* InitializePrimitiveClass(mirror::Class* primitive_class, Primitive::Type type)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700418 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom5b8e4c82011-09-18 01:38:59 -0700419
Brian Carlstroma331b3c2011-07-18 17:47:56 -0700420
Ian Rogers98379392014-02-24 16:53:16 -0800421 mirror::Class* CreateArrayClass(Thread* self, const char* descriptor,
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700422 const Handle<mirror::ClassLoader>& class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700423 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstroma331b3c2011-07-18 17:47:56 -0700424
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700425 void AppendToBootClassPath(const DexFile& dex_file)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700426 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700427 void AppendToBootClassPath(const DexFile& dex_file, const Handle<mirror::DexCache>& dex_cache)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700428 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700429
Elliott Hughes5fe594f2011-09-08 12:33:17 -0700430 void ConstructFieldMap(const DexFile& dex_file, const DexFile::ClassDef& dex_class_def,
Brian Carlstromea46f952013-07-30 01:26:50 -0700431 mirror::Class* c, SafeMap<uint32_t, mirror::ArtField*>& field_map)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700432 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes5fe594f2011-09-08 12:33:17 -0700433
Ian Rogers6fac4472014-02-25 17:01:10 -0800434 uint32_t SizeOfClass(const DexFile& dex_file,
Brian Carlstrom4873d462011-08-21 15:23:39 -0700435 const DexFile::ClassDef& dex_class_def);
436
Brian Carlstromf615a612011-07-23 12:50:34 -0700437 void LoadClass(const DexFile& dex_file,
438 const DexFile::ClassDef& dex_class_def,
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700439 const Handle<mirror::Class>& klass,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800440 mirror::ClassLoader* class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700441 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Vladimir Markod3c5beb2014-04-11 16:32:51 +0100442 void LoadClassMembers(const DexFile& dex_file,
443 const byte* class_data,
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700444 const Handle<mirror::Class>& klass,
Vladimir Markod3c5beb2014-04-11 16:32:51 +0100445 mirror::ClassLoader* class_loader,
446 const OatFile::OatClass* oat_class)
447 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700448
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800449 void LoadField(const DexFile& dex_file, const ClassDataItemIterator& it,
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700450 const Handle<mirror::Class>& klass, const Handle<mirror::ArtField>& dst)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800451 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700452
Brian Carlstromea46f952013-07-30 01:26:50 -0700453 mirror::ArtMethod* LoadMethod(Thread* self, const DexFile& dex_file,
454 const ClassDataItemIterator& dex_method,
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700455 const Handle<mirror::Class>& klass)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800456 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom934486c2011-07-12 23:42:50 -0700457
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800458 void FixupStaticTrampolines(mirror::Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers19846512012-02-24 11:42:47 -0800459
460 // Finds the associated oat class for a dex_file and descriptor
Vladimir Markod3c5beb2014-04-11 16:32:51 +0100461 OatFile::OatClass GetOatClass(const DexFile& dex_file, uint16_t class_def_idx)
Ian Rogers33e95662013-05-20 20:29:14 -0700462 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers19846512012-02-24 11:42:47 -0800463
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700464 void RegisterDexFileLocked(const DexFile& dex_file, const Handle<mirror::DexCache>& dex_cache)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700465 EXCLUSIVE_LOCKS_REQUIRED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700466 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700467 bool IsDexFileRegisteredLocked(const DexFile& dex_file) const
468 SHARED_LOCKS_REQUIRED(dex_lock_, Locks::mutator_lock_);
Brian Carlstromaded5f72011-10-07 17:15:04 -0700469
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700470 bool InitializeClass(const Handle<mirror::Class>& klass, bool can_run_clinit,
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800471 bool can_init_parents)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700472 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700473 bool WaitForInitializeClass(const Handle<mirror::Class>& klass, Thread* self,
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800474 ObjectLock<mirror::Class>& lock);
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700475 bool ValidateSuperClassDescriptors(const Handle<mirror::Class>& klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700476 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700477
Ian Rogers98379392014-02-24 16:53:16 -0800478 bool IsSameDescriptorInDifferentClassContexts(Thread* self, const char* descriptor,
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700479 Handle<mirror::ClassLoader>& class_loader1,
480 Handle<mirror::ClassLoader>& class_loader2)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700481 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700482
Ian Rogers98379392014-02-24 16:53:16 -0800483 bool IsSameMethodSignatureInDifferentClassContexts(Thread* self, mirror::ArtMethod* method,
Ian Rogersef7d42f2014-01-06 12:55:46 -0800484 mirror::Class* klass1,
485 mirror::Class* klass2)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700486 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700487
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700488 bool LinkClass(Thread* self, const Handle<mirror::Class>& klass,
Ian Rogers700a4022014-05-19 16:49:03 -0700489 const Handle<mirror::ObjectArray<mirror::Class>>& interfaces)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700490 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700491
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700492 bool LinkSuperClass(const Handle<mirror::Class>& klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700493 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700494
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700495 bool LoadSuperAndInterfaces(const Handle<mirror::Class>& klass, const DexFile& dex_file)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700496 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700497
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700498 bool LinkMethods(const Handle<mirror::Class>& klass,
Ian Rogers700a4022014-05-19 16:49:03 -0700499 const Handle<mirror::ObjectArray<mirror::Class>>& interfaces)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700500 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700501
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700502 bool LinkVirtualMethods(const Handle<mirror::Class>& klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700503 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700504
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700505 bool LinkInterfaceMethods(const Handle<mirror::Class>& klass,
Ian Rogers700a4022014-05-19 16:49:03 -0700506 const 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 Chartiereb8167a2014-05-07 15:43:14 -0700509 bool LinkStaticFields(const Handle<mirror::Class>& klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700510 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700511 bool LinkInstanceFields(const Handle<mirror::Class>& klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700512 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700513 bool LinkFields(const Handle<mirror::Class>& klass, bool is_static)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700514 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Dmitry Petrochenkof0972a42014-05-16 17:43:39 +0700515 void LinkCode(const Handle<mirror::ArtMethod>& method, const OatFile::OatClass* oat_class,
516 const DexFile& dex_file, uint32_t dex_method_index, uint32_t method_index)
517 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700518
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700519
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700520 void CreateReferenceInstanceOffsets(const Handle<mirror::Class>& klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700521 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700522 void CreateReferenceStaticOffsets(const Handle<mirror::Class>& klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700523 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700524 void CreateReferenceOffsets(const Handle<mirror::Class>& klass, bool is_static,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700525 uint32_t reference_offsets)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700526 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700527
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700528 // For use by ImageWriter to find DexCaches for its roots
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800529 const std::vector<mirror::DexCache*>& GetDexCaches() {
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700530 return dex_caches_;
531 }
532
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700533 const OatFile* FindOpenedOatFileForDexFile(const DexFile& dex_file)
Ian Rogers33e95662013-05-20 20:29:14 -0700534 LOCKS_EXCLUDED(dex_lock_)
535 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700536 const OatFile* FindOpenedOatFileFromDexLocation(const char* dex_location,
Brian Carlstrom08cbf662013-12-10 16:52:57 -0800537 const uint32_t* const dex_location_checksum)
Ian Rogers719d1a32014-03-06 12:13:39 -0800538 LOCKS_EXCLUDED(dex_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700539 const OatFile* FindOpenedOatFileFromOatLocation(const std::string& oat_location)
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700540 LOCKS_EXCLUDED(dex_lock_);
541 const DexFile* FindDexFileInOatLocation(const char* dex_location,
Ian Rogerse3359f72013-06-11 15:14:11 -0700542 uint32_t dex_location_checksum,
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700543 const char* oat_location,
544 std::string* error_msg)
545 LOCKS_EXCLUDED(dex_lock_);
Ian Rogerse3359f72013-06-11 15:14:11 -0700546
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700547 const DexFile* VerifyAndOpenDexFileFromOatFile(const std::string& oat_file_location,
548 const char* dex_location,
549 std::string* error_msg,
550 bool* open_failed)
551 LOCKS_EXCLUDED(dex_lock_);
Brian Carlstromfad71432011-10-16 20:25:10 -0700552
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700553 mirror::ArtMethod* CreateProxyConstructor(Thread* self, const Handle<mirror::Class>& klass,
Brian Carlstromea46f952013-07-30 01:26:50 -0700554 mirror::Class* proxy_class)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700555 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700556 mirror::ArtMethod* CreateProxyMethod(Thread* self, const Handle<mirror::Class>& klass,
557 const Handle<mirror::ArtMethod>& prototype)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700558 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jesse Wilson95caa792011-10-12 18:14:17 -0400559
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700560 std::vector<const DexFile*> boot_class_path_;
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700561
Ian Rogers1bf8d4d2013-05-30 00:18:49 -0700562 mutable ReaderWriterMutex dex_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
Mathieu Chartier893263b2014-03-04 11:07:42 -0800563 std::vector<size_t> new_dex_cache_roots_ GUARDED_BY(dex_lock_);;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800564 std::vector<mirror::DexCache*> dex_caches_ GUARDED_BY(dex_lock_);
Elliott Hughesf8349362012-06-18 15:00:06 -0700565 std::vector<const OatFile*> oat_files_ GUARDED_BY(dex_lock_);
Brian Carlstrom47d237a2011-10-18 15:08:33 -0700566
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700567
Brian Carlstromaded5f72011-10-07 17:15:04 -0700568 // multimap from a string hash code of a class descriptor to
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800569 // mirror::Class* instances. Results should be compared for a matching
Brian Carlstrom9cff8e12011-08-18 16:47:29 -0700570 // Class::descriptor_ and Class::class_loader_.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800571 typedef std::multimap<size_t, mirror::Class*> Table;
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700572 Table class_table_ GUARDED_BY(Locks::classlinker_classes_lock_);
Ian Rogers700a4022014-05-19 16:49:03 -0700573 std::vector<std::pair<size_t, mirror::Class*>> new_class_roots_;
Elliott Hughesf8349362012-06-18 15:00:06 -0700574
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700575 // Do we need to search dex caches to find image classes?
576 bool dex_cache_image_class_lookup_required_;
577 // Number of times we've searched dex caches for a class. After a certain number of misses we move
578 // the classes into the class_table_ to avoid dex cache based searches.
579 AtomicInteger failed_dex_cache_class_lookups_;
580
581 mirror::Class* LookupClassFromTableLocked(const char* descriptor,
582 const mirror::ClassLoader* class_loader,
583 size_t hash)
584 SHARED_LOCKS_REQUIRED(Locks::classlinker_classes_lock_, Locks::mutator_lock_);
585
586 void MoveImageClassesToClassTable() LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
587 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
588 mirror::Class* LookupClassFromImage(const char* descriptor)
589 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700590
Brian Carlstroma663ea52011-08-19 23:33:41 -0700591 // indexes into class_roots_.
592 // needs to be kept in sync with class_roots_descriptors_.
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700593 enum ClassRoot {
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700594 kJavaLangClass,
595 kJavaLangObject,
Elliott Hughes418d20f2011-09-22 14:00:39 -0700596 kClassArrayClass,
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700597 kObjectArrayClass,
598 kJavaLangString,
Mathieu Chartier66f19252012-09-18 08:57:04 -0700599 kJavaLangDexCache,
Elliott Hughesbf61ba32011-10-11 10:53:09 -0700600 kJavaLangRefReference,
Brian Carlstromea46f952013-07-30 01:26:50 -0700601 kJavaLangReflectArtField,
602 kJavaLangReflectArtMethod,
Ian Rogers466bb252011-10-14 03:29:56 -0700603 kJavaLangReflectProxy,
Mathieu Chartier66f19252012-09-18 08:57:04 -0700604 kJavaLangStringArrayClass,
Brian Carlstromea46f952013-07-30 01:26:50 -0700605 kJavaLangReflectArtFieldArrayClass,
606 kJavaLangReflectArtMethodArrayClass,
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700607 kJavaLangClassLoader,
Ian Rogers5167c972012-02-03 10:41:20 -0800608 kJavaLangThrowable,
jeffhao8cd6dda2012-02-22 10:15:34 -0800609 kJavaLangClassNotFoundException,
Shih-wei Liao55df06b2011-08-26 14:39:27 -0700610 kJavaLangStackTraceElement,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700611 kPrimitiveBoolean,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700612 kPrimitiveByte,
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700613 kPrimitiveChar,
614 kPrimitiveDouble,
615 kPrimitiveFloat,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700616 kPrimitiveInt,
617 kPrimitiveLong,
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700618 kPrimitiveShort,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700619 kPrimitiveVoid,
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700620 kBooleanArrayClass,
621 kByteArrayClass,
622 kCharArrayClass,
623 kDoubleArrayClass,
624 kFloatArrayClass,
625 kIntArrayClass,
626 kLongArrayClass,
627 kShortArrayClass,
Shih-wei Liao55df06b2011-08-26 14:39:27 -0700628 kJavaLangStackTraceElementArrayClass,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700629 kClassRootsMax,
630 };
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800631 mirror::ObjectArray<mirror::Class>* class_roots_;
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700632
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800633 mirror::Class* GetClassRoot(ClassRoot class_root) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700634
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800635 void SetClassRoot(ClassRoot class_root, mirror::Class* klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700636 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstroma663ea52011-08-19 23:33:41 -0700637
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800638 mirror::ObjectArray<mirror::Class>* GetClassRoots() {
Brian Carlstrom34f426c2011-10-04 12:58:02 -0700639 DCHECK(class_roots_ != NULL);
640 return class_roots_;
641 }
642
Elliott Hughes418d20f2011-09-22 14:00:39 -0700643 static const char* class_roots_descriptors_[];
Brian Carlstroma663ea52011-08-19 23:33:41 -0700644
645 const char* GetClassRootDescriptor(ClassRoot class_root) {
646 const char* descriptor = class_roots_descriptors_[class_root];
647 CHECK(descriptor != NULL);
648 return descriptor;
649 }
650
Ian Rogers98379392014-02-24 16:53:16 -0800651 // The interface table used by all arrays.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800652 mirror::IfTable* array_iftable_;
Carl Shapiro565f5072011-07-10 13:39:43 -0700653
Ian Rogers98379392014-02-24 16:53:16 -0800654 // A cache of the last FindArrayClass results. The cache serves to avoid creating array class
655 // descriptors for the sake of performing FindClass.
656 static constexpr size_t kFindArrayCacheSize = 16;
657 mirror::Class* find_array_class_cache_[kFindArrayCacheSize];
658 size_t find_array_class_cache_next_victim_;
659
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700660 bool init_done_;
Mathieu Chartier893263b2014-03-04 11:07:42 -0800661 bool log_new_dex_caches_roots_ GUARDED_BY(dex_lock_);
662 bool log_new_class_table_roots_ GUARDED_BY(Locks::classlinker_classes_lock_);
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700663
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700664 InternTable* intern_table_;
665
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700666 const void* portable_resolution_trampoline_;
667 const void* quick_resolution_trampoline_;
Jeff Hao88474b42013-10-23 16:24:40 -0700668 const void* portable_imt_conflict_trampoline_;
669 const void* quick_imt_conflict_trampoline_;
Andreas Gampe2da88232014-02-27 12:26:20 -0800670 const void* quick_generic_jni_trampoline_;
Vladimir Marko8a630572014-04-09 18:45:35 +0100671 const void* quick_to_interpreter_bridge_trampoline_;
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700672
Brian Carlstrom34f426c2011-10-04 12:58:02 -0700673 friend class ImageWriter; // for GetClassRoots
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800674 FRIEND_TEST(ClassLinkerTest, ClassRootDescriptors);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800675 FRIEND_TEST(mirror::DexCacheTest, Open);
Brian Carlstromae826982011-11-09 01:33:42 -0800676 FRIEND_TEST(ExceptionTest, FindExceptionHandler);
677 FRIEND_TEST(ObjectTest, AllocObjectArray);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700678 DISALLOW_COPY_AND_ASSIGN(ClassLinker);
679};
680
681} // namespace art
682
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700683#endif // ART_RUNTIME_CLASS_LINKER_H_