blob: ded4e0ae7a7f3fb6887738121e141450a99d6667 [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
20#include "base/casts.h"
21#include "base/logging.h"
22#include "base/macros.h"
23#include "cutils/atomic-inline.h"
Ian Rogersef7d42f2014-01-06 12:55:46 -080024#include "object_reference.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080025#include "offsets.h"
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010026#include "runtime.h"
Mathieu Chartier4e305412014-02-19 10:54:44 -080027#include "verify_object.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080028
29namespace art {
30
31class ImageWriter;
Ian Rogersd9c4fc92013-10-01 19:45:43 -070032class LockWord;
Mathieu Chartierad2541a2013-10-25 10:05:23 -070033class Monitor;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080034struct ObjectOffsets;
35class Thread;
Mathieu Chartier590fee92013-09-13 13:46:47 -070036template <typename T> class SirtRef;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080037
38namespace mirror {
39
Brian Carlstromea46f952013-07-30 01:26:50 -070040class ArtField;
41class ArtMethod;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080042class Array;
43class Class;
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;
54class String;
55class Throwable;
56
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080057// Fields within mirror objects aren't accessed directly so that the appropriate amount of
58// handshaking is done with GC (for example, read and write barriers). This macro is used to
59// compute an offset for the Set/Get methods defined in Object that can safely access fields.
60#define OFFSET_OF_OBJECT_MEMBER(type, field) \
61 MemberOffset(OFFSETOF_MEMBER(type, field))
62
Mathieu Chartier4e305412014-02-19 10:54:44 -080063// Checks that we don't do field assignments which violate the typing system.
64static constexpr bool kCheckFieldAssignments = false;
Ian Rogers04d7aa92013-03-16 14:29:17 -070065
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080066// C++ mirror of java.lang.Object
67class MANAGED Object {
68 public:
69 static MemberOffset ClassOffset() {
70 return OFFSET_OF_OBJECT_MEMBER(Object, klass_);
71 }
72
Mathieu Chartier4e305412014-02-19 10:54:44 -080073 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -080074 Class* GetClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080075
Mathieu Chartier4e305412014-02-19 10:54:44 -080076 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -080077 void SetClass(Class* new_klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080078
Hiroshi Yamauchi9d04a202014-01-31 13:35:49 -080079 Object* GetBrooksPointer() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
80 void SetBrooksPointer(Object* brooks_pointer) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
81 void AssertSelfBrooksPointer() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
82
Jeff Haoa3faaf42013-09-03 19:07:00 -070083 // The verifier treats all interfaces as java.lang.Object and relies on runtime checks in
84 // invoke-interface to detect incompatible interface types.
Mathieu Chartier4e305412014-02-19 10:54:44 -080085 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -080086 bool VerifierInstanceOf(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -080087 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -080088 bool InstanceOf(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080089
Mathieu Chartier4e305412014-02-19 10:54:44 -080090 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -080091 size_t SizeOf() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080092
93 Object* Clone(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
94
Mathieu Chartierad2541a2013-10-25 10:05:23 -070095 int32_t IdentityHashCode() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080096
97 static MemberOffset MonitorOffset() {
98 return OFFSET_OF_OBJECT_MEMBER(Object, monitor_);
99 }
100
Ian Rogersef7d42f2014-01-06 12:55:46 -0800101 LockWord GetLockWord();
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700102 void SetLockWord(LockWord new_val);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800103 bool CasLockWord(LockWord old_val, LockWord new_val) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700104 uint32_t GetLockOwnerThreadId();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800105
Mathieu Chartiere7e8a5f2014-02-14 16:59:41 -0800106 mirror::Object* MonitorEnter(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800107 EXCLUSIVE_LOCK_FUNCTION(monitor_lock_);
Ian Rogers05f30572013-02-20 12:13:11 -0800108 bool MonitorExit(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800109 UNLOCK_FUNCTION(monitor_lock_);
Ian Rogers05f30572013-02-20 12:13:11 -0800110 void Notify(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers05f30572013-02-20 12:13:11 -0800111 void NotifyAll(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers05f30572013-02-20 12:13:11 -0800112 void Wait(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers05f30572013-02-20 12:13:11 -0800113 void Wait(Thread* self, int64_t timeout, int32_t nanos) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800114
Mathieu Chartier4e305412014-02-19 10:54:44 -0800115 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800116 bool IsClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800117 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800118 Class* AsClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800119
Mathieu Chartier4e305412014-02-19 10:54:44 -0800120 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800121 bool IsObjectArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800122 template<class T, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800123 ObjectArray<T>* AsObjectArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800124
Mathieu Chartier4e305412014-02-19 10:54:44 -0800125 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800126 bool IsArrayInstance() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800127 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800128 Array* AsArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800129
Mathieu Chartier4e305412014-02-19 10:54:44 -0800130 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800131 BooleanArray* AsBooleanArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800132 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800133 ByteArray* AsByteArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800134 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800135 ByteArray* AsByteSizedArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800136
Mathieu Chartier4e305412014-02-19 10:54:44 -0800137 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800138 CharArray* AsCharArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800139 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800140 ShortArray* AsShortArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800141 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800142 ShortArray* AsShortSizedArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800143
Mathieu Chartier4e305412014-02-19 10:54:44 -0800144 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800145 IntArray* AsIntArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800146 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800147 LongArray* AsLongArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800148
Mathieu Chartier4e305412014-02-19 10:54:44 -0800149 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100150 FloatArray* AsFloatArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800151 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100152 DoubleArray* AsDoubleArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
153
Mathieu Chartier4e305412014-02-19 10:54:44 -0800154 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800155 String* AsString() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800156
Mathieu Chartier4e305412014-02-19 10:54:44 -0800157 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800158 Throwable* AsThrowable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
159
Mathieu Chartier4e305412014-02-19 10:54:44 -0800160 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800161 bool IsArtMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800162 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800163 ArtMethod* AsArtMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800164
Mathieu Chartier4e305412014-02-19 10:54:44 -0800165 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800166 bool IsArtField() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800167 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Brian Carlstromea46f952013-07-30 01:26:50 -0700168 ArtField* AsArtField() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800169
Mathieu Chartier4e305412014-02-19 10:54:44 -0800170 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800171 bool IsReferenceInstance() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800172 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800173 bool IsWeakReferenceInstance() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800174 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800175 bool IsSoftReferenceInstance() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800176 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800177 bool IsFinalizerReferenceInstance() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800178 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800179 bool IsPhantomReferenceInstance() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800180
Ian Rogersef7d42f2014-01-06 12:55:46 -0800181 // Accessor for Java type fields.
Mathieu Chartier4e305412014-02-19 10:54:44 -0800182 template<class T, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
183 T* GetFieldObject(MemberOffset field_offset, bool is_volatile)
Ian Rogersef7d42f2014-01-06 12:55:46 -0800184 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800185 template<bool kTransactionActive, bool kCheckTransaction = true,
186 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800187 void SetFieldObjectWithoutWriteBarrier(MemberOffset field_offset, Object* new_value,
Mathieu Chartier4e305412014-02-19 10:54:44 -0800188 bool is_volatile)
Ian Rogersef7d42f2014-01-06 12:55:46 -0800189 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800190 template<bool kTransactionActive, bool kCheckTransaction = true,
191 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
192 void SetFieldObject(MemberOffset field_offset, Object* new_value, bool is_volatile)
Ian Rogersef7d42f2014-01-06 12:55:46 -0800193 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800194 template<bool kTransactionActive, bool kCheckTransaction = true,
195 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800196 bool CasFieldObject(MemberOffset field_offset, Object* old_value, Object* new_value)
197 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800198
Mathieu Chartier4e305412014-02-19 10:54:44 -0800199 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
200 HeapReference<Object>* GetFieldObjectReferenceAddr(MemberOffset field_offset);
Mathieu Chartier11409ae2013-09-23 11:49:36 -0700201
Mathieu Chartier4e305412014-02-19 10:54:44 -0800202 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
203 int32_t GetField32(MemberOffset field_offset, bool is_volatile)
204 NO_THREAD_SAFETY_ANALYSIS;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800205
Mathieu Chartier4e305412014-02-19 10:54:44 -0800206 template<bool kTransactionActive, bool kCheckTransaction = true,
207 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
208 void SetField32(MemberOffset field_offset, int32_t new_value, bool is_volatile);
209 template<bool kTransactionActive, bool kCheckTransaction = true,
210 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogers29501cf2014-02-07 21:00:25 -0800211 bool CasField32(MemberOffset field_offset, int32_t old_value, int32_t new_value)
Ian Rogersef7d42f2014-01-06 12:55:46 -0800212 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700213
Mathieu Chartier4e305412014-02-19 10:54:44 -0800214 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogers29501cf2014-02-07 21:00:25 -0800215 int64_t GetField64(MemberOffset field_offset, bool is_volatile);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800216 template<bool kTransactionActive, bool kCheckTransaction = true,
217 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
218 void SetField64(MemberOffset field_offset, int64_t new_value, bool is_volatile);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800219
Mathieu Chartier4e305412014-02-19 10:54:44 -0800220 template<bool kTransactionActive, bool kCheckTransaction = true,
221 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogers29501cf2014-02-07 21:00:25 -0800222 bool CasField64(MemberOffset field_offset, int64_t old_value, int64_t new_value)
Ian Rogersef7d42f2014-01-06 12:55:46 -0800223 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800224
Mathieu Chartier4e305412014-02-19 10:54:44 -0800225 template<bool kTransactionActive, bool kCheckTransaction = true,
226 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, typename T>
227 void SetFieldPtr(MemberOffset field_offset, T new_value, bool is_volatile) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800228#ifndef __LP64__
Mathieu Chartier4e305412014-02-19 10:54:44 -0800229 SetField32<kTransactionActive, kCheckTransaction, kVerifyFlags>(
230 field_offset, reinterpret_cast<int32_t>(new_value), is_volatile);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800231#else
Mathieu Chartier4e305412014-02-19 10:54:44 -0800232 SetField64<kTransactionActive, kCheckTransaction, kVerifyFlags>(
233 field_offset, reinterpret_cast<int64_t>(new_value), is_volatile);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800234#endif
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800235 }
236
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800237 protected:
238 // Accessors for non-Java type fields
Mathieu Chartier4e305412014-02-19 10:54:44 -0800239 template<class T, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
240 T GetFieldPtr(MemberOffset field_offset, bool is_volatile) NO_THREAD_SAFETY_ANALYSIS {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800241#ifndef __LP64__
Mathieu Chartier4e305412014-02-19 10:54:44 -0800242 return reinterpret_cast<T>(GetField32<kVerifyFlags>(field_offset, is_volatile));
Ian Rogersef7d42f2014-01-06 12:55:46 -0800243#else
Mathieu Chartier4e305412014-02-19 10:54:44 -0800244 return reinterpret_cast<T>(GetField64<kVerifyFlags>(field_offset, is_volatile));
Ian Rogersef7d42f2014-01-06 12:55:46 -0800245#endif
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800246 }
247
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800248 private:
Ian Rogers04d7aa92013-03-16 14:29:17 -0700249 // Verify the type correctness of stores to fields.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800250 void CheckFieldAssignmentImpl(MemberOffset field_offset, Object* new_value)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800251 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800252 void CheckFieldAssignment(MemberOffset field_offset, Object* new_value)
Ian Rogers04d7aa92013-03-16 14:29:17 -0700253 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
254 if (kCheckFieldAssignments) {
255 CheckFieldAssignmentImpl(field_offset, new_value);
256 }
257 }
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800258
Mathieu Chartierad2541a2013-10-25 10:05:23 -0700259 // Generate an identity hash code.
Mathieu Chartier4e6a31e2013-10-31 10:35:05 -0700260 static int32_t GenerateIdentityHashCode();
Mathieu Chartierad2541a2013-10-25 10:05:23 -0700261
Ian Rogersef7d42f2014-01-06 12:55:46 -0800262 // The Class representing the type of the object.
263 HeapReference<Class> klass_;
264 // Monitor and hash code information.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800265 uint32_t monitor_;
266
Hiroshi Yamauchi9d04a202014-01-31 13:35:49 -0800267#ifdef USE_BROOKS_POINTER
268 // Note names use a 'x' prefix and the x_brooks_ptr_ is of type int
269 // instead of Object to go with the alphabetical/by-type field order
270 // on the Java side.
271 uint32_t x_brooks_ptr_; // For the Brooks pointer.
272 uint32_t x_padding_; // For 8-byte alignment. TODO: get rid of this.
273#endif
274
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800275 friend class art::ImageWriter;
Mathieu Chartierad2541a2013-10-25 10:05:23 -0700276 friend class art::Monitor;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800277 friend struct art::ObjectOffsets; // for verifying offset information
278 DISALLOW_IMPLICIT_CONSTRUCTORS(Object);
279};
280
281} // namespace mirror
282} // namespace art
283
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700284#endif // ART_RUNTIME_MIRROR_OBJECT_H_