blob: f75b8aeef402f9accd193577b5a8f8d64951ee54 [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 Rogerscdc1aaf2014-10-09 13:21:38 -070020#include "globals.h"
Ian Rogersef7d42f2014-01-06 12:55:46 -080021#include "object_reference.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080022#include "offsets.h"
Mathieu Chartier4e305412014-02-19 10:54:44 -080023#include "verify_object.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080024
25namespace art {
26
Mathieu Chartierc7853442015-03-27 14:35:38 -070027class ArtField;
Mathieu Chartiere401d142015-04-22 13:56:20 -070028class ArtMethod;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080029class ImageWriter;
Ian Rogersd9c4fc92013-10-01 19:45:43 -070030class LockWord;
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070031class Monitor;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080032struct ObjectOffsets;
33class Thread;
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070034class VoidFunctor;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080035
36namespace mirror {
37
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080038class Array;
39class Class;
Mathieu Chartiere4275c02015-08-06 15:34:15 -070040class ClassLoader;
Vladimir Marko05792b92015-08-03 11:56:49 +010041class DexCache;
Mathieu Chartier8fa2dad2014-03-13 12:22:56 -070042class FinalizerReference;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080043template<class T> class ObjectArray;
44template<class T> class PrimitiveArray;
45typedef PrimitiveArray<uint8_t> BooleanArray;
46typedef PrimitiveArray<int8_t> ByteArray;
47typedef PrimitiveArray<uint16_t> CharArray;
48typedef PrimitiveArray<double> DoubleArray;
49typedef PrimitiveArray<float> FloatArray;
50typedef PrimitiveArray<int32_t> IntArray;
51typedef PrimitiveArray<int64_t> LongArray;
52typedef PrimitiveArray<int16_t> ShortArray;
Mathieu Chartier8fa2dad2014-03-13 12:22:56 -070053class Reference;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080054class String;
55class Throwable;
56
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080057// Fields within mirror objects aren't accessed directly so that the appropriate amount of
58// handshaking is done with GC (for example, read and write barriers). This macro is used to
59// compute an offset for the Set/Get methods defined in Object that can safely access fields.
60#define OFFSET_OF_OBJECT_MEMBER(type, field) \
61 MemberOffset(OFFSETOF_MEMBER(type, field))
62
Mathieu Chartier4e305412014-02-19 10:54:44 -080063// Checks that we don't do field assignments which violate the typing system.
64static constexpr bool kCheckFieldAssignments = false;
Ian Rogers04d7aa92013-03-16 14:29:17 -070065
Ian Rogerscdc1aaf2014-10-09 13:21:38 -070066// Size of Object.
Hiroshi Yamauchi60f63f52015-04-23 16:12:40 -070067static constexpr uint32_t kObjectHeaderSize = kUseBrooksReadBarrier ? 16 : 8;
Ian Rogerscdc1aaf2014-10-09 13:21:38 -070068
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080069// C++ mirror of java.lang.Object
Ian Rogers719d1a32014-03-06 12:13:39 -080070class MANAGED LOCKABLE Object {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080071 public:
Mingyao Yang98d1cc82014-05-15 17:02:16 -070072 // The number of vtable entries in java.lang.Object.
73 static constexpr size_t kVTableLength = 11;
74
75 // The size of the java.lang.Class representing a java.lang.Object.
Mathieu Chartiere401d142015-04-22 13:56:20 -070076 static uint32_t ClassSize(size_t pointer_size);
Mingyao Yang98d1cc82014-05-15 17:02:16 -070077
78 // Size of an instance of java.lang.Object.
79 static constexpr uint32_t InstanceSize() {
80 return sizeof(Object);
81 }
82
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080083 static MemberOffset ClassOffset() {
84 return OFFSET_OF_OBJECT_MEMBER(Object, klass_);
85 }
86
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -070087 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
88 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mathieu Chartier90443472015-07-16 20:32:27 -070089 ALWAYS_INLINE Class* GetClass() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080090
Mathieu Chartier4e305412014-02-19 10:54:44 -080091 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -070092 void SetClass(Class* new_klass) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080093
Mathieu Chartier90443472015-07-16 20:32:27 -070094 Object* GetReadBarrierPointer() SHARED_REQUIRES(Locks::mutator_lock_);
Andreas Gampe65b798e2015-04-06 09:35:22 -070095#ifndef USE_BAKER_OR_BROOKS_READ_BARRIER
96 NO_RETURN
97#endif
Mathieu Chartier90443472015-07-16 20:32:27 -070098 void SetReadBarrierPointer(Object* rb_ptr) SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchi60f63f52015-04-23 16:12:40 -070099#ifndef USE_BAKER_OR_BROOKS_READ_BARRIER
100 NO_RETURN
101#endif
Hiroshi Yamauchi9103c862014-04-22 13:51:07 -0700102 bool AtomicSetReadBarrierPointer(Object* expected_rb_ptr, Object* rb_ptr)
Mathieu Chartier90443472015-07-16 20:32:27 -0700103 SHARED_REQUIRES(Locks::mutator_lock_);
104 void AssertReadBarrierPointer() const SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchi9d04a202014-01-31 13:35:49 -0800105
Jeff Haoa3faaf42013-09-03 19:07:00 -0700106 // The verifier treats all interfaces as java.lang.Object and relies on runtime checks in
107 // invoke-interface to detect incompatible interface types.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800108 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700109 bool VerifierInstanceOf(Class* klass) SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800110 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700111 ALWAYS_INLINE bool InstanceOf(Class* klass) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800112
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700113 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
114 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mathieu Chartier90443472015-07-16 20:32:27 -0700115 size_t SizeOf() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800116
Mathieu Chartier4e2cb092015-07-22 16:17:51 -0700117 Object* Clone(Thread* self) SHARED_REQUIRES(Locks::mutator_lock_)
118 REQUIRES(!Roles::uninterruptible_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800119
Sebastien Hertz69206392015-04-07 15:54:25 +0200120 int32_t IdentityHashCode() const
Mathieu Chartier90443472015-07-16 20:32:27 -0700121 SHARED_REQUIRES(Locks::mutator_lock_)
122 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800123
124 static MemberOffset MonitorOffset() {
125 return OFFSET_OF_OBJECT_MEMBER(Object, monitor_);
126 }
127
Hans Boehmd8434432014-07-11 09:56:07 -0700128 // As_volatile can be false if the mutators are suspended. This is an optimization since it
Mathieu Chartier4d7f61d2014-04-17 14:43:39 -0700129 // avoids the barriers.
Andreas Gampe3b45ef22015-05-26 21:34:09 -0700130 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700131 LockWord GetLockWord(bool as_volatile) SHARED_REQUIRES(Locks::mutator_lock_);
Andreas Gampe3b45ef22015-05-26 21:34:09 -0700132 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700133 void SetLockWord(LockWord new_val, bool as_volatile) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers228602f2014-07-10 02:07:54 -0700134 bool CasLockWordWeakSequentiallyConsistent(LockWord old_val, LockWord new_val)
Mathieu Chartier90443472015-07-16 20:32:27 -0700135 SHARED_REQUIRES(Locks::mutator_lock_);
Hans Boehmd8434432014-07-11 09:56:07 -0700136 bool CasLockWordWeakRelaxed(LockWord old_val, LockWord new_val)
Mathieu Chartier90443472015-07-16 20:32:27 -0700137 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700138 uint32_t GetLockOwnerThreadId();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800139
Mathieu Chartier2d096c92015-10-12 16:18:20 -0700140 mirror::Object* MonitorEnter(Thread* self)
141 EXCLUSIVE_LOCK_FUNCTION()
142 REQUIRES(!Roles::uninterruptible_)
143 SHARED_REQUIRES(Locks::mutator_lock_);
144 bool MonitorExit(Thread* self)
145 REQUIRES(!Roles::uninterruptible_)
146 SHARED_REQUIRES(Locks::mutator_lock_)
Ian Rogers719d1a32014-03-06 12:13:39 -0800147 UNLOCK_FUNCTION();
Mathieu Chartier90443472015-07-16 20:32:27 -0700148 void Notify(Thread* self) SHARED_REQUIRES(Locks::mutator_lock_);
149 void NotifyAll(Thread* self) SHARED_REQUIRES(Locks::mutator_lock_);
150 void Wait(Thread* self) SHARED_REQUIRES(Locks::mutator_lock_);
151 void Wait(Thread* self, int64_t timeout, int32_t nanos) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800152
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700153 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
154 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mathieu Chartier90443472015-07-16 20:32:27 -0700155 bool IsClass() SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700156 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
157 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mathieu Chartier90443472015-07-16 20:32:27 -0700158 Class* AsClass() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800159
Mathieu Chartier4e305412014-02-19 10:54:44 -0800160 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700161 bool IsObjectArray() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800162 template<class T, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700163 ObjectArray<T>* AsObjectArray() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800164
Mathieu Chartiere4275c02015-08-06 15:34:15 -0700165 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
166 bool IsClassLoader() SHARED_REQUIRES(Locks::mutator_lock_);
167 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
168 ClassLoader* AsClassLoader() SHARED_REQUIRES(Locks::mutator_lock_);
169
Vladimir Marko05792b92015-08-03 11:56:49 +0100170 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
171 bool IsDexCache() SHARED_REQUIRES(Locks::mutator_lock_);
172 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
173 DexCache* AsDexCache() SHARED_REQUIRES(Locks::mutator_lock_);
174
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700175 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
176 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mathieu Chartier90443472015-07-16 20:32:27 -0700177 bool IsArrayInstance() SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700178 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
179 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mathieu Chartier90443472015-07-16 20:32:27 -0700180 Array* AsArray() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800181
Mathieu Chartier4e305412014-02-19 10:54:44 -0800182 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700183 BooleanArray* AsBooleanArray() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800184 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700185 ByteArray* AsByteArray() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800186 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700187 ByteArray* AsByteSizedArray() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800188
Mathieu Chartier4e305412014-02-19 10:54:44 -0800189 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700190 CharArray* AsCharArray() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800191 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700192 ShortArray* AsShortArray() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800193 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700194 ShortArray* AsShortSizedArray() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800195
Mathieu Chartier4e305412014-02-19 10:54:44 -0800196 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700197 bool IsIntArray() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700198 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700199 IntArray* AsIntArray() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700200
201 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700202 bool IsLongArray() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800203 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700204 LongArray* AsLongArray() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800205
Mathieu Chartier4e305412014-02-19 10:54:44 -0800206 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700207 bool IsFloatArray() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700208 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700209 FloatArray* AsFloatArray() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700210
211 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700212 bool IsDoubleArray() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800213 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700214 DoubleArray* AsDoubleArray() SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100215
Jeff Hao848f70a2014-01-15 13:49:50 -0800216 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
217 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mathieu Chartier90443472015-07-16 20:32:27 -0700218 bool IsString() SHARED_REQUIRES(Locks::mutator_lock_);
Jeff Hao848f70a2014-01-15 13:49:50 -0800219
220 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
221 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mathieu Chartier90443472015-07-16 20:32:27 -0700222 String* AsString() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800223
Mathieu Chartier4e305412014-02-19 10:54:44 -0800224 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700225 Throwable* AsThrowable() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800226
Mathieu Chartier4e305412014-02-19 10:54:44 -0800227 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700228 bool IsReferenceInstance() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800229 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700230 Reference* AsReference() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier8fa2dad2014-03-13 12:22:56 -0700231 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700232 bool IsWeakReferenceInstance() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800233 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700234 bool IsSoftReferenceInstance() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800235 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700236 bool IsFinalizerReferenceInstance() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800237 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700238 FinalizerReference* AsFinalizerReference() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier8fa2dad2014-03-13 12:22:56 -0700239 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700240 bool IsPhantomReferenceInstance() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800241
Ian Rogersef7d42f2014-01-06 12:55:46 -0800242 // Accessor for Java type fields.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700243 template<class T, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700244 ReadBarrierOption kReadBarrierOption = kWithReadBarrier, bool kIsVolatile = false>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700245 ALWAYS_INLINE T* GetFieldObject(MemberOffset field_offset)
Mathieu Chartier90443472015-07-16 20:32:27 -0700246 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700247
248 template<class T, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700249 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700250 ALWAYS_INLINE T* GetFieldObjectVolatile(MemberOffset field_offset)
Mathieu Chartier90443472015-07-16 20:32:27 -0700251 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700252
253 template<bool kTransactionActive, bool kCheckTransaction = true,
254 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700255 ALWAYS_INLINE void SetFieldObjectWithoutWriteBarrier(MemberOffset field_offset, Object* new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700256 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700257
258 template<bool kTransactionActive, bool kCheckTransaction = true,
259 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700260 ALWAYS_INLINE void SetFieldObject(MemberOffset field_offset, Object* new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700261 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700262
Mathieu Chartier4e305412014-02-19 10:54:44 -0800263 template<bool kTransactionActive, bool kCheckTransaction = true,
264 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700265 ALWAYS_INLINE void SetFieldObjectVolatile(MemberOffset field_offset, Object* new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700266 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700267
Mathieu Chartier4e305412014-02-19 10:54:44 -0800268 template<bool kTransactionActive, bool kCheckTransaction = true,
269 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogers228602f2014-07-10 02:07:54 -0700270 bool CasFieldWeakSequentiallyConsistentObject(MemberOffset field_offset, Object* old_value,
271 Object* new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700272 SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800273 template<bool kTransactionActive, bool kCheckTransaction = true,
274 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
275 bool CasFieldWeakSequentiallyConsistentObjectWithoutWriteBarrier(MemberOffset field_offset,
276 Object* old_value,
277 Object* new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700278 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800279
Hans Boehmd8434432014-07-11 09:56:07 -0700280 template<bool kTransactionActive, bool kCheckTransaction = true,
281 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
282 bool CasFieldStrongSequentiallyConsistentObject(MemberOffset field_offset, Object* old_value,
283 Object* new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700284 SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800285 template<bool kTransactionActive, bool kCheckTransaction = true,
286 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
287 bool CasFieldStrongSequentiallyConsistentObjectWithoutWriteBarrier(MemberOffset field_offset,
288 Object* old_value,
289 Object* new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700290 SHARED_REQUIRES(Locks::mutator_lock_);
Hans Boehmd8434432014-07-11 09:56:07 -0700291
Mathieu Chartier4e305412014-02-19 10:54:44 -0800292 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
293 HeapReference<Object>* GetFieldObjectReferenceAddr(MemberOffset field_offset);
Mathieu Chartier11409ae2013-09-23 11:49:36 -0700294
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700295 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
Fred Shih37f05ef2014-07-16 18:38:08 -0700296 ALWAYS_INLINE uint8_t GetFieldBoolean(MemberOffset field_offset)
Mathieu Chartier90443472015-07-16 20:32:27 -0700297 SHARED_REQUIRES(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700298
299 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
300 ALWAYS_INLINE int8_t GetFieldByte(MemberOffset field_offset)
Mathieu Chartier90443472015-07-16 20:32:27 -0700301 SHARED_REQUIRES(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700302
303 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
304 ALWAYS_INLINE uint8_t GetFieldBooleanVolatile(MemberOffset field_offset)
Mathieu Chartier90443472015-07-16 20:32:27 -0700305 SHARED_REQUIRES(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700306
307 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
308 ALWAYS_INLINE int8_t GetFieldByteVolatile(MemberOffset field_offset)
Mathieu Chartier90443472015-07-16 20:32:27 -0700309 SHARED_REQUIRES(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700310
311 template<bool kTransactionActive, bool kCheckTransaction = true,
312 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
313 ALWAYS_INLINE void SetFieldBoolean(MemberOffset field_offset, uint8_t new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700314 SHARED_REQUIRES(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700315
316 template<bool kTransactionActive, bool kCheckTransaction = true,
317 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
318 ALWAYS_INLINE void SetFieldByte(MemberOffset field_offset, int8_t new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700319 SHARED_REQUIRES(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700320
321 template<bool kTransactionActive, bool kCheckTransaction = true,
322 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
323 ALWAYS_INLINE void SetFieldBooleanVolatile(MemberOffset field_offset, uint8_t new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700324 SHARED_REQUIRES(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700325
326 template<bool kTransactionActive, bool kCheckTransaction = true,
327 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
328 ALWAYS_INLINE void SetFieldByteVolatile(MemberOffset field_offset, int8_t new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700329 SHARED_REQUIRES(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700330
331 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
332 ALWAYS_INLINE uint16_t GetFieldChar(MemberOffset field_offset)
Mathieu Chartier90443472015-07-16 20:32:27 -0700333 SHARED_REQUIRES(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700334
335 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
336 ALWAYS_INLINE int16_t GetFieldShort(MemberOffset field_offset)
Mathieu Chartier90443472015-07-16 20:32:27 -0700337 SHARED_REQUIRES(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700338
339 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
340 ALWAYS_INLINE uint16_t GetFieldCharVolatile(MemberOffset field_offset)
Mathieu Chartier90443472015-07-16 20:32:27 -0700341 SHARED_REQUIRES(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700342
343 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
344 ALWAYS_INLINE int16_t GetFieldShortVolatile(MemberOffset field_offset)
Mathieu Chartier90443472015-07-16 20:32:27 -0700345 SHARED_REQUIRES(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700346
347 template<bool kTransactionActive, bool kCheckTransaction = true,
348 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
349 ALWAYS_INLINE void SetFieldChar(MemberOffset field_offset, uint16_t new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700350 SHARED_REQUIRES(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700351
352 template<bool kTransactionActive, bool kCheckTransaction = true,
353 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
354 ALWAYS_INLINE void SetFieldShort(MemberOffset field_offset, int16_t new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700355 SHARED_REQUIRES(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700356
357 template<bool kTransactionActive, bool kCheckTransaction = true,
358 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
359 ALWAYS_INLINE void SetFieldCharVolatile(MemberOffset field_offset, uint16_t new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700360 SHARED_REQUIRES(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700361
362 template<bool kTransactionActive, bool kCheckTransaction = true,
363 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
364 ALWAYS_INLINE void SetFieldShortVolatile(MemberOffset field_offset, int16_t new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700365 SHARED_REQUIRES(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700366
367 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700368 ALWAYS_INLINE int32_t GetField32(MemberOffset field_offset)
Mathieu Chartier90443472015-07-16 20:32:27 -0700369 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700370
Mathieu Chartier4e305412014-02-19 10:54:44 -0800371 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700372 ALWAYS_INLINE int32_t GetField32Volatile(MemberOffset field_offset)
Mathieu Chartier90443472015-07-16 20:32:27 -0700373 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700374
375 template<bool kTransactionActive, bool kCheckTransaction = true,
376 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700377 ALWAYS_INLINE void SetField32(MemberOffset field_offset, int32_t new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700378 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700379
Mathieu Chartier4e305412014-02-19 10:54:44 -0800380 template<bool kTransactionActive, bool kCheckTransaction = true,
381 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700382 ALWAYS_INLINE void SetField32Volatile(MemberOffset field_offset, int32_t new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700383 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700384
385 template<bool kTransactionActive, bool kCheckTransaction = true,
386 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700387 ALWAYS_INLINE bool CasFieldWeakSequentiallyConsistent32(MemberOffset field_offset,
388 int32_t old_value, int32_t new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700389 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700390
Hans Boehmd8434432014-07-11 09:56:07 -0700391 template<bool kTransactionActive, bool kCheckTransaction = true,
392 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
393 bool CasFieldWeakRelaxed32(MemberOffset field_offset, int32_t old_value,
394 int32_t new_value) ALWAYS_INLINE
Mathieu Chartier90443472015-07-16 20:32:27 -0700395 SHARED_REQUIRES(Locks::mutator_lock_);
Hans Boehmd8434432014-07-11 09:56:07 -0700396
397 template<bool kTransactionActive, bool kCheckTransaction = true,
398 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
399 bool CasFieldStrongSequentiallyConsistent32(MemberOffset field_offset, int32_t old_value,
400 int32_t new_value) ALWAYS_INLINE
Mathieu Chartier90443472015-07-16 20:32:27 -0700401 SHARED_REQUIRES(Locks::mutator_lock_);
Hans Boehmd8434432014-07-11 09:56:07 -0700402
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700403 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700404 ALWAYS_INLINE int64_t GetField64(MemberOffset field_offset)
Mathieu Chartier90443472015-07-16 20:32:27 -0700405 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700406
407 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700408 ALWAYS_INLINE int64_t GetField64Volatile(MemberOffset field_offset)
Mathieu Chartier90443472015-07-16 20:32:27 -0700409 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700410
411 template<bool kTransactionActive, bool kCheckTransaction = true,
412 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700413 ALWAYS_INLINE void SetField64(MemberOffset field_offset, int64_t new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700414 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700415
416 template<bool kTransactionActive, bool kCheckTransaction = true,
417 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700418 ALWAYS_INLINE void SetField64Volatile(MemberOffset field_offset, int64_t new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700419 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800420
Mathieu Chartier4e305412014-02-19 10:54:44 -0800421 template<bool kTransactionActive, bool kCheckTransaction = true,
422 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogers228602f2014-07-10 02:07:54 -0700423 bool CasFieldWeakSequentiallyConsistent64(MemberOffset field_offset, int64_t old_value,
424 int64_t new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700425 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800426
Mathieu Chartier4e305412014-02-19 10:54:44 -0800427 template<bool kTransactionActive, bool kCheckTransaction = true,
Hans Boehmd8434432014-07-11 09:56:07 -0700428 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
429 bool CasFieldStrongSequentiallyConsistent64(MemberOffset field_offset, int64_t old_value,
430 int64_t new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700431 SHARED_REQUIRES(Locks::mutator_lock_);
Hans Boehmd8434432014-07-11 09:56:07 -0700432
433 template<bool kTransactionActive, bool kCheckTransaction = true,
Mathieu Chartier4e305412014-02-19 10:54:44 -0800434 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, typename T>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700435 void SetFieldPtr(MemberOffset field_offset, T new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700436 SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800437 SetFieldPtrWithSize<kTransactionActive, kCheckTransaction, kVerifyFlags>(
438 field_offset, new_value, sizeof(void*));
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800439 }
440
Mathieu Chartier2d721012014-11-10 11:08:06 -0800441 template<bool kTransactionActive, bool kCheckTransaction = true,
442 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, typename T>
443 ALWAYS_INLINE void SetFieldPtrWithSize(MemberOffset field_offset, T new_value,
444 size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700445 SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800446 DCHECK(pointer_size == 4 || pointer_size == 8) << pointer_size;
447 if (pointer_size == 4) {
448 intptr_t ptr = reinterpret_cast<intptr_t>(new_value);
449 DCHECK_EQ(static_cast<int32_t>(ptr), ptr); // Check that we dont lose any non 0 bits.
450 SetField32<kTransactionActive, kCheckTransaction, kVerifyFlags>(
451 field_offset, static_cast<int32_t>(ptr));
452 } else {
453 SetField64<kTransactionActive, kCheckTransaction, kVerifyFlags>(
Vladimir Marko6e1372f2015-06-01 11:02:59 +0100454 field_offset, static_cast<int64_t>(reinterpret_cast<uintptr_t>(new_value)));
Mathieu Chartier2d721012014-11-10 11:08:06 -0800455 }
456 }
Mathieu Chartier407f7022014-02-18 14:37:05 -0800457 // TODO fix thread safety analysis broken by the use of template. This should be
Mathieu Chartier90443472015-07-16 20:32:27 -0700458 // SHARED_REQUIRES(Locks::mutator_lock_).
Mathieu Chartier059ef3d2015-08-18 13:54:21 -0700459 template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
460 typename Visitor,
461 typename JavaLangRefVisitor = VoidFunctor>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700462 void VisitReferences(const Visitor& visitor, const JavaLangRefVisitor& ref_visitor)
Mathieu Chartier407f7022014-02-18 14:37:05 -0800463 NO_THREAD_SAFETY_ANALYSIS;
464
Mathieu Chartier90443472015-07-16 20:32:27 -0700465 ArtField* FindFieldByOffset(MemberOffset offset) SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchieb2baaf2015-05-13 21:14:22 -0700466
tony.ys_liu7380c312015-01-16 19:16:45 +0800467 // Used by object_test.
468 static void SetHashCodeSeed(uint32_t new_seed);
469 // Generate an identity hash code. Public for object test.
470 static uint32_t GenerateIdentityHashCode();
471
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800472 protected:
473 // Accessors for non-Java type fields
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700474 template<class T, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
475 T GetFieldPtr(MemberOffset field_offset)
Mathieu Chartier90443472015-07-16 20:32:27 -0700476 SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800477 return GetFieldPtrWithSize<T, kVerifyFlags, kIsVolatile>(field_offset, sizeof(void*));
478 }
479
480 template<class T, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
481 ALWAYS_INLINE T GetFieldPtrWithSize(MemberOffset field_offset, size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700482 SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800483 DCHECK(pointer_size == 4 || pointer_size == 8) << pointer_size;
484 if (pointer_size == 4) {
485 return reinterpret_cast<T>(GetField32<kVerifyFlags, kIsVolatile>(field_offset));
486 } else {
487 int64_t v = GetField64<kVerifyFlags, kIsVolatile>(field_offset);
488 // Check that we dont lose any non 0 bits.
Vladimir Marko6e1372f2015-06-01 11:02:59 +0100489 DCHECK_EQ(static_cast<int64_t>(static_cast<uintptr_t>(v)), v);
490 return reinterpret_cast<T>(static_cast<uintptr_t>(v));
Mathieu Chartier2d721012014-11-10 11:08:06 -0800491 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800492 }
493
Mathieu Chartier407f7022014-02-18 14:37:05 -0800494 // TODO: Fixme when anotatalysis works with visitors.
Mathieu Chartier059ef3d2015-08-18 13:54:21 -0700495 template<bool kIsStatic, typename Visitor>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700496 void VisitFieldsReferences(uint32_t ref_offsets, const Visitor& visitor) HOT_ATTR
Mathieu Chartier407f7022014-02-18 14:37:05 -0800497 NO_THREAD_SAFETY_ANALYSIS;
Mathieu Chartier059ef3d2015-08-18 13:54:21 -0700498 template<typename Visitor>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700499 void VisitInstanceFieldsReferences(mirror::Class* klass, const Visitor& visitor) HOT_ATTR
Mathieu Chartier90443472015-07-16 20:32:27 -0700500 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier059ef3d2015-08-18 13:54:21 -0700501 template<typename Visitor>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700502 void VisitStaticFieldsReferences(mirror::Class* klass, const Visitor& visitor) HOT_ATTR
Mathieu Chartier90443472015-07-16 20:32:27 -0700503 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier407f7022014-02-18 14:37:05 -0800504
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800505 private:
Fred Shih37f05ef2014-07-16 18:38:08 -0700506 template<typename kSize, bool kIsVolatile>
507 ALWAYS_INLINE void SetField(MemberOffset field_offset, kSize new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700508 SHARED_REQUIRES(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700509 template<typename kSize, bool kIsVolatile>
510 ALWAYS_INLINE kSize GetField(MemberOffset field_offset)
Mathieu Chartier90443472015-07-16 20:32:27 -0700511 SHARED_REQUIRES(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700512
Ian Rogers04d7aa92013-03-16 14:29:17 -0700513 // Verify the type correctness of stores to fields.
Mathieu Chartier61c5ebc2014-06-05 17:42:53 -0700514 // TODO: This can cause thread suspension and isn't moving GC safe.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800515 void CheckFieldAssignmentImpl(MemberOffset field_offset, Object* new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700516 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800517 void CheckFieldAssignment(MemberOffset field_offset, Object* new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700518 SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers04d7aa92013-03-16 14:29:17 -0700519 if (kCheckFieldAssignments) {
520 CheckFieldAssignmentImpl(field_offset, new_value);
521 }
522 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800523
Hiroshi Yamauchi0fbd6e62014-07-17 16:16:31 -0700524 // A utility function that copies an object in a read barrier and
525 // write barrier-aware way. This is internally used by Clone() and
526 // Class::CopyOf().
527 static Object* CopyObject(Thread* self, mirror::Object* dest, mirror::Object* src,
528 size_t num_bytes)
Mathieu Chartier90443472015-07-16 20:32:27 -0700529 SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchi0fbd6e62014-07-17 16:16:31 -0700530
tony.ys_liu7380c312015-01-16 19:16:45 +0800531 static Atomic<uint32_t> hash_code_seed;
532
Ian Rogersef7d42f2014-01-06 12:55:46 -0800533 // The Class representing the type of the object.
534 HeapReference<Class> klass_;
535 // Monitor and hash code information.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800536 uint32_t monitor_;
537
Hiroshi Yamauchi60f63f52015-04-23 16:12:40 -0700538#ifdef USE_BROOKS_READ_BARRIER
Hiroshi Yamauchi624468c2014-03-31 15:14:47 -0700539 // Note names use a 'x' prefix and the x_rb_ptr_ is of type int
Hiroshi Yamauchi9d04a202014-01-31 13:35:49 -0800540 // instead of Object to go with the alphabetical/by-type field order
541 // on the Java side.
Hiroshi Yamauchi60f63f52015-04-23 16:12:40 -0700542 uint32_t x_rb_ptr_; // For the Brooks pointer.
Hiroshi Yamauchi624468c2014-03-31 15:14:47 -0700543 uint32_t x_xpadding_; // For 8-byte alignment. TODO: get rid of this.
Hiroshi Yamauchi9d04a202014-01-31 13:35:49 -0800544#endif
545
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800546 friend class art::ImageWriter;
Mathieu Chartierad2541a2013-10-25 10:05:23 -0700547 friend class art::Monitor;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800548 friend struct art::ObjectOffsets; // for verifying offset information
Hiroshi Yamauchi0fbd6e62014-07-17 16:16:31 -0700549 friend class CopyObjectVisitor; // for CopyObject().
550 friend class CopyClassVisitor; // for CopyObject().
Ian Rogerscf7f1912014-10-22 22:06:39 -0700551 DISALLOW_ALLOCATION();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800552 DISALLOW_IMPLICIT_CONSTRUCTORS(Object);
553};
554
555} // namespace mirror
556} // namespace art
557
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700558#endif // ART_RUNTIME_MIRROR_OBJECT_H_