blob: d635002d12ca4b5a7808d21bb9fd945efcf12d33 [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_);
Hiroshi Yamauchied70b4a2015-11-17 17:52:15 -080095
Andreas Gampe65b798e2015-04-06 09:35:22 -070096#ifndef USE_BAKER_OR_BROOKS_READ_BARRIER
97 NO_RETURN
98#endif
Mathieu Chartier90443472015-07-16 20:32:27 -070099 void SetReadBarrierPointer(Object* rb_ptr) SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchied70b4a2015-11-17 17:52:15 -0800100
101 template<bool kCasRelease = false>
Hiroshi Yamauchi723e6ce2015-10-28 20:59:47 -0700102 ALWAYS_INLINE 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_);
Hiroshi Yamauchifed3e2f2015-10-20 11:11:56 -0700138 bool CasLockWordWeakRelease(LockWord old_val, LockWord new_val)
139 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700140 uint32_t GetLockOwnerThreadId();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800141
Mathieu Chartier2d096c92015-10-12 16:18:20 -0700142 mirror::Object* MonitorEnter(Thread* self)
143 EXCLUSIVE_LOCK_FUNCTION()
144 REQUIRES(!Roles::uninterruptible_)
145 SHARED_REQUIRES(Locks::mutator_lock_);
146 bool MonitorExit(Thread* self)
147 REQUIRES(!Roles::uninterruptible_)
148 SHARED_REQUIRES(Locks::mutator_lock_)
Ian Rogers719d1a32014-03-06 12:13:39 -0800149 UNLOCK_FUNCTION();
Mathieu Chartier90443472015-07-16 20:32:27 -0700150 void Notify(Thread* self) SHARED_REQUIRES(Locks::mutator_lock_);
151 void NotifyAll(Thread* self) SHARED_REQUIRES(Locks::mutator_lock_);
152 void Wait(Thread* self) SHARED_REQUIRES(Locks::mutator_lock_);
153 void Wait(Thread* self, int64_t timeout, int32_t nanos) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800154
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700155 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
156 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mathieu Chartier90443472015-07-16 20:32:27 -0700157 bool IsClass() SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700158 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
159 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mathieu Chartier90443472015-07-16 20:32:27 -0700160 Class* AsClass() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800161
Mathieu Chartier4e305412014-02-19 10:54:44 -0800162 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700163 bool IsObjectArray() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800164 template<class T, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700165 ObjectArray<T>* AsObjectArray() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800166
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800167 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
168 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mathieu Chartiere4275c02015-08-06 15:34:15 -0700169 bool IsClassLoader() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800170 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
171 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mathieu Chartiere4275c02015-08-06 15:34:15 -0700172 ClassLoader* AsClassLoader() SHARED_REQUIRES(Locks::mutator_lock_);
173
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800174 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
175 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Vladimir Marko05792b92015-08-03 11:56:49 +0100176 bool IsDexCache() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800177 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
178 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Vladimir Marko05792b92015-08-03 11:56:49 +0100179 DexCache* AsDexCache() SHARED_REQUIRES(Locks::mutator_lock_);
180
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700181 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
182 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mathieu Chartier90443472015-07-16 20:32:27 -0700183 bool IsArrayInstance() SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700184 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
185 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mathieu Chartier90443472015-07-16 20:32:27 -0700186 Array* AsArray() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800187
Mathieu Chartier4e305412014-02-19 10:54:44 -0800188 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700189 BooleanArray* AsBooleanArray() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800190 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700191 ByteArray* AsByteArray() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800192 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700193 ByteArray* AsByteSizedArray() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800194
Mathieu Chartier4e305412014-02-19 10:54:44 -0800195 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700196 CharArray* AsCharArray() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800197 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700198 ShortArray* AsShortArray() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800199 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700200 ShortArray* AsShortSizedArray() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800201
Mathieu Chartier4e305412014-02-19 10:54:44 -0800202 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700203 bool IsIntArray() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700204 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700205 IntArray* AsIntArray() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700206
207 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700208 bool IsLongArray() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800209 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700210 LongArray* AsLongArray() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800211
Mathieu Chartier4e305412014-02-19 10:54:44 -0800212 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700213 bool IsFloatArray() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700214 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700215 FloatArray* AsFloatArray() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700216
217 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700218 bool IsDoubleArray() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800219 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700220 DoubleArray* AsDoubleArray() SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100221
Jeff Hao848f70a2014-01-15 13:49:50 -0800222 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
223 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mathieu Chartier90443472015-07-16 20:32:27 -0700224 bool IsString() SHARED_REQUIRES(Locks::mutator_lock_);
Jeff Hao848f70a2014-01-15 13:49:50 -0800225
226 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
227 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mathieu Chartier90443472015-07-16 20:32:27 -0700228 String* AsString() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800229
Mathieu Chartier4e305412014-02-19 10:54:44 -0800230 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700231 Throwable* AsThrowable() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800232
Mathieu Chartier4e305412014-02-19 10:54:44 -0800233 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700234 bool IsReferenceInstance() 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 Reference* AsReference() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier8fa2dad2014-03-13 12:22:56 -0700237 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700238 bool IsWeakReferenceInstance() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800239 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700240 bool IsSoftReferenceInstance() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800241 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700242 bool IsFinalizerReferenceInstance() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800243 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700244 FinalizerReference* AsFinalizerReference() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier8fa2dad2014-03-13 12:22:56 -0700245 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700246 bool IsPhantomReferenceInstance() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800247
Ian Rogersef7d42f2014-01-06 12:55:46 -0800248 // Accessor for Java type fields.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700249 template<class T, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700250 ReadBarrierOption kReadBarrierOption = kWithReadBarrier, bool kIsVolatile = false>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700251 ALWAYS_INLINE T* GetFieldObject(MemberOffset field_offset)
Mathieu Chartier90443472015-07-16 20:32:27 -0700252 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700253
254 template<class T, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700255 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700256 ALWAYS_INLINE T* GetFieldObjectVolatile(MemberOffset field_offset)
Mathieu Chartier90443472015-07-16 20:32:27 -0700257 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700258
259 template<bool kTransactionActive, bool kCheckTransaction = true,
260 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700261 ALWAYS_INLINE void SetFieldObjectWithoutWriteBarrier(MemberOffset field_offset, Object* new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700262 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700263
264 template<bool kTransactionActive, bool kCheckTransaction = true,
265 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700266 ALWAYS_INLINE void SetFieldObject(MemberOffset field_offset, Object* new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700267 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700268
Mathieu Chartier4e305412014-02-19 10:54:44 -0800269 template<bool kTransactionActive, bool kCheckTransaction = true,
270 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700271 ALWAYS_INLINE void SetFieldObjectVolatile(MemberOffset field_offset, Object* new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700272 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700273
Mathieu Chartier4e305412014-02-19 10:54:44 -0800274 template<bool kTransactionActive, bool kCheckTransaction = true,
275 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogers228602f2014-07-10 02:07:54 -0700276 bool CasFieldWeakSequentiallyConsistentObject(MemberOffset field_offset, Object* old_value,
277 Object* new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700278 SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800279 template<bool kTransactionActive, bool kCheckTransaction = true,
280 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
281 bool CasFieldWeakSequentiallyConsistentObjectWithoutWriteBarrier(MemberOffset field_offset,
282 Object* old_value,
283 Object* new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700284 SHARED_REQUIRES(Locks::mutator_lock_);
Hans Boehmd8434432014-07-11 09:56:07 -0700285 template<bool kTransactionActive, bool kCheckTransaction = true,
286 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
287 bool CasFieldStrongSequentiallyConsistentObject(MemberOffset field_offset, Object* old_value,
288 Object* new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700289 SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800290 template<bool kTransactionActive, bool kCheckTransaction = true,
291 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
292 bool CasFieldStrongSequentiallyConsistentObjectWithoutWriteBarrier(MemberOffset field_offset,
293 Object* old_value,
294 Object* new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700295 SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchifed3e2f2015-10-20 11:11:56 -0700296 template<bool kTransactionActive, bool kCheckTransaction = true,
297 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
298 bool CasFieldWeakRelaxedObjectWithoutWriteBarrier(MemberOffset field_offset,
299 Object* old_value,
300 Object* new_value)
301 SHARED_REQUIRES(Locks::mutator_lock_);
302 template<bool kTransactionActive, bool kCheckTransaction = true,
303 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
304 bool CasFieldStrongRelaxedObjectWithoutWriteBarrier(MemberOffset field_offset,
305 Object* old_value,
306 Object* new_value)
307 SHARED_REQUIRES(Locks::mutator_lock_);
Hans Boehmd8434432014-07-11 09:56:07 -0700308
Mathieu Chartier4e305412014-02-19 10:54:44 -0800309 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
310 HeapReference<Object>* GetFieldObjectReferenceAddr(MemberOffset field_offset);
Mathieu Chartier11409ae2013-09-23 11:49:36 -0700311
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700312 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
Fred Shih37f05ef2014-07-16 18:38:08 -0700313 ALWAYS_INLINE uint8_t GetFieldBoolean(MemberOffset field_offset)
Mathieu Chartier90443472015-07-16 20:32:27 -0700314 SHARED_REQUIRES(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700315
316 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
317 ALWAYS_INLINE int8_t GetFieldByte(MemberOffset field_offset)
Mathieu Chartier90443472015-07-16 20:32:27 -0700318 SHARED_REQUIRES(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700319
320 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
321 ALWAYS_INLINE uint8_t GetFieldBooleanVolatile(MemberOffset field_offset)
Mathieu Chartier90443472015-07-16 20:32:27 -0700322 SHARED_REQUIRES(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700323
324 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
325 ALWAYS_INLINE int8_t GetFieldByteVolatile(MemberOffset field_offset)
Mathieu Chartier90443472015-07-16 20:32:27 -0700326 SHARED_REQUIRES(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700327
328 template<bool kTransactionActive, bool kCheckTransaction = true,
329 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
330 ALWAYS_INLINE void SetFieldBoolean(MemberOffset field_offset, uint8_t new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700331 SHARED_REQUIRES(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700332
333 template<bool kTransactionActive, bool kCheckTransaction = true,
334 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
335 ALWAYS_INLINE void SetFieldByte(MemberOffset field_offset, int8_t new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700336 SHARED_REQUIRES(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700337
338 template<bool kTransactionActive, bool kCheckTransaction = true,
339 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
340 ALWAYS_INLINE void SetFieldBooleanVolatile(MemberOffset field_offset, uint8_t new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700341 SHARED_REQUIRES(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700342
343 template<bool kTransactionActive, bool kCheckTransaction = true,
344 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
345 ALWAYS_INLINE void SetFieldByteVolatile(MemberOffset field_offset, int8_t new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700346 SHARED_REQUIRES(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700347
348 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
349 ALWAYS_INLINE uint16_t GetFieldChar(MemberOffset field_offset)
Mathieu Chartier90443472015-07-16 20:32:27 -0700350 SHARED_REQUIRES(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700351
352 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
353 ALWAYS_INLINE int16_t GetFieldShort(MemberOffset field_offset)
Mathieu Chartier90443472015-07-16 20:32:27 -0700354 SHARED_REQUIRES(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700355
356 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
357 ALWAYS_INLINE uint16_t GetFieldCharVolatile(MemberOffset field_offset)
Mathieu Chartier90443472015-07-16 20:32:27 -0700358 SHARED_REQUIRES(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700359
360 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
361 ALWAYS_INLINE int16_t GetFieldShortVolatile(MemberOffset field_offset)
Mathieu Chartier90443472015-07-16 20:32:27 -0700362 SHARED_REQUIRES(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700363
364 template<bool kTransactionActive, bool kCheckTransaction = true,
365 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
366 ALWAYS_INLINE void SetFieldChar(MemberOffset field_offset, uint16_t new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700367 SHARED_REQUIRES(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700368
369 template<bool kTransactionActive, bool kCheckTransaction = true,
370 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
371 ALWAYS_INLINE void SetFieldShort(MemberOffset field_offset, int16_t new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700372 SHARED_REQUIRES(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700373
374 template<bool kTransactionActive, bool kCheckTransaction = true,
375 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
376 ALWAYS_INLINE void SetFieldCharVolatile(MemberOffset field_offset, uint16_t new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700377 SHARED_REQUIRES(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700378
379 template<bool kTransactionActive, bool kCheckTransaction = true,
380 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
381 ALWAYS_INLINE void SetFieldShortVolatile(MemberOffset field_offset, int16_t new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700382 SHARED_REQUIRES(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700383
384 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700385 ALWAYS_INLINE int32_t GetField32(MemberOffset field_offset)
Mathieu Chartier90443472015-07-16 20:32:27 -0700386 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700387
Mathieu Chartier4e305412014-02-19 10:54:44 -0800388 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700389 ALWAYS_INLINE int32_t GetField32Volatile(MemberOffset field_offset)
Mathieu Chartier90443472015-07-16 20:32:27 -0700390 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700391
392 template<bool kTransactionActive, bool kCheckTransaction = true,
393 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700394 ALWAYS_INLINE void SetField32(MemberOffset field_offset, int32_t new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700395 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700396
Mathieu Chartier4e305412014-02-19 10:54:44 -0800397 template<bool kTransactionActive, bool kCheckTransaction = true,
398 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700399 ALWAYS_INLINE void SetField32Volatile(MemberOffset field_offset, int32_t new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700400 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700401
402 template<bool kTransactionActive, bool kCheckTransaction = true,
403 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700404 ALWAYS_INLINE bool CasFieldWeakSequentiallyConsistent32(MemberOffset field_offset,
405 int32_t old_value, int32_t new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700406 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700407
Hans Boehmd8434432014-07-11 09:56:07 -0700408 template<bool kTransactionActive, bool kCheckTransaction = true,
409 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
410 bool CasFieldWeakRelaxed32(MemberOffset field_offset, int32_t old_value,
411 int32_t new_value) ALWAYS_INLINE
Mathieu Chartier90443472015-07-16 20:32:27 -0700412 SHARED_REQUIRES(Locks::mutator_lock_);
Hans Boehmd8434432014-07-11 09:56:07 -0700413
414 template<bool kTransactionActive, bool kCheckTransaction = true,
415 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Hiroshi Yamauchifed3e2f2015-10-20 11:11:56 -0700416 bool CasFieldWeakRelease32(MemberOffset field_offset, int32_t old_value,
417 int32_t new_value) ALWAYS_INLINE
418 SHARED_REQUIRES(Locks::mutator_lock_);
419
420 template<bool kTransactionActive, bool kCheckTransaction = true,
421 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Hans Boehmd8434432014-07-11 09:56:07 -0700422 bool CasFieldStrongSequentiallyConsistent32(MemberOffset field_offset, int32_t old_value,
423 int32_t new_value) ALWAYS_INLINE
Mathieu Chartier90443472015-07-16 20:32:27 -0700424 SHARED_REQUIRES(Locks::mutator_lock_);
Hans Boehmd8434432014-07-11 09:56:07 -0700425
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700426 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700427 ALWAYS_INLINE int64_t GetField64(MemberOffset field_offset)
Mathieu Chartier90443472015-07-16 20:32:27 -0700428 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700429
430 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700431 ALWAYS_INLINE int64_t GetField64Volatile(MemberOffset field_offset)
Mathieu Chartier90443472015-07-16 20:32:27 -0700432 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700433
434 template<bool kTransactionActive, bool kCheckTransaction = true,
435 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700436 ALWAYS_INLINE void SetField64(MemberOffset field_offset, int64_t new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700437 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700438
439 template<bool kTransactionActive, bool kCheckTransaction = true,
440 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700441 ALWAYS_INLINE void SetField64Volatile(MemberOffset field_offset, int64_t new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700442 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800443
Mathieu Chartier4e305412014-02-19 10:54:44 -0800444 template<bool kTransactionActive, bool kCheckTransaction = true,
445 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogers228602f2014-07-10 02:07:54 -0700446 bool CasFieldWeakSequentiallyConsistent64(MemberOffset field_offset, int64_t old_value,
447 int64_t new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700448 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800449
Mathieu Chartier4e305412014-02-19 10:54:44 -0800450 template<bool kTransactionActive, bool kCheckTransaction = true,
Hans Boehmd8434432014-07-11 09:56:07 -0700451 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
452 bool CasFieldStrongSequentiallyConsistent64(MemberOffset field_offset, int64_t old_value,
453 int64_t new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700454 SHARED_REQUIRES(Locks::mutator_lock_);
Hans Boehmd8434432014-07-11 09:56:07 -0700455
456 template<bool kTransactionActive, bool kCheckTransaction = true,
Mathieu Chartier4e305412014-02-19 10:54:44 -0800457 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, typename T>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700458 void SetFieldPtr(MemberOffset field_offset, T new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700459 SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800460 SetFieldPtrWithSize<kTransactionActive, kCheckTransaction, kVerifyFlags>(
461 field_offset, new_value, sizeof(void*));
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800462 }
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800463 template<bool kTransactionActive, bool kCheckTransaction = true,
464 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, typename T>
465 void SetFieldPtr64(MemberOffset field_offset, T new_value)
466 SHARED_REQUIRES(Locks::mutator_lock_) {
467 SetFieldPtrWithSize<kTransactionActive, kCheckTransaction, kVerifyFlags>(
468 field_offset, new_value, 8u);
469 }
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800470
Mathieu Chartier2d721012014-11-10 11:08:06 -0800471 template<bool kTransactionActive, bool kCheckTransaction = true,
472 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, typename T>
473 ALWAYS_INLINE void SetFieldPtrWithSize(MemberOffset field_offset, T new_value,
474 size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700475 SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800476 DCHECK(pointer_size == 4 || pointer_size == 8) << pointer_size;
477 if (pointer_size == 4) {
478 intptr_t ptr = reinterpret_cast<intptr_t>(new_value);
479 DCHECK_EQ(static_cast<int32_t>(ptr), ptr); // Check that we dont lose any non 0 bits.
480 SetField32<kTransactionActive, kCheckTransaction, kVerifyFlags>(
481 field_offset, static_cast<int32_t>(ptr));
482 } else {
483 SetField64<kTransactionActive, kCheckTransaction, kVerifyFlags>(
Vladimir Marko6e1372f2015-06-01 11:02:59 +0100484 field_offset, static_cast<int64_t>(reinterpret_cast<uintptr_t>(new_value)));
Mathieu Chartier2d721012014-11-10 11:08:06 -0800485 }
486 }
Mathieu Chartier407f7022014-02-18 14:37:05 -0800487 // TODO fix thread safety analysis broken by the use of template. This should be
Mathieu Chartier90443472015-07-16 20:32:27 -0700488 // SHARED_REQUIRES(Locks::mutator_lock_).
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800489 template <bool kVisitNativeRoots = true,
490 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
491 ReadBarrierOption kReadBarrierOption = kWithReadBarrier,
Mathieu Chartier059ef3d2015-08-18 13:54:21 -0700492 typename Visitor,
493 typename JavaLangRefVisitor = VoidFunctor>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700494 void VisitReferences(const Visitor& visitor, const JavaLangRefVisitor& ref_visitor)
Mathieu Chartier407f7022014-02-18 14:37:05 -0800495 NO_THREAD_SAFETY_ANALYSIS;
496
Mathieu Chartier90443472015-07-16 20:32:27 -0700497 ArtField* FindFieldByOffset(MemberOffset offset) SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchieb2baaf2015-05-13 21:14:22 -0700498
tony.ys_liu7380c312015-01-16 19:16:45 +0800499 // Used by object_test.
500 static void SetHashCodeSeed(uint32_t new_seed);
501 // Generate an identity hash code. Public for object test.
502 static uint32_t GenerateIdentityHashCode();
503
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800504 protected:
505 // Accessors for non-Java type fields
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700506 template<class T, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
507 T GetFieldPtr(MemberOffset field_offset)
Mathieu Chartier90443472015-07-16 20:32:27 -0700508 SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800509 return GetFieldPtrWithSize<T, kVerifyFlags, kIsVolatile>(field_offset, sizeof(void*));
510 }
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800511 template<class T, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
512 T GetFieldPtr64(MemberOffset field_offset)
513 SHARED_REQUIRES(Locks::mutator_lock_) {
514 return GetFieldPtrWithSize<T, kVerifyFlags, kIsVolatile>(field_offset, 8u);
515 }
Mathieu Chartier2d721012014-11-10 11:08:06 -0800516
517 template<class T, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
518 ALWAYS_INLINE T GetFieldPtrWithSize(MemberOffset field_offset, size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700519 SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800520 DCHECK(pointer_size == 4 || pointer_size == 8) << pointer_size;
521 if (pointer_size == 4) {
522 return reinterpret_cast<T>(GetField32<kVerifyFlags, kIsVolatile>(field_offset));
523 } else {
524 int64_t v = GetField64<kVerifyFlags, kIsVolatile>(field_offset);
525 // Check that we dont lose any non 0 bits.
Vladimir Marko6e1372f2015-06-01 11:02:59 +0100526 DCHECK_EQ(static_cast<int64_t>(static_cast<uintptr_t>(v)), v);
527 return reinterpret_cast<T>(static_cast<uintptr_t>(v));
Mathieu Chartier2d721012014-11-10 11:08:06 -0800528 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800529 }
530
Mathieu Chartier407f7022014-02-18 14:37:05 -0800531 // TODO: Fixme when anotatalysis works with visitors.
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800532 template<bool kIsStatic,
533 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
534 ReadBarrierOption kReadBarrierOption = kWithReadBarrier,
535 typename Visitor>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700536 void VisitFieldsReferences(uint32_t ref_offsets, const Visitor& visitor) HOT_ATTR
Mathieu Chartier407f7022014-02-18 14:37:05 -0800537 NO_THREAD_SAFETY_ANALYSIS;
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800538 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
539 ReadBarrierOption kReadBarrierOption = kWithReadBarrier,
540 typename Visitor>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700541 void VisitInstanceFieldsReferences(mirror::Class* klass, const Visitor& visitor) HOT_ATTR
Mathieu Chartier90443472015-07-16 20:32:27 -0700542 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800543 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
544 ReadBarrierOption kReadBarrierOption = kWithReadBarrier,
545 typename Visitor>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700546 void VisitStaticFieldsReferences(mirror::Class* klass, const Visitor& visitor) HOT_ATTR
Mathieu Chartier90443472015-07-16 20:32:27 -0700547 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier407f7022014-02-18 14:37:05 -0800548
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800549 private:
Fred Shih37f05ef2014-07-16 18:38:08 -0700550 template<typename kSize, bool kIsVolatile>
551 ALWAYS_INLINE void SetField(MemberOffset field_offset, kSize new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700552 SHARED_REQUIRES(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700553 template<typename kSize, bool kIsVolatile>
554 ALWAYS_INLINE kSize GetField(MemberOffset field_offset)
Mathieu Chartier90443472015-07-16 20:32:27 -0700555 SHARED_REQUIRES(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700556
Ian Rogers04d7aa92013-03-16 14:29:17 -0700557 // Verify the type correctness of stores to fields.
Mathieu Chartier61c5ebc2014-06-05 17:42:53 -0700558 // TODO: This can cause thread suspension and isn't moving GC safe.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800559 void CheckFieldAssignmentImpl(MemberOffset field_offset, Object* new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700560 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800561 void CheckFieldAssignment(MemberOffset field_offset, Object* new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700562 SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers04d7aa92013-03-16 14:29:17 -0700563 if (kCheckFieldAssignments) {
564 CheckFieldAssignmentImpl(field_offset, new_value);
565 }
566 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800567
Hiroshi Yamauchi0fbd6e62014-07-17 16:16:31 -0700568 // A utility function that copies an object in a read barrier and
569 // write barrier-aware way. This is internally used by Clone() and
570 // Class::CopyOf().
571 static Object* CopyObject(Thread* self, mirror::Object* dest, mirror::Object* src,
572 size_t num_bytes)
Mathieu Chartier90443472015-07-16 20:32:27 -0700573 SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchi0fbd6e62014-07-17 16:16:31 -0700574
tony.ys_liu7380c312015-01-16 19:16:45 +0800575 static Atomic<uint32_t> hash_code_seed;
576
Ian Rogersef7d42f2014-01-06 12:55:46 -0800577 // The Class representing the type of the object.
578 HeapReference<Class> klass_;
579 // Monitor and hash code information.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800580 uint32_t monitor_;
581
Hiroshi Yamauchi60f63f52015-04-23 16:12:40 -0700582#ifdef USE_BROOKS_READ_BARRIER
Hiroshi Yamauchi624468c2014-03-31 15:14:47 -0700583 // Note names use a 'x' prefix and the x_rb_ptr_ is of type int
Hiroshi Yamauchi9d04a202014-01-31 13:35:49 -0800584 // instead of Object to go with the alphabetical/by-type field order
585 // on the Java side.
Hiroshi Yamauchi60f63f52015-04-23 16:12:40 -0700586 uint32_t x_rb_ptr_; // For the Brooks pointer.
Hiroshi Yamauchi624468c2014-03-31 15:14:47 -0700587 uint32_t x_xpadding_; // For 8-byte alignment. TODO: get rid of this.
Hiroshi Yamauchi9d04a202014-01-31 13:35:49 -0800588#endif
589
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800590 friend class art::ImageWriter;
Mathieu Chartierad2541a2013-10-25 10:05:23 -0700591 friend class art::Monitor;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800592 friend struct art::ObjectOffsets; // for verifying offset information
Hiroshi Yamauchi0fbd6e62014-07-17 16:16:31 -0700593 friend class CopyObjectVisitor; // for CopyObject().
594 friend class CopyClassVisitor; // for CopyObject().
Ian Rogerscf7f1912014-10-22 22:06:39 -0700595 DISALLOW_ALLOCATION();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800596 DISALLOW_IMPLICIT_CONSTRUCTORS(Object);
597};
598
599} // namespace mirror
600} // namespace art
601
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700602#endif // ART_RUNTIME_MIRROR_OBJECT_H_