blob: 6a7faaaf34f3a6fa5891a1be8063466a72a53e1b [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
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080032namespace art {
33
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080034struct ClassOffsets;
Andreas Gampe5a4b8a22014-09-11 08:30:08 -070035template<class T> class Handle;
Mathieu Chartierbf99f772014-08-23 16:37:27 -070036template<class T> class Handle;
Ian Rogersd91d6d62013-09-25 20:26:14 -070037class Signature;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080038class StringPiece;
Mathieu Chartier2d2621a2014-10-23 16:48:06 -070039template<size_t kNumReferences> class PACKED(4) StackHandleScope;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080040
41namespace mirror {
42
Brian Carlstromea46f952013-07-30 01:26:50 -070043class ArtField;
Mingyao Yang98d1cc82014-05-15 17:02:16 -070044class ArtMethod;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080045class ClassLoader;
46class DexCache;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080047class IfTable;
48
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080049// C++ mirror of java.lang.Class
Mingyao Yang98d1cc82014-05-15 17:02:16 -070050class MANAGED Class FINAL : public Object {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080051 public:
Ian Rogerscdc1aaf2014-10-09 13:21:38 -070052 // A magic value for reference_instance_offsets_. Ignore the bits and walk the super chain when
53 // this is the value.
54 // [This is an unlikely "natural" value, since it would be 30 non-ref instance fields followed by
55 // 2 ref instance fields.]
56 static constexpr uint32_t kClassWalkSuper = 0xC0000000;
57
Mingyao Yang98d1cc82014-05-15 17:02:16 -070058 // Interface method table size. Increasing this value reduces the chance of two interface methods
59 // colliding in the interface method table but increases the size of classes that implement
60 // (non-marker) interfaces.
61 static constexpr size_t kImtSize = 64;
62
63 // imtable entry embedded in class object.
64 struct MANAGED ImTableEntry {
65 HeapReference<ArtMethod> method;
66 };
67
68 // vtable entry embedded in class object.
69 struct MANAGED VTableEntry {
70 HeapReference<ArtMethod> method;
71 };
72
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080073 // Class Status
74 //
Mingyao Yang46f0e972014-09-10 15:16:19 -070075 // kStatusRetired: Class that's temporarily used till class linking time
76 // has its (vtable) size figured out and has been cloned to one with the
77 // right size which will be the one used later. The old one is retired and
78 // will be gc'ed once all refs to the class point to the newly
79 // cloned version.
80 //
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080081 // kStatusNotReady: If a Class cannot be found in the class table by
82 // FindClass, it allocates an new one with AllocClass in the
83 // kStatusNotReady and calls LoadClass. Note if it does find a
84 // class, it may not be kStatusResolved and it will try to push it
85 // forward toward kStatusResolved.
86 //
87 // kStatusIdx: LoadClass populates with Class with information from
88 // the DexFile, moving the status to kStatusIdx, indicating that the
89 // Class value in super_class_ has not been populated. The new Class
90 // can then be inserted into the classes table.
91 //
92 // kStatusLoaded: After taking a lock on Class, the ClassLinker will
93 // attempt to move a kStatusIdx class forward to kStatusLoaded by
94 // using ResolveClass to initialize the super_class_ and ensuring the
95 // interfaces are resolved.
96 //
Mingyao Yang98d1cc82014-05-15 17:02:16 -070097 // kStatusResolving: Class is just cloned with the right size from
98 // temporary class that's acting as a placeholder for linking. The old
99 // class will be retired. New class is set to this status first before
100 // moving on to being resolved.
101 //
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800102 // kStatusResolved: Still holding the lock on Class, the ClassLinker
103 // shows linking is complete and fields of the Class populated by making
104 // it kStatusResolved. Java allows circularities of the form where a super
105 // class has a field that is of the type of the sub class. We need to be able
106 // to fully resolve super classes while resolving types for fields.
107 //
108 // kStatusRetryVerificationAtRuntime: The verifier sets a class to
109 // this state if it encounters a soft failure at compile time. This
110 // often happens when there are unresolved classes in other dex
111 // files, and this status marks a class as needing to be verified
112 // again at runtime.
113 //
114 // TODO: Explain the other states
115 enum Status {
Brian Carlstromf3978662014-09-11 12:21:04 -0700116 kStatusRetired = -2, // Retired, should not be used. Use the newly cloned one instead.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800117 kStatusError = -1,
118 kStatusNotReady = 0,
119 kStatusIdx = 1, // Loaded, DEX idx in super_class_type_idx_ and interfaces_type_idx_.
120 kStatusLoaded = 2, // DEX idx values resolved.
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700121 kStatusResolving = 3, // Just cloned from temporary class object.
122 kStatusResolved = 4, // Part of linking.
123 kStatusVerifying = 5, // In the process of being verified.
124 kStatusRetryVerificationAtRuntime = 6, // Compile time verification failed, retry at runtime.
125 kStatusVerifyingAtRuntime = 7, // Retrying verification at runtime.
126 kStatusVerified = 8, // Logically part of linking; done pre-init.
127 kStatusInitializing = 9, // Class init in progress.
128 kStatusInitialized = 10, // Ready to go.
129 kStatusMax = 11,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800130 };
131
Mathieu Chartier4e305412014-02-19 10:54:44 -0800132 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800133 Status GetStatus() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800134 COMPILE_ASSERT(sizeof(Status) == sizeof(uint32_t), size_of_status_not_uint32);
Ian Rogers03dbc042014-06-02 14:24:56 -0700135 return static_cast<Status>(
136 GetField32Volatile<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, status_)));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800137 }
138
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700139 void SetStatus(Status new_status, Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800140
Ian Rogers5ddb4102014-01-07 08:58:46 -0800141 static MemberOffset StatusOffset() {
142 return OFFSET_OF_OBJECT_MEMBER(Class, status_);
143 }
144
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700145 // Returns true if the class has been retired.
146 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
147 bool IsRetired() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
148 return GetStatus<kVerifyFlags>() == kStatusRetired;
149 }
150
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800151 // Returns true if the class has failed to link.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800152 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800153 bool IsErroneous() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800154 return GetStatus<kVerifyFlags>() == kStatusError;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800155 }
156
157 // Returns true if the class has been loaded.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800158 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800159 bool IsIdxLoaded() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800160 return GetStatus<kVerifyFlags>() >= kStatusIdx;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800161 }
162
163 // Returns true if the class has been loaded.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800164 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800165 bool IsLoaded() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800166 return GetStatus<kVerifyFlags>() >= kStatusLoaded;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800167 }
168
169 // Returns true if the class has been linked.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800170 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800171 bool IsResolved() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800172 return GetStatus<kVerifyFlags>() >= kStatusResolved;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800173 }
174
175 // Returns true if the class was compile-time verified.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800176 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800177 bool IsCompileTimeVerified() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800178 return GetStatus<kVerifyFlags>() >= kStatusRetryVerificationAtRuntime;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800179 }
180
181 // Returns true if the class has been verified.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800182 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800183 bool IsVerified() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800184 return GetStatus<kVerifyFlags>() >= kStatusVerified;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800185 }
186
187 // Returns true if the class is initializing.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800188 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800189 bool IsInitializing() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800190 return GetStatus<kVerifyFlags>() >= kStatusInitializing;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800191 }
192
193 // Returns true if the class is initialized.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800194 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800195 bool IsInitialized() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800196 return GetStatus<kVerifyFlags>() == kStatusInitialized;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800197 }
198
Mathieu Chartier4e305412014-02-19 10:54:44 -0800199 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700200 ALWAYS_INLINE uint32_t GetAccessFlags() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800201
Andreas Gampe48498592014-09-10 19:48:05 -0700202 void SetAccessFlags(uint32_t new_access_flags) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800203
204 // Returns true if the class is an interface.
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700205 ALWAYS_INLINE bool IsInterface() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800206 return (GetAccessFlags() & kAccInterface) != 0;
207 }
208
209 // Returns true if the class is declared public.
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700210 ALWAYS_INLINE bool IsPublic() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800211 return (GetAccessFlags() & kAccPublic) != 0;
212 }
213
214 // Returns true if the class is declared final.
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700215 ALWAYS_INLINE bool IsFinal() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800216 return (GetAccessFlags() & kAccFinal) != 0;
217 }
218
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700219 ALWAYS_INLINE bool IsFinalizable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800220 return (GetAccessFlags() & kAccClassIsFinalizable) != 0;
221 }
222
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700223 ALWAYS_INLINE void SetFinalizable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700224 uint32_t flags = GetField32(OFFSET_OF_OBJECT_MEMBER(Class, access_flags_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800225 SetAccessFlags(flags | kAccClassIsFinalizable);
226 }
227
228 // Returns true if the class is abstract.
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700229 ALWAYS_INLINE bool IsAbstract() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800230 return (GetAccessFlags() & kAccAbstract) != 0;
231 }
232
233 // Returns true if the class is an annotation.
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700234 ALWAYS_INLINE bool IsAnnotation() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800235 return (GetAccessFlags() & kAccAnnotation) != 0;
236 }
237
238 // Returns true if the class is synthetic.
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700239 ALWAYS_INLINE bool IsSynthetic() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800240 return (GetAccessFlags() & kAccSynthetic) != 0;
241 }
242
Ian Rogers7b078e82014-09-10 14:44:24 -0700243 // Returns true if the class can avoid access checks.
244 bool IsPreverified() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
245 return (GetAccessFlags() & kAccPreverified) != 0;
246 }
247
248 void SetPreverified() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
249 uint32_t flags = GetField32(OFFSET_OF_OBJECT_MEMBER(Class, access_flags_));
250 SetAccessFlags(flags | kAccPreverified);
251 }
252
Mathieu Chartier4e305412014-02-19 10:54:44 -0800253 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Fred Shih4ee7a662014-07-11 09:59:27 -0700254 bool IsTypeOfReferenceClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800255 return (GetAccessFlags<kVerifyFlags>() & kAccClassIsReference) != 0;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800256 }
257
Mathieu Chartier4e305412014-02-19 10:54:44 -0800258 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800259 bool IsWeakReferenceClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800260 return (GetAccessFlags<kVerifyFlags>() & kAccClassIsWeakReference) != 0;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800261 }
262
Mathieu Chartier4e305412014-02-19 10:54:44 -0800263 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800264 bool IsSoftReferenceClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800265 return (GetAccessFlags<kVerifyFlags>() & kAccReferenceFlagsMask) == kAccClassIsReference;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800266 }
267
Mathieu Chartier4e305412014-02-19 10:54:44 -0800268 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800269 bool IsFinalizerReferenceClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800270 return (GetAccessFlags<kVerifyFlags>() & kAccClassIsFinalizerReference) != 0;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800271 }
272
Mathieu Chartier4e305412014-02-19 10:54:44 -0800273 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800274 bool IsPhantomReferenceClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800275 return (GetAccessFlags<kVerifyFlags>() & kAccClassIsPhantomReference) != 0;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800276 }
277
Ian Rogers04f94f42013-06-10 15:09:26 -0700278 // Can references of this type be assigned to by things of another type? For non-array types
279 // this is a matter of whether sub-classes may exist - which they can't if the type is final.
280 // For array classes, where all the classes are final due to there being no sub-classes, an
281 // Object[] may be assigned to by a String[] but a String[] may not be assigned to by other
282 // types as the component is final.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800283 bool CannotBeAssignedFromOtherTypes() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers04f94f42013-06-10 15:09:26 -0700284 if (!IsArrayClass()) {
285 return IsFinal();
286 } else {
287 Class* component = GetComponentType();
288 if (component->IsPrimitive()) {
Ian Rogersa9a82542013-10-04 11:17:26 -0700289 return true;
Ian Rogers04f94f42013-06-10 15:09:26 -0700290 } else {
291 return component->CannotBeAssignedFromOtherTypes();
292 }
293 }
294 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800295
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700296 // Returns true if this class is the placeholder and should retire and
297 // be replaced with a class with the right size for embedded imt/vtable.
298 bool IsTemp() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
299 Status s = GetStatus();
300 return s < Status::kStatusResolving && ShouldHaveEmbeddedImtAndVTable();
301 }
302
Ian Rogersef7d42f2014-01-06 12:55:46 -0800303 String* GetName() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); // Returns the cached name.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800304 void SetName(String* name) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); // Sets the cached name.
305 // Computes the name, then sets the cached value.
Mathieu Chartierf8322842014-05-16 10:59:25 -0700306 static String* ComputeName(Handle<Class> h_this) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800307
Mathieu Chartierc2f4d022014-03-03 16:11:42 -0800308 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier4e305412014-02-19 10:54:44 -0800309 bool IsProxyClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800310 // Read access flags without using getter as whether something is a proxy can be check in
311 // any loaded state
312 // TODO: switch to a check if the super class is java.lang.reflect.Proxy?
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700313 uint32_t access_flags = GetField32<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, access_flags_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800314 return (access_flags & kAccClassIsProxy) != 0;
315 }
316
Mathieu Chartier4e305412014-02-19 10:54:44 -0800317 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700318 Primitive::Type GetPrimitiveType() ALWAYS_INLINE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800319
Ian Rogersef7d42f2014-01-06 12:55:46 -0800320 void SetPrimitiveType(Primitive::Type new_type) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800321 DCHECK_EQ(sizeof(Primitive::Type), sizeof(int32_t));
Hiroshi Yamauchif0edfc32014-09-25 11:46:46 -0700322 int32_t v32 = static_cast<int32_t>(new_type);
323 DCHECK_EQ(v32 & 0xFFFF, v32) << "upper 16 bits aren't zero";
324 // Store the component size shift in the upper 16 bits.
325 v32 |= Primitive::ComponentSizeShift(new_type) << 16;
326 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, primitive_type_), v32);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800327 }
328
Hiroshi Yamauchif0edfc32014-09-25 11:46:46 -0700329 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
330 size_t GetPrimitiveTypeSizeShift() ALWAYS_INLINE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
331
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800332 // Returns true if the class is a primitive type.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800333 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800334 bool IsPrimitive() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800335 return GetPrimitiveType<kVerifyFlags>() != Primitive::kPrimNot;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800336 }
337
Mathieu Chartier4e305412014-02-19 10:54:44 -0800338 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800339 bool IsPrimitiveBoolean() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800340 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimBoolean;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800341 }
342
Mathieu Chartier4e305412014-02-19 10:54:44 -0800343 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800344 bool IsPrimitiveByte() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800345 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimByte;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800346 }
347
Mathieu Chartier4e305412014-02-19 10:54:44 -0800348 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800349 bool IsPrimitiveChar() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800350 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimChar;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800351 }
352
Mathieu Chartier4e305412014-02-19 10:54:44 -0800353 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800354 bool IsPrimitiveShort() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800355 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimShort;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800356 }
357
Mathieu Chartier4e305412014-02-19 10:54:44 -0800358 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800359 bool IsPrimitiveInt() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800360 return GetPrimitiveType() == Primitive::kPrimInt;
361 }
362
Mathieu Chartier4e305412014-02-19 10:54:44 -0800363 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800364 bool IsPrimitiveLong() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800365 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimLong;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800366 }
367
Mathieu Chartier4e305412014-02-19 10:54:44 -0800368 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800369 bool IsPrimitiveFloat() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800370 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimFloat;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800371 }
372
Mathieu Chartier4e305412014-02-19 10:54:44 -0800373 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800374 bool IsPrimitiveDouble() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800375 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimDouble;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800376 }
377
Mathieu Chartier4e305412014-02-19 10:54:44 -0800378 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800379 bool IsPrimitiveVoid() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800380 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimVoid;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800381 }
382
Mathieu Chartier4e305412014-02-19 10:54:44 -0800383 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800384 bool IsPrimitiveArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800385 return IsArrayClass<kVerifyFlags>() &&
386 GetComponentType<static_cast<VerifyObjectFlags>(kVerifyFlags & ~kVerifyThis)>()->
387 IsPrimitive();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800388 }
389
390 // Depth of class from java.lang.Object
Ian Rogersef7d42f2014-01-06 12:55:46 -0800391 uint32_t Depth() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
392 uint32_t depth = 0;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800393 for (Class* klass = this; klass->GetSuperClass() != NULL; klass = klass->GetSuperClass()) {
394 depth++;
395 }
396 return depth;
397 }
398
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700399 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
400 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800401 bool IsArrayClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700402 return GetComponentType<kVerifyFlags, kReadBarrierOption>() != NULL;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800403 }
404
Hiroshi Yamauchi25023c72014-05-09 11:45:53 -0700405 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
406 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800407 bool IsClassClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800408
Hiroshi Yamauchibd0fb612014-05-20 13:46:00 -0700409 bool IsStringClass() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800410
Ian Rogersef7d42f2014-01-06 12:55:46 -0800411 bool IsThrowableClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800412
Hiroshi Yamauchi4f1ebc22014-06-25 14:30:41 -0700413 template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Hiroshi Yamauchibd0fb612014-05-20 13:46:00 -0700414 bool IsArtFieldClass() const 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>
Hiroshi Yamauchibd0fb612014-05-20 13:46:00 -0700417 bool IsArtMethodClass() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800418
Fred Shih4ee7a662014-07-11 09:59:27 -0700419 template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
420 bool IsReferenceClass() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
421
Ian Rogersa9a82542013-10-04 11:17:26 -0700422 static MemberOffset ComponentTypeOffset() {
423 return OFFSET_OF_OBJECT_MEMBER(Class, component_type_);
424 }
425
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700426 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
427 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800428 Class* GetComponentType() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700429 return GetFieldObject<Class, kVerifyFlags, kReadBarrierOption>(ComponentTypeOffset());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800430 }
431
432 void SetComponentType(Class* new_component_type) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
433 DCHECK(GetComponentType() == NULL);
434 DCHECK(new_component_type != NULL);
Sebastien Hertzee1d79a2014-02-21 15:46:30 +0100435 // Component type is invariant: use non-transactional mode without check.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700436 SetFieldObject<false, false>(ComponentTypeOffset(), new_component_type);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800437 }
438
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700439 template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800440 size_t GetComponentSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Hiroshi Yamauchif0edfc32014-09-25 11:46:46 -0700441 return 1U << GetComponentSizeShift();
442 }
443
444 template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
445 size_t GetComponentSizeShift() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
446 return GetComponentType<kDefaultVerifyFlags, kReadBarrierOption>()->GetPrimitiveTypeSizeShift();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800447 }
448
Ian Rogersef7d42f2014-01-06 12:55:46 -0800449 bool IsObjectClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800450 return !IsPrimitive() && GetSuperClass() == NULL;
451 }
Ian Rogers68d8b422014-07-17 11:09:10 -0700452
453 bool IsInstantiableNonArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
454 return !IsPrimitive() && !IsInterface() && !IsAbstract() && !IsArrayClass();
455 }
456
Ian Rogersef7d42f2014-01-06 12:55:46 -0800457 bool IsInstantiable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers68d8b422014-07-17 11:09:10 -0700458 return (!IsPrimitive() && !IsInterface() && !IsAbstract()) ||
459 ((IsAbstract()) && IsArrayClass());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800460 }
461
Mathieu Chartier4e305412014-02-19 10:54:44 -0800462 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800463 bool IsObjectArrayClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800464 return GetComponentType<kVerifyFlags>() != nullptr && !GetComponentType<kVerifyFlags>()->IsPrimitive();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800465 }
466
467 // Creates a raw object instance but does not invoke the default constructor.
Mathieu Chartier8668c3c2014-04-24 16:48:11 -0700468 template<bool kIsInstrumented, bool kCheckAddFinalizer = true>
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800469 ALWAYS_INLINE Object* Alloc(Thread* self, gc::AllocatorType allocator_type)
470 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -0700471
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800472 Object* AllocObject(Thread* self)
473 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
474 Object* AllocNonMovableObject(Thread* self)
475 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800476
Hiroshi Yamauchi25023c72014-05-09 11:45:53 -0700477 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
478 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800479 bool IsVariableSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800480 // Classes and arrays vary in size, and so the object_size_ field cannot
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700481 // be used to Get their instance size
Hiroshi Yamauchi25023c72014-05-09 11:45:53 -0700482 return IsClassClass<kVerifyFlags, kReadBarrierOption>() ||
483 IsArrayClass<kVerifyFlags, kReadBarrierOption>();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800484 }
485
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700486 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
487 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800488 uint32_t SizeOf() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700489 return GetField32<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, class_size_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800490 }
491
Mathieu Chartier4e305412014-02-19 10:54:44 -0800492 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800493 uint32_t GetClassSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700494 return GetField32<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, class_size_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800495 }
496
Ian Rogersef7d42f2014-01-06 12:55:46 -0800497 void SetClassSize(uint32_t new_class_size)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800498 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
499
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700500 // Compute how many bytes would be used a class with the given elements.
501 static uint32_t ComputeClassSize(bool has_embedded_tables,
502 uint32_t num_vtable_entries,
Fred Shih37f05ef2014-07-16 18:38:08 -0700503 uint32_t num_8bit_static_fields,
504 uint32_t num_16bit_static_fields,
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700505 uint32_t num_32bit_static_fields,
506 uint32_t num_64bit_static_fields,
507 uint32_t num_ref_static_fields);
508
509 // The size of java.lang.Class.class.
510 static uint32_t ClassClassSize() {
511 // The number of vtable entries in java.lang.Class.
Brian Carlstromb144fce2014-10-16 22:02:23 -0700512 uint32_t vtable_entries = Object::kVTableLength + 66;
Fred Shih37f05ef2014-07-16 18:38:08 -0700513 return ComputeClassSize(true, vtable_entries, 0, 0, 0, 1, 0);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700514 }
515
516 // The size of a java.lang.Class representing a primitive such as int.class.
517 static uint32_t PrimitiveClassSize() {
Fred Shih37f05ef2014-07-16 18:38:08 -0700518 return ComputeClassSize(false, 0, 0, 0, 0, 0, 0);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700519 }
520
Hiroshi Yamauchi25023c72014-05-09 11:45:53 -0700521 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
522 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800523 uint32_t GetObjectSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800524
Ian Rogersef7d42f2014-01-06 12:55:46 -0800525 void SetObjectSize(uint32_t new_object_size) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800526 DCHECK(!IsVariableSize());
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100527 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700528 return SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, object_size_), new_object_size);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800529 }
530
531 // Returns true if this class is in the same packages as that class.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800532 bool IsInSamePackage(Class* that) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800533
534 static bool IsInSamePackage(const StringPiece& descriptor1, const StringPiece& descriptor2);
535
536 // Returns true if this class can access that class.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800537 bool CanAccess(Class* that) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800538 return that->IsPublic() || this->IsInSamePackage(that);
539 }
540
541 // Can this class access a member in the provided class with the provided member access flags?
542 // Note that access to the class isn't checked in case the declaring class is protected and the
543 // method has been exposed by a public sub-class
Ian Rogersef7d42f2014-01-06 12:55:46 -0800544 bool CanAccessMember(Class* access_to, uint32_t member_flags)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800545 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
546 // Classes can access all of their own members
547 if (this == access_to) {
548 return true;
549 }
550 // Public members are trivially accessible
551 if (member_flags & kAccPublic) {
552 return true;
553 }
554 // Private members are trivially not accessible
555 if (member_flags & kAccPrivate) {
556 return false;
557 }
558 // Check for protected access from a sub-class, which may or may not be in the same package.
559 if (member_flags & kAccProtected) {
Andreas Gampe13f8a162014-08-08 19:55:37 -0700560 if (!this->IsInterface() && this->IsSubClass(access_to)) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800561 return true;
562 }
563 }
564 // Allow protected access from other classes in the same package.
565 return this->IsInSamePackage(access_to);
566 }
567
Vladimir Marko23a28212014-01-09 19:24:37 +0000568 // Can this class access a resolved field?
569 // Note that access to field's class is checked and this may require looking up the class
570 // referenced by the FieldId in the DexFile in case the declaring class is inaccessible.
Vladimir Marko23a28212014-01-09 19:24:37 +0000571 bool CanAccessResolvedField(Class* access_to, ArtField* field,
Ian Rogersef7d42f2014-01-06 12:55:46 -0800572 DexCache* dex_cache, uint32_t field_idx)
Vladimir Marko89786432014-01-31 15:03:55 +0000573 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
574 bool CheckResolvedFieldAccess(Class* access_to, ArtField* field,
575 uint32_t field_idx)
576 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Vladimir Marko23a28212014-01-09 19:24:37 +0000577
578 // Can this class access a resolved method?
579 // Note that access to methods's class is checked and this may require looking up the class
580 // referenced by the MethodId in the DexFile in case the declaring class is inaccessible.
Vladimir Marko23a28212014-01-09 19:24:37 +0000581 bool CanAccessResolvedMethod(Class* access_to, ArtMethod* resolved_method,
Ian Rogersef7d42f2014-01-06 12:55:46 -0800582 DexCache* dex_cache, uint32_t method_idx)
Vladimir Marko89786432014-01-31 15:03:55 +0000583 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
584 template <InvokeType throw_invoke_type>
585 bool CheckResolvedMethodAccess(Class* access_to, ArtMethod* resolved_method,
586 uint32_t method_idx)
587 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Vladimir Marko23a28212014-01-09 19:24:37 +0000588
Ian Rogersef7d42f2014-01-06 12:55:46 -0800589 bool IsSubClass(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800590
591 // Can src be assigned to this class? For example, String can be assigned to Object (by an
592 // upcast), however, an Object cannot be assigned to a String as a potentially exception throwing
593 // downcast would be necessary. Similarly for interfaces, a class that implements (or an interface
594 // that extends) another can be assigned to its parent, but not vice-versa. All Classes may assign
595 // to themselves. Classes for primitive types may not assign to each other.
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700596 ALWAYS_INLINE bool IsAssignableFrom(Class* src) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800597 DCHECK(src != NULL);
598 if (this == src) {
599 // Can always assign to things of the same type.
600 return true;
601 } else if (IsObjectClass()) {
602 // Can assign any reference to java.lang.Object.
603 return !src->IsPrimitive();
604 } else if (IsInterface()) {
605 return src->Implements(this);
606 } else if (src->IsArrayClass()) {
607 return IsAssignableFromArray(src);
608 } else {
609 return !src->IsInterface() && src->IsSubClass(this);
610 }
611 }
612
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700613 ALWAYS_INLINE Class* GetSuperClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800614
615 void SetSuperClass(Class *new_super_class) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800616 // Super class is assigned once, except during class linker initialization.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700617 Class* old_super_class = GetFieldObject<Class>(OFFSET_OF_OBJECT_MEMBER(Class, super_class_));
Ian Rogersef7d42f2014-01-06 12:55:46 -0800618 DCHECK(old_super_class == nullptr || old_super_class == new_super_class);
619 DCHECK(new_super_class != nullptr);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700620 SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(Class, super_class_), new_super_class);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800621 }
622
Ian Rogersef7d42f2014-01-06 12:55:46 -0800623 bool HasSuperClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800624 return GetSuperClass() != NULL;
625 }
626
627 static MemberOffset SuperClassOffset() {
628 return MemberOffset(OFFSETOF_MEMBER(Class, super_class_));
629 }
630
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700631 ClassLoader* GetClassLoader() ALWAYS_INLINE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800632
633 void SetClassLoader(ClassLoader* new_cl) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
634
635 static MemberOffset DexCacheOffset() {
636 return MemberOffset(OFFSETOF_MEMBER(Class, dex_cache_));
637 }
638
639 enum {
640 kDumpClassFullDetail = 1,
641 kDumpClassClassLoader = (1 << 1),
642 kDumpClassInitialized = (1 << 2),
643 };
644
Ian Rogersef7d42f2014-01-06 12:55:46 -0800645 void DumpClass(std::ostream& os, int flags) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800646
Mathieu Chartierc2f4d022014-03-03 16:11:42 -0800647 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800648 DexCache* GetDexCache() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800649
650 void SetDexCache(DexCache* new_dex_cache) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
651
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700652 ALWAYS_INLINE ObjectArray<ArtMethod>* GetDirectMethods()
653 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800654
Brian Carlstromea46f952013-07-30 01:26:50 -0700655 void SetDirectMethods(ObjectArray<ArtMethod>* new_direct_methods)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800656 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
657
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700658 ALWAYS_INLINE ArtMethod* GetDirectMethod(int32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800659
Brian Carlstromea46f952013-07-30 01:26:50 -0700660 void SetDirectMethod(uint32_t i, ArtMethod* f) // TODO: uint16_t
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800661 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
662
663 // Returns the number of static, private, and constructor methods.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800664 uint32_t NumDirectMethods() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800665
Mathieu Chartier4e305412014-02-19 10:54:44 -0800666 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700667 ALWAYS_INLINE ObjectArray<ArtMethod>* GetVirtualMethods()
668 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800669
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700670 ALWAYS_INLINE void SetVirtualMethods(ObjectArray<ArtMethod>* new_virtual_methods)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800671 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
672
673 // Returns the number of non-inherited virtual methods.
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700674 ALWAYS_INLINE uint32_t NumVirtualMethods() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800675
Mathieu Chartier4e305412014-02-19 10:54:44 -0800676 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800677 ArtMethod* GetVirtualMethod(uint32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800678
Ian Rogersef7d42f2014-01-06 12:55:46 -0800679 ArtMethod* GetVirtualMethodDuringLinking(uint32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800680
Brian Carlstromea46f952013-07-30 01:26:50 -0700681 void SetVirtualMethod(uint32_t i, ArtMethod* f) // TODO: uint16_t
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800682 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
683
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700684 ALWAYS_INLINE ObjectArray<ArtMethod>* GetVTable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800685
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700686 ALWAYS_INLINE ObjectArray<ArtMethod>* GetVTableDuringLinking()
687 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800688
Brian Carlstromea46f952013-07-30 01:26:50 -0700689 void SetVTable(ObjectArray<ArtMethod>* new_vtable)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800690 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
691
692 static MemberOffset VTableOffset() {
693 return OFFSET_OF_OBJECT_MEMBER(Class, vtable_);
694 }
695
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700696 static MemberOffset EmbeddedImTableOffset() {
697 return MemberOffset(sizeof(Class));
698 }
699
Mingyao Yang2cdbad72014-07-16 10:44:41 -0700700 static MemberOffset EmbeddedVTableLengthOffset() {
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700701 return MemberOffset(sizeof(Class) + kImtSize * sizeof(mirror::Class::ImTableEntry));
702 }
703
Mingyao Yang2cdbad72014-07-16 10:44:41 -0700704 static MemberOffset EmbeddedVTableOffset() {
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700705 return MemberOffset(sizeof(Class) + kImtSize * sizeof(ImTableEntry) + sizeof(int32_t));
Mingyao Yang2cdbad72014-07-16 10:44:41 -0700706 }
707
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700708 bool ShouldHaveEmbeddedImtAndVTable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
709 return IsInstantiable();
710 }
711
Mingyao Yang2cdbad72014-07-16 10:44:41 -0700712 bool HasVTable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
713
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700714 ArtMethod* GetEmbeddedImTableEntry(uint32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
715
716 void SetEmbeddedImTableEntry(uint32_t i, ArtMethod* method) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
717
Mingyao Yang2cdbad72014-07-16 10:44:41 -0700718 int32_t GetVTableLength() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
719
720 ArtMethod* GetVTableEntry(uint32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
721
722 int32_t GetEmbeddedVTableLength() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
723
724 void SetEmbeddedVTableLength(int32_t len) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
725
726 ArtMethod* GetEmbeddedVTableEntry(uint32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
727
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700728 void SetEmbeddedVTableEntry(uint32_t i, ArtMethod* method) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
729
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700730 void PopulateEmbeddedImtAndVTable(StackHandleScope<kImtSize>* imt_handle_scope)
731 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700732
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800733 // Given a method implemented by this class but potentially from a super class, return the
734 // specific implementation method for this class.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800735 ArtMethod* FindVirtualMethodForVirtual(ArtMethod* method)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800736 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
737
738 // Given a method implemented by this class' super class, return the specific implementation
739 // method for this class.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800740 ArtMethod* FindVirtualMethodForSuper(ArtMethod* method)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800741 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
742
743 // Given a method implemented by this class, but potentially from a
744 // super class or interface, return the specific implementation
745 // method for this class.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800746 ArtMethod* FindVirtualMethodForInterface(ArtMethod* method)
Ian Rogers1ffa32f2013-02-05 18:29:08 -0800747 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) ALWAYS_INLINE;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800748
Ian Rogersef7d42f2014-01-06 12:55:46 -0800749 ArtMethod* FindVirtualMethodForVirtualOrInterface(ArtMethod* method)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700750 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
751
Brian Carlstrom004644f2014-06-18 08:34:01 -0700752 ArtMethod* FindInterfaceMethod(const StringPiece& name, const StringPiece& signature)
753 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
754
Ian Rogersef7d42f2014-01-06 12:55:46 -0800755 ArtMethod* FindInterfaceMethod(const StringPiece& name, const Signature& signature)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800756 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
757
Ian Rogersef7d42f2014-01-06 12:55:46 -0800758 ArtMethod* FindInterfaceMethod(const DexCache* dex_cache, uint32_t dex_method_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800759 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
760
Ian Rogersef7d42f2014-01-06 12:55:46 -0800761 ArtMethod* FindDeclaredDirectMethod(const StringPiece& name, const StringPiece& signature)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800762 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
763
Ian Rogersef7d42f2014-01-06 12:55:46 -0800764 ArtMethod* FindDeclaredDirectMethod(const StringPiece& name, const Signature& signature)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700765 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
766
Ian Rogersef7d42f2014-01-06 12:55:46 -0800767 ArtMethod* FindDeclaredDirectMethod(const DexCache* dex_cache, uint32_t dex_method_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800768 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
769
Ian Rogersef7d42f2014-01-06 12:55:46 -0800770 ArtMethod* FindDirectMethod(const StringPiece& name, const StringPiece& signature)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800771 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
772
Ian Rogersef7d42f2014-01-06 12:55:46 -0800773 ArtMethod* FindDirectMethod(const StringPiece& name, const Signature& signature)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700774 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
775
Ian Rogersef7d42f2014-01-06 12:55:46 -0800776 ArtMethod* FindDirectMethod(const DexCache* dex_cache, uint32_t dex_method_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800777 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
778
Ian Rogersef7d42f2014-01-06 12:55:46 -0800779 ArtMethod* FindDeclaredVirtualMethod(const StringPiece& name, const StringPiece& signature)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700780 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
781
Ian Rogersef7d42f2014-01-06 12:55:46 -0800782 ArtMethod* FindDeclaredVirtualMethod(const StringPiece& name, const Signature& signature)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700783 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
784
Ian Rogersef7d42f2014-01-06 12:55:46 -0800785 ArtMethod* FindDeclaredVirtualMethod(const DexCache* dex_cache, uint32_t dex_method_idx)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700786 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
787
Ian Rogersef7d42f2014-01-06 12:55:46 -0800788 ArtMethod* FindVirtualMethod(const StringPiece& name, const StringPiece& signature)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700789 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
790
Ian Rogersef7d42f2014-01-06 12:55:46 -0800791 ArtMethod* FindVirtualMethod(const StringPiece& name, const Signature& 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* FindVirtualMethod(const DexCache* dex_cache, uint32_t dex_method_idx)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700795 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
796
Ian Rogersef7d42f2014-01-06 12:55:46 -0800797 ArtMethod* FindClassInitializer() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersd91d6d62013-09-25 20:26:14 -0700798
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700799 ALWAYS_INLINE int32_t GetIfTableCount() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800800
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700801 ALWAYS_INLINE IfTable* GetIfTable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800802
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700803 ALWAYS_INLINE void SetIfTable(IfTable* new_iftable) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800804
805 // Get instance fields of the class (See also GetSFields).
Ian Rogersef7d42f2014-01-06 12:55:46 -0800806 ObjectArray<ArtField>* GetIFields() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800807
Brian Carlstromea46f952013-07-30 01:26:50 -0700808 void SetIFields(ObjectArray<ArtField>* new_ifields) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800809
Ian Rogersef7d42f2014-01-06 12:55:46 -0800810 uint32_t NumInstanceFields() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800811
Ian Rogersef7d42f2014-01-06 12:55:46 -0800812 ArtField* GetInstanceField(uint32_t i) // TODO: uint16_t
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800813 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
814
Brian Carlstromea46f952013-07-30 01:26:50 -0700815 void SetInstanceField(uint32_t i, ArtField* f) // TODO: uint16_t
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800816 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
817
818 // Returns the number of instance fields containing reference types.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800819 uint32_t NumReferenceInstanceFields() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800820 DCHECK(IsResolved() || IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700821 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_instance_fields_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800822 }
823
Ian Rogersef7d42f2014-01-06 12:55:46 -0800824 uint32_t NumReferenceInstanceFieldsDuringLinking() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800825 DCHECK(IsLoaded() || IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700826 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_instance_fields_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800827 }
828
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700829 void SetNumReferenceInstanceFields(uint32_t new_num) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100830 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700831 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_instance_fields_), new_num);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800832 }
833
Mathieu Chartier4e305412014-02-19 10:54:44 -0800834 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700835 uint32_t GetReferenceInstanceOffsets() ALWAYS_INLINE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800836
837 void SetReferenceInstanceOffsets(uint32_t new_reference_offsets)
838 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
839
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800840 // Returns the number of static fields containing reference types.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800841 uint32_t NumReferenceStaticFields() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Hiroshi Yamauchif4c15a12014-10-20 16:56:58 -0700842 DCHECK(IsResolved() || IsErroneous()) << PrettyClass(this) << " status=" << GetStatus();
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700843 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_static_fields_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800844 }
845
Ian Rogersef7d42f2014-01-06 12:55:46 -0800846 uint32_t NumReferenceStaticFieldsDuringLinking() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700847 DCHECK(IsLoaded() || IsErroneous() || IsRetired());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700848 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_static_fields_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800849 }
850
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700851 void SetNumReferenceStaticFields(uint32_t new_num) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100852 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700853 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_static_fields_), new_num);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800854 }
855
856 // Gets the static fields of the class.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800857 ObjectArray<ArtField>* GetSFields() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800858
Brian Carlstromea46f952013-07-30 01:26:50 -0700859 void SetSFields(ObjectArray<ArtField>* new_sfields) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800860
Ian Rogersef7d42f2014-01-06 12:55:46 -0800861 uint32_t NumStaticFields() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800862
Ian Rogersef7d42f2014-01-06 12:55:46 -0800863 // TODO: uint16_t
864 ArtField* GetStaticField(uint32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800865
Ian Rogersef7d42f2014-01-06 12:55:46 -0800866 // TODO: uint16_t
867 void SetStaticField(uint32_t i, ArtField* f) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800868
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800869 // Find a static or instance field using the JLS resolution order
Mathieu Chartierf8322842014-05-16 10:59:25 -0700870 static ArtField* FindField(Thread* self, Handle<Class> klass, const StringPiece& name,
871 const StringPiece& type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800872 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
873
874 // Finds the given instance field in this class or a superclass.
Brian Carlstromea46f952013-07-30 01:26:50 -0700875 ArtField* FindInstanceField(const StringPiece& name, const StringPiece& type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800876 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
877
878 // Finds the given instance field in this class or a superclass, only searches classes that
879 // have the same dex cache.
Brian Carlstromea46f952013-07-30 01:26:50 -0700880 ArtField* FindInstanceField(const DexCache* dex_cache, uint32_t dex_field_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800881 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
882
Brian Carlstromea46f952013-07-30 01:26:50 -0700883 ArtField* FindDeclaredInstanceField(const StringPiece& name, const StringPiece& type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800884 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
885
Brian Carlstromea46f952013-07-30 01:26:50 -0700886 ArtField* FindDeclaredInstanceField(const DexCache* dex_cache, uint32_t dex_field_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800887 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
888
889 // Finds the given static field in this class or a superclass.
Mathieu Chartierf8322842014-05-16 10:59:25 -0700890 static ArtField* FindStaticField(Thread* self, Handle<Class> klass, const StringPiece& name,
891 const StringPiece& type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800892 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
893
894 // Finds the given static field in this class or superclass, only searches classes that
895 // have the same dex cache.
Mathieu Chartierf8322842014-05-16 10:59:25 -0700896 static ArtField* FindStaticField(Thread* self, Handle<Class> klass, const DexCache* dex_cache,
897 uint32_t dex_field_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800898 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
899
Brian Carlstromea46f952013-07-30 01:26:50 -0700900 ArtField* FindDeclaredStaticField(const StringPiece& name, const StringPiece& type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800901 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
902
Brian Carlstromea46f952013-07-30 01:26:50 -0700903 ArtField* FindDeclaredStaticField(const DexCache* dex_cache, uint32_t dex_field_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800904 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
905
Ian Rogersef7d42f2014-01-06 12:55:46 -0800906 pid_t GetClinitThreadId() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800907 DCHECK(IsIdxLoaded() || IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700908 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, clinit_thread_id_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800909 }
910
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700911 void SetClinitThreadId(pid_t new_clinit_thread_id) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800912
Ian Rogersef7d42f2014-01-06 12:55:46 -0800913 Class* GetVerifyErrorClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800914 // DCHECK(IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700915 return GetFieldObject<Class>(OFFSET_OF_OBJECT_MEMBER(Class, verify_error_class_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800916 }
917
Ian Rogersef7d42f2014-01-06 12:55:46 -0800918 uint16_t GetDexClassDefIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700919 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, dex_class_def_idx_));
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700920 }
921
Ian Rogersef7d42f2014-01-06 12:55:46 -0800922 void SetDexClassDefIndex(uint16_t class_def_idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100923 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700924 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, dex_class_def_idx_), class_def_idx);
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700925 }
926
Ian Rogersef7d42f2014-01-06 12:55:46 -0800927 uint16_t GetDexTypeIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700928 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, dex_type_idx_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800929 }
930
Ian Rogersef7d42f2014-01-06 12:55:46 -0800931 void SetDexTypeIndex(uint16_t type_idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100932 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700933 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, dex_type_idx_), type_idx);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800934 }
935
Hiroshi Yamauchi4f1ebc22014-06-25 14:30:41 -0700936 static Class* GetJavaLangClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -0700937 DCHECK(!java_lang_Class_.IsNull());
938 return java_lang_Class_.Read();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800939 }
940
941 // Can't call this SetClass or else gets called instead of Object::SetClass in places.
Hiroshi Yamauchi4f1ebc22014-06-25 14:30:41 -0700942 static void SetClassClass(Class* java_lang_Class) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800943 static void ResetClass();
Mathieu Chartier83c8ee02014-01-28 14:50:23 -0800944 static void VisitRoots(RootCallback* callback, void* arg)
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800945 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800946
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200947 // When class is verified, set the kAccPreverified flag on each method.
948 void SetPreverifiedFlagOnAllMethods() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
949
Mathieu Chartier407f7022014-02-18 14:37:05 -0800950 template <bool kVisitClass, typename Visitor>
951 void VisitReferences(mirror::Class* klass, const Visitor& visitor)
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700952 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
953
954 // Visit references within the embedded tables of the class.
955 // TODO: remove NO_THREAD_SAFETY_ANALYSIS when annotalysis handles visitors better.
956 template<typename Visitor>
957 void VisitEmbeddedImtAndVTable(const Visitor& visitor) NO_THREAD_SAFETY_ANALYSIS;
Mathieu Chartier407f7022014-02-18 14:37:05 -0800958
Ian Rogers1ff3c982014-08-12 02:30:58 -0700959 // Get the descriptor of the class. In a few cases a std::string is required, rather than
960 // always create one the storage argument is populated and its internal c_str() returned. We do
961 // this to avoid memory allocation in the common case.
962 const char* GetDescriptor(std::string* storage) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
963
964 const char* GetArrayDescriptor(std::string* storage) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700965
Mathieu Chartierf8322842014-05-16 10:59:25 -0700966 bool DescriptorEquals(const char* match) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700967
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700968
Mathieu Chartierf8322842014-05-16 10:59:25 -0700969 const DexFile::ClassDef* GetClassDef() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700970
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700971 ALWAYS_INLINE uint32_t NumDirectInterfaces() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700972
Mathieu Chartierf8322842014-05-16 10:59:25 -0700973 uint16_t GetDirectInterfaceTypeIdx(uint32_t idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700974
Andreas Gampe5a4b8a22014-09-11 08:30:08 -0700975 static mirror::Class* GetDirectInterface(Thread* self, Handle<mirror::Class> klass,
Mathieu Chartierbf99f772014-08-23 16:37:27 -0700976 uint32_t idx)
Mathieu Chartierf8322842014-05-16 10:59:25 -0700977 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700978
Mathieu Chartierf8322842014-05-16 10:59:25 -0700979 const char* GetSourceFile() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700980
Mathieu Chartierf8322842014-05-16 10:59:25 -0700981 std::string GetLocation() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700982
Mathieu Chartierf8322842014-05-16 10:59:25 -0700983 const DexFile& GetDexFile() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700984
Mathieu Chartierf8322842014-05-16 10:59:25 -0700985 const DexFile::TypeList* GetInterfaceTypeList() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
986
Sebastien Hertz4e99b3d2014-06-24 14:35:40 +0200987 // Asserts we are initialized or initializing in the given thread.
988 void AssertInitializedOrInitializingInThread(Thread* self)
989 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
990
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700991 Class* CopyOf(Thread* self, int32_t new_length, StackHandleScope<kImtSize>* imt_handle_scope)
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700992 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
993
994 // For proxy class only.
995 ObjectArray<Class>* GetInterfaces() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
996
997 // For proxy class only.
998 ObjectArray<ObjectArray<Class>>* GetThrows() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
999
Fred Shih4ee7a662014-07-11 09:59:27 -07001000 // For reference class only.
1001 MemberOffset GetDisableIntrinsicFlagOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1002 MemberOffset GetSlowPathFlagOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1003 bool GetSlowPathEnabled() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1004 void SetSlowPath(bool enabled) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1005
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001006 // Used to initialize a class in the allocation code path to ensure it is guarded by a StoreStore
1007 // fence.
1008 class InitializeClassVisitor {
1009 public:
1010 explicit InitializeClassVisitor(uint32_t class_size) : class_size_(class_size) {
1011 }
1012
1013 void operator()(mirror::Object* obj, size_t usable_size) const
1014 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1015
1016 private:
1017 const uint32_t class_size_;
1018
1019 DISALLOW_COPY_AND_ASSIGN(InitializeClassVisitor);
1020 };
1021
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001022 private:
1023 void SetVerifyErrorClass(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1024
Vladimir Marko89786432014-01-31 15:03:55 +00001025 template <bool throw_on_failure, bool use_referrers_cache>
1026 bool ResolvedFieldAccessTest(Class* access_to, ArtField* field,
Ian Rogersef7d42f2014-01-06 12:55:46 -08001027 uint32_t field_idx, DexCache* dex_cache)
Vladimir Marko89786432014-01-31 15:03:55 +00001028 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1029 template <bool throw_on_failure, bool use_referrers_cache, InvokeType throw_invoke_type>
1030 bool ResolvedMethodAccessTest(Class* access_to, ArtMethod* resolved_method,
Ian Rogersef7d42f2014-01-06 12:55:46 -08001031 uint32_t method_idx, DexCache* dex_cache)
Vladimir Marko89786432014-01-31 15:03:55 +00001032 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1033
Ian Rogersef7d42f2014-01-06 12:55:46 -08001034 bool Implements(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1035 bool IsArrayAssignableFromArray(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1036 bool IsAssignableFromArray(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001037
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -07001038 void CheckObjectAlloc() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1039
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001040 // defining class loader, or NULL for the "bootstrap" system loader
Ian Rogersef7d42f2014-01-06 12:55:46 -08001041 HeapReference<ClassLoader> class_loader_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001042
1043 // For array classes, the component class object for instanceof/checkcast
1044 // (for String[][][], this will be String[][]). NULL for non-array classes.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001045 HeapReference<Class> component_type_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001046
1047 // DexCache of resolved constant pool entries (will be NULL for classes generated by the
1048 // runtime such as arrays and primitive classes).
Ian Rogersef7d42f2014-01-06 12:55:46 -08001049 HeapReference<DexCache> dex_cache_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001050
1051 // static, private, and <init> methods
Ian Rogers700a4022014-05-19 16:49:03 -07001052 HeapReference<ObjectArray<ArtMethod>> direct_methods_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001053
1054 // instance fields
1055 //
1056 // These describe the layout of the contents of an Object.
1057 // Note that only the fields directly declared by this class are
1058 // listed in ifields; fields declared by a superclass are listed in
1059 // the superclass's Class.ifields.
1060 //
1061 // All instance fields that refer to objects are guaranteed to be at
1062 // the beginning of the field list. num_reference_instance_fields_
1063 // specifies the number of reference fields.
Ian Rogers700a4022014-05-19 16:49:03 -07001064 HeapReference<ObjectArray<ArtField>> ifields_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001065
1066 // The interface table (iftable_) contains pairs of a interface class and an array of the
1067 // interface methods. There is one pair per interface supported by this class. That means one
1068 // pair for each interface we support directly, indirectly via superclass, or indirectly via a
1069 // superinterface. This will be null if neither we nor our superclass implement any interfaces.
1070 //
1071 // Why we need this: given "class Foo implements Face", declare "Face faceObj = new Foo()".
1072 // Invoke faceObj.blah(), where "blah" is part of the Face interface. We can't easily use a
1073 // single vtable.
1074 //
1075 // For every interface a concrete class implements, we create an array of the concrete vtable_
1076 // methods for the methods in the interface.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001077 HeapReference<IfTable> iftable_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001078
Jeff Hao88474b42013-10-23 16:24:40 -07001079 // Interface method table (imt), for quick "invoke-interface".
Ian Rogers700a4022014-05-19 16:49:03 -07001080 HeapReference<ObjectArray<ArtMethod>> imtable_;
Jeff Hao88474b42013-10-23 16:24:40 -07001081
Ian Rogersef7d42f2014-01-06 12:55:46 -08001082 // Descriptor for the class such as "java.lang.Class" or "[C". Lazily initialized by ComputeName
1083 HeapReference<String> name_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001084
1085 // Static fields
Ian Rogersef7d42f2014-01-06 12:55:46 -08001086 HeapReference<ObjectArray<ArtField>> sfields_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001087
1088 // The superclass, or NULL if this is java.lang.Object, an interface or primitive type.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001089 HeapReference<Class> super_class_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001090
1091 // If class verify fails, we must return same error on subsequent tries.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001092 HeapReference<Class> verify_error_class_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001093
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001094 // Virtual methods defined in this class; invoked through vtable.
Ian Rogers700a4022014-05-19 16:49:03 -07001095 HeapReference<ObjectArray<ArtMethod>> virtual_methods_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001096
1097 // Virtual method table (vtable), for use by "invoke-virtual". The vtable from the superclass is
1098 // copied in, and virtual methods from our class either replace those from the super or are
1099 // appended. For abstract classes, methods may be created in the vtable that aren't in
1100 // virtual_ methods_ for miranda methods.
Ian Rogers700a4022014-05-19 16:49:03 -07001101 HeapReference<ObjectArray<ArtMethod>> vtable_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001102
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001103 // Access flags; low 16 bits are defined by VM spec.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001104 uint32_t access_flags_;
1105
1106 // Total size of the Class instance; used when allocating storage on gc heap.
1107 // See also object_size_.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001108 uint32_t class_size_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001109
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001110 // Tid used to check for recursive <clinit> invocation.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001111 pid_t clinit_thread_id_;
1112
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001113 // ClassDef index in dex file, -1 if no class definition such as an array.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001114 // TODO: really 16bits
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001115 int32_t dex_class_def_idx_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001116
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001117 // Type index in dex file.
1118 // TODO: really 16bits
1119 int32_t dex_type_idx_;
1120
1121 // Number of instance fields that are object refs.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001122 uint32_t num_reference_instance_fields_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001123
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001124 // Number of static fields that are object refs,
Ian Rogersef7d42f2014-01-06 12:55:46 -08001125 uint32_t num_reference_static_fields_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001126
1127 // Total object size; used when allocating storage on gc heap.
1128 // (For interfaces and abstract classes this will be zero.)
1129 // See also class_size_.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001130 uint32_t object_size_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001131
Hiroshi Yamauchif0edfc32014-09-25 11:46:46 -07001132 // The lower 16 bits contains a Primitive::Type value. The upper 16
1133 // bits contains the size shift of the primitive type.
1134 uint32_t primitive_type_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001135
1136 // Bitmap of offsets of ifields.
1137 uint32_t reference_instance_offsets_;
1138
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001139 // State of class initialization.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001140 Status status_;
1141
1142 // TODO: ?
1143 // initiating class loader list
1144 // NOTE: for classes with low serialNumber, these are unused, and the
1145 // values are kept in a table in gDvm.
1146 // InitiatingLoaderList initiating_loader_list_;
1147
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001148 // The following data exist in real class objects.
1149 // Embedded Imtable, for class object that's not an interface, fixed size.
1150 ImTableEntry embedded_imtable_[0];
1151 // Embedded Vtable, for class object that's not an interface, variable size.
1152 VTableEntry embedded_vtable_[0];
1153 // Static fields, variable size.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001154 uint32_t fields_[0];
1155
1156 // java.lang.Class
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -07001157 static GcRoot<Class> java_lang_Class_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001158
1159 friend struct art::ClassOffsets; // for verifying offset information
1160 DISALLOW_IMPLICIT_CONSTRUCTORS(Class);
1161};
1162
1163std::ostream& operator<<(std::ostream& os, const Class::Status& rhs);
1164
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001165} // namespace mirror
1166} // namespace art
1167
Brian Carlstromfc0e3212013-07-17 14:40:12 -07001168#endif // ART_RUNTIME_MIRROR_CLASS_H_