Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 1 | /* |
| 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 Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 17 | #ifndef ART_RUNTIME_MIRROR_ART_FIELD_INL_H_ |
| 18 | #define ART_RUNTIME_MIRROR_ART_FIELD_INL_H_ |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 19 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 20 | #include "art_field.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 21 | |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 22 | #include "base/logging.h" |
Ian Rogers | 08f1f50 | 2014-12-02 15:04:37 -0800 | [diff] [blame] | 23 | #include "class_linker.h" |
Ian Rogers | 22d5e73 | 2014-07-15 22:23:51 -0700 | [diff] [blame] | 24 | #include "dex_cache.h" |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 25 | #include "gc/accounting/card_table-inl.h" |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 26 | #include "jvalue.h" |
| 27 | #include "object-inl.h" |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 28 | #include "primitive.h" |
Mathieu Chartier | 7643327 | 2014-09-26 14:32:37 -0700 | [diff] [blame] | 29 | #include "thread-inl.h" |
| 30 | #include "scoped_thread_state_change.h" |
| 31 | #include "well_known_classes.h" |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 32 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 33 | namespace art { |
| 34 | namespace mirror { |
| 35 | |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 36 | inline uint32_t ArtField::ClassSize() { |
| 37 | uint32_t vtable_entries = Object::kVTableLength + 6; |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 38 | return Class::ComputeClassSize(true, vtable_entries, 0, 0, 0, 0, 0); |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 39 | } |
| 40 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 41 | inline Class* ArtField::GetDeclaringClass() { |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 42 | Class* result = GetFieldObject<Class>(OFFSET_OF_OBJECT_MEMBER(ArtField, declaring_class_)); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 43 | DCHECK(result != NULL); |
| 44 | DCHECK(result->IsLoaded() || result->IsErroneous()); |
| 45 | return result; |
| 46 | } |
| 47 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 48 | inline void ArtField::SetDeclaringClass(Class *new_declaring_class) { |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 49 | SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(ArtField, declaring_class_), new_declaring_class); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 50 | } |
| 51 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 52 | inline uint32_t ArtField::GetAccessFlags() { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 53 | DCHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous()); |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 54 | return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtField, access_flags_)); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 55 | } |
| 56 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 57 | inline MemberOffset ArtField::GetOffset() { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 58 | DCHECK(GetDeclaringClass()->IsResolved() || GetDeclaringClass()->IsErroneous()); |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 59 | return MemberOffset(GetField32(OFFSET_OF_OBJECT_MEMBER(ArtField, offset_))); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 60 | } |
| 61 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 62 | inline MemberOffset ArtField::GetOffsetDuringLinking() { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 63 | DCHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous()); |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 64 | return MemberOffset(GetField32(OFFSET_OF_OBJECT_MEMBER(ArtField, offset_))); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 65 | } |
| 66 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 67 | inline uint32_t ArtField::Get32(Object* object) { |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 68 | DCHECK(object != nullptr) << PrettyField(this); |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 69 | DCHECK(!IsStatic() || (object == GetDeclaringClass()) || !Runtime::Current()->IsStarted()); |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 70 | if (UNLIKELY(IsVolatile())) { |
| 71 | return object->GetField32Volatile(GetOffset()); |
| 72 | } |
| 73 | return object->GetField32(GetOffset()); |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 74 | } |
| 75 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 76 | template<bool kTransactionActive> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 77 | inline void ArtField::Set32(Object* object, uint32_t new_value) { |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 78 | DCHECK(object != nullptr) << PrettyField(this); |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 79 | DCHECK(!IsStatic() || (object == GetDeclaringClass()) || !Runtime::Current()->IsStarted()); |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 80 | if (UNLIKELY(IsVolatile())) { |
| 81 | object->SetField32Volatile<kTransactionActive>(GetOffset(), new_value); |
| 82 | } else { |
| 83 | object->SetField32<kTransactionActive>(GetOffset(), new_value); |
| 84 | } |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 85 | } |
| 86 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 87 | inline uint64_t ArtField::Get64(Object* object) { |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 88 | DCHECK(object != NULL) << PrettyField(this); |
| 89 | DCHECK(!IsStatic() || (object == GetDeclaringClass()) || !Runtime::Current()->IsStarted()); |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 90 | if (UNLIKELY(IsVolatile())) { |
| 91 | return object->GetField64Volatile(GetOffset()); |
| 92 | } |
| 93 | return object->GetField64(GetOffset()); |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 94 | } |
| 95 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 96 | template<bool kTransactionActive> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 97 | inline void ArtField::Set64(Object* object, uint64_t new_value) { |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 98 | DCHECK(object != NULL) << PrettyField(this); |
| 99 | DCHECK(!IsStatic() || (object == GetDeclaringClass()) || !Runtime::Current()->IsStarted()); |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 100 | if (UNLIKELY(IsVolatile())) { |
| 101 | object->SetField64Volatile<kTransactionActive>(GetOffset(), new_value); |
| 102 | } else { |
| 103 | object->SetField64<kTransactionActive>(GetOffset(), new_value); |
| 104 | } |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 105 | } |
| 106 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 107 | inline Object* ArtField::GetObj(Object* object) { |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 108 | DCHECK(object != NULL) << PrettyField(this); |
| 109 | DCHECK(!IsStatic() || (object == GetDeclaringClass()) || !Runtime::Current()->IsStarted()); |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 110 | if (UNLIKELY(IsVolatile())) { |
| 111 | return object->GetFieldObjectVolatile<Object>(GetOffset()); |
| 112 | } |
| 113 | return object->GetFieldObject<Object>(GetOffset()); |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 114 | } |
| 115 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 116 | template<bool kTransactionActive> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 117 | inline void ArtField::SetObj(Object* object, Object* new_value) { |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 118 | DCHECK(object != NULL) << PrettyField(this); |
| 119 | DCHECK(!IsStatic() || (object == GetDeclaringClass()) || !Runtime::Current()->IsStarted()); |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 120 | if (UNLIKELY(IsVolatile())) { |
| 121 | object->SetFieldObjectVolatile<kTransactionActive>(GetOffset(), new_value); |
| 122 | } else { |
| 123 | object->SetFieldObject<kTransactionActive>(GetOffset(), new_value); |
| 124 | } |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 125 | } |
| 126 | |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 127 | #define FIELD_GET(object, type) \ |
| 128 | DCHECK_EQ(Primitive::kPrim ## type, GetTypeAsPrimitiveType()) << PrettyField(this); \ |
| 129 | DCHECK(object != nullptr) << PrettyField(this); \ |
| 130 | DCHECK(!IsStatic() || (object == GetDeclaringClass()) || !Runtime::Current()->IsStarted()); \ |
| 131 | if (UNLIKELY(IsVolatile())) { \ |
| 132 | return object->GetField ## type ## Volatile(GetOffset()); \ |
| 133 | } \ |
| 134 | return object->GetField ## type(GetOffset()); |
| 135 | |
| 136 | #define FIELD_SET(object, type, value) \ |
| 137 | DCHECK_EQ(Primitive::kPrim ## type, GetTypeAsPrimitiveType()) << PrettyField(this); \ |
| 138 | DCHECK(object != nullptr) << PrettyField(this); \ |
| 139 | DCHECK(!IsStatic() || (object == GetDeclaringClass()) || !Runtime::Current()->IsStarted()); \ |
| 140 | if (UNLIKELY(IsVolatile())) { \ |
| 141 | object->SetField ## type ## Volatile<kTransactionActive>(GetOffset(), value); \ |
| 142 | } else { \ |
| 143 | object->SetField ## type<kTransactionActive>(GetOffset(), value); \ |
| 144 | } |
| 145 | |
| 146 | inline uint8_t ArtField::GetBoolean(Object* object) { |
| 147 | FIELD_GET(object, Boolean); |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 148 | } |
| 149 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 150 | template<bool kTransactionActive> |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 151 | inline void ArtField::SetBoolean(Object* object, uint8_t z) { |
| 152 | FIELD_SET(object, Boolean, z); |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 153 | } |
| 154 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 155 | inline int8_t ArtField::GetByte(Object* object) { |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 156 | FIELD_GET(object, Byte); |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 157 | } |
| 158 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 159 | template<bool kTransactionActive> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 160 | inline void ArtField::SetByte(Object* object, int8_t b) { |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 161 | FIELD_SET(object, Byte, b); |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 162 | } |
| 163 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 164 | inline uint16_t ArtField::GetChar(Object* object) { |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 165 | FIELD_GET(object, Char); |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 166 | } |
| 167 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 168 | template<bool kTransactionActive> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 169 | inline void ArtField::SetChar(Object* object, uint16_t c) { |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 170 | FIELD_SET(object, Char, c); |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 171 | } |
| 172 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 173 | inline int16_t ArtField::GetShort(Object* object) { |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 174 | FIELD_GET(object, Short); |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 175 | } |
| 176 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 177 | template<bool kTransactionActive> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 178 | inline void ArtField::SetShort(Object* object, int16_t s) { |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 179 | FIELD_SET(object, Short, s); |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 180 | } |
| 181 | |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 182 | #undef FIELD_GET |
| 183 | #undef FIELD_SET |
| 184 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 185 | inline int32_t ArtField::GetInt(Object* object) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 186 | if (kIsDebugBuild) { |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 187 | Primitive::Type type = GetTypeAsPrimitiveType(); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 188 | CHECK(type == Primitive::kPrimInt || type == Primitive::kPrimFloat) << PrettyField(this); |
| 189 | } |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 190 | return Get32(object); |
| 191 | } |
| 192 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 193 | template<bool kTransactionActive> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 194 | inline void ArtField::SetInt(Object* object, int32_t i) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 195 | if (kIsDebugBuild) { |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 196 | Primitive::Type type = GetTypeAsPrimitiveType(); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 197 | CHECK(type == Primitive::kPrimInt || type == Primitive::kPrimFloat) << PrettyField(this); |
| 198 | } |
| 199 | Set32<kTransactionActive>(object, i); |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 200 | } |
| 201 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 202 | inline int64_t ArtField::GetLong(Object* object) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 203 | if (kIsDebugBuild) { |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 204 | Primitive::Type type = GetTypeAsPrimitiveType(); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 205 | CHECK(type == Primitive::kPrimLong || type == Primitive::kPrimDouble) << PrettyField(this); |
| 206 | } |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 207 | return Get64(object); |
| 208 | } |
| 209 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 210 | template<bool kTransactionActive> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 211 | inline void ArtField::SetLong(Object* object, int64_t j) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 212 | if (kIsDebugBuild) { |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 213 | Primitive::Type type = GetTypeAsPrimitiveType(); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 214 | CHECK(type == Primitive::kPrimLong || type == Primitive::kPrimDouble) << PrettyField(this); |
| 215 | } |
| 216 | Set64<kTransactionActive>(object, j); |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 217 | } |
| 218 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 219 | inline float ArtField::GetFloat(Object* object) { |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 220 | DCHECK_EQ(Primitive::kPrimFloat, GetTypeAsPrimitiveType()) << PrettyField(this); |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 221 | JValue bits; |
| 222 | bits.SetI(Get32(object)); |
| 223 | return bits.GetF(); |
| 224 | } |
| 225 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 226 | template<bool kTransactionActive> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 227 | inline void ArtField::SetFloat(Object* object, float f) { |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 228 | DCHECK_EQ(Primitive::kPrimFloat, GetTypeAsPrimitiveType()) << PrettyField(this); |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 229 | JValue bits; |
| 230 | bits.SetF(f); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 231 | Set32<kTransactionActive>(object, bits.GetI()); |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 232 | } |
| 233 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 234 | inline double ArtField::GetDouble(Object* object) { |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 235 | DCHECK_EQ(Primitive::kPrimDouble, GetTypeAsPrimitiveType()) << PrettyField(this); |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 236 | JValue bits; |
| 237 | bits.SetJ(Get64(object)); |
| 238 | return bits.GetD(); |
| 239 | } |
| 240 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 241 | template<bool kTransactionActive> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 242 | inline void ArtField::SetDouble(Object* object, double d) { |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 243 | DCHECK_EQ(Primitive::kPrimDouble, GetTypeAsPrimitiveType()) << PrettyField(this); |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 244 | JValue bits; |
| 245 | bits.SetD(d); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 246 | Set64<kTransactionActive>(object, bits.GetJ()); |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 247 | } |
| 248 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 249 | inline Object* ArtField::GetObject(Object* object) { |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 250 | DCHECK_EQ(Primitive::kPrimNot, GetTypeAsPrimitiveType()) << PrettyField(this); |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 251 | return GetObj(object); |
| 252 | } |
| 253 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 254 | template<bool kTransactionActive> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 255 | inline void ArtField::SetObject(Object* object, Object* l) { |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 256 | DCHECK_EQ(Primitive::kPrimNot, GetTypeAsPrimitiveType()) << PrettyField(this); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 257 | SetObj<kTransactionActive>(object, l); |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 258 | } |
| 259 | |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 260 | inline const char* ArtField::GetName() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 261 | uint32_t field_index = GetDexFieldIndex(); |
| 262 | if (UNLIKELY(GetDeclaringClass()->IsProxyClass())) { |
| 263 | DCHECK(IsStatic()); |
| 264 | DCHECK_LT(field_index, 2U); |
| 265 | return field_index == 0 ? "interfaces" : "throws"; |
| 266 | } |
| 267 | const DexFile* dex_file = GetDexFile(); |
| 268 | return dex_file->GetFieldName(dex_file->GetFieldId(field_index)); |
| 269 | } |
| 270 | |
| 271 | inline const char* ArtField::GetTypeDescriptor() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 272 | uint32_t field_index = GetDexFieldIndex(); |
| 273 | if (UNLIKELY(GetDeclaringClass()->IsProxyClass())) { |
| 274 | DCHECK(IsStatic()); |
| 275 | DCHECK_LT(field_index, 2U); |
| 276 | // 0 == Class[] interfaces; 1 == Class[][] throws; |
| 277 | return field_index == 0 ? "[Ljava/lang/Class;" : "[[Ljava/lang/Class;"; |
| 278 | } |
| 279 | const DexFile* dex_file = GetDexFile(); |
| 280 | const DexFile::FieldId& field_id = dex_file->GetFieldId(field_index); |
| 281 | return dex_file->GetFieldTypeDescriptor(field_id); |
| 282 | } |
| 283 | |
| 284 | inline Primitive::Type ArtField::GetTypeAsPrimitiveType() |
| 285 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 286 | return Primitive::GetType(GetTypeDescriptor()[0]); |
| 287 | } |
| 288 | |
| 289 | inline bool ArtField::IsPrimitiveType() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 290 | return GetTypeAsPrimitiveType() != Primitive::kPrimNot; |
| 291 | } |
| 292 | |
Ian Rogers | 08f1f50 | 2014-12-02 15:04:37 -0800 | [diff] [blame] | 293 | inline Class* ArtField::GetType(bool resolve) { |
| 294 | uint32_t field_index = GetDexFieldIndex(); |
| 295 | if (UNLIKELY(GetDeclaringClass()->IsProxyClass())) { |
| 296 | return Runtime::Current()->GetClassLinker()->FindSystemClass(Thread::Current(), |
| 297 | GetTypeDescriptor()); |
| 298 | } |
| 299 | const DexFile* dex_file = GetDexFile(); |
| 300 | const DexFile::FieldId& field_id = dex_file->GetFieldId(field_index); |
| 301 | mirror::Class* type = GetDexCache()->GetResolvedType(field_id.type_idx_); |
| 302 | if (resolve && (type == nullptr)) { |
| 303 | type = Runtime::Current()->GetClassLinker()->ResolveType(field_id.type_idx_, this); |
| 304 | CHECK(type != nullptr || Thread::Current()->IsExceptionPending()); |
| 305 | } |
| 306 | return type; |
| 307 | } |
| 308 | |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 309 | inline size_t ArtField::FieldSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 310 | return Primitive::ComponentSize(GetTypeAsPrimitiveType()); |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | inline mirror::DexCache* ArtField::GetDexCache() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 314 | return GetDeclaringClass()->GetDexCache(); |
| 315 | } |
| 316 | |
| 317 | inline const DexFile* ArtField::GetDexFile() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 318 | return GetDexCache()->GetDexFile(); |
| 319 | } |
| 320 | |
Mathieu Chartier | 7643327 | 2014-09-26 14:32:37 -0700 | [diff] [blame] | 321 | inline ArtField* ArtField::FromReflectedField(const ScopedObjectAccessAlreadyRunnable& soa, |
| 322 | jobject jlr_field) { |
| 323 | mirror::ArtField* f = soa.DecodeField(WellKnownClasses::java_lang_reflect_Field_artField); |
| 324 | mirror::ArtField* field = f->GetObject(soa.Decode<mirror::Object*>(jlr_field))->AsArtField(); |
| 325 | DCHECK(field != nullptr); |
| 326 | return field; |
| 327 | } |
| 328 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 329 | } // namespace mirror |
| 330 | } // namespace art |
| 331 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 332 | #endif // ART_RUNTIME_MIRROR_ART_FIELD_INL_H_ |