Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 1 | /* |
| 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 Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 17 | #ifndef ART_RUNTIME_MIRROR_OBJECT_H_ |
| 18 | #define ART_RUNTIME_MIRROR_OBJECT_H_ |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 19 | |
| 20 | #include "base/casts.h" |
| 21 | #include "base/logging.h" |
| 22 | #include "base/macros.h" |
| 23 | #include "cutils/atomic-inline.h" |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 24 | #include "object_reference.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 25 | #include "offsets.h" |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 26 | #include "runtime.h" |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 27 | #include "verify_object.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 28 | |
| 29 | namespace art { |
| 30 | |
| 31 | class ImageWriter; |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 32 | class LockWord; |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 33 | class Monitor; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 34 | struct ObjectOffsets; |
| 35 | class Thread; |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 36 | template <typename T> class SirtRef; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 37 | |
| 38 | namespace mirror { |
| 39 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 40 | class ArtField; |
| 41 | class ArtMethod; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 42 | class Array; |
| 43 | class Class; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 44 | template<class T> class ObjectArray; |
| 45 | template<class T> class PrimitiveArray; |
| 46 | typedef PrimitiveArray<uint8_t> BooleanArray; |
| 47 | typedef PrimitiveArray<int8_t> ByteArray; |
| 48 | typedef PrimitiveArray<uint16_t> CharArray; |
| 49 | typedef PrimitiveArray<double> DoubleArray; |
| 50 | typedef PrimitiveArray<float> FloatArray; |
| 51 | typedef PrimitiveArray<int32_t> IntArray; |
| 52 | typedef PrimitiveArray<int64_t> LongArray; |
| 53 | typedef PrimitiveArray<int16_t> ShortArray; |
| 54 | class String; |
| 55 | class Throwable; |
| 56 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 57 | // 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 Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 63 | // Checks that we don't do field assignments which violate the typing system. |
| 64 | static constexpr bool kCheckFieldAssignments = false; |
Ian Rogers | 04d7aa9 | 2013-03-16 14:29:17 -0700 | [diff] [blame] | 65 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 66 | // C++ mirror of java.lang.Object |
| 67 | class MANAGED Object { |
| 68 | public: |
| 69 | static MemberOffset ClassOffset() { |
| 70 | return OFFSET_OF_OBJECT_MEMBER(Object, klass_); |
| 71 | } |
| 72 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 73 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 74 | Class* GetClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 75 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 76 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 77 | void SetClass(Class* new_klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 78 | |
Hiroshi Yamauchi | 9d04a20 | 2014-01-31 13:35:49 -0800 | [diff] [blame^] | 79 | 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 Hao | a3faaf4 | 2013-09-03 19:07:00 -0700 | [diff] [blame] | 83 | // The verifier treats all interfaces as java.lang.Object and relies on runtime checks in |
| 84 | // invoke-interface to detect incompatible interface types. |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 85 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 86 | bool VerifierInstanceOf(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 87 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 88 | bool InstanceOf(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 89 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 90 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 91 | size_t SizeOf() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 92 | |
| 93 | Object* Clone(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 94 | |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 95 | int32_t IdentityHashCode() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 96 | |
| 97 | static MemberOffset MonitorOffset() { |
| 98 | return OFFSET_OF_OBJECT_MEMBER(Object, monitor_); |
| 99 | } |
| 100 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 101 | LockWord GetLockWord(); |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 102 | void SetLockWord(LockWord new_val); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 103 | bool CasLockWord(LockWord old_val, LockWord new_val) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 104 | uint32_t GetLockOwnerThreadId(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 105 | |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 106 | mirror::Object* MonitorEnter(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 107 | EXCLUSIVE_LOCK_FUNCTION(monitor_lock_); |
Ian Rogers | 05f3057 | 2013-02-20 12:13:11 -0800 | [diff] [blame] | 108 | bool MonitorExit(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 109 | UNLOCK_FUNCTION(monitor_lock_); |
Ian Rogers | 05f3057 | 2013-02-20 12:13:11 -0800 | [diff] [blame] | 110 | void Notify(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 05f3057 | 2013-02-20 12:13:11 -0800 | [diff] [blame] | 111 | void NotifyAll(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 05f3057 | 2013-02-20 12:13:11 -0800 | [diff] [blame] | 112 | void Wait(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 05f3057 | 2013-02-20 12:13:11 -0800 | [diff] [blame] | 113 | void Wait(Thread* self, int64_t timeout, int32_t nanos) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 114 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 115 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 116 | bool IsClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 117 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 118 | Class* AsClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 119 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 120 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 121 | bool IsObjectArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 122 | template<class T, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 123 | ObjectArray<T>* AsObjectArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 124 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 125 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 126 | bool IsArrayInstance() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 127 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 128 | Array* AsArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 129 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 130 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 131 | BooleanArray* AsBooleanArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 132 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 133 | ByteArray* AsByteArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 134 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 135 | ByteArray* AsByteSizedArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 136 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 137 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 138 | CharArray* AsCharArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 139 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 140 | ShortArray* AsShortArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 141 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 142 | ShortArray* AsShortSizedArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 143 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 144 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 145 | IntArray* AsIntArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 146 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 147 | LongArray* AsLongArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 148 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 149 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 150 | FloatArray* AsFloatArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 151 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 152 | DoubleArray* AsDoubleArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 153 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 154 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 155 | String* AsString() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 156 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 157 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 158 | Throwable* AsThrowable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 159 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 160 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 161 | bool IsArtMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 162 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 163 | ArtMethod* AsArtMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 164 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 165 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 166 | bool IsArtField() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 167 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 168 | ArtField* AsArtField() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 169 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 170 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 171 | bool IsReferenceInstance() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 172 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 173 | bool IsWeakReferenceInstance() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 174 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 175 | bool IsSoftReferenceInstance() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 176 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 177 | bool IsFinalizerReferenceInstance() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 178 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 179 | bool IsPhantomReferenceInstance() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 180 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 181 | // Accessor for Java type fields. |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 182 | template<class T, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
| 183 | T* GetFieldObject(MemberOffset field_offset, bool is_volatile) |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 184 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 185 | template<bool kTransactionActive, bool kCheckTransaction = true, |
| 186 | VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 187 | void SetFieldObjectWithoutWriteBarrier(MemberOffset field_offset, Object* new_value, |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 188 | bool is_volatile) |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 189 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 190 | template<bool kTransactionActive, bool kCheckTransaction = true, |
| 191 | VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
| 192 | void SetFieldObject(MemberOffset field_offset, Object* new_value, bool is_volatile) |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 193 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 194 | template<bool kTransactionActive, bool kCheckTransaction = true, |
| 195 | VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 196 | bool CasFieldObject(MemberOffset field_offset, Object* old_value, Object* new_value) |
| 197 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 198 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 199 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
| 200 | HeapReference<Object>* GetFieldObjectReferenceAddr(MemberOffset field_offset); |
Mathieu Chartier | 11409ae | 2013-09-23 11:49:36 -0700 | [diff] [blame] | 201 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 202 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
| 203 | int32_t GetField32(MemberOffset field_offset, bool is_volatile) |
| 204 | NO_THREAD_SAFETY_ANALYSIS; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 205 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 206 | 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 Rogers | 29501cf | 2014-02-07 21:00:25 -0800 | [diff] [blame] | 211 | bool CasField32(MemberOffset field_offset, int32_t old_value, int32_t new_value) |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 212 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 213 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 214 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | 29501cf | 2014-02-07 21:00:25 -0800 | [diff] [blame] | 215 | int64_t GetField64(MemberOffset field_offset, bool is_volatile); |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 216 | template<bool kTransactionActive, bool kCheckTransaction = true, |
| 217 | VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
| 218 | void SetField64(MemberOffset field_offset, int64_t new_value, bool is_volatile); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 219 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 220 | template<bool kTransactionActive, bool kCheckTransaction = true, |
| 221 | VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | 29501cf | 2014-02-07 21:00:25 -0800 | [diff] [blame] | 222 | bool CasField64(MemberOffset field_offset, int64_t old_value, int64_t new_value) |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 223 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 224 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 225 | 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 Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 228 | #ifndef __LP64__ |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 229 | SetField32<kTransactionActive, kCheckTransaction, kVerifyFlags>( |
| 230 | field_offset, reinterpret_cast<int32_t>(new_value), is_volatile); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 231 | #else |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 232 | SetField64<kTransactionActive, kCheckTransaction, kVerifyFlags>( |
| 233 | field_offset, reinterpret_cast<int64_t>(new_value), is_volatile); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 234 | #endif |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 235 | } |
| 236 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 237 | protected: |
| 238 | // Accessors for non-Java type fields |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 239 | template<class T, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
| 240 | T GetFieldPtr(MemberOffset field_offset, bool is_volatile) NO_THREAD_SAFETY_ANALYSIS { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 241 | #ifndef __LP64__ |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 242 | return reinterpret_cast<T>(GetField32<kVerifyFlags>(field_offset, is_volatile)); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 243 | #else |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 244 | return reinterpret_cast<T>(GetField64<kVerifyFlags>(field_offset, is_volatile)); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 245 | #endif |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 246 | } |
| 247 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 248 | private: |
Ian Rogers | 04d7aa9 | 2013-03-16 14:29:17 -0700 | [diff] [blame] | 249 | // Verify the type correctness of stores to fields. |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 250 | void CheckFieldAssignmentImpl(MemberOffset field_offset, Object* new_value) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 251 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 252 | void CheckFieldAssignment(MemberOffset field_offset, Object* new_value) |
Ian Rogers | 04d7aa9 | 2013-03-16 14:29:17 -0700 | [diff] [blame] | 253 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 254 | if (kCheckFieldAssignments) { |
| 255 | CheckFieldAssignmentImpl(field_offset, new_value); |
| 256 | } |
| 257 | } |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 258 | |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 259 | // Generate an identity hash code. |
Mathieu Chartier | 4e6a31e | 2013-10-31 10:35:05 -0700 | [diff] [blame] | 260 | static int32_t GenerateIdentityHashCode(); |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 261 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 262 | // The Class representing the type of the object. |
| 263 | HeapReference<Class> klass_; |
| 264 | // Monitor and hash code information. |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 265 | uint32_t monitor_; |
| 266 | |
Hiroshi Yamauchi | 9d04a20 | 2014-01-31 13:35:49 -0800 | [diff] [blame^] | 267 | #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 Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 275 | friend class art::ImageWriter; |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 276 | friend class art::Monitor; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 277 | friend struct art::ObjectOffsets; // for verifying offset information |
| 278 | DISALLOW_IMPLICIT_CONSTRUCTORS(Object); |
| 279 | }; |
| 280 | |
| 281 | } // namespace mirror |
| 282 | } // namespace art |
| 283 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 284 | #endif // ART_RUNTIME_MIRROR_OBJECT_H_ |