blob: 442909dfabc9ee5c92de55c8e0d50eac3c25c1bb [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 Yamauchi6e83c172014-05-01 21:25:41 -070070 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
71 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070072 Class* GetClass() ALWAYS_INLINE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080073
Mathieu Chartier4e305412014-02-19 10:54:44 -080074 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -080075 void SetClass(Class* new_klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080076
Hiroshi Yamauchi624468c2014-03-31 15:14:47 -070077 Object* GetReadBarrierPointer() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Hiroshi Yamauchi9103c862014-04-22 13:51:07 -070078 void SetReadBarrierPointer(Object* rb_ptr) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
79 bool AtomicSetReadBarrierPointer(Object* expected_rb_ptr, Object* rb_ptr)
80 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Hiroshi Yamauchi624468c2014-03-31 15:14:47 -070081 void AssertReadBarrierPointer() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Hiroshi Yamauchi9d04a202014-01-31 13:35:49 -080082
Jeff Haoa3faaf42013-09-03 19:07:00 -070083 // The verifier treats all interfaces as java.lang.Object and relies on runtime checks in
84 // invoke-interface to detect incompatible interface types.
Mathieu Chartier4e305412014-02-19 10:54:44 -080085 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -080086 bool VerifierInstanceOf(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -080087 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -080088 bool InstanceOf(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080089
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -070090 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
91 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -080092 size_t SizeOf() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080093
94 Object* Clone(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
95
Mathieu Chartierad2541a2013-10-25 10:05:23 -070096 int32_t IdentityHashCode() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080097
98 static MemberOffset MonitorOffset() {
99 return OFFSET_OF_OBJECT_MEMBER(Object, monitor_);
100 }
101
Mathieu Chartier4d7f61d2014-04-17 14:43:39 -0700102 // As volatile can be false if the mutators are suspended. This is an optimization since it
103 // avoids the barriers.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700104 LockWord GetLockWord(bool as_volatile) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
105 void SetLockWord(LockWord new_val, bool as_volatile) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800106 bool CasLockWord(LockWord old_val, LockWord new_val) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700107 uint32_t GetLockOwnerThreadId();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800108
Mathieu Chartiere7e8a5f2014-02-14 16:59:41 -0800109 mirror::Object* MonitorEnter(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
Ian Rogers719d1a32014-03-06 12:13:39 -0800110 EXCLUSIVE_LOCK_FUNCTION();
Ian Rogers05f30572013-02-20 12:13:11 -0800111 bool MonitorExit(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
Ian Rogers719d1a32014-03-06 12:13:39 -0800112 UNLOCK_FUNCTION();
Ian Rogers05f30572013-02-20 12:13:11 -0800113 void Notify(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers05f30572013-02-20 12:13:11 -0800114 void NotifyAll(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers05f30572013-02-20 12:13:11 -0800115 void Wait(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers05f30572013-02-20 12:13:11 -0800116 void Wait(Thread* self, int64_t timeout, int32_t nanos) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800117
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700118 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
119 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800120 bool IsClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700121 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
122 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800123 Class* AsClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800124
Mathieu Chartier4e305412014-02-19 10:54:44 -0800125 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800126 bool IsObjectArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800127 template<class T, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800128 ObjectArray<T>* AsObjectArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800129
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700130 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
131 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800132 bool IsArrayInstance() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700133 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
134 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800135 Array* AsArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800136
Mathieu Chartier4e305412014-02-19 10:54:44 -0800137 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800138 BooleanArray* AsBooleanArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800139 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800140 ByteArray* AsByteArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800141 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800142 ByteArray* AsByteSizedArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800143
Mathieu Chartier4e305412014-02-19 10:54:44 -0800144 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800145 CharArray* AsCharArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800146 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800147 ShortArray* AsShortArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800148 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800149 ShortArray* AsShortSizedArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800150
Mathieu Chartier4e305412014-02-19 10:54:44 -0800151 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800152 IntArray* AsIntArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800153 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800154 LongArray* AsLongArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800155
Mathieu Chartier4e305412014-02-19 10:54:44 -0800156 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100157 FloatArray* AsFloatArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800158 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100159 DoubleArray* AsDoubleArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
160
Mathieu Chartier4e305412014-02-19 10:54:44 -0800161 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800162 String* AsString() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800163
Mathieu Chartier4e305412014-02-19 10:54:44 -0800164 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800165 Throwable* AsThrowable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
166
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700167 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
168 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800169 bool IsArtMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800170 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800171 ArtMethod* AsArtMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800172
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700173 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
174 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800175 bool IsArtField() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800176 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Brian Carlstromea46f952013-07-30 01:26:50 -0700177 ArtField* AsArtField() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800178
Mathieu Chartier4e305412014-02-19 10:54:44 -0800179 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800180 bool IsReferenceInstance() 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 Reference* AsReference() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
183 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800184 bool IsWeakReferenceInstance() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800185 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800186 bool IsSoftReferenceInstance() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800187 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800188 bool IsFinalizerReferenceInstance() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800189 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier8fa2dad2014-03-13 12:22:56 -0700190 FinalizerReference* AsFinalizerReference() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
191 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800192 bool IsPhantomReferenceInstance() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800193
Ian Rogersef7d42f2014-01-06 12:55:46 -0800194 // Accessor for Java type fields.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700195 template<class T, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700196 ReadBarrierOption kReadBarrierOption = kWithReadBarrier, bool kIsVolatile = false>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700197 T* GetFieldObject(MemberOffset field_offset) ALWAYS_INLINE
Ian Rogersef7d42f2014-01-06 12:55:46 -0800198 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700199
200 template<class T, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700201 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700202 T* GetFieldObjectVolatile(MemberOffset field_offset) ALWAYS_INLINE
203 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
204
205 template<bool kTransactionActive, bool kCheckTransaction = true,
206 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
207 void SetFieldObjectWithoutWriteBarrier(MemberOffset field_offset, Object* new_value)
208 ALWAYS_INLINE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
209
210 template<bool kTransactionActive, bool kCheckTransaction = true,
211 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
212 void SetFieldObject(MemberOffset field_offset, Object* new_value) ALWAYS_INLINE
213 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
214
Mathieu Chartier4e305412014-02-19 10:54:44 -0800215 template<bool kTransactionActive, bool kCheckTransaction = true,
216 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700217 void SetFieldObjectVolatile(MemberOffset field_offset, Object* new_value) ALWAYS_INLINE
Ian Rogersef7d42f2014-01-06 12:55:46 -0800218 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700219
Mathieu Chartier4e305412014-02-19 10:54:44 -0800220 template<bool kTransactionActive, bool kCheckTransaction = true,
221 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800222 bool CasFieldObject(MemberOffset field_offset, Object* old_value, Object* new_value)
223 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800224
Mathieu Chartier4e305412014-02-19 10:54:44 -0800225 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
226 HeapReference<Object>* GetFieldObjectReferenceAddr(MemberOffset field_offset);
Mathieu Chartier11409ae2013-09-23 11:49:36 -0700227
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700228 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
229 int32_t GetField32(MemberOffset field_offset) ALWAYS_INLINE
Ian Rogersef7d42f2014-01-06 12:55:46 -0800230 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700231
Mathieu Chartier4e305412014-02-19 10:54:44 -0800232 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700233 int32_t GetField32Volatile(MemberOffset field_offset) ALWAYS_INLINE
234 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
235
236 template<bool kTransactionActive, bool kCheckTransaction = true,
237 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
238 void SetField32(MemberOffset field_offset, int32_t new_value) ALWAYS_INLINE
239 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
240
Mathieu Chartier4e305412014-02-19 10:54:44 -0800241 template<bool kTransactionActive, bool kCheckTransaction = true,
242 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700243 void SetField32Volatile(MemberOffset field_offset, int32_t new_value) ALWAYS_INLINE
244 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
245
246 template<bool kTransactionActive, bool kCheckTransaction = true,
247 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
248 bool CasField32(MemberOffset field_offset, int32_t old_value, int32_t new_value) ALWAYS_INLINE
249 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
250
251 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
252 int64_t GetField64(MemberOffset field_offset) ALWAYS_INLINE
253 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
254
255 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
256 int64_t GetField64Volatile(MemberOffset field_offset) ALWAYS_INLINE
257 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
258
259 template<bool kTransactionActive, bool kCheckTransaction = true,
260 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
261 void SetField64(MemberOffset field_offset, int64_t new_value) ALWAYS_INLINE
262 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
263
264 template<bool kTransactionActive, bool kCheckTransaction = true,
265 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
266 void SetField64Volatile(MemberOffset field_offset, int64_t new_value) ALWAYS_INLINE
267 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800268
Mathieu Chartier4e305412014-02-19 10:54:44 -0800269 template<bool kTransactionActive, bool kCheckTransaction = true,
270 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogers29501cf2014-02-07 21:00:25 -0800271 bool CasField64(MemberOffset field_offset, int64_t old_value, int64_t new_value)
Ian Rogersef7d42f2014-01-06 12:55:46 -0800272 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800273
Mathieu Chartier4e305412014-02-19 10:54:44 -0800274 template<bool kTransactionActive, bool kCheckTransaction = true,
275 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, typename T>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700276 void SetFieldPtr(MemberOffset field_offset, T new_value)
277 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800278#ifndef __LP64__
Mathieu Chartier4e305412014-02-19 10:54:44 -0800279 SetField32<kTransactionActive, kCheckTransaction, kVerifyFlags>(
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700280 field_offset, reinterpret_cast<int32_t>(new_value));
Ian Rogersef7d42f2014-01-06 12:55:46 -0800281#else
Mathieu Chartier4e305412014-02-19 10:54:44 -0800282 SetField64<kTransactionActive, kCheckTransaction, kVerifyFlags>(
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700283 field_offset, reinterpret_cast<int64_t>(new_value));
Ian Rogersef7d42f2014-01-06 12:55:46 -0800284#endif
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800285 }
286
Mathieu Chartier407f7022014-02-18 14:37:05 -0800287 // TODO fix thread safety analysis broken by the use of template. This should be
288 // SHARED_LOCKS_REQUIRED(Locks::mutator_lock_).
289 template <const bool kVisitClass, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
290 typename Visitor, typename JavaLangRefVisitor = VoidFunctor>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700291 void VisitReferences(const Visitor& visitor, const JavaLangRefVisitor& ref_visitor)
Mathieu Chartier407f7022014-02-18 14:37:05 -0800292 NO_THREAD_SAFETY_ANALYSIS;
293
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800294 protected:
295 // Accessors for non-Java type fields
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700296 template<class T, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
297 T GetFieldPtr(MemberOffset field_offset)
298 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800299#ifndef __LP64__
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700300 return reinterpret_cast<T>(GetField32<kVerifyFlags, kIsVolatile>(field_offset));
Ian Rogersef7d42f2014-01-06 12:55:46 -0800301#else
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700302 return reinterpret_cast<T>(GetField64<kVerifyFlags, kIsVolatile>(field_offset));
Ian Rogersef7d42f2014-01-06 12:55:46 -0800303#endif
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800304 }
305
Mathieu Chartier407f7022014-02-18 14:37:05 -0800306 // TODO: Fixme when anotatalysis works with visitors.
307 template<bool kVisitClass, bool kIsStatic, typename Visitor>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700308 void VisitFieldsReferences(uint32_t ref_offsets, const Visitor& visitor) HOT_ATTR
Mathieu Chartier407f7022014-02-18 14:37:05 -0800309 NO_THREAD_SAFETY_ANALYSIS;
310 template<bool kVisitClass, typename Visitor>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700311 void VisitInstanceFieldsReferences(mirror::Class* klass, const Visitor& visitor) HOT_ATTR
Mathieu Chartier407f7022014-02-18 14:37:05 -0800312 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
313 template<bool kVisitClass, typename Visitor>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700314 void VisitStaticFieldsReferences(mirror::Class* klass, const Visitor& visitor) HOT_ATTR
Mathieu Chartier407f7022014-02-18 14:37:05 -0800315 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
316
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800317 private:
Ian Rogers04d7aa92013-03-16 14:29:17 -0700318 // Verify the type correctness of stores to fields.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800319 void CheckFieldAssignmentImpl(MemberOffset field_offset, Object* new_value)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800320 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800321 void CheckFieldAssignment(MemberOffset field_offset, Object* new_value)
Ian Rogers04d7aa92013-03-16 14:29:17 -0700322 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
323 if (kCheckFieldAssignments) {
324 CheckFieldAssignmentImpl(field_offset, new_value);
325 }
326 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800327
Mathieu Chartierad2541a2013-10-25 10:05:23 -0700328 // Generate an identity hash code.
Mathieu Chartier4e6a31e2013-10-31 10:35:05 -0700329 static int32_t GenerateIdentityHashCode();
Mathieu Chartierad2541a2013-10-25 10:05:23 -0700330
Ian Rogersef7d42f2014-01-06 12:55:46 -0800331 // The Class representing the type of the object.
332 HeapReference<Class> klass_;
333 // Monitor and hash code information.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800334 uint32_t monitor_;
335
Hiroshi Yamauchi624468c2014-03-31 15:14:47 -0700336#ifdef USE_BAKER_OR_BROOKS_READ_BARRIER
337 // Note names use a 'x' prefix and the x_rb_ptr_ is of type int
Hiroshi Yamauchi9d04a202014-01-31 13:35:49 -0800338 // instead of Object to go with the alphabetical/by-type field order
339 // on the Java side.
Hiroshi Yamauchi624468c2014-03-31 15:14:47 -0700340 uint32_t x_rb_ptr_; // For the Baker or Brooks pointer.
341 uint32_t x_xpadding_; // For 8-byte alignment. TODO: get rid of this.
Hiroshi Yamauchi9d04a202014-01-31 13:35:49 -0800342#endif
343
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800344 friend class art::ImageWriter;
Mathieu Chartierad2541a2013-10-25 10:05:23 -0700345 friend class art::Monitor;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800346 friend struct art::ObjectOffsets; // for verifying offset information
347 DISALLOW_IMPLICIT_CONSTRUCTORS(Object);
348};
349
350} // namespace mirror
351} // namespace art
352
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700353#endif // ART_RUNTIME_MIRROR_OBJECT_H_