blob: 4991ad7513036386fddb8911794c4a91fe7db54c [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
Mathieu Chartierc7853442015-03-27 14:35:38 -070017#ifndef ART_RUNTIME_ART_FIELD_INL_H_
18#define ART_RUNTIME_ART_FIELD_INL_H_
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080019
Brian Carlstromea46f952013-07-30 01:26:50 -070020#include "art_field.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080021
Ian Rogersc0fa3ad2013-02-05 00:11:55 -080022#include "base/logging.h"
Ian Rogers08f1f502014-12-02 15:04:37 -080023#include "class_linker.h"
Vladimir Marko3481ba22015-04-13 12:22:36 +010024#include "gc_root-inl.h"
Ian Rogers1d54e732013-05-02 21:10:01 -070025#include "gc/accounting/card_table-inl.h"
Ian Rogersc0fa3ad2013-02-05 00:11:55 -080026#include "jvalue.h"
Mathieu Chartierc7853442015-03-27 14:35:38 -070027#include "mirror/dex_cache.h"
28#include "mirror/object-inl.h"
Ian Rogersc0fa3ad2013-02-05 00:11:55 -080029#include "primitive.h"
Mathieu Chartier76433272014-09-26 14:32:37 -070030#include "thread-inl.h"
31#include "scoped_thread_state_change.h"
32#include "well_known_classes.h"
Ian Rogersc0fa3ad2013-02-05 00:11:55 -080033
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080034namespace art {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080035
Mathieu Chartierc7853442015-03-27 14:35:38 -070036inline mirror::Class* ArtField::GetDeclaringClass() {
37 mirror::Class* result = declaring_class_.Read();
38 DCHECK(result != nullptr);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080039 DCHECK(result->IsLoaded() || result->IsErroneous());
40 return result;
41}
42
Mathieu Chartierc7853442015-03-27 14:35:38 -070043inline void ArtField::SetDeclaringClass(mirror::Class* new_declaring_class) {
44 declaring_class_ = GcRoot<mirror::Class>(new_declaring_class);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080045}
46
Ian Rogersef7d42f2014-01-06 12:55:46 -080047inline uint32_t ArtField::GetAccessFlags() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080048 DCHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous());
Mathieu Chartierc7853442015-03-27 14:35:38 -070049 return access_flags_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080050}
51
Ian Rogersef7d42f2014-01-06 12:55:46 -080052inline MemberOffset ArtField::GetOffset() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080053 DCHECK(GetDeclaringClass()->IsResolved() || GetDeclaringClass()->IsErroneous());
Mathieu Chartierc7853442015-03-27 14:35:38 -070054 return MemberOffset(offset_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080055}
56
Ian Rogersef7d42f2014-01-06 12:55:46 -080057inline MemberOffset ArtField::GetOffsetDuringLinking() {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080058 DCHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous());
Mathieu Chartierc7853442015-03-27 14:35:38 -070059 return MemberOffset(offset_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080060}
61
Mathieu Chartierc7853442015-03-27 14:35:38 -070062inline uint32_t ArtField::Get32(mirror::Object* object) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070063 DCHECK(object != nullptr) << PrettyField(this);
Ian Rogersc0fa3ad2013-02-05 00:11:55 -080064 DCHECK(!IsStatic() || (object == GetDeclaringClass()) || !Runtime::Current()->IsStarted());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070065 if (UNLIKELY(IsVolatile())) {
66 return object->GetField32Volatile(GetOffset());
67 }
68 return object->GetField32(GetOffset());
Ian Rogersc0fa3ad2013-02-05 00:11:55 -080069}
70
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010071template<bool kTransactionActive>
Mathieu Chartierc7853442015-03-27 14:35:38 -070072inline void ArtField::Set32(mirror::Object* object, uint32_t new_value) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070073 DCHECK(object != nullptr) << PrettyField(this);
Ian Rogersc0fa3ad2013-02-05 00:11:55 -080074 DCHECK(!IsStatic() || (object == GetDeclaringClass()) || !Runtime::Current()->IsStarted());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070075 if (UNLIKELY(IsVolatile())) {
76 object->SetField32Volatile<kTransactionActive>(GetOffset(), new_value);
77 } else {
78 object->SetField32<kTransactionActive>(GetOffset(), new_value);
79 }
Ian Rogersc0fa3ad2013-02-05 00:11:55 -080080}
81
Mathieu Chartierc7853442015-03-27 14:35:38 -070082inline uint64_t ArtField::Get64(mirror::Object* object) {
Mathieu Chartier2cebb242015-04-21 16:50:40 -070083 DCHECK(object != nullptr) << PrettyField(this);
Ian Rogersc0fa3ad2013-02-05 00:11:55 -080084 DCHECK(!IsStatic() || (object == GetDeclaringClass()) || !Runtime::Current()->IsStarted());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070085 if (UNLIKELY(IsVolatile())) {
86 return object->GetField64Volatile(GetOffset());
87 }
88 return object->GetField64(GetOffset());
Ian Rogersc0fa3ad2013-02-05 00:11:55 -080089}
90
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010091template<bool kTransactionActive>
Mathieu Chartierc7853442015-03-27 14:35:38 -070092inline void ArtField::Set64(mirror::Object* object, uint64_t new_value) {
Mathieu Chartier2cebb242015-04-21 16:50:40 -070093 DCHECK(object != nullptr) << PrettyField(this);
Ian Rogersc0fa3ad2013-02-05 00:11:55 -080094 DCHECK(!IsStatic() || (object == GetDeclaringClass()) || !Runtime::Current()->IsStarted());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070095 if (UNLIKELY(IsVolatile())) {
96 object->SetField64Volatile<kTransactionActive>(GetOffset(), new_value);
97 } else {
98 object->SetField64<kTransactionActive>(GetOffset(), new_value);
99 }
Ian Rogersc0fa3ad2013-02-05 00:11:55 -0800100}
101
Mathieu Chartierc7853442015-03-27 14:35:38 -0700102inline mirror::Object* ArtField::GetObj(mirror::Object* object) {
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700103 DCHECK(object != nullptr) << PrettyField(this);
Ian Rogersc0fa3ad2013-02-05 00:11:55 -0800104 DCHECK(!IsStatic() || (object == GetDeclaringClass()) || !Runtime::Current()->IsStarted());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700105 if (UNLIKELY(IsVolatile())) {
Mathieu Chartierc7853442015-03-27 14:35:38 -0700106 return object->GetFieldObjectVolatile<mirror::Object>(GetOffset());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700107 }
Mathieu Chartierc7853442015-03-27 14:35:38 -0700108 return object->GetFieldObject<mirror::Object>(GetOffset());
Ian Rogersc0fa3ad2013-02-05 00:11:55 -0800109}
110
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100111template<bool kTransactionActive>
Mathieu Chartierc7853442015-03-27 14:35:38 -0700112inline void ArtField::SetObj(mirror::Object* object, mirror::Object* new_value) {
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700113 DCHECK(object != nullptr) << PrettyField(this);
Ian Rogersc0fa3ad2013-02-05 00:11:55 -0800114 DCHECK(!IsStatic() || (object == GetDeclaringClass()) || !Runtime::Current()->IsStarted());
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700115 if (UNLIKELY(IsVolatile())) {
116 object->SetFieldObjectVolatile<kTransactionActive>(GetOffset(), new_value);
117 } else {
118 object->SetFieldObject<kTransactionActive>(GetOffset(), new_value);
119 }
Ian Rogersc0fa3ad2013-02-05 00:11:55 -0800120}
121
Fred Shih37f05ef2014-07-16 18:38:08 -0700122#define FIELD_GET(object, type) \
123 DCHECK_EQ(Primitive::kPrim ## type, GetTypeAsPrimitiveType()) << PrettyField(this); \
124 DCHECK(object != nullptr) << PrettyField(this); \
125 DCHECK(!IsStatic() || (object == GetDeclaringClass()) || !Runtime::Current()->IsStarted()); \
126 if (UNLIKELY(IsVolatile())) { \
127 return object->GetField ## type ## Volatile(GetOffset()); \
128 } \
129 return object->GetField ## type(GetOffset());
130
131#define FIELD_SET(object, type, value) \
132 DCHECK_EQ(Primitive::kPrim ## type, GetTypeAsPrimitiveType()) << PrettyField(this); \
133 DCHECK(object != nullptr) << PrettyField(this); \
134 DCHECK(!IsStatic() || (object == GetDeclaringClass()) || !Runtime::Current()->IsStarted()); \
135 if (UNLIKELY(IsVolatile())) { \
136 object->SetField ## type ## Volatile<kTransactionActive>(GetOffset(), value); \
137 } else { \
138 object->SetField ## type<kTransactionActive>(GetOffset(), value); \
139 }
140
Mathieu Chartierc7853442015-03-27 14:35:38 -0700141inline uint8_t ArtField::GetBoolean(mirror::Object* object) {
Fred Shih37f05ef2014-07-16 18:38:08 -0700142 FIELD_GET(object, Boolean);
Ian Rogersc0fa3ad2013-02-05 00:11:55 -0800143}
144
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100145template<bool kTransactionActive>
Mathieu Chartierc7853442015-03-27 14:35:38 -0700146inline void ArtField::SetBoolean(mirror::Object* object, uint8_t z) {
Fred Shih37f05ef2014-07-16 18:38:08 -0700147 FIELD_SET(object, Boolean, z);
Ian Rogersc0fa3ad2013-02-05 00:11:55 -0800148}
149
Mathieu Chartierc7853442015-03-27 14:35:38 -0700150inline int8_t ArtField::GetByte(mirror::Object* object) {
Fred Shih37f05ef2014-07-16 18:38:08 -0700151 FIELD_GET(object, Byte);
Ian Rogersc0fa3ad2013-02-05 00:11:55 -0800152}
153
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100154template<bool kTransactionActive>
Mathieu Chartierc7853442015-03-27 14:35:38 -0700155inline void ArtField::SetByte(mirror::Object* object, int8_t b) {
Fred Shih37f05ef2014-07-16 18:38:08 -0700156 FIELD_SET(object, Byte, b);
Ian Rogersc0fa3ad2013-02-05 00:11:55 -0800157}
158
Mathieu Chartierc7853442015-03-27 14:35:38 -0700159inline uint16_t ArtField::GetChar(mirror::Object* object) {
Fred Shih37f05ef2014-07-16 18:38:08 -0700160 FIELD_GET(object, Char);
Ian Rogersc0fa3ad2013-02-05 00:11:55 -0800161}
162
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100163template<bool kTransactionActive>
Mathieu Chartierc7853442015-03-27 14:35:38 -0700164inline void ArtField::SetChar(mirror::Object* object, uint16_t c) {
Fred Shih37f05ef2014-07-16 18:38:08 -0700165 FIELD_SET(object, Char, c);
Ian Rogersc0fa3ad2013-02-05 00:11:55 -0800166}
167
Mathieu Chartierc7853442015-03-27 14:35:38 -0700168inline int16_t ArtField::GetShort(mirror::Object* object) {
Fred Shih37f05ef2014-07-16 18:38:08 -0700169 FIELD_GET(object, Short);
Ian Rogersc0fa3ad2013-02-05 00:11:55 -0800170}
171
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100172template<bool kTransactionActive>
Mathieu Chartierc7853442015-03-27 14:35:38 -0700173inline void ArtField::SetShort(mirror::Object* object, int16_t s) {
Fred Shih37f05ef2014-07-16 18:38:08 -0700174 FIELD_SET(object, Short, s);
Ian Rogersc0fa3ad2013-02-05 00:11:55 -0800175}
176
Fred Shih37f05ef2014-07-16 18:38:08 -0700177#undef FIELD_GET
178#undef FIELD_SET
179
Mathieu Chartierc7853442015-03-27 14:35:38 -0700180inline int32_t ArtField::GetInt(mirror::Object* object) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100181 if (kIsDebugBuild) {
Mathieu Chartier61c5ebc2014-06-05 17:42:53 -0700182 Primitive::Type type = GetTypeAsPrimitiveType();
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100183 CHECK(type == Primitive::kPrimInt || type == Primitive::kPrimFloat) << PrettyField(this);
184 }
Ian Rogersc0fa3ad2013-02-05 00:11:55 -0800185 return Get32(object);
186}
187
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100188template<bool kTransactionActive>
Mathieu Chartierc7853442015-03-27 14:35:38 -0700189inline void ArtField::SetInt(mirror::Object* object, int32_t i) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100190 if (kIsDebugBuild) {
Mathieu Chartier61c5ebc2014-06-05 17:42:53 -0700191 Primitive::Type type = GetTypeAsPrimitiveType();
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100192 CHECK(type == Primitive::kPrimInt || type == Primitive::kPrimFloat) << PrettyField(this);
193 }
194 Set32<kTransactionActive>(object, i);
Ian Rogersc0fa3ad2013-02-05 00:11:55 -0800195}
196
Mathieu Chartierc7853442015-03-27 14:35:38 -0700197inline int64_t ArtField::GetLong(mirror::Object* object) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100198 if (kIsDebugBuild) {
Mathieu Chartier61c5ebc2014-06-05 17:42:53 -0700199 Primitive::Type type = GetTypeAsPrimitiveType();
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100200 CHECK(type == Primitive::kPrimLong || type == Primitive::kPrimDouble) << PrettyField(this);
201 }
Ian Rogersc0fa3ad2013-02-05 00:11:55 -0800202 return Get64(object);
203}
204
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100205template<bool kTransactionActive>
Mathieu Chartierc7853442015-03-27 14:35:38 -0700206inline void ArtField::SetLong(mirror::Object* object, int64_t j) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100207 if (kIsDebugBuild) {
Mathieu Chartier61c5ebc2014-06-05 17:42:53 -0700208 Primitive::Type type = GetTypeAsPrimitiveType();
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100209 CHECK(type == Primitive::kPrimLong || type == Primitive::kPrimDouble) << PrettyField(this);
210 }
211 Set64<kTransactionActive>(object, j);
Ian Rogersc0fa3ad2013-02-05 00:11:55 -0800212}
213
Mathieu Chartierc7853442015-03-27 14:35:38 -0700214inline float ArtField::GetFloat(mirror::Object* object) {
Mathieu Chartier61c5ebc2014-06-05 17:42:53 -0700215 DCHECK_EQ(Primitive::kPrimFloat, GetTypeAsPrimitiveType()) << PrettyField(this);
Ian Rogersc0fa3ad2013-02-05 00:11:55 -0800216 JValue bits;
217 bits.SetI(Get32(object));
218 return bits.GetF();
219}
220
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100221template<bool kTransactionActive>
Mathieu Chartierc7853442015-03-27 14:35:38 -0700222inline void ArtField::SetFloat(mirror::Object* object, float f) {
Mathieu Chartier61c5ebc2014-06-05 17:42:53 -0700223 DCHECK_EQ(Primitive::kPrimFloat, GetTypeAsPrimitiveType()) << PrettyField(this);
Ian Rogersc0fa3ad2013-02-05 00:11:55 -0800224 JValue bits;
225 bits.SetF(f);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100226 Set32<kTransactionActive>(object, bits.GetI());
Ian Rogersc0fa3ad2013-02-05 00:11:55 -0800227}
228
Mathieu Chartierc7853442015-03-27 14:35:38 -0700229inline double ArtField::GetDouble(mirror::Object* object) {
Mathieu Chartier61c5ebc2014-06-05 17:42:53 -0700230 DCHECK_EQ(Primitive::kPrimDouble, GetTypeAsPrimitiveType()) << PrettyField(this);
Ian Rogersc0fa3ad2013-02-05 00:11:55 -0800231 JValue bits;
232 bits.SetJ(Get64(object));
233 return bits.GetD();
234}
235
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100236template<bool kTransactionActive>
Mathieu Chartierc7853442015-03-27 14:35:38 -0700237inline void ArtField::SetDouble(mirror::Object* object, double d) {
Mathieu Chartier61c5ebc2014-06-05 17:42:53 -0700238 DCHECK_EQ(Primitive::kPrimDouble, GetTypeAsPrimitiveType()) << PrettyField(this);
Ian Rogersc0fa3ad2013-02-05 00:11:55 -0800239 JValue bits;
240 bits.SetD(d);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100241 Set64<kTransactionActive>(object, bits.GetJ());
Ian Rogersc0fa3ad2013-02-05 00:11:55 -0800242}
243
Mathieu Chartierc7853442015-03-27 14:35:38 -0700244inline mirror::Object* ArtField::GetObject(mirror::Object* object) {
Mathieu Chartier61c5ebc2014-06-05 17:42:53 -0700245 DCHECK_EQ(Primitive::kPrimNot, GetTypeAsPrimitiveType()) << PrettyField(this);
Ian Rogersc0fa3ad2013-02-05 00:11:55 -0800246 return GetObj(object);
247}
248
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100249template<bool kTransactionActive>
Mathieu Chartierc7853442015-03-27 14:35:38 -0700250inline void ArtField::SetObject(mirror::Object* object, mirror::Object* l) {
Mathieu Chartier61c5ebc2014-06-05 17:42:53 -0700251 DCHECK_EQ(Primitive::kPrimNot, GetTypeAsPrimitiveType()) << PrettyField(this);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100252 SetObj<kTransactionActive>(object, l);
Ian Rogersc0fa3ad2013-02-05 00:11:55 -0800253}
254
Mathieu Chartier61c5ebc2014-06-05 17:42:53 -0700255inline const char* ArtField::GetName() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
256 uint32_t field_index = GetDexFieldIndex();
257 if (UNLIKELY(GetDeclaringClass()->IsProxyClass())) {
258 DCHECK(IsStatic());
259 DCHECK_LT(field_index, 2U);
260 return field_index == 0 ? "interfaces" : "throws";
261 }
262 const DexFile* dex_file = GetDexFile();
263 return dex_file->GetFieldName(dex_file->GetFieldId(field_index));
264}
265
266inline const char* ArtField::GetTypeDescriptor() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
267 uint32_t field_index = GetDexFieldIndex();
268 if (UNLIKELY(GetDeclaringClass()->IsProxyClass())) {
269 DCHECK(IsStatic());
270 DCHECK_LT(field_index, 2U);
271 // 0 == Class[] interfaces; 1 == Class[][] throws;
272 return field_index == 0 ? "[Ljava/lang/Class;" : "[[Ljava/lang/Class;";
273 }
274 const DexFile* dex_file = GetDexFile();
275 const DexFile::FieldId& field_id = dex_file->GetFieldId(field_index);
276 return dex_file->GetFieldTypeDescriptor(field_id);
277}
278
279inline Primitive::Type ArtField::GetTypeAsPrimitiveType()
280 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
281 return Primitive::GetType(GetTypeDescriptor()[0]);
282}
283
284inline bool ArtField::IsPrimitiveType() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
285 return GetTypeAsPrimitiveType() != Primitive::kPrimNot;
286}
287
Mathieu Chartierdaaf3262015-03-24 13:30:28 -0700288template <bool kResolve>
Mathieu Chartierc7853442015-03-27 14:35:38 -0700289inline mirror::Class* ArtField::GetType() {
Mathieu Chartierdaaf3262015-03-24 13:30:28 -0700290 const uint32_t field_index = GetDexFieldIndex();
291 auto* declaring_class = GetDeclaringClass();
292 if (UNLIKELY(declaring_class->IsProxyClass())) {
Vladimir Marko3481ba22015-04-13 12:22:36 +0100293 return ProxyFindSystemClass(GetTypeDescriptor());
Ian Rogers08f1f502014-12-02 15:04:37 -0800294 }
Mathieu Chartierdaaf3262015-03-24 13:30:28 -0700295 auto* dex_cache = declaring_class->GetDexCache();
296 const DexFile* const dex_file = dex_cache->GetDexFile();
Ian Rogers08f1f502014-12-02 15:04:37 -0800297 const DexFile::FieldId& field_id = dex_file->GetFieldId(field_index);
Mathieu Chartierdaaf3262015-03-24 13:30:28 -0700298 mirror::Class* type = dex_cache->GetResolvedType(field_id.type_idx_);
299 if (kResolve && UNLIKELY(type == nullptr)) {
Vladimir Marko3481ba22015-04-13 12:22:36 +0100300 type = ResolveGetType(field_id.type_idx_);
Ian Rogers08f1f502014-12-02 15:04:37 -0800301 CHECK(type != nullptr || Thread::Current()->IsExceptionPending());
302 }
303 return type;
304}
305
Mathieu Chartier61c5ebc2014-06-05 17:42:53 -0700306inline size_t ArtField::FieldSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Fred Shih37f05ef2014-07-16 18:38:08 -0700307 return Primitive::ComponentSize(GetTypeAsPrimitiveType());
Mathieu Chartier61c5ebc2014-06-05 17:42:53 -0700308}
309
310inline mirror::DexCache* ArtField::GetDexCache() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
311 return GetDeclaringClass()->GetDexCache();
312}
313
314inline const DexFile* ArtField::GetDexFile() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
315 return GetDexCache()->GetDexFile();
316}
317
Mathieu Chartierc7853442015-03-27 14:35:38 -0700318inline mirror::String* ArtField::GetStringName(Thread* self, bool resolve) {
Mathieu Chartierdaaf3262015-03-24 13:30:28 -0700319 auto dex_field_index = GetDexFieldIndex();
320 CHECK_NE(dex_field_index, DexFile::kDexNoIndex);
321 auto* dex_cache = GetDexCache();
322 const auto* dex_file = dex_cache->GetDexFile();
323 const auto& field_id = dex_file->GetFieldId(dex_field_index);
324 auto* name = dex_cache->GetResolvedString(field_id.name_idx_);
325 if (resolve && name == nullptr) {
Vladimir Marko3481ba22015-04-13 12:22:36 +0100326 name = ResolveGetStringName(self, *dex_file, field_id.name_idx_, dex_cache);
Mathieu Chartierdaaf3262015-03-24 13:30:28 -0700327 }
328 return name;
Mathieu Chartier76433272014-09-26 14:32:37 -0700329}
330
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800331} // namespace art
332
Mathieu Chartierc7853442015-03-27 14:35:38 -0700333#endif // ART_RUNTIME_ART_FIELD_INL_H_