blob: 886637be5cb8f60fb30a9c9b7fcee3b44e4eed68 [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
Vladimir Markodb8e62d2016-03-30 16:30:21 +010020#include "base/casts.h"
Andreas Gampe542451c2016-07-26 09:02:02 -070021#include "base/enums.h"
Ian Rogerscdc1aaf2014-10-09 13:21:38 -070022#include "globals.h"
Mathieu Chartiera59d9b22016-09-26 18:13:17 -070023#include "obj_ptr.h"
Ian Rogersef7d42f2014-01-06 12:55:46 -080024#include "object_reference.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080025#include "offsets.h"
Mathieu Chartier4e305412014-02-19 10:54:44 -080026#include "verify_object.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080027
28namespace art {
29
Mathieu Chartierc7853442015-03-27 14:35:38 -070030class ArtField;
Mathieu Chartiere401d142015-04-22 13:56:20 -070031class ArtMethod;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080032class ImageWriter;
Ian Rogersd9c4fc92013-10-01 19:45:43 -070033class LockWord;
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070034class Monitor;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080035struct ObjectOffsets;
36class Thread;
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070037class VoidFunctor;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080038
39namespace mirror {
40
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080041class Array;
42class Class;
Mathieu Chartiere4275c02015-08-06 15:34:15 -070043class ClassLoader;
Vladimir Marko05792b92015-08-03 11:56:49 +010044class DexCache;
Mathieu Chartier8fa2dad2014-03-13 12:22:56 -070045class FinalizerReference;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080046template<class T> class ObjectArray;
47template<class T> class PrimitiveArray;
48typedef PrimitiveArray<uint8_t> BooleanArray;
49typedef PrimitiveArray<int8_t> ByteArray;
50typedef PrimitiveArray<uint16_t> CharArray;
51typedef PrimitiveArray<double> DoubleArray;
52typedef PrimitiveArray<float> FloatArray;
53typedef PrimitiveArray<int32_t> IntArray;
54typedef PrimitiveArray<int64_t> LongArray;
55typedef PrimitiveArray<int16_t> ShortArray;
Mathieu Chartier8fa2dad2014-03-13 12:22:56 -070056class Reference;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080057class String;
58class Throwable;
59
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080060// Fields within mirror objects aren't accessed directly so that the appropriate amount of
61// handshaking is done with GC (for example, read and write barriers). This macro is used to
62// compute an offset for the Set/Get methods defined in Object that can safely access fields.
63#define OFFSET_OF_OBJECT_MEMBER(type, field) \
64 MemberOffset(OFFSETOF_MEMBER(type, field))
65
Mathieu Chartier4e305412014-02-19 10:54:44 -080066// Checks that we don't do field assignments which violate the typing system.
67static constexpr bool kCheckFieldAssignments = false;
Ian Rogers04d7aa92013-03-16 14:29:17 -070068
Ian Rogerscdc1aaf2014-10-09 13:21:38 -070069// Size of Object.
Hiroshi Yamauchi60f63f52015-04-23 16:12:40 -070070static constexpr uint32_t kObjectHeaderSize = kUseBrooksReadBarrier ? 16 : 8;
Ian Rogerscdc1aaf2014-10-09 13:21:38 -070071
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080072// C++ mirror of java.lang.Object
Ian Rogers719d1a32014-03-06 12:13:39 -080073class MANAGED LOCKABLE Object {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080074 public:
Mingyao Yang98d1cc82014-05-15 17:02:16 -070075 // The number of vtable entries in java.lang.Object.
76 static constexpr size_t kVTableLength = 11;
77
78 // The size of the java.lang.Class representing a java.lang.Object.
Andreas Gampe542451c2016-07-26 09:02:02 -070079 static uint32_t ClassSize(PointerSize pointer_size);
Mingyao Yang98d1cc82014-05-15 17:02:16 -070080
81 // Size of an instance of java.lang.Object.
82 static constexpr uint32_t InstanceSize() {
83 return sizeof(Object);
84 }
85
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080086 static MemberOffset ClassOffset() {
87 return OFFSET_OF_OBJECT_MEMBER(Object, klass_);
88 }
89
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -070090 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
91 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070092 ALWAYS_INLINE Class* GetClass() REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080093
Mathieu Chartier4e305412014-02-19 10:54:44 -080094 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartiera058fdf2016-10-06 15:13:58 -070095 void SetClass(ObjPtr<Class> new_klass) REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080096
Mathieu Chartierc381c362016-08-23 13:27:53 -070097 // TODO: Clean these up and change to return int32_t
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070098 Object* GetReadBarrierPointer() REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchied70b4a2015-11-17 17:52:15 -080099
Mathieu Chartierc381c362016-08-23 13:27:53 -0700100 // Get the read barrier pointer with release semantics, only supported for baker.
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700101 Object* GetReadBarrierPointerAcquire() REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartierc381c362016-08-23 13:27:53 -0700102
Andreas Gampe65b798e2015-04-06 09:35:22 -0700103#ifndef USE_BAKER_OR_BROOKS_READ_BARRIER
104 NO_RETURN
105#endif
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700106 void SetReadBarrierPointer(Object* rb_ptr) REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchied70b4a2015-11-17 17:52:15 -0800107
108 template<bool kCasRelease = false>
Hiroshi Yamauchi723e6ce2015-10-28 20:59:47 -0700109 ALWAYS_INLINE bool AtomicSetReadBarrierPointer(Object* expected_rb_ptr, Object* rb_ptr)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700110 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier36a270a2016-07-28 18:08:51 -0700111
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700112 ALWAYS_INLINE uint32_t GetMarkBit() REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier36a270a2016-07-28 18:08:51 -0700113
114 ALWAYS_INLINE bool AtomicSetMarkBit(uint32_t expected_mark_bit, uint32_t mark_bit)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700115 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier36a270a2016-07-28 18:08:51 -0700116
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700117 void AssertReadBarrierPointer() const REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchi9d04a202014-01-31 13:35:49 -0800118
Jeff Haoa3faaf42013-09-03 19:07:00 -0700119 // The verifier treats all interfaces as java.lang.Object and relies on runtime checks in
120 // invoke-interface to detect incompatible interface types.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800121 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartieref41db72016-10-25 15:08:01 -0700122 bool VerifierInstanceOf(ObjPtr<Class> klass) REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800123 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartiera59d9b22016-09-26 18:13:17 -0700124 ALWAYS_INLINE bool InstanceOf(ObjPtr<Class> klass) REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800125
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700126 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
127 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700128 size_t SizeOf() REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800129
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700130 Object* Clone(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartier4e2cb092015-07-22 16:17:51 -0700131 REQUIRES(!Roles::uninterruptible_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800132
Mathieu Chartier31e88222016-10-14 18:43:19 -0700133 int32_t IdentityHashCode()
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700134 REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartier31e88222016-10-14 18:43:19 -0700135 REQUIRES(!Locks::thread_list_lock_,
136 !Locks::thread_suspend_count_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800137
138 static MemberOffset MonitorOffset() {
139 return OFFSET_OF_OBJECT_MEMBER(Object, monitor_);
140 }
141
Hans Boehmd8434432014-07-11 09:56:07 -0700142 // As_volatile can be false if the mutators are suspended. This is an optimization since it
Mathieu Chartier4d7f61d2014-04-17 14:43:39 -0700143 // avoids the barriers.
Andreas Gampe3b45ef22015-05-26 21:34:09 -0700144 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700145 LockWord GetLockWord(bool as_volatile) REQUIRES_SHARED(Locks::mutator_lock_);
Andreas Gampe3b45ef22015-05-26 21:34:09 -0700146 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700147 void SetLockWord(LockWord new_val, bool as_volatile) REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers228602f2014-07-10 02:07:54 -0700148 bool CasLockWordWeakSequentiallyConsistent(LockWord old_val, LockWord new_val)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700149 REQUIRES_SHARED(Locks::mutator_lock_);
Hans Boehmd8434432014-07-11 09:56:07 -0700150 bool CasLockWordWeakRelaxed(LockWord old_val, LockWord new_val)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700151 REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchifed3e2f2015-10-20 11:11:56 -0700152 bool CasLockWordWeakRelease(LockWord old_val, LockWord new_val)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700153 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700154 uint32_t GetLockOwnerThreadId();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800155
Mathieu Chartiera704eda2016-07-13 09:53:35 -0700156 // Try to enter the monitor, returns non null if we succeeded.
157 mirror::Object* MonitorTryEnter(Thread* self)
158 EXCLUSIVE_LOCK_FUNCTION()
159 REQUIRES(!Roles::uninterruptible_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700160 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier2d096c92015-10-12 16:18:20 -0700161 mirror::Object* MonitorEnter(Thread* self)
162 EXCLUSIVE_LOCK_FUNCTION()
163 REQUIRES(!Roles::uninterruptible_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700164 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier2d096c92015-10-12 16:18:20 -0700165 bool MonitorExit(Thread* self)
166 REQUIRES(!Roles::uninterruptible_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700167 REQUIRES_SHARED(Locks::mutator_lock_)
Ian Rogers719d1a32014-03-06 12:13:39 -0800168 UNLOCK_FUNCTION();
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700169 void Notify(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_);
170 void NotifyAll(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_);
171 void Wait(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_);
172 void Wait(Thread* self, int64_t timeout, int32_t nanos) REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800173
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700174 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
175 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700176 bool IsClass() REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700177 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
178 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700179 Class* AsClass() REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800180
Mathieu Chartierdfe02f62016-02-01 20:15:11 -0800181 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
182 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700183 bool IsObjectArray() REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartierdfe02f62016-02-01 20:15:11 -0800184 template<class T,
185 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
186 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700187 ObjectArray<T>* AsObjectArray() REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800188
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800189 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
190 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700191 bool IsClassLoader() REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800192 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
193 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700194 ClassLoader* AsClassLoader() REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartiere4275c02015-08-06 15:34:15 -0700195
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800196 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
197 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700198 bool IsDexCache() REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800199 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
200 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700201 DexCache* AsDexCache() REQUIRES_SHARED(Locks::mutator_lock_);
Vladimir Marko05792b92015-08-03 11:56:49 +0100202
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700203 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
204 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700205 bool IsArrayInstance() REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700206 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
207 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700208 Array* AsArray() REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800209
Mathieu Chartier4e305412014-02-19 10:54:44 -0800210 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700211 BooleanArray* AsBooleanArray() REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800212 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700213 ByteArray* AsByteArray() REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800214 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700215 ByteArray* AsByteSizedArray() REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800216
Mathieu Chartier4e305412014-02-19 10:54:44 -0800217 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700218 CharArray* AsCharArray() REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800219 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700220 ShortArray* AsShortArray() REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800221 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700222 ShortArray* AsShortSizedArray() REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800223
Mathieu Chartierdfe02f62016-02-01 20:15:11 -0800224 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
225 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700226 bool IsIntArray() REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartierdfe02f62016-02-01 20:15:11 -0800227 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
228 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700229 IntArray* AsIntArray() REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700230
Mathieu Chartierdfe02f62016-02-01 20:15:11 -0800231 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
232 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700233 bool IsLongArray() REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartierdfe02f62016-02-01 20:15:11 -0800234 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
235 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700236 LongArray* AsLongArray() REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800237
Mathieu Chartier4e305412014-02-19 10:54:44 -0800238 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700239 bool IsFloatArray() REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700240 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700241 FloatArray* AsFloatArray() REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700242
243 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700244 bool IsDoubleArray() REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800245 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700246 DoubleArray* AsDoubleArray() REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100247
Jeff Hao848f70a2014-01-15 13:49:50 -0800248 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
249 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700250 bool IsString() REQUIRES_SHARED(Locks::mutator_lock_);
Jeff Hao848f70a2014-01-15 13:49:50 -0800251
252 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
253 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700254 String* AsString() REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800255
Mathieu Chartier4e305412014-02-19 10:54:44 -0800256 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700257 Throwable* AsThrowable() REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800258
Mathieu Chartierdfe02f62016-02-01 20:15:11 -0800259 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
260 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700261 bool IsReferenceInstance() REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartierdfe02f62016-02-01 20:15:11 -0800262 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
263 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700264 Reference* AsReference() REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier8fa2dad2014-03-13 12:22:56 -0700265 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700266 bool IsWeakReferenceInstance() REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800267 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700268 bool IsSoftReferenceInstance() REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800269 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700270 bool IsFinalizerReferenceInstance() REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800271 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700272 FinalizerReference* AsFinalizerReference() REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier8fa2dad2014-03-13 12:22:56 -0700273 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700274 bool IsPhantomReferenceInstance() REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800275
Ian Rogersef7d42f2014-01-06 12:55:46 -0800276 // Accessor for Java type fields.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700277 template<class T, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700278 ReadBarrierOption kReadBarrierOption = kWithReadBarrier, bool kIsVolatile = false>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700279 ALWAYS_INLINE T* GetFieldObject(MemberOffset field_offset)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700280 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700281
282 template<class T, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700283 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700284 ALWAYS_INLINE T* GetFieldObjectVolatile(MemberOffset field_offset)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700285 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700286
Mathieu Chartiera058fdf2016-10-06 15:13:58 -0700287 template<bool kTransactionActive,
288 bool kCheckTransaction = true,
289 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
290 bool kIsVolatile = false>
291 ALWAYS_INLINE void SetFieldObjectWithoutWriteBarrier(MemberOffset field_offset,
292 ObjPtr<Object> new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700293 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700294
Mathieu Chartiera058fdf2016-10-06 15:13:58 -0700295 template<bool kTransactionActive,
296 bool kCheckTransaction = true,
297 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
298 bool kIsVolatile = false>
299 ALWAYS_INLINE void SetFieldObject(MemberOffset field_offset, ObjPtr<Object> new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700300 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700301
Mathieu Chartiera058fdf2016-10-06 15:13:58 -0700302 template<bool kTransactionActive,
303 bool kCheckTransaction = true,
304 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
305 ALWAYS_INLINE void SetFieldObjectVolatile(MemberOffset field_offset,
306 ObjPtr<Object> new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700307 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700308
Mathieu Chartiera058fdf2016-10-06 15:13:58 -0700309 template<bool kTransactionActive,
310 bool kCheckTransaction = true,
311 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
312 bool CasFieldWeakSequentiallyConsistentObject(MemberOffset field_offset,
313 ObjPtr<Object> old_value,
314 ObjPtr<Object> new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700315 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartiera058fdf2016-10-06 15:13:58 -0700316 template<bool kTransactionActive,
317 bool kCheckTransaction = true,
318 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800319 bool CasFieldWeakSequentiallyConsistentObjectWithoutWriteBarrier(MemberOffset field_offset,
Mathieu Chartiera058fdf2016-10-06 15:13:58 -0700320 ObjPtr<Object> old_value,
321 ObjPtr<Object> new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700322 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartiera058fdf2016-10-06 15:13:58 -0700323 template<bool kTransactionActive,
324 bool kCheckTransaction = true,
325 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
326 bool CasFieldStrongSequentiallyConsistentObject(MemberOffset field_offset,
327 ObjPtr<Object> old_value,
328 ObjPtr<Object> new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700329 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartiera058fdf2016-10-06 15:13:58 -0700330 template<bool kTransactionActive,
331 bool kCheckTransaction = true,
332 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800333 bool CasFieldStrongSequentiallyConsistentObjectWithoutWriteBarrier(MemberOffset field_offset,
Mathieu Chartiera058fdf2016-10-06 15:13:58 -0700334 ObjPtr<Object> old_value,
335 ObjPtr<Object> new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700336 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartiera058fdf2016-10-06 15:13:58 -0700337 template<bool kTransactionActive,
338 bool kCheckTransaction = true,
339 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Hiroshi Yamauchifed3e2f2015-10-20 11:11:56 -0700340 bool CasFieldWeakRelaxedObjectWithoutWriteBarrier(MemberOffset field_offset,
Mathieu Chartiera058fdf2016-10-06 15:13:58 -0700341 ObjPtr<Object> old_value,
342 ObjPtr<Object> new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700343 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartiera058fdf2016-10-06 15:13:58 -0700344 template<bool kTransactionActive,
345 bool kCheckTransaction = true,
346 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Hiroshi Yamauchifed3e2f2015-10-20 11:11:56 -0700347 bool CasFieldStrongRelaxedObjectWithoutWriteBarrier(MemberOffset field_offset,
Mathieu Chartiera058fdf2016-10-06 15:13:58 -0700348 ObjPtr<Object> old_value,
349 ObjPtr<Object> new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700350 REQUIRES_SHARED(Locks::mutator_lock_);
Hans Boehmd8434432014-07-11 09:56:07 -0700351
Mathieu Chartier4e305412014-02-19 10:54:44 -0800352 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
353 HeapReference<Object>* GetFieldObjectReferenceAddr(MemberOffset field_offset);
Mathieu Chartier11409ae2013-09-23 11:49:36 -0700354
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700355 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
Fred Shih37f05ef2014-07-16 18:38:08 -0700356 ALWAYS_INLINE uint8_t GetFieldBoolean(MemberOffset field_offset)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700357 REQUIRES_SHARED(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700358
359 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
360 ALWAYS_INLINE int8_t GetFieldByte(MemberOffset field_offset)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700361 REQUIRES_SHARED(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700362
363 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
364 ALWAYS_INLINE uint8_t GetFieldBooleanVolatile(MemberOffset field_offset)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700365 REQUIRES_SHARED(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700366
367 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
368 ALWAYS_INLINE int8_t GetFieldByteVolatile(MemberOffset field_offset)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700369 REQUIRES_SHARED(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700370
371 template<bool kTransactionActive, bool kCheckTransaction = true,
372 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
373 ALWAYS_INLINE void SetFieldBoolean(MemberOffset field_offset, uint8_t new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700374 REQUIRES_SHARED(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700375
376 template<bool kTransactionActive, bool kCheckTransaction = true,
377 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
378 ALWAYS_INLINE void SetFieldByte(MemberOffset field_offset, int8_t new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700379 REQUIRES_SHARED(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700380
381 template<bool kTransactionActive, bool kCheckTransaction = true,
382 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
383 ALWAYS_INLINE void SetFieldBooleanVolatile(MemberOffset field_offset, uint8_t new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700384 REQUIRES_SHARED(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700385
386 template<bool kTransactionActive, bool kCheckTransaction = true,
387 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
388 ALWAYS_INLINE void SetFieldByteVolatile(MemberOffset field_offset, int8_t new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700389 REQUIRES_SHARED(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700390
391 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
392 ALWAYS_INLINE uint16_t GetFieldChar(MemberOffset field_offset)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700393 REQUIRES_SHARED(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700394
395 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
396 ALWAYS_INLINE int16_t GetFieldShort(MemberOffset field_offset)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700397 REQUIRES_SHARED(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700398
399 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
400 ALWAYS_INLINE uint16_t GetFieldCharVolatile(MemberOffset field_offset)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700401 REQUIRES_SHARED(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700402
403 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
404 ALWAYS_INLINE int16_t GetFieldShortVolatile(MemberOffset field_offset)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700405 REQUIRES_SHARED(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700406
407 template<bool kTransactionActive, bool kCheckTransaction = true,
408 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
409 ALWAYS_INLINE void SetFieldChar(MemberOffset field_offset, uint16_t new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700410 REQUIRES_SHARED(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700411
412 template<bool kTransactionActive, bool kCheckTransaction = true,
413 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
414 ALWAYS_INLINE void SetFieldShort(MemberOffset field_offset, int16_t new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700415 REQUIRES_SHARED(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700416
417 template<bool kTransactionActive, bool kCheckTransaction = true,
418 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
419 ALWAYS_INLINE void SetFieldCharVolatile(MemberOffset field_offset, uint16_t new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700420 REQUIRES_SHARED(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700421
422 template<bool kTransactionActive, bool kCheckTransaction = true,
423 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
424 ALWAYS_INLINE void SetFieldShortVolatile(MemberOffset field_offset, int16_t new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700425 REQUIRES_SHARED(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700426
427 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700428 ALWAYS_INLINE int32_t GetField32(MemberOffset field_offset)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700429 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700430
Mathieu Chartier4e305412014-02-19 10:54:44 -0800431 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700432 ALWAYS_INLINE int32_t GetField32Volatile(MemberOffset field_offset)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700433 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700434
435 template<bool kTransactionActive, bool kCheckTransaction = true,
436 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700437 ALWAYS_INLINE void SetField32(MemberOffset field_offset, int32_t new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700438 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700439
Mathieu Chartier4e305412014-02-19 10:54:44 -0800440 template<bool kTransactionActive, bool kCheckTransaction = true,
441 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700442 ALWAYS_INLINE void SetField32Volatile(MemberOffset field_offset, int32_t new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700443 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700444
445 template<bool kTransactionActive, bool kCheckTransaction = true,
446 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700447 ALWAYS_INLINE bool CasFieldWeakSequentiallyConsistent32(MemberOffset field_offset,
448 int32_t old_value, int32_t new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700449 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700450
Hans Boehmd8434432014-07-11 09:56:07 -0700451 template<bool kTransactionActive, bool kCheckTransaction = true,
452 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
453 bool CasFieldWeakRelaxed32(MemberOffset field_offset, int32_t old_value,
454 int32_t new_value) ALWAYS_INLINE
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700455 REQUIRES_SHARED(Locks::mutator_lock_);
Hans Boehmd8434432014-07-11 09:56:07 -0700456
457 template<bool kTransactionActive, bool kCheckTransaction = true,
458 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Hiroshi Yamauchifed3e2f2015-10-20 11:11:56 -0700459 bool CasFieldWeakRelease32(MemberOffset field_offset, int32_t old_value,
460 int32_t new_value) ALWAYS_INLINE
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700461 REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchifed3e2f2015-10-20 11:11:56 -0700462
463 template<bool kTransactionActive, bool kCheckTransaction = true,
464 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Hans Boehmd8434432014-07-11 09:56:07 -0700465 bool CasFieldStrongSequentiallyConsistent32(MemberOffset field_offset, int32_t old_value,
466 int32_t new_value) ALWAYS_INLINE
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700467 REQUIRES_SHARED(Locks::mutator_lock_);
Hans Boehmd8434432014-07-11 09:56:07 -0700468
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700469 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700470 ALWAYS_INLINE int64_t GetField64(MemberOffset field_offset)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700471 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700472
473 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700474 ALWAYS_INLINE int64_t GetField64Volatile(MemberOffset field_offset)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700475 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700476
477 template<bool kTransactionActive, bool kCheckTransaction = true,
478 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700479 ALWAYS_INLINE void SetField64(MemberOffset field_offset, int64_t new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700480 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700481
482 template<bool kTransactionActive, bool kCheckTransaction = true,
483 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700484 ALWAYS_INLINE void SetField64Volatile(MemberOffset field_offset, int64_t new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700485 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800486
Mathieu Chartier4e305412014-02-19 10:54:44 -0800487 template<bool kTransactionActive, bool kCheckTransaction = true,
488 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogers228602f2014-07-10 02:07:54 -0700489 bool CasFieldWeakSequentiallyConsistent64(MemberOffset field_offset, int64_t old_value,
490 int64_t new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700491 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800492
Mathieu Chartier4e305412014-02-19 10:54:44 -0800493 template<bool kTransactionActive, bool kCheckTransaction = true,
Hans Boehmd8434432014-07-11 09:56:07 -0700494 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
495 bool CasFieldStrongSequentiallyConsistent64(MemberOffset field_offset, int64_t old_value,
496 int64_t new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700497 REQUIRES_SHARED(Locks::mutator_lock_);
Hans Boehmd8434432014-07-11 09:56:07 -0700498
499 template<bool kTransactionActive, bool kCheckTransaction = true,
Mathieu Chartier4e305412014-02-19 10:54:44 -0800500 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, typename T>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700501 void SetFieldPtr(MemberOffset field_offset, T new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700502 REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800503 SetFieldPtrWithSize<kTransactionActive, kCheckTransaction, kVerifyFlags>(
Andreas Gampe542451c2016-07-26 09:02:02 -0700504 field_offset, new_value, kRuntimePointerSize);
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800505 }
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800506 template<bool kTransactionActive, bool kCheckTransaction = true,
507 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, typename T>
508 void SetFieldPtr64(MemberOffset field_offset, T new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700509 REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800510 SetFieldPtrWithSize<kTransactionActive, kCheckTransaction, kVerifyFlags>(
511 field_offset, new_value, 8u);
512 }
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800513
Mathieu Chartier2d721012014-11-10 11:08:06 -0800514 template<bool kTransactionActive, bool kCheckTransaction = true,
515 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, typename T>
Andreas Gampe542451c2016-07-26 09:02:02 -0700516 ALWAYS_INLINE void SetFieldPtrWithSize(MemberOffset field_offset,
517 T new_value,
518 PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700519 REQUIRES_SHARED(Locks::mutator_lock_) {
Andreas Gampe542451c2016-07-26 09:02:02 -0700520 if (pointer_size == PointerSize::k32) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800521 intptr_t ptr = reinterpret_cast<intptr_t>(new_value);
522 DCHECK_EQ(static_cast<int32_t>(ptr), ptr); // Check that we dont lose any non 0 bits.
523 SetField32<kTransactionActive, kCheckTransaction, kVerifyFlags>(
524 field_offset, static_cast<int32_t>(ptr));
525 } else {
526 SetField64<kTransactionActive, kCheckTransaction, kVerifyFlags>(
Vladimir Markodb8e62d2016-03-30 16:30:21 +0100527 field_offset, reinterpret_cast64<int64_t>(new_value));
Mathieu Chartier2d721012014-11-10 11:08:06 -0800528 }
529 }
Mathieu Chartier407f7022014-02-18 14:37:05 -0800530 // TODO fix thread safety analysis broken by the use of template. This should be
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700531 // REQUIRES_SHARED(Locks::mutator_lock_).
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800532 template <bool kVisitNativeRoots = true,
533 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
534 ReadBarrierOption kReadBarrierOption = kWithReadBarrier,
Mathieu Chartier059ef3d2015-08-18 13:54:21 -0700535 typename Visitor,
536 typename JavaLangRefVisitor = VoidFunctor>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700537 void VisitReferences(const Visitor& visitor, const JavaLangRefVisitor& ref_visitor)
Mathieu Chartier407f7022014-02-18 14:37:05 -0800538 NO_THREAD_SAFETY_ANALYSIS;
539
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700540 ArtField* FindFieldByOffset(MemberOffset offset) REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchieb2baaf2015-05-13 21:14:22 -0700541
tony.ys_liu7380c312015-01-16 19:16:45 +0800542 // Used by object_test.
543 static void SetHashCodeSeed(uint32_t new_seed);
544 // Generate an identity hash code. Public for object test.
545 static uint32_t GenerateIdentityHashCode();
546
David Sehr709b0702016-10-13 09:12:37 -0700547 // Returns a human-readable form of the name of the *class* of the given object.
548 // So given an instance of java.lang.String, the output would
549 // be "java.lang.String". Given an array of int, the output would be "int[]".
550 // Given String.class, the output would be "java.lang.Class<java.lang.String>".
551 static std::string PrettyTypeOf(ObjPtr<mirror::Object> obj)
552 REQUIRES_SHARED(Locks::mutator_lock_);
553 std::string PrettyTypeOf()
554 REQUIRES_SHARED(Locks::mutator_lock_);
555
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800556 protected:
557 // Accessors for non-Java type fields
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700558 template<class T, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
559 T GetFieldPtr(MemberOffset field_offset)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700560 REQUIRES_SHARED(Locks::mutator_lock_) {
Andreas Gampe542451c2016-07-26 09:02:02 -0700561 return GetFieldPtrWithSize<T, kVerifyFlags, kIsVolatile>(field_offset, kRuntimePointerSize);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800562 }
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800563 template<class T, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
564 T GetFieldPtr64(MemberOffset field_offset)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700565 REQUIRES_SHARED(Locks::mutator_lock_) {
Andreas Gampe542451c2016-07-26 09:02:02 -0700566 return GetFieldPtrWithSize<T, kVerifyFlags, kIsVolatile>(field_offset,
567 PointerSize::k64);
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800568 }
Mathieu Chartier2d721012014-11-10 11:08:06 -0800569
570 template<class T, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
Andreas Gampe542451c2016-07-26 09:02:02 -0700571 ALWAYS_INLINE T GetFieldPtrWithSize(MemberOffset field_offset, PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700572 REQUIRES_SHARED(Locks::mutator_lock_) {
Andreas Gampe542451c2016-07-26 09:02:02 -0700573 if (pointer_size == PointerSize::k32) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800574 return reinterpret_cast<T>(GetField32<kVerifyFlags, kIsVolatile>(field_offset));
575 } else {
576 int64_t v = GetField64<kVerifyFlags, kIsVolatile>(field_offset);
Vladimir Markodb8e62d2016-03-30 16:30:21 +0100577 return reinterpret_cast64<T>(v);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800578 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800579 }
580
Mathieu Chartier407f7022014-02-18 14:37:05 -0800581 // TODO: Fixme when anotatalysis works with visitors.
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800582 template<bool kIsStatic,
583 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
584 ReadBarrierOption kReadBarrierOption = kWithReadBarrier,
585 typename Visitor>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700586 void VisitFieldsReferences(uint32_t ref_offsets, const Visitor& visitor) HOT_ATTR
Mathieu Chartier407f7022014-02-18 14:37:05 -0800587 NO_THREAD_SAFETY_ANALYSIS;
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800588 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
589 ReadBarrierOption kReadBarrierOption = kWithReadBarrier,
590 typename Visitor>
Mathieu Chartier31e88222016-10-14 18:43:19 -0700591 void VisitInstanceFieldsReferences(ObjPtr<mirror::Class> klass, const Visitor& visitor) HOT_ATTR
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700592 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800593 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
594 ReadBarrierOption kReadBarrierOption = kWithReadBarrier,
595 typename Visitor>
Mathieu Chartier31e88222016-10-14 18:43:19 -0700596 void VisitStaticFieldsReferences(ObjPtr<mirror::Class> klass, const Visitor& visitor) HOT_ATTR
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700597 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier407f7022014-02-18 14:37:05 -0800598
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800599 private:
Fred Shih37f05ef2014-07-16 18:38:08 -0700600 template<typename kSize, bool kIsVolatile>
601 ALWAYS_INLINE void SetField(MemberOffset field_offset, kSize new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700602 REQUIRES_SHARED(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700603 template<typename kSize, bool kIsVolatile>
604 ALWAYS_INLINE kSize GetField(MemberOffset field_offset)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700605 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartierc381c362016-08-23 13:27:53 -0700606 // Get a field with acquire semantics.
607 template<typename kSize>
608 ALWAYS_INLINE kSize GetFieldAcquire(MemberOffset field_offset)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700609 REQUIRES_SHARED(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700610
Ian Rogers04d7aa92013-03-16 14:29:17 -0700611 // Verify the type correctness of stores to fields.
Mathieu Chartier61c5ebc2014-06-05 17:42:53 -0700612 // TODO: This can cause thread suspension and isn't moving GC safe.
Mathieu Chartiera058fdf2016-10-06 15:13:58 -0700613 void CheckFieldAssignmentImpl(MemberOffset field_offset, ObjPtr<Object> new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700614 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartiera058fdf2016-10-06 15:13:58 -0700615 void CheckFieldAssignment(MemberOffset field_offset, ObjPtr<Object>new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700616 REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogers04d7aa92013-03-16 14:29:17 -0700617 if (kCheckFieldAssignments) {
618 CheckFieldAssignmentImpl(field_offset, new_value);
619 }
620 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800621
Mathieu Chartier51eaa7f2016-10-12 16:08:35 -0700622 // A utility function that copies an object in a read barrier and write barrier-aware way.
623 // This is internally used by Clone() and Class::CopyOf(). If the object is finalizable,
624 // it is the callers job to call Heap::AddFinalizerReference.
625 static Object* CopyObject(ObjPtr<mirror::Object> dest,
Mathieu Chartier9d156d52016-10-06 17:44:26 -0700626 ObjPtr<mirror::Object> src,
Hiroshi Yamauchi0fbd6e62014-07-17 16:16:31 -0700627 size_t num_bytes)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700628 REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchi0fbd6e62014-07-17 16:16:31 -0700629
tony.ys_liu7380c312015-01-16 19:16:45 +0800630 static Atomic<uint32_t> hash_code_seed;
631
Ian Rogersef7d42f2014-01-06 12:55:46 -0800632 // The Class representing the type of the object.
633 HeapReference<Class> klass_;
634 // Monitor and hash code information.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800635 uint32_t monitor_;
636
Hiroshi Yamauchi60f63f52015-04-23 16:12:40 -0700637#ifdef USE_BROOKS_READ_BARRIER
Hiroshi Yamauchi624468c2014-03-31 15:14:47 -0700638 // Note names use a 'x' prefix and the x_rb_ptr_ is of type int
Hiroshi Yamauchi9d04a202014-01-31 13:35:49 -0800639 // instead of Object to go with the alphabetical/by-type field order
640 // on the Java side.
Hiroshi Yamauchi60f63f52015-04-23 16:12:40 -0700641 uint32_t x_rb_ptr_; // For the Brooks pointer.
Hiroshi Yamauchi624468c2014-03-31 15:14:47 -0700642 uint32_t x_xpadding_; // For 8-byte alignment. TODO: get rid of this.
Hiroshi Yamauchi9d04a202014-01-31 13:35:49 -0800643#endif
644
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800645 friend class art::ImageWriter;
Mathieu Chartierad2541a2013-10-25 10:05:23 -0700646 friend class art::Monitor;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800647 friend struct art::ObjectOffsets; // for verifying offset information
Hiroshi Yamauchi0fbd6e62014-07-17 16:16:31 -0700648 friend class CopyObjectVisitor; // for CopyObject().
649 friend class CopyClassVisitor; // for CopyObject().
Ian Rogerscf7f1912014-10-22 22:06:39 -0700650 DISALLOW_ALLOCATION();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800651 DISALLOW_IMPLICIT_CONSTRUCTORS(Object);
652};
653
654} // namespace mirror
655} // namespace art
656
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700657#endif // ART_RUNTIME_MIRROR_OBJECT_H_