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