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" |
Vladimir Marko | 3481ba2 | 2015-04-13 12:22:36 +0100 | [diff] [blame] | 24 | #include "gc_root-inl.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" |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 27 | #include "mirror/dex_cache.h" |
| 28 | #include "mirror/object-inl.h" |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 29 | #include "primitive.h" |
Mathieu Chartier | 7643327 | 2014-09-26 14:32:37 -0700 | [diff] [blame] | 30 | #include "thread-inl.h" |
| 31 | #include "scoped_thread_state_change.h" |
| 32 | #include "well_known_classes.h" |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 33 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 34 | namespace art { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 35 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 36 | inline mirror::Class* ArtField::GetDeclaringClass() { |
| 37 | mirror::Class* result = declaring_class_.Read(); |
| 38 | DCHECK(result != nullptr); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 39 | DCHECK(result->IsLoaded() || result->IsErroneous()); |
| 40 | return result; |
| 41 | } |
| 42 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 43 | inline void ArtField::SetDeclaringClass(mirror::Class* new_declaring_class) { |
| 44 | declaring_class_ = GcRoot<mirror::Class>(new_declaring_class); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 45 | } |
| 46 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 47 | inline uint32_t ArtField::GetAccessFlags() { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 48 | DCHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous()); |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 49 | return access_flags_; |
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 MemberOffset ArtField::GetOffset() { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 53 | DCHECK(GetDeclaringClass()->IsResolved() || GetDeclaringClass()->IsErroneous()); |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 54 | return MemberOffset(offset_); |
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::GetOffsetDuringLinking() { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 58 | DCHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous()); |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 59 | return MemberOffset(offset_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 60 | } |
| 61 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 62 | inline uint32_t ArtField::Get32(mirror::Object* object) { |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 63 | DCHECK(object != nullptr) << PrettyField(this); |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 64 | DCHECK(!IsStatic() || (object == GetDeclaringClass()) || !Runtime::Current()->IsStarted()); |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 65 | if (UNLIKELY(IsVolatile())) { |
| 66 | return object->GetField32Volatile(GetOffset()); |
| 67 | } |
| 68 | return object->GetField32(GetOffset()); |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 69 | } |
| 70 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 71 | template<bool kTransactionActive> |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 72 | inline void ArtField::Set32(mirror::Object* object, uint32_t new_value) { |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 73 | DCHECK(object != nullptr) << PrettyField(this); |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 74 | DCHECK(!IsStatic() || (object == GetDeclaringClass()) || !Runtime::Current()->IsStarted()); |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 75 | if (UNLIKELY(IsVolatile())) { |
| 76 | object->SetField32Volatile<kTransactionActive>(GetOffset(), new_value); |
| 77 | } else { |
| 78 | object->SetField32<kTransactionActive>(GetOffset(), new_value); |
| 79 | } |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 80 | } |
| 81 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 82 | inline uint64_t ArtField::Get64(mirror::Object* object) { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 83 | DCHECK(object != nullptr) << PrettyField(this); |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 84 | DCHECK(!IsStatic() || (object == GetDeclaringClass()) || !Runtime::Current()->IsStarted()); |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 85 | if (UNLIKELY(IsVolatile())) { |
| 86 | return object->GetField64Volatile(GetOffset()); |
| 87 | } |
| 88 | return object->GetField64(GetOffset()); |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 89 | } |
| 90 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 91 | template<bool kTransactionActive> |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 92 | inline void ArtField::Set64(mirror::Object* object, uint64_t new_value) { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 93 | DCHECK(object != nullptr) << PrettyField(this); |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 94 | DCHECK(!IsStatic() || (object == GetDeclaringClass()) || !Runtime::Current()->IsStarted()); |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 95 | if (UNLIKELY(IsVolatile())) { |
| 96 | object->SetField64Volatile<kTransactionActive>(GetOffset(), new_value); |
| 97 | } else { |
| 98 | object->SetField64<kTransactionActive>(GetOffset(), new_value); |
| 99 | } |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 100 | } |
| 101 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 102 | inline mirror::Object* ArtField::GetObj(mirror::Object* object) { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 103 | DCHECK(object != nullptr) << PrettyField(this); |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 104 | DCHECK(!IsStatic() || (object == GetDeclaringClass()) || !Runtime::Current()->IsStarted()); |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 105 | if (UNLIKELY(IsVolatile())) { |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 106 | return object->GetFieldObjectVolatile<mirror::Object>(GetOffset()); |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 107 | } |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 108 | return object->GetFieldObject<mirror::Object>(GetOffset()); |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 109 | } |
| 110 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 111 | template<bool kTransactionActive> |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 112 | inline void ArtField::SetObj(mirror::Object* object, mirror::Object* new_value) { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 113 | DCHECK(object != nullptr) << PrettyField(this); |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 114 | DCHECK(!IsStatic() || (object == GetDeclaringClass()) || !Runtime::Current()->IsStarted()); |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 115 | if (UNLIKELY(IsVolatile())) { |
| 116 | object->SetFieldObjectVolatile<kTransactionActive>(GetOffset(), new_value); |
| 117 | } else { |
| 118 | object->SetFieldObject<kTransactionActive>(GetOffset(), new_value); |
| 119 | } |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 120 | } |
| 121 | |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 122 | #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 Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 141 | inline uint8_t ArtField::GetBoolean(mirror::Object* object) { |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 142 | FIELD_GET(object, Boolean); |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 143 | } |
| 144 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 145 | template<bool kTransactionActive> |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 146 | inline void ArtField::SetBoolean(mirror::Object* object, uint8_t z) { |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 147 | FIELD_SET(object, Boolean, z); |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 148 | } |
| 149 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 150 | inline int8_t ArtField::GetByte(mirror::Object* object) { |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 151 | FIELD_GET(object, Byte); |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 152 | } |
| 153 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 154 | template<bool kTransactionActive> |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 155 | inline void ArtField::SetByte(mirror::Object* object, int8_t b) { |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 156 | FIELD_SET(object, Byte, b); |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 157 | } |
| 158 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 159 | inline uint16_t ArtField::GetChar(mirror::Object* object) { |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 160 | FIELD_GET(object, Char); |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 161 | } |
| 162 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 163 | template<bool kTransactionActive> |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 164 | inline void ArtField::SetChar(mirror::Object* object, uint16_t c) { |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 165 | FIELD_SET(object, Char, c); |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 166 | } |
| 167 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 168 | inline int16_t ArtField::GetShort(mirror::Object* object) { |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 169 | FIELD_GET(object, Short); |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 170 | } |
| 171 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 172 | template<bool kTransactionActive> |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 173 | inline void ArtField::SetShort(mirror::Object* object, int16_t s) { |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 174 | FIELD_SET(object, Short, s); |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 175 | } |
| 176 | |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 177 | #undef FIELD_GET |
| 178 | #undef FIELD_SET |
| 179 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 180 | inline int32_t ArtField::GetInt(mirror::Object* object) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 181 | if (kIsDebugBuild) { |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 182 | Primitive::Type type = GetTypeAsPrimitiveType(); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 183 | CHECK(type == Primitive::kPrimInt || type == Primitive::kPrimFloat) << PrettyField(this); |
| 184 | } |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 185 | return Get32(object); |
| 186 | } |
| 187 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 188 | template<bool kTransactionActive> |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 189 | inline void ArtField::SetInt(mirror::Object* object, int32_t i) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 190 | if (kIsDebugBuild) { |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 191 | Primitive::Type type = GetTypeAsPrimitiveType(); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 192 | CHECK(type == Primitive::kPrimInt || type == Primitive::kPrimFloat) << PrettyField(this); |
| 193 | } |
| 194 | Set32<kTransactionActive>(object, i); |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 195 | } |
| 196 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 197 | inline int64_t ArtField::GetLong(mirror::Object* object) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 198 | if (kIsDebugBuild) { |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 199 | Primitive::Type type = GetTypeAsPrimitiveType(); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 200 | CHECK(type == Primitive::kPrimLong || type == Primitive::kPrimDouble) << PrettyField(this); |
| 201 | } |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 202 | return Get64(object); |
| 203 | } |
| 204 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 205 | template<bool kTransactionActive> |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 206 | inline void ArtField::SetLong(mirror::Object* object, int64_t j) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 207 | if (kIsDebugBuild) { |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 208 | Primitive::Type type = GetTypeAsPrimitiveType(); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 209 | CHECK(type == Primitive::kPrimLong || type == Primitive::kPrimDouble) << PrettyField(this); |
| 210 | } |
| 211 | Set64<kTransactionActive>(object, j); |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 212 | } |
| 213 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 214 | inline float ArtField::GetFloat(mirror::Object* object) { |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 215 | DCHECK_EQ(Primitive::kPrimFloat, GetTypeAsPrimitiveType()) << PrettyField(this); |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 216 | JValue bits; |
| 217 | bits.SetI(Get32(object)); |
| 218 | return bits.GetF(); |
| 219 | } |
| 220 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 221 | template<bool kTransactionActive> |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 222 | inline void ArtField::SetFloat(mirror::Object* object, float f) { |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 223 | DCHECK_EQ(Primitive::kPrimFloat, GetTypeAsPrimitiveType()) << PrettyField(this); |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 224 | JValue bits; |
| 225 | bits.SetF(f); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 226 | Set32<kTransactionActive>(object, bits.GetI()); |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 227 | } |
| 228 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 229 | inline double ArtField::GetDouble(mirror::Object* object) { |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 230 | DCHECK_EQ(Primitive::kPrimDouble, GetTypeAsPrimitiveType()) << PrettyField(this); |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 231 | JValue bits; |
| 232 | bits.SetJ(Get64(object)); |
| 233 | return bits.GetD(); |
| 234 | } |
| 235 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 236 | template<bool kTransactionActive> |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 237 | inline void ArtField::SetDouble(mirror::Object* object, double d) { |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 238 | DCHECK_EQ(Primitive::kPrimDouble, GetTypeAsPrimitiveType()) << PrettyField(this); |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 239 | JValue bits; |
| 240 | bits.SetD(d); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 241 | Set64<kTransactionActive>(object, bits.GetJ()); |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 242 | } |
| 243 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 244 | inline mirror::Object* ArtField::GetObject(mirror::Object* object) { |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 245 | DCHECK_EQ(Primitive::kPrimNot, GetTypeAsPrimitiveType()) << PrettyField(this); |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 246 | return GetObj(object); |
| 247 | } |
| 248 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 249 | template<bool kTransactionActive> |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 250 | inline void ArtField::SetObject(mirror::Object* object, mirror::Object* l) { |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 251 | DCHECK_EQ(Primitive::kPrimNot, GetTypeAsPrimitiveType()) << PrettyField(this); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 252 | SetObj<kTransactionActive>(object, l); |
Ian Rogers | c0fa3ad | 2013-02-05 00:11:55 -0800 | [diff] [blame] | 253 | } |
| 254 | |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 255 | inline 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 | |
| 266 | inline 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 | |
| 279 | inline Primitive::Type ArtField::GetTypeAsPrimitiveType() |
| 280 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 281 | return Primitive::GetType(GetTypeDescriptor()[0]); |
| 282 | } |
| 283 | |
| 284 | inline bool ArtField::IsPrimitiveType() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 285 | return GetTypeAsPrimitiveType() != Primitive::kPrimNot; |
| 286 | } |
| 287 | |
Mathieu Chartier | daaf326 | 2015-03-24 13:30:28 -0700 | [diff] [blame] | 288 | template <bool kResolve> |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 289 | inline mirror::Class* ArtField::GetType() { |
Mathieu Chartier | daaf326 | 2015-03-24 13:30:28 -0700 | [diff] [blame] | 290 | const uint32_t field_index = GetDexFieldIndex(); |
| 291 | auto* declaring_class = GetDeclaringClass(); |
| 292 | if (UNLIKELY(declaring_class->IsProxyClass())) { |
Vladimir Marko | 3481ba2 | 2015-04-13 12:22:36 +0100 | [diff] [blame] | 293 | return ProxyFindSystemClass(GetTypeDescriptor()); |
Ian Rogers | 08f1f50 | 2014-12-02 15:04:37 -0800 | [diff] [blame] | 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)) { |
Vladimir Marko | 3481ba2 | 2015-04-13 12:22:36 +0100 | [diff] [blame] | 300 | type = ResolveGetType(field_id.type_idx_); |
Ian Rogers | 08f1f50 | 2014-12-02 15:04:37 -0800 | [diff] [blame] | 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) { |
Vladimir Marko | 3481ba2 | 2015-04-13 12:22:36 +0100 | [diff] [blame] | 326 | name = ResolveGetStringName(self, *dex_file, field_id.name_idx_, dex_cache); |
Mathieu Chartier | daaf326 | 2015-03-24 13:30:28 -0700 | [diff] [blame] | 327 | } |
| 328 | return name; |
Mathieu Chartier | 7643327 | 2014-09-26 14:32:37 -0700 | [diff] [blame] | 329 | } |
| 330 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 331 | } // namespace art |
| 332 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 333 | #endif // ART_RUNTIME_ART_FIELD_INL_H_ |