blob: 262cb57904844697aade2e2e651f88cc7027a320 [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"
Ian Rogersef7d42f2014-01-06 12:55:46 -080023#include "object_reference.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080024#include "offsets.h"
Mathieu Chartier4e305412014-02-19 10:54:44 -080025#include "verify_object.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080026
27namespace art {
28
Mathieu Chartierc7853442015-03-27 14:35:38 -070029class ArtField;
Mathieu Chartiere401d142015-04-22 13:56:20 -070030class ArtMethod;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080031class ImageWriter;
Ian Rogersd9c4fc92013-10-01 19:45:43 -070032class LockWord;
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070033class Monitor;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080034struct ObjectOffsets;
35class Thread;
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070036class VoidFunctor;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080037
38namespace mirror {
39
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080040class Array;
41class Class;
Mathieu Chartiere4275c02015-08-06 15:34:15 -070042class ClassLoader;
Vladimir Marko05792b92015-08-03 11:56:49 +010043class DexCache;
Mathieu Chartier8fa2dad2014-03-13 12:22:56 -070044class FinalizerReference;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080045template<class T> class ObjectArray;
46template<class T> class PrimitiveArray;
47typedef PrimitiveArray<uint8_t> BooleanArray;
48typedef PrimitiveArray<int8_t> ByteArray;
49typedef PrimitiveArray<uint16_t> CharArray;
50typedef PrimitiveArray<double> DoubleArray;
51typedef PrimitiveArray<float> FloatArray;
52typedef PrimitiveArray<int32_t> IntArray;
53typedef PrimitiveArray<int64_t> LongArray;
54typedef PrimitiveArray<int16_t> ShortArray;
Mathieu Chartier8fa2dad2014-03-13 12:22:56 -070055class Reference;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080056class String;
57class Throwable;
58
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080059// Fields within mirror objects aren't accessed directly so that the appropriate amount of
60// handshaking is done with GC (for example, read and write barriers). This macro is used to
61// compute an offset for the Set/Get methods defined in Object that can safely access fields.
62#define OFFSET_OF_OBJECT_MEMBER(type, field) \
63 MemberOffset(OFFSETOF_MEMBER(type, field))
64
Mathieu Chartier4e305412014-02-19 10:54:44 -080065// Checks that we don't do field assignments which violate the typing system.
66static constexpr bool kCheckFieldAssignments = false;
Ian Rogers04d7aa92013-03-16 14:29:17 -070067
Ian Rogerscdc1aaf2014-10-09 13:21:38 -070068// Size of Object.
Hiroshi Yamauchi60f63f52015-04-23 16:12:40 -070069static constexpr uint32_t kObjectHeaderSize = kUseBrooksReadBarrier ? 16 : 8;
Ian Rogerscdc1aaf2014-10-09 13:21:38 -070070
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080071// C++ mirror of java.lang.Object
Ian Rogers719d1a32014-03-06 12:13:39 -080072class MANAGED LOCKABLE Object {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080073 public:
Mingyao Yang98d1cc82014-05-15 17:02:16 -070074 // The number of vtable entries in java.lang.Object.
75 static constexpr size_t kVTableLength = 11;
76
77 // The size of the java.lang.Class representing a java.lang.Object.
Andreas Gampe542451c2016-07-26 09:02:02 -070078 static uint32_t ClassSize(PointerSize pointer_size);
Mingyao Yang98d1cc82014-05-15 17:02:16 -070079
80 // Size of an instance of java.lang.Object.
81 static constexpr uint32_t InstanceSize() {
82 return sizeof(Object);
83 }
84
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080085 static MemberOffset ClassOffset() {
86 return OFFSET_OF_OBJECT_MEMBER(Object, klass_);
87 }
88
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -070089 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
90 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070091 ALWAYS_INLINE Class* GetClass() REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080092
Mathieu Chartier4e305412014-02-19 10:54:44 -080093 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070094 void SetClass(Class* new_klass) REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080095
Mathieu Chartierc381c362016-08-23 13:27:53 -070096 // TODO: Clean these up and change to return int32_t
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070097 Object* GetReadBarrierPointer() REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchied70b4a2015-11-17 17:52:15 -080098
Mathieu Chartierc381c362016-08-23 13:27:53 -070099 // Get the read barrier pointer with release semantics, only supported for baker.
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700100 Object* GetReadBarrierPointerAcquire() REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartierc381c362016-08-23 13:27:53 -0700101
Andreas Gampe65b798e2015-04-06 09:35:22 -0700102#ifndef USE_BAKER_OR_BROOKS_READ_BARRIER
103 NO_RETURN
104#endif
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700105 void SetReadBarrierPointer(Object* rb_ptr) REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchied70b4a2015-11-17 17:52:15 -0800106
107 template<bool kCasRelease = false>
Hiroshi Yamauchi723e6ce2015-10-28 20:59:47 -0700108 ALWAYS_INLINE bool AtomicSetReadBarrierPointer(Object* expected_rb_ptr, Object* rb_ptr)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700109 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier36a270a2016-07-28 18:08:51 -0700110
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700111 ALWAYS_INLINE uint32_t GetMarkBit() REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier36a270a2016-07-28 18:08:51 -0700112
113 ALWAYS_INLINE bool AtomicSetMarkBit(uint32_t expected_mark_bit, uint32_t mark_bit)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700114 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier36a270a2016-07-28 18:08:51 -0700115
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700116 void AssertReadBarrierPointer() const REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchi9d04a202014-01-31 13:35:49 -0800117
Jeff Haoa3faaf42013-09-03 19:07:00 -0700118 // The verifier treats all interfaces as java.lang.Object and relies on runtime checks in
119 // invoke-interface to detect incompatible interface types.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800120 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700121 bool VerifierInstanceOf(Class* klass) REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800122 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700123 ALWAYS_INLINE bool InstanceOf(Class* klass) REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800124
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700125 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
126 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700127 size_t SizeOf() REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800128
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700129 Object* Clone(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartier4e2cb092015-07-22 16:17:51 -0700130 REQUIRES(!Roles::uninterruptible_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800131
Sebastien Hertz69206392015-04-07 15:54:25 +0200132 int32_t IdentityHashCode() const
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700133 REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartier90443472015-07-16 20:32:27 -0700134 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800135
136 static MemberOffset MonitorOffset() {
137 return OFFSET_OF_OBJECT_MEMBER(Object, monitor_);
138 }
139
Hans Boehmd8434432014-07-11 09:56:07 -0700140 // As_volatile can be false if the mutators are suspended. This is an optimization since it
Mathieu Chartier4d7f61d2014-04-17 14:43:39 -0700141 // avoids the barriers.
Andreas Gampe3b45ef22015-05-26 21:34:09 -0700142 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700143 LockWord GetLockWord(bool as_volatile) REQUIRES_SHARED(Locks::mutator_lock_);
Andreas Gampe3b45ef22015-05-26 21:34:09 -0700144 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700145 void SetLockWord(LockWord new_val, bool as_volatile) REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers228602f2014-07-10 02:07:54 -0700146 bool CasLockWordWeakSequentiallyConsistent(LockWord old_val, LockWord new_val)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700147 REQUIRES_SHARED(Locks::mutator_lock_);
Hans Boehmd8434432014-07-11 09:56:07 -0700148 bool CasLockWordWeakRelaxed(LockWord old_val, LockWord new_val)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700149 REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchifed3e2f2015-10-20 11:11:56 -0700150 bool CasLockWordWeakRelease(LockWord old_val, LockWord new_val)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700151 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700152 uint32_t GetLockOwnerThreadId();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800153
Mathieu Chartiera704eda2016-07-13 09:53:35 -0700154 // Try to enter the monitor, returns non null if we succeeded.
155 mirror::Object* MonitorTryEnter(Thread* self)
156 EXCLUSIVE_LOCK_FUNCTION()
157 REQUIRES(!Roles::uninterruptible_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700158 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier2d096c92015-10-12 16:18:20 -0700159 mirror::Object* MonitorEnter(Thread* self)
160 EXCLUSIVE_LOCK_FUNCTION()
161 REQUIRES(!Roles::uninterruptible_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700162 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier2d096c92015-10-12 16:18:20 -0700163 bool MonitorExit(Thread* self)
164 REQUIRES(!Roles::uninterruptible_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700165 REQUIRES_SHARED(Locks::mutator_lock_)
Ian Rogers719d1a32014-03-06 12:13:39 -0800166 UNLOCK_FUNCTION();
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700167 void Notify(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_);
168 void NotifyAll(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_);
169 void Wait(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_);
170 void Wait(Thread* self, int64_t timeout, int32_t nanos) REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800171
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700172 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
173 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700174 bool IsClass() REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700175 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
176 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700177 Class* AsClass() REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800178
Mathieu Chartierdfe02f62016-02-01 20:15:11 -0800179 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
180 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700181 bool IsObjectArray() REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartierdfe02f62016-02-01 20:15:11 -0800182 template<class T,
183 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
184 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700185 ObjectArray<T>* AsObjectArray() REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800186
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800187 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
188 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700189 bool IsClassLoader() REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800190 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
191 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700192 ClassLoader* AsClassLoader() REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartiere4275c02015-08-06 15:34:15 -0700193
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800194 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
195 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700196 bool IsDexCache() REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800197 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
198 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700199 DexCache* AsDexCache() REQUIRES_SHARED(Locks::mutator_lock_);
Vladimir Marko05792b92015-08-03 11:56:49 +0100200
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700201 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
202 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700203 bool IsArrayInstance() REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700204 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
205 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700206 Array* AsArray() REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800207
Mathieu Chartier4e305412014-02-19 10:54:44 -0800208 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700209 BooleanArray* AsBooleanArray() REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800210 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700211 ByteArray* AsByteArray() 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* AsByteSizedArray() REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800214
Mathieu Chartier4e305412014-02-19 10:54:44 -0800215 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700216 CharArray* AsCharArray() REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800217 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700218 ShortArray* AsShortArray() 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* AsShortSizedArray() REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800221
Mathieu Chartierdfe02f62016-02-01 20:15:11 -0800222 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
223 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700224 bool IsIntArray() REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartierdfe02f62016-02-01 20:15:11 -0800225 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
226 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700227 IntArray* AsIntArray() REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700228
Mathieu Chartierdfe02f62016-02-01 20:15:11 -0800229 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
230 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700231 bool IsLongArray() REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartierdfe02f62016-02-01 20:15:11 -0800232 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
233 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700234 LongArray* AsLongArray() REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800235
Mathieu Chartier4e305412014-02-19 10:54:44 -0800236 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700237 bool IsFloatArray() REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700238 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700239 FloatArray* AsFloatArray() REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700240
241 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700242 bool IsDoubleArray() REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800243 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700244 DoubleArray* AsDoubleArray() REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100245
Jeff Hao848f70a2014-01-15 13:49:50 -0800246 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
247 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700248 bool IsString() REQUIRES_SHARED(Locks::mutator_lock_);
Jeff Hao848f70a2014-01-15 13:49:50 -0800249
250 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
251 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700252 String* AsString() REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800253
Mathieu Chartier4e305412014-02-19 10:54:44 -0800254 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700255 Throwable* AsThrowable() REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800256
Mathieu Chartierdfe02f62016-02-01 20:15:11 -0800257 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
258 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700259 bool IsReferenceInstance() REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartierdfe02f62016-02-01 20:15:11 -0800260 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
261 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700262 Reference* AsReference() REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier8fa2dad2014-03-13 12:22:56 -0700263 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700264 bool IsWeakReferenceInstance() REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800265 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700266 bool IsSoftReferenceInstance() 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 IsFinalizerReferenceInstance() 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 FinalizerReference* AsFinalizerReference() REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier8fa2dad2014-03-13 12:22:56 -0700271 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700272 bool IsPhantomReferenceInstance() REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800273
Ian Rogersef7d42f2014-01-06 12:55:46 -0800274 // Accessor for Java type fields.
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700275 template<class T, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700276 ReadBarrierOption kReadBarrierOption = kWithReadBarrier, bool kIsVolatile = false>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700277 ALWAYS_INLINE T* GetFieldObject(MemberOffset field_offset)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700278 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700279
280 template<class T, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
Hiroshi Yamauchi6e83c172014-05-01 21:25:41 -0700281 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700282 ALWAYS_INLINE T* GetFieldObjectVolatile(MemberOffset field_offset)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700283 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700284
285 template<bool kTransactionActive, bool kCheckTransaction = true,
286 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700287 ALWAYS_INLINE void SetFieldObjectWithoutWriteBarrier(MemberOffset field_offset, Object* new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700288 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700289
290 template<bool kTransactionActive, bool kCheckTransaction = true,
291 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700292 ALWAYS_INLINE void SetFieldObject(MemberOffset field_offset, 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 Chartier4e305412014-02-19 10:54:44 -0800295 template<bool kTransactionActive, bool kCheckTransaction = true,
296 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700297 ALWAYS_INLINE void SetFieldObjectVolatile(MemberOffset field_offset, Object* new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700298 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700299
Mathieu Chartier4e305412014-02-19 10:54:44 -0800300 template<bool kTransactionActive, bool kCheckTransaction = true,
301 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogers228602f2014-07-10 02:07:54 -0700302 bool CasFieldWeakSequentiallyConsistentObject(MemberOffset field_offset, Object* old_value,
303 Object* new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700304 REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800305 template<bool kTransactionActive, bool kCheckTransaction = true,
306 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
307 bool CasFieldWeakSequentiallyConsistentObjectWithoutWriteBarrier(MemberOffset field_offset,
308 Object* old_value,
309 Object* new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700310 REQUIRES_SHARED(Locks::mutator_lock_);
Hans Boehmd8434432014-07-11 09:56:07 -0700311 template<bool kTransactionActive, bool kCheckTransaction = true,
312 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
313 bool CasFieldStrongSequentiallyConsistentObject(MemberOffset field_offset, Object* old_value,
314 Object* new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700315 REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchi2cd334a2015-01-09 14:03:35 -0800316 template<bool kTransactionActive, bool kCheckTransaction = true,
317 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
318 bool CasFieldStrongSequentiallyConsistentObjectWithoutWriteBarrier(MemberOffset field_offset,
319 Object* old_value,
320 Object* new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700321 REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchifed3e2f2015-10-20 11:11:56 -0700322 template<bool kTransactionActive, bool kCheckTransaction = true,
323 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
324 bool CasFieldWeakRelaxedObjectWithoutWriteBarrier(MemberOffset field_offset,
325 Object* old_value,
326 Object* new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700327 REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchifed3e2f2015-10-20 11:11:56 -0700328 template<bool kTransactionActive, bool kCheckTransaction = true,
329 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
330 bool CasFieldStrongRelaxedObjectWithoutWriteBarrier(MemberOffset field_offset,
331 Object* old_value,
332 Object* new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700333 REQUIRES_SHARED(Locks::mutator_lock_);
Hans Boehmd8434432014-07-11 09:56:07 -0700334
Mathieu Chartier4e305412014-02-19 10:54:44 -0800335 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
336 HeapReference<Object>* GetFieldObjectReferenceAddr(MemberOffset field_offset);
Mathieu Chartier11409ae2013-09-23 11:49:36 -0700337
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700338 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
Fred Shih37f05ef2014-07-16 18:38:08 -0700339 ALWAYS_INLINE uint8_t GetFieldBoolean(MemberOffset field_offset)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700340 REQUIRES_SHARED(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700341
342 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
343 ALWAYS_INLINE int8_t GetFieldByte(MemberOffset field_offset)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700344 REQUIRES_SHARED(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700345
346 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
347 ALWAYS_INLINE uint8_t GetFieldBooleanVolatile(MemberOffset field_offset)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700348 REQUIRES_SHARED(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700349
350 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
351 ALWAYS_INLINE int8_t GetFieldByteVolatile(MemberOffset field_offset)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700352 REQUIRES_SHARED(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700353
354 template<bool kTransactionActive, bool kCheckTransaction = true,
355 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
356 ALWAYS_INLINE void SetFieldBoolean(MemberOffset field_offset, uint8_t new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700357 REQUIRES_SHARED(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700358
359 template<bool kTransactionActive, bool kCheckTransaction = true,
360 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
361 ALWAYS_INLINE void SetFieldByte(MemberOffset field_offset, int8_t new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700362 REQUIRES_SHARED(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700363
364 template<bool kTransactionActive, bool kCheckTransaction = true,
365 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
366 ALWAYS_INLINE void SetFieldBooleanVolatile(MemberOffset field_offset, uint8_t new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700367 REQUIRES_SHARED(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700368
369 template<bool kTransactionActive, bool kCheckTransaction = true,
370 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
371 ALWAYS_INLINE void SetFieldByteVolatile(MemberOffset field_offset, int8_t new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700372 REQUIRES_SHARED(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700373
374 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
375 ALWAYS_INLINE uint16_t GetFieldChar(MemberOffset field_offset)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700376 REQUIRES_SHARED(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700377
378 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
379 ALWAYS_INLINE int16_t GetFieldShort(MemberOffset field_offset)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700380 REQUIRES_SHARED(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700381
382 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
383 ALWAYS_INLINE uint16_t GetFieldCharVolatile(MemberOffset field_offset)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700384 REQUIRES_SHARED(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700385
386 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
387 ALWAYS_INLINE int16_t GetFieldShortVolatile(MemberOffset field_offset)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700388 REQUIRES_SHARED(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700389
390 template<bool kTransactionActive, bool kCheckTransaction = true,
391 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
392 ALWAYS_INLINE void SetFieldChar(MemberOffset field_offset, uint16_t new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700393 REQUIRES_SHARED(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700394
395 template<bool kTransactionActive, bool kCheckTransaction = true,
396 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
397 ALWAYS_INLINE void SetFieldShort(MemberOffset field_offset, int16_t new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700398 REQUIRES_SHARED(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700399
400 template<bool kTransactionActive, bool kCheckTransaction = true,
401 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
402 ALWAYS_INLINE void SetFieldCharVolatile(MemberOffset field_offset, uint16_t new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700403 REQUIRES_SHARED(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700404
405 template<bool kTransactionActive, bool kCheckTransaction = true,
406 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
407 ALWAYS_INLINE void SetFieldShortVolatile(MemberOffset field_offset, int16_t new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700408 REQUIRES_SHARED(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700409
410 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700411 ALWAYS_INLINE int32_t GetField32(MemberOffset field_offset)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700412 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700413
Mathieu Chartier4e305412014-02-19 10:54:44 -0800414 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700415 ALWAYS_INLINE int32_t GetField32Volatile(MemberOffset field_offset)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700416 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700417
418 template<bool kTransactionActive, bool kCheckTransaction = true,
419 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700420 ALWAYS_INLINE void SetField32(MemberOffset field_offset, int32_t new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700421 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700422
Mathieu Chartier4e305412014-02-19 10:54:44 -0800423 template<bool kTransactionActive, bool kCheckTransaction = true,
424 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700425 ALWAYS_INLINE void SetField32Volatile(MemberOffset field_offset, int32_t new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700426 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700427
428 template<bool kTransactionActive, bool kCheckTransaction = true,
429 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700430 ALWAYS_INLINE bool CasFieldWeakSequentiallyConsistent32(MemberOffset field_offset,
431 int32_t old_value, int32_t new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700432 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700433
Hans Boehmd8434432014-07-11 09:56:07 -0700434 template<bool kTransactionActive, bool kCheckTransaction = true,
435 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
436 bool CasFieldWeakRelaxed32(MemberOffset field_offset, int32_t old_value,
437 int32_t new_value) ALWAYS_INLINE
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700438 REQUIRES_SHARED(Locks::mutator_lock_);
Hans Boehmd8434432014-07-11 09:56:07 -0700439
440 template<bool kTransactionActive, bool kCheckTransaction = true,
441 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Hiroshi Yamauchifed3e2f2015-10-20 11:11:56 -0700442 bool CasFieldWeakRelease32(MemberOffset field_offset, int32_t old_value,
443 int32_t new_value) ALWAYS_INLINE
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700444 REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchifed3e2f2015-10-20 11:11:56 -0700445
446 template<bool kTransactionActive, bool kCheckTransaction = true,
447 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Hans Boehmd8434432014-07-11 09:56:07 -0700448 bool CasFieldStrongSequentiallyConsistent32(MemberOffset field_offset, int32_t old_value,
449 int32_t new_value) ALWAYS_INLINE
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700450 REQUIRES_SHARED(Locks::mutator_lock_);
Hans Boehmd8434432014-07-11 09:56:07 -0700451
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700452 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700453 ALWAYS_INLINE int64_t GetField64(MemberOffset field_offset)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700454 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700455
456 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700457 ALWAYS_INLINE int64_t GetField64Volatile(MemberOffset field_offset)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700458 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700459
460 template<bool kTransactionActive, bool kCheckTransaction = true,
461 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700462 ALWAYS_INLINE void SetField64(MemberOffset field_offset, int64_t new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700463 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700464
465 template<bool kTransactionActive, bool kCheckTransaction = true,
466 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700467 ALWAYS_INLINE void SetField64Volatile(MemberOffset field_offset, int64_t new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700468 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800469
Mathieu Chartier4e305412014-02-19 10:54:44 -0800470 template<bool kTransactionActive, bool kCheckTransaction = true,
471 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogers228602f2014-07-10 02:07:54 -0700472 bool CasFieldWeakSequentiallyConsistent64(MemberOffset field_offset, int64_t old_value,
473 int64_t new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700474 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800475
Mathieu Chartier4e305412014-02-19 10:54:44 -0800476 template<bool kTransactionActive, bool kCheckTransaction = true,
Hans Boehmd8434432014-07-11 09:56:07 -0700477 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
478 bool CasFieldStrongSequentiallyConsistent64(MemberOffset field_offset, int64_t old_value,
479 int64_t new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700480 REQUIRES_SHARED(Locks::mutator_lock_);
Hans Boehmd8434432014-07-11 09:56:07 -0700481
482 template<bool kTransactionActive, bool kCheckTransaction = true,
Mathieu Chartier4e305412014-02-19 10:54:44 -0800483 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, typename T>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700484 void SetFieldPtr(MemberOffset field_offset, T new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700485 REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800486 SetFieldPtrWithSize<kTransactionActive, kCheckTransaction, kVerifyFlags>(
Andreas Gampe542451c2016-07-26 09:02:02 -0700487 field_offset, new_value, kRuntimePointerSize);
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800488 }
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800489 template<bool kTransactionActive, bool kCheckTransaction = true,
490 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, typename T>
491 void SetFieldPtr64(MemberOffset field_offset, T new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700492 REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800493 SetFieldPtrWithSize<kTransactionActive, kCheckTransaction, kVerifyFlags>(
494 field_offset, new_value, 8u);
495 }
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800496
Mathieu Chartier2d721012014-11-10 11:08:06 -0800497 template<bool kTransactionActive, bool kCheckTransaction = true,
498 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, typename T>
Andreas Gampe542451c2016-07-26 09:02:02 -0700499 ALWAYS_INLINE void SetFieldPtrWithSize(MemberOffset field_offset,
500 T new_value,
501 PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700502 REQUIRES_SHARED(Locks::mutator_lock_) {
Andreas Gampe542451c2016-07-26 09:02:02 -0700503 if (pointer_size == PointerSize::k32) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800504 intptr_t ptr = reinterpret_cast<intptr_t>(new_value);
505 DCHECK_EQ(static_cast<int32_t>(ptr), ptr); // Check that we dont lose any non 0 bits.
506 SetField32<kTransactionActive, kCheckTransaction, kVerifyFlags>(
507 field_offset, static_cast<int32_t>(ptr));
508 } else {
509 SetField64<kTransactionActive, kCheckTransaction, kVerifyFlags>(
Vladimir Markodb8e62d2016-03-30 16:30:21 +0100510 field_offset, reinterpret_cast64<int64_t>(new_value));
Mathieu Chartier2d721012014-11-10 11:08:06 -0800511 }
512 }
Mathieu Chartier407f7022014-02-18 14:37:05 -0800513 // TODO fix thread safety analysis broken by the use of template. This should be
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700514 // REQUIRES_SHARED(Locks::mutator_lock_).
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800515 template <bool kVisitNativeRoots = true,
516 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
517 ReadBarrierOption kReadBarrierOption = kWithReadBarrier,
Mathieu Chartier059ef3d2015-08-18 13:54:21 -0700518 typename Visitor,
519 typename JavaLangRefVisitor = VoidFunctor>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700520 void VisitReferences(const Visitor& visitor, const JavaLangRefVisitor& ref_visitor)
Mathieu Chartier407f7022014-02-18 14:37:05 -0800521 NO_THREAD_SAFETY_ANALYSIS;
522
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700523 ArtField* FindFieldByOffset(MemberOffset offset) REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchieb2baaf2015-05-13 21:14:22 -0700524
tony.ys_liu7380c312015-01-16 19:16:45 +0800525 // Used by object_test.
526 static void SetHashCodeSeed(uint32_t new_seed);
527 // Generate an identity hash code. Public for object test.
528 static uint32_t GenerateIdentityHashCode();
529
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800530 protected:
531 // Accessors for non-Java type fields
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700532 template<class T, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
533 T GetFieldPtr(MemberOffset field_offset)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700534 REQUIRES_SHARED(Locks::mutator_lock_) {
Andreas Gampe542451c2016-07-26 09:02:02 -0700535 return GetFieldPtrWithSize<T, kVerifyFlags, kIsVolatile>(field_offset, kRuntimePointerSize);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800536 }
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800537 template<class T, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
538 T GetFieldPtr64(MemberOffset field_offset)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700539 REQUIRES_SHARED(Locks::mutator_lock_) {
Andreas Gampe542451c2016-07-26 09:02:02 -0700540 return GetFieldPtrWithSize<T, kVerifyFlags, kIsVolatile>(field_offset,
541 PointerSize::k64);
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800542 }
Mathieu Chartier2d721012014-11-10 11:08:06 -0800543
544 template<class T, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false>
Andreas Gampe542451c2016-07-26 09:02:02 -0700545 ALWAYS_INLINE T GetFieldPtrWithSize(MemberOffset field_offset, PointerSize pointer_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700546 REQUIRES_SHARED(Locks::mutator_lock_) {
Andreas Gampe542451c2016-07-26 09:02:02 -0700547 if (pointer_size == PointerSize::k32) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800548 return reinterpret_cast<T>(GetField32<kVerifyFlags, kIsVolatile>(field_offset));
549 } else {
550 int64_t v = GetField64<kVerifyFlags, kIsVolatile>(field_offset);
Vladimir Markodb8e62d2016-03-30 16:30:21 +0100551 return reinterpret_cast64<T>(v);
Mathieu Chartier2d721012014-11-10 11:08:06 -0800552 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800553 }
554
Mathieu Chartier407f7022014-02-18 14:37:05 -0800555 // TODO: Fixme when anotatalysis works with visitors.
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800556 template<bool kIsStatic,
557 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
558 ReadBarrierOption kReadBarrierOption = kWithReadBarrier,
559 typename Visitor>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700560 void VisitFieldsReferences(uint32_t ref_offsets, const Visitor& visitor) HOT_ATTR
Mathieu Chartier407f7022014-02-18 14:37:05 -0800561 NO_THREAD_SAFETY_ANALYSIS;
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800562 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
563 ReadBarrierOption kReadBarrierOption = kWithReadBarrier,
564 typename Visitor>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700565 void VisitInstanceFieldsReferences(mirror::Class* klass, const Visitor& visitor) HOT_ATTR
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700566 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800567 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
568 ReadBarrierOption kReadBarrierOption = kWithReadBarrier,
569 typename Visitor>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700570 void VisitStaticFieldsReferences(mirror::Class* klass, const Visitor& visitor) HOT_ATTR
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700571 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier407f7022014-02-18 14:37:05 -0800572
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800573 private:
Fred Shih37f05ef2014-07-16 18:38:08 -0700574 template<typename kSize, bool kIsVolatile>
575 ALWAYS_INLINE void SetField(MemberOffset field_offset, kSize new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700576 REQUIRES_SHARED(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700577 template<typename kSize, bool kIsVolatile>
578 ALWAYS_INLINE kSize GetField(MemberOffset field_offset)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700579 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartierc381c362016-08-23 13:27:53 -0700580 // Get a field with acquire semantics.
581 template<typename kSize>
582 ALWAYS_INLINE kSize GetFieldAcquire(MemberOffset field_offset)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700583 REQUIRES_SHARED(Locks::mutator_lock_);
Fred Shih37f05ef2014-07-16 18:38:08 -0700584
Ian Rogers04d7aa92013-03-16 14:29:17 -0700585 // Verify the type correctness of stores to fields.
Mathieu Chartier61c5ebc2014-06-05 17:42:53 -0700586 // TODO: This can cause thread suspension and isn't moving GC safe.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800587 void CheckFieldAssignmentImpl(MemberOffset field_offset, Object* new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700588 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800589 void CheckFieldAssignment(MemberOffset field_offset, Object* new_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700590 REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogers04d7aa92013-03-16 14:29:17 -0700591 if (kCheckFieldAssignments) {
592 CheckFieldAssignmentImpl(field_offset, new_value);
593 }
594 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800595
Hiroshi Yamauchi0fbd6e62014-07-17 16:16:31 -0700596 // A utility function that copies an object in a read barrier and
597 // write barrier-aware way. This is internally used by Clone() and
598 // Class::CopyOf().
599 static Object* CopyObject(Thread* self, mirror::Object* dest, mirror::Object* src,
600 size_t num_bytes)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700601 REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchi0fbd6e62014-07-17 16:16:31 -0700602
tony.ys_liu7380c312015-01-16 19:16:45 +0800603 static Atomic<uint32_t> hash_code_seed;
604
Ian Rogersef7d42f2014-01-06 12:55:46 -0800605 // The Class representing the type of the object.
606 HeapReference<Class> klass_;
607 // Monitor and hash code information.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800608 uint32_t monitor_;
609
Hiroshi Yamauchi60f63f52015-04-23 16:12:40 -0700610#ifdef USE_BROOKS_READ_BARRIER
Hiroshi Yamauchi624468c2014-03-31 15:14:47 -0700611 // Note names use a 'x' prefix and the x_rb_ptr_ is of type int
Hiroshi Yamauchi9d04a202014-01-31 13:35:49 -0800612 // instead of Object to go with the alphabetical/by-type field order
613 // on the Java side.
Hiroshi Yamauchi60f63f52015-04-23 16:12:40 -0700614 uint32_t x_rb_ptr_; // For the Brooks pointer.
Hiroshi Yamauchi624468c2014-03-31 15:14:47 -0700615 uint32_t x_xpadding_; // For 8-byte alignment. TODO: get rid of this.
Hiroshi Yamauchi9d04a202014-01-31 13:35:49 -0800616#endif
617
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800618 friend class art::ImageWriter;
Mathieu Chartierad2541a2013-10-25 10:05:23 -0700619 friend class art::Monitor;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800620 friend struct art::ObjectOffsets; // for verifying offset information
Hiroshi Yamauchi0fbd6e62014-07-17 16:16:31 -0700621 friend class CopyObjectVisitor; // for CopyObject().
622 friend class CopyClassVisitor; // for CopyObject().
Ian Rogerscf7f1912014-10-22 22:06:39 -0700623 DISALLOW_ALLOCATION();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800624 DISALLOW_IMPLICIT_CONSTRUCTORS(Object);
625};
626
627} // namespace mirror
628} // namespace art
629
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700630#endif // ART_RUNTIME_MIRROR_OBJECT_H_