blob: cf28b18a0aeafd40812348b76097719c01f65d37 [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 Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_RUNTIME_MIRROR_OBJECT_H_
18#define ART_RUNTIME_MIRROR_OBJECT_H_
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080019
Ian Rogersef7d42f2014-01-06 12:55:46 -080020#include "object_reference.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080021#include "offsets.h"
Mathieu Chartier4e305412014-02-19 10:54:44 -080022#include "verify_object.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080023
24namespace art {
25
26class ImageWriter;
Ian Rogersd9c4fc92013-10-01 19:45:43 -070027class LockWord;
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070028class Monitor;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080029struct ObjectOffsets;
30class Thread;
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070031class VoidFunctor;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080032
33namespace mirror {
34
Brian Carlstromea46f952013-07-30 01:26:50 -070035class ArtField;
36class ArtMethod;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080037class Array;
38class Class;
Mathieu Chartier8fa2dad2014-03-13 12:22:56 -070039class FinalizerReference;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080040template<class T> class ObjectArray;
41template<class T> class PrimitiveArray;
42typedef PrimitiveArray<uint8_t> BooleanArray;
43typedef PrimitiveArray<int8_t> ByteArray;
44typedef PrimitiveArray<uint16_t> CharArray;
45typedef PrimitiveArray<double> DoubleArray;
46typedef PrimitiveArray<float> FloatArray;
47typedef PrimitiveArray<int32_t> IntArray;
48typedef PrimitiveArray<int64_t> LongArray;
49typedef PrimitiveArray<int16_t> ShortArray;
Mathieu Chartier8fa2dad2014-03-13 12:22:56 -070050class Reference;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080051class String;
52class Throwable;
53
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080054// Fields within mirror objects aren't accessed directly so that the appropriate amount of
55// handshaking is done with GC (for example, read and write barriers). This macro is used to
56// compute an offset for the Set/Get methods defined in Object that can safely access fields.
57#define OFFSET_OF_OBJECT_MEMBER(type, field) \
58 MemberOffset(OFFSETOF_MEMBER(type, field))
59
Mathieu Chartier4e305412014-02-19 10:54:44 -080060// Checks that we don't do field assignments which violate the typing system.
61static constexpr bool kCheckFieldAssignments = false;
Ian Rogers04d7aa92013-03-16 14:29:17 -070062
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080063// C++ mirror of java.lang.Object
Ian Rogers719d1a32014-03-06 12:13:39 -080064class MANAGED LOCKABLE Object {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080065 public:
66 static MemberOffset ClassOffset() {
67 return OFFSET_OF_OBJECT_MEMBER(Object, klass_);
68 }
69
Hiroshi Yamauchi9103c862014-04-22 13:51:07 -070070 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kDoReadBarrier = true>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070071 Class* GetClass() ALWAYS_INLINE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080072
Mathieu Chartier4e305412014-02-19 10:54:44 -080073 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -080074 void SetClass(Class* new_klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080075
Hiroshi Yamauchi624468c2014-03-31 15:14:47 -070076 Object* GetReadBarrierPointer() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Hiroshi Yamauchi9103c862014-04-22 13:51:07 -070077 void SetReadBarrierPointer(Object* rb_ptr) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
78 bool AtomicSetReadBarrierPointer(Object* expected_rb_ptr, Object* rb_ptr)
79 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Hiroshi Yamauchi624468c2014-03-31 15:14:47 -070080 void AssertReadBarrierPointer() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Hiroshi Yamauchi9d04a202014-01-31 13:35:49 -080081
Jeff Haoa3faaf42013-09-03 19:07:00 -070082 // The verifier treats all interfaces as java.lang.Object and relies on runtime checks in
83 // invoke-interface to detect incompatible interface types.
Mathieu Chartier4e305412014-02-19 10:54:44 -080084 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -080085 bool VerifierInstanceOf(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -080086 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -080087 bool InstanceOf(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080088
Hiroshi Yamauchi9103c862014-04-22 13:51:07 -070089 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kDoReadBarrier = true>
Ian Rogersef7d42f2014-01-06 12:55:46 -080090 size_t SizeOf() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080091
92 Object* Clone(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
93
Mathieu Chartierad2541a2013-10-25 10:05:23 -070094 int32_t IdentityHashCode() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080095
96 static MemberOffset MonitorOffset() {
97 return OFFSET_OF_OBJECT_MEMBER(Object, monitor_);
98 }
99
Mathieu Chartier4d7f61d2014-04-17 14:43:39 -0700100 // As volatile can be false if the mutators are suspended. This is an optimization since it
101 // avoids the barriers.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700102 LockWord GetLockWord(bool as_volatile) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
103 void SetLockWord(LockWord new_val, bool as_volatile) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800104 bool CasLockWord(LockWord old_val, LockWord new_val) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700105 uint32_t GetLockOwnerThreadId();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800106
Mathieu Chartiere7e8a5f2014-02-14 16:59:41 -0800107 mirror::Object* MonitorEnter(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
Ian Rogers719d1a32014-03-06 12:13:39 -0800108 EXCLUSIVE_LOCK_FUNCTION();
Ian Rogers05f30572013-02-20 12:13:11 -0800109 bool MonitorExit(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
Ian Rogers719d1a32014-03-06 12:13:39 -0800110 UNLOCK_FUNCTION();
Ian Rogers05f30572013-02-20 12:13:11 -0800111 void Notify(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers05f30572013-02-20 12:13:11 -0800112 void NotifyAll(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers05f30572013-02-20 12:13:11 -0800113 void Wait(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers05f30572013-02-20 12:13:11 -0800114 void Wait(Thread* self, int64_t timeout, int32_t nanos) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800115
Hiroshi Yamauchi9103c862014-04-22 13:51:07 -0700116 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kDoReadBarrier = true>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800117 bool IsClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Hiroshi Yamauchi9103c862014-04-22 13:51:07 -0700118 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kDoReadBarrier = true>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800119 Class* AsClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800120
Mathieu Chartier4e305412014-02-19 10:54:44 -0800121 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800122 bool IsObjectArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800123 template<class T, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800124 ObjectArray<T>* AsObjectArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800125
Hiroshi Yamauchi9103c862014-04-22 13:51:07 -0700126 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kDoReadBarrier = true>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800127 bool IsArrayInstance() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Hiroshi Yamauchi9103c862014-04-22 13:51:07 -0700128 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kDoReadBarrier = true>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800129 Array* AsArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800130
Mathieu Chartier4e305412014-02-19 10:54:44 -0800131 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800132 BooleanArray* AsBooleanArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800133 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800134 ByteArray* AsByteArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800135 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800136 ByteArray* AsByteSizedArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800137
Mathieu Chartier4e305412014-02-19 10:54:44 -0800138 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800139 CharArray* AsCharArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800140 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800141 ShortArray* AsShortArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800142 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800143 ShortArray* AsShortSizedArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800144
Mathieu Chartier4e305412014-02-19 10:54:44 -0800145 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800146 IntArray* AsIntArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800147 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800148 LongArray* AsLongArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800149
Mathieu Chartier4e305412014-02-19 10:54:44 -0800150 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100151 FloatArray* AsFloatArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800152 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100153 DoubleArray* AsDoubleArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
154
Mathieu Chartier4e305412014-02-19 10:54:44 -0800155 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800156 String* AsString() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800157
Mathieu Chartier4e305412014-02-19 10:54:44 -0800158 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800159 Throwable* AsThrowable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
160
Hiroshi Yamauchi9103c862014-04-22 13:51:07 -0700161 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kDoReadBarrier = true>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800162 bool IsArtMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800163 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800164 ArtMethod* AsArtMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800165
Hiroshi Yamauchi9103c862014-04-22 13:51:07 -0700166 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kDoReadBarrier = true>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800167 bool IsArtField() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800168 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Brian Carlstromea46f952013-07-30 01:26:50 -0700169 ArtField* AsArtField() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800170
Mathieu Chartier4e305412014-02-19 10:54:44 -0800171 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800172 bool IsReferenceInstance() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800173 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier8fa2dad2014-03-13 12:22:56 -0700174 Reference* AsReference() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
175 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800176 bool IsWeakReferenceInstance() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800177 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800178 bool IsSoftReferenceInstance() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800179 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800180 bool IsFinalizerReferenceInstance() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800181 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier8fa2dad2014-03-13 12:22:56 -0700182 FinalizerReference* AsFinalizerReference() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
183 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800184 bool IsPhantomReferenceInstance() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800185
Ian Rogersef7d42f2014-01-06 12:55:46 -0800186 // Accessor for Java type fields.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700187 template<class T, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
188 bool kDoReadBarrier = true, bool kIsVolatile = false>
189 T* GetFieldObject(MemberOffset field_offset) ALWAYS_INLINE
Ian Rogersef7d42f2014-01-06 12:55:46 -0800190 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700191
192 template<class T, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
193 bool kDoReadBarrier = true>
194 T* GetFieldObjectVolatile(MemberOffset field_offset) ALWAYS_INLINE
195 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
196
197 template<bool kTransactionActive, bool kCheckTransaction = true,
198 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
199 void SetFieldObjectWithoutWriteBarrier(MemberOffset field_offset, Object* new_value)
200 ALWAYS_INLINE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
201
202 template<bool kTransactionActive, bool kCheckTransaction = true,
203 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
204 void SetFieldObject(MemberOffset field_offset, Object* new_value) ALWAYS_INLINE
205 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
206
Mathieu Chartier4e305412014-02-19 10:54:44 -0800207 template<bool kTransactionActive, bool kCheckTransaction = true,
208 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700209 void SetFieldObjectVolatile(MemberOffset field_offset, Object* new_value) ALWAYS_INLINE
Ian Rogersef7d42f2014-01-06 12:55:46 -0800210 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700211
Mathieu Chartier4e305412014-02-19 10:54:44 -0800212 template<bool kTransactionActive, bool kCheckTransaction = true,
213 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800214 bool CasFieldObject(MemberOffset field_offset, Object* old_value, Object* new_value)
215 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800216
Mathieu Chartier4e305412014-02-19 10:54:44 -0800217 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
218 HeapReference<Object>* GetFieldObjectReferenceAddr(MemberOffset field_offset);
Mathieu Chartier11409ae2013-09-23 11:49:36 -0700219
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700220 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
221 int32_t GetField32(MemberOffset field_offset) ALWAYS_INLINE
Ian Rogersef7d42f2014-01-06 12:55:46 -0800222 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700223
Mathieu Chartier4e305412014-02-19 10:54:44 -0800224 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700225 int32_t GetField32Volatile(MemberOffset field_offset) ALWAYS_INLINE
226 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
227
228 template<bool kTransactionActive, bool kCheckTransaction = true,
229 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
230 void SetField32(MemberOffset field_offset, int32_t new_value) ALWAYS_INLINE
231 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
232
Mathieu Chartier4e305412014-02-19 10:54:44 -0800233 template<bool kTransactionActive, bool kCheckTransaction = true,
234 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700235 void SetField32Volatile(MemberOffset field_offset, int32_t new_value) ALWAYS_INLINE
236 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
237
238 template<bool kTransactionActive, bool kCheckTransaction = true,
239 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
240 bool CasField32(MemberOffset field_offset, int32_t old_value, int32_t new_value) ALWAYS_INLINE
241 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
242
243 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
244 int64_t GetField64(MemberOffset field_offset) ALWAYS_INLINE
245 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
246
247 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
248 int64_t GetField64Volatile(MemberOffset field_offset) ALWAYS_INLINE
249 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
250
251 template<bool kTransactionActive, bool kCheckTransaction = true,
252 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
253 void SetField64(MemberOffset field_offset, int64_t new_value) ALWAYS_INLINE
254 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
255
256 template<bool kTransactionActive, bool kCheckTransaction = true,
257 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
258 void SetField64Volatile(MemberOffset field_offset, int64_t new_value) ALWAYS_INLINE
259 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800260
Mathieu Chartier4e305412014-02-19 10:54:44 -0800261 template<bool kTransactionActive, bool kCheckTransaction = true,
262 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogers29501cf2014-02-07 21:00:25 -0800263 bool CasField64(MemberOffset field_offset, int64_t old_value, int64_t new_value)
Ian Rogersef7d42f2014-01-06 12:55:46 -0800264 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800265
Mathieu Chartier4e305412014-02-19 10:54:44 -0800266 template<bool kTransactionActive, bool kCheckTransaction = true,
267 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, typename T>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700268 void SetFieldPtr(MemberOffset field_offset, T new_value)
269 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800270#ifndef __LP64__
Mathieu Chartier4e305412014-02-19 10:54:44 -0800271 SetField32<kTransactionActive, kCheckTransaction, kVerifyFlags>(
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700272 field_offset, reinterpret_cast<int32_t>(new_value));
Ian Rogersef7d42f2014-01-06 12:55:46 -0800273#else
Mathieu Chartier4e305412014-02-19 10:54:44 -0800274 SetField64<kTransactionActive, kCheckTransaction, kVerifyFlags>(
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700275 field_offset, reinterpret_cast<int64_t>(new_value));
Ian Rogersef7d42f2014-01-06 12:55:46 -0800276#endif
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800277 }
278
Mathieu Chartier407f7022014-02-18 14:37:05 -0800279 // TODO fix thread safety analysis broken by the use of template. This should be
280 // SHARED_LOCKS_REQUIRED(Locks::mutator_lock_).
281 template <const bool kVisitClass, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
282 typename Visitor, typename JavaLangRefVisitor = VoidFunctor>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700283 void VisitReferences(const Visitor& visitor, const JavaLangRefVisitor& ref_visitor)
Mathieu Chartier407f7022014-02-18 14:37:05 -0800284 NO_THREAD_SAFETY_ANALYSIS;
285
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800286 protected:
287 // Accessors for non-Java type fields
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700288 template<class T, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
289 T GetFieldPtr(MemberOffset field_offset)
290 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800291#ifndef __LP64__
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700292 return reinterpret_cast<T>(GetField32<kVerifyFlags, kIsVolatile>(field_offset));
Ian Rogersef7d42f2014-01-06 12:55:46 -0800293#else
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700294 return reinterpret_cast<T>(GetField64<kVerifyFlags, kIsVolatile>(field_offset));
Ian Rogersef7d42f2014-01-06 12:55:46 -0800295#endif
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800296 }
297
Mathieu Chartier407f7022014-02-18 14:37:05 -0800298 // TODO: Fixme when anotatalysis works with visitors.
299 template<bool kVisitClass, bool kIsStatic, typename Visitor>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700300 void VisitFieldsReferences(uint32_t ref_offsets, const Visitor& visitor) HOT_ATTR
Mathieu Chartier407f7022014-02-18 14:37:05 -0800301 NO_THREAD_SAFETY_ANALYSIS;
302 template<bool kVisitClass, typename Visitor>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700303 void VisitInstanceFieldsReferences(mirror::Class* klass, const Visitor& visitor) HOT_ATTR
Mathieu Chartier407f7022014-02-18 14:37:05 -0800304 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
305 template<bool kVisitClass, typename Visitor>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700306 void VisitStaticFieldsReferences(mirror::Class* klass, const Visitor& visitor) HOT_ATTR
Mathieu Chartier407f7022014-02-18 14:37:05 -0800307 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
308
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800309 private:
Ian Rogers04d7aa92013-03-16 14:29:17 -0700310 // Verify the type correctness of stores to fields.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800311 void CheckFieldAssignmentImpl(MemberOffset field_offset, Object* new_value)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800312 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800313 void CheckFieldAssignment(MemberOffset field_offset, Object* new_value)
Ian Rogers04d7aa92013-03-16 14:29:17 -0700314 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
315 if (kCheckFieldAssignments) {
316 CheckFieldAssignmentImpl(field_offset, new_value);
317 }
318 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800319
Mathieu Chartierad2541a2013-10-25 10:05:23 -0700320 // Generate an identity hash code.
Mathieu Chartier4e6a31e2013-10-31 10:35:05 -0700321 static int32_t GenerateIdentityHashCode();
Mathieu Chartierad2541a2013-10-25 10:05:23 -0700322
Ian Rogersef7d42f2014-01-06 12:55:46 -0800323 // The Class representing the type of the object.
324 HeapReference<Class> klass_;
325 // Monitor and hash code information.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800326 uint32_t monitor_;
327
Hiroshi Yamauchi624468c2014-03-31 15:14:47 -0700328#ifdef USE_BAKER_OR_BROOKS_READ_BARRIER
329 // Note names use a 'x' prefix and the x_rb_ptr_ is of type int
Hiroshi Yamauchi9d04a202014-01-31 13:35:49 -0800330 // instead of Object to go with the alphabetical/by-type field order
331 // on the Java side.
Hiroshi Yamauchi624468c2014-03-31 15:14:47 -0700332 uint32_t x_rb_ptr_; // For the Baker or Brooks pointer.
333 uint32_t x_xpadding_; // For 8-byte alignment. TODO: get rid of this.
Hiroshi Yamauchi9d04a202014-01-31 13:35:49 -0800334#endif
335
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800336 friend class art::ImageWriter;
Mathieu Chartierad2541a2013-10-25 10:05:23 -0700337 friend class art::Monitor;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800338 friend struct art::ObjectOffsets; // for verifying offset information
339 DISALLOW_IMPLICIT_CONSTRUCTORS(Object);
340};
341
342} // namespace mirror
343} // namespace art
344
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700345#endif // ART_RUNTIME_MIRROR_OBJECT_H_