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_MIRROR_ART_FIELD_H_ 18 #define ART_RUNTIME_MIRROR_ART_FIELD_H_ 19 20 #include "class.h" 21 #include "modifiers.h" 22 #include "object.h" 23 24 namespace art { 25 26 struct ArtFieldOffsets; 27 28 namespace mirror { 29 30 // C++ mirror of java.lang.reflect.ArtField 31 class MANAGED ArtField : public Object { 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) { 40 SetField32(OFFSET_OF_OBJECT_MEMBER(ArtField, access_flags_), new_access_flags, false); 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 { 56 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtField, field_dex_idx_), false); 57 } 58 59 void SetDexFieldIndex(uint32_t new_idx) { 60 SetField32(OFFSET_OF_OBJECT_MEMBER(ArtField, field_dex_idx_), new_idx, false); 61 } 62 63 // Offset to field within an Object 64 MemberOffset GetOffset() const; 65 66 static MemberOffset OffsetOffset() { 67 return MemberOffset(OFFSETOF_MEMBER(ArtField, offset_)); 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 126 static Class* GetJavaLangReflectArtField() { 127 DCHECK(java_lang_reflect_ArtField_ != NULL); 128 return java_lang_reflect_ArtField_; 129 } 130 131 static void SetClass(Class* java_lang_reflect_ArtField); 132 static void ResetClass(); 133 134 bool IsVolatile() const { 135 return (GetAccessFlags() & kAccVolatile) != 0; 136 } 137 138 private: 139 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses". 140 // The class we are a part of 141 Class* declaring_class_; 142 143 uint32_t access_flags_; 144 145 // Dex cache index of field id 146 uint32_t field_dex_idx_; 147 148 // Offset of field within an instance or in the Class' static fields 149 uint32_t offset_; 150 151 static Class* java_lang_reflect_ArtField_; 152 153 friend struct art::ArtFieldOffsets; // for verifying offset information 154 DISALLOW_IMPLICIT_CONSTRUCTORS(ArtField); 155 }; 156 157 class MANAGED ArtFieldClass : public Class { 158 private: 159 DISALLOW_IMPLICIT_CONSTRUCTORS(ArtFieldClass); 160 }; 161 162 } // namespace mirror 163 } // namespace art 164 165 #endif // ART_RUNTIME_MIRROR_ART_FIELD_H_ 166