blob: ba8a693bdbe3c41757a72b54e29815f96389b09d [file] [log] [blame]
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001/*
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 */
16
Brian Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_RUNTIME_MIRROR_CLASS_H_
18#define ART_RUNTIME_MIRROR_CLASS_H_
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080019
Mathieu Chartiere401d142015-04-22 13:56:20 -070020#include "base/iteration_range.h"
Mathieu Chartierf8322842014-05-16 10:59:25 -070021#include "dex_file.h"
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -070022#include "gc_root.h"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070023#include "gc/allocator_type.h"
Vladimir Marko23a28212014-01-09 19:24:37 +000024#include "invoke_type.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080025#include "modifiers.h"
26#include "object.h"
Mingyao Yang98d1cc82014-05-15 17:02:16 -070027#include "object_array.h"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070028#include "object_callbacks.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080029#include "primitive.h"
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -070030#include "read_barrier_option.h"
Mathieu Chartiere401d142015-04-22 13:56:20 -070031#include "stride_iterator.h"
32#include "utils.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080033
Mathieu Chartiercd195fe2014-11-25 18:36:01 -080034#ifndef IMT_SIZE
35#error IMT_SIZE not defined
36#endif
37
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080038namespace art {
39
Mathieu Chartierc7853442015-03-27 14:35:38 -070040class ArtField;
Mathieu Chartiere401d142015-04-22 13:56:20 -070041class ArtMethod;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080042struct ClassOffsets;
Andreas Gampe5a4b8a22014-09-11 08:30:08 -070043template<class T> class Handle;
Mathieu Chartierbf99f772014-08-23 16:37:27 -070044template<class T> class Handle;
Ian Rogersd91d6d62013-09-25 20:26:14 -070045class Signature;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080046class StringPiece;
Mathieu Chartier2d2621a2014-10-23 16:48:06 -070047template<size_t kNumReferences> class PACKED(4) StackHandleScope;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080048
49namespace mirror {
50
51class ClassLoader;
Mathieu Chartierfc58af42015-04-16 18:00:39 -070052class Constructor;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080053class DexCache;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080054class IfTable;
55
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080056// C++ mirror of java.lang.Class
Mingyao Yang98d1cc82014-05-15 17:02:16 -070057class MANAGED Class FINAL : public Object {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080058 public:
Ian Rogerscdc1aaf2014-10-09 13:21:38 -070059 // A magic value for reference_instance_offsets_. Ignore the bits and walk the super chain when
60 // this is the value.
61 // [This is an unlikely "natural" value, since it would be 30 non-ref instance fields followed by
62 // 2 ref instance fields.]
63 static constexpr uint32_t kClassWalkSuper = 0xC0000000;
64
Mingyao Yang98d1cc82014-05-15 17:02:16 -070065 // Interface method table size. Increasing this value reduces the chance of two interface methods
66 // colliding in the interface method table but increases the size of classes that implement
67 // (non-marker) interfaces.
Mathieu Chartiercd195fe2014-11-25 18:36:01 -080068 static constexpr size_t kImtSize = IMT_SIZE;
Mingyao Yang98d1cc82014-05-15 17:02:16 -070069
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080070 // Class Status
71 //
Mingyao Yang46f0e972014-09-10 15:16:19 -070072 // kStatusRetired: Class that's temporarily used till class linking time
73 // has its (vtable) size figured out and has been cloned to one with the
74 // right size which will be the one used later. The old one is retired and
75 // will be gc'ed once all refs to the class point to the newly
76 // cloned version.
77 //
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080078 // kStatusNotReady: If a Class cannot be found in the class table by
79 // FindClass, it allocates an new one with AllocClass in the
80 // kStatusNotReady and calls LoadClass. Note if it does find a
81 // class, it may not be kStatusResolved and it will try to push it
82 // forward toward kStatusResolved.
83 //
84 // kStatusIdx: LoadClass populates with Class with information from
85 // the DexFile, moving the status to kStatusIdx, indicating that the
86 // Class value in super_class_ has not been populated. The new Class
87 // can then be inserted into the classes table.
88 //
89 // kStatusLoaded: After taking a lock on Class, the ClassLinker will
90 // attempt to move a kStatusIdx class forward to kStatusLoaded by
91 // using ResolveClass to initialize the super_class_ and ensuring the
92 // interfaces are resolved.
93 //
Mingyao Yang98d1cc82014-05-15 17:02:16 -070094 // kStatusResolving: Class is just cloned with the right size from
95 // temporary class that's acting as a placeholder for linking. The old
96 // class will be retired. New class is set to this status first before
97 // moving on to being resolved.
98 //
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080099 // kStatusResolved: Still holding the lock on Class, the ClassLinker
100 // shows linking is complete and fields of the Class populated by making
101 // it kStatusResolved. Java allows circularities of the form where a super
102 // class has a field that is of the type of the sub class. We need to be able
103 // to fully resolve super classes while resolving types for fields.
104 //
105 // kStatusRetryVerificationAtRuntime: The verifier sets a class to
106 // this state if it encounters a soft failure at compile time. This
107 // often happens when there are unresolved classes in other dex
108 // files, and this status marks a class as needing to be verified
109 // again at runtime.
110 //
111 // TODO: Explain the other states
112 enum Status {
Brian Carlstromf3978662014-09-11 12:21:04 -0700113 kStatusRetired = -2, // Retired, should not be used. Use the newly cloned one instead.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800114 kStatusError = -1,
115 kStatusNotReady = 0,
116 kStatusIdx = 1, // Loaded, DEX idx in super_class_type_idx_ and interfaces_type_idx_.
117 kStatusLoaded = 2, // DEX idx values resolved.
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700118 kStatusResolving = 3, // Just cloned from temporary class object.
119 kStatusResolved = 4, // Part of linking.
120 kStatusVerifying = 5, // In the process of being verified.
121 kStatusRetryVerificationAtRuntime = 6, // Compile time verification failed, retry at runtime.
122 kStatusVerifyingAtRuntime = 7, // Retrying verification at runtime.
123 kStatusVerified = 8, // Logically part of linking; done pre-init.
124 kStatusInitializing = 9, // Class init in progress.
125 kStatusInitialized = 10, // Ready to go.
126 kStatusMax = 11,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800127 };
128
Mathieu Chartier4e305412014-02-19 10:54:44 -0800129 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800130 Status GetStatus() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Andreas Gampe575e78c2014-11-03 23:41:03 -0800131 static_assert(sizeof(Status) == sizeof(uint32_t), "Size of status not equal to uint32");
Ian Rogers03dbc042014-06-02 14:24:56 -0700132 return static_cast<Status>(
133 GetField32Volatile<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, status_)));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800134 }
135
Hiroshi Yamauchi5b783e62015-03-18 17:20:11 -0700136 // This is static because 'this' may be moved by GC.
137 static void SetStatus(Handle<Class> h_this, Status new_status, Thread* self)
138 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800139
Ian Rogers5ddb4102014-01-07 08:58:46 -0800140 static MemberOffset StatusOffset() {
141 return OFFSET_OF_OBJECT_MEMBER(Class, status_);
142 }
143
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700144 // Returns true if the class has been retired.
145 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
146 bool IsRetired() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
147 return GetStatus<kVerifyFlags>() == kStatusRetired;
148 }
149
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800150 // Returns true if the class has failed to link.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800151 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800152 bool IsErroneous() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800153 return GetStatus<kVerifyFlags>() == kStatusError;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800154 }
155
156 // Returns true if the class has been loaded.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800157 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800158 bool IsIdxLoaded() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800159 return GetStatus<kVerifyFlags>() >= kStatusIdx;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800160 }
161
162 // Returns true if the class has been loaded.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800163 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800164 bool IsLoaded() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800165 return GetStatus<kVerifyFlags>() >= kStatusLoaded;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800166 }
167
168 // Returns true if the class has been linked.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800169 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800170 bool IsResolved() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800171 return GetStatus<kVerifyFlags>() >= kStatusResolved;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800172 }
173
174 // Returns true if the class was compile-time verified.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800175 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800176 bool IsCompileTimeVerified() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800177 return GetStatus<kVerifyFlags>() >= kStatusRetryVerificationAtRuntime;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800178 }
179
180 // Returns true if the class has been verified.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800181 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800182 bool IsVerified() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800183 return GetStatus<kVerifyFlags>() >= kStatusVerified;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800184 }
185
186 // Returns true if the class is initializing.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800187 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800188 bool IsInitializing() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800189 return GetStatus<kVerifyFlags>() >= kStatusInitializing;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800190 }
191
192 // Returns true if the class is initialized.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800193 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800194 bool IsInitialized() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800195 return GetStatus<kVerifyFlags>() == kStatusInitialized;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800196 }
197
Mathieu Chartier4e305412014-02-19 10:54:44 -0800198 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700199 ALWAYS_INLINE uint32_t GetAccessFlags() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Hiroshi Yamauchie01a5202015-03-19 12:35:04 -0700200 static MemberOffset AccessFlagsOffset() {
201 return OFFSET_OF_OBJECT_MEMBER(Class, access_flags_);
202 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800203
Andreas Gampe48498592014-09-10 19:48:05 -0700204 void SetAccessFlags(uint32_t new_access_flags) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800205
206 // Returns true if the class is an interface.
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700207 ALWAYS_INLINE bool IsInterface() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800208 return (GetAccessFlags() & kAccInterface) != 0;
209 }
210
211 // Returns true if the class is declared public.
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700212 ALWAYS_INLINE bool IsPublic() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800213 return (GetAccessFlags() & kAccPublic) != 0;
214 }
215
216 // Returns true if the class is declared final.
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700217 ALWAYS_INLINE bool IsFinal() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800218 return (GetAccessFlags() & kAccFinal) != 0;
219 }
220
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700221 ALWAYS_INLINE bool IsFinalizable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800222 return (GetAccessFlags() & kAccClassIsFinalizable) != 0;
223 }
224
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700225 ALWAYS_INLINE void SetFinalizable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700226 uint32_t flags = GetField32(OFFSET_OF_OBJECT_MEMBER(Class, access_flags_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800227 SetAccessFlags(flags | kAccClassIsFinalizable);
228 }
229
Jeff Hao848f70a2014-01-15 13:49:50 -0800230 ALWAYS_INLINE bool IsStringClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
231 return (GetField32(AccessFlagsOffset()) & kAccClassIsStringClass) != 0;
232 }
233
234 ALWAYS_INLINE void SetStringClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
235 uint32_t flags = GetField32(OFFSET_OF_OBJECT_MEMBER(Class, access_flags_));
236 SetAccessFlags(flags | kAccClassIsStringClass);
237 }
238
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800239 // Returns true if the class is abstract.
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700240 ALWAYS_INLINE bool IsAbstract() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800241 return (GetAccessFlags() & kAccAbstract) != 0;
242 }
243
244 // Returns true if the class is an annotation.
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700245 ALWAYS_INLINE bool IsAnnotation() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800246 return (GetAccessFlags() & kAccAnnotation) != 0;
247 }
248
249 // Returns true if the class is synthetic.
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700250 ALWAYS_INLINE bool IsSynthetic() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800251 return (GetAccessFlags() & kAccSynthetic) != 0;
252 }
253
Ian Rogers7b078e82014-09-10 14:44:24 -0700254 // Returns true if the class can avoid access checks.
255 bool IsPreverified() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
256 return (GetAccessFlags() & kAccPreverified) != 0;
257 }
258
259 void SetPreverified() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
260 uint32_t flags = GetField32(OFFSET_OF_OBJECT_MEMBER(Class, access_flags_));
261 SetAccessFlags(flags | kAccPreverified);
262 }
263
Mathieu Chartier4e305412014-02-19 10:54:44 -0800264 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Fred Shih4ee7a662014-07-11 09:59:27 -0700265 bool IsTypeOfReferenceClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800266 return (GetAccessFlags<kVerifyFlags>() & kAccClassIsReference) != 0;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800267 }
268
Mathieu Chartier4e305412014-02-19 10:54:44 -0800269 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800270 bool IsWeakReferenceClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800271 return (GetAccessFlags<kVerifyFlags>() & kAccClassIsWeakReference) != 0;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800272 }
273
Mathieu Chartier4e305412014-02-19 10:54:44 -0800274 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800275 bool IsSoftReferenceClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800276 return (GetAccessFlags<kVerifyFlags>() & kAccReferenceFlagsMask) == kAccClassIsReference;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800277 }
278
Mathieu Chartier4e305412014-02-19 10:54:44 -0800279 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800280 bool IsFinalizerReferenceClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800281 return (GetAccessFlags<kVerifyFlags>() & kAccClassIsFinalizerReference) != 0;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800282 }
283
Mathieu Chartier4e305412014-02-19 10:54:44 -0800284 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800285 bool IsPhantomReferenceClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800286 return (GetAccessFlags<kVerifyFlags>() & kAccClassIsPhantomReference) != 0;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800287 }
288
Ian Rogers04f94f42013-06-10 15:09:26 -0700289 // Can references of this type be assigned to by things of another type? For non-array types
290 // this is a matter of whether sub-classes may exist - which they can't if the type is final.
291 // For array classes, where all the classes are final due to there being no sub-classes, an
292 // Object[] may be assigned to by a String[] but a String[] may not be assigned to by other
293 // types as the component is final.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800294 bool CannotBeAssignedFromOtherTypes() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers04f94f42013-06-10 15:09:26 -0700295 if (!IsArrayClass()) {
296 return IsFinal();
297 } else {
298 Class* component = GetComponentType();
299 if (component->IsPrimitive()) {
Ian Rogersa9a82542013-10-04 11:17:26 -0700300 return true;
Ian Rogers04f94f42013-06-10 15:09:26 -0700301 } else {
302 return component->CannotBeAssignedFromOtherTypes();
303 }
304 }
305 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800306
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700307 // Returns true if this class is the placeholder and should retire and
308 // be replaced with a class with the right size for embedded imt/vtable.
309 bool IsTemp() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
310 Status s = GetStatus();
311 return s < Status::kStatusResolving && ShouldHaveEmbeddedImtAndVTable();
312 }
313
Ian Rogersef7d42f2014-01-06 12:55:46 -0800314 String* GetName() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); // Returns the cached name.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800315 void SetName(String* name) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); // Sets the cached name.
316 // Computes the name, then sets the cached value.
Mathieu Chartierf8322842014-05-16 10:59:25 -0700317 static String* ComputeName(Handle<Class> h_this) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800318
Mathieu Chartierc2f4d022014-03-03 16:11:42 -0800319 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier4e305412014-02-19 10:54:44 -0800320 bool IsProxyClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800321 // Read access flags without using getter as whether something is a proxy can be check in
322 // any loaded state
323 // TODO: switch to a check if the super class is java.lang.reflect.Proxy?
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700324 uint32_t access_flags = GetField32<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, access_flags_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800325 return (access_flags & kAccClassIsProxy) != 0;
326 }
327
Mathieu Chartier4e305412014-02-19 10:54:44 -0800328 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700329 Primitive::Type GetPrimitiveType() ALWAYS_INLINE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800330
Ian Rogersef7d42f2014-01-06 12:55:46 -0800331 void SetPrimitiveType(Primitive::Type new_type) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800332 DCHECK_EQ(sizeof(Primitive::Type), sizeof(int32_t));
Hiroshi Yamauchif0edfc32014-09-25 11:46:46 -0700333 int32_t v32 = static_cast<int32_t>(new_type);
334 DCHECK_EQ(v32 & 0xFFFF, v32) << "upper 16 bits aren't zero";
335 // Store the component size shift in the upper 16 bits.
336 v32 |= Primitive::ComponentSizeShift(new_type) << 16;
337 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, primitive_type_), v32);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800338 }
339
Hiroshi Yamauchif0edfc32014-09-25 11:46:46 -0700340 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
341 size_t GetPrimitiveTypeSizeShift() ALWAYS_INLINE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
342
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800343 // Returns true if the class is a primitive type.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800344 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800345 bool IsPrimitive() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800346 return GetPrimitiveType<kVerifyFlags>() != Primitive::kPrimNot;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800347 }
348
Mathieu Chartier4e305412014-02-19 10:54:44 -0800349 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800350 bool IsPrimitiveBoolean() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800351 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimBoolean;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800352 }
353
Mathieu Chartier4e305412014-02-19 10:54:44 -0800354 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800355 bool IsPrimitiveByte() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800356 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimByte;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800357 }
358
Mathieu Chartier4e305412014-02-19 10:54:44 -0800359 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800360 bool IsPrimitiveChar() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800361 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimChar;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800362 }
363
Mathieu Chartier4e305412014-02-19 10:54:44 -0800364 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800365 bool IsPrimitiveShort() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800366 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimShort;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800367 }
368
Mathieu Chartier4e305412014-02-19 10:54:44 -0800369 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800370 bool IsPrimitiveInt() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800371 return GetPrimitiveType() == Primitive::kPrimInt;
372 }
373
Mathieu Chartier4e305412014-02-19 10:54:44 -0800374 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800375 bool IsPrimitiveLong() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800376 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimLong;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800377 }
378
Mathieu Chartier4e305412014-02-19 10:54:44 -0800379 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800380 bool IsPrimitiveFloat() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800381 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimFloat;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800382 }
383
Mathieu Chartier4e305412014-02-19 10:54:44 -0800384 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800385 bool IsPrimitiveDouble() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800386 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimDouble;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800387 }
388
Mathieu Chartier4e305412014-02-19 10:54:44 -0800389 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800390 bool IsPrimitiveVoid() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800391 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimVoid;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800392 }
393
Mathieu Chartier4e305412014-02-19 10:54:44 -0800394 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800395 bool IsPrimitiveArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800396 return IsArrayClass<kVerifyFlags>() &&
397 GetComponentType<static_cast<VerifyObjectFlags>(kVerifyFlags & ~kVerifyThis)>()->
398 IsPrimitive();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800399 }
400
401 // Depth of class from java.lang.Object
Mathieu Chartiere401d142015-04-22 13:56:20 -0700402 uint32_t Depth() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800403
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700404 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
405 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800406 bool IsArrayClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700407 return GetComponentType<kVerifyFlags, kReadBarrierOption>() != nullptr;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800408 }
409
Hiroshi Yamauchi25023c72014-05-09 11:45:53 -0700410 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
411 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800412 bool IsClassClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800413
Ian Rogersef7d42f2014-01-06 12:55:46 -0800414 bool IsThrowableClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800415
Hiroshi Yamauchi4f1ebc22014-06-25 14:30:41 -0700416 template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Fred Shih4ee7a662014-07-11 09:59:27 -0700417 bool IsReferenceClass() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
418
Ian Rogersa9a82542013-10-04 11:17:26 -0700419 static MemberOffset ComponentTypeOffset() {
420 return OFFSET_OF_OBJECT_MEMBER(Class, component_type_);
421 }
422
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700423 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
424 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800425 Class* GetComponentType() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700426 return GetFieldObject<Class, kVerifyFlags, kReadBarrierOption>(ComponentTypeOffset());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800427 }
428
429 void SetComponentType(Class* new_component_type) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700430 DCHECK(GetComponentType() == nullptr);
431 DCHECK(new_component_type != nullptr);
Sebastien Hertzee1d79a2014-02-21 15:46:30 +0100432 // Component type is invariant: use non-transactional mode without check.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700433 SetFieldObject<false, false>(ComponentTypeOffset(), new_component_type);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800434 }
435
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700436 template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800437 size_t GetComponentSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Hiroshi Yamauchif0edfc32014-09-25 11:46:46 -0700438 return 1U << GetComponentSizeShift();
439 }
440
441 template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
442 size_t GetComponentSizeShift() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
443 return GetComponentType<kDefaultVerifyFlags, kReadBarrierOption>()->GetPrimitiveTypeSizeShift();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800444 }
445
Ian Rogersef7d42f2014-01-06 12:55:46 -0800446 bool IsObjectClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700447 return !IsPrimitive() && GetSuperClass() == nullptr;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800448 }
Ian Rogers68d8b422014-07-17 11:09:10 -0700449
450 bool IsInstantiableNonArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
451 return !IsPrimitive() && !IsInterface() && !IsAbstract() && !IsArrayClass();
452 }
453
Ian Rogersef7d42f2014-01-06 12:55:46 -0800454 bool IsInstantiable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers68d8b422014-07-17 11:09:10 -0700455 return (!IsPrimitive() && !IsInterface() && !IsAbstract()) ||
Mathieu Chartiere401d142015-04-22 13:56:20 -0700456 (IsAbstract() && IsArrayClass());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800457 }
458
Mathieu Chartier4e305412014-02-19 10:54:44 -0800459 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800460 bool IsObjectArrayClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700461 return GetComponentType<kVerifyFlags>() != nullptr &&
462 !GetComponentType<kVerifyFlags>()->IsPrimitive();
463 }
464
465 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
466 bool IsIntArrayClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
467 constexpr auto kNewFlags = static_cast<VerifyObjectFlags>(kVerifyFlags & ~kVerifyThis);
468 auto* component_type = GetComponentType<kVerifyFlags>();
469 return component_type != nullptr && component_type->template IsPrimitiveInt<kNewFlags>();
470 }
471
472 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
473 bool IsLongArrayClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
474 constexpr auto kNewFlags = static_cast<VerifyObjectFlags>(kVerifyFlags & ~kVerifyThis);
475 auto* component_type = GetComponentType<kVerifyFlags>();
476 return component_type != nullptr && component_type->template IsPrimitiveLong<kNewFlags>();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800477 }
478
479 // Creates a raw object instance but does not invoke the default constructor.
Mathieu Chartier8668c3c2014-04-24 16:48:11 -0700480 template<bool kIsInstrumented, bool kCheckAddFinalizer = true>
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800481 ALWAYS_INLINE Object* Alloc(Thread* self, gc::AllocatorType allocator_type)
482 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -0700483
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800484 Object* AllocObject(Thread* self)
485 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
486 Object* AllocNonMovableObject(Thread* self)
487 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800488
Hiroshi Yamauchi25023c72014-05-09 11:45:53 -0700489 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
490 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800491 bool IsVariableSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Jeff Hao848f70a2014-01-15 13:49:50 -0800492 // Classes, arrays, and strings vary in size, and so the object_size_ field cannot
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700493 // be used to Get their instance size
Hiroshi Yamauchi25023c72014-05-09 11:45:53 -0700494 return IsClassClass<kVerifyFlags, kReadBarrierOption>() ||
Jeff Hao848f70a2014-01-15 13:49:50 -0800495 IsArrayClass<kVerifyFlags, kReadBarrierOption>() || IsStringClass();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800496 }
497
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700498 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
499 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800500 uint32_t SizeOf() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700501 return GetField32<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, class_size_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800502 }
503
Mathieu Chartier4e305412014-02-19 10:54:44 -0800504 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800505 uint32_t GetClassSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700506 return GetField32<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, class_size_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800507 }
508
Ian Rogersef7d42f2014-01-06 12:55:46 -0800509 void SetClassSize(uint32_t new_class_size)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800510 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
511
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700512 // Compute how many bytes would be used a class with the given elements.
513 static uint32_t ComputeClassSize(bool has_embedded_tables,
514 uint32_t num_vtable_entries,
Fred Shih37f05ef2014-07-16 18:38:08 -0700515 uint32_t num_8bit_static_fields,
516 uint32_t num_16bit_static_fields,
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700517 uint32_t num_32bit_static_fields,
518 uint32_t num_64bit_static_fields,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700519 uint32_t num_ref_static_fields,
520 size_t pointer_size);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700521
522 // The size of java.lang.Class.class.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700523 static uint32_t ClassClassSize(size_t pointer_size) {
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700524 // The number of vtable entries in java.lang.Class.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700525 uint32_t vtable_entries = Object::kVTableLength + 65;
526 return ComputeClassSize(true, vtable_entries, 0, 0, 0, 1, 0, pointer_size);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700527 }
528
529 // The size of a java.lang.Class representing a primitive such as int.class.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700530 static uint32_t PrimitiveClassSize(size_t pointer_size) {
531 return ComputeClassSize(false, 0, 0, 0, 0, 0, 0, pointer_size);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700532 }
533
Hiroshi Yamauchi25023c72014-05-09 11:45:53 -0700534 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
535 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800536 uint32_t GetObjectSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Hiroshi Yamauchie01a5202015-03-19 12:35:04 -0700537 static MemberOffset ObjectSizeOffset() {
538 return OFFSET_OF_OBJECT_MEMBER(Class, object_size_);
539 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800540
Ian Rogersef7d42f2014-01-06 12:55:46 -0800541 void SetObjectSize(uint32_t new_object_size) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800542 DCHECK(!IsVariableSize());
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100543 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700544 return SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, object_size_), new_object_size);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800545 }
546
Mathieu Chartier2d721012014-11-10 11:08:06 -0800547 void SetObjectSizeWithoutChecks(uint32_t new_object_size)
548 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
549 // Not called within a transaction.
550 return SetField32<false, false, kVerifyNone>(
551 OFFSET_OF_OBJECT_MEMBER(Class, object_size_), new_object_size);
552 }
553
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800554 // Returns true if this class is in the same packages as that class.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800555 bool IsInSamePackage(Class* that) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800556
557 static bool IsInSamePackage(const StringPiece& descriptor1, const StringPiece& descriptor2);
558
559 // Returns true if this class can access that class.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800560 bool CanAccess(Class* that) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800561 return that->IsPublic() || this->IsInSamePackage(that);
562 }
563
564 // Can this class access a member in the provided class with the provided member access flags?
565 // Note that access to the class isn't checked in case the declaring class is protected and the
566 // method has been exposed by a public sub-class
Ian Rogersef7d42f2014-01-06 12:55:46 -0800567 bool CanAccessMember(Class* access_to, uint32_t member_flags)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800568 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
569 // Classes can access all of their own members
570 if (this == access_to) {
571 return true;
572 }
573 // Public members are trivially accessible
574 if (member_flags & kAccPublic) {
575 return true;
576 }
577 // Private members are trivially not accessible
578 if (member_flags & kAccPrivate) {
579 return false;
580 }
581 // Check for protected access from a sub-class, which may or may not be in the same package.
582 if (member_flags & kAccProtected) {
Andreas Gampe13f8a162014-08-08 19:55:37 -0700583 if (!this->IsInterface() && this->IsSubClass(access_to)) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800584 return true;
585 }
586 }
587 // Allow protected access from other classes in the same package.
588 return this->IsInSamePackage(access_to);
589 }
590
Vladimir Marko23a28212014-01-09 19:24:37 +0000591 // Can this class access a resolved field?
592 // Note that access to field's class is checked and this may require looking up the class
593 // referenced by the FieldId in the DexFile in case the declaring class is inaccessible.
Vladimir Marko23a28212014-01-09 19:24:37 +0000594 bool CanAccessResolvedField(Class* access_to, ArtField* field,
Ian Rogersef7d42f2014-01-06 12:55:46 -0800595 DexCache* dex_cache, uint32_t field_idx)
Vladimir Marko89786432014-01-31 15:03:55 +0000596 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
597 bool CheckResolvedFieldAccess(Class* access_to, ArtField* field,
598 uint32_t field_idx)
599 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Vladimir Marko23a28212014-01-09 19:24:37 +0000600
601 // Can this class access a resolved method?
602 // Note that access to methods's class is checked and this may require looking up the class
603 // referenced by the MethodId in the DexFile in case the declaring class is inaccessible.
Vladimir Marko23a28212014-01-09 19:24:37 +0000604 bool CanAccessResolvedMethod(Class* access_to, ArtMethod* resolved_method,
Ian Rogersef7d42f2014-01-06 12:55:46 -0800605 DexCache* dex_cache, uint32_t method_idx)
Vladimir Marko89786432014-01-31 15:03:55 +0000606 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
607 template <InvokeType throw_invoke_type>
608 bool CheckResolvedMethodAccess(Class* access_to, ArtMethod* resolved_method,
609 uint32_t method_idx)
610 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Vladimir Marko23a28212014-01-09 19:24:37 +0000611
Ian Rogersef7d42f2014-01-06 12:55:46 -0800612 bool IsSubClass(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800613
614 // Can src be assigned to this class? For example, String can be assigned to Object (by an
615 // upcast), however, an Object cannot be assigned to a String as a potentially exception throwing
616 // downcast would be necessary. Similarly for interfaces, a class that implements (or an interface
617 // that extends) another can be assigned to its parent, but not vice-versa. All Classes may assign
618 // to themselves. Classes for primitive types may not assign to each other.
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700619 ALWAYS_INLINE bool IsAssignableFrom(Class* src) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700620 DCHECK(src != nullptr);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800621 if (this == src) {
622 // Can always assign to things of the same type.
623 return true;
624 } else if (IsObjectClass()) {
625 // Can assign any reference to java.lang.Object.
626 return !src->IsPrimitive();
627 } else if (IsInterface()) {
628 return src->Implements(this);
629 } else if (src->IsArrayClass()) {
630 return IsAssignableFromArray(src);
631 } else {
632 return !src->IsInterface() && src->IsSubClass(this);
633 }
634 }
635
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700636 ALWAYS_INLINE Class* GetSuperClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800637
638 void SetSuperClass(Class *new_super_class) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800639 // Super class is assigned once, except during class linker initialization.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700640 Class* old_super_class = GetFieldObject<Class>(OFFSET_OF_OBJECT_MEMBER(Class, super_class_));
Ian Rogersef7d42f2014-01-06 12:55:46 -0800641 DCHECK(old_super_class == nullptr || old_super_class == new_super_class);
642 DCHECK(new_super_class != nullptr);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700643 SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(Class, super_class_), new_super_class);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800644 }
645
Ian Rogersef7d42f2014-01-06 12:55:46 -0800646 bool HasSuperClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700647 return GetSuperClass() != nullptr;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800648 }
649
650 static MemberOffset SuperClassOffset() {
651 return MemberOffset(OFFSETOF_MEMBER(Class, super_class_));
652 }
653
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700654 ClassLoader* GetClassLoader() ALWAYS_INLINE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800655
656 void SetClassLoader(ClassLoader* new_cl) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
657
658 static MemberOffset DexCacheOffset() {
659 return MemberOffset(OFFSETOF_MEMBER(Class, dex_cache_));
660 }
661
662 enum {
663 kDumpClassFullDetail = 1,
664 kDumpClassClassLoader = (1 << 1),
665 kDumpClassInitialized = (1 << 2),
666 };
667
Ian Rogersef7d42f2014-01-06 12:55:46 -0800668 void DumpClass(std::ostream& os, int flags) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800669
Mathieu Chartierc2f4d022014-03-03 16:11:42 -0800670 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800671 DexCache* GetDexCache() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800672
Mathieu Chartier91a6dc42014-12-01 10:31:15 -0800673 // Also updates the dex_cache_strings_ variable from new_dex_cache.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800674 void SetDexCache(DexCache* new_dex_cache) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
675
Mathieu Chartiere401d142015-04-22 13:56:20 -0700676 ALWAYS_INLINE StrideIterator<ArtMethod> DirectMethodsBegin(size_t pointer_size)
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700677 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800678
Mathieu Chartiere401d142015-04-22 13:56:20 -0700679 ALWAYS_INLINE StrideIterator<ArtMethod> DirectMethodsEnd(size_t pointer_size)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800680 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
681
Mathieu Chartiere401d142015-04-22 13:56:20 -0700682 ALWAYS_INLINE IterationRange<StrideIterator<ArtMethod>> GetDirectMethods(size_t pointer_size)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800683 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
684
Mathieu Chartiere401d142015-04-22 13:56:20 -0700685 ArtMethod* GetDirectMethodsPtr() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);\
686
687 void SetDirectMethodsPtr(ArtMethod* new_direct_methods)
688 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
689 // Used by image writer.
690 void SetDirectMethodsPtrUnchecked(ArtMethod* new_direct_methods)
691 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
692
693 ALWAYS_INLINE ArtMethod* GetDirectMethod(size_t i, size_t pointer_size)
694 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
695
696 // Use only when we are allocating populating the method arrays.
697 ALWAYS_INLINE ArtMethod* GetDirectMethodUnchecked(size_t i, size_t pointer_size)
698 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
699 ALWAYS_INLINE ArtMethod* GetVirtualMethodUnchecked(size_t i, size_t pointer_size)
700 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
701
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800702 // Returns the number of static, private, and constructor methods.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700703 ALWAYS_INLINE uint32_t NumDirectMethods() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
704 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_direct_methods_));
705 }
706 void SetNumDirectMethods(uint32_t num) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
707 return SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, num_direct_methods_), num);
708 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800709
Mathieu Chartier4e305412014-02-19 10:54:44 -0800710 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartiere401d142015-04-22 13:56:20 -0700711 ALWAYS_INLINE ArtMethod* GetVirtualMethodsPtr() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
712
713 ALWAYS_INLINE StrideIterator<ArtMethod> VirtualMethodsBegin(size_t pointer_size)
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700714 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800715
Mathieu Chartiere401d142015-04-22 13:56:20 -0700716 ALWAYS_INLINE StrideIterator<ArtMethod> VirtualMethodsEnd(size_t pointer_size)
717 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
718
719 ALWAYS_INLINE IterationRange<StrideIterator<ArtMethod>> GetVirtualMethods(size_t pointer_size)
720 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
721
722 void SetVirtualMethodsPtr(ArtMethod* new_virtual_methods)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800723 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
724
725 // Returns the number of non-inherited virtual methods.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700726 ALWAYS_INLINE uint32_t NumVirtualMethods() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
727 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_virtual_methods_));
728 }
729 void SetNumVirtualMethods(uint32_t num) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
730 return SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, num_virtual_methods_), num);
731 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800732
Mathieu Chartier4e305412014-02-19 10:54:44 -0800733 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartiere401d142015-04-22 13:56:20 -0700734 ArtMethod* GetVirtualMethod(size_t i, size_t pointer_size)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800735 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
736
Mathieu Chartiere401d142015-04-22 13:56:20 -0700737 ArtMethod* GetVirtualMethodDuringLinking(size_t i, size_t pointer_size)
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700738 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800739
Mathieu Chartiere401d142015-04-22 13:56:20 -0700740 ALWAYS_INLINE PointerArray* GetVTable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
741
742 ALWAYS_INLINE PointerArray* GetVTableDuringLinking() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
743
744 void SetVTable(PointerArray* new_vtable) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800745
746 static MemberOffset VTableOffset() {
747 return OFFSET_OF_OBJECT_MEMBER(Class, vtable_);
748 }
749
Mingyao Yang2cdbad72014-07-16 10:44:41 -0700750 static MemberOffset EmbeddedVTableLengthOffset() {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700751 return MemberOffset(sizeof(Class));
Mingyao Yang2cdbad72014-07-16 10:44:41 -0700752 }
753
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700754 bool ShouldHaveEmbeddedImtAndVTable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
755 return IsInstantiable();
756 }
757
Mingyao Yang2cdbad72014-07-16 10:44:41 -0700758 bool HasVTable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
759
Mathieu Chartiere401d142015-04-22 13:56:20 -0700760 static MemberOffset EmbeddedImTableEntryOffset(uint32_t i, size_t pointer_size);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700761
Mathieu Chartiere401d142015-04-22 13:56:20 -0700762 static MemberOffset EmbeddedVTableEntryOffset(uint32_t i, size_t pointer_size);
763
764 ArtMethod* GetEmbeddedImTableEntry(uint32_t i, size_t pointer_size)
765 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
766
767 void SetEmbeddedImTableEntry(uint32_t i, ArtMethod* method, size_t pointer_size)
768 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700769
Mingyao Yang2cdbad72014-07-16 10:44:41 -0700770 int32_t GetVTableLength() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
771
Mathieu Chartiere401d142015-04-22 13:56:20 -0700772 ArtMethod* GetVTableEntry(uint32_t i, size_t pointer_size)
773 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang2cdbad72014-07-16 10:44:41 -0700774
775 int32_t GetEmbeddedVTableLength() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
776
777 void SetEmbeddedVTableLength(int32_t len) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
778
Mathieu Chartiere401d142015-04-22 13:56:20 -0700779 ArtMethod* GetEmbeddedVTableEntry(uint32_t i, size_t pointer_size)
780 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang2cdbad72014-07-16 10:44:41 -0700781
Mathieu Chartiere401d142015-04-22 13:56:20 -0700782 void SetEmbeddedVTableEntry(uint32_t i, ArtMethod* method, size_t pointer_size)
783 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700784
Mathieu Chartiere401d142015-04-22 13:56:20 -0700785 inline void SetEmbeddedVTableEntryUnchecked(uint32_t i, ArtMethod* method, size_t pointer_size)
786 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
787
788 void PopulateEmbeddedImtAndVTable(ArtMethod* const (&methods)[kImtSize], size_t pointer_size)
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700789 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700790
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800791 // Given a method implemented by this class but potentially from a super class, return the
792 // specific implementation method for this class.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700793 ArtMethod* FindVirtualMethodForVirtual(ArtMethod* method, size_t pointer_size)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800794 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
795
796 // Given a method implemented by this class' super class, return the specific implementation
797 // method for this class.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700798 ArtMethod* FindVirtualMethodForSuper(ArtMethod* method, size_t pointer_size)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800799 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
800
801 // Given a method implemented by this class, but potentially from a
802 // super class or interface, return the specific implementation
803 // method for this class.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700804 ArtMethod* FindVirtualMethodForInterface(ArtMethod* method, size_t pointer_size)
Ian Rogers1ffa32f2013-02-05 18:29:08 -0800805 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) ALWAYS_INLINE;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800806
Mathieu Chartiere401d142015-04-22 13:56:20 -0700807 ArtMethod* FindVirtualMethodForVirtualOrInterface(ArtMethod* method, size_t pointer_size)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700808 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
809
Mathieu Chartiere401d142015-04-22 13:56:20 -0700810 ArtMethod* FindInterfaceMethod(const StringPiece& name, const StringPiece& signature,
811 size_t pointer_size)
Brian Carlstrom004644f2014-06-18 08:34:01 -0700812 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
813
Mathieu Chartiere401d142015-04-22 13:56:20 -0700814 ArtMethod* FindInterfaceMethod(const StringPiece& name, const Signature& signature,
815 size_t pointer_size)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800816 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
817
Mathieu Chartiere401d142015-04-22 13:56:20 -0700818 ArtMethod* FindInterfaceMethod(const DexCache* dex_cache, uint32_t dex_method_idx,
819 size_t pointer_size)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800820 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
821
Mathieu Chartiere401d142015-04-22 13:56:20 -0700822 ArtMethod* FindDeclaredDirectMethod(const StringPiece& name, const StringPiece& signature,
823 size_t pointer_size)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800824 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
825
Mathieu Chartiere401d142015-04-22 13:56:20 -0700826 ArtMethod* FindDeclaredDirectMethod(const StringPiece& name, const Signature& signature,
827 size_t pointer_size)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700828 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
829
Mathieu Chartiere401d142015-04-22 13:56:20 -0700830 ArtMethod* FindDeclaredDirectMethod(const DexCache* dex_cache, uint32_t dex_method_idx,
831 size_t pointer_size)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800832 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
833
Mathieu Chartiere401d142015-04-22 13:56:20 -0700834 ArtMethod* FindDirectMethod(const StringPiece& name, const StringPiece& signature,
835 size_t pointer_size)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800836 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
837
Mathieu Chartiere401d142015-04-22 13:56:20 -0700838 ArtMethod* FindDirectMethod(const StringPiece& name, const Signature& signature,
839 size_t pointer_size)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700840 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
841
Mathieu Chartiere401d142015-04-22 13:56:20 -0700842 ArtMethod* FindDirectMethod(const DexCache* dex_cache, uint32_t dex_method_idx,
843 size_t pointer_size)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800844 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
845
Mathieu Chartiere401d142015-04-22 13:56:20 -0700846 ArtMethod* FindDeclaredVirtualMethod(const StringPiece& name, const StringPiece& signature,
847 size_t pointer_size)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700848 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
849
Mathieu Chartiere401d142015-04-22 13:56:20 -0700850 ArtMethod* FindDeclaredVirtualMethod(const StringPiece& name, const Signature& signature,
851 size_t pointer_size)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700852 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
853
Mathieu Chartiere401d142015-04-22 13:56:20 -0700854 ArtMethod* FindDeclaredVirtualMethod(const DexCache* dex_cache, uint32_t dex_method_idx,
855 size_t pointer_size)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700856 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
857
Mathieu Chartiere401d142015-04-22 13:56:20 -0700858 ArtMethod* FindVirtualMethod(const StringPiece& name, const StringPiece& signature,
859 size_t pointer_size)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700860 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
861
Mathieu Chartiere401d142015-04-22 13:56:20 -0700862 ArtMethod* FindVirtualMethod(const StringPiece& name, const Signature& signature,
863 size_t pointer_size)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700864 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
865
Mathieu Chartiere401d142015-04-22 13:56:20 -0700866 ArtMethod* FindVirtualMethod(const DexCache* dex_cache, uint32_t dex_method_idx,
867 size_t pointer_size)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700868 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
869
Mathieu Chartiere401d142015-04-22 13:56:20 -0700870 ArtMethod* FindClassInitializer(size_t pointer_size) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersd91d6d62013-09-25 20:26:14 -0700871
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700872 ALWAYS_INLINE int32_t GetIfTableCount() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800873
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700874 ALWAYS_INLINE IfTable* GetIfTable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800875
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700876 ALWAYS_INLINE void SetIfTable(IfTable* new_iftable) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800877
878 // Get instance fields of the class (See also GetSFields).
Mathieu Chartierc7853442015-03-27 14:35:38 -0700879 ArtField* GetIFields() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800880
Mathieu Chartierc7853442015-03-27 14:35:38 -0700881 void SetIFields(ArtField* new_ifields) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800882
Mathieu Chartierc7853442015-03-27 14:35:38 -0700883 // Unchecked edition has no verification flags.
884 void SetIFieldsUnchecked(ArtField* new_sfields) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800885
Mathieu Chartierc7853442015-03-27 14:35:38 -0700886 uint32_t NumInstanceFields() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
887 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_instance_fields_));
888 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800889
Mathieu Chartierc7853442015-03-27 14:35:38 -0700890 void SetNumInstanceFields(uint32_t num) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
891 return SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, num_instance_fields_), num);
892 }
893
894 ArtField* GetInstanceField(uint32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800895
896 // Returns the number of instance fields containing reference types.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800897 uint32_t NumReferenceInstanceFields() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800898 DCHECK(IsResolved() || IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700899 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_instance_fields_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800900 }
901
Ian Rogersef7d42f2014-01-06 12:55:46 -0800902 uint32_t NumReferenceInstanceFieldsDuringLinking() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800903 DCHECK(IsLoaded() || IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700904 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_instance_fields_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800905 }
906
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700907 void SetNumReferenceInstanceFields(uint32_t new_num) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100908 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700909 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_instance_fields_), new_num);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800910 }
911
Mathieu Chartier4e305412014-02-19 10:54:44 -0800912 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700913 uint32_t GetReferenceInstanceOffsets() ALWAYS_INLINE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800914
915 void SetReferenceInstanceOffsets(uint32_t new_reference_offsets)
916 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
917
Vladimir Marko76649e82014-11-10 18:32:59 +0000918 // Get the offset of the first reference instance field. Other reference instance fields follow.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700919 MemberOffset GetFirstReferenceInstanceFieldOffset()
920 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Vladimir Marko76649e82014-11-10 18:32:59 +0000921
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800922 // Returns the number of static fields containing reference types.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800923 uint32_t NumReferenceStaticFields() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700924 DCHECK(IsResolved() || IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700925 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_static_fields_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800926 }
927
Ian Rogersef7d42f2014-01-06 12:55:46 -0800928 uint32_t NumReferenceStaticFieldsDuringLinking() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700929 DCHECK(IsLoaded() || IsErroneous() || IsRetired());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700930 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_static_fields_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800931 }
932
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700933 void SetNumReferenceStaticFields(uint32_t new_num) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100934 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700935 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_static_fields_), new_num);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800936 }
937
Vladimir Marko76649e82014-11-10 18:32:59 +0000938 // Get the offset of the first reference static field. Other reference static fields follow.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700939 MemberOffset GetFirstReferenceStaticFieldOffset(size_t pointer_size)
940 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Vladimir Marko76649e82014-11-10 18:32:59 +0000941
942 // Get the offset of the first reference static field. Other reference static fields follow.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700943 MemberOffset GetFirstReferenceStaticFieldOffsetDuringLinking(size_t pointer_size)
Vladimir Marko76649e82014-11-10 18:32:59 +0000944 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
945
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800946 // Gets the static fields of the class.
Mathieu Chartierc7853442015-03-27 14:35:38 -0700947 ArtField* GetSFields() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800948
Mathieu Chartierc7853442015-03-27 14:35:38 -0700949 void SetSFields(ArtField* new_sfields) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800950
Mathieu Chartierc7853442015-03-27 14:35:38 -0700951 // Unchecked edition has no verification flags.
952 void SetSFieldsUnchecked(ArtField* new_sfields) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
953
954 uint32_t NumStaticFields() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
955 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_static_fields_));
956 }
957
958 void SetNumStaticFields(uint32_t num) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
959 return SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, num_static_fields_), num);
960 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800961
Ian Rogersef7d42f2014-01-06 12:55:46 -0800962 // TODO: uint16_t
963 ArtField* GetStaticField(uint32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800964
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800965 // Find a static or instance field using the JLS resolution order
Mathieu Chartierf8322842014-05-16 10:59:25 -0700966 static ArtField* FindField(Thread* self, Handle<Class> klass, const StringPiece& name,
967 const StringPiece& type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800968 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
969
970 // Finds the given instance field in this class or a superclass.
Brian Carlstromea46f952013-07-30 01:26:50 -0700971 ArtField* FindInstanceField(const StringPiece& name, const StringPiece& type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800972 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
973
974 // Finds the given instance field in this class or a superclass, only searches classes that
975 // have the same dex cache.
Brian Carlstromea46f952013-07-30 01:26:50 -0700976 ArtField* FindInstanceField(const DexCache* dex_cache, uint32_t dex_field_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800977 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
978
Brian Carlstromea46f952013-07-30 01:26:50 -0700979 ArtField* FindDeclaredInstanceField(const StringPiece& name, const StringPiece& type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800980 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
981
Brian Carlstromea46f952013-07-30 01:26:50 -0700982 ArtField* FindDeclaredInstanceField(const DexCache* dex_cache, uint32_t dex_field_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800983 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
984
985 // Finds the given static field in this class or a superclass.
Mathieu Chartierf8322842014-05-16 10:59:25 -0700986 static ArtField* FindStaticField(Thread* self, Handle<Class> klass, const StringPiece& name,
987 const StringPiece& type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800988 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
989
990 // Finds the given static field in this class or superclass, only searches classes that
991 // have the same dex cache.
Mathieu Chartierf8322842014-05-16 10:59:25 -0700992 static ArtField* FindStaticField(Thread* self, Handle<Class> klass, const DexCache* dex_cache,
993 uint32_t dex_field_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800994 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
995
Brian Carlstromea46f952013-07-30 01:26:50 -0700996 ArtField* FindDeclaredStaticField(const StringPiece& name, const StringPiece& type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800997 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
998
Brian Carlstromea46f952013-07-30 01:26:50 -0700999 ArtField* FindDeclaredStaticField(const DexCache* dex_cache, uint32_t dex_field_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001000 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1001
Ian Rogersef7d42f2014-01-06 12:55:46 -08001002 pid_t GetClinitThreadId() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001003 DCHECK(IsIdxLoaded() || IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -07001004 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, clinit_thread_id_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001005 }
1006
Ian Rogersb0fa5dc2014-04-28 16:47:08 -07001007 void SetClinitThreadId(pid_t new_clinit_thread_id) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001008
Ian Rogersef7d42f2014-01-06 12:55:46 -08001009 Class* GetVerifyErrorClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001010 // DCHECK(IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -07001011 return GetFieldObject<Class>(OFFSET_OF_OBJECT_MEMBER(Class, verify_error_class_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001012 }
1013
Ian Rogersef7d42f2014-01-06 12:55:46 -08001014 uint16_t GetDexClassDefIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -07001015 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, dex_class_def_idx_));
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001016 }
1017
Ian Rogersef7d42f2014-01-06 12:55:46 -08001018 void SetDexClassDefIndex(uint16_t class_def_idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +01001019 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -07001020 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, dex_class_def_idx_), class_def_idx);
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001021 }
1022
Ian Rogersef7d42f2014-01-06 12:55:46 -08001023 uint16_t GetDexTypeIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -07001024 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, dex_type_idx_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001025 }
1026
Ian Rogersef7d42f2014-01-06 12:55:46 -08001027 void SetDexTypeIndex(uint16_t type_idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +01001028 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -07001029 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, dex_type_idx_), type_idx);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001030 }
1031
Hiroshi Yamauchi4f1ebc22014-06-25 14:30:41 -07001032 static Class* GetJavaLangClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -07001033 DCHECK(!java_lang_Class_.IsNull());
1034 return java_lang_Class_.Read();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001035 }
1036
1037 // Can't call this SetClass or else gets called instead of Object::SetClass in places.
Hiroshi Yamauchi4f1ebc22014-06-25 14:30:41 -07001038 static void SetClassClass(Class* java_lang_Class) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001039 static void ResetClass();
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -07001040 static void VisitRoots(RootVisitor* visitor)
Mathieu Chartierc528dba2013-11-26 12:00:11 -08001041 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001042
Mathieu Chartiere401d142015-04-22 13:56:20 -07001043 // Visit native roots visits roots which are keyed off the native pointers such as ArtFields and
1044 // ArtMethods.
Mathieu Chartierc7853442015-03-27 14:35:38 -07001045 template<class Visitor>
Mathieu Chartiere401d142015-04-22 13:56:20 -07001046 void VisitNativeRoots(Visitor& visitor, size_t pointer_size)
1047 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartierc7853442015-03-27 14:35:38 -07001048
Sebastien Hertz233ea8e2013-06-06 11:57:09 +02001049 // When class is verified, set the kAccPreverified flag on each method.
Mathieu Chartiere401d142015-04-22 13:56:20 -07001050 void SetPreverifiedFlagOnAllMethods(size_t pointer_size)
1051 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz233ea8e2013-06-06 11:57:09 +02001052
Mathieu Chartier407f7022014-02-18 14:37:05 -08001053 template <bool kVisitClass, typename Visitor>
1054 void VisitReferences(mirror::Class* klass, const Visitor& visitor)
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001055 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1056
Ian Rogers1ff3c982014-08-12 02:30:58 -07001057 // Get the descriptor of the class. In a few cases a std::string is required, rather than
1058 // always create one the storage argument is populated and its internal c_str() returned. We do
1059 // this to avoid memory allocation in the common case.
1060 const char* GetDescriptor(std::string* storage) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1061
1062 const char* GetArrayDescriptor(std::string* storage) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001063
Mathieu Chartierf8322842014-05-16 10:59:25 -07001064 bool DescriptorEquals(const char* match) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001065
Mathieu Chartierf8322842014-05-16 10:59:25 -07001066 const DexFile::ClassDef* GetClassDef() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001067
Mathieu Chartier2d2621a2014-10-23 16:48:06 -07001068 ALWAYS_INLINE uint32_t NumDirectInterfaces() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001069
Mathieu Chartierf8322842014-05-16 10:59:25 -07001070 uint16_t GetDirectInterfaceTypeIdx(uint32_t idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001071
Andreas Gampe5a4b8a22014-09-11 08:30:08 -07001072 static mirror::Class* GetDirectInterface(Thread* self, Handle<mirror::Class> klass,
Mathieu Chartierbf99f772014-08-23 16:37:27 -07001073 uint32_t idx)
Mathieu Chartierf8322842014-05-16 10:59:25 -07001074 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001075
Mathieu Chartierf8322842014-05-16 10:59:25 -07001076 const char* GetSourceFile() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001077
Mathieu Chartierf8322842014-05-16 10:59:25 -07001078 std::string GetLocation() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001079
Mathieu Chartierf8322842014-05-16 10:59:25 -07001080 const DexFile& GetDexFile() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001081
Mathieu Chartierf8322842014-05-16 10:59:25 -07001082 const DexFile::TypeList* GetInterfaceTypeList() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1083
Sebastien Hertz4e99b3d2014-06-24 14:35:40 +02001084 // Asserts we are initialized or initializing in the given thread.
1085 void AssertInitializedOrInitializingInThread(Thread* self)
1086 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1087
Mathieu Chartiere401d142015-04-22 13:56:20 -07001088 Class* CopyOf(Thread* self, int32_t new_length, ArtMethod* const (&imt)[mirror::Class::kImtSize],
1089 size_t pointer_size) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001090
1091 // For proxy class only.
1092 ObjectArray<Class>* GetInterfaces() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1093
1094 // For proxy class only.
1095 ObjectArray<ObjectArray<Class>>* GetThrows() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1096
Fred Shih4ee7a662014-07-11 09:59:27 -07001097 // For reference class only.
1098 MemberOffset GetDisableIntrinsicFlagOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1099 MemberOffset GetSlowPathFlagOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1100 bool GetSlowPathEnabled() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1101 void SetSlowPath(bool enabled) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1102
Mathieu Chartiereace4582014-11-24 18:29:54 -08001103 ObjectArray<String>* GetDexCacheStrings() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1104 void SetDexCacheStrings(ObjectArray<String>* new_dex_cache_strings)
1105 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1106 static MemberOffset DexCacheStringsOffset() {
1107 return OFFSET_OF_OBJECT_MEMBER(Class, dex_cache_strings_);
1108 }
1109
Mathieu Chartierfc58af42015-04-16 18:00:39 -07001110 // May cause thread suspension due to EqualParameters.
Mathieu Chartiere401d142015-04-22 13:56:20 -07001111 ArtMethod* GetDeclaredConstructor(
Mathieu Chartierfc58af42015-04-16 18:00:39 -07001112 Thread* self, Handle<mirror::ObjectArray<mirror::Class>> args)
1113 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1114
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001115 // Used to initialize a class in the allocation code path to ensure it is guarded by a StoreStore
1116 // fence.
1117 class InitializeClassVisitor {
1118 public:
1119 explicit InitializeClassVisitor(uint32_t class_size) : class_size_(class_size) {
1120 }
1121
1122 void operator()(mirror::Object* obj, size_t usable_size) const
1123 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1124
1125 private:
1126 const uint32_t class_size_;
1127
1128 DISALLOW_COPY_AND_ASSIGN(InitializeClassVisitor);
1129 };
1130
Sebastien Hertz6963e442014-11-26 22:11:27 +01001131 // Returns true if the class loader is null, ie the class loader is the boot strap class loader.
1132 bool IsBootStrapClassLoaded() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
1133 return GetClassLoader() == nullptr;
1134 }
1135
Mathieu Chartiere401d142015-04-22 13:56:20 -07001136 static size_t ImTableEntrySize(size_t pointer_size) {
1137 return pointer_size;
1138 }
1139
1140 static size_t VTableEntrySize(size_t pointer_size) {
1141 return pointer_size;
1142 }
1143
1144 ALWAYS_INLINE ArtMethod* GetDirectMethodsPtrUnchecked()
1145 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1146
1147 ALWAYS_INLINE ArtMethod* GetVirtualMethodsPtrUnchecked()
1148 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1149
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001150 private:
1151 void SetVerifyErrorClass(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1152
Vladimir Marko89786432014-01-31 15:03:55 +00001153 template <bool throw_on_failure, bool use_referrers_cache>
1154 bool ResolvedFieldAccessTest(Class* access_to, ArtField* field,
Ian Rogersef7d42f2014-01-06 12:55:46 -08001155 uint32_t field_idx, DexCache* dex_cache)
Vladimir Marko89786432014-01-31 15:03:55 +00001156 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1157 template <bool throw_on_failure, bool use_referrers_cache, InvokeType throw_invoke_type>
1158 bool ResolvedMethodAccessTest(Class* access_to, ArtMethod* resolved_method,
Ian Rogersef7d42f2014-01-06 12:55:46 -08001159 uint32_t method_idx, DexCache* dex_cache)
Vladimir Marko89786432014-01-31 15:03:55 +00001160 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1161
Ian Rogersef7d42f2014-01-06 12:55:46 -08001162 bool Implements(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1163 bool IsArrayAssignableFromArray(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1164 bool IsAssignableFromArray(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001165
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -07001166 void CheckObjectAlloc() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1167
Mathieu Chartierc7853442015-03-27 14:35:38 -07001168 // Unchecked editions is for root visiting.
1169 ArtField* GetSFieldsUnchecked() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1170 ArtField* GetIFieldsUnchecked() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1171
Vladimir Marko3481ba22015-04-13 12:22:36 +01001172 bool ProxyDescriptorEquals(const char* match) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1173
Mathieu Chartiere401d142015-04-22 13:56:20 -07001174 // Check that the pointer size mathces the one in the class linker.
1175 ALWAYS_INLINE static void CheckPointerSize(size_t pointer_size);
1176
1177 static MemberOffset EmbeddedImTableOffset(size_t pointer_size);
1178 static MemberOffset EmbeddedVTableOffset(size_t pointer_size);
1179
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001180 // Defining class loader, or null for the "bootstrap" system loader.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001181 HeapReference<ClassLoader> class_loader_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001182
1183 // For array classes, the component class object for instanceof/checkcast
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001184 // (for String[][][], this will be String[][]). null for non-array classes.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001185 HeapReference<Class> component_type_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001186
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001187 // DexCache of resolved constant pool entries (will be null for classes generated by the
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001188 // runtime such as arrays and primitive classes).
Ian Rogersef7d42f2014-01-06 12:55:46 -08001189 HeapReference<DexCache> dex_cache_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001190
Mathieu Chartiereace4582014-11-24 18:29:54 -08001191 // Short cuts to dex_cache_ member for fast compiled code access.
1192 HeapReference<ObjectArray<String>> dex_cache_strings_;
1193
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001194 // The interface table (iftable_) contains pairs of a interface class and an array of the
1195 // interface methods. There is one pair per interface supported by this class. That means one
1196 // pair for each interface we support directly, indirectly via superclass, or indirectly via a
1197 // superinterface. This will be null if neither we nor our superclass implement any interfaces.
1198 //
1199 // Why we need this: given "class Foo implements Face", declare "Face faceObj = new Foo()".
1200 // Invoke faceObj.blah(), where "blah" is part of the Face interface. We can't easily use a
1201 // single vtable.
1202 //
1203 // For every interface a concrete class implements, we create an array of the concrete vtable_
1204 // methods for the methods in the interface.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001205 HeapReference<IfTable> iftable_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001206
Ian Rogersef7d42f2014-01-06 12:55:46 -08001207 // Descriptor for the class such as "java.lang.Class" or "[C". Lazily initialized by ComputeName
1208 HeapReference<String> name_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001209
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001210 // The superclass, or null if this is java.lang.Object, an interface or primitive type.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001211 HeapReference<Class> super_class_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001212
1213 // If class verify fails, we must return same error on subsequent tries.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001214 HeapReference<Class> verify_error_class_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001215
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001216 // Virtual method table (vtable), for use by "invoke-virtual". The vtable from the superclass is
1217 // copied in, and virtual methods from our class either replace those from the super or are
1218 // appended. For abstract classes, methods may be created in the vtable that aren't in
1219 // virtual_ methods_ for miranda methods.
Mathieu Chartiere401d142015-04-22 13:56:20 -07001220 HeapReference<PointerArray> vtable_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001221
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001222 // Access flags; low 16 bits are defined by VM spec.
Mathieu Chartierc7853442015-03-27 14:35:38 -07001223 // Note: Shuffled back.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001224 uint32_t access_flags_;
1225
Mathieu Chartiere401d142015-04-22 13:56:20 -07001226 // static, private, and <init> methods. Pointer to an ArtMethod array.
1227 uint64_t direct_methods_;
1228
Mathieu Chartierc7853442015-03-27 14:35:38 -07001229 // instance fields
1230 //
1231 // These describe the layout of the contents of an Object.
1232 // Note that only the fields directly declared by this class are
1233 // listed in ifields; fields declared by a superclass are listed in
1234 // the superclass's Class.ifields.
1235 //
1236 // ArtField arrays are allocated as an array of fields, and not an array of fields pointers.
1237 uint64_t ifields_;
1238
1239 // Static fields
1240 uint64_t sfields_;
1241
Mathieu Chartiere401d142015-04-22 13:56:20 -07001242 // Virtual methods defined in this class; invoked through vtable. Pointer to an ArtMethod array.
1243 uint64_t virtual_methods_;
1244
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001245 // Total size of the Class instance; used when allocating storage on gc heap.
1246 // See also object_size_.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001247 uint32_t class_size_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001248
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001249 // Tid used to check for recursive <clinit> invocation.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001250 pid_t clinit_thread_id_;
1251
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001252 // ClassDef index in dex file, -1 if no class definition such as an array.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001253 // TODO: really 16bits
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001254 int32_t dex_class_def_idx_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001255
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001256 // Type index in dex file.
1257 // TODO: really 16bits
1258 int32_t dex_type_idx_;
1259
Mathieu Chartiere401d142015-04-22 13:56:20 -07001260 // Number of direct fields.
1261 uint32_t num_direct_methods_;
1262
1263 // Number of instance fields.
Mathieu Chartierc7853442015-03-27 14:35:38 -07001264 uint32_t num_instance_fields_;
1265
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001266 // Number of instance fields that are object refs.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001267 uint32_t num_reference_instance_fields_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001268
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001269 // Number of static fields that are object refs,
Ian Rogersef7d42f2014-01-06 12:55:46 -08001270 uint32_t num_reference_static_fields_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001271
Mathieu Chartierc7853442015-03-27 14:35:38 -07001272 // Number of static fields.
1273 uint32_t num_static_fields_;
1274
Mathieu Chartiere401d142015-04-22 13:56:20 -07001275 // Number of virtual methods.
1276 uint32_t num_virtual_methods_;
1277
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001278 // Total object size; used when allocating storage on gc heap.
1279 // (For interfaces and abstract classes this will be zero.)
1280 // See also class_size_.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001281 uint32_t object_size_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001282
Hiroshi Yamauchif0edfc32014-09-25 11:46:46 -07001283 // The lower 16 bits contains a Primitive::Type value. The upper 16
1284 // bits contains the size shift of the primitive type.
1285 uint32_t primitive_type_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001286
1287 // Bitmap of offsets of ifields.
1288 uint32_t reference_instance_offsets_;
1289
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001290 // State of class initialization.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001291 Status status_;
1292
1293 // TODO: ?
1294 // initiating class loader list
1295 // NOTE: for classes with low serialNumber, these are unused, and the
1296 // values are kept in a table in gDvm.
1297 // InitiatingLoaderList initiating_loader_list_;
1298
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001299 // The following data exist in real class objects.
1300 // Embedded Imtable, for class object that's not an interface, fixed size.
Ian Rogers03b6eaf2014-10-28 09:34:57 -07001301 // ImTableEntry embedded_imtable_[0];
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001302 // Embedded Vtable, for class object that's not an interface, variable size.
Ian Rogers03b6eaf2014-10-28 09:34:57 -07001303 // VTableEntry embedded_vtable_[0];
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001304 // Static fields, variable size.
Ian Rogers03b6eaf2014-10-28 09:34:57 -07001305 // uint32_t fields_[0];
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001306
1307 // java.lang.Class
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -07001308 static GcRoot<Class> java_lang_Class_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001309
1310 friend struct art::ClassOffsets; // for verifying offset information
1311 DISALLOW_IMPLICIT_CONSTRUCTORS(Class);
1312};
1313
1314std::ostream& operator<<(std::ostream& os, const Class::Status& rhs);
1315
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001316} // namespace mirror
1317} // namespace art
1318
Brian Carlstromfc0e3212013-07-17 14:40:12 -07001319#endif // ART_RUNTIME_MIRROR_CLASS_H_