blob: 7e31356ea3a9f3e098c114dd7faeae23143d64f4 [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"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080029#include "root_visitor.h"
Brian Carlstrom58ae9412011-10-04 00:56:06 -070030#include "oat_file.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;
Ian Rogers1f539342012-10-03 21:09:42 -070050template<class T> class SirtRef;
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
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070054class ClassLinker {
55 public:
Jeff Hao88474b42013-10-23 16:24:40 -070056 // Interface method table size. Increasing this value reduces the chance of two interface methods
57 // colliding in the interface method table but increases the size of classes that implement
58 // (non-marker) interfaces.
59 static constexpr size_t kImtSize = 64;
60
Mathieu Chartier590fee92013-09-13 13:46:47 -070061 explicit ClassLinker(InternTable* intern_table);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -070062 ~ClassLinker();
Carl Shapiro565f5072011-07-10 13:39:43 -070063
Mathieu Chartier590fee92013-09-13 13:46:47 -070064 // Initialize class linker by bootstraping from dex files
65 void InitFromCompiler(const std::vector<const DexFile*>& boot_class_path)
66 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
67
68 // Initialize class linker from one or more images.
69 void InitFromImage() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
70
Ian Rogersbe7149f2013-08-20 09:29:39 -070071 bool IsInBootClassPath(const char* descriptor);
72
Elliott Hughes64bf5a32011-09-20 14:43:12 -070073 // Finds a class by its descriptor, loading it if necessary.
Brian Carlstrom74eb46a2011-08-02 20:10:14 -070074 // If class_loader is null, searches boot_class_path_.
Mathieu Chartierc528dba2013-11-26 12:00:11 -080075 mirror::Class* FindClass(const char* descriptor, const SirtRef<mirror::ClassLoader>& class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -070076 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromaded5f72011-10-07 17:15:04 -070077
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080078 mirror::Class* FindSystemClass(const char* descriptor)
Ian Rogersb726dcb2012-09-05 08:57:23 -070079 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromaded5f72011-10-07 17:15:04 -070080
Mathieu Chartier590fee92013-09-13 13:46:47 -070081 // Reutrns true if the class linker is initialized.
82 bool IsInitialized() const;
83
Brian Carlstromaded5f72011-10-07 17:15:04 -070084 // Define a new a class based on a ClassDef from a DexFile
Mathieu Chartierc528dba2013-11-26 12:00:11 -080085 mirror::Class* DefineClass(const char* descriptor,
86 const SirtRef<mirror::ClassLoader>& class_loader,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080087 const DexFile& dex_file, const DexFile::ClassDef& dex_class_def)
Ian Rogersb726dcb2012-09-05 08:57:23 -070088 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes64bf5a32011-09-20 14:43:12 -070089
90 // Finds a class by its descriptor, returning NULL if it isn't wasn't loaded
91 // by the given 'class_loader'.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080092 mirror::Class* LookupClass(const char* descriptor, const mirror::ClassLoader* class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -070093 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
94 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -070095
Elliott Hughes6fa602d2011-12-02 17:54:25 -080096 // Finds all the classes with the given descriptor, regardless of ClassLoader.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080097 void LookupClasses(const char* descriptor, std::vector<mirror::Class*>& classes)
Ian Rogersb726dcb2012-09-05 08:57:23 -070098 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
99 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes6fa602d2011-12-02 17:54:25 -0800100
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800101 mirror::Class* FindPrimitiveClass(char type) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700102
Brian Carlstromae826982011-11-09 01:33:42 -0800103 // General class unloading is not supported, this is used to prune
104 // unwanted classes during image writing.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800105 bool RemoveClass(const char* descriptor, const mirror::ClassLoader* class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700106 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
107 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromae826982011-11-09 01:33:42 -0800108
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700109 void DumpAllClasses(int flags)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700110 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
111 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes9d5ccec2011-09-19 13:19:50 -0700112
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700113 void DumpForSigQuit(std::ostream& os)
114 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
115 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughescac6cc72011-11-03 20:31:21 -0700116
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700117 size_t NumLoadedClasses()
118 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
119 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughese27955c2011-08-26 15:21:24 -0700120
Brian Carlstromb63ec392011-08-27 17:38:27 -0700121 // Resolve a String with the given index from the DexFile, storing the
Brian Carlstromaded5f72011-10-07 17:15:04 -0700122 // result in the DexCache. The referrer is used to identify the
123 // target DexCache and ClassLoader to use for resolution.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800124 mirror::String* ResolveString(uint32_t string_idx, mirror::ArtMethod* referrer)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800125 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromaded5f72011-10-07 17:15:04 -0700126
127 // Resolve a String with the given index from the DexFile, storing the
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700128 // result in the DexCache.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800129 mirror::String* ResolveString(const DexFile& dex_file, uint32_t string_idx,
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800130 const SirtRef<mirror::DexCache>& dex_cache)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700131 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700132
Brian Carlstromb63ec392011-08-27 17:38:27 -0700133 // Resolve a Type with the given index from the DexFile, storing the
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700134 // result in the DexCache. The referrer is used to identity the
135 // target DexCache and ClassLoader to use for resolution.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800136 mirror::Class* ResolveType(const DexFile& dex_file, uint16_t type_idx, mirror::Class* referrer)
Mathieu Chartier590fee92013-09-13 13:46:47 -0700137 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700138
Brian Carlstromb63ec392011-08-27 17:38:27 -0700139 // Resolve a Type with the given index from the DexFile, storing the
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700140 // result in the DexCache. The referrer is used to identify the
Brian Carlstromb63ec392011-08-27 17:38:27 -0700141 // target DexCache and ClassLoader to use for resolution.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800142 mirror::Class* ResolveType(uint16_t type_idx, mirror::ArtMethod* referrer)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800143 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700144
Ian Rogersef7d42f2014-01-06 12:55:46 -0800145 mirror::Class* ResolveType(uint16_t type_idx, mirror::ArtField* referrer)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800146 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromb63ec392011-08-27 17:38:27 -0700147
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700148 // Resolve a type with the given ID from the DexFile, storing the
149 // result in DexCache. The ClassLoader is used to search for the
150 // type, since it may be referenced from but not contained within
151 // the given DexFile.
Mathieu Chartier590fee92013-09-13 13:46:47 -0700152 mirror::Class* ResolveType(const DexFile& dex_file, uint16_t type_idx,
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800153 const SirtRef<mirror::DexCache>& dex_cache,
154 const SirtRef<mirror::ClassLoader>& class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700155 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700156
157 // Resolve a method with a given ID from the DexFile, storing the
158 // result in DexCache. The ClassLinker and ClassLoader are used as
159 // in ResolveType. What is unique is the method type argument which
160 // is used to determine if this method is a direct, static, or
161 // virtual method.
Brian Carlstromea46f952013-07-30 01:26:50 -0700162 mirror::ArtMethod* ResolveMethod(const DexFile& dex_file,
163 uint32_t method_idx,
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800164 const SirtRef<mirror::DexCache>& dex_cache,
165 const SirtRef<mirror::ClassLoader>& class_loader,
Ian Rogersef7d42f2014-01-06 12:55:46 -0800166 mirror::ArtMethod* referrer,
Brian Carlstromea46f952013-07-30 01:26:50 -0700167 InvokeType type)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700168 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700169
Ian Rogersef7d42f2014-01-06 12:55:46 -0800170 mirror::ArtMethod* ResolveMethod(uint32_t method_idx, mirror::ArtMethod* referrer,
Brian Carlstromea46f952013-07-30 01:26:50 -0700171 InvokeType type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800172 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom16192862011-09-12 17:50:06 -0700173
Ian Rogersef7d42f2014-01-06 12:55:46 -0800174 mirror::ArtField* ResolveField(uint32_t field_idx, mirror::ArtMethod* referrer,
Brian Carlstromea46f952013-07-30 01:26:50 -0700175 bool is_static)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800176 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromb9edb842011-08-28 16:31:06 -0700177
Brian Carlstrom16192862011-09-12 17:50:06 -0700178 // Resolve a field with a given ID from the DexFile, storing the
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700179 // result in DexCache. The ClassLinker and ClassLoader are used as
180 // in ResolveType. What is unique is the is_static argument which is
181 // used to determine if we are resolving a static or non-static
182 // field.
Brian Carlstromea46f952013-07-30 01:26:50 -0700183 mirror::ArtField* ResolveField(const DexFile& dex_file,
184 uint32_t field_idx,
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800185 const SirtRef<mirror::DexCache>& dex_cache,
186 const SirtRef<mirror::ClassLoader>& class_loader,
Brian Carlstromea46f952013-07-30 01:26:50 -0700187 bool is_static)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700188 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom9ea1cb12011-08-24 23:18:18 -0700189
Ian Rogersb067ac22011-12-13 18:05:09 -0800190 // Resolve a field with a given ID from the DexFile, storing the
191 // result in DexCache. The ClassLinker and ClassLoader are used as
192 // in ResolveType. No is_static argument is provided so that Java
193 // field resolution semantics are followed.
Brian Carlstromea46f952013-07-30 01:26:50 -0700194 mirror::ArtField* ResolveFieldJLS(const DexFile& dex_file,
195 uint32_t field_idx,
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800196 const SirtRef<mirror::DexCache>& dex_cache,
197 const SirtRef<mirror::ClassLoader>& class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700198 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersb067ac22011-12-13 18:05:09 -0800199
Ian Rogersad25ac52011-10-04 19:13:33 -0700200 // Get shorty from method index without resolution. Used to do handlerization.
Brian Carlstromea46f952013-07-30 01:26:50 -0700201 const char* MethodShorty(uint32_t method_idx, mirror::ArtMethod* referrer, uint32_t* length)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700202 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersad25ac52011-10-04 19:13:33 -0700203
Elliott Hughesf4c21c92011-08-19 17:31:31 -0700204 // Returns true on success, false if there's an exception pending.
Brian Carlstrom25c33252011-09-18 15:58:35 -0700205 // can_run_clinit=false allows the compiler to attempt to init a class,
206 // given the restriction that no <clinit> execution is possible.
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800207 bool EnsureInitialized(const SirtRef<mirror::Class>& c,
208 bool can_init_fields, bool can_init_parents)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700209 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700210
Elliott Hughes2a20cfd2011-09-23 19:30:41 -0700211 // Initializes classes that have instances in the image but that have
212 // <clinit> methods so they could not be initialized by the compiler.
Ian Rogersb726dcb2012-09-05 08:57:23 -0700213 void RunRootClinits() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes2a20cfd2011-09-23 19:30:41 -0700214
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700215 void RegisterDexFile(const DexFile& dex_file)
216 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700217 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800218 void RegisterDexFile(const DexFile& dex_file, const SirtRef<mirror::DexCache>& dex_cache)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700219 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700220 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700221
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700222 const OatFile* RegisterOatFile(const OatFile* oat_file)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700223 LOCKS_EXCLUDED(dex_lock_);
Brian Carlstrom866c8622012-01-06 16:35:13 -0800224
Brian Carlstrom8a487412011-08-29 20:08:52 -0700225 const std::vector<const DexFile*>& GetBootClassPath() {
226 return boot_class_path_;
227 }
228
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700229 void VisitClasses(ClassVisitor* visitor, void* arg)
230 LOCKS_EXCLUDED(dex_lock_)
231 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700232 // Less efficient variant of VisitClasses that doesn't hold the classlinker_classes_lock_
233 // when calling the visitor.
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700234 void VisitClassesWithoutClassesLock(ClassVisitor* visitor, void* arg)
235 LOCKS_EXCLUDED(dex_lock_)
236 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesa2155262011-11-16 16:26:58 -0800237
Mathieu Chartierc4621982013-09-16 19:43:47 -0700238 void VisitRoots(RootVisitor* visitor, void* arg, bool only_dirty, bool clean_dirty)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700239 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_, dex_lock_);
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700240
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800241 mirror::DexCache* FindDexCache(const DexFile& dex_file) const
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700242 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700243 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700244 bool IsDexFileRegistered(const DexFile& dex_file) const
245 LOCKS_EXCLUDED(dex_lock_);
Brian Carlstromea46f952013-07-30 01:26:50 -0700246 void FixupDexCaches(mirror::ArtMethod* resolution_method) const
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700247 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700248 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom1d9f52b2011-10-13 10:50:45 -0700249
jeffhao262bf462011-10-20 18:36:32 -0700250 // Generate an oat file from a dex file
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700251 bool GenerateOatFile(const char* dex_filename,
Brian Carlstromd601af82012-01-06 10:15:19 -0800252 int oat_fd,
Vladimir Marko60836d52014-01-16 15:53:38 +0000253 const char* oat_cache_filename,
254 std::string* error_msg);
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700255 LOCKS_EXCLUDED(Locks::mutator_lock_);
jeffhao262bf462011-10-20 18:36:32 -0700256
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700257 const OatFile* FindOatFileFromOatLocation(const std::string& location,
258 std::string* error_msg)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700259 LOCKS_EXCLUDED(dex_lock_);
260
Brian Carlstrom5b332c82012-02-01 15:02:31 -0800261 // Finds the oat file for a dex location, generating the oat file if
262 // it is missing or out of date. Returns the DexFile from within the
263 // created oat file.
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700264 const DexFile* FindOrCreateOatFileForDexLocation(const char* dex_location,
Brian Carlstrom756ee4e2013-10-03 15:46:12 -0700265 uint32_t dex_location_checksum,
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700266 const char* oat_location,
267 std::string* error_msg)
268 LOCKS_EXCLUDED(dex_lock_, Locks::mutator_lock_);
Brian Carlstrom5b332c82012-02-01 15:02:31 -0800269 // Find a DexFile within an OatFile given a DexFile location. Note
270 // that this returns null if the location checksum of the DexFile
271 // does not match the OatFile.
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700272 const DexFile* FindDexFileInOatFileFromDexLocation(const char* location,
Brian Carlstrom08cbf662013-12-10 16:52:57 -0800273 const uint32_t* const location_checksum,
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700274 std::string* error_msg)
275 LOCKS_EXCLUDED(dex_lock_, Locks::mutator_lock_);
Brian Carlstrom5b332c82012-02-01 15:02:31 -0800276
jeffhaof6174e82012-01-31 16:14:17 -0800277
Brian Carlstrom28db0122012-10-18 16:20:41 -0700278 // Returns true if oat file contains the dex file with the given location and checksum.
Brian Carlstromafe25512012-06-27 17:02:58 -0700279 static bool VerifyOatFileChecksums(const OatFile* oat_file,
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700280 const char* dex_location,
281 uint32_t dex_location_checksum,
282 std::string* error_msg);
Brian Carlstromafe25512012-06-27 17:02:58 -0700283
Elliott Hughes418d20f2011-09-22 14:00:39 -0700284 // TODO: replace this with multiple methods that allocate the correct managed type.
Shih-wei Liao44175362011-08-28 16:59:17 -0700285 template <class T>
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800286 mirror::ObjectArray<T>* AllocObjectArray(Thread* self, size_t length)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700287 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Shih-wei Liao55df06b2011-08-26 14:39:27 -0700288
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800289 mirror::ObjectArray<mirror::Class>* AllocClassArray(Thread* self, size_t length)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700290 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
jeffhao98eacac2011-09-14 16:11:53 -0700291
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800292 mirror::ObjectArray<mirror::String>* AllocStringArray(Thread* self, size_t length)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700293 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800294
Brian Carlstromea46f952013-07-30 01:26:50 -0700295 mirror::ObjectArray<mirror::ArtMethod>* AllocArtMethodArray(Thread* self, size_t length)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800296 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
297
298 mirror::IfTable* AllocIfTable(Thread* self, size_t ifcount)
299 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
300
Brian Carlstromea46f952013-07-30 01:26:50 -0700301 mirror::ObjectArray<mirror::ArtField>* AllocArtFieldArray(Thread* self, size_t length)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800302 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
303
304 mirror::ObjectArray<mirror::StackTraceElement>* AllocStackTraceElementArray(Thread* self,
305 size_t length)
306 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
307
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800308 void VerifyClass(const SirtRef<mirror::Class>& klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800309 bool VerifyClassUsingOatFile(const DexFile& dex_file, mirror::Class* klass,
310 mirror::Class::Status& oat_file_class_status)
311 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800312 void ResolveClassExceptionHandlerTypes(const DexFile& dex_file,
313 const SirtRef<mirror::Class>& klass)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800314 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromea46f952013-07-30 01:26:50 -0700315 void ResolveMethodExceptionHandlerTypes(const DexFile& dex_file, mirror::ArtMethod* klass)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800316 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
317
Mathieu Chartier590fee92013-09-13 13:46:47 -0700318 mirror::Class* CreateProxyClass(ScopedObjectAccess& soa, jstring name, jobjectArray interfaces,
319 jobject loader, jobjectArray methods, jobjectArray throws)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800320 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800321 std::string GetDescriptorForProxy(mirror::Class* proxy_class)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800322 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800323 mirror::ArtMethod* FindMethodForProxy(mirror::Class* proxy_class,
324 mirror::ArtMethod* proxy_method)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700325 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700326 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jesse Wilson95caa792011-10-12 18:14:17 -0400327
Ian Rogers19846512012-02-24 11:42:47 -0800328 // Get the oat code for a method when its class isn't yet initialized
Ian Rogersef7d42f2014-01-06 12:55:46 -0800329 const void* GetQuickOatCodeFor(mirror::ArtMethod* method)
330 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
331 const void* GetPortableOatCodeFor(mirror::ArtMethod* method, bool* have_portable_code)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700332 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers19846512012-02-24 11:42:47 -0800333
Mathieu Chartiere35517a2012-10-30 18:49:55 -0700334 // Get the oat code for a method from a method index.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800335 const void* GetQuickOatCodeFor(const DexFile& dex_file, uint16_t class_def_idx, uint32_t method_idx)
336 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
337 const void* GetPortableOatCodeFor(const DexFile& dex_file, uint16_t class_def_idx, uint32_t method_idx)
Ian Rogers33e95662013-05-20 20:29:14 -0700338 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartiere35517a2012-10-30 18:49:55 -0700339
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700340 pid_t GetClassesLockOwner(); // For SignalCatcher.
341 pid_t GetDexLockOwner(); // For SignalCatcher.
Brian Carlstrom24a3c2e2011-10-17 18:07:52 -0700342
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700343 const void* GetPortableResolutionTrampoline() const {
344 return portable_resolution_trampoline_;
345 }
346
347 const void* GetQuickResolutionTrampoline() const {
348 return quick_resolution_trampoline_;
349 }
350
Jeff Hao88474b42013-10-23 16:24:40 -0700351 const void* GetPortableImtConflictTrampoline() const {
352 return portable_imt_conflict_trampoline_;
353 }
354
355 const void* GetQuickImtConflictTrampoline() const {
356 return quick_imt_conflict_trampoline_;
357 }
358
359 InternTable* GetInternTable() const {
360 return intern_table_;
361 }
362
Ian Rogers848871b2013-08-05 10:56:33 -0700363 // Attempts to insert a class into a class table. Returns NULL if
364 // the class was inserted, otherwise returns an existing class with
365 // the same descriptor and ClassLoader.
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700366 mirror::Class* InsertClass(const char* descriptor, mirror::Class* klass, size_t hash)
Ian Rogers848871b2013-08-05 10:56:33 -0700367 LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
368 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
369
Mathieu Chartier590fee92013-09-13 13:46:47 -0700370 // Special code to allocate an art method, use this instead of class->AllocObject.
371 mirror::ArtMethod* AllocArtMethod(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro61e019d2011-07-14 16:53:09 -0700372
Mathieu Chartier590fee92013-09-13 13:46:47 -0700373 private:
Ian Rogersef7d42f2014-01-06 12:55:46 -0800374 const OatFile::OatMethod GetOatMethodFor(mirror::ArtMethod* method)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700375 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
TDYa12785321912012-04-01 15:24:56 -0700376
Brian Carlstrom56d947f2013-07-15 13:14:23 -0700377 OatFile& GetImageOatFile(gc::space::ImageSpace* space)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700378 LOCKS_EXCLUDED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700379 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstroma663ea52011-08-19 23:33:41 -0700380
Ian Rogersb726dcb2012-09-05 08:57:23 -0700381 void FinishInit() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstroma663ea52011-08-19 23:33:41 -0700382
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700383 // For early bootstrapping by Init
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800384 mirror::Class* AllocClass(Thread* self, mirror::Class* java_lang_Class, size_t class_size)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700385 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700386
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800387 // Alloc* convenience functions to avoid needing to pass in mirror::Class*
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700388 // values that are known to the ClassLinker such as
389 // kObjectArrayClass and kJavaLangString etc.
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800390 mirror::Class* AllocClass(Thread* self, size_t class_size)
391 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800392 mirror::DexCache* AllocDexCache(Thread* self, const DexFile& dex_file)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700393 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromea46f952013-07-30 01:26:50 -0700394 mirror::ArtField* AllocArtField(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersbdb03912011-09-14 00:55:44 -0700395
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800396 mirror::Class* CreatePrimitiveClass(Thread* self, Primitive::Type type)
397 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
398 mirror::Class* InitializePrimitiveClass(mirror::Class* primitive_class, Primitive::Type type)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700399 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom5b8e4c82011-09-18 01:38:59 -0700400
Brian Carlstroma331b3c2011-07-18 17:47:56 -0700401
Mathieu Chartier590fee92013-09-13 13:46:47 -0700402 mirror::Class* CreateArrayClass(const char* descriptor,
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800403 const SirtRef<mirror::ClassLoader>& class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700404 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstroma331b3c2011-07-18 17:47:56 -0700405
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700406 void AppendToBootClassPath(const DexFile& dex_file)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700407 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800408 void AppendToBootClassPath(const DexFile& dex_file, const SirtRef<mirror::DexCache>& dex_cache)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700409 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700410
Elliott Hughes5fe594f2011-09-08 12:33:17 -0700411 void ConstructFieldMap(const DexFile& dex_file, const DexFile::ClassDef& dex_class_def,
Brian Carlstromea46f952013-07-30 01:26:50 -0700412 mirror::Class* c, SafeMap<uint32_t, mirror::ArtField*>& field_map)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700413 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes5fe594f2011-09-08 12:33:17 -0700414
Brian Carlstrom4873d462011-08-21 15:23:39 -0700415 size_t SizeOfClass(const DexFile& dex_file,
416 const DexFile::ClassDef& dex_class_def);
417
Brian Carlstromf615a612011-07-23 12:50:34 -0700418 void LoadClass(const DexFile& dex_file,
419 const DexFile::ClassDef& dex_class_def,
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800420 const SirtRef<mirror::Class>& klass,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800421 mirror::ClassLoader* class_loader)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700422 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700423
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800424 void LoadField(const DexFile& dex_file, const ClassDataItemIterator& it,
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800425 const SirtRef<mirror::Class>& klass, const SirtRef<mirror::ArtField>& dst)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800426 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700427
Brian Carlstromea46f952013-07-30 01:26:50 -0700428 mirror::ArtMethod* LoadMethod(Thread* self, const DexFile& dex_file,
429 const ClassDataItemIterator& dex_method,
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800430 const SirtRef<mirror::Class>& klass)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800431 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom934486c2011-07-12 23:42:50 -0700432
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800433 void FixupStaticTrampolines(mirror::Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers19846512012-02-24 11:42:47 -0800434
435 // Finds the associated oat class for a dex_file and descriptor
Ian Rogersee39a102013-09-19 02:56:49 -0700436 const OatFile::OatClass* GetOatClass(const DexFile& dex_file, uint16_t class_def_idx)
Ian Rogers33e95662013-05-20 20:29:14 -0700437 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers19846512012-02-24 11:42:47 -0800438
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800439 void RegisterDexFileLocked(const DexFile& dex_file, const SirtRef<mirror::DexCache>& dex_cache)
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700440 EXCLUSIVE_LOCKS_REQUIRED(dex_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700441 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers1bf8d4d2013-05-30 00:18:49 -0700442 bool IsDexFileRegisteredLocked(const DexFile& dex_file) const SHARED_LOCKS_REQUIRED(dex_lock_);
Brian Carlstromaded5f72011-10-07 17:15:04 -0700443
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800444 bool InitializeClass(const SirtRef<mirror::Class>& klass, bool can_run_clinit,
445 bool can_init_parents)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700446 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800447 bool WaitForInitializeClass(const SirtRef<mirror::Class>& klass, Thread* self,
448 ObjectLock<mirror::Class>& lock);
449 bool ValidateSuperClassDescriptors(const SirtRef<mirror::Class>& klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700450 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700451
Ian Rogers595799e2012-01-11 17:32:51 -0800452 bool IsSameDescriptorInDifferentClassContexts(const char* descriptor,
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800453 SirtRef<mirror::ClassLoader>& class_loader1,
454 SirtRef<mirror::ClassLoader>& class_loader2)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700455 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700456
Ian Rogersef7d42f2014-01-06 12:55:46 -0800457 bool IsSameMethodSignatureInDifferentClassContexts(mirror::ArtMethod* method,
458 mirror::Class* klass1,
459 mirror::Class* klass2)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700460 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700461
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800462 bool LinkClass(Thread* self, const SirtRef<mirror::Class>& klass,
463 const SirtRef<mirror::ObjectArray<mirror::Class> >& interfaces)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700464 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700465
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800466 bool LinkSuperClass(const SirtRef<mirror::Class>& klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700467 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700468
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800469 bool LoadSuperAndInterfaces(const SirtRef<mirror::Class>& klass, const DexFile& dex_file)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700470 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700471
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800472 bool LinkMethods(const SirtRef<mirror::Class>& klass,
473 const SirtRef<mirror::ObjectArray<mirror::Class> >& interfaces)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700474 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700475
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800476 bool LinkVirtualMethods(const SirtRef<mirror::Class>& klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700477 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700478
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800479 bool LinkInterfaceMethods(const SirtRef<mirror::Class>& klass,
480 const SirtRef<mirror::ObjectArray<mirror::Class> >& interfaces)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700481 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700482
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800483 bool LinkStaticFields(const SirtRef<mirror::Class>& klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700484 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800485 bool LinkInstanceFields(const SirtRef<mirror::Class>& klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700486 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800487 bool LinkFields(const SirtRef<mirror::Class>& klass, bool is_static)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700488 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers0cfe1fb2011-08-26 03:29:44 -0700489
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700490
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800491 void CreateReferenceInstanceOffsets(const SirtRef<mirror::Class>& klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700492 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800493 void CreateReferenceStaticOffsets(const SirtRef<mirror::Class>& klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700494 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800495 void CreateReferenceOffsets(const SirtRef<mirror::Class>& klass, bool is_static,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700496 uint32_t reference_offsets)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700497 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700498
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700499 // For use by ImageWriter to find DexCaches for its roots
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800500 const std::vector<mirror::DexCache*>& GetDexCaches() {
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700501 return dex_caches_;
502 }
503
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700504 const OatFile* FindOpenedOatFileForDexFile(const DexFile& dex_file)
Ian Rogers33e95662013-05-20 20:29:14 -0700505 LOCKS_EXCLUDED(dex_lock_)
506 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700507 const OatFile* FindOpenedOatFileFromDexLocation(const char* dex_location,
Brian Carlstrom08cbf662013-12-10 16:52:57 -0800508 const uint32_t* const dex_location_checksum)
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700509 LOCKS_EXCLUDED(dex_lock);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700510 const OatFile* FindOpenedOatFileFromOatLocation(const std::string& oat_location)
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700511 LOCKS_EXCLUDED(dex_lock_);
512 const DexFile* FindDexFileInOatLocation(const char* dex_location,
Ian Rogerse3359f72013-06-11 15:14:11 -0700513 uint32_t dex_location_checksum,
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700514 const char* oat_location,
515 std::string* error_msg)
516 LOCKS_EXCLUDED(dex_lock_);
Ian Rogerse3359f72013-06-11 15:14:11 -0700517
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700518 const DexFile* VerifyAndOpenDexFileFromOatFile(const std::string& oat_file_location,
519 const char* dex_location,
520 std::string* error_msg,
521 bool* open_failed)
522 LOCKS_EXCLUDED(dex_lock_);
Brian Carlstromfad71432011-10-16 20:25:10 -0700523
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800524 mirror::ArtMethod* CreateProxyConstructor(Thread* self, const SirtRef<mirror::Class>& klass,
Brian Carlstromea46f952013-07-30 01:26:50 -0700525 mirror::Class* proxy_class)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700526 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800527 mirror::ArtMethod* CreateProxyMethod(Thread* self, const SirtRef<mirror::Class>& klass,
528 const SirtRef<mirror::ArtMethod>& prototype)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700529 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jesse Wilson95caa792011-10-12 18:14:17 -0400530
Brian Carlstrom4a96b602011-07-26 16:40:23 -0700531 std::vector<const DexFile*> boot_class_path_;
Brian Carlstrom578bbdc2011-07-21 14:07:47 -0700532
Ian Rogers1bf8d4d2013-05-30 00:18:49 -0700533 mutable ReaderWriterMutex dex_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800534 std::vector<mirror::DexCache*> dex_caches_ GUARDED_BY(dex_lock_);
Elliott Hughesf8349362012-06-18 15:00:06 -0700535 std::vector<const OatFile*> oat_files_ GUARDED_BY(dex_lock_);
Brian Carlstrom47d237a2011-10-18 15:08:33 -0700536
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700537
Brian Carlstromaded5f72011-10-07 17:15:04 -0700538 // multimap from a string hash code of a class descriptor to
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800539 // mirror::Class* instances. Results should be compared for a matching
Brian Carlstrom9cff8e12011-08-18 16:47:29 -0700540 // Class::descriptor_ and Class::class_loader_.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800541 typedef std::multimap<size_t, mirror::Class*> Table;
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700542 Table class_table_ GUARDED_BY(Locks::classlinker_classes_lock_);
Elliott Hughesf8349362012-06-18 15:00:06 -0700543
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700544 // Do we need to search dex caches to find image classes?
545 bool dex_cache_image_class_lookup_required_;
546 // Number of times we've searched dex caches for a class. After a certain number of misses we move
547 // the classes into the class_table_ to avoid dex cache based searches.
548 AtomicInteger failed_dex_cache_class_lookups_;
549
550 mirror::Class* LookupClassFromTableLocked(const char* descriptor,
551 const mirror::ClassLoader* class_loader,
552 size_t hash)
553 SHARED_LOCKS_REQUIRED(Locks::classlinker_classes_lock_, Locks::mutator_lock_);
554
555 void MoveImageClassesToClassTable() LOCKS_EXCLUDED(Locks::classlinker_classes_lock_)
556 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
557 mirror::Class* LookupClassFromImage(const char* descriptor)
558 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700559
Brian Carlstroma663ea52011-08-19 23:33:41 -0700560 // indexes into class_roots_.
561 // needs to be kept in sync with class_roots_descriptors_.
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700562 enum ClassRoot {
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700563 kJavaLangClass,
564 kJavaLangObject,
Elliott Hughes418d20f2011-09-22 14:00:39 -0700565 kClassArrayClass,
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700566 kObjectArrayClass,
567 kJavaLangString,
Mathieu Chartier66f19252012-09-18 08:57:04 -0700568 kJavaLangDexCache,
Elliott Hughesbf61ba32011-10-11 10:53:09 -0700569 kJavaLangRefReference,
Brian Carlstromea46f952013-07-30 01:26:50 -0700570 kJavaLangReflectArtField,
571 kJavaLangReflectArtMethod,
Ian Rogers466bb252011-10-14 03:29:56 -0700572 kJavaLangReflectProxy,
Mathieu Chartier66f19252012-09-18 08:57:04 -0700573 kJavaLangStringArrayClass,
Brian Carlstromea46f952013-07-30 01:26:50 -0700574 kJavaLangReflectArtFieldArrayClass,
575 kJavaLangReflectArtMethodArrayClass,
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700576 kJavaLangClassLoader,
Ian Rogers5167c972012-02-03 10:41:20 -0800577 kJavaLangThrowable,
jeffhao8cd6dda2012-02-22 10:15:34 -0800578 kJavaLangClassNotFoundException,
Shih-wei Liao55df06b2011-08-26 14:39:27 -0700579 kJavaLangStackTraceElement,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700580 kPrimitiveBoolean,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700581 kPrimitiveByte,
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700582 kPrimitiveChar,
583 kPrimitiveDouble,
584 kPrimitiveFloat,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700585 kPrimitiveInt,
586 kPrimitiveLong,
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700587 kPrimitiveShort,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700588 kPrimitiveVoid,
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700589 kBooleanArrayClass,
590 kByteArrayClass,
591 kCharArrayClass,
592 kDoubleArrayClass,
593 kFloatArrayClass,
594 kIntArrayClass,
595 kLongArrayClass,
596 kShortArrayClass,
Shih-wei Liao55df06b2011-08-26 14:39:27 -0700597 kJavaLangStackTraceElementArrayClass,
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700598 kClassRootsMax,
599 };
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800600 mirror::ObjectArray<mirror::Class>* class_roots_;
Brian Carlstrom913af1b2011-07-23 21:41:13 -0700601
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800602 mirror::Class* GetClassRoot(ClassRoot class_root) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom74eb46a2011-08-02 20:10:14 -0700603
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800604 void SetClassRoot(ClassRoot class_root, mirror::Class* klass)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700605 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstroma663ea52011-08-19 23:33:41 -0700606
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800607 mirror::ObjectArray<mirror::Class>* GetClassRoots() {
Brian Carlstrom34f426c2011-10-04 12:58:02 -0700608 DCHECK(class_roots_ != NULL);
609 return class_roots_;
610 }
611
Elliott Hughes418d20f2011-09-22 14:00:39 -0700612 static const char* class_roots_descriptors_[];
Brian Carlstroma663ea52011-08-19 23:33:41 -0700613
614 const char* GetClassRootDescriptor(ClassRoot class_root) {
615 const char* descriptor = class_roots_descriptors_[class_root];
616 CHECK(descriptor != NULL);
617 return descriptor;
618 }
619
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800620 mirror::IfTable* array_iftable_;
Carl Shapiro565f5072011-07-10 13:39:43 -0700621
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700622 bool init_done_;
Mathieu Chartierc4621982013-09-16 19:43:47 -0700623 bool dex_caches_dirty_ GUARDED_BY(dex_lock_);
624 bool class_table_dirty_ GUARDED_BY(Locks::classlinker_classes_lock_);
Brian Carlstrom75cb3b42011-07-28 02:13:36 -0700625
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700626 InternTable* intern_table_;
627
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700628 const void* portable_resolution_trampoline_;
629 const void* quick_resolution_trampoline_;
Jeff Hao88474b42013-10-23 16:24:40 -0700630 const void* portable_imt_conflict_trampoline_;
631 const void* quick_imt_conflict_trampoline_;
Jeff Hao0aba0ba2013-06-03 14:49:28 -0700632
Brian Carlstrom34f426c2011-10-04 12:58:02 -0700633 friend class ImageWriter; // for GetClassRoots
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800634 FRIEND_TEST(ClassLinkerTest, ClassRootDescriptors);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800635 FRIEND_TEST(mirror::DexCacheTest, Open);
Brian Carlstromae826982011-11-09 01:33:42 -0800636 FRIEND_TEST(ExceptionTest, FindExceptionHandler);
637 FRIEND_TEST(ObjectTest, AllocObjectArray);
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700638 DISALLOW_COPY_AND_ASSIGN(ClassLinker);
639};
640
641} // namespace art
642
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700643#endif // ART_RUNTIME_CLASS_LINKER_H_