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 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 20 | #include "object_reference.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 21 | #include "offsets.h" |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 22 | #include "verify_object.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 23 | |
| 24 | namespace art { |
| 25 | |
| 26 | class ImageWriter; |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 27 | class LockWord; |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 28 | class Monitor; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 29 | struct ObjectOffsets; |
| 30 | class Thread; |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 31 | class VoidFunctor; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 32 | |
| 33 | namespace mirror { |
| 34 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 35 | class ArtField; |
| 36 | class ArtMethod; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 37 | class Array; |
| 38 | class Class; |
Mathieu Chartier | 8fa2dad | 2014-03-13 12:22:56 -0700 | [diff] [blame] | 39 | class FinalizerReference; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 40 | template<class T> class ObjectArray; |
| 41 | template<class T> class PrimitiveArray; |
| 42 | typedef PrimitiveArray<uint8_t> BooleanArray; |
| 43 | typedef PrimitiveArray<int8_t> ByteArray; |
| 44 | typedef PrimitiveArray<uint16_t> CharArray; |
| 45 | typedef PrimitiveArray<double> DoubleArray; |
| 46 | typedef PrimitiveArray<float> FloatArray; |
| 47 | typedef PrimitiveArray<int32_t> IntArray; |
| 48 | typedef PrimitiveArray<int64_t> LongArray; |
| 49 | typedef PrimitiveArray<int16_t> ShortArray; |
Mathieu Chartier | 8fa2dad | 2014-03-13 12:22:56 -0700 | [diff] [blame] | 50 | class Reference; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 51 | class String; |
| 52 | class Throwable; |
| 53 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 54 | // Fields within mirror objects aren't accessed directly so that the appropriate amount of |
| 55 | // handshaking is done with GC (for example, read and write barriers). This macro is used to |
| 56 | // compute an offset for the Set/Get methods defined in Object that can safely access fields. |
| 57 | #define OFFSET_OF_OBJECT_MEMBER(type, field) \ |
| 58 | MemberOffset(OFFSETOF_MEMBER(type, field)) |
| 59 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 60 | // Checks that we don't do field assignments which violate the typing system. |
| 61 | static constexpr bool kCheckFieldAssignments = false; |
Ian Rogers | 04d7aa9 | 2013-03-16 14:29:17 -0700 | [diff] [blame] | 62 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 63 | // C++ mirror of java.lang.Object |
Ian Rogers | 719d1a3 | 2014-03-06 12:13:39 -0800 | [diff] [blame] | 64 | class MANAGED LOCKABLE Object { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 65 | public: |
| 66 | static MemberOffset ClassOffset() { |
| 67 | return OFFSET_OF_OBJECT_MEMBER(Object, klass_); |
| 68 | } |
| 69 | |
Hiroshi Yamauchi | 9103c86 | 2014-04-22 13:51:07 -0700 | [diff] [blame] | 70 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kDoReadBarrier = true> |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 71 | Class* GetClass() ALWAYS_INLINE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 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 | void SetClass(Class* new_klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 75 | |
Hiroshi Yamauchi | 624468c | 2014-03-31 15:14:47 -0700 | [diff] [blame] | 76 | Object* GetReadBarrierPointer() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Hiroshi Yamauchi | 9103c86 | 2014-04-22 13:51:07 -0700 | [diff] [blame] | 77 | void SetReadBarrierPointer(Object* rb_ptr) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 78 | bool AtomicSetReadBarrierPointer(Object* expected_rb_ptr, Object* rb_ptr) |
| 79 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Hiroshi Yamauchi | 624468c | 2014-03-31 15:14:47 -0700 | [diff] [blame] | 80 | void AssertReadBarrierPointer() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Hiroshi Yamauchi | 9d04a20 | 2014-01-31 13:35:49 -0800 | [diff] [blame] | 81 | |
Jeff Hao | a3faaf4 | 2013-09-03 19:07:00 -0700 | [diff] [blame] | 82 | // The verifier treats all interfaces as java.lang.Object and relies on runtime checks in |
| 83 | // invoke-interface to detect incompatible interface types. |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 84 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 85 | bool VerifierInstanceOf(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 86 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 87 | bool InstanceOf(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 88 | |
Hiroshi Yamauchi | 9103c86 | 2014-04-22 13:51:07 -0700 | [diff] [blame] | 89 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kDoReadBarrier = true> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 90 | size_t SizeOf() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 91 | |
| 92 | Object* Clone(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 93 | |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 94 | int32_t IdentityHashCode() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 95 | |
| 96 | static MemberOffset MonitorOffset() { |
| 97 | return OFFSET_OF_OBJECT_MEMBER(Object, monitor_); |
| 98 | } |
| 99 | |
Mathieu Chartier | 4d7f61d | 2014-04-17 14:43:39 -0700 | [diff] [blame] | 100 | // As volatile can be false if the mutators are suspended. This is an optimization since it |
| 101 | // avoids the barriers. |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 102 | LockWord GetLockWord(bool as_volatile) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 103 | void SetLockWord(LockWord new_val, bool as_volatile) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 104 | 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] | 105 | uint32_t GetLockOwnerThreadId(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 106 | |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 107 | mirror::Object* MonitorEnter(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) |
Ian Rogers | 719d1a3 | 2014-03-06 12:13:39 -0800 | [diff] [blame] | 108 | EXCLUSIVE_LOCK_FUNCTION(); |
Ian Rogers | 05f3057 | 2013-02-20 12:13:11 -0800 | [diff] [blame] | 109 | bool MonitorExit(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) |
Ian Rogers | 719d1a3 | 2014-03-06 12:13:39 -0800 | [diff] [blame] | 110 | UNLOCK_FUNCTION(); |
Ian Rogers | 05f3057 | 2013-02-20 12:13:11 -0800 | [diff] [blame] | 111 | void Notify(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 05f3057 | 2013-02-20 12:13:11 -0800 | [diff] [blame] | 112 | void NotifyAll(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) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 05f3057 | 2013-02-20 12:13:11 -0800 | [diff] [blame] | 114 | 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] | 115 | |
Hiroshi Yamauchi | 9103c86 | 2014-04-22 13:51:07 -0700 | [diff] [blame] | 116 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kDoReadBarrier = true> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 117 | bool IsClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Hiroshi Yamauchi | 9103c86 | 2014-04-22 13:51:07 -0700 | [diff] [blame] | 118 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kDoReadBarrier = true> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 119 | Class* AsClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 120 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 121 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 122 | bool IsObjectArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 123 | template<class T, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 124 | ObjectArray<T>* AsObjectArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 125 | |
Hiroshi Yamauchi | 9103c86 | 2014-04-22 13:51:07 -0700 | [diff] [blame] | 126 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kDoReadBarrier = true> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 127 | bool IsArrayInstance() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Hiroshi Yamauchi | 9103c86 | 2014-04-22 13:51:07 -0700 | [diff] [blame] | 128 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kDoReadBarrier = true> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 129 | Array* AsArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 130 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 131 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 132 | BooleanArray* AsBooleanArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 133 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 134 | ByteArray* AsByteArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 135 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 136 | ByteArray* AsByteSizedArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 137 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 138 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 139 | CharArray* AsCharArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 140 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 141 | ShortArray* AsShortArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 142 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 143 | ShortArray* AsShortSizedArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 144 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 145 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 146 | IntArray* AsIntArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 147 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 148 | LongArray* AsLongArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 149 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 150 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 151 | FloatArray* AsFloatArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 152 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 153 | DoubleArray* AsDoubleArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 154 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 155 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 156 | String* AsString() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 157 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 158 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 159 | Throwable* AsThrowable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 160 | |
Hiroshi Yamauchi | 9103c86 | 2014-04-22 13:51:07 -0700 | [diff] [blame] | 161 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kDoReadBarrier = true> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 162 | bool IsArtMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 163 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 164 | ArtMethod* AsArtMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 165 | |
Hiroshi Yamauchi | 9103c86 | 2014-04-22 13:51:07 -0700 | [diff] [blame] | 166 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kDoReadBarrier = true> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 167 | bool IsArtField() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 168 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 169 | ArtField* AsArtField() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 170 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 171 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 172 | bool IsReferenceInstance() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 173 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Mathieu Chartier | 8fa2dad | 2014-03-13 12:22:56 -0700 | [diff] [blame] | 174 | Reference* AsReference() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 175 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 176 | bool IsWeakReferenceInstance() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 177 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 178 | bool IsSoftReferenceInstance() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 179 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 180 | bool IsFinalizerReferenceInstance() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 181 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Mathieu Chartier | 8fa2dad | 2014-03-13 12:22:56 -0700 | [diff] [blame] | 182 | FinalizerReference* AsFinalizerReference() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 183 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 184 | bool IsPhantomReferenceInstance() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 185 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 186 | // Accessor for Java type fields. |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 187 | template<class T, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, |
| 188 | bool kDoReadBarrier = true, bool kIsVolatile = false> |
| 189 | T* GetFieldObject(MemberOffset field_offset) ALWAYS_INLINE |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 190 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 191 | |
| 192 | template<class T, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, |
| 193 | bool kDoReadBarrier = true> |
| 194 | T* GetFieldObjectVolatile(MemberOffset field_offset) ALWAYS_INLINE |
| 195 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 196 | |
| 197 | template<bool kTransactionActive, bool kCheckTransaction = true, |
| 198 | VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false> |
| 199 | void SetFieldObjectWithoutWriteBarrier(MemberOffset field_offset, Object* new_value) |
| 200 | ALWAYS_INLINE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 201 | |
| 202 | template<bool kTransactionActive, bool kCheckTransaction = true, |
| 203 | VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false> |
| 204 | void SetFieldObject(MemberOffset field_offset, Object* new_value) ALWAYS_INLINE |
| 205 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 206 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 207 | template<bool kTransactionActive, bool kCheckTransaction = true, |
| 208 | VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 209 | void SetFieldObjectVolatile(MemberOffset field_offset, Object* new_value) ALWAYS_INLINE |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 210 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 211 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 212 | template<bool kTransactionActive, bool kCheckTransaction = true, |
| 213 | VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 214 | bool CasFieldObject(MemberOffset field_offset, Object* old_value, Object* new_value) |
| 215 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 216 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 217 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
| 218 | HeapReference<Object>* GetFieldObjectReferenceAddr(MemberOffset field_offset); |
Mathieu Chartier | 11409ae | 2013-09-23 11:49:36 -0700 | [diff] [blame] | 219 | |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 220 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false> |
| 221 | int32_t GetField32(MemberOffset field_offset) ALWAYS_INLINE |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 222 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 223 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 224 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 225 | int32_t GetField32Volatile(MemberOffset field_offset) ALWAYS_INLINE |
| 226 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 227 | |
| 228 | template<bool kTransactionActive, bool kCheckTransaction = true, |
| 229 | VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false> |
| 230 | void SetField32(MemberOffset field_offset, int32_t new_value) ALWAYS_INLINE |
| 231 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 232 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 233 | template<bool kTransactionActive, bool kCheckTransaction = true, |
| 234 | VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 235 | void SetField32Volatile(MemberOffset field_offset, int32_t new_value) ALWAYS_INLINE |
| 236 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 237 | |
| 238 | template<bool kTransactionActive, bool kCheckTransaction = true, |
| 239 | VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
| 240 | bool CasField32(MemberOffset field_offset, int32_t old_value, int32_t new_value) ALWAYS_INLINE |
| 241 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 242 | |
| 243 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false> |
| 244 | int64_t GetField64(MemberOffset field_offset) ALWAYS_INLINE |
| 245 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 246 | |
| 247 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
| 248 | int64_t GetField64Volatile(MemberOffset field_offset) ALWAYS_INLINE |
| 249 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 250 | |
| 251 | template<bool kTransactionActive, bool kCheckTransaction = true, |
| 252 | VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false> |
| 253 | void SetField64(MemberOffset field_offset, int64_t new_value) ALWAYS_INLINE |
| 254 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 255 | |
| 256 | template<bool kTransactionActive, bool kCheckTransaction = true, |
| 257 | VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
| 258 | void SetField64Volatile(MemberOffset field_offset, int64_t new_value) ALWAYS_INLINE |
| 259 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 260 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 261 | template<bool kTransactionActive, bool kCheckTransaction = true, |
| 262 | VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | 29501cf | 2014-02-07 21:00:25 -0800 | [diff] [blame] | 263 | 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] | 264 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 265 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 266 | template<bool kTransactionActive, bool kCheckTransaction = true, |
| 267 | VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, typename T> |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 268 | void SetFieldPtr(MemberOffset field_offset, T new_value) |
| 269 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 270 | #ifndef __LP64__ |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 271 | SetField32<kTransactionActive, kCheckTransaction, kVerifyFlags>( |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 272 | field_offset, reinterpret_cast<int32_t>(new_value)); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 273 | #else |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 274 | SetField64<kTransactionActive, kCheckTransaction, kVerifyFlags>( |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 275 | field_offset, reinterpret_cast<int64_t>(new_value)); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 276 | #endif |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 277 | } |
| 278 | |
Mathieu Chartier | 407f702 | 2014-02-18 14:37:05 -0800 | [diff] [blame] | 279 | // TODO fix thread safety analysis broken by the use of template. This should be |
| 280 | // SHARED_LOCKS_REQUIRED(Locks::mutator_lock_). |
| 281 | template <const bool kVisitClass, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, |
| 282 | typename Visitor, typename JavaLangRefVisitor = VoidFunctor> |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 283 | void VisitReferences(const Visitor& visitor, const JavaLangRefVisitor& ref_visitor) |
Mathieu Chartier | 407f702 | 2014-02-18 14:37:05 -0800 | [diff] [blame] | 284 | NO_THREAD_SAFETY_ANALYSIS; |
| 285 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 286 | protected: |
| 287 | // Accessors for non-Java type fields |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 288 | template<class T, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false> |
| 289 | T GetFieldPtr(MemberOffset field_offset) |
| 290 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 291 | #ifndef __LP64__ |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 292 | return reinterpret_cast<T>(GetField32<kVerifyFlags, kIsVolatile>(field_offset)); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 293 | #else |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 294 | return reinterpret_cast<T>(GetField64<kVerifyFlags, kIsVolatile>(field_offset)); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 295 | #endif |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 296 | } |
| 297 | |
Mathieu Chartier | 407f702 | 2014-02-18 14:37:05 -0800 | [diff] [blame] | 298 | // TODO: Fixme when anotatalysis works with visitors. |
| 299 | template<bool kVisitClass, bool kIsStatic, typename Visitor> |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 300 | void VisitFieldsReferences(uint32_t ref_offsets, const Visitor& visitor) HOT_ATTR |
Mathieu Chartier | 407f702 | 2014-02-18 14:37:05 -0800 | [diff] [blame] | 301 | NO_THREAD_SAFETY_ANALYSIS; |
| 302 | template<bool kVisitClass, typename Visitor> |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 303 | void VisitInstanceFieldsReferences(mirror::Class* klass, const Visitor& visitor) HOT_ATTR |
Mathieu Chartier | 407f702 | 2014-02-18 14:37:05 -0800 | [diff] [blame] | 304 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 305 | template<bool kVisitClass, typename Visitor> |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 306 | void VisitStaticFieldsReferences(mirror::Class* klass, const Visitor& visitor) HOT_ATTR |
Mathieu Chartier | 407f702 | 2014-02-18 14:37:05 -0800 | [diff] [blame] | 307 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 308 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 309 | private: |
Ian Rogers | 04d7aa9 | 2013-03-16 14:29:17 -0700 | [diff] [blame] | 310 | // Verify the type correctness of stores to fields. |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 311 | void CheckFieldAssignmentImpl(MemberOffset field_offset, Object* new_value) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 312 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 313 | void CheckFieldAssignment(MemberOffset field_offset, Object* new_value) |
Ian Rogers | 04d7aa9 | 2013-03-16 14:29:17 -0700 | [diff] [blame] | 314 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 315 | if (kCheckFieldAssignments) { |
| 316 | CheckFieldAssignmentImpl(field_offset, new_value); |
| 317 | } |
| 318 | } |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 319 | |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 320 | // Generate an identity hash code. |
Mathieu Chartier | 4e6a31e | 2013-10-31 10:35:05 -0700 | [diff] [blame] | 321 | static int32_t GenerateIdentityHashCode(); |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 322 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 323 | // The Class representing the type of the object. |
| 324 | HeapReference<Class> klass_; |
| 325 | // Monitor and hash code information. |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 326 | uint32_t monitor_; |
| 327 | |
Hiroshi Yamauchi | 624468c | 2014-03-31 15:14:47 -0700 | [diff] [blame] | 328 | #ifdef USE_BAKER_OR_BROOKS_READ_BARRIER |
| 329 | // Note names use a 'x' prefix and the x_rb_ptr_ is of type int |
Hiroshi Yamauchi | 9d04a20 | 2014-01-31 13:35:49 -0800 | [diff] [blame] | 330 | // instead of Object to go with the alphabetical/by-type field order |
| 331 | // on the Java side. |
Hiroshi Yamauchi | 624468c | 2014-03-31 15:14:47 -0700 | [diff] [blame] | 332 | uint32_t x_rb_ptr_; // For the Baker or Brooks pointer. |
| 333 | uint32_t x_xpadding_; // For 8-byte alignment. TODO: get rid of this. |
Hiroshi Yamauchi | 9d04a20 | 2014-01-31 13:35:49 -0800 | [diff] [blame] | 334 | #endif |
| 335 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 336 | friend class art::ImageWriter; |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 337 | friend class art::Monitor; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 338 | friend struct art::ObjectOffsets; // for verifying offset information |
| 339 | DISALLOW_IMPLICIT_CONSTRUCTORS(Object); |
| 340 | }; |
| 341 | |
| 342 | } // namespace mirror |
| 343 | } // namespace art |
| 344 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 345 | #endif // ART_RUNTIME_MIRROR_OBJECT_H_ |