blob: 0acf6952c2a8eb0a3256cff273c463f4c59e2822 [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"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080030
31/*
32 * A magic value for refOffsets. Ignore the bits and walk the super
33 * chain when this is the value.
34 * [This is an unlikely "natural" value, since it would be 30 non-ref instance
35 * fields followed by 2 ref instance fields.]
36 */
Brian Carlstromfb6996f2013-07-18 18:21:14 -070037#define CLASS_WALK_SUPER 3U
38#define CLASS_BITS_PER_WORD (sizeof(uint32_t) * 8)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080039#define CLASS_OFFSET_ALIGNMENT 4
Brian Carlstromfb6996f2013-07-18 18:21:14 -070040#define CLASS_HIGH_BIT (1U << (CLASS_BITS_PER_WORD - 1))
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080041/*
42 * Given an offset, return the bit number which would encode that offset.
43 * Local use only.
44 */
45#define _CLASS_BIT_NUMBER_FROM_OFFSET(byteOffset) \
46 ((unsigned int)(byteOffset) / \
47 CLASS_OFFSET_ALIGNMENT)
48/*
49 * Is the given offset too large to be encoded?
50 */
51#define CLASS_CAN_ENCODE_OFFSET(byteOffset) \
52 (_CLASS_BIT_NUMBER_FROM_OFFSET(byteOffset) < CLASS_BITS_PER_WORD)
53/*
54 * Return a single bit, encoding the offset.
55 * Undefined if the offset is too large, as defined above.
56 */
57#define CLASS_BIT_FROM_OFFSET(byteOffset) \
58 (CLASS_HIGH_BIT >> _CLASS_BIT_NUMBER_FROM_OFFSET(byteOffset))
59/*
60 * Return an offset, given a bit number as returned from CLZ.
61 */
62#define CLASS_OFFSET_FROM_CLZ(rshift) \
63 MemberOffset((static_cast<int>(rshift) * CLASS_OFFSET_ALIGNMENT))
64
65namespace art {
66
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080067struct ClassOffsets;
Andreas Gampe5a4b8a22014-09-11 08:30:08 -070068template<class T> class Handle;
Mathieu Chartierbf99f772014-08-23 16:37:27 -070069template<class T> class Handle;
Ian Rogersd91d6d62013-09-25 20:26:14 -070070class Signature;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080071class StringPiece;
72
73namespace mirror {
74
Brian Carlstromea46f952013-07-30 01:26:50 -070075class ArtField;
Mingyao Yang98d1cc82014-05-15 17:02:16 -070076class ArtMethod;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080077class ClassLoader;
78class DexCache;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080079class IfTable;
80
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080081// C++ mirror of java.lang.Class
Mingyao Yang98d1cc82014-05-15 17:02:16 -070082class MANAGED Class FINAL : public Object {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080083 public:
Mingyao Yang98d1cc82014-05-15 17:02:16 -070084 // Interface method table size. Increasing this value reduces the chance of two interface methods
85 // colliding in the interface method table but increases the size of classes that implement
86 // (non-marker) interfaces.
87 static constexpr size_t kImtSize = 64;
88
89 // imtable entry embedded in class object.
90 struct MANAGED ImTableEntry {
91 HeapReference<ArtMethod> method;
92 };
93
94 // vtable entry embedded in class object.
95 struct MANAGED VTableEntry {
96 HeapReference<ArtMethod> method;
97 };
98
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080099 // Class Status
100 //
Mingyao Yang46f0e972014-09-10 15:16:19 -0700101 // kStatusRetired: Class that's temporarily used till class linking time
102 // has its (vtable) size figured out and has been cloned to one with the
103 // right size which will be the one used later. The old one is retired and
104 // will be gc'ed once all refs to the class point to the newly
105 // cloned version.
106 //
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800107 // kStatusNotReady: If a Class cannot be found in the class table by
108 // FindClass, it allocates an new one with AllocClass in the
109 // kStatusNotReady and calls LoadClass. Note if it does find a
110 // class, it may not be kStatusResolved and it will try to push it
111 // forward toward kStatusResolved.
112 //
113 // kStatusIdx: LoadClass populates with Class with information from
114 // the DexFile, moving the status to kStatusIdx, indicating that the
115 // Class value in super_class_ has not been populated. The new Class
116 // can then be inserted into the classes table.
117 //
118 // kStatusLoaded: After taking a lock on Class, the ClassLinker will
119 // attempt to move a kStatusIdx class forward to kStatusLoaded by
120 // using ResolveClass to initialize the super_class_ and ensuring the
121 // interfaces are resolved.
122 //
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700123 // kStatusResolving: Class is just cloned with the right size from
124 // temporary class that's acting as a placeholder for linking. The old
125 // class will be retired. New class is set to this status first before
126 // moving on to being resolved.
127 //
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800128 // kStatusResolved: Still holding the lock on Class, the ClassLinker
129 // shows linking is complete and fields of the Class populated by making
130 // it kStatusResolved. Java allows circularities of the form where a super
131 // class has a field that is of the type of the sub class. We need to be able
132 // to fully resolve super classes while resolving types for fields.
133 //
134 // kStatusRetryVerificationAtRuntime: The verifier sets a class to
135 // this state if it encounters a soft failure at compile time. This
136 // often happens when there are unresolved classes in other dex
137 // files, and this status marks a class as needing to be verified
138 // again at runtime.
139 //
140 // TODO: Explain the other states
141 enum Status {
Brian Carlstromf3978662014-09-11 12:21:04 -0700142 kStatusRetired = -2, // Retired, should not be used. Use the newly cloned one instead.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800143 kStatusError = -1,
144 kStatusNotReady = 0,
145 kStatusIdx = 1, // Loaded, DEX idx in super_class_type_idx_ and interfaces_type_idx_.
146 kStatusLoaded = 2, // DEX idx values resolved.
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700147 kStatusResolving = 3, // Just cloned from temporary class object.
148 kStatusResolved = 4, // Part of linking.
149 kStatusVerifying = 5, // In the process of being verified.
150 kStatusRetryVerificationAtRuntime = 6, // Compile time verification failed, retry at runtime.
151 kStatusVerifyingAtRuntime = 7, // Retrying verification at runtime.
152 kStatusVerified = 8, // Logically part of linking; done pre-init.
153 kStatusInitializing = 9, // Class init in progress.
154 kStatusInitialized = 10, // Ready to go.
155 kStatusMax = 11,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800156 };
157
Mathieu Chartier4e305412014-02-19 10:54:44 -0800158 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800159 Status GetStatus() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800160 COMPILE_ASSERT(sizeof(Status) == sizeof(uint32_t), size_of_status_not_uint32);
Ian Rogers03dbc042014-06-02 14:24:56 -0700161 return static_cast<Status>(
162 GetField32Volatile<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, status_)));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800163 }
164
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700165 void SetStatus(Status new_status, Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800166
Ian Rogers5ddb4102014-01-07 08:58:46 -0800167 static MemberOffset StatusOffset() {
168 return OFFSET_OF_OBJECT_MEMBER(Class, status_);
169 }
170
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700171 // Returns true if the class has been retired.
172 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
173 bool IsRetired() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
174 return GetStatus<kVerifyFlags>() == kStatusRetired;
175 }
176
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800177 // Returns true if the class has failed to link.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800178 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800179 bool IsErroneous() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800180 return GetStatus<kVerifyFlags>() == kStatusError;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800181 }
182
183 // Returns true if the class has been loaded.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800184 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800185 bool IsIdxLoaded() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800186 return GetStatus<kVerifyFlags>() >= kStatusIdx;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800187 }
188
189 // Returns true if the class has been loaded.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800190 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800191 bool IsLoaded() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800192 return GetStatus<kVerifyFlags>() >= kStatusLoaded;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800193 }
194
195 // Returns true if the class has been linked.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800196 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800197 bool IsResolved() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800198 return GetStatus<kVerifyFlags>() >= kStatusResolved;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800199 }
200
201 // Returns true if the class was compile-time verified.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800202 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800203 bool IsCompileTimeVerified() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800204 return GetStatus<kVerifyFlags>() >= kStatusRetryVerificationAtRuntime;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800205 }
206
207 // Returns true if the class has been verified.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800208 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800209 bool IsVerified() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800210 return GetStatus<kVerifyFlags>() >= kStatusVerified;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800211 }
212
213 // Returns true if the class is initializing.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800214 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800215 bool IsInitializing() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800216 return GetStatus<kVerifyFlags>() >= kStatusInitializing;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800217 }
218
219 // Returns true if the class is initialized.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800220 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800221 bool IsInitialized() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800222 return GetStatus<kVerifyFlags>() == kStatusInitialized;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800223 }
224
Mathieu Chartier4e305412014-02-19 10:54:44 -0800225 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800226 uint32_t GetAccessFlags() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800227
Andreas Gampe48498592014-09-10 19:48:05 -0700228 void SetAccessFlags(uint32_t new_access_flags) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800229
230 // Returns true if the class is an interface.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800231 bool IsInterface() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800232 return (GetAccessFlags() & kAccInterface) != 0;
233 }
234
235 // Returns true if the class is declared public.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800236 bool IsPublic() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800237 return (GetAccessFlags() & kAccPublic) != 0;
238 }
239
240 // Returns true if the class is declared final.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800241 bool IsFinal() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800242 return (GetAccessFlags() & kAccFinal) != 0;
243 }
244
Ian Rogersef7d42f2014-01-06 12:55:46 -0800245 bool IsFinalizable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800246 return (GetAccessFlags() & kAccClassIsFinalizable) != 0;
247 }
248
Ian Rogersef7d42f2014-01-06 12:55:46 -0800249 void SetFinalizable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700250 uint32_t flags = GetField32(OFFSET_OF_OBJECT_MEMBER(Class, access_flags_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800251 SetAccessFlags(flags | kAccClassIsFinalizable);
252 }
253
254 // Returns true if the class is abstract.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800255 bool IsAbstract() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800256 return (GetAccessFlags() & kAccAbstract) != 0;
257 }
258
259 // Returns true if the class is an annotation.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800260 bool IsAnnotation() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800261 return (GetAccessFlags() & kAccAnnotation) != 0;
262 }
263
264 // Returns true if the class is synthetic.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800265 bool IsSynthetic() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800266 return (GetAccessFlags() & kAccSynthetic) != 0;
267 }
268
Ian Rogers7b078e82014-09-10 14:44:24 -0700269 // Returns true if the class can avoid access checks.
270 bool IsPreverified() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
271 return (GetAccessFlags() & kAccPreverified) != 0;
272 }
273
274 void SetPreverified() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
275 uint32_t flags = GetField32(OFFSET_OF_OBJECT_MEMBER(Class, access_flags_));
276 SetAccessFlags(flags | kAccPreverified);
277 }
278
Mathieu Chartier4e305412014-02-19 10:54:44 -0800279 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Fred Shih4ee7a662014-07-11 09:59:27 -0700280 bool IsTypeOfReferenceClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800281 return (GetAccessFlags<kVerifyFlags>() & kAccClassIsReference) != 0;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800282 }
283
Mathieu Chartier4e305412014-02-19 10:54:44 -0800284 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800285 bool IsWeakReferenceClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800286 return (GetAccessFlags<kVerifyFlags>() & kAccClassIsWeakReference) != 0;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800287 }
288
Mathieu Chartier4e305412014-02-19 10:54:44 -0800289 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800290 bool IsSoftReferenceClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800291 return (GetAccessFlags<kVerifyFlags>() & kAccReferenceFlagsMask) == kAccClassIsReference;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800292 }
293
Mathieu Chartier4e305412014-02-19 10:54:44 -0800294 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800295 bool IsFinalizerReferenceClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800296 return (GetAccessFlags<kVerifyFlags>() & kAccClassIsFinalizerReference) != 0;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800297 }
298
Mathieu Chartier4e305412014-02-19 10:54:44 -0800299 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800300 bool IsPhantomReferenceClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800301 return (GetAccessFlags<kVerifyFlags>() & kAccClassIsPhantomReference) != 0;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800302 }
303
Ian Rogers04f94f42013-06-10 15:09:26 -0700304 // Can references of this type be assigned to by things of another type? For non-array types
305 // this is a matter of whether sub-classes may exist - which they can't if the type is final.
306 // For array classes, where all the classes are final due to there being no sub-classes, an
307 // Object[] may be assigned to by a String[] but a String[] may not be assigned to by other
308 // types as the component is final.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800309 bool CannotBeAssignedFromOtherTypes() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers04f94f42013-06-10 15:09:26 -0700310 if (!IsArrayClass()) {
311 return IsFinal();
312 } else {
313 Class* component = GetComponentType();
314 if (component->IsPrimitive()) {
Ian Rogersa9a82542013-10-04 11:17:26 -0700315 return true;
Ian Rogers04f94f42013-06-10 15:09:26 -0700316 } else {
317 return component->CannotBeAssignedFromOtherTypes();
318 }
319 }
320 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800321
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700322 // Returns true if this class is the placeholder and should retire and
323 // be replaced with a class with the right size for embedded imt/vtable.
324 bool IsTemp() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
325 Status s = GetStatus();
326 return s < Status::kStatusResolving && ShouldHaveEmbeddedImtAndVTable();
327 }
328
Ian Rogersef7d42f2014-01-06 12:55:46 -0800329 String* GetName() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); // Returns the cached name.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800330 void SetName(String* name) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); // Sets the cached name.
331 // Computes the name, then sets the cached value.
Mathieu Chartierf8322842014-05-16 10:59:25 -0700332 static String* ComputeName(Handle<Class> h_this) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800333
Mathieu Chartierc2f4d022014-03-03 16:11:42 -0800334 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier4e305412014-02-19 10:54:44 -0800335 bool IsProxyClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800336 // Read access flags without using getter as whether something is a proxy can be check in
337 // any loaded state
338 // TODO: switch to a check if the super class is java.lang.reflect.Proxy?
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700339 uint32_t access_flags = GetField32<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, access_flags_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800340 return (access_flags & kAccClassIsProxy) != 0;
341 }
342
Mathieu Chartier4e305412014-02-19 10:54:44 -0800343 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700344 Primitive::Type GetPrimitiveType() ALWAYS_INLINE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800345
Ian Rogersef7d42f2014-01-06 12:55:46 -0800346 void SetPrimitiveType(Primitive::Type new_type) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800347 DCHECK_EQ(sizeof(Primitive::Type), sizeof(int32_t));
Hiroshi Yamauchif0edfc32014-09-25 11:46:46 -0700348 int32_t v32 = static_cast<int32_t>(new_type);
349 DCHECK_EQ(v32 & 0xFFFF, v32) << "upper 16 bits aren't zero";
350 // Store the component size shift in the upper 16 bits.
351 v32 |= Primitive::ComponentSizeShift(new_type) << 16;
352 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, primitive_type_), v32);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800353 }
354
Hiroshi Yamauchif0edfc32014-09-25 11:46:46 -0700355 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
356 size_t GetPrimitiveTypeSizeShift() ALWAYS_INLINE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
357
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800358 // Returns true if the class is a primitive type.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800359 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800360 bool IsPrimitive() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800361 return GetPrimitiveType<kVerifyFlags>() != Primitive::kPrimNot;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800362 }
363
Mathieu Chartier4e305412014-02-19 10:54:44 -0800364 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800365 bool IsPrimitiveBoolean() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800366 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimBoolean;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800367 }
368
Mathieu Chartier4e305412014-02-19 10:54:44 -0800369 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800370 bool IsPrimitiveByte() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800371 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimByte;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800372 }
373
Mathieu Chartier4e305412014-02-19 10:54:44 -0800374 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800375 bool IsPrimitiveChar() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800376 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimChar;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800377 }
378
Mathieu Chartier4e305412014-02-19 10:54:44 -0800379 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800380 bool IsPrimitiveShort() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800381 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimShort;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800382 }
383
Mathieu Chartier4e305412014-02-19 10:54:44 -0800384 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800385 bool IsPrimitiveInt() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800386 return GetPrimitiveType() == Primitive::kPrimInt;
387 }
388
Mathieu Chartier4e305412014-02-19 10:54:44 -0800389 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800390 bool IsPrimitiveLong() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800391 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimLong;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800392 }
393
Mathieu Chartier4e305412014-02-19 10:54:44 -0800394 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800395 bool IsPrimitiveFloat() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800396 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimFloat;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800397 }
398
Mathieu Chartier4e305412014-02-19 10:54:44 -0800399 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800400 bool IsPrimitiveDouble() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800401 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimDouble;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800402 }
403
Mathieu Chartier4e305412014-02-19 10:54:44 -0800404 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800405 bool IsPrimitiveVoid() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800406 return GetPrimitiveType<kVerifyFlags>() == Primitive::kPrimVoid;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800407 }
408
Mathieu Chartier4e305412014-02-19 10:54:44 -0800409 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800410 bool IsPrimitiveArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800411 return IsArrayClass<kVerifyFlags>() &&
412 GetComponentType<static_cast<VerifyObjectFlags>(kVerifyFlags & ~kVerifyThis)>()->
413 IsPrimitive();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800414 }
415
416 // Depth of class from java.lang.Object
Ian Rogersef7d42f2014-01-06 12:55:46 -0800417 uint32_t Depth() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
418 uint32_t depth = 0;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800419 for (Class* klass = this; klass->GetSuperClass() != NULL; klass = klass->GetSuperClass()) {
420 depth++;
421 }
422 return depth;
423 }
424
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700425 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
426 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800427 bool IsArrayClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700428 return GetComponentType<kVerifyFlags, kReadBarrierOption>() != NULL;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800429 }
430
Hiroshi Yamauchi25023c72014-05-09 11:45:53 -0700431 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
432 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800433 bool IsClassClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800434
Hiroshi Yamauchibd0fb612014-05-20 13:46:00 -0700435 bool IsStringClass() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800436
Ian Rogersef7d42f2014-01-06 12:55:46 -0800437 bool IsThrowableClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800438
Hiroshi Yamauchi4f1ebc22014-06-25 14:30:41 -0700439 template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Hiroshi Yamauchibd0fb612014-05-20 13:46:00 -0700440 bool IsArtFieldClass() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800441
Hiroshi Yamauchi4f1ebc22014-06-25 14:30:41 -0700442 template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Hiroshi Yamauchibd0fb612014-05-20 13:46:00 -0700443 bool IsArtMethodClass() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800444
Fred Shih4ee7a662014-07-11 09:59:27 -0700445 template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
446 bool IsReferenceClass() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
447
Ian Rogersa9a82542013-10-04 11:17:26 -0700448 static MemberOffset ComponentTypeOffset() {
449 return OFFSET_OF_OBJECT_MEMBER(Class, component_type_);
450 }
451
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700452 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
453 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800454 Class* GetComponentType() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700455 return GetFieldObject<Class, kVerifyFlags, kReadBarrierOption>(ComponentTypeOffset());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800456 }
457
458 void SetComponentType(Class* new_component_type) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
459 DCHECK(GetComponentType() == NULL);
460 DCHECK(new_component_type != NULL);
Sebastien Hertzee1d79a2014-02-21 15:46:30 +0100461 // Component type is invariant: use non-transactional mode without check.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700462 SetFieldObject<false, false>(ComponentTypeOffset(), new_component_type);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800463 }
464
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700465 template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800466 size_t GetComponentSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Hiroshi Yamauchif0edfc32014-09-25 11:46:46 -0700467 return 1U << GetComponentSizeShift();
468 }
469
470 template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
471 size_t GetComponentSizeShift() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
472 return GetComponentType<kDefaultVerifyFlags, kReadBarrierOption>()->GetPrimitiveTypeSizeShift();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800473 }
474
Ian Rogersef7d42f2014-01-06 12:55:46 -0800475 bool IsObjectClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800476 return !IsPrimitive() && GetSuperClass() == NULL;
477 }
Ian Rogers68d8b422014-07-17 11:09:10 -0700478
479 bool IsInstantiableNonArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
480 return !IsPrimitive() && !IsInterface() && !IsAbstract() && !IsArrayClass();
481 }
482
Ian Rogersef7d42f2014-01-06 12:55:46 -0800483 bool IsInstantiable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers68d8b422014-07-17 11:09:10 -0700484 return (!IsPrimitive() && !IsInterface() && !IsAbstract()) ||
485 ((IsAbstract()) && IsArrayClass());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800486 }
487
Mathieu Chartier4e305412014-02-19 10:54:44 -0800488 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800489 bool IsObjectArrayClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800490 return GetComponentType<kVerifyFlags>() != nullptr && !GetComponentType<kVerifyFlags>()->IsPrimitive();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800491 }
492
493 // Creates a raw object instance but does not invoke the default constructor.
Mathieu Chartier8668c3c2014-04-24 16:48:11 -0700494 template<bool kIsInstrumented, bool kCheckAddFinalizer = true>
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800495 ALWAYS_INLINE Object* Alloc(Thread* self, gc::AllocatorType allocator_type)
496 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -0700497
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800498 Object* AllocObject(Thread* self)
499 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
500 Object* AllocNonMovableObject(Thread* self)
501 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800502
Hiroshi Yamauchi25023c72014-05-09 11:45:53 -0700503 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
504 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800505 bool IsVariableSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800506 // Classes and arrays vary in size, and so the object_size_ field cannot
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700507 // be used to Get their instance size
Hiroshi Yamauchi25023c72014-05-09 11:45:53 -0700508 return IsClassClass<kVerifyFlags, kReadBarrierOption>() ||
509 IsArrayClass<kVerifyFlags, kReadBarrierOption>();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800510 }
511
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700512 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
513 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800514 uint32_t SizeOf() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700515 return GetField32<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, class_size_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800516 }
517
Mathieu Chartier4e305412014-02-19 10:54:44 -0800518 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800519 uint32_t GetClassSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700520 return GetField32<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, class_size_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800521 }
522
Ian Rogersef7d42f2014-01-06 12:55:46 -0800523 void SetClassSize(uint32_t new_class_size)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800524 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
525
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700526 // Compute how many bytes would be used a class with the given elements.
527 static uint32_t ComputeClassSize(bool has_embedded_tables,
528 uint32_t num_vtable_entries,
Fred Shih37f05ef2014-07-16 18:38:08 -0700529 uint32_t num_8bit_static_fields,
530 uint32_t num_16bit_static_fields,
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700531 uint32_t num_32bit_static_fields,
532 uint32_t num_64bit_static_fields,
533 uint32_t num_ref_static_fields);
534
535 // The size of java.lang.Class.class.
536 static uint32_t ClassClassSize() {
537 // The number of vtable entries in java.lang.Class.
538 uint32_t vtable_entries = Object::kVTableLength + 64;
Fred Shih37f05ef2014-07-16 18:38:08 -0700539 return ComputeClassSize(true, vtable_entries, 0, 0, 0, 1, 0);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700540 }
541
542 // The size of a java.lang.Class representing a primitive such as int.class.
543 static uint32_t PrimitiveClassSize() {
Fred Shih37f05ef2014-07-16 18:38:08 -0700544 return ComputeClassSize(false, 0, 0, 0, 0, 0, 0);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700545 }
546
Hiroshi Yamauchi25023c72014-05-09 11:45:53 -0700547 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
548 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800549 uint32_t GetObjectSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800550
Ian Rogersef7d42f2014-01-06 12:55:46 -0800551 void SetObjectSize(uint32_t new_object_size) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800552 DCHECK(!IsVariableSize());
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100553 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700554 return SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, object_size_), new_object_size);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800555 }
556
557 // Returns true if this class is in the same packages as that class.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800558 bool IsInSamePackage(Class* that) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800559
560 static bool IsInSamePackage(const StringPiece& descriptor1, const StringPiece& descriptor2);
561
562 // Returns true if this class can access that class.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800563 bool CanAccess(Class* that) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800564 return that->IsPublic() || this->IsInSamePackage(that);
565 }
566
567 // Can this class access a member in the provided class with the provided member access flags?
568 // Note that access to the class isn't checked in case the declaring class is protected and the
569 // method has been exposed by a public sub-class
Ian Rogersef7d42f2014-01-06 12:55:46 -0800570 bool CanAccessMember(Class* access_to, uint32_t member_flags)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800571 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
572 // Classes can access all of their own members
573 if (this == access_to) {
574 return true;
575 }
576 // Public members are trivially accessible
577 if (member_flags & kAccPublic) {
578 return true;
579 }
580 // Private members are trivially not accessible
581 if (member_flags & kAccPrivate) {
582 return false;
583 }
584 // Check for protected access from a sub-class, which may or may not be in the same package.
585 if (member_flags & kAccProtected) {
Andreas Gampe13f8a162014-08-08 19:55:37 -0700586 if (!this->IsInterface() && this->IsSubClass(access_to)) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800587 return true;
588 }
589 }
590 // Allow protected access from other classes in the same package.
591 return this->IsInSamePackage(access_to);
592 }
593
Vladimir Marko23a28212014-01-09 19:24:37 +0000594 // Can this class access a resolved field?
595 // Note that access to field's class is checked and this may require looking up the class
596 // referenced by the FieldId in the DexFile in case the declaring class is inaccessible.
Vladimir Marko23a28212014-01-09 19:24:37 +0000597 bool CanAccessResolvedField(Class* access_to, ArtField* field,
Ian Rogersef7d42f2014-01-06 12:55:46 -0800598 DexCache* dex_cache, uint32_t field_idx)
Vladimir Marko89786432014-01-31 15:03:55 +0000599 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
600 bool CheckResolvedFieldAccess(Class* access_to, ArtField* field,
601 uint32_t field_idx)
602 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Vladimir Marko23a28212014-01-09 19:24:37 +0000603
604 // Can this class access a resolved method?
605 // Note that access to methods's class is checked and this may require looking up the class
606 // referenced by the MethodId in the DexFile in case the declaring class is inaccessible.
Vladimir Marko23a28212014-01-09 19:24:37 +0000607 bool CanAccessResolvedMethod(Class* access_to, ArtMethod* resolved_method,
Ian Rogersef7d42f2014-01-06 12:55:46 -0800608 DexCache* dex_cache, uint32_t method_idx)
Vladimir Marko89786432014-01-31 15:03:55 +0000609 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
610 template <InvokeType throw_invoke_type>
611 bool CheckResolvedMethodAccess(Class* access_to, ArtMethod* resolved_method,
612 uint32_t method_idx)
613 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Vladimir Marko23a28212014-01-09 19:24:37 +0000614
Ian Rogersef7d42f2014-01-06 12:55:46 -0800615 bool IsSubClass(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800616
617 // Can src be assigned to this class? For example, String can be assigned to Object (by an
618 // upcast), however, an Object cannot be assigned to a String as a potentially exception throwing
619 // downcast would be necessary. Similarly for interfaces, a class that implements (or an interface
620 // that extends) another can be assigned to its parent, but not vice-versa. All Classes may assign
621 // to themselves. Classes for primitive types may not assign to each other.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800622 inline bool IsAssignableFrom(Class* src) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800623 DCHECK(src != NULL);
624 if (this == src) {
625 // Can always assign to things of the same type.
626 return true;
627 } else if (IsObjectClass()) {
628 // Can assign any reference to java.lang.Object.
629 return !src->IsPrimitive();
630 } else if (IsInterface()) {
631 return src->Implements(this);
632 } else if (src->IsArrayClass()) {
633 return IsAssignableFromArray(src);
634 } else {
635 return !src->IsInterface() && src->IsSubClass(this);
636 }
637 }
638
Ian Rogersef7d42f2014-01-06 12:55:46 -0800639 Class* GetSuperClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800640
641 void SetSuperClass(Class *new_super_class) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800642 // Super class is assigned once, except during class linker initialization.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700643 Class* old_super_class = GetFieldObject<Class>(OFFSET_OF_OBJECT_MEMBER(Class, super_class_));
Ian Rogersef7d42f2014-01-06 12:55:46 -0800644 DCHECK(old_super_class == nullptr || old_super_class == new_super_class);
645 DCHECK(new_super_class != nullptr);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700646 SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(Class, super_class_), new_super_class);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800647 }
648
Ian Rogersef7d42f2014-01-06 12:55:46 -0800649 bool HasSuperClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800650 return GetSuperClass() != NULL;
651 }
652
653 static MemberOffset SuperClassOffset() {
654 return MemberOffset(OFFSETOF_MEMBER(Class, super_class_));
655 }
656
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700657 ClassLoader* GetClassLoader() ALWAYS_INLINE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800658
659 void SetClassLoader(ClassLoader* new_cl) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
660
661 static MemberOffset DexCacheOffset() {
662 return MemberOffset(OFFSETOF_MEMBER(Class, dex_cache_));
663 }
664
665 enum {
666 kDumpClassFullDetail = 1,
667 kDumpClassClassLoader = (1 << 1),
668 kDumpClassInitialized = (1 << 2),
669 };
670
Ian Rogersef7d42f2014-01-06 12:55:46 -0800671 void DumpClass(std::ostream& os, int flags) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800672
Mathieu Chartierc2f4d022014-03-03 16:11:42 -0800673 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800674 DexCache* GetDexCache() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800675
676 void SetDexCache(DexCache* new_dex_cache) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
677
Ian Rogersef7d42f2014-01-06 12:55:46 -0800678 ObjectArray<ArtMethod>* GetDirectMethods() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800679
Brian Carlstromea46f952013-07-30 01:26:50 -0700680 void SetDirectMethods(ObjectArray<ArtMethod>* new_direct_methods)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800681 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
682
Ian Rogersef7d42f2014-01-06 12:55:46 -0800683 ArtMethod* GetDirectMethod(int32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800684
Brian Carlstromea46f952013-07-30 01:26:50 -0700685 void SetDirectMethod(uint32_t i, ArtMethod* f) // TODO: uint16_t
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800686 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
687
688 // Returns the number of static, private, and constructor methods.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800689 uint32_t NumDirectMethods() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800690
Mathieu Chartier4e305412014-02-19 10:54:44 -0800691 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800692 ObjectArray<ArtMethod>* GetVirtualMethods() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800693
Brian Carlstromea46f952013-07-30 01:26:50 -0700694 void SetVirtualMethods(ObjectArray<ArtMethod>* new_virtual_methods)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800695 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
696
697 // Returns the number of non-inherited virtual methods.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800698 uint32_t NumVirtualMethods() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800699
Mathieu Chartier4e305412014-02-19 10:54:44 -0800700 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800701 ArtMethod* GetVirtualMethod(uint32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800702
Ian Rogersef7d42f2014-01-06 12:55:46 -0800703 ArtMethod* GetVirtualMethodDuringLinking(uint32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800704
Brian Carlstromea46f952013-07-30 01:26:50 -0700705 void SetVirtualMethod(uint32_t i, ArtMethod* f) // TODO: uint16_t
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800706 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
707
Ian Rogersef7d42f2014-01-06 12:55:46 -0800708 ObjectArray<ArtMethod>* GetVTable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800709
Ian Rogersef7d42f2014-01-06 12:55:46 -0800710 ObjectArray<ArtMethod>* GetVTableDuringLinking() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800711
Brian Carlstromea46f952013-07-30 01:26:50 -0700712 void SetVTable(ObjectArray<ArtMethod>* new_vtable)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800713 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
714
715 static MemberOffset VTableOffset() {
716 return OFFSET_OF_OBJECT_MEMBER(Class, vtable_);
717 }
718
Jeff Hao88474b42013-10-23 16:24:40 -0700719 void SetImTable(ObjectArray<ArtMethod>* new_imtable)
720 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
721
722 static MemberOffset ImTableOffset() {
723 return OFFSET_OF_OBJECT_MEMBER(Class, imtable_);
724 }
725
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700726 static MemberOffset EmbeddedImTableOffset() {
727 return MemberOffset(sizeof(Class));
728 }
729
Mingyao Yang2cdbad72014-07-16 10:44:41 -0700730 static MemberOffset EmbeddedVTableLengthOffset() {
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700731 return MemberOffset(sizeof(Class) + kImtSize * sizeof(mirror::Class::ImTableEntry));
732 }
733
Mingyao Yang2cdbad72014-07-16 10:44:41 -0700734 static MemberOffset EmbeddedVTableOffset() {
735 return MemberOffset(sizeof(Class) + kImtSize * sizeof(mirror::Class::ImTableEntry) + sizeof(int32_t));
736 }
737
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700738 bool ShouldHaveEmbeddedImtAndVTable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
739 return IsInstantiable();
740 }
741
Mingyao Yang2cdbad72014-07-16 10:44:41 -0700742 bool HasVTable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
743
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700744 ArtMethod* GetEmbeddedImTableEntry(uint32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
745
746 void SetEmbeddedImTableEntry(uint32_t i, ArtMethod* method) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
747
Mingyao Yang2cdbad72014-07-16 10:44:41 -0700748 int32_t GetVTableLength() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
749
750 ArtMethod* GetVTableEntry(uint32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
751
752 int32_t GetEmbeddedVTableLength() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
753
754 void SetEmbeddedVTableLength(int32_t len) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
755
756 ArtMethod* GetEmbeddedVTableEntry(uint32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
757
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700758 void SetEmbeddedVTableEntry(uint32_t i, ArtMethod* method) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
759
760 void PopulateEmbeddedImtAndVTable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
761
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800762 // Given a method implemented by this class but potentially from a super class, return the
763 // specific implementation method for this class.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800764 ArtMethod* FindVirtualMethodForVirtual(ArtMethod* method)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800765 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
766
767 // Given a method implemented by this class' super class, return the specific implementation
768 // method for this class.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800769 ArtMethod* FindVirtualMethodForSuper(ArtMethod* method)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800770 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
771
772 // Given a method implemented by this class, but potentially from a
773 // super class or interface, return the specific implementation
774 // method for this class.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800775 ArtMethod* FindVirtualMethodForInterface(ArtMethod* method)
Ian Rogers1ffa32f2013-02-05 18:29:08 -0800776 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) ALWAYS_INLINE;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800777
Ian Rogersef7d42f2014-01-06 12:55:46 -0800778 ArtMethod* FindVirtualMethodForVirtualOrInterface(ArtMethod* method)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700779 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
780
Brian Carlstrom004644f2014-06-18 08:34:01 -0700781 ArtMethod* FindInterfaceMethod(const StringPiece& name, const StringPiece& signature)
782 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
783
Ian Rogersef7d42f2014-01-06 12:55:46 -0800784 ArtMethod* FindInterfaceMethod(const StringPiece& name, const Signature& signature)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800785 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
786
Ian Rogersef7d42f2014-01-06 12:55:46 -0800787 ArtMethod* FindInterfaceMethod(const DexCache* dex_cache, uint32_t dex_method_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800788 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
789
Ian Rogersef7d42f2014-01-06 12:55:46 -0800790 ArtMethod* FindDeclaredDirectMethod(const StringPiece& name, const StringPiece& signature)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800791 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
792
Ian Rogersef7d42f2014-01-06 12:55:46 -0800793 ArtMethod* FindDeclaredDirectMethod(const StringPiece& name, const Signature& signature)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700794 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
795
Ian Rogersef7d42f2014-01-06 12:55:46 -0800796 ArtMethod* FindDeclaredDirectMethod(const DexCache* dex_cache, uint32_t dex_method_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800797 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
798
Ian Rogersef7d42f2014-01-06 12:55:46 -0800799 ArtMethod* FindDirectMethod(const StringPiece& name, const StringPiece& signature)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800800 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
801
Ian Rogersef7d42f2014-01-06 12:55:46 -0800802 ArtMethod* FindDirectMethod(const StringPiece& name, const Signature& signature)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700803 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
804
Ian Rogersef7d42f2014-01-06 12:55:46 -0800805 ArtMethod* FindDirectMethod(const DexCache* dex_cache, uint32_t dex_method_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800806 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
807
Ian Rogersef7d42f2014-01-06 12:55:46 -0800808 ArtMethod* FindDeclaredVirtualMethod(const StringPiece& name, const StringPiece& signature)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700809 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
810
Ian Rogersef7d42f2014-01-06 12:55:46 -0800811 ArtMethod* FindDeclaredVirtualMethod(const StringPiece& name, const Signature& signature)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700812 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
813
Ian Rogersef7d42f2014-01-06 12:55:46 -0800814 ArtMethod* FindDeclaredVirtualMethod(const DexCache* dex_cache, uint32_t dex_method_idx)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700815 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
816
Ian Rogersef7d42f2014-01-06 12:55:46 -0800817 ArtMethod* FindVirtualMethod(const StringPiece& name, const StringPiece& signature)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700818 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
819
Ian Rogersef7d42f2014-01-06 12:55:46 -0800820 ArtMethod* FindVirtualMethod(const StringPiece& name, const Signature& signature)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700821 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
822
Ian Rogersef7d42f2014-01-06 12:55:46 -0800823 ArtMethod* FindVirtualMethod(const DexCache* dex_cache, uint32_t dex_method_idx)
Ian Rogersd91d6d62013-09-25 20:26:14 -0700824 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
825
Ian Rogersef7d42f2014-01-06 12:55:46 -0800826 ArtMethod* FindClassInitializer() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersd91d6d62013-09-25 20:26:14 -0700827
Ian Rogersef7d42f2014-01-06 12:55:46 -0800828 int32_t GetIfTableCount() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800829
Ian Rogersef7d42f2014-01-06 12:55:46 -0800830 IfTable* GetIfTable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800831
832 void SetIfTable(IfTable* new_iftable) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
833
834 // Get instance fields of the class (See also GetSFields).
Ian Rogersef7d42f2014-01-06 12:55:46 -0800835 ObjectArray<ArtField>* GetIFields() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800836
Brian Carlstromea46f952013-07-30 01:26:50 -0700837 void SetIFields(ObjectArray<ArtField>* new_ifields) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800838
Ian Rogersef7d42f2014-01-06 12:55:46 -0800839 uint32_t NumInstanceFields() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800840
Ian Rogersef7d42f2014-01-06 12:55:46 -0800841 ArtField* GetInstanceField(uint32_t i) // TODO: uint16_t
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800842 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
843
Brian Carlstromea46f952013-07-30 01:26:50 -0700844 void SetInstanceField(uint32_t i, ArtField* f) // TODO: uint16_t
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800845 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
846
847 // Returns the number of instance fields containing reference types.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800848 uint32_t NumReferenceInstanceFields() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800849 DCHECK(IsResolved() || IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700850 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_instance_fields_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800851 }
852
Ian Rogersef7d42f2014-01-06 12:55:46 -0800853 uint32_t NumReferenceInstanceFieldsDuringLinking() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800854 DCHECK(IsLoaded() || IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700855 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_instance_fields_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800856 }
857
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700858 void SetNumReferenceInstanceFields(uint32_t new_num) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100859 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700860 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_instance_fields_), new_num);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800861 }
862
Mathieu Chartier4e305412014-02-19 10:54:44 -0800863 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700864 uint32_t GetReferenceInstanceOffsets() ALWAYS_INLINE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800865
866 void SetReferenceInstanceOffsets(uint32_t new_reference_offsets)
867 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
868
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800869 // Returns the number of static fields containing reference types.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800870 uint32_t NumReferenceStaticFields() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800871 DCHECK(IsResolved() || IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700872 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_static_fields_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800873 }
874
Ian Rogersef7d42f2014-01-06 12:55:46 -0800875 uint32_t NumReferenceStaticFieldsDuringLinking() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700876 DCHECK(IsLoaded() || IsErroneous() || IsRetired());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700877 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_static_fields_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800878 }
879
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700880 void SetNumReferenceStaticFields(uint32_t new_num) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100881 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700882 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, num_reference_static_fields_), new_num);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800883 }
884
885 // Gets the static fields of the class.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800886 ObjectArray<ArtField>* GetSFields() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800887
Brian Carlstromea46f952013-07-30 01:26:50 -0700888 void SetSFields(ObjectArray<ArtField>* new_sfields) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800889
Ian Rogersef7d42f2014-01-06 12:55:46 -0800890 uint32_t NumStaticFields() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800891
Ian Rogersef7d42f2014-01-06 12:55:46 -0800892 // TODO: uint16_t
893 ArtField* GetStaticField(uint32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800894
Ian Rogersef7d42f2014-01-06 12:55:46 -0800895 // TODO: uint16_t
896 void SetStaticField(uint32_t i, ArtField* f) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800897
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800898 // Find a static or instance field using the JLS resolution order
Mathieu Chartierf8322842014-05-16 10:59:25 -0700899 static ArtField* FindField(Thread* self, Handle<Class> klass, const StringPiece& name,
900 const StringPiece& type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800901 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
902
903 // Finds the given instance field in this class or a superclass.
Brian Carlstromea46f952013-07-30 01:26:50 -0700904 ArtField* FindInstanceField(const StringPiece& name, const StringPiece& type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800905 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
906
907 // Finds the given instance field in this class or a superclass, only searches classes that
908 // have the same dex cache.
Brian Carlstromea46f952013-07-30 01:26:50 -0700909 ArtField* FindInstanceField(const DexCache* dex_cache, uint32_t dex_field_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800910 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
911
Brian Carlstromea46f952013-07-30 01:26:50 -0700912 ArtField* FindDeclaredInstanceField(const StringPiece& name, const StringPiece& type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800913 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
914
Brian Carlstromea46f952013-07-30 01:26:50 -0700915 ArtField* FindDeclaredInstanceField(const DexCache* dex_cache, uint32_t dex_field_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800916 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
917
918 // Finds the given static field in this class or a superclass.
Mathieu Chartierf8322842014-05-16 10:59:25 -0700919 static ArtField* FindStaticField(Thread* self, Handle<Class> klass, const StringPiece& name,
920 const StringPiece& type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800921 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
922
923 // Finds the given static field in this class or superclass, only searches classes that
924 // have the same dex cache.
Mathieu Chartierf8322842014-05-16 10:59:25 -0700925 static ArtField* FindStaticField(Thread* self, Handle<Class> klass, const DexCache* dex_cache,
926 uint32_t dex_field_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800927 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
928
Brian Carlstromea46f952013-07-30 01:26:50 -0700929 ArtField* FindDeclaredStaticField(const StringPiece& name, const StringPiece& type)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800930 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
931
Brian Carlstromea46f952013-07-30 01:26:50 -0700932 ArtField* FindDeclaredStaticField(const DexCache* dex_cache, uint32_t dex_field_idx)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800933 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
934
Ian Rogersef7d42f2014-01-06 12:55:46 -0800935 pid_t GetClinitThreadId() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800936 DCHECK(IsIdxLoaded() || IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700937 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, clinit_thread_id_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800938 }
939
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700940 void SetClinitThreadId(pid_t new_clinit_thread_id) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800941
Ian Rogersef7d42f2014-01-06 12:55:46 -0800942 Class* GetVerifyErrorClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800943 // DCHECK(IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700944 return GetFieldObject<Class>(OFFSET_OF_OBJECT_MEMBER(Class, verify_error_class_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800945 }
946
Ian Rogersef7d42f2014-01-06 12:55:46 -0800947 uint16_t GetDexClassDefIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700948 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, dex_class_def_idx_));
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700949 }
950
Ian Rogersef7d42f2014-01-06 12:55:46 -0800951 void SetDexClassDefIndex(uint16_t class_def_idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100952 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700953 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, dex_class_def_idx_), class_def_idx);
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700954 }
955
Ian Rogersef7d42f2014-01-06 12:55:46 -0800956 uint16_t GetDexTypeIndex() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700957 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, dex_type_idx_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800958 }
959
Ian Rogersef7d42f2014-01-06 12:55:46 -0800960 void SetDexTypeIndex(uint16_t type_idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100961 // Not called within a transaction.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700962 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, dex_type_idx_), type_idx);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800963 }
964
Hiroshi Yamauchi4f1ebc22014-06-25 14:30:41 -0700965 static Class* GetJavaLangClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -0700966 DCHECK(!java_lang_Class_.IsNull());
967 return java_lang_Class_.Read();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800968 }
969
970 // Can't call this SetClass or else gets called instead of Object::SetClass in places.
Hiroshi Yamauchi4f1ebc22014-06-25 14:30:41 -0700971 static void SetClassClass(Class* java_lang_Class) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800972 static void ResetClass();
Mathieu Chartier83c8ee02014-01-28 14:50:23 -0800973 static void VisitRoots(RootCallback* callback, void* arg)
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800974 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800975
Sebastien Hertz233ea8e2013-06-06 11:57:09 +0200976 // When class is verified, set the kAccPreverified flag on each method.
977 void SetPreverifiedFlagOnAllMethods() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
978
Mathieu Chartier407f7022014-02-18 14:37:05 -0800979 template <bool kVisitClass, typename Visitor>
980 void VisitReferences(mirror::Class* klass, const Visitor& visitor)
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700981 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
982
983 // Visit references within the embedded tables of the class.
984 // TODO: remove NO_THREAD_SAFETY_ANALYSIS when annotalysis handles visitors better.
985 template<typename Visitor>
986 void VisitEmbeddedImtAndVTable(const Visitor& visitor) NO_THREAD_SAFETY_ANALYSIS;
Mathieu Chartier407f7022014-02-18 14:37:05 -0800987
Ian Rogers1ff3c982014-08-12 02:30:58 -0700988 // Get the descriptor of the class. In a few cases a std::string is required, rather than
989 // always create one the storage argument is populated and its internal c_str() returned. We do
990 // this to avoid memory allocation in the common case.
991 const char* GetDescriptor(std::string* storage) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
992
993 const char* GetArrayDescriptor(std::string* storage) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700994
Mathieu Chartierf8322842014-05-16 10:59:25 -0700995 bool DescriptorEquals(const char* match) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700996
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700997
Mathieu Chartierf8322842014-05-16 10:59:25 -0700998 const DexFile::ClassDef* GetClassDef() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700999
Mathieu Chartierf8322842014-05-16 10:59:25 -07001000 uint32_t NumDirectInterfaces() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001001
Mathieu Chartierf8322842014-05-16 10:59:25 -07001002 uint16_t GetDirectInterfaceTypeIdx(uint32_t idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001003
Andreas Gampe5a4b8a22014-09-11 08:30:08 -07001004 static mirror::Class* GetDirectInterface(Thread* self, Handle<mirror::Class> klass,
Mathieu Chartierbf99f772014-08-23 16:37:27 -07001005 uint32_t idx)
Mathieu Chartierf8322842014-05-16 10:59:25 -07001006 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001007
Mathieu Chartierf8322842014-05-16 10:59:25 -07001008 const char* GetSourceFile() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001009
Mathieu Chartierf8322842014-05-16 10:59:25 -07001010 std::string GetLocation() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001011
Mathieu Chartierf8322842014-05-16 10:59:25 -07001012 const DexFile& GetDexFile() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001013
Mathieu Chartierf8322842014-05-16 10:59:25 -07001014 const DexFile::TypeList* GetInterfaceTypeList() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1015
Sebastien Hertz4e99b3d2014-06-24 14:35:40 +02001016 // Asserts we are initialized or initializing in the given thread.
1017 void AssertInitializedOrInitializingInThread(Thread* self)
1018 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1019
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001020 Class* CopyOf(Thread* self, int32_t new_length)
1021 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1022
1023 // For proxy class only.
1024 ObjectArray<Class>* GetInterfaces() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1025
1026 // For proxy class only.
1027 ObjectArray<ObjectArray<Class>>* GetThrows() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1028
Fred Shih4ee7a662014-07-11 09:59:27 -07001029 // For reference class only.
1030 MemberOffset GetDisableIntrinsicFlagOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1031 MemberOffset GetSlowPathFlagOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1032 bool GetSlowPathEnabled() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1033 void SetSlowPath(bool enabled) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
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
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001051 private:
1052 void SetVerifyErrorClass(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1053
Vladimir Marko89786432014-01-31 15:03:55 +00001054 template <bool throw_on_failure, bool use_referrers_cache>
1055 bool ResolvedFieldAccessTest(Class* access_to, ArtField* field,
Ian Rogersef7d42f2014-01-06 12:55:46 -08001056 uint32_t field_idx, DexCache* dex_cache)
Vladimir Marko89786432014-01-31 15:03:55 +00001057 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1058 template <bool throw_on_failure, bool use_referrers_cache, InvokeType throw_invoke_type>
1059 bool ResolvedMethodAccessTest(Class* access_to, ArtMethod* resolved_method,
Ian Rogersef7d42f2014-01-06 12:55:46 -08001060 uint32_t method_idx, DexCache* dex_cache)
Vladimir Marko89786432014-01-31 15:03:55 +00001061 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1062
Ian Rogersef7d42f2014-01-06 12:55:46 -08001063 bool Implements(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1064 bool IsArrayAssignableFromArray(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1065 bool IsAssignableFromArray(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001066
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -07001067 void CheckObjectAlloc() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1068
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001069 ObjectArray<ArtMethod>* GetImTable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
1070
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001071 // defining class loader, or NULL for the "bootstrap" system loader
Ian Rogersef7d42f2014-01-06 12:55:46 -08001072 HeapReference<ClassLoader> class_loader_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001073
1074 // For array classes, the component class object for instanceof/checkcast
1075 // (for String[][][], this will be String[][]). NULL for non-array classes.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001076 HeapReference<Class> component_type_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001077
1078 // DexCache of resolved constant pool entries (will be NULL for classes generated by the
1079 // runtime such as arrays and primitive classes).
Ian Rogersef7d42f2014-01-06 12:55:46 -08001080 HeapReference<DexCache> dex_cache_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001081
1082 // static, private, and <init> methods
Ian Rogers700a4022014-05-19 16:49:03 -07001083 HeapReference<ObjectArray<ArtMethod>> direct_methods_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001084
1085 // instance fields
1086 //
1087 // These describe the layout of the contents of an Object.
1088 // Note that only the fields directly declared by this class are
1089 // listed in ifields; fields declared by a superclass are listed in
1090 // the superclass's Class.ifields.
1091 //
1092 // All instance fields that refer to objects are guaranteed to be at
1093 // the beginning of the field list. num_reference_instance_fields_
1094 // specifies the number of reference fields.
Ian Rogers700a4022014-05-19 16:49:03 -07001095 HeapReference<ObjectArray<ArtField>> ifields_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001096
1097 // The interface table (iftable_) contains pairs of a interface class and an array of the
1098 // interface methods. There is one pair per interface supported by this class. That means one
1099 // pair for each interface we support directly, indirectly via superclass, or indirectly via a
1100 // superinterface. This will be null if neither we nor our superclass implement any interfaces.
1101 //
1102 // Why we need this: given "class Foo implements Face", declare "Face faceObj = new Foo()".
1103 // Invoke faceObj.blah(), where "blah" is part of the Face interface. We can't easily use a
1104 // single vtable.
1105 //
1106 // For every interface a concrete class implements, we create an array of the concrete vtable_
1107 // methods for the methods in the interface.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001108 HeapReference<IfTable> iftable_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001109
Jeff Hao88474b42013-10-23 16:24:40 -07001110 // Interface method table (imt), for quick "invoke-interface".
Ian Rogers700a4022014-05-19 16:49:03 -07001111 HeapReference<ObjectArray<ArtMethod>> imtable_;
Jeff Hao88474b42013-10-23 16:24:40 -07001112
Ian Rogersef7d42f2014-01-06 12:55:46 -08001113 // Descriptor for the class such as "java.lang.Class" or "[C". Lazily initialized by ComputeName
1114 HeapReference<String> name_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001115
1116 // Static fields
Ian Rogersef7d42f2014-01-06 12:55:46 -08001117 HeapReference<ObjectArray<ArtField>> sfields_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001118
1119 // The superclass, or NULL if this is java.lang.Object, an interface or primitive type.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001120 HeapReference<Class> super_class_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001121
1122 // If class verify fails, we must return same error on subsequent tries.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001123 HeapReference<Class> verify_error_class_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001124
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001125 // Virtual methods defined in this class; invoked through vtable.
Ian Rogers700a4022014-05-19 16:49:03 -07001126 HeapReference<ObjectArray<ArtMethod>> virtual_methods_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001127
1128 // Virtual method table (vtable), for use by "invoke-virtual". The vtable from the superclass is
1129 // copied in, and virtual methods from our class either replace those from the super or are
1130 // appended. For abstract classes, methods may be created in the vtable that aren't in
1131 // virtual_ methods_ for miranda methods.
Ian Rogers700a4022014-05-19 16:49:03 -07001132 HeapReference<ObjectArray<ArtMethod>> vtable_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001133
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001134 // Access flags; low 16 bits are defined by VM spec.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001135 uint32_t access_flags_;
1136
1137 // Total size of the Class instance; used when allocating storage on gc heap.
1138 // See also object_size_.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001139 uint32_t class_size_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001140
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001141 // Tid used to check for recursive <clinit> invocation.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001142 pid_t clinit_thread_id_;
1143
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001144 // ClassDef index in dex file, -1 if no class definition such as an array.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001145 // TODO: really 16bits
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001146 int32_t dex_class_def_idx_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001147
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001148 // Type index in dex file.
1149 // TODO: really 16bits
1150 int32_t dex_type_idx_;
1151
1152 // Number of instance fields that are object refs.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001153 uint32_t num_reference_instance_fields_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001154
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001155 // Number of static fields that are object refs,
Ian Rogersef7d42f2014-01-06 12:55:46 -08001156 uint32_t num_reference_static_fields_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001157
1158 // Total object size; used when allocating storage on gc heap.
1159 // (For interfaces and abstract classes this will be zero.)
1160 // See also class_size_.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001161 uint32_t object_size_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001162
Hiroshi Yamauchif0edfc32014-09-25 11:46:46 -07001163 // The lower 16 bits contains a Primitive::Type value. The upper 16
1164 // bits contains the size shift of the primitive type.
1165 uint32_t primitive_type_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001166
1167 // Bitmap of offsets of ifields.
1168 uint32_t reference_instance_offsets_;
1169
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001170 // State of class initialization.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001171 Status status_;
1172
1173 // TODO: ?
1174 // initiating class loader list
1175 // NOTE: for classes with low serialNumber, these are unused, and the
1176 // values are kept in a table in gDvm.
1177 // InitiatingLoaderList initiating_loader_list_;
1178
Mingyao Yang98d1cc82014-05-15 17:02:16 -07001179 // The following data exist in real class objects.
1180 // Embedded Imtable, for class object that's not an interface, fixed size.
1181 ImTableEntry embedded_imtable_[0];
1182 // Embedded Vtable, for class object that's not an interface, variable size.
1183 VTableEntry embedded_vtable_[0];
1184 // Static fields, variable size.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001185 uint32_t fields_[0];
1186
1187 // java.lang.Class
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -07001188 static GcRoot<Class> java_lang_Class_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001189
1190 friend struct art::ClassOffsets; // for verifying offset information
1191 DISALLOW_IMPLICIT_CONSTRUCTORS(Class);
1192};
1193
1194std::ostream& operator<<(std::ostream& os, const Class::Status& rhs);
1195
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001196} // namespace mirror
1197} // namespace art
1198
Brian Carlstromfc0e3212013-07-17 14:40:12 -07001199#endif // ART_RUNTIME_MIRROR_CLASS_H_