blob: 62bcf062e13ae61bbe78b5884bcd5c0680503c01 [file] [log] [blame]
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001/*
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 Carlstromea46f952013-07-30 01:26:50 -070017#ifndef ART_RUNTIME_MIRROR_ART_FIELD_H_
18#define ART_RUNTIME_MIRROR_ART_FIELD_H_
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080019
20#include "class.h"
21#include "modifiers.h"
22#include "object.h"
23
24namespace art {
25
Brian Carlstromea46f952013-07-30 01:26:50 -070026struct ArtFieldOffsets;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080027
28namespace mirror {
29
Brian Carlstromea46f952013-07-30 01:26:50 -070030// C++ mirror of java.lang.reflect.ArtField
31class MANAGED ArtField : public Object {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080032 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 Carlstromea46f952013-07-30 01:26:50 -070040 SetField32(OFFSET_OF_OBJECT_MEMBER(ArtField, access_flags_), new_access_flags, false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080041 }
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 Carlstromea46f952013-07-30 01:26:50 -070056 return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtField, field_dex_idx_), false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080057 }
58
59 void SetDexFieldIndex(uint32_t new_idx) {
Brian Carlstromea46f952013-07-30 01:26:50 -070060 SetField32(OFFSET_OF_OBJECT_MEMBER(ArtField, field_dex_idx_), new_idx, false);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080061 }
62
63 // Offset to field within an Object
64 MemberOffset GetOffset() const;
65
66 static MemberOffset OffsetOffset() {
Brian Carlstromea46f952013-07-30 01:26:50 -070067 return MemberOffset(OFFSETOF_MEMBER(ArtField, offset_));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080068 }
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 Carlstromea46f952013-07-30 01:26:50 -0700126 static Class* GetJavaLangReflectArtField() {
127 DCHECK(java_lang_reflect_ArtField_ != NULL);
128 return java_lang_reflect_ArtField_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800129 }
130
Brian Carlstromea46f952013-07-30 01:26:50 -0700131 static void SetClass(Class* java_lang_reflect_ArtField);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800132 static void ResetClass();
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800133 static void VisitRoots(RootVisitor* visitor, void* arg)
134 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800135
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 Carlstromea46f952013-07-30 01:26:50 -0700153 static Class* java_lang_reflect_ArtField_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800154
Brian Carlstromea46f952013-07-30 01:26:50 -0700155 friend struct art::ArtFieldOffsets; // for verifying offset information
156 DISALLOW_IMPLICIT_CONSTRUCTORS(ArtField);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800157};
158
Brian Carlstromea46f952013-07-30 01:26:50 -0700159class MANAGED ArtFieldClass : public Class {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800160 private:
Brian Carlstromea46f952013-07-30 01:26:50 -0700161 DISALLOW_IMPLICIT_CONSTRUCTORS(ArtFieldClass);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800162};
163
164} // namespace mirror
165} // namespace art
166
Brian Carlstromea46f952013-07-30 01:26:50 -0700167#endif // ART_RUNTIME_MIRROR_ART_FIELD_H_