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_H_ |
| 18 | #define ART_RUNTIME_MIRROR_ART_FIELD_H_ |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 19 | |
| 20 | #include "class.h" |
| 21 | #include "modifiers.h" |
| 22 | #include "object.h" |
| 23 | |
| 24 | namespace art { |
| 25 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 26 | struct ArtFieldOffsets; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 27 | |
| 28 | namespace mirror { |
| 29 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 30 | // C++ mirror of java.lang.reflect.ArtField |
| 31 | class MANAGED ArtField : public Object { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 32 | public: |
| 33 | Class* GetDeclaringClass() const; |
| 34 | |
| 35 | void SetDeclaringClass(Class *new_declaring_class) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 36 | |
| 37 | uint32_t GetAccessFlags() const; |
| 38 | |
| 39 | void SetAccessFlags(uint32_t new_access_flags) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 40 | SetField32(OFFSET_OF_OBJECT_MEMBER(ArtField, access_flags_), new_access_flags, false); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | bool IsPublic() const { |
| 44 | return (GetAccessFlags() & kAccPublic) != 0; |
| 45 | } |
| 46 | |
| 47 | bool IsStatic() const { |
| 48 | return (GetAccessFlags() & kAccStatic) != 0; |
| 49 | } |
| 50 | |
| 51 | bool IsFinal() const { |
| 52 | return (GetAccessFlags() & kAccFinal) != 0; |
| 53 | } |
| 54 | |
| 55 | uint32_t GetDexFieldIndex() const { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 56 | return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtField, field_dex_idx_), false); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | void SetDexFieldIndex(uint32_t new_idx) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 60 | SetField32(OFFSET_OF_OBJECT_MEMBER(ArtField, field_dex_idx_), new_idx, false); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | // Offset to field within an Object |
| 64 | MemberOffset GetOffset() const; |
| 65 | |
| 66 | static MemberOffset OffsetOffset() { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 67 | return MemberOffset(OFFSETOF_MEMBER(ArtField, offset_)); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | MemberOffset GetOffsetDuringLinking() const; |
| 71 | |
| 72 | void SetOffset(MemberOffset num_bytes); |
| 73 | |
| 74 | // field access, null object for static fields |
| 75 | bool GetBoolean(const Object* object) const |
| 76 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 77 | void SetBoolean(Object* object, bool z) const |
| 78 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 79 | int8_t GetByte(const Object* object) const |
| 80 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 81 | void SetByte(Object* object, int8_t b) const |
| 82 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 83 | uint16_t GetChar(const Object* object) const |
| 84 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 85 | void SetChar(Object* object, uint16_t c) const |
| 86 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 87 | int16_t GetShort(const Object* object) const |
| 88 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 89 | void SetShort(Object* object, int16_t s) const |
| 90 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 91 | int32_t GetInt(const Object* object) const |
| 92 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 93 | void SetInt(Object* object, int32_t i) const |
| 94 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 95 | int64_t GetLong(const Object* object) const |
| 96 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 97 | void SetLong(Object* object, int64_t j) const |
| 98 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 99 | float GetFloat(const Object* object) const |
| 100 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 101 | void SetFloat(Object* object, float f) const |
| 102 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 103 | double GetDouble(const Object* object) const |
| 104 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 105 | void SetDouble(Object* object, double d) const |
| 106 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 107 | Object* GetObject(const Object* object) const |
| 108 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 109 | void SetObject(Object* object, const Object* l) const |
| 110 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 111 | |
| 112 | // raw field accesses |
| 113 | uint32_t Get32(const Object* object) const |
| 114 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 115 | void Set32(Object* object, uint32_t new_value) const |
| 116 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 117 | uint64_t Get64(const Object* object) const |
| 118 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 119 | void Set64(Object* object, uint64_t new_value) const |
| 120 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 121 | Object* GetObj(const Object* object) const |
| 122 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 123 | void SetObj(Object* object, const Object* new_value) const |
| 124 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 125 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 126 | static Class* GetJavaLangReflectArtField() { |
| 127 | DCHECK(java_lang_reflect_ArtField_ != NULL); |
| 128 | return java_lang_reflect_ArtField_; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 129 | } |
| 130 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 131 | static void SetClass(Class* java_lang_reflect_ArtField); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 132 | static void ResetClass(); |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 133 | static void VisitRoots(RootVisitor* visitor, void* arg) |
| 134 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 135 | |
| 136 | bool IsVolatile() const { |
| 137 | return (GetAccessFlags() & kAccVolatile) != 0; |
| 138 | } |
| 139 | |
| 140 | private: |
| 141 | // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses". |
| 142 | // The class we are a part of |
| 143 | Class* declaring_class_; |
| 144 | |
| 145 | uint32_t access_flags_; |
| 146 | |
| 147 | // Dex cache index of field id |
| 148 | uint32_t field_dex_idx_; |
| 149 | |
| 150 | // Offset of field within an instance or in the Class' static fields |
| 151 | uint32_t offset_; |
| 152 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 153 | static Class* java_lang_reflect_ArtField_; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 154 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 155 | friend struct art::ArtFieldOffsets; // for verifying offset information |
| 156 | DISALLOW_IMPLICIT_CONSTRUCTORS(ArtField); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 157 | }; |
| 158 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 159 | class MANAGED ArtFieldClass : public Class { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 160 | private: |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 161 | DISALLOW_IMPLICIT_CONSTRUCTORS(ArtFieldClass); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 162 | }; |
| 163 | |
| 164 | } // namespace mirror |
| 165 | } // namespace art |
| 166 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 167 | #endif // ART_RUNTIME_MIRROR_ART_FIELD_H_ |