blob: 329a9848426c1fcbd63ed0c834d2c7876a1e009f [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_INL_H_
18#define ART_RUNTIME_MIRROR_CLASS_INL_H_
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080019
20#include "class.h"
21
Mingyao Yang98d1cc82014-05-15 17:02:16 -070022#include "art_field-inl.h"
23#include "art_method-inl.h"
Mathieu Chartierf8322842014-05-16 10:59:25 -070024#include "class_linker-inl.h"
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070025#include "class_loader.h"
Vladimir Marko23a28212014-01-09 19:24:37 +000026#include "common_throws.h"
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070027#include "dex_cache.h"
Mathieu Chartierf8322842014-05-16 10:59:25 -070028#include "dex_file.h"
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -070029#include "gc/heap-inl.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080030#include "iftable.h"
Ian Rogers62d6c772013-02-27 08:32:07 -080031#include "object_array-inl.h"
Mingyao Yang98d1cc82014-05-15 17:02:16 -070032#include "read_barrier-inl.h"
Fred Shih4ee7a662014-07-11 09:59:27 -070033#include "reference-inl.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080034#include "runtime.h"
35#include "string.h"
36
37namespace art {
38namespace mirror {
39
Hiroshi Yamauchi25023c72014-05-09 11:45:53 -070040template<VerifyObjectFlags kVerifyFlags, ReadBarrierOption kReadBarrierOption>
Ian Rogersef7d42f2014-01-06 12:55:46 -080041inline uint32_t Class::GetObjectSize() {
Hiroshi Yamauchi25023c72014-05-09 11:45:53 -070042 if (kIsDebugBuild) {
43 // Use a local variable as (D)CHECK can't handle the space between
44 // the two template params.
45 bool is_variable_size = IsVariableSize<kVerifyFlags, kReadBarrierOption>();
46 CHECK(!is_variable_size) << " class=" << PrettyTypeOf(this);
47 }
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070048 return GetField32(OFFSET_OF_OBJECT_MEMBER(Class, object_size_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080049}
50
Ian Rogersef7d42f2014-01-06 12:55:46 -080051inline Class* Class::GetSuperClass() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080052 // Can only get super class for loaded classes (hack for when runtime is
53 // initializing)
Brian Carlstrom073278c2014-02-19 15:21:21 -080054 DCHECK(IsLoaded() || IsErroneous() || !Runtime::Current()->IsStarted()) << IsLoaded();
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070055 return GetFieldObject<Class>(OFFSET_OF_OBJECT_MEMBER(Class, super_class_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080056}
57
Ian Rogersef7d42f2014-01-06 12:55:46 -080058inline ClassLoader* Class::GetClassLoader() {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070059 return GetFieldObject<ClassLoader>(OFFSET_OF_OBJECT_MEMBER(Class, class_loader_));
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070060}
61
Mathieu Chartierc2f4d022014-03-03 16:11:42 -080062template<VerifyObjectFlags kVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -080063inline DexCache* Class::GetDexCache() {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070064 return GetFieldObject<DexCache, kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, dex_cache_));
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070065}
66
Ian Rogersef7d42f2014-01-06 12:55:46 -080067inline ObjectArray<ArtMethod>* Class::GetDirectMethods() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080068 DCHECK(IsLoaded() || IsErroneous());
Ian Rogers700a4022014-05-19 16:49:03 -070069 return GetFieldObject<ObjectArray<ArtMethod>>(OFFSET_OF_OBJECT_MEMBER(Class, direct_methods_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080070}
71
Brian Carlstromea46f952013-07-30 01:26:50 -070072inline void Class::SetDirectMethods(ObjectArray<ArtMethod>* new_direct_methods)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080073 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers700a4022014-05-19 16:49:03 -070074 DCHECK(NULL == GetFieldObject<ObjectArray<ArtMethod>>(
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070075 OFFSET_OF_OBJECT_MEMBER(Class, direct_methods_)));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080076 DCHECK_NE(0, new_direct_methods->GetLength());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070077 SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(Class, direct_methods_), new_direct_methods);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080078}
79
Ian Rogersef7d42f2014-01-06 12:55:46 -080080inline ArtMethod* Class::GetDirectMethod(int32_t i) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080081 return GetDirectMethods()->Get(i);
82}
83
Brian Carlstromea46f952013-07-30 01:26:50 -070084inline void Class::SetDirectMethod(uint32_t i, ArtMethod* f) // TODO: uint16_t
Brian Carlstrom2ce745c2013-07-17 17:44:30 -070085 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Brian Carlstromea46f952013-07-30 01:26:50 -070086 ObjectArray<ArtMethod>* direct_methods =
Ian Rogers700a4022014-05-19 16:49:03 -070087 GetFieldObject<ObjectArray<ArtMethod>>(OFFSET_OF_OBJECT_MEMBER(Class, direct_methods_));
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010088 direct_methods->Set<false>(i, f);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080089}
90
91// Returns the number of static, private, and constructor methods.
Ian Rogersef7d42f2014-01-06 12:55:46 -080092inline uint32_t Class::NumDirectMethods() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080093 return (GetDirectMethods() != NULL) ? GetDirectMethods()->GetLength() : 0;
94}
95
Mathieu Chartier4e305412014-02-19 10:54:44 -080096template<VerifyObjectFlags kVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -080097inline ObjectArray<ArtMethod>* Class::GetVirtualMethods() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080098 DCHECK(IsLoaded() || IsErroneous());
Ian Rogers700a4022014-05-19 16:49:03 -070099 return GetFieldObject<ObjectArray<ArtMethod>>(OFFSET_OF_OBJECT_MEMBER(Class, virtual_methods_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800100}
101
Brian Carlstromea46f952013-07-30 01:26:50 -0700102inline void Class::SetVirtualMethods(ObjectArray<ArtMethod>* new_virtual_methods) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800103 // TODO: we reassign virtual methods to grow the table for miranda
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100104 // methods.. they should really just be assigned once.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800105 DCHECK_NE(0, new_virtual_methods->GetLength());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700106 SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(Class, virtual_methods_), new_virtual_methods);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800107}
108
Ian Rogersef7d42f2014-01-06 12:55:46 -0800109inline uint32_t Class::NumVirtualMethods() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800110 return (GetVirtualMethods() != NULL) ? GetVirtualMethods()->GetLength() : 0;
111}
112
Mathieu Chartier4e305412014-02-19 10:54:44 -0800113template<VerifyObjectFlags kVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800114inline ArtMethod* Class::GetVirtualMethod(uint32_t i) {
Mathieu Chartier4e305412014-02-19 10:54:44 -0800115 DCHECK(IsResolved<kVerifyFlags>() || IsErroneous<kVerifyFlags>());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800116 return GetVirtualMethods()->Get(i);
117}
118
Ian Rogersef7d42f2014-01-06 12:55:46 -0800119inline ArtMethod* Class::GetVirtualMethodDuringLinking(uint32_t i) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800120 DCHECK(IsLoaded() || IsErroneous());
121 return GetVirtualMethods()->Get(i);
122}
123
Brian Carlstromea46f952013-07-30 01:26:50 -0700124inline void Class::SetVirtualMethod(uint32_t i, ArtMethod* f) // TODO: uint16_t
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800125 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Brian Carlstromea46f952013-07-30 01:26:50 -0700126 ObjectArray<ArtMethod>* virtual_methods =
Ian Rogers700a4022014-05-19 16:49:03 -0700127 GetFieldObject<ObjectArray<ArtMethod>>(OFFSET_OF_OBJECT_MEMBER(Class, virtual_methods_));
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100128 virtual_methods->Set<false>(i, f);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800129}
130
Ian Rogersef7d42f2014-01-06 12:55:46 -0800131inline ObjectArray<ArtMethod>* Class::GetVTable() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800132 DCHECK(IsResolved() || IsErroneous());
Ian Rogers700a4022014-05-19 16:49:03 -0700133 return GetFieldObject<ObjectArray<ArtMethod>>(OFFSET_OF_OBJECT_MEMBER(Class, vtable_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800134}
135
Ian Rogersef7d42f2014-01-06 12:55:46 -0800136inline ObjectArray<ArtMethod>* Class::GetVTableDuringLinking() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800137 DCHECK(IsLoaded() || IsErroneous());
Ian Rogers700a4022014-05-19 16:49:03 -0700138 return GetFieldObject<ObjectArray<ArtMethod>>(OFFSET_OF_OBJECT_MEMBER(Class, vtable_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800139}
140
Ian Rogersef7d42f2014-01-06 12:55:46 -0800141inline void Class::SetVTable(ObjectArray<ArtMethod>* new_vtable) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700142 SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(Class, vtable_), new_vtable);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800143}
144
Ian Rogersef7d42f2014-01-06 12:55:46 -0800145inline ObjectArray<ArtMethod>* Class::GetImTable() {
Ian Rogers700a4022014-05-19 16:49:03 -0700146 return GetFieldObject<ObjectArray<ArtMethod>>(OFFSET_OF_OBJECT_MEMBER(Class, imtable_));
Jeff Hao88474b42013-10-23 16:24:40 -0700147}
148
149inline void Class::SetImTable(ObjectArray<ArtMethod>* new_imtable) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700150 SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(Class, imtable_), new_imtable);
Jeff Hao88474b42013-10-23 16:24:40 -0700151}
152
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700153inline ArtMethod* Class::GetEmbeddedImTableEntry(uint32_t i) {
154 uint32_t offset = EmbeddedImTableOffset().Uint32Value() + i * sizeof(ImTableEntry);
155 return GetFieldObject<mirror::ArtMethod>(MemberOffset(offset));
156}
157
158inline void Class::SetEmbeddedImTableEntry(uint32_t i, ArtMethod* method) {
159 uint32_t offset = EmbeddedImTableOffset().Uint32Value() + i * sizeof(ImTableEntry);
160 SetFieldObject<false>(MemberOffset(offset), method);
161 CHECK(method == GetImTable()->Get(i));
162}
163
164inline void Class::SetEmbeddedVTableEntry(uint32_t i, ArtMethod* method) {
165 uint32_t offset = EmbeddedVTableOffset().Uint32Value() + i * sizeof(VTableEntry);
166 SetFieldObject<false>(MemberOffset(offset), method);
167 CHECK(method == GetVTableDuringLinking()->Get(i));
168}
169
Ian Rogersef7d42f2014-01-06 12:55:46 -0800170inline bool Class::Implements(Class* klass) {
Ian Rogers693ff612013-02-01 10:56:12 -0800171 DCHECK(klass != NULL);
172 DCHECK(klass->IsInterface()) << PrettyClass(this);
173 // All interfaces implemented directly and by our superclass, and
174 // recursively all super-interfaces of those interfaces, are listed
175 // in iftable_, so we can just do a linear scan through that.
176 int32_t iftable_count = GetIfTableCount();
177 IfTable* iftable = GetIfTable();
178 for (int32_t i = 0; i < iftable_count; i++) {
179 if (iftable->GetInterface(i) == klass) {
180 return true;
181 }
182 }
183 return false;
184}
185
186// Determine whether "this" is assignable from "src", where both of these
187// are array classes.
188//
189// Consider an array class, e.g. Y[][], where Y is a subclass of X.
190// Y[][] = Y[][] --> true (identity)
191// X[][] = Y[][] --> true (element superclass)
192// Y = Y[][] --> false
193// Y[] = Y[][] --> false
194// Object = Y[][] --> true (everything is an object)
195// Object[] = Y[][] --> true
196// Object[][] = Y[][] --> true
197// Object[][][] = Y[][] --> false (too many []s)
198// Serializable = Y[][] --> true (all arrays are Serializable)
199// Serializable[] = Y[][] --> true
200// Serializable[][] = Y[][] --> false (unless Y is Serializable)
201//
202// Don't forget about primitive types.
203// Object[] = int[] --> false
204//
Ian Rogersef7d42f2014-01-06 12:55:46 -0800205inline bool Class::IsArrayAssignableFromArray(Class* src) {
Ian Rogers693ff612013-02-01 10:56:12 -0800206 DCHECK(IsArrayClass()) << PrettyClass(this);
207 DCHECK(src->IsArrayClass()) << PrettyClass(src);
208 return GetComponentType()->IsAssignableFrom(src->GetComponentType());
209}
210
Ian Rogersef7d42f2014-01-06 12:55:46 -0800211inline bool Class::IsAssignableFromArray(Class* src) {
Ian Rogers693ff612013-02-01 10:56:12 -0800212 DCHECK(!IsInterface()) << PrettyClass(this); // handled first in IsAssignableFrom
213 DCHECK(src->IsArrayClass()) << PrettyClass(src);
214 if (!IsArrayClass()) {
215 // If "this" is not also an array, it must be Object.
216 // src's super should be java_lang_Object, since it is an array.
217 Class* java_lang_Object = src->GetSuperClass();
218 DCHECK(java_lang_Object != NULL) << PrettyClass(src);
Ian Rogersfa46d3e2013-05-15 00:16:04 -0700219 DCHECK(java_lang_Object->GetSuperClass() == NULL) << PrettyClass(src);
Ian Rogers693ff612013-02-01 10:56:12 -0800220 return this == java_lang_Object;
221 }
222 return IsArrayAssignableFromArray(src);
223}
224
Vladimir Marko89786432014-01-31 15:03:55 +0000225template <bool throw_on_failure, bool use_referrers_cache>
226inline bool Class::ResolvedFieldAccessTest(Class* access_to, ArtField* field,
Ian Rogersef7d42f2014-01-06 12:55:46 -0800227 uint32_t field_idx, DexCache* dex_cache) {
Vladimir Marko89786432014-01-31 15:03:55 +0000228 DCHECK_EQ(use_referrers_cache, dex_cache == nullptr);
Vladimir Marko23a28212014-01-09 19:24:37 +0000229 if (UNLIKELY(!this->CanAccess(access_to))) {
230 // The referrer class can't access the field's declaring class but may still be able
231 // to access the field if the FieldId specifies an accessible subclass of the declaring
232 // class rather than the declaring class itself.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800233 DexCache* referrer_dex_cache = use_referrers_cache ? this->GetDexCache() : dex_cache;
Vladimir Marko23a28212014-01-09 19:24:37 +0000234 uint32_t class_idx = referrer_dex_cache->GetDexFile()->GetFieldId(field_idx).class_idx_;
235 // The referenced class has already been resolved with the field, get it from the dex cache.
236 Class* dex_access_to = referrer_dex_cache->GetResolvedType(class_idx);
237 DCHECK(dex_access_to != nullptr);
238 if (UNLIKELY(!this->CanAccess(dex_access_to))) {
239 if (throw_on_failure) {
240 ThrowIllegalAccessErrorClass(this, dex_access_to);
241 }
242 return false;
243 }
244 DCHECK_EQ(this->CanAccessMember(access_to, field->GetAccessFlags()),
245 this->CanAccessMember(dex_access_to, field->GetAccessFlags()));
246 }
247 if (LIKELY(this->CanAccessMember(access_to, field->GetAccessFlags()))) {
248 return true;
249 }
250 if (throw_on_failure) {
251 ThrowIllegalAccessErrorField(this, field);
252 }
253 return false;
254}
255
Vladimir Marko89786432014-01-31 15:03:55 +0000256template <bool throw_on_failure, bool use_referrers_cache, InvokeType throw_invoke_type>
257inline bool Class::ResolvedMethodAccessTest(Class* access_to, ArtMethod* method,
Ian Rogersef7d42f2014-01-06 12:55:46 -0800258 uint32_t method_idx, DexCache* dex_cache) {
Vladimir Marko23a28212014-01-09 19:24:37 +0000259 COMPILE_ASSERT(throw_on_failure || throw_invoke_type == kStatic, non_default_throw_invoke_type);
Vladimir Marko89786432014-01-31 15:03:55 +0000260 DCHECK_EQ(use_referrers_cache, dex_cache == nullptr);
Vladimir Marko23a28212014-01-09 19:24:37 +0000261 if (UNLIKELY(!this->CanAccess(access_to))) {
262 // The referrer class can't access the method's declaring class but may still be able
263 // to access the method if the MethodId specifies an accessible subclass of the declaring
264 // class rather than the declaring class itself.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800265 DexCache* referrer_dex_cache = use_referrers_cache ? this->GetDexCache() : dex_cache;
Vladimir Marko23a28212014-01-09 19:24:37 +0000266 uint32_t class_idx = referrer_dex_cache->GetDexFile()->GetMethodId(method_idx).class_idx_;
267 // The referenced class has already been resolved with the method, get it from the dex cache.
268 Class* dex_access_to = referrer_dex_cache->GetResolvedType(class_idx);
269 DCHECK(dex_access_to != nullptr);
270 if (UNLIKELY(!this->CanAccess(dex_access_to))) {
271 if (throw_on_failure) {
272 ThrowIllegalAccessErrorClassForMethodDispatch(this, dex_access_to,
273 method, throw_invoke_type);
274 }
275 return false;
276 }
277 DCHECK_EQ(this->CanAccessMember(access_to, method->GetAccessFlags()),
278 this->CanAccessMember(dex_access_to, method->GetAccessFlags()));
279 }
280 if (LIKELY(this->CanAccessMember(access_to, method->GetAccessFlags()))) {
281 return true;
282 }
283 if (throw_on_failure) {
284 ThrowIllegalAccessErrorMethod(this, method);
285 }
286 return false;
287}
288
Vladimir Marko89786432014-01-31 15:03:55 +0000289inline bool Class::CanAccessResolvedField(Class* access_to, ArtField* field,
Ian Rogersef7d42f2014-01-06 12:55:46 -0800290 DexCache* dex_cache, uint32_t field_idx) {
291 return ResolvedFieldAccessTest<false, false>(access_to, field, field_idx, dex_cache);
Vladimir Marko89786432014-01-31 15:03:55 +0000292}
293
294inline bool Class::CheckResolvedFieldAccess(Class* access_to, ArtField* field,
295 uint32_t field_idx) {
296 return ResolvedFieldAccessTest<true, true>(access_to, field, field_idx, nullptr);
297}
298
299inline bool Class::CanAccessResolvedMethod(Class* access_to, ArtMethod* method,
Ian Rogersef7d42f2014-01-06 12:55:46 -0800300 DexCache* dex_cache, uint32_t method_idx) {
301 return ResolvedMethodAccessTest<false, false, kStatic>(access_to, method, method_idx, dex_cache);
Vladimir Marko89786432014-01-31 15:03:55 +0000302}
303
304template <InvokeType throw_invoke_type>
305inline bool Class::CheckResolvedMethodAccess(Class* access_to, ArtMethod* method,
306 uint32_t method_idx) {
307 return ResolvedMethodAccessTest<true, true, throw_invoke_type>(access_to, method, method_idx,
308 nullptr);
309}
310
Ian Rogersef7d42f2014-01-06 12:55:46 -0800311inline bool Class::IsSubClass(Class* klass) {
Ian Rogers693ff612013-02-01 10:56:12 -0800312 DCHECK(!IsInterface()) << PrettyClass(this);
313 DCHECK(!IsArrayClass()) << PrettyClass(this);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800314 Class* current = this;
Ian Rogers693ff612013-02-01 10:56:12 -0800315 do {
316 if (current == klass) {
317 return true;
318 }
319 current = current->GetSuperClass();
320 } while (current != NULL);
321 return false;
322}
323
Ian Rogersef7d42f2014-01-06 12:55:46 -0800324inline ArtMethod* Class::FindVirtualMethodForInterface(ArtMethod* method) {
Ian Rogers693ff612013-02-01 10:56:12 -0800325 Class* declaring_class = method->GetDeclaringClass();
326 DCHECK(declaring_class != NULL) << PrettyClass(this);
327 DCHECK(declaring_class->IsInterface()) << PrettyMethod(method);
328 // TODO cache to improve lookup speed
329 int32_t iftable_count = GetIfTableCount();
330 IfTable* iftable = GetIfTable();
331 for (int32_t i = 0; i < iftable_count; i++) {
332 if (iftable->GetInterface(i) == declaring_class) {
333 return iftable->GetMethodArray(i)->Get(method->GetMethodIndex());
334 }
335 }
336 return NULL;
337}
338
Ian Rogersef7d42f2014-01-06 12:55:46 -0800339inline ArtMethod* Class::FindVirtualMethodForVirtual(ArtMethod* method) {
Sameer Abu Asal02c42232013-04-30 12:09:45 -0700340 DCHECK(!method->GetDeclaringClass()->IsInterface() || method->IsMiranda());
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800341 // The argument method may from a super class.
342 // Use the index to a potentially overridden one for this instance's class.
343 return GetVTable()->Get(method->GetMethodIndex());
344}
345
Ian Rogersef7d42f2014-01-06 12:55:46 -0800346inline ArtMethod* Class::FindVirtualMethodForSuper(ArtMethod* method) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800347 DCHECK(!method->GetDeclaringClass()->IsInterface());
348 return GetSuperClass()->GetVTable()->Get(method->GetMethodIndex());
349}
350
Ian Rogersef7d42f2014-01-06 12:55:46 -0800351inline ArtMethod* Class::FindVirtualMethodForVirtualOrInterface(ArtMethod* method) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800352 if (method->IsDirect()) {
353 return method;
354 }
Jeff Hao201803f2013-11-20 18:11:39 -0800355 if (method->GetDeclaringClass()->IsInterface() && !method->IsMiranda()) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800356 return FindVirtualMethodForInterface(method);
357 }
358 return FindVirtualMethodForVirtual(method);
359}
360
Ian Rogersef7d42f2014-01-06 12:55:46 -0800361inline IfTable* Class::GetIfTable() {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700362 return GetFieldObject<IfTable>(OFFSET_OF_OBJECT_MEMBER(Class, iftable_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800363}
364
Ian Rogersef7d42f2014-01-06 12:55:46 -0800365inline int32_t Class::GetIfTableCount() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800366 IfTable* iftable = GetIfTable();
367 if (iftable == NULL) {
368 return 0;
369 }
370 return iftable->Count();
371}
372
373inline void Class::SetIfTable(IfTable* new_iftable) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700374 SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(Class, iftable_), new_iftable);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800375}
376
Ian Rogersef7d42f2014-01-06 12:55:46 -0800377inline ObjectArray<ArtField>* Class::GetIFields() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800378 DCHECK(IsLoaded() || IsErroneous());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700379 return GetFieldObject<ObjectArray<ArtField>>(OFFSET_OF_OBJECT_MEMBER(Class, ifields_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800380}
381
Brian Carlstromea46f952013-07-30 01:26:50 -0700382inline void Class::SetIFields(ObjectArray<ArtField>* new_ifields)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800383 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers700a4022014-05-19 16:49:03 -0700384 DCHECK(NULL == GetFieldObject<ObjectArray<ArtField>>(OFFSET_OF_OBJECT_MEMBER(Class, ifields_)));
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700385 SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(Class, ifields_), new_ifields);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800386}
387
Ian Rogersef7d42f2014-01-06 12:55:46 -0800388inline ObjectArray<ArtField>* Class::GetSFields() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800389 DCHECK(IsLoaded() || IsErroneous());
Ian Rogers700a4022014-05-19 16:49:03 -0700390 return GetFieldObject<ObjectArray<ArtField>>(OFFSET_OF_OBJECT_MEMBER(Class, sfields_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800391}
392
Brian Carlstromea46f952013-07-30 01:26:50 -0700393inline void Class::SetSFields(ObjectArray<ArtField>* new_sfields)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800394 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700395 DCHECK((IsRetired() && new_sfields == nullptr) ||
396 (NULL == GetFieldObject<ObjectArray<ArtField>>(OFFSET_OF_OBJECT_MEMBER(Class, sfields_))));
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700397 SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(Class, sfields_), new_sfields);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800398}
399
Ian Rogersef7d42f2014-01-06 12:55:46 -0800400inline uint32_t Class::NumStaticFields() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800401 return (GetSFields() != NULL) ? GetSFields()->GetLength() : 0;
402}
403
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700404
Ian Rogersef7d42f2014-01-06 12:55:46 -0800405inline ArtField* Class::GetStaticField(uint32_t i) // TODO: uint16_t
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800406 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700407 return GetSFields()->GetWithoutChecks(i);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800408}
409
Brian Carlstromea46f952013-07-30 01:26:50 -0700410inline void Class::SetStaticField(uint32_t i, ArtField* f) // TODO: uint16_t
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800411 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers700a4022014-05-19 16:49:03 -0700412 ObjectArray<ArtField>* sfields= GetFieldObject<ObjectArray<ArtField>>(
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700413 OFFSET_OF_OBJECT_MEMBER(Class, sfields_));
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100414 sfields->Set<false>(i, f);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800415}
416
Ian Rogersef7d42f2014-01-06 12:55:46 -0800417inline uint32_t Class::NumInstanceFields() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800418 return (GetIFields() != NULL) ? GetIFields()->GetLength() : 0;
419}
420
Ian Rogersef7d42f2014-01-06 12:55:46 -0800421inline ArtField* Class::GetInstanceField(uint32_t i) { // TODO: uint16_t
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800422 DCHECK_NE(NumInstanceFields(), 0U);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700423 return GetIFields()->GetWithoutChecks(i);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800424}
425
Brian Carlstromea46f952013-07-30 01:26:50 -0700426inline void Class::SetInstanceField(uint32_t i, ArtField* f) // TODO: uint16_t
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700427 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers700a4022014-05-19 16:49:03 -0700428 ObjectArray<ArtField>* ifields= GetFieldObject<ObjectArray<ArtField>>(
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700429 OFFSET_OF_OBJECT_MEMBER(Class, ifields_));
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100430 ifields->Set<false>(i, f);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800431}
432
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700433template<VerifyObjectFlags kVerifyFlags>
434inline uint32_t Class::GetReferenceInstanceOffsets() {
435 DCHECK(IsResolved<kVerifyFlags>() || IsErroneous<kVerifyFlags>());
436 return GetField32<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, reference_instance_offsets_));
437}
438
439inline void Class::SetClinitThreadId(pid_t new_clinit_thread_id) {
440 if (Runtime::Current()->IsActiveTransaction()) {
441 SetField32<true>(OFFSET_OF_OBJECT_MEMBER(Class, clinit_thread_id_), new_clinit_thread_id);
442 } else {
443 SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, clinit_thread_id_), new_clinit_thread_id);
444 }
445}
446
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800447inline void Class::SetVerifyErrorClass(Class* klass) {
448 CHECK(klass != NULL) << PrettyClass(this);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100449 if (Runtime::Current()->IsActiveTransaction()) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700450 SetFieldObject<true>(OFFSET_OF_OBJECT_MEMBER(Class, verify_error_class_), klass);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100451 } else {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700452 SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(Class, verify_error_class_), klass);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100453 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800454}
455
Mathieu Chartier4e305412014-02-19 10:54:44 -0800456template<VerifyObjectFlags kVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800457inline uint32_t Class::GetAccessFlags() {
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700458 // Check class is loaded/retired or this is java.lang.String that has a
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800459 // circularity issue during loading the names of its members
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700460 DCHECK(IsIdxLoaded<kVerifyFlags>() || IsRetired<kVerifyFlags>() ||
Mathieu Chartier4e305412014-02-19 10:54:44 -0800461 IsErroneous<static_cast<VerifyObjectFlags>(kVerifyFlags & ~kVerifyThis)>() ||
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800462 this == String::GetJavaLangString() ||
Brian Carlstromea46f952013-07-30 01:26:50 -0700463 this == ArtField::GetJavaLangReflectArtField() ||
464 this == ArtMethod::GetJavaLangReflectArtMethod());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700465 return GetField32<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, access_flags_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800466}
467
Ian Rogersef7d42f2014-01-06 12:55:46 -0800468inline String* Class::GetName() {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700469 return GetFieldObject<String>(OFFSET_OF_OBJECT_MEMBER(Class, name_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800470}
471inline void Class::SetName(String* name) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100472 if (Runtime::Current()->IsActiveTransaction()) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700473 SetFieldObject<true>(OFFSET_OF_OBJECT_MEMBER(Class, name_), name);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100474 } else {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700475 SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(Class, name_), name);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100476 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800477}
478
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700479template<VerifyObjectFlags kVerifyFlags>
480inline Primitive::Type Class::GetPrimitiveType() {
481 DCHECK_EQ(sizeof(Primitive::Type), sizeof(int32_t));
482 return static_cast<Primitive::Type>(
483 GetField32<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, primitive_type_)));
484}
485
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -0700486inline void Class::CheckObjectAlloc() {
Hiroshi Yamauchi4cd662e2014-04-03 16:28:10 -0700487 DCHECK(!IsArrayClass())
488 << PrettyClass(this)
489 << "A array shouldn't be allocated through this "
490 << "as it requires a pre-fence visitor that sets the class size.";
491 DCHECK(!IsClassClass())
492 << PrettyClass(this)
493 << "A class object shouldn't be allocated through this "
494 << "as it requires a pre-fence visitor that sets the class size.";
Hiroshi Yamauchi967a0ad2013-09-10 16:24:21 -0700495 DCHECK(IsInstantiable()) << PrettyClass(this);
496 // TODO: decide whether we want this check. It currently fails during bootstrap.
497 // DCHECK(!Runtime::Current()->IsStarted() || IsInitializing()) << PrettyClass(this);
498 DCHECK_GE(this->object_size_, sizeof(Object));
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -0700499}
500
Mathieu Chartier8668c3c2014-04-24 16:48:11 -0700501template<bool kIsInstrumented, bool kCheckAddFinalizer>
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800502inline Object* Class::Alloc(Thread* self, gc::AllocatorType allocator_type) {
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -0700503 CheckObjectAlloc();
Mathieu Chartier590fee92013-09-13 13:46:47 -0700504 gc::Heap* heap = Runtime::Current()->GetHeap();
Mathieu Chartier8668c3c2014-04-24 16:48:11 -0700505 const bool add_finalizer = kCheckAddFinalizer && IsFinalizable();
506 if (!kCheckAddFinalizer) {
507 DCHECK(!IsFinalizable());
508 }
509 mirror::Object* obj =
510 heap->AllocObjectWithAllocator<kIsInstrumented, false>(self, this, this->object_size_,
511 allocator_type, VoidFunctor());
512 if (add_finalizer && LIKELY(obj != nullptr)) {
513 heap->AddFinalizerReference(self, &obj);
514 }
515 return obj;
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800516}
517
518inline Object* Class::AllocObject(Thread* self) {
519 return Alloc<true>(self, Runtime::Current()->GetHeap()->GetCurrentAllocator());
520}
521
522inline Object* Class::AllocNonMovableObject(Thread* self) {
523 return Alloc<true>(self, Runtime::Current()->GetHeap()->GetCurrentNonMovingAllocator());
Hiroshi Yamauchi967a0ad2013-09-10 16:24:21 -0700524}
525
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700526inline uint32_t Class::ComputeClassSize(bool has_embedded_tables,
527 uint32_t num_vtable_entries,
528 uint32_t num_32bit_static_fields,
529 uint32_t num_64bit_static_fields,
530 uint32_t num_ref_static_fields) {
531 // Space used by java.lang.Class and its instance fields.
532 uint32_t size = sizeof(Class);
533 // Space used by embedded tables.
534 if (has_embedded_tables) {
535 uint32_t embedded_imt_size = kImtSize * sizeof(ImTableEntry);
536 uint32_t embedded_vtable_size = num_vtable_entries * sizeof(VTableEntry);
537 size += embedded_imt_size + embedded_vtable_size;
538 }
539 // Space used by reference statics.
540 size += num_ref_static_fields * sizeof(HeapReference<Object>);
541 // Possible pad for alignment.
542 if (((size & 7) != 0) && (num_64bit_static_fields > 0) && (num_32bit_static_fields == 0)) {
543 size += sizeof(uint32_t);
544 }
545 // Space used for primitive static fields.
546 size += (num_32bit_static_fields * sizeof(uint32_t)) +
547 (num_64bit_static_fields * sizeof(uint64_t));
548 return size;
549}
550
Mathieu Chartier407f7022014-02-18 14:37:05 -0800551template <bool kVisitClass, typename Visitor>
552inline void Class::VisitReferences(mirror::Class* klass, const Visitor& visitor) {
Mathieu Chartier52e4b432014-06-10 11:22:31 -0700553 // Visit the static fields first so that we don't overwrite the SFields / IFields instance
554 // fields.
Mathieu Chartier52e4b432014-06-10 11:22:31 -0700555 VisitInstanceFieldsReferences<kVisitClass>(klass, visitor);
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700556 if (!IsTemp()) {
557 // Temp classes don't ever populate imt/vtable or static fields and they are not even
558 // allocated with the right size for those.
559 VisitStaticFieldsReferences<kVisitClass>(this, visitor);
560 if (ShouldHaveEmbeddedImtAndVTable()) {
561 VisitEmbeddedImtAndVTable(visitor);
562 }
563 }
564}
565
566template<typename Visitor>
567inline void Class::VisitEmbeddedImtAndVTable(const Visitor& visitor) {
568 uint32_t pos = sizeof(mirror::Class);
569
570 size_t count = kImtSize;
571 for (size_t i = 0; i < count; ++i) {
572 MemberOffset offset = MemberOffset(pos);
573 visitor(this, offset, true);
574 pos += sizeof(ImTableEntry);
575 }
576
577 count = ((GetVTable() != NULL) ? GetVTable()->GetLength() : 0);
578 for (size_t i = 0; i < count; ++i) {
579 MemberOffset offset = MemberOffset(pos);
580 visitor(this, offset, true);
581 pos += sizeof(VTableEntry);
582 }
Mathieu Chartier407f7022014-02-18 14:37:05 -0800583}
584
Hiroshi Yamauchi4f1ebc22014-06-25 14:30:41 -0700585template<ReadBarrierOption kReadBarrierOption>
Hiroshi Yamauchibd0fb612014-05-20 13:46:00 -0700586inline bool Class::IsArtFieldClass() const {
Hiroshi Yamauchi4f1ebc22014-06-25 14:30:41 -0700587 return this == ArtField::GetJavaLangReflectArtField<kReadBarrierOption>();
Hiroshi Yamauchi9103c862014-04-22 13:51:07 -0700588}
589
Hiroshi Yamauchi4f1ebc22014-06-25 14:30:41 -0700590template<ReadBarrierOption kReadBarrierOption>
Hiroshi Yamauchibd0fb612014-05-20 13:46:00 -0700591inline bool Class::IsArtMethodClass() const {
Hiroshi Yamauchi4f1ebc22014-06-25 14:30:41 -0700592 return this == ArtMethod::GetJavaLangReflectArtMethod<kReadBarrierOption>();
Hiroshi Yamauchi9103c862014-04-22 13:51:07 -0700593}
594
Fred Shih4ee7a662014-07-11 09:59:27 -0700595template<ReadBarrierOption kReadBarrierOption>
596inline bool Class::IsReferenceClass() const {
597 return this == Reference::GetJavaLangRefReference<kReadBarrierOption>();
598}
599
Hiroshi Yamauchi25023c72014-05-09 11:45:53 -0700600template<VerifyObjectFlags kVerifyFlags, ReadBarrierOption kReadBarrierOption>
601inline bool Class::IsClassClass() {
602 Class* java_lang_Class = GetClass<kVerifyFlags, kReadBarrierOption>()->
603 template GetClass<kVerifyFlags, kReadBarrierOption>();
604 return this == java_lang_Class;
605}
606
Mathieu Chartierf8322842014-05-16 10:59:25 -0700607inline const DexFile& Class::GetDexFile() {
608 return *GetDexCache()->GetDexFile();
609}
610
611inline bool Class::DescriptorEquals(const char* match) {
612 if (UNLIKELY(IsArrayClass())) {
613 return match[0] == '[' && GetComponentType()->DescriptorEquals(match + 1);
614 } else if (UNLIKELY(IsPrimitive())) {
615 return strcmp(Primitive::Descriptor(GetPrimitiveType()), match) == 0;
616 } else if (UNLIKELY(IsProxyClass())) {
617 return Runtime::Current()->GetClassLinker()->GetDescriptorForProxy(this) == match;
618 } else {
619 const DexFile& dex_file = GetDexFile();
620 const DexFile::TypeId& type_id = dex_file.GetTypeId(GetClassDef()->class_idx_);
621 return strcmp(dex_file.GetTypeDescriptor(type_id), match) == 0;
622 }
623}
624
Sebastien Hertz4e99b3d2014-06-24 14:35:40 +0200625inline void Class::AssertInitializedOrInitializingInThread(Thread* self) {
626 if (kIsDebugBuild && !IsInitialized()) {
627 CHECK(IsInitializing()) << PrettyClass(this) << " is not initializing: " << GetStatus();
628 CHECK_EQ(GetClinitThreadId(), self->GetTid()) << PrettyClass(this)
629 << " is initializing in a different thread";
630 }
631}
632
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700633inline ObjectArray<Class>* Class::GetInterfaces() {
634 CHECK(IsProxyClass());
635 // First static field.
636 DCHECK(GetSFields()->Get(0)->IsArtField());
637 DCHECK_STREQ(GetSFields()->Get(0)->GetName(), "interfaces");
638 MemberOffset field_offset = GetSFields()->Get(0)->GetOffset();
639 return GetFieldObject<ObjectArray<Class>>(field_offset);
640}
641
642inline ObjectArray<ObjectArray<Class>>* Class::GetThrows() {
643 CHECK(IsProxyClass());
644 // Second static field.
645 DCHECK(GetSFields()->Get(1)->IsArtField());
646 DCHECK_STREQ(GetSFields()->Get(1)->GetName(), "throws");
647 MemberOffset field_offset = GetSFields()->Get(1)->GetOffset();
648 return GetFieldObject<ObjectArray<ObjectArray<Class>>>(field_offset);
649}
650
Fred Shih4ee7a662014-07-11 09:59:27 -0700651inline MemberOffset Class::GetDisableIntrinsicFlagOffset() {
652 CHECK(IsReferenceClass());
653 // First static field
654 DCHECK(GetSFields()->Get(0)->IsArtField());
655 DCHECK_STREQ(GetSFields()->Get(0)->GetName(), "disableIntrinsic");
656 return GetSFields()->Get(0)->GetOffset();
657}
658
659inline MemberOffset Class::GetSlowPathFlagOffset() {
660 CHECK(IsReferenceClass());
661 // Second static field
662 DCHECK(GetSFields()->Get(1)->IsArtField());
663 DCHECK_STREQ(GetSFields()->Get(1)->GetName(), "slowPathEnabled");
664 return GetSFields()->Get(1)->GetOffset();
665}
666
667inline bool Class::GetSlowPathEnabled() {
668 return GetField32(GetSlowPathFlagOffset());
669}
670
671inline void Class::SetSlowPath(bool enabled) {
672 SetField32<false>(GetSlowPathFlagOffset(), enabled);
673}
674
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700675inline void Class::InitializeClassVisitor::operator()(
676 mirror::Object* obj, size_t usable_size) const {
677 DCHECK_LE(class_size_, usable_size);
678 // Avoid AsClass as object is not yet in live bitmap or allocation stack.
679 mirror::Class* klass = down_cast<mirror::Class*>(obj);
680 // DCHECK(klass->IsClass());
681 klass->SetClassSize(class_size_);
682 klass->SetPrimitiveType(Primitive::kPrimNot); // Default to not being primitive.
683 klass->SetDexClassDefIndex(DexFile::kDexNoIndex16); // Default to no valid class def index.
684 klass->SetDexTypeIndex(DexFile::kDexNoIndex16); // Default to no valid type index.
685}
686
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800687} // namespace mirror
688} // namespace art
689
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700690#endif // ART_RUNTIME_MIRROR_CLASS_INL_H_