Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [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 | |
| 17 | #ifndef ART_RUNTIME_ART_FIELD_H_ |
| 18 | #define ART_RUNTIME_ART_FIELD_H_ |
| 19 | |
| 20 | #include <jni.h> |
| 21 | |
| 22 | #include "gc_root.h" |
| 23 | #include "modifiers.h" |
| 24 | #include "object_callbacks.h" |
| 25 | #include "offsets.h" |
| 26 | #include "primitive.h" |
| 27 | #include "read_barrier_option.h" |
| 28 | |
| 29 | namespace art { |
| 30 | |
| 31 | class DexFile; |
| 32 | class ScopedObjectAccessAlreadyRunnable; |
| 33 | |
| 34 | namespace mirror { |
| 35 | class Class; |
| 36 | class DexCache; |
| 37 | class Object; |
| 38 | class String; |
| 39 | } // namespace mirror |
| 40 | |
| 41 | class ArtField { |
| 42 | public: |
| 43 | ArtField(); |
| 44 | |
| 45 | mirror::Class* GetDeclaringClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 46 | |
| 47 | void SetDeclaringClass(mirror::Class *new_declaring_class) |
| 48 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 49 | |
| 50 | uint32_t GetAccessFlags() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 51 | |
| 52 | void SetAccessFlags(uint32_t new_access_flags) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 53 | // Not called within a transaction. |
| 54 | access_flags_ = new_access_flags; |
| 55 | } |
| 56 | |
| 57 | bool IsPublic() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 58 | return (GetAccessFlags() & kAccPublic) != 0; |
| 59 | } |
| 60 | |
| 61 | bool IsStatic() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 62 | return (GetAccessFlags() & kAccStatic) != 0; |
| 63 | } |
| 64 | |
| 65 | bool IsFinal() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 66 | return (GetAccessFlags() & kAccFinal) != 0; |
| 67 | } |
| 68 | |
| 69 | uint32_t GetDexFieldIndex() { |
| 70 | return field_dex_idx_; |
| 71 | } |
| 72 | |
| 73 | void SetDexFieldIndex(uint32_t new_idx) { |
| 74 | // Not called within a transaction. |
| 75 | field_dex_idx_ = new_idx; |
| 76 | } |
| 77 | |
| 78 | // Offset to field within an Object. |
| 79 | MemberOffset GetOffset() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 80 | |
| 81 | static MemberOffset OffsetOffset() { |
| 82 | return MemberOffset(OFFSETOF_MEMBER(ArtField, offset_)); |
| 83 | } |
| 84 | |
| 85 | MemberOffset GetOffsetDuringLinking() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 86 | |
| 87 | void SetOffset(MemberOffset num_bytes) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 88 | |
| 89 | // field access, null object for static fields |
| 90 | uint8_t GetBoolean(mirror::Object* object) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 91 | |
| 92 | template<bool kTransactionActive> |
| 93 | void SetBoolean(mirror::Object* object, uint8_t z) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 94 | |
| 95 | int8_t GetByte(mirror::Object* object) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 96 | |
| 97 | template<bool kTransactionActive> |
| 98 | void SetByte(mirror::Object* object, int8_t b) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 99 | |
| 100 | uint16_t GetChar(mirror::Object* object) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 101 | |
| 102 | template<bool kTransactionActive> |
| 103 | void SetChar(mirror::Object* object, uint16_t c) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 104 | |
| 105 | int16_t GetShort(mirror::Object* object) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 106 | |
| 107 | template<bool kTransactionActive> |
| 108 | void SetShort(mirror::Object* object, int16_t s) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 109 | |
| 110 | int32_t GetInt(mirror::Object* object) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 111 | |
| 112 | template<bool kTransactionActive> |
| 113 | void SetInt(mirror::Object* object, int32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 114 | |
| 115 | int64_t GetLong(mirror::Object* object) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 116 | |
| 117 | template<bool kTransactionActive> |
| 118 | void SetLong(mirror::Object* object, int64_t j) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 119 | |
| 120 | float GetFloat(mirror::Object* object) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 121 | |
| 122 | template<bool kTransactionActive> |
| 123 | void SetFloat(mirror::Object* object, float f) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 124 | |
| 125 | double GetDouble(mirror::Object* object) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 126 | |
| 127 | template<bool kTransactionActive> |
| 128 | void SetDouble(mirror::Object* object, double d) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 129 | |
| 130 | mirror::Object* GetObject(mirror::Object* object) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 131 | |
| 132 | template<bool kTransactionActive> |
| 133 | void SetObject(mirror::Object* object, mirror::Object* l) |
| 134 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 135 | |
| 136 | // Raw field accesses. |
| 137 | uint32_t Get32(mirror::Object* object) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 138 | |
| 139 | template<bool kTransactionActive> |
| 140 | void Set32(mirror::Object* object, uint32_t new_value) |
| 141 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 142 | |
| 143 | uint64_t Get64(mirror::Object* object) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 144 | |
| 145 | template<bool kTransactionActive> |
| 146 | void Set64(mirror::Object* object, uint64_t new_value) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 147 | |
| 148 | mirror::Object* GetObj(mirror::Object* object) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 149 | |
| 150 | template<bool kTransactionActive> |
| 151 | void SetObj(mirror::Object* object, mirror::Object* new_value) |
| 152 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 153 | |
| 154 | void VisitRoots(RootVisitor* visitor) |
| 155 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 156 | |
| 157 | bool IsVolatile() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 158 | return (GetAccessFlags() & kAccVolatile) != 0; |
| 159 | } |
| 160 | |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 161 | // Returns an instance field with this offset in the given class or null if not found. |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 162 | static ArtField* FindInstanceFieldWithOffset(mirror::Class* klass, uint32_t field_offset) |
| 163 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 164 | |
| 165 | const char* GetName() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 166 | |
| 167 | // Resolves / returns the name from the dex cache. |
| 168 | mirror::String* GetStringName(Thread* self, bool resolve) |
| 169 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 170 | |
| 171 | const char* GetTypeDescriptor() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 172 | |
| 173 | Primitive::Type GetTypeAsPrimitiveType() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 174 | |
| 175 | bool IsPrimitiveType() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 176 | |
| 177 | template <bool kResolve> |
| 178 | mirror::Class* GetType() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 179 | |
| 180 | size_t FieldSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 181 | |
| 182 | mirror::DexCache* GetDexCache() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 183 | |
| 184 | const DexFile* GetDexFile() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 185 | |
| 186 | GcRoot<mirror::Class>& DeclaringClassRoot() { |
| 187 | return declaring_class_; |
| 188 | } |
| 189 | |
| 190 | private: |
Vladimir Marko | 3481ba2 | 2015-04-13 12:22:36 +0100 | [diff] [blame] | 191 | mirror::Class* ProxyFindSystemClass(const char* descriptor) |
| 192 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 193 | mirror::Class* ResolveGetType(uint32_t type_idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 194 | mirror::String* ResolveGetStringName(Thread* self, const DexFile& dex_file, uint32_t string_idx, |
| 195 | mirror::DexCache* dex_cache) |
| 196 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 197 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 198 | GcRoot<mirror::Class> declaring_class_; |
| 199 | |
| 200 | uint32_t access_flags_; |
| 201 | |
| 202 | // Dex cache index of field id |
| 203 | uint32_t field_dex_idx_; |
| 204 | |
| 205 | // Offset of field within an instance or in the Class' static fields |
| 206 | uint32_t offset_; |
| 207 | }; |
| 208 | |
| 209 | } // namespace art |
| 210 | |
| 211 | #endif // ART_RUNTIME_ART_FIELD_H_ |