blob: bd497547319150d4ea8872efd5ac6a474a79fe5c [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 Chartierf8322842014-05-16 10:59:25 -070020#include "dex_file.h"
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -070021#include "gc_root.h"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070022#include "gc/allocator_type.h"
Vladimir Marko23a28212014-01-09 19:24:37 +000023#include "invoke_type.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080024#include "modifiers.h"
25#include "object.h"
Mingyao Yang98d1cc82014-05-15 17:02:16 -070026#include "object_array.h"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070027#include "object_callbacks.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080028#include "primitive.h"
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -070029#include "read_barrier_option.h"
Hiroshi Yamauchif4c15a12014-10-20 16:56:58 -070030#include "utils.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080031
Mathieu Chartiercd195fe2014-11-25 18:36:01 -080032#ifndef IMT_SIZE
33#error IMT_SIZE not defined
34#endif
35
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080036namespace art {
37
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080038struct ClassOffsets;
Andreas Gampe5a4b8a22014-09-11 08:30:08 -070039template<class T> class Handle;
Mathieu Chartierbf99f772014-08-23 16:37:27 -070040template<class T> class Handle;
Ian Rogersd91d6d62013-09-25 20:26:14 -070041class Signature;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080042class StringPiece;
Mathieu Chartier2d2621a2014-10-23 16:48:06 -070043template<size_t kNumReferences> class PACKED(4) StackHandleScope;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080044
45namespace mirror {
46
Brian Carlstromea46f952013-07-30 01:26:50 -070047class ArtField;
Mingyao Yang98d1cc82014-05-15 17:02:16 -070048class ArtMethod;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080049class ClassLoader;
50class DexCache;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080051class IfTable;
52
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080053// C++ mirror of java.lang.Class
Mingyao Yang98d1cc82014-05-15 17:02:16 -070054class MANAGED Class FINAL : public Object {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080055 public:
Ian Rogerscdc1aaf2014-10-09 13:21:38 -070056 // A magic value for reference_instance_offsets_. Ignore the bits and walk the super chain when
57 // this is the value.
58 // [This is an unlikely "natural" value, since it would be 30 non-ref instance fields followed by
59 // 2 ref instance fields.]
60 static constexpr uint32_t kClassWalkSuper = 0xC0000000;
61
Mingyao Yang98d1cc82014-05-15 17:02:16 -070062 // Interface method table size. Increasing this value reduces the chance of two interface methods
63 // colliding in the interface method table but increases the size of classes that implement
64 // (non-marker) interfaces.
Mathieu Chartiercd195fe2014-11-25 18:36:01 -080065 static constexpr size_t kImtSize = IMT_SIZE;
Mingyao Yang98d1cc82014-05-15 17:02:16 -070066
67 // imtable entry embedded in class object.
68 struct MANAGED ImTableEntry {
69 HeapReference<ArtMethod> method;
70 };
71
72 // vtable entry embedded in class object.
73 struct MANAGED VTableEntry {
74 HeapReference<ArtMethod> method;
75 };
76
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080077 // Class Status
78 //
Mingyao Yang46f0e972014-09-10 15:16:19 -070079 // kStatusRetired: Class that's temporarily used till class linking time
80 // has its (vtable) size figured out and has been cloned to one with the
81 // right size which will be the one used later. The old one is retired and
82 // will be gc'ed once all refs to the class point to the newly
83 // cloned version.
84 //
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080085 // kStatusNotReady: If a Class cannot be found in the class table by
86 // FindClass, it allocates an new one with AllocClass in the
87 // kStatusNotReady and calls LoadClass. Note if it does find a
88 // class, it may not be kStatusResolved and it will try to push it
89 // forward toward kStatusResolved.
90 //
91 // kStatusIdx: LoadClass populates with Class with information from
92 // the DexFile, moving the status to kStatusIdx, indicating that the
93 // Class value in super_class_ has not been populated. The new Class
94 // can then be inserted into the classes table.
95 //
96 // kStatusLoaded: After taking a lock on Class, the ClassLinker will
97 // attempt to move a kStatusIdx class forward to kStatusLoaded by
98 // using ResolveClass to initialize the super_class_ and ensuring the
99 // interfaces are resolved.
100 //
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700101 // kStatusResolving: Class is just cloned with the right size from
102 // temporary class that's acting as a placeholder for linking. The old
103 // class will be retired. New class is set to this status first before
104 // moving on to being resolved.
105 //
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800106 // kStatusResolved: Still holding the lock on Class, the ClassLinker
107 // shows linking is complete and fields of the Class populated by making
108 // it kStatusResolved. Java allows circularities of the form where a super
109 // class has a field that is of the type of the sub class. We need to be able
110 // to fully resolve super classes while resolving types for fields.
111 //
112 // kStatusRetryVerificationAtRuntime: The verifier sets a class to
113 // this state if it encounters a soft failure at compile time. This
114 // often happens when there are unresolved classes in other dex
115 // files, and this status marks a class as needing to be verified
116 // again at runtime.
117 //
118 // TODO: Explain the other states
119 enum Status {
Brian Carlstromf3978662014-09-11 12:21:04 -0700120 kStatusRetired = -2, // Retired, should not be used. Use the newly cloned one instead.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800121 kStatusError = -1,
122 kStatusNotReady = 0,
123 kStatusIdx = 1, // Loaded, DEX idx in super_class_type_idx_ and interfaces_type_idx_.
124 kStatusLoaded = 2, // DEX idx values resolved.
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700125 kStatusResolving = 3, // Just cloned from temporary class object.
126 kStatusResolved = 4, // Part of linking.
127 kStatusVerifying = 5, // In the process of being verified.
128 kStatusRetryVerificationAtRuntime = 6, // Compile time verification failed, retry at runtime.
129 kStatusVerifyingAtRuntime = 7, // Retrying verification at runtime.
130 kStatusVerified = 8, // Logically part of linking; done pre-init.
131 kStatusInitializing = 9, // Class init in progress.
132 kStatusInitialized = 10, // Ready to go.
133 kStatusMax = 11,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800134 };
135
Mathieu Chartier4e305412014-02-19 10:54:44 -0800136 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800137 Status GetStatus() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Andreas Gampe575e78c2014-11-03 23:41:03 -0800138 static_assert(sizeof(Status) == sizeof(uint32_t), "Size of status not equal to uint32");
Ian Rogers03dbc042014-06-02 14:24:56 -0700139 return static_cast<Status>(
140 GetField32Volatile<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, status_)));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800141 }
142
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700143 void SetStatus(Status new_status, Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800144
Ian Rogers5ddb4102014-01-07 08:58:46 -0800145 static MemberOffset StatusOffset() {
146 return OFFSET_OF_OBJECT_MEMBER(Class, status_);
147 }
148
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700149 // Returns true if the class has been retired.
150 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
151 bool IsRetired() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
152 return GetStatus<kVerifyFlags>() == kStatusRetired;
153 }
154
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800155 // Returns true if the class has failed to link.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800156 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800157 bool IsErroneous() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800158 return GetStatus<kVerifyFlags>() == kStatusError;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800159 }
160
161 // Returns true if the class has been loaded.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800162 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800163 bool IsIdxLoaded() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800164 return GetStatus<kVerifyFlags>() >= kStatusIdx;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800165 }
166
167 // Returns true if the class has been loaded.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800168 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800169 bool IsLoaded() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800170 return GetStatus<kVerifyFlags>() >= kStatusLoaded;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800171 }
172
173 // Returns true if the class has been linked.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800174 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800175 bool IsResolved() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800176 return GetStatus<kVerifyFlags>() >= kStatusResolved;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800177 }
178
179 // Returns true if the class was compile-time verified.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800180 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800181 bool IsCompileTimeVerified() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800182 return GetStatus<kVerifyFlags>() >= kStatusRetryVerificationAtRuntime;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800183 }
184
185 // Returns true if the class has been verified.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800186 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800187 bool IsVerified() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800188 return GetStatus<kVerifyFlags>() >= kStatusVerified;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800189 }
190
191 // Returns true if the class is initializing.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800192 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800193 bool IsInitializing() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800194 return GetStatus<kVerifyFlags>() >= kStatusInitializing;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800195 }
196
197 // Returns true if the class is initialized.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800198 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800199 bool IsInitialized() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800200 return GetStatus<kVerifyFlags>() == kStatusInitialized;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800201 }
202
Mathieu Chartier4e305412014-02-19 10:54:44 -0800203 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700204 ALWAYS_INLINE uint32_t GetAccessFlags() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800205
Andreas Gampe48498592014-09-10 19:48:05 -0700206 void SetAccessFlags(uint32_t new_access_flags) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800207
208 // Returns true if the class is an interface.
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700209 ALWAYS_INLINE bool IsInterface() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800210 return (GetAccessFlags() & kAccInterface) != 0;
211 }
212
213 // Returns true if the class is declared public.
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700214 ALWAYS_INLINE bool IsPublic() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800215 return (GetAccessFlags() & kAccPublic) != 0;
216 }
217
218 // Returns true if the class is declared final.
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700219 ALWAYS_INLINE bool IsFinal() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800220 return (GetAccessFlags() & kAccFinal) != 0;
221 }
222
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700223 ALWAYS_INLINE bool IsFinalizable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800224 return (GetAccessFlags() & kAccClassIsFinalizable) != 0;
225 }
226
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700227 ALWAYS_INLINE void SetFinalizable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700228 uint32_t flags = GetField32(OFFSET_OF_OBJECT_MEMBER(Class, access_flags_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800229 SetAccessFlags(flags | kAccClassIsFinalizable);
230 }
231
232 // Returns true if the class is abstract.
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700233 ALWAYS_INLINE bool IsAbstract() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800234 return (GetAccessFlags() & kAccAbstract) != 0;
235 }
236
237 // Returns true if the class is an annotation.
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700238 ALWAYS_INLINE bool IsAnnotation() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800239 return (GetAccessFlags() & kAccAnnotation) != 0;
240 }
241
242 // Returns true if the class is synthetic.
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700243 ALWAYS_INLINE bool IsSynthetic() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800244 return (GetAccessFlags() & kAccSynthetic) != 0;
245 }
246
Ian Rogers7b078e82014-09-10 14:44:24 -0700247 // Returns true if the class can avoid access checks.
248 bool IsPreverified() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
249 return (GetAccessFlags() & kAccPreverified) != 0;
250 }
251
252 void SetPreverified() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
253 uint32_t flags = GetField32(OFFSET_OF_OBJECT_MEMBER(Class, access_flags_));
254 SetAccessFlags(flags | kAccPreverified);
255 }
256
Mathieu Chartier4e305412014-02-19 10:54:44 -0800257 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Fred Shih4ee7a662014-07-11 09:59:27 -0700258 bool IsTypeOfReferenceClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800259 return (GetAccessFlags<kVerifyFlags>() & kAccClassIsReference) != 0;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800260 }
261
Mathieu Chartier4e305412014-02-19 10:54:44 -0800262 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800263 bool IsWeakReferenceClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800264 return (GetAccessFlags<kVerifyFlags>() & kAccClassIsWeakReference) != 0;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800265 }
266
Mathieu Chartier4e305412014-02-19 10:54:44 -0800267 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800268 bool IsSoftReferenceClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800269 return (GetAccessFlags<kVerifyFlags>() & kAccReferenceFlagsMask) == kAccClassIsReference;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800270 }
271
Mathieu Chartier4e305412014-02-19 10:54:44 -0800272 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800273 bool IsFinalizerReferenceClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800274 return (GetAccessFlags<kVerifyFlags>() & kAccClassIsFinalizerReference) != 0;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800275 }
276
Mathieu Chartier4e305412014-02-19 10:54:44 -0800277 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800278 bool IsPhantomReferenceClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800279 return (GetAccessFlags<kVerifyFlags>() & kAccClassIsPhantomReference) != 0;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800280 }
281
Ian Rogers04f94f42013-06-10 15:09:26 -0700282 // Can references of this type be assigned to by things of another type? For non-array types
283 // this is a matter of whether sub-classes may exist - which they can't if the type is final.
284 // For array classes, where all the classes are final due to there being no sub-classes, an
285 // Object[] may be assigned to by a String[] but a String[] may not be assigned to by other
286 // types as the component is final.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800287 bool CannotBeAssignedFromOtherTypes() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers04f94f42013-06-10 15:09:26 -0700288 if (!IsArrayClass()) {
289 return IsFinal();
290 } else {
291 Class* component = GetComponentType();
292 if (component->IsPrimitive()) {
Ian Rogersa9a82542013-10-04 11:17:26 -0700293 return true;
Ian Rogers04f94f42013-06-10 15:09:26 -0700294 } else {
295 return component->CannotBeAssignedFromOtherTypes();
296 }
297 }
298 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800299
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700300 // Returns true if this class is the placeholder and should retire and
301 // be replaced with a class with the right size for embedded imt/vtable.
302 bool IsTemp() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
303 Status s = GetStatus();
304 return s < Status::kStatusResolving && ShouldHaveEmbeddedImtAndVTable();
305 }
306
Ian Rogersef7d42f2014-01-06 12:55:46 -0800307 String* GetName() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); // Returns the cached name.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800308 void SetName(String* name) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); // Sets the cached name.
309 // Computes the name, then sets the cached value.
Mathieu Chartierf8322842014-05-16 10:59:25 -0700310 static String* ComputeName(Handle<Class> h_this) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800311
Mathieu Chartierc2f4d022014-03-03 16:11:42 -0800312 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier4e305412014-02-19 10:54:44 -0800313 bool IsProxyClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800314 // Read access flags without using getter as whether something is a proxy can be check in
315 // any loaded state
316 // TODO: switch to a check if the super class is java.lang.reflect.Proxy?
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700317 uint32_t access_flags = GetField32<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, access_flags_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800318 return (access_flags & kAccClassIsProxy) != 0;
319 }
320
Mathieu Chartier4e305412014-02-19 10:54:44 -0800321 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700322 Primitive::Type GetPrimitiveType() ALWAYS_INLINE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800323
Ian Rogersef7d42f2014-01-06 12:55:46 -0800324 void SetPrimitiveType(Primitive::Type new_type) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800325 DCHECK_EQ(sizeof(Primitive::Type), sizeof(int32_t));
Hiroshi Yamauchif0edfc32014-09-25 11:46:46 -0700326 int32_t v32 = static_cast<int32_t>(new_type);
327 DCHECK_EQ(v32 & 0xFFFF, v32) << "upper 16 bits aren't zero";
328 // Store the component size shift in the upper 16 bits.
329 v32 |= Primitive::ComponentSizeShift(new_type) << 16;
330 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, primitive_type_), v32);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800331 }
332
Hiroshi Yamauchif0edfc32014-09-25 11:46:46 -0700333 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
334 size_t GetPrimitiveTypeSizeShift() ALWAYS_INLINE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
335
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800336 // Returns true if the class is a primitive type.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800337 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800338 bool IsPrimitive() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800339 return GetPrimitiveType<kVerifyFlags>() != Primitive::kPrimNot;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800340 }
341
Mathieu Chartier4e305412014-02-19 10:54:44 -0800342 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800343 bool IsPrimitiveBoolean() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800344 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimBoolean;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800345 }
346
Mathieu Chartier4e305412014-02-19 10:54:44 -0800347 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800348 bool IsPrimitiveByte() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800349 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimByte;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800350 }
351
Mathieu Chartier4e305412014-02-19 10:54:44 -0800352 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800353 bool IsPrimitiveChar() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800354 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimChar;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800355 }
356
Mathieu Chartier4e305412014-02-19 10:54:44 -0800357 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800358 bool IsPrimitiveShort() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800359 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimShort;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800360 }
361
Mathieu Chartier4e305412014-02-19 10:54:44 -0800362 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800363 bool IsPrimitiveInt() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800364 return GetPrimitiveType() == Primitive::kPrimInt;
365 }
366
Mathieu Chartier4e305412014-02-19 10:54:44 -0800367 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800368 bool IsPrimitiveLong() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800369 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimLong;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800370 }
371
Mathieu Chartier4e305412014-02-19 10:54:44 -0800372 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800373 bool IsPrimitiveFloat() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800374 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimFloat;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800375 }
376
Mathieu Chartier4e305412014-02-19 10:54:44 -0800377 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800378 bool IsPrimitiveDouble() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800379 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimDouble;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800380 }
381
Mathieu Chartier4e305412014-02-19 10:54:44 -0800382 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800383 bool IsPrimitiveVoid() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800384 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimVoid;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800385 }
386
Mathieu Chartier4e305412014-02-19 10:54:44 -0800387 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800388 bool IsPrimitiveArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800389 return IsArrayClass<kVerifyFlags>() &&
390 GetComponentType<static_cast<VerifyObjectFlags>(kVerifyFlags & ~kVerifyThis)>()->
391 IsPrimitive();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800392 }
393
394 // Depth of class from java.lang.Object
Ian Rogersef7d42f2014-01-06 12:55:46 -0800395 uint32_t Depth() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
396 uint32_t depth = 0;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800397 for (Class* klass = this; klass->GetSuperClass() != NULL; klass = klass->GetSuperClass()) {
398 depth++;
399 }
400 return depth;
401 }
402
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700403 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
404 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800405 bool IsArrayClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700406 return GetComponentType<kVerifyFlags, kReadBarrierOption>() != NULL;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800407 }
408
Hiroshi Yamauchi25023c72014-05-09 11:45:53 -0700409 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
410 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800411 bool IsClassClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800412
Hiroshi Yamauchibd0fb612014-05-20 13:46:00 -0700413 bool IsStringClass() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800414
Ian Rogersef7d42f2014-01-06 12:55:46 -0800415 bool IsThrowableClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800416
Hiroshi Yamauchi4f1ebc22014-06-25 14:30:41 -0700417 template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Hiroshi Yamauchibd0fb612014-05-20 13:46:00 -0700418 bool IsArtFieldClass() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800419
Hiroshi Yamauchi4f1ebc22014-06-25 14:30:41 -0700420 template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Hiroshi Yamauchibd0fb612014-05-20 13:46:00 -0700421 bool IsArtMethodClass() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800422
Fred Shih4ee7a662014-07-11 09:59:27 -0700423 template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
424 bool IsReferenceClass() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
425
Ian Rogersa9a82542013-10-04 11:17:26 -0700426 static MemberOffset ComponentTypeOffset() {
427 return OFFSET_OF_OBJECT_MEMBER(Class, component_type_);
428 }
429
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700430 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
431 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800432 Class* GetComponentType() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700433 return GetFieldObject<Class, kVerifyFlags, kReadBarrierOption>(ComponentTypeOffset());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800434 }
435
436 void SetComponentType(Class* new_component_type) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
437 DCHECK(GetComponentType() == NULL);
438 DCHECK(new_component_type != NULL);
Sebastien Hertzee1d79a2014-02-21 15:46:30 +0100439 // Component type is invariant: use non-transactional mode without check.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700440 SetFieldObject<false, false>(ComponentTypeOffset(), new_component_type);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800441 }
442
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700443 template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800444 size_t GetComponentSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Hiroshi Yamauchif0edfc32014-09-25 11:46:46 -0700445 return 1U << GetComponentSizeShift();
446 }
447
448 template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
449 size_t GetComponentSizeShift() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
450 return GetComponentType<kDefaultVerifyFlags, kReadBarrierOption>()->GetPrimitiveTypeSizeShift();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800451 }
452
Ian Rogersef7d42f2014-01-06 12:55:46 -0800453 bool IsObjectClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800454 return !IsPrimitive() && GetSuperClass() == NULL;
455 }
Ian Rogers68d8b422014-07-17 11:09:10 -0700456
457 bool IsInstantiableNonArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
458 return !IsPrimitive() && !IsInterface() && !IsAbstract() && !IsArrayClass();
459 }
460
Ian Rogersef7d42f2014-01-06 12:55:46 -0800461 bool IsInstantiable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers68d8b422014-07-17 11:09:10 -0700462 return (!IsPrimitive() && !IsInterface() && !IsAbstract()) ||
463 ((IsAbstract()) && IsArrayClass());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800464 }
465
Mathieu Chartier4e305412014-02-19 10:54:44 -0800466 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800467 bool IsObjectArrayClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800468 return GetComponentType<kVerifyFlags>() != nullptr && !GetComponentType<kVerifyFlags>()->IsPrimitive();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800469 }
470
471 // Creates a raw object instance but does not invoke the default constructor.
Mathieu Chartier8668c3c2014-04-24 16:48:11 -0700472 template<bool kIsInstrumented, bool kCheckAddFinalizer = true>
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800473 ALWAYS_INLINE Object* Alloc(Thread* self, gc::AllocatorType allocator_type)
474 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -0700475
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800476 Object* AllocObject(Thread* self)
477 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
478 Object* AllocNonMovableObject(Thread* self)
479 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800480
Hiroshi Yamauchi25023c72014-05-09 11:45:53 -0700481 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
482 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800483 bool IsVariableSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800484 // Classes and arrays vary in size, and so the object_size_ field cannot
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700485 // be used to Get their instance size
Hiroshi Yamauchi25023c72014-05-09 11:45:53 -0700486 return IsClassClass<kVerifyFlags, kReadBarrierOption>() ||
487 IsArrayClass<kVerifyFlags, kReadBarrierOption>();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800488 }
489
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700490 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
491 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800492 uint32_t SizeOf() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700493 return GetField32<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, class_size_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800494 }
495
Mathieu Chartier4e305412014-02-19 10:54:44 -0800496 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800497 uint32_t GetClassSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700498 return GetField32<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, class_size_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800499 }
500
Ian Rogersef7d42f2014-01-06 12:55:46 -0800501 void SetClassSize(uint32_t new_class_size)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800502 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
503
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700504 // Compute how many bytes would be used a class with the given elements.
505 static uint32_t ComputeClassSize(bool has_embedded_tables,
506 uint32_t num_vtable_entries,
Fred Shih37f05ef2014-07-16 18:38:08 -0700507 uint32_t num_8bit_static_fields,
508 uint32_t num_16bit_static_fields,
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700509 uint32_t num_32bit_static_fields,
510 uint32_t num_64bit_static_fields,
511 uint32_t num_ref_static_fields);
512
513 // The size of java.lang.Class.class.
514 static uint32_t ClassClassSize() {
515 // The number of vtable entries in java.lang.Class.
Brian Carlstromb144fce2014-10-16 22:02:23 -0700516 uint32_t vtable_entries = Object::kVTableLength + 66;
Fred Shih37f05ef2014-07-16 18:38:08 -0700517 return ComputeClassSize(true, vtable_entries, 0, 0, 0, 1, 0);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700518 }
519
520 // The size of a java.lang.Class representing a primitive such as int.class.
521 static uint32_t PrimitiveClassSize() {
Fred Shih37f05ef2014-07-16 18:38:08 -0700522 return ComputeClassSize(false, 0, 0, 0, 0, 0, 0);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700523 }
524
Hiroshi Yamauchi25023c72014-05-09 11:45:53 -0700525 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
526 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800527 uint32_t GetObjectSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800528
Ian Rogersef7d42f2014-01-06 12:55:46 -0800529 void SetObjectSize(uint32_t new_object_size) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800530 DCHECK(!IsVariableSize());
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100531 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700532 return SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, object_size_), new_object_size);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800533 }
534
Mathieu Chartier2d721012014-11-10 11:08:06 -0800535 void SetObjectSizeWithoutChecks(uint32_t new_object_size)
536 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
537 // Not called within a transaction.
538 return SetField32<false, false, kVerifyNone>(
539 OFFSET_OF_OBJECT_MEMBER(Class, object_size_), new_object_size);
540 }
541
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800542 // Returns true if this class is in the same packages as that class.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800543 bool IsInSamePackage(Class* that) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800544
545 static bool IsInSamePackage(const StringPiece& descriptor1, const StringPiece& descriptor2);
546
547 // Returns true if this class can access that class.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800548 bool CanAccess(Class* that) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800549 return that->IsPublic() || this->IsInSamePackage(that);
550 }
551
552 // Can this class access a member in the provided class with the provided member access flags?
553 // Note that access to the class isn't checked in case the declaring class is protected and the
554 // method has been exposed by a public sub-class
Ian Rogersef7d42f2014-01-06 12:55:46 -0800555 bool CanAccessMember(Class* access_to, uint32_t member_flags)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800556 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
557 // Classes can access all of their own members
558 if (this == access_to) {
559 return true;
560 }
561 // Public members are trivially accessible
562 if (member_flags & kAccPublic) {
563 return true;
564 }
565 // Private members are trivially not accessible
566 if (member_flags & kAccPrivate) {
567 return false;
568 }
569 // Check for protected access from a sub-class, which may or may not be in the same package.
570 if (member_flags & kAccProtected) {
Andreas Gampe13f8a162014-08-08 19:55:37 -0700571 if (!this->IsInterface() && this->IsSubClass(access_to)) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800572 return true;
573 }
574 }
575 // Allow protected access from other classes in the same package.
576 return this->IsInSamePackage(access_to);
577 }
578
Vladimir Marko23a28212014-01-09 19:24:37 +0000579 // Can this class access a resolved field?
580 // Note that access to field's class is checked and this may require looking up the class
581 // referenced by the FieldId in the DexFile in case the declaring class is inaccessible.
Vladimir Marko23a28212014-01-09 19:24:37 +0000582 bool CanAccessResolvedField(Class* access_to, ArtField* field,
Ian Rogersef7d42f2014-01-06 12:55:46 -0800583 DexCache* dex_cache, uint32_t field_idx)
Vladimir Marko89786432014-01-31 15:03:55 +0000584 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
585 bool CheckResolvedFieldAccess(Class* access_to, ArtField* field,
586 uint32_t field_idx)
587 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Vladimir Marko23a28212014-01-09 19:24:37 +0000588
589 // Can this class access a resolved method?
590 // Note that access to methods's class is checked and this may require looking up the class
591 // referenced by the MethodId in the DexFile in case the declaring class is inaccessible.
Vladimir Marko23a28212014-01-09 19:24:37 +0000592 bool CanAccessResolvedMethod(Class* access_to, ArtMethod* resolved_method,
Ian Rogersef7d42f2014-01-06 12:55:46 -0800593 DexCache* dex_cache, uint32_t method_idx)
Vladimir Marko89786432014-01-31 15:03:55 +0000594 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
595 template <InvokeType throw_invoke_type>
596 bool CheckResolvedMethodAccess(Class* access_to, ArtMethod* resolved_method,
597 uint32_t method_idx)
598 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Vladimir Marko23a28212014-01-09 19:24:37 +0000599
Ian Rogersef7d42f2014-01-06 12:55:46 -0800600 bool IsSubClass(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800601
602 // Can src be assigned to this class? For example, String can be assigned to Object (by an
603 // upcast), however, an Object cannot be assigned to a String as a potentially exception throwing
604 // downcast would be necessary. Similarly for interfaces, a class that implements (or an interface
605 // that extends) another can be assigned to its parent, but not vice-versa. All Classes may assign
606 // to themselves. Classes for primitive types may not assign to each other.
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700607 ALWAYS_INLINE bool IsAssignableFrom(Class* src) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800608 DCHECK(src != NULL);
609 if (this == src) {
610 // Can always assign to things of the same type.
611 return true;
612 } else if (IsObjectClass()) {
613 // Can assign any reference to java.lang.Object.
614 return !src->IsPrimitive();
615 } else if (IsInterface()) {
616 return src->Implements(this);
617 } else if (src->IsArrayClass()) {
618 return IsAssignableFromArray(src);
619 } else {
620 return !src->IsInterface() && src->IsSubClass(this);
621 }
622 }
623
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700624 ALWAYS_INLINE Class* GetSuperClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800625
626 void SetSuperClass(Class *new_super_class) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800627 // Super class is assigned once, except during class linker initialization.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700628 Class* old_super_class = GetFieldObject<Class>(OFFSET_OF_OBJECT_MEMBER(Class, super_class_));
Ian Rogersef7d42f2014-01-06 12:55:46 -0800629 DCHECK(old_super_class == nullptr || old_super_class == new_super_class);
630 DCHECK(new_super_class != nullptr);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700631 SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(Class, super_class_), new_super_class);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800632 }
633
Ian Rogersef7d42f2014-01-06 12:55:46 -0800634 bool HasSuperClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800635 return GetSuperClass() != NULL;
636 }
637
638 static MemberOffset SuperClassOffset() {
639 return MemberOffset(OFFSETOF_MEMBER(Class, super_class_));
640 }
641
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700642 ClassLoader* GetClassLoader() ALWAYS_INLINE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800643
644 void SetClassLoader(ClassLoader* new_cl) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
645
646 static MemberOffset DexCacheOffset() {
647 return MemberOffset(OFFSETOF_MEMBER(Class, dex_cache_));
648 }
649
650 enum {
651 kDumpClassFullDetail = 1,
652 kDumpClassClassLoader = (1 << 1),
653 kDumpClassInitialized = (1 << 2),
654 };
655
Ian Rogersef7d42f2014-01-06 12:55:46 -0800656 void DumpClass(std::ostream& os, int flags) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800657
Mathieu Chartierc2f4d022014-03-03 16:11:42 -0800658 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800659 DexCache* GetDexCache() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800660
Mathieu Chartier91a6dc42014-12-01 10:31:15 -0800661 // Also updates the dex_cache_strings_ variable from new_dex_cache.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800662 void SetDexCache(DexCache* new_dex_cache) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
663
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700664 ALWAYS_INLINE ObjectArray<ArtMethod>* GetDirectMethods()
665 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800666
Brian Carlstromea46f952013-07-30 01:26:50 -0700667 void SetDirectMethods(ObjectArray<ArtMethod>* new_direct_methods)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800668 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
669
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700670 ALWAYS_INLINE ArtMethod* GetDirectMethod(int32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800671
Brian Carlstromea46f952013-07-30 01:26:50 -0700672 void SetDirectMethod(uint32_t i, ArtMethod* f) // TODO: uint16_t
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800673 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
674
675 // Returns the number of static, private, and constructor methods.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800676 uint32_t NumDirectMethods() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800677
Mathieu Chartier4e305412014-02-19 10:54:44 -0800678 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700679 ALWAYS_INLINE ObjectArray<ArtMethod>* GetVirtualMethods()
680 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800681
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700682 ALWAYS_INLINE void SetVirtualMethods(ObjectArray<ArtMethod>* new_virtual_methods)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800683 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
684
685 // Returns the number of non-inherited virtual methods.
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700686 ALWAYS_INLINE uint32_t NumVirtualMethods() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800687
Mathieu Chartier4e305412014-02-19 10:54:44 -0800688 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800689 ArtMethod* GetVirtualMethod(uint32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800690
Ian Rogersef7d42f2014-01-06 12:55:46 -0800691 ArtMethod* GetVirtualMethodDuringLinking(uint32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800692
Brian Carlstromea46f952013-07-30 01:26:50 -0700693 void SetVirtualMethod(uint32_t i, ArtMethod* f) // TODO: uint16_t
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800694 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
695
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700696 ALWAYS_INLINE ObjectArray<ArtMethod>* GetVTable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800697
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700698 ALWAYS_INLINE ObjectArray<ArtMethod>* GetVTableDuringLinking()
699 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800700
Brian Carlstromea46f952013-07-30 01:26:50 -0700701 void SetVTable(ObjectArray<ArtMethod>* new_vtable)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800702 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
703
704 static MemberOffset VTableOffset() {
705 return OFFSET_OF_OBJECT_MEMBER(Class, vtable_);
706 }
707
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700708 static MemberOffset EmbeddedImTableOffset() {
709 return MemberOffset(sizeof(Class));
710 }
711
Mingyao Yang2cdbad72014-07-16 10:44:41 -0700712 static MemberOffset EmbeddedVTableLengthOffset() {
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700713 return MemberOffset(sizeof(Class) + kImtSize * sizeof(mirror::Class::ImTableEntry));
714 }
715
Mingyao Yang2cdbad72014-07-16 10:44:41 -0700716 static MemberOffset EmbeddedVTableOffset() {
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700717 return MemberOffset(sizeof(Class) + kImtSize * sizeof(ImTableEntry) + sizeof(int32_t));
Mingyao Yang2cdbad72014-07-16 10:44:41 -0700718 }
719
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700720 bool ShouldHaveEmbeddedImtAndVTable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
721 return IsInstantiable();
722 }
723
Mingyao Yang2cdbad72014-07-16 10:44:41 -0700724 bool HasVTable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
725
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700726 ArtMethod* GetEmbeddedImTableEntry(uint32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
727
728 void SetEmbeddedImTableEntry(uint32_t i, ArtMethod* method) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
729
Mingyao Yang2cdbad72014-07-16 10:44:41 -0700730 int32_t GetVTableLength() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
731
732 ArtMethod* GetVTableEntry(uint32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
733
734 int32_t GetEmbeddedVTableLength() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
735
736 void SetEmbeddedVTableLength(int32_t len) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
737
738 ArtMethod* GetEmbeddedVTableEntry(uint32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
739
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700740 void SetEmbeddedVTableEntry(uint32_t i, ArtMethod* method) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
741
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700742 void PopulateEmbeddedImtAndVTable(StackHandleScope<kImtSize>* imt_handle_scope)
743 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700744
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800745 // Given a method implemented by this class but potentially from a super class, return the
746 // specific implementation method for this class.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800747 ArtMethod* FindVirtualMethodForVirtual(ArtMethod* method)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800748 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
749
750 // Given a method implemented by this class' super class, return the specific implementation
751 // method for this class.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800752 ArtMethod* FindVirtualMethodForSuper(ArtMethod* method)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800753 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
754
755 // Given a method implemented by this class, but potentially from a
756 // super class or interface, return the specific implementation
757 // method for this class.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800758 ArtMethod* FindVirtualMethodForInterface(ArtMethod* method)
Ian Rogers1ffa32f2013-02-05 18:29:08 -0800759 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) ALWAYS_INLINE;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800760
Ian Rogersef7d42f2014-01-06 12:55:46 -0800761 ArtMethod* FindVirtualMethodForVirtualOrInterface(ArtMethod* method)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700762 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
763
Brian Carlstrom004644f2014-06-18 08:34:01 -0700764 ArtMethod* FindInterfaceMethod(const StringPiece& name, const StringPiece& signature)
765 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
766
Ian Rogersef7d42f2014-01-06 12:55:46 -0800767 ArtMethod* FindInterfaceMethod(const StringPiece& name, const Signature& signature)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800768 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
769
Ian Rogersef7d42f2014-01-06 12:55:46 -0800770 ArtMethod* FindInterfaceMethod(const DexCache* dex_cache, uint32_t dex_method_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800771 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
772
Ian Rogersef7d42f2014-01-06 12:55:46 -0800773 ArtMethod* FindDeclaredDirectMethod(const StringPiece& name, const StringPiece& signature)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800774 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
775
Ian Rogersef7d42f2014-01-06 12:55:46 -0800776 ArtMethod* FindDeclaredDirectMethod(const StringPiece& name, const Signature& signature)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700777 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
778
Ian Rogersef7d42f2014-01-06 12:55:46 -0800779 ArtMethod* FindDeclaredDirectMethod(const DexCache* dex_cache, uint32_t dex_method_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800780 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
781
Ian Rogersef7d42f2014-01-06 12:55:46 -0800782 ArtMethod* FindDirectMethod(const StringPiece& name, const StringPiece& signature)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800783 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
784
Ian Rogersef7d42f2014-01-06 12:55:46 -0800785 ArtMethod* FindDirectMethod(const StringPiece& name, const Signature& signature)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700786 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
787
Ian Rogersef7d42f2014-01-06 12:55:46 -0800788 ArtMethod* FindDirectMethod(const DexCache* dex_cache, uint32_t dex_method_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800789 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
790
Ian Rogersef7d42f2014-01-06 12:55:46 -0800791 ArtMethod* FindDeclaredVirtualMethod(const StringPiece& name, const StringPiece& signature)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700792 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
793
Ian Rogersef7d42f2014-01-06 12:55:46 -0800794 ArtMethod* FindDeclaredVirtualMethod(const StringPiece& name, const Signature& signature)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700795 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
796
Ian Rogersef7d42f2014-01-06 12:55:46 -0800797 ArtMethod* FindDeclaredVirtualMethod(const DexCache* dex_cache, uint32_t dex_method_idx)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700798 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
799
Ian Rogersef7d42f2014-01-06 12:55:46 -0800800 ArtMethod* FindVirtualMethod(const StringPiece& name, const StringPiece& signature)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700801 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
802
Ian Rogersef7d42f2014-01-06 12:55:46 -0800803 ArtMethod* FindVirtualMethod(const StringPiece& name, const Signature& signature)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700804 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
805
Ian Rogersef7d42f2014-01-06 12:55:46 -0800806 ArtMethod* FindVirtualMethod(const DexCache* dex_cache, uint32_t dex_method_idx)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700807 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
808
Ian Rogersef7d42f2014-01-06 12:55:46 -0800809 ArtMethod* FindClassInitializer() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersd91d6d62013-09-25 20:26:14 -0700810
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700811 ALWAYS_INLINE int32_t GetIfTableCount() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800812
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700813 ALWAYS_INLINE IfTable* GetIfTable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800814
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700815 ALWAYS_INLINE void SetIfTable(IfTable* new_iftable) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800816
817 // Get instance fields of the class (See also GetSFields).
Ian Rogersef7d42f2014-01-06 12:55:46 -0800818 ObjectArray<ArtField>* GetIFields() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800819
Brian Carlstromea46f952013-07-30 01:26:50 -0700820 void SetIFields(ObjectArray<ArtField>* new_ifields) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800821
Ian Rogersef7d42f2014-01-06 12:55:46 -0800822 uint32_t NumInstanceFields() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800823
Ian Rogersef7d42f2014-01-06 12:55:46 -0800824 ArtField* GetInstanceField(uint32_t i) // TODO: uint16_t
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800825 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
826
Brian Carlstromea46f952013-07-30 01:26:50 -0700827 void SetInstanceField(uint32_t i, ArtField* f) // TODO: uint16_t
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800828 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
829
830 // Returns the number of instance fields containing reference types.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800831 uint32_t NumReferenceInstanceFields() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800832 DCHECK(IsResolved() || IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700833 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_instance_fields_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800834 }
835
Ian Rogersef7d42f2014-01-06 12:55:46 -0800836 uint32_t NumReferenceInstanceFieldsDuringLinking() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800837 DCHECK(IsLoaded() || IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700838 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_instance_fields_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800839 }
840
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700841 void SetNumReferenceInstanceFields(uint32_t new_num) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100842 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700843 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_instance_fields_), new_num);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800844 }
845
Mathieu Chartier4e305412014-02-19 10:54:44 -0800846 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700847 uint32_t GetReferenceInstanceOffsets() ALWAYS_INLINE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800848
849 void SetReferenceInstanceOffsets(uint32_t new_reference_offsets)
850 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
851
Vladimir Marko76649e82014-11-10 18:32:59 +0000852 // Get the offset of the first reference instance field. Other reference instance fields follow.
853 MemberOffset GetFirstReferenceInstanceFieldOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
854
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800855 // Returns the number of static fields containing reference types.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800856 uint32_t NumReferenceStaticFields() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700857 DCHECK(IsResolved() || IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700858 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_static_fields_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800859 }
860
Ian Rogersef7d42f2014-01-06 12:55:46 -0800861 uint32_t NumReferenceStaticFieldsDuringLinking() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700862 DCHECK(IsLoaded() || IsErroneous() || IsRetired());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700863 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_static_fields_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800864 }
865
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700866 void SetNumReferenceStaticFields(uint32_t new_num) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100867 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700868 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_static_fields_), new_num);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800869 }
870
Vladimir Marko76649e82014-11-10 18:32:59 +0000871 // Get the offset of the first reference static field. Other reference static fields follow.
872 MemberOffset GetFirstReferenceStaticFieldOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
873
874 // Get the offset of the first reference static field. Other reference static fields follow.
875 MemberOffset GetFirstReferenceStaticFieldOffsetDuringLinking()
876 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
877
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800878 // Gets the static fields of the class.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800879 ObjectArray<ArtField>* GetSFields() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800880
Brian Carlstromea46f952013-07-30 01:26:50 -0700881 void SetSFields(ObjectArray<ArtField>* new_sfields) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800882
Ian Rogersef7d42f2014-01-06 12:55:46 -0800883 uint32_t NumStaticFields() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800884
Ian Rogersef7d42f2014-01-06 12:55:46 -0800885 // TODO: uint16_t
886 ArtField* GetStaticField(uint32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800887
Ian Rogersef7d42f2014-01-06 12:55:46 -0800888 // TODO: uint16_t
889 void SetStaticField(uint32_t i, ArtField* f) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800890
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800891 // Find a static or instance field using the JLS resolution order
Mathieu Chartierf8322842014-05-16 10:59:25 -0700892 static ArtField* FindField(Thread* self, Handle<Class> klass, const StringPiece& name,
893 const StringPiece& type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800894 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
895
896 // Finds the given instance field in this class or a superclass.
Brian Carlstromea46f952013-07-30 01:26:50 -0700897 ArtField* FindInstanceField(const StringPiece& name, const StringPiece& type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800898 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
899
900 // Finds the given instance field in this class or a superclass, only searches classes that
901 // have the same dex cache.
Brian Carlstromea46f952013-07-30 01:26:50 -0700902 ArtField* FindInstanceField(const DexCache* dex_cache, uint32_t dex_field_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800903 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
904
Brian Carlstromea46f952013-07-30 01:26:50 -0700905 ArtField* FindDeclaredInstanceField(const StringPiece& name, const StringPiece& type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800906 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
907
Brian Carlstromea46f952013-07-30 01:26:50 -0700908 ArtField* FindDeclaredInstanceField(const DexCache* dex_cache, uint32_t dex_field_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800909 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
910
911 // Finds the given static field in this class or a superclass.
Mathieu Chartierf8322842014-05-16 10:59:25 -0700912 static ArtField* FindStaticField(Thread* self, Handle<Class> klass, const StringPiece& name,
913 const StringPiece& type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800914 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
915
916 // Finds the given static field in this class or superclass, only searches classes that
917 // have the same dex cache.
Mathieu Chartierf8322842014-05-16 10:59:25 -0700918 static ArtField* FindStaticField(Thread* self, Handle<Class> klass, const DexCache* dex_cache,
919 uint32_t dex_field_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800920 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
921
Brian Carlstromea46f952013-07-30 01:26:50 -0700922 ArtField* FindDeclaredStaticField(const StringPiece& name, const StringPiece& type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800923 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
924
Brian Carlstromea46f952013-07-30 01:26:50 -0700925 ArtField* FindDeclaredStaticField(const DexCache* dex_cache, uint32_t dex_field_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800926 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
927
Ian Rogersef7d42f2014-01-06 12:55:46 -0800928 pid_t GetClinitThreadId() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800929 DCHECK(IsIdxLoaded() || IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700930 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, clinit_thread_id_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800931 }
932
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700933 void SetClinitThreadId(pid_t new_clinit_thread_id) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800934
Ian Rogersef7d42f2014-01-06 12:55:46 -0800935 Class* GetVerifyErrorClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800936 // DCHECK(IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700937 return GetFieldObject<Class>(OFFSET_OF_OBJECT_MEMBER(Class, verify_error_class_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800938 }
939
Ian Rogersef7d42f2014-01-06 12:55:46 -0800940 uint16_t GetDexClassDefIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700941 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, dex_class_def_idx_));
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700942 }
943
Ian Rogersef7d42f2014-01-06 12:55:46 -0800944 void SetDexClassDefIndex(uint16_t class_def_idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100945 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700946 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, dex_class_def_idx_), class_def_idx);
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700947 }
948
Ian Rogersef7d42f2014-01-06 12:55:46 -0800949 uint16_t GetDexTypeIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700950 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, dex_type_idx_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800951 }
952
Ian Rogersef7d42f2014-01-06 12:55:46 -0800953 void SetDexTypeIndex(uint16_t type_idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100954 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700955 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, dex_type_idx_), type_idx);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800956 }
957
Hiroshi Yamauchi4f1ebc22014-06-25 14:30:41 -0700958 static Class* GetJavaLangClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -0700959 DCHECK(!java_lang_Class_.IsNull());
960 return java_lang_Class_.Read();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800961 }
962
963 // Can't call this SetClass or else gets called instead of Object::SetClass in places.
Hiroshi Yamauchi4f1ebc22014-06-25 14:30:41 -0700964 static void SetClassClass(Class* java_lang_Class) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800965 static void ResetClass();
Mathieu Chartier83c8ee02014-01-28 14:50:23 -0800966 static void VisitRoots(RootCallback* callback, void* arg)
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800967 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800968
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200969 // When class is verified, set the kAccPreverified flag on each method.
970 void SetPreverifiedFlagOnAllMethods() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
971
Mathieu Chartier407f7022014-02-18 14:37:05 -0800972 template <bool kVisitClass, typename Visitor>
973 void VisitReferences(mirror::Class* klass, const Visitor& visitor)
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700974 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
975
976 // Visit references within the embedded tables of the class.
977 // TODO: remove NO_THREAD_SAFETY_ANALYSIS when annotalysis handles visitors better.
978 template<typename Visitor>
979 void VisitEmbeddedImtAndVTable(const Visitor& visitor) NO_THREAD_SAFETY_ANALYSIS;
Mathieu Chartier407f7022014-02-18 14:37:05 -0800980
Ian Rogers1ff3c982014-08-12 02:30:58 -0700981 // Get the descriptor of the class. In a few cases a std::string is required, rather than
982 // always create one the storage argument is populated and its internal c_str() returned. We do
983 // this to avoid memory allocation in the common case.
984 const char* GetDescriptor(std::string* storage) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
985
986 const char* GetArrayDescriptor(std::string* storage) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700987
Mathieu Chartierf8322842014-05-16 10:59:25 -0700988 bool DescriptorEquals(const char* match) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700989
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700990
Mathieu Chartierf8322842014-05-16 10:59:25 -0700991 const DexFile::ClassDef* GetClassDef() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700992
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700993 ALWAYS_INLINE uint32_t NumDirectInterfaces() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700994
Mathieu Chartierf8322842014-05-16 10:59:25 -0700995 uint16_t GetDirectInterfaceTypeIdx(uint32_t idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700996
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700997 static mirror::Class* GetDirectInterface(Thread* self, Handle<mirror::Class> klass,
Mathieu Chartierbf99f772014-08-23 16:37:27 -0700998 uint32_t idx)
Mathieu Chartierf8322842014-05-16 10:59:25 -0700999 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001000
Mathieu Chartierf8322842014-05-16 10:59:25 -07001001 const char* GetSourceFile() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001002
Mathieu Chartierf8322842014-05-16 10:59:25 -07001003 std::string GetLocation() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001004
Mathieu Chartierf8322842014-05-16 10:59:25 -07001005 const DexFile& GetDexFile() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001006
Mathieu Chartierf8322842014-05-16 10:59:25 -07001007 const DexFile::TypeList* GetInterfaceTypeList() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1008
Sebastien Hertz4e99b3d2014-06-24 14:35:40 +02001009 // Asserts we are initialized or initializing in the given thread.
1010 void AssertInitializedOrInitializingInThread(Thread* self)
1011 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1012
Mathieu Chartier2d2621a2014-10-23 16:48:06 -07001013 Class* CopyOf(Thread* self, int32_t new_length, StackHandleScope<kImtSize>* imt_handle_scope)
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001014 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1015
1016 // For proxy class only.
1017 ObjectArray<Class>* GetInterfaces() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1018
1019 // For proxy class only.
1020 ObjectArray<ObjectArray<Class>>* GetThrows() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1021
Fred Shih4ee7a662014-07-11 09:59:27 -07001022 // For reference class only.
1023 MemberOffset GetDisableIntrinsicFlagOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1024 MemberOffset GetSlowPathFlagOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1025 bool GetSlowPathEnabled() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1026 void SetSlowPath(bool enabled) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1027
Mathieu Chartiereace4582014-11-24 18:29:54 -08001028 ObjectArray<String>* GetDexCacheStrings() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1029 void SetDexCacheStrings(ObjectArray<String>* new_dex_cache_strings)
1030 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1031 static MemberOffset DexCacheStringsOffset() {
1032 return OFFSET_OF_OBJECT_MEMBER(Class, dex_cache_strings_);
1033 }
1034
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001035 // Used to initialize a class in the allocation code path to ensure it is guarded by a StoreStore
1036 // fence.
1037 class InitializeClassVisitor {
1038 public:
1039 explicit InitializeClassVisitor(uint32_t class_size) : class_size_(class_size) {
1040 }
1041
1042 void operator()(mirror::Object* obj, size_t usable_size) const
1043 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1044
1045 private:
1046 const uint32_t class_size_;
1047
1048 DISALLOW_COPY_AND_ASSIGN(InitializeClassVisitor);
1049 };
1050
Sebastien Hertz6963e442014-11-26 22:11:27 +01001051 // Returns true if the class loader is null, ie the class loader is the boot strap class loader.
1052 bool IsBootStrapClassLoaded() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
1053 return GetClassLoader() == nullptr;
1054 }
1055
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001056 private:
1057 void SetVerifyErrorClass(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1058
Vladimir Marko89786432014-01-31 15:03:55 +00001059 template <bool throw_on_failure, bool use_referrers_cache>
1060 bool ResolvedFieldAccessTest(Class* access_to, ArtField* field,
Ian Rogersef7d42f2014-01-06 12:55:46 -08001061 uint32_t field_idx, DexCache* dex_cache)
Vladimir Marko89786432014-01-31 15:03:55 +00001062 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1063 template <bool throw_on_failure, bool use_referrers_cache, InvokeType throw_invoke_type>
1064 bool ResolvedMethodAccessTest(Class* access_to, ArtMethod* resolved_method,
Ian Rogersef7d42f2014-01-06 12:55:46 -08001065 uint32_t method_idx, DexCache* dex_cache)
Vladimir Marko89786432014-01-31 15:03:55 +00001066 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1067
Ian Rogersef7d42f2014-01-06 12:55:46 -08001068 bool Implements(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1069 bool IsArrayAssignableFromArray(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1070 bool IsAssignableFromArray(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001071
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -07001072 void CheckObjectAlloc() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1073
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001074 // defining class loader, or NULL for the "bootstrap" system loader
Ian Rogersef7d42f2014-01-06 12:55:46 -08001075 HeapReference<ClassLoader> class_loader_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001076
1077 // For array classes, the component class object for instanceof/checkcast
1078 // (for String[][][], this will be String[][]). NULL for non-array classes.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001079 HeapReference<Class> component_type_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001080
1081 // DexCache of resolved constant pool entries (will be NULL for classes generated by the
1082 // runtime such as arrays and primitive classes).
Ian Rogersef7d42f2014-01-06 12:55:46 -08001083 HeapReference<DexCache> dex_cache_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001084
Mathieu Chartiereace4582014-11-24 18:29:54 -08001085 // Short cuts to dex_cache_ member for fast compiled code access.
1086 HeapReference<ObjectArray<String>> dex_cache_strings_;
1087
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001088 // static, private, and <init> methods
Ian Rogers700a4022014-05-19 16:49:03 -07001089 HeapReference<ObjectArray<ArtMethod>> direct_methods_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001090
1091 // instance fields
1092 //
1093 // These describe the layout of the contents of an Object.
1094 // Note that only the fields directly declared by this class are
1095 // listed in ifields; fields declared by a superclass are listed in
1096 // the superclass's Class.ifields.
1097 //
1098 // All instance fields that refer to objects are guaranteed to be at
1099 // the beginning of the field list. num_reference_instance_fields_
1100 // specifies the number of reference fields.
Ian Rogers700a4022014-05-19 16:49:03 -07001101 HeapReference<ObjectArray<ArtField>> ifields_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001102
1103 // The interface table (iftable_) contains pairs of a interface class and an array of the
1104 // interface methods. There is one pair per interface supported by this class. That means one
1105 // pair for each interface we support directly, indirectly via superclass, or indirectly via a
1106 // superinterface. This will be null if neither we nor our superclass implement any interfaces.
1107 //
1108 // Why we need this: given "class Foo implements Face", declare "Face faceObj = new Foo()".
1109 // Invoke faceObj.blah(), where "blah" is part of the Face interface. We can't easily use a
1110 // single vtable.
1111 //
1112 // For every interface a concrete class implements, we create an array of the concrete vtable_
1113 // methods for the methods in the interface.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001114 HeapReference<IfTable> iftable_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001115
Ian Rogersef7d42f2014-01-06 12:55:46 -08001116 // Descriptor for the class such as "java.lang.Class" or "[C". Lazily initialized by ComputeName
1117 HeapReference<String> name_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001118
1119 // Static fields
Ian Rogersef7d42f2014-01-06 12:55:46 -08001120 HeapReference<ObjectArray<ArtField>> sfields_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001121
1122 // The superclass, or NULL if this is java.lang.Object, an interface or primitive type.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001123 HeapReference<Class> super_class_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001124
1125 // If class verify fails, we must return same error on subsequent tries.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001126 HeapReference<Class> verify_error_class_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001127
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001128 // Virtual methods defined in this class; invoked through vtable.
Ian Rogers700a4022014-05-19 16:49:03 -07001129 HeapReference<ObjectArray<ArtMethod>> virtual_methods_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001130
1131 // Virtual method table (vtable), for use by "invoke-virtual". The vtable from the superclass is
1132 // copied in, and virtual methods from our class either replace those from the super or are
1133 // appended. For abstract classes, methods may be created in the vtable that aren't in
1134 // virtual_ methods_ for miranda methods.
Ian Rogers700a4022014-05-19 16:49:03 -07001135 HeapReference<ObjectArray<ArtMethod>> vtable_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001136
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001137 // Access flags; low 16 bits are defined by VM spec.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001138 uint32_t access_flags_;
1139
1140 // Total size of the Class instance; used when allocating storage on gc heap.
1141 // See also object_size_.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001142 uint32_t class_size_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001143
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001144 // Tid used to check for recursive <clinit> invocation.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001145 pid_t clinit_thread_id_;
1146
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001147 // ClassDef index in dex file, -1 if no class definition such as an array.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001148 // TODO: really 16bits
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001149 int32_t dex_class_def_idx_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001150
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001151 // Type index in dex file.
1152 // TODO: really 16bits
1153 int32_t dex_type_idx_;
1154
1155 // Number of instance fields that are object refs.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001156 uint32_t num_reference_instance_fields_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001157
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001158 // Number of static fields that are object refs,
Ian Rogersef7d42f2014-01-06 12:55:46 -08001159 uint32_t num_reference_static_fields_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001160
1161 // Total object size; used when allocating storage on gc heap.
1162 // (For interfaces and abstract classes this will be zero.)
1163 // See also class_size_.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001164 uint32_t object_size_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001165
Hiroshi Yamauchif0edfc32014-09-25 11:46:46 -07001166 // The lower 16 bits contains a Primitive::Type value. The upper 16
1167 // bits contains the size shift of the primitive type.
1168 uint32_t primitive_type_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001169
1170 // Bitmap of offsets of ifields.
1171 uint32_t reference_instance_offsets_;
1172
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001173 // State of class initialization.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001174 Status status_;
1175
1176 // TODO: ?
1177 // initiating class loader list
1178 // NOTE: for classes with low serialNumber, these are unused, and the
1179 // values are kept in a table in gDvm.
1180 // InitiatingLoaderList initiating_loader_list_;
1181
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001182 // The following data exist in real class objects.
1183 // Embedded Imtable, for class object that's not an interface, fixed size.
Ian Rogers03b6eaf2014-10-28 09:34:57 -07001184 // ImTableEntry embedded_imtable_[0];
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001185 // Embedded Vtable, for class object that's not an interface, variable size.
Ian Rogers03b6eaf2014-10-28 09:34:57 -07001186 // VTableEntry embedded_vtable_[0];
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001187 // Static fields, variable size.
Ian Rogers03b6eaf2014-10-28 09:34:57 -07001188 // uint32_t fields_[0];
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001189
1190 // java.lang.Class
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -07001191 static GcRoot<Class> java_lang_Class_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001192
1193 friend struct art::ClassOffsets; // for verifying offset information
1194 DISALLOW_IMPLICIT_CONSTRUCTORS(Class);
1195};
1196
1197std::ostream& operator<<(std::ostream& os, const Class::Status& rhs);
1198
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001199} // namespace mirror
1200} // namespace art
1201
Brian Carlstromfc0e3212013-07-17 14:40:12 -07001202#endif // ART_RUNTIME_MIRROR_CLASS_H_