blob: 0ee46c3556071bd0ce965fb8e1fe34462137d37c [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"
Ian Rogerscdc1aaf2014-10-09 13:21:38 -070021#include "globals.h"
Ian Rogersef7d42f2014-01-06 12:55:46 -080022#include "object_reference.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080023#include "offsets.h"
Mathieu Chartier4e305412014-02-19 10:54:44 -080024#include "verify_object.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080025
26namespace art {
27
Mathieu Chartierc7853442015-03-27 14:35:38 -070028class ArtField;
Mathieu Chartiere401d142015-04-22 13:56:20 -070029class ArtMethod;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080030class ImageWriter;
Ian Rogersd9c4fc92013-10-01 19:45:43 -070031class LockWord;
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070032class Monitor;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080033struct ObjectOffsets;
34class Thread;
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070035class VoidFunctor;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080036
37namespace mirror {
38
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080039class Array;
40class Class;
Mathieu Chartiere4275c02015-08-06 15:34:15 -070041class ClassLoader;
Vladimir Marko05792b92015-08-03 11:56:49 +010042class DexCache;
Mathieu Chartier8fa2dad2014-03-13 12:22:56 -070043class FinalizerReference;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080044template<class T> class ObjectArray;
45template<class T> class PrimitiveArray;
46typedef PrimitiveArray<uint8_t> BooleanArray;
47typedef PrimitiveArray<int8_t> ByteArray;
48typedef PrimitiveArray<uint16_t> CharArray;
49typedef PrimitiveArray<double> DoubleArray;
50typedef PrimitiveArray<float> FloatArray;
51typedef PrimitiveArray<int32_t> IntArray;
52typedef PrimitiveArray<int64_t> LongArray;
53typedef PrimitiveArray<int16_t> ShortArray;
Mathieu Chartier8fa2dad2014-03-13 12:22:56 -070054class Reference;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080055class String;
56class Throwable;
57
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080058// Fields within mirror objects aren't accessed directly so that the appropriate amount of
59// handshaking is done with GC (for example, read and write barriers). This macro is used to
60// compute an offset for the Set/Get methods defined in Object that can safely access fields.
61#define OFFSET_OF_OBJECT_MEMBER(type, field) \
62 MemberOffset(OFFSETOF_MEMBER(type, field))
63
Mathieu Chartier4e305412014-02-19 10:54:44 -080064// Checks that we don't do field assignments which violate the typing system.
65static constexpr bool kCheckFieldAssignments = false;
Ian Rogers04d7aa92013-03-16 14:29:17 -070066
Ian Rogerscdc1aaf2014-10-09 13:21:38 -070067// Size of Object.
Hiroshi Yamauchi60f63f52015-04-23 16:12:40 -070068static constexpr uint32_t kObjectHeaderSize = kUseBrooksReadBarrier ? 16 : 8;
Ian Rogerscdc1aaf2014-10-09 13:21:38 -070069
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080070// C++ mirror of java.lang.Object
Ian Rogers719d1a32014-03-06 12:13:39 -080071class MANAGED LOCKABLE Object {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080072 public:
Mingyao Yang98d1cc82014-05-15 17:02:16 -070073 // The number of vtable entries in java.lang.Object.
74 static constexpr size_t kVTableLength = 11;
75
76 // The size of the java.lang.Class representing a java.lang.Object.
Mathieu Chartiere401d142015-04-22 13:56:20 -070077 static uint32_t ClassSize(size_t pointer_size);
Mingyao Yang98d1cc82014-05-15 17:02:16 -070078
79 // Size of an instance of java.lang.Object.
80 static constexpr uint32_t InstanceSize() {
81 return sizeof(Object);
82 }
83
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080084 static MemberOffset ClassOffset() {
85 return OFFSET_OF_OBJECT_MEMBER(Object, klass_);
86 }
87
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -070088 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
89 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mathieu Chartier90443472015-07-16 20:32:27 -070090 ALWAYS_INLINE Class* GetClass() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080091
Mathieu Chartier4e305412014-02-19 10:54:44 -080092 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -070093 void SetClass(Class* new_klass) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080094
Mathieu Chartier90443472015-07-16 20:32:27 -070095 Object* GetReadBarrierPointer() SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchied70b4a2015-11-17 17:52:15 -080096
Andreas Gampe65b798e2015-04-06 09:35:22 -070097#ifndef USE_BAKER_OR_BROOKS_READ_BARRIER
98 NO_RETURN
99#endif
Mathieu Chartier90443472015-07-16 20:32:27 -0700100 void SetReadBarrierPointer(Object* rb_ptr) SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchied70b4a2015-11-17 17:52:15 -0800101
102 template<bool kCasRelease = false>
Hiroshi Yamauchi723e6ce2015-10-28 20:59:47 -0700103 ALWAYS_INLINE bool AtomicSetReadBarrierPointer(Object* expected_rb_ptr, Object* rb_ptr)
Mathieu Chartier90443472015-07-16 20:32:27 -0700104 SHARED_REQUIRES(Locks::mutator_lock_);
105 void AssertReadBarrierPointer() const SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchi9d04a202014-01-31 13:35:49 -0800106
Jeff Haoa3faaf42013-09-03 19:07:00 -0700107 // The verifier treats all interfaces as java.lang.Object and relies on runtime checks in
108 // invoke-interface to detect incompatible interface types.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800109 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700110 bool VerifierInstanceOf(Class* klass) SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800111 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700112 ALWAYS_INLINE bool InstanceOf(Class* klass) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800113
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700114 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
115 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mathieu Chartier90443472015-07-16 20:32:27 -0700116 size_t SizeOf() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800117
Mathieu Chartier4e2cb092015-07-22 16:17:51 -0700118 Object* Clone(Thread* self) SHARED_REQUIRES(Locks::mutator_lock_)
119 REQUIRES(!Roles::uninterruptible_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800120
Sebastien Hertz69206392015-04-07 15:54:25 +0200121 int32_t IdentityHashCode() const
Mathieu Chartier90443472015-07-16 20:32:27 -0700122 SHARED_REQUIRES(Locks::mutator_lock_)
123 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800124
125 static MemberOffset MonitorOffset() {
126 return OFFSET_OF_OBJECT_MEMBER(Object, monitor_);
127 }
128
Hans Boehmd8434432014-07-11 09:56:07 -0700129 // As_volatile can be false if the mutators are suspended. This is an optimization since it
Mathieu Chartier4d7f61d2014-04-17 14:43:39 -0700130 // avoids the barriers.
Andreas Gampe3b45ef22015-05-26 21:34:09 -0700131 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700132 LockWord GetLockWord(bool as_volatile) SHARED_REQUIRES(Locks::mutator_lock_);
Andreas Gampe3b45ef22015-05-26 21:34:09 -0700133 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700134 void SetLockWord(LockWord new_val, bool as_volatile) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers228602f2014-07-10 02:07:54 -0700135 bool CasLockWordWeakSequentiallyConsistent(LockWord old_val, LockWord new_val)
Mathieu Chartier90443472015-07-16 20:32:27 -0700136 SHARED_REQUIRES(Locks::mutator_lock_);
Hans Boehmd8434432014-07-11 09:56:07 -0700137 bool CasLockWordWeakRelaxed(LockWord old_val, LockWord new_val)
Mathieu Chartier90443472015-07-16 20:32:27 -0700138 SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchifed3e2f2015-10-20 11:11:56 -0700139 bool CasLockWordWeakRelease(LockWord old_val, LockWord new_val)
140 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700141 uint32_t GetLockOwnerThreadId();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800142
Mathieu Chartier2d096c92015-10-12 16:18:20 -0700143 mirror::Object* MonitorEnter(Thread* self)
144 EXCLUSIVE_LOCK_FUNCTION()
145 REQUIRES(!Roles::uninterruptible_)
146 SHARED_REQUIRES(Locks::mutator_lock_);
147 bool MonitorExit(Thread* self)
148 REQUIRES(!Roles::uninterruptible_)
149 SHARED_REQUIRES(Locks::mutator_lock_)
Ian Rogers719d1a32014-03-06 12:13:39 -0800150 UNLOCK_FUNCTION();
Mathieu Chartier90443472015-07-16 20:32:27 -0700151 void Notify(Thread* self) SHARED_REQUIRES(Locks::mutator_lock_);
152 void NotifyAll(Thread* self) SHARED_REQUIRES(Locks::mutator_lock_);
153 void Wait(Thread* self) SHARED_REQUIRES(Locks::mutator_lock_);
154 void Wait(Thread* self, int64_t timeout, int32_t nanos) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800155
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700156 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
157 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mathieu Chartier90443472015-07-16 20:32:27 -0700158 bool IsClass() SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700159 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
160 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mathieu Chartier90443472015-07-16 20:32:27 -0700161 Class* AsClass() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800162
Mathieu Chartierdfe02f62016-02-01 20:15:11 -0800163 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
164 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mathieu Chartier90443472015-07-16 20:32:27 -0700165 bool IsObjectArray() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartierdfe02f62016-02-01 20:15:11 -0800166 template<class T,
167 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
168 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mathieu Chartier90443472015-07-16 20:32:27 -0700169 ObjectArray<T>* AsObjectArray() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800170
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800171 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
172 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mathieu Chartiere4275c02015-08-06 15:34:15 -0700173 bool IsClassLoader() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800174 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
175 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mathieu Chartiere4275c02015-08-06 15:34:15 -0700176 ClassLoader* AsClassLoader() SHARED_REQUIRES(Locks::mutator_lock_);
177
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800178 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
179 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Vladimir Marko05792b92015-08-03 11:56:49 +0100180 bool IsDexCache() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800181 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
182 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Vladimir Marko05792b92015-08-03 11:56:49 +0100183 DexCache* AsDexCache() SHARED_REQUIRES(Locks::mutator_lock_);
184
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700185 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
186 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mathieu Chartier90443472015-07-16 20:32:27 -0700187 bool IsArrayInstance() SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700188 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
189 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mathieu Chartier90443472015-07-16 20:32:27 -0700190 Array* AsArray() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800191
Mathieu Chartier4e305412014-02-19 10:54:44 -0800192 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700193 BooleanArray* AsBooleanArray() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800194 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700195 ByteArray* AsByteArray() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800196 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700197 ByteArray* AsByteSizedArray() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800198
Mathieu Chartier4e305412014-02-19 10:54:44 -0800199 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700200 CharArray* AsCharArray() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800201 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700202 ShortArray* AsShortArray() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800203 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700204 ShortArray* AsShortSizedArray() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800205
Mathieu Chartierdfe02f62016-02-01 20:15:11 -0800206 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
207 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mathieu Chartier90443472015-07-16 20:32:27 -0700208 bool IsIntArray() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartierdfe02f62016-02-01 20:15:11 -0800209 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
210 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mathieu Chartier90443472015-07-16 20:32:27 -0700211 IntArray* AsIntArray() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700212
Mathieu Chartierdfe02f62016-02-01 20:15:11 -0800213 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
214 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mathieu Chartier90443472015-07-16 20:32:27 -0700215 bool IsLongArray() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartierdfe02f62016-02-01 20:15:11 -0800216 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
217 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mathieu Chartier90443472015-07-16 20:32:27 -0700218 LongArray* AsLongArray() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800219
Mathieu Chartier4e305412014-02-19 10:54:44 -0800220 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700221 bool IsFloatArray() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700222 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700223 FloatArray* AsFloatArray() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700224
225 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700226 bool IsDoubleArray() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800227 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700228 DoubleArray* AsDoubleArray() SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100229
Jeff Hao848f70a2014-01-15 13:49:50 -0800230 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
231 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mathieu Chartier90443472015-07-16 20:32:27 -0700232 bool IsString() SHARED_REQUIRES(Locks::mutator_lock_);
Jeff Hao848f70a2014-01-15 13:49:50 -0800233
234 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
235 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mathieu Chartier90443472015-07-16 20:32:27 -0700236 String* AsString() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800237
Mathieu Chartier4e305412014-02-19 10:54:44 -0800238 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700239 Throwable* AsThrowable() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800240
Mathieu Chartierdfe02f62016-02-01 20:15:11 -0800241 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
242 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mathieu Chartier90443472015-07-16 20:32:27 -0700243 bool IsReferenceInstance() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartierdfe02f62016-02-01 20:15:11 -0800244 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
245 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mathieu Chartier90443472015-07-16 20:32:27 -0700246 Reference* AsReference() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier8fa2dad2014-03-13 12:22:56 -0700247 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700248 bool IsWeakReferenceInstance() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800249 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700250 bool IsSoftReferenceInstance() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800251 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700252 bool IsFinalizerReferenceInstance() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800253 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700254 FinalizerReference* AsFinalizerReference() SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier8fa2dad2014-03-13 12:22:56 -0700255 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier90443472015-07-16 20:32:27 -0700256 bool IsPhantomReferenceInstance() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800257
Ian Rogersef7d42f2014-01-06 12:55:46 -0800258 // Accessor for Java type fields.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700259 template<class T, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700260 ReadBarrierOption kReadBarrierOption = kWithReadBarrier, bool kIsVolatile = false>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700261 ALWAYS_INLINE T* GetFieldObject(MemberOffset field_offset)
Mathieu Chartier90443472015-07-16 20:32:27 -0700262 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700263
264 template<class T, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700265 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700266 ALWAYS_INLINE T* GetFieldObjectVolatile(MemberOffset field_offset)
Mathieu Chartier90443472015-07-16 20:32:27 -0700267 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700268
269 template<bool kTransactionActive, bool kCheckTransaction = true,
270 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700271 ALWAYS_INLINE void SetFieldObjectWithoutWriteBarrier(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
274 template<bool kTransactionActive, bool kCheckTransaction = true,
275 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700276 ALWAYS_INLINE void SetFieldObject(MemberOffset field_offset, Object* new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700277 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700278
Mathieu Chartier4e305412014-02-19 10:54:44 -0800279 template<bool kTransactionActive, bool kCheckTransaction = true,
280 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700281 ALWAYS_INLINE void SetFieldObjectVolatile(MemberOffset field_offset, Object* new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700282 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700283
Mathieu Chartier4e305412014-02-19 10:54:44 -0800284 template<bool kTransactionActive, bool kCheckTransaction = true,
285 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogers228602f2014-07-10 02:07:54 -0700286 bool CasFieldWeakSequentiallyConsistentObject(MemberOffset field_offset, Object* old_value,
287 Object* new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700288 SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800289 template<bool kTransactionActive, bool kCheckTransaction = true,
290 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
291 bool CasFieldWeakSequentiallyConsistentObjectWithoutWriteBarrier(MemberOffset field_offset,
292 Object* old_value,
293 Object* new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700294 SHARED_REQUIRES(Locks::mutator_lock_);
Hans Boehmd8434432014-07-11 09:56:07 -0700295 template<bool kTransactionActive, bool kCheckTransaction = true,
296 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
297 bool CasFieldStrongSequentiallyConsistentObject(MemberOffset field_offset, Object* old_value,
298 Object* new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700299 SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800300 template<bool kTransactionActive, bool kCheckTransaction = true,
301 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
302 bool CasFieldStrongSequentiallyConsistentObjectWithoutWriteBarrier(MemberOffset field_offset,
303 Object* old_value,
304 Object* new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700305 SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchifed3e2f2015-10-20 11:11:56 -0700306 template<bool kTransactionActive, bool kCheckTransaction = true,
307 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
308 bool CasFieldWeakRelaxedObjectWithoutWriteBarrier(MemberOffset field_offset,
309 Object* old_value,
310 Object* new_value)
311 SHARED_REQUIRES(Locks::mutator_lock_);
312 template<bool kTransactionActive, bool kCheckTransaction = true,
313 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
314 bool CasFieldStrongRelaxedObjectWithoutWriteBarrier(MemberOffset field_offset,
315 Object* old_value,
316 Object* new_value)
317 SHARED_REQUIRES(Locks::mutator_lock_);
Hans Boehmd8434432014-07-11 09:56:07 -0700318
Mathieu Chartier4e305412014-02-19 10:54:44 -0800319 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
320 HeapReference<Object>* GetFieldObjectReferenceAddr(MemberOffset field_offset);
Mathieu Chartier11409ae2013-09-23 11:49:36 -0700321
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700322 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
Fred Shih37f05ef2014-07-16 18:38:08 -0700323 ALWAYS_INLINE uint8_t GetFieldBoolean(MemberOffset field_offset)
Mathieu Chartier90443472015-07-16 20:32:27 -0700324 SHARED_REQUIRES(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700325
326 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
327 ALWAYS_INLINE int8_t GetFieldByte(MemberOffset field_offset)
Mathieu Chartier90443472015-07-16 20:32:27 -0700328 SHARED_REQUIRES(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700329
330 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
331 ALWAYS_INLINE uint8_t GetFieldBooleanVolatile(MemberOffset field_offset)
Mathieu Chartier90443472015-07-16 20:32:27 -0700332 SHARED_REQUIRES(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700333
334 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
335 ALWAYS_INLINE int8_t GetFieldByteVolatile(MemberOffset field_offset)
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, bool kIsVolatile = false>
340 ALWAYS_INLINE void SetFieldBoolean(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, bool kIsVolatile = false>
345 ALWAYS_INLINE void SetFieldByte(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<bool kTransactionActive, bool kCheckTransaction = true,
349 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
350 ALWAYS_INLINE void SetFieldBooleanVolatile(MemberOffset field_offset, uint8_t new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700351 SHARED_REQUIRES(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700352
353 template<bool kTransactionActive, bool kCheckTransaction = true,
354 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
355 ALWAYS_INLINE void SetFieldByteVolatile(MemberOffset field_offset, int8_t new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700356 SHARED_REQUIRES(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700357
358 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
359 ALWAYS_INLINE uint16_t GetFieldChar(MemberOffset field_offset)
Mathieu Chartier90443472015-07-16 20:32:27 -0700360 SHARED_REQUIRES(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700361
362 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
363 ALWAYS_INLINE int16_t GetFieldShort(MemberOffset field_offset)
Mathieu Chartier90443472015-07-16 20:32:27 -0700364 SHARED_REQUIRES(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700365
366 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
367 ALWAYS_INLINE uint16_t GetFieldCharVolatile(MemberOffset field_offset)
Mathieu Chartier90443472015-07-16 20:32:27 -0700368 SHARED_REQUIRES(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700369
370 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
371 ALWAYS_INLINE int16_t GetFieldShortVolatile(MemberOffset field_offset)
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, bool kIsVolatile = false>
376 ALWAYS_INLINE void SetFieldChar(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, bool kIsVolatile = false>
381 ALWAYS_INLINE void SetFieldShort(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<bool kTransactionActive, bool kCheckTransaction = true,
385 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
386 ALWAYS_INLINE void SetFieldCharVolatile(MemberOffset field_offset, uint16_t new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700387 SHARED_REQUIRES(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700388
389 template<bool kTransactionActive, bool kCheckTransaction = true,
390 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
391 ALWAYS_INLINE void SetFieldShortVolatile(MemberOffset field_offset, int16_t new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700392 SHARED_REQUIRES(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700393
394 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700395 ALWAYS_INLINE int32_t GetField32(MemberOffset field_offset)
Mathieu Chartier90443472015-07-16 20:32:27 -0700396 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700397
Mathieu Chartier4e305412014-02-19 10:54:44 -0800398 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700399 ALWAYS_INLINE int32_t GetField32Volatile(MemberOffset field_offset)
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, bool kIsVolatile = false>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700404 ALWAYS_INLINE void SetField32(MemberOffset field_offset, int32_t new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700405 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700406
Mathieu Chartier4e305412014-02-19 10:54:44 -0800407 template<bool kTransactionActive, bool kCheckTransaction = true,
408 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700409 ALWAYS_INLINE void SetField32Volatile(MemberOffset field_offset, int32_t new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700410 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700411
412 template<bool kTransactionActive, bool kCheckTransaction = true,
413 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700414 ALWAYS_INLINE bool CasFieldWeakSequentiallyConsistent32(MemberOffset field_offset,
415 int32_t old_value, int32_t new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700416 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700417
Hans Boehmd8434432014-07-11 09:56:07 -0700418 template<bool kTransactionActive, bool kCheckTransaction = true,
419 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
420 bool CasFieldWeakRelaxed32(MemberOffset field_offset, int32_t old_value,
421 int32_t new_value) ALWAYS_INLINE
Mathieu Chartier90443472015-07-16 20:32:27 -0700422 SHARED_REQUIRES(Locks::mutator_lock_);
Hans Boehmd8434432014-07-11 09:56:07 -0700423
424 template<bool kTransactionActive, bool kCheckTransaction = true,
425 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Hiroshi Yamauchifed3e2f2015-10-20 11:11:56 -0700426 bool CasFieldWeakRelease32(MemberOffset field_offset, int32_t old_value,
427 int32_t new_value) ALWAYS_INLINE
428 SHARED_REQUIRES(Locks::mutator_lock_);
429
430 template<bool kTransactionActive, bool kCheckTransaction = true,
431 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Hans Boehmd8434432014-07-11 09:56:07 -0700432 bool CasFieldStrongSequentiallyConsistent32(MemberOffset field_offset, int32_t old_value,
433 int32_t new_value) ALWAYS_INLINE
Mathieu Chartier90443472015-07-16 20:32:27 -0700434 SHARED_REQUIRES(Locks::mutator_lock_);
Hans Boehmd8434432014-07-11 09:56:07 -0700435
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700436 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700437 ALWAYS_INLINE int64_t GetField64(MemberOffset field_offset)
Mathieu Chartier90443472015-07-16 20:32:27 -0700438 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700439
440 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700441 ALWAYS_INLINE int64_t GetField64Volatile(MemberOffset field_offset)
Mathieu Chartier90443472015-07-16 20:32:27 -0700442 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700443
444 template<bool kTransactionActive, bool kCheckTransaction = true,
445 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700446 ALWAYS_INLINE void SetField64(MemberOffset field_offset, int64_t new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700447 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700448
449 template<bool kTransactionActive, bool kCheckTransaction = true,
450 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700451 ALWAYS_INLINE void SetField64Volatile(MemberOffset field_offset, int64_t new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700452 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800453
Mathieu Chartier4e305412014-02-19 10:54:44 -0800454 template<bool kTransactionActive, bool kCheckTransaction = true,
455 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogers228602f2014-07-10 02:07:54 -0700456 bool CasFieldWeakSequentiallyConsistent64(MemberOffset field_offset, int64_t old_value,
457 int64_t new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700458 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800459
Mathieu Chartier4e305412014-02-19 10:54:44 -0800460 template<bool kTransactionActive, bool kCheckTransaction = true,
Hans Boehmd8434432014-07-11 09:56:07 -0700461 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
462 bool CasFieldStrongSequentiallyConsistent64(MemberOffset field_offset, int64_t old_value,
463 int64_t new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700464 SHARED_REQUIRES(Locks::mutator_lock_);
Hans Boehmd8434432014-07-11 09:56:07 -0700465
466 template<bool kTransactionActive, bool kCheckTransaction = true,
Mathieu Chartier4e305412014-02-19 10:54:44 -0800467 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, typename T>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700468 void SetFieldPtr(MemberOffset field_offset, T new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700469 SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800470 SetFieldPtrWithSize<kTransactionActive, kCheckTransaction, kVerifyFlags>(
471 field_offset, new_value, sizeof(void*));
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800472 }
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800473 template<bool kTransactionActive, bool kCheckTransaction = true,
474 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, typename T>
475 void SetFieldPtr64(MemberOffset field_offset, T new_value)
476 SHARED_REQUIRES(Locks::mutator_lock_) {
477 SetFieldPtrWithSize<kTransactionActive, kCheckTransaction, kVerifyFlags>(
478 field_offset, new_value, 8u);
479 }
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800480
Mathieu Chartier2d721012014-11-10 11:08:06 -0800481 template<bool kTransactionActive, bool kCheckTransaction = true,
482 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, typename T>
483 ALWAYS_INLINE void SetFieldPtrWithSize(MemberOffset field_offset, T new_value,
484 size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700485 SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800486 DCHECK(pointer_size == 4 || pointer_size == 8) << pointer_size;
487 if (pointer_size == 4) {
488 intptr_t ptr = reinterpret_cast<intptr_t>(new_value);
489 DCHECK_EQ(static_cast<int32_t>(ptr), ptr); // Check that we dont lose any non 0 bits.
490 SetField32<kTransactionActive, kCheckTransaction, kVerifyFlags>(
491 field_offset, static_cast<int32_t>(ptr));
492 } else {
493 SetField64<kTransactionActive, kCheckTransaction, kVerifyFlags>(
Vladimir Markodb8e62d2016-03-30 16:30:21 +0100494 field_offset, reinterpret_cast64<int64_t>(new_value));
Mathieu Chartier2d721012014-11-10 11:08:06 -0800495 }
496 }
Mathieu Chartier407f7022014-02-18 14:37:05 -0800497 // TODO fix thread safety analysis broken by the use of template. This should be
Mathieu Chartier90443472015-07-16 20:32:27 -0700498 // SHARED_REQUIRES(Locks::mutator_lock_).
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800499 template <bool kVisitNativeRoots = true,
500 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
501 ReadBarrierOption kReadBarrierOption = kWithReadBarrier,
Mathieu Chartier059ef3d2015-08-18 13:54:21 -0700502 typename Visitor,
503 typename JavaLangRefVisitor = VoidFunctor>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700504 void VisitReferences(const Visitor& visitor, const JavaLangRefVisitor& ref_visitor)
Mathieu Chartier407f7022014-02-18 14:37:05 -0800505 NO_THREAD_SAFETY_ANALYSIS;
506
Mathieu Chartier90443472015-07-16 20:32:27 -0700507 ArtField* FindFieldByOffset(MemberOffset offset) SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchieb2baaf2015-05-13 21:14:22 -0700508
tony.ys_liu7380c312015-01-16 19:16:45 +0800509 // Used by object_test.
510 static void SetHashCodeSeed(uint32_t new_seed);
511 // Generate an identity hash code. Public for object test.
512 static uint32_t GenerateIdentityHashCode();
513
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800514 protected:
515 // Accessors for non-Java type fields
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700516 template<class T, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
517 T GetFieldPtr(MemberOffset field_offset)
Mathieu Chartier90443472015-07-16 20:32:27 -0700518 SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800519 return GetFieldPtrWithSize<T, kVerifyFlags, kIsVolatile>(field_offset, sizeof(void*));
520 }
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800521 template<class T, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
522 T GetFieldPtr64(MemberOffset field_offset)
523 SHARED_REQUIRES(Locks::mutator_lock_) {
524 return GetFieldPtrWithSize<T, kVerifyFlags, kIsVolatile>(field_offset, 8u);
525 }
Mathieu Chartier2d721012014-11-10 11:08:06 -0800526
527 template<class T, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
528 ALWAYS_INLINE T GetFieldPtrWithSize(MemberOffset field_offset, size_t pointer_size)
Mathieu Chartier90443472015-07-16 20:32:27 -0700529 SHARED_REQUIRES(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800530 DCHECK(pointer_size == 4 || pointer_size == 8) << pointer_size;
531 if (pointer_size == 4) {
532 return reinterpret_cast<T>(GetField32<kVerifyFlags, kIsVolatile>(field_offset));
533 } else {
534 int64_t v = GetField64<kVerifyFlags, kIsVolatile>(field_offset);
Vladimir Markodb8e62d2016-03-30 16:30:21 +0100535 return reinterpret_cast64<T>(v);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800536 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800537 }
538
Mathieu Chartier407f7022014-02-18 14:37:05 -0800539 // TODO: Fixme when anotatalysis works with visitors.
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800540 template<bool kIsStatic,
541 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
542 ReadBarrierOption kReadBarrierOption = kWithReadBarrier,
543 typename Visitor>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700544 void VisitFieldsReferences(uint32_t ref_offsets, const Visitor& visitor) HOT_ATTR
Mathieu Chartier407f7022014-02-18 14:37:05 -0800545 NO_THREAD_SAFETY_ANALYSIS;
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800546 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
547 ReadBarrierOption kReadBarrierOption = kWithReadBarrier,
548 typename Visitor>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700549 void VisitInstanceFieldsReferences(mirror::Class* klass, const Visitor& visitor) HOT_ATTR
Mathieu Chartier90443472015-07-16 20:32:27 -0700550 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800551 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
552 ReadBarrierOption kReadBarrierOption = kWithReadBarrier,
553 typename Visitor>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700554 void VisitStaticFieldsReferences(mirror::Class* klass, const Visitor& visitor) HOT_ATTR
Mathieu Chartier90443472015-07-16 20:32:27 -0700555 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier407f7022014-02-18 14:37:05 -0800556
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800557 private:
Fred Shih37f05ef2014-07-16 18:38:08 -0700558 template<typename kSize, bool kIsVolatile>
559 ALWAYS_INLINE void SetField(MemberOffset field_offset, kSize new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700560 SHARED_REQUIRES(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700561 template<typename kSize, bool kIsVolatile>
562 ALWAYS_INLINE kSize GetField(MemberOffset field_offset)
Mathieu Chartier90443472015-07-16 20:32:27 -0700563 SHARED_REQUIRES(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700564
Ian Rogers04d7aa92013-03-16 14:29:17 -0700565 // Verify the type correctness of stores to fields.
Mathieu Chartier61c5ebc2014-06-05 17:42:53 -0700566 // TODO: This can cause thread suspension and isn't moving GC safe.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800567 void CheckFieldAssignmentImpl(MemberOffset field_offset, Object* new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700568 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800569 void CheckFieldAssignment(MemberOffset field_offset, Object* new_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700570 SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers04d7aa92013-03-16 14:29:17 -0700571 if (kCheckFieldAssignments) {
572 CheckFieldAssignmentImpl(field_offset, new_value);
573 }
574 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800575
Hiroshi Yamauchi0fbd6e62014-07-17 16:16:31 -0700576 // A utility function that copies an object in a read barrier and
577 // write barrier-aware way. This is internally used by Clone() and
578 // Class::CopyOf().
579 static Object* CopyObject(Thread* self, mirror::Object* dest, mirror::Object* src,
580 size_t num_bytes)
Mathieu Chartier90443472015-07-16 20:32:27 -0700581 SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchi0fbd6e62014-07-17 16:16:31 -0700582
tony.ys_liu7380c312015-01-16 19:16:45 +0800583 static Atomic<uint32_t> hash_code_seed;
584
Ian Rogersef7d42f2014-01-06 12:55:46 -0800585 // The Class representing the type of the object.
586 HeapReference<Class> klass_;
587 // Monitor and hash code information.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800588 uint32_t monitor_;
589
Hiroshi Yamauchi60f63f52015-04-23 16:12:40 -0700590#ifdef USE_BROOKS_READ_BARRIER
Hiroshi Yamauchi624468c2014-03-31 15:14:47 -0700591 // Note names use a 'x' prefix and the x_rb_ptr_ is of type int
Hiroshi Yamauchi9d04a202014-01-31 13:35:49 -0800592 // instead of Object to go with the alphabetical/by-type field order
593 // on the Java side.
Hiroshi Yamauchi60f63f52015-04-23 16:12:40 -0700594 uint32_t x_rb_ptr_; // For the Brooks pointer.
Hiroshi Yamauchi624468c2014-03-31 15:14:47 -0700595 uint32_t x_xpadding_; // For 8-byte alignment. TODO: get rid of this.
Hiroshi Yamauchi9d04a202014-01-31 13:35:49 -0800596#endif
597
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800598 friend class art::ImageWriter;
Mathieu Chartierad2541a2013-10-25 10:05:23 -0700599 friend class art::Monitor;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800600 friend struct art::ObjectOffsets; // for verifying offset information
Hiroshi Yamauchi0fbd6e62014-07-17 16:16:31 -0700601 friend class CopyObjectVisitor; // for CopyObject().
602 friend class CopyClassVisitor; // for CopyObject().
Ian Rogerscf7f1912014-10-22 22:06:39 -0700603 DISALLOW_ALLOCATION();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800604 DISALLOW_IMPLICIT_CONSTRUCTORS(Object);
605};
606
607} // namespace mirror
608} // namespace art
609
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700610#endif // ART_RUNTIME_MIRROR_OBJECT_H_