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 | cdc1aaf | 2014-10-09 13:21:38 -0700 | [diff] [blame] | 20 | #include "globals.h" |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 21 | #include "object_reference.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 22 | #include "offsets.h" |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 23 | #include "verify_object.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 24 | |
| 25 | namespace art { |
| 26 | |
| 27 | class ImageWriter; |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 28 | class LockWord; |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 29 | class Monitor; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 30 | struct ObjectOffsets; |
| 31 | class Thread; |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 32 | class VoidFunctor; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 33 | |
| 34 | namespace mirror { |
| 35 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 36 | class ArtField; |
| 37 | class ArtMethod; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 38 | class Array; |
| 39 | class Class; |
Mathieu Chartier | 8fa2dad | 2014-03-13 12:22:56 -0700 | [diff] [blame] | 40 | class FinalizerReference; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 41 | template<class T> class ObjectArray; |
| 42 | template<class T> class PrimitiveArray; |
| 43 | typedef PrimitiveArray<uint8_t> BooleanArray; |
| 44 | typedef PrimitiveArray<int8_t> ByteArray; |
| 45 | typedef PrimitiveArray<uint16_t> CharArray; |
| 46 | typedef PrimitiveArray<double> DoubleArray; |
| 47 | typedef PrimitiveArray<float> FloatArray; |
| 48 | typedef PrimitiveArray<int32_t> IntArray; |
| 49 | typedef PrimitiveArray<int64_t> LongArray; |
| 50 | typedef PrimitiveArray<int16_t> ShortArray; |
Mathieu Chartier | 8fa2dad | 2014-03-13 12:22:56 -0700 | [diff] [blame] | 51 | class Reference; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 52 | class String; |
| 53 | class Throwable; |
| 54 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 55 | // Fields within mirror objects aren't accessed directly so that the appropriate amount of |
| 56 | // handshaking is done with GC (for example, read and write barriers). This macro is used to |
| 57 | // compute an offset for the Set/Get methods defined in Object that can safely access fields. |
| 58 | #define OFFSET_OF_OBJECT_MEMBER(type, field) \ |
| 59 | MemberOffset(OFFSETOF_MEMBER(type, field)) |
| 60 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 61 | // Checks that we don't do field assignments which violate the typing system. |
| 62 | static constexpr bool kCheckFieldAssignments = false; |
Ian Rogers | 04d7aa9 | 2013-03-16 14:29:17 -0700 | [diff] [blame] | 63 | |
Ian Rogers | cdc1aaf | 2014-10-09 13:21:38 -0700 | [diff] [blame] | 64 | // Size of Object. |
Ian Rogers | 6cdedf0 | 2014-10-09 16:29:40 -0700 | [diff] [blame] | 65 | static constexpr uint32_t kObjectHeaderSize = kUseBakerOrBrooksReadBarrier ? 16 : 8; |
Ian Rogers | cdc1aaf | 2014-10-09 13:21:38 -0700 | [diff] [blame] | 66 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 67 | // C++ mirror of java.lang.Object |
Ian Rogers | 719d1a3 | 2014-03-06 12:13:39 -0800 | [diff] [blame] | 68 | class MANAGED LOCKABLE Object { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 69 | public: |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 70 | // The number of vtable entries in java.lang.Object. |
| 71 | static constexpr size_t kVTableLength = 11; |
| 72 | |
| 73 | // The size of the java.lang.Class representing a java.lang.Object. |
| 74 | static uint32_t ClassSize(); |
| 75 | |
| 76 | // Size of an instance of java.lang.Object. |
| 77 | static constexpr uint32_t InstanceSize() { |
| 78 | return sizeof(Object); |
| 79 | } |
| 80 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 81 | static MemberOffset ClassOffset() { |
| 82 | return OFFSET_OF_OBJECT_MEMBER(Object, klass_); |
| 83 | } |
| 84 | |
Hiroshi Yamauchi | 6e83c17 | 2014-05-01 21:25:41 -0700 | [diff] [blame] | 85 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, |
| 86 | ReadBarrierOption kReadBarrierOption = kWithReadBarrier> |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 87 | ALWAYS_INLINE Class* GetClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 88 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 89 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 90 | void SetClass(Class* new_klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 91 | |
Hiroshi Yamauchi | 624468c | 2014-03-31 15:14:47 -0700 | [diff] [blame] | 92 | Object* GetReadBarrierPointer() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Hiroshi Yamauchi | 9103c86 | 2014-04-22 13:51:07 -0700 | [diff] [blame] | 93 | void SetReadBarrierPointer(Object* rb_ptr) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 94 | bool AtomicSetReadBarrierPointer(Object* expected_rb_ptr, Object* rb_ptr) |
| 95 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Hiroshi Yamauchi | 624468c | 2014-03-31 15:14:47 -0700 | [diff] [blame] | 96 | void AssertReadBarrierPointer() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Hiroshi Yamauchi | 9d04a20 | 2014-01-31 13:35:49 -0800 | [diff] [blame] | 97 | |
Jeff Hao | a3faaf4 | 2013-09-03 19:07:00 -0700 | [diff] [blame] | 98 | // The verifier treats all interfaces as java.lang.Object and relies on runtime checks in |
| 99 | // invoke-interface to detect incompatible interface types. |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 100 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 101 | bool VerifierInstanceOf(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 102 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 103 | bool InstanceOf(Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 104 | |
Hiroshi Yamauchi | 6e83c17 | 2014-05-01 21:25:41 -0700 | [diff] [blame] | 105 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, |
| 106 | ReadBarrierOption kReadBarrierOption = kWithReadBarrier> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 107 | size_t SizeOf() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 108 | |
| 109 | Object* Clone(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 110 | |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 111 | int32_t IdentityHashCode() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 112 | |
| 113 | static MemberOffset MonitorOffset() { |
| 114 | return OFFSET_OF_OBJECT_MEMBER(Object, monitor_); |
| 115 | } |
| 116 | |
Hans Boehm | d843443 | 2014-07-11 09:56:07 -0700 | [diff] [blame] | 117 | // As_volatile can be false if the mutators are suspended. This is an optimization since it |
Mathieu Chartier | 4d7f61d | 2014-04-17 14:43:39 -0700 | [diff] [blame] | 118 | // avoids the barriers. |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 119 | LockWord GetLockWord(bool as_volatile) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 120 | void SetLockWord(LockWord new_val, bool as_volatile) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 228602f | 2014-07-10 02:07:54 -0700 | [diff] [blame] | 121 | bool CasLockWordWeakSequentiallyConsistent(LockWord old_val, LockWord new_val) |
| 122 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Hans Boehm | d843443 | 2014-07-11 09:56:07 -0700 | [diff] [blame] | 123 | bool CasLockWordWeakRelaxed(LockWord old_val, LockWord new_val) |
| 124 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 125 | uint32_t GetLockOwnerThreadId(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 126 | |
Mathieu Chartier | e7e8a5f | 2014-02-14 16:59:41 -0800 | [diff] [blame] | 127 | mirror::Object* MonitorEnter(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) |
Ian Rogers | 719d1a3 | 2014-03-06 12:13:39 -0800 | [diff] [blame] | 128 | EXCLUSIVE_LOCK_FUNCTION(); |
Ian Rogers | 05f3057 | 2013-02-20 12:13:11 -0800 | [diff] [blame] | 129 | bool MonitorExit(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) |
Ian Rogers | 719d1a3 | 2014-03-06 12:13:39 -0800 | [diff] [blame] | 130 | UNLOCK_FUNCTION(); |
Ian Rogers | 05f3057 | 2013-02-20 12:13:11 -0800 | [diff] [blame] | 131 | void Notify(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 05f3057 | 2013-02-20 12:13:11 -0800 | [diff] [blame] | 132 | void NotifyAll(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 05f3057 | 2013-02-20 12:13:11 -0800 | [diff] [blame] | 133 | void Wait(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 05f3057 | 2013-02-20 12:13:11 -0800 | [diff] [blame] | 134 | 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] | 135 | |
Hiroshi Yamauchi | 6e83c17 | 2014-05-01 21:25:41 -0700 | [diff] [blame] | 136 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, |
| 137 | ReadBarrierOption kReadBarrierOption = kWithReadBarrier> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 138 | bool IsClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Hiroshi Yamauchi | 6e83c17 | 2014-05-01 21:25:41 -0700 | [diff] [blame] | 139 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, |
| 140 | ReadBarrierOption kReadBarrierOption = kWithReadBarrier> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 141 | Class* AsClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 142 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 143 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 144 | bool IsObjectArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 145 | template<class T, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 146 | ObjectArray<T>* AsObjectArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 147 | |
Hiroshi Yamauchi | 6e83c17 | 2014-05-01 21:25:41 -0700 | [diff] [blame] | 148 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, |
| 149 | ReadBarrierOption kReadBarrierOption = kWithReadBarrier> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 150 | bool IsArrayInstance() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Hiroshi Yamauchi | 6e83c17 | 2014-05-01 21:25:41 -0700 | [diff] [blame] | 151 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, |
| 152 | ReadBarrierOption kReadBarrierOption = kWithReadBarrier> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 153 | Array* AsArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 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 | BooleanArray* AsBooleanArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 157 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 158 | ByteArray* AsByteArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 159 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 160 | ByteArray* AsByteSizedArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 161 | |
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 | CharArray* AsCharArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 164 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 165 | ShortArray* AsShortArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 166 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 167 | ShortArray* AsShortSizedArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 168 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 169 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 170 | IntArray* AsIntArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
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 | LongArray* AsLongArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 173 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 174 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 175 | FloatArray* AsFloatArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 176 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 177 | DoubleArray* AsDoubleArray() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 178 | |
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 | String* AsString() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 181 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 182 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 183 | Throwable* AsThrowable() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 184 | |
Hiroshi Yamauchi | 6e83c17 | 2014-05-01 21:25:41 -0700 | [diff] [blame] | 185 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, |
| 186 | ReadBarrierOption kReadBarrierOption = kWithReadBarrier> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 187 | bool IsArtMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 188 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 189 | ArtMethod* AsArtMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 190 | |
Hiroshi Yamauchi | 6e83c17 | 2014-05-01 21:25:41 -0700 | [diff] [blame] | 191 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, |
| 192 | ReadBarrierOption kReadBarrierOption = kWithReadBarrier> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 193 | bool IsArtField() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 194 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 195 | ArtField* AsArtField() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 196 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 197 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 198 | bool IsReferenceInstance() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 199 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Mathieu Chartier | 8fa2dad | 2014-03-13 12:22:56 -0700 | [diff] [blame] | 200 | Reference* AsReference() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 201 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 202 | bool IsWeakReferenceInstance() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 203 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 204 | bool IsSoftReferenceInstance() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 205 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 206 | bool IsFinalizerReferenceInstance() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 207 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Mathieu Chartier | 8fa2dad | 2014-03-13 12:22:56 -0700 | [diff] [blame] | 208 | FinalizerReference* AsFinalizerReference() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 209 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 210 | bool IsPhantomReferenceInstance() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 211 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 212 | // Accessor for Java type fields. |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 213 | template<class T, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, |
Hiroshi Yamauchi | 6e83c17 | 2014-05-01 21:25:41 -0700 | [diff] [blame] | 214 | ReadBarrierOption kReadBarrierOption = kWithReadBarrier, bool kIsVolatile = false> |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 215 | ALWAYS_INLINE T* GetFieldObject(MemberOffset field_offset) |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 216 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 217 | |
| 218 | template<class T, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, |
Hiroshi Yamauchi | 6e83c17 | 2014-05-01 21:25:41 -0700 | [diff] [blame] | 219 | ReadBarrierOption kReadBarrierOption = kWithReadBarrier> |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 220 | ALWAYS_INLINE T* GetFieldObjectVolatile(MemberOffset field_offset) |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 221 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 222 | |
| 223 | template<bool kTransactionActive, bool kCheckTransaction = true, |
| 224 | VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false> |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 225 | ALWAYS_INLINE void SetFieldObjectWithoutWriteBarrier(MemberOffset field_offset, Object* new_value) |
| 226 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 227 | |
| 228 | template<bool kTransactionActive, bool kCheckTransaction = true, |
| 229 | VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false> |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 230 | ALWAYS_INLINE void SetFieldObject(MemberOffset field_offset, Object* new_value) |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 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> |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 235 | ALWAYS_INLINE void SetFieldObjectVolatile(MemberOffset field_offset, Object* new_value) |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 236 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 237 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 238 | template<bool kTransactionActive, bool kCheckTransaction = true, |
| 239 | VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | 228602f | 2014-07-10 02:07:54 -0700 | [diff] [blame] | 240 | bool CasFieldWeakSequentiallyConsistentObject(MemberOffset field_offset, Object* old_value, |
| 241 | Object* new_value) |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 242 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 243 | |
Hans Boehm | d843443 | 2014-07-11 09:56:07 -0700 | [diff] [blame] | 244 | template<bool kTransactionActive, bool kCheckTransaction = true, |
| 245 | VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
| 246 | bool CasFieldStrongSequentiallyConsistentObject(MemberOffset field_offset, Object* old_value, |
| 247 | Object* new_value) |
| 248 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 249 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 250 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
| 251 | HeapReference<Object>* GetFieldObjectReferenceAddr(MemberOffset field_offset); |
Mathieu Chartier | 11409ae | 2013-09-23 11:49:36 -0700 | [diff] [blame] | 252 | |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 253 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false> |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 254 | ALWAYS_INLINE uint8_t GetFieldBoolean(MemberOffset field_offset) |
| 255 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 256 | |
| 257 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false> |
| 258 | ALWAYS_INLINE int8_t GetFieldByte(MemberOffset field_offset) |
| 259 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 260 | |
| 261 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
| 262 | ALWAYS_INLINE uint8_t GetFieldBooleanVolatile(MemberOffset field_offset) |
| 263 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 264 | |
| 265 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
| 266 | ALWAYS_INLINE int8_t GetFieldByteVolatile(MemberOffset field_offset) |
| 267 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 268 | |
| 269 | template<bool kTransactionActive, bool kCheckTransaction = true, |
| 270 | VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false> |
| 271 | ALWAYS_INLINE void SetFieldBoolean(MemberOffset field_offset, uint8_t new_value) |
| 272 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 273 | |
| 274 | template<bool kTransactionActive, bool kCheckTransaction = true, |
| 275 | VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false> |
| 276 | ALWAYS_INLINE void SetFieldByte(MemberOffset field_offset, int8_t new_value) |
| 277 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 278 | |
| 279 | template<bool kTransactionActive, bool kCheckTransaction = true, |
| 280 | VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
| 281 | ALWAYS_INLINE void SetFieldBooleanVolatile(MemberOffset field_offset, uint8_t new_value) |
| 282 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 283 | |
| 284 | template<bool kTransactionActive, bool kCheckTransaction = true, |
| 285 | VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
| 286 | ALWAYS_INLINE void SetFieldByteVolatile(MemberOffset field_offset, int8_t new_value) |
| 287 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 288 | |
| 289 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false> |
| 290 | ALWAYS_INLINE uint16_t GetFieldChar(MemberOffset field_offset) |
| 291 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 292 | |
| 293 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false> |
| 294 | ALWAYS_INLINE int16_t GetFieldShort(MemberOffset field_offset) |
| 295 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 296 | |
| 297 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
| 298 | ALWAYS_INLINE uint16_t GetFieldCharVolatile(MemberOffset field_offset) |
| 299 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 300 | |
| 301 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
| 302 | ALWAYS_INLINE int16_t GetFieldShortVolatile(MemberOffset field_offset) |
| 303 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 304 | |
| 305 | template<bool kTransactionActive, bool kCheckTransaction = true, |
| 306 | VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false> |
| 307 | ALWAYS_INLINE void SetFieldChar(MemberOffset field_offset, uint16_t new_value) |
| 308 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 309 | |
| 310 | template<bool kTransactionActive, bool kCheckTransaction = true, |
| 311 | VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false> |
| 312 | ALWAYS_INLINE void SetFieldShort(MemberOffset field_offset, int16_t new_value) |
| 313 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 314 | |
| 315 | template<bool kTransactionActive, bool kCheckTransaction = true, |
| 316 | VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
| 317 | ALWAYS_INLINE void SetFieldCharVolatile(MemberOffset field_offset, uint16_t new_value) |
| 318 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 319 | |
| 320 | template<bool kTransactionActive, bool kCheckTransaction = true, |
| 321 | VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
| 322 | ALWAYS_INLINE void SetFieldShortVolatile(MemberOffset field_offset, int16_t new_value) |
| 323 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 324 | |
| 325 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false> |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 326 | ALWAYS_INLINE int32_t GetField32(MemberOffset field_offset) |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 327 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 328 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 329 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 330 | ALWAYS_INLINE int32_t GetField32Volatile(MemberOffset field_offset) |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 331 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 332 | |
| 333 | template<bool kTransactionActive, bool kCheckTransaction = true, |
| 334 | VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false> |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 335 | ALWAYS_INLINE void SetField32(MemberOffset field_offset, int32_t new_value) |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 336 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 337 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 338 | template<bool kTransactionActive, bool kCheckTransaction = true, |
| 339 | VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 340 | ALWAYS_INLINE void SetField32Volatile(MemberOffset field_offset, int32_t new_value) |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 341 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 342 | |
| 343 | template<bool kTransactionActive, bool kCheckTransaction = true, |
| 344 | VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 345 | ALWAYS_INLINE bool CasFieldWeakSequentiallyConsistent32(MemberOffset field_offset, |
| 346 | int32_t old_value, int32_t new_value) |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 347 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 348 | |
Hans Boehm | d843443 | 2014-07-11 09:56:07 -0700 | [diff] [blame] | 349 | template<bool kTransactionActive, bool kCheckTransaction = true, |
| 350 | VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
| 351 | bool CasFieldWeakRelaxed32(MemberOffset field_offset, int32_t old_value, |
| 352 | int32_t new_value) ALWAYS_INLINE |
| 353 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 354 | |
| 355 | template<bool kTransactionActive, bool kCheckTransaction = true, |
| 356 | VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
| 357 | bool CasFieldStrongSequentiallyConsistent32(MemberOffset field_offset, int32_t old_value, |
| 358 | int32_t new_value) ALWAYS_INLINE |
| 359 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 360 | |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 361 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false> |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 362 | ALWAYS_INLINE int64_t GetField64(MemberOffset field_offset) |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 363 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 364 | |
| 365 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 366 | ALWAYS_INLINE int64_t GetField64Volatile(MemberOffset field_offset) |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 367 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 368 | |
| 369 | template<bool kTransactionActive, bool kCheckTransaction = true, |
| 370 | VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false> |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 371 | ALWAYS_INLINE void SetField64(MemberOffset field_offset, int64_t new_value) |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 372 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 373 | |
| 374 | template<bool kTransactionActive, bool kCheckTransaction = true, |
| 375 | VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 376 | ALWAYS_INLINE void SetField64Volatile(MemberOffset field_offset, int64_t new_value) |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 377 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 378 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 379 | template<bool kTransactionActive, bool kCheckTransaction = true, |
| 380 | VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Ian Rogers | 228602f | 2014-07-10 02:07:54 -0700 | [diff] [blame] | 381 | bool CasFieldWeakSequentiallyConsistent64(MemberOffset field_offset, int64_t old_value, |
| 382 | int64_t new_value) |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 383 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 384 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 385 | template<bool kTransactionActive, bool kCheckTransaction = true, |
Hans Boehm | d843443 | 2014-07-11 09:56:07 -0700 | [diff] [blame] | 386 | VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
| 387 | bool CasFieldStrongSequentiallyConsistent64(MemberOffset field_offset, int64_t old_value, |
| 388 | int64_t new_value) |
| 389 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 390 | |
| 391 | template<bool kTransactionActive, bool kCheckTransaction = true, |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 392 | VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, typename T> |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 393 | void SetFieldPtr(MemberOffset field_offset, T new_value) |
| 394 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame^] | 395 | SetFieldPtrWithSize<kTransactionActive, kCheckTransaction, kVerifyFlags>( |
| 396 | field_offset, new_value, sizeof(void*)); |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 397 | } |
| 398 | |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame^] | 399 | template<bool kTransactionActive, bool kCheckTransaction = true, |
| 400 | VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, typename T> |
| 401 | ALWAYS_INLINE void SetFieldPtrWithSize(MemberOffset field_offset, T new_value, |
| 402 | size_t pointer_size) |
| 403 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 404 | DCHECK(pointer_size == 4 || pointer_size == 8) << pointer_size; |
| 405 | if (pointer_size == 4) { |
| 406 | intptr_t ptr = reinterpret_cast<intptr_t>(new_value); |
| 407 | DCHECK_EQ(static_cast<int32_t>(ptr), ptr); // Check that we dont lose any non 0 bits. |
| 408 | SetField32<kTransactionActive, kCheckTransaction, kVerifyFlags>( |
| 409 | field_offset, static_cast<int32_t>(ptr)); |
| 410 | } else { |
| 411 | SetField64<kTransactionActive, kCheckTransaction, kVerifyFlags>( |
| 412 | field_offset, static_cast<int64_t>(reinterpret_cast<intptr_t>(new_value))); |
| 413 | } |
| 414 | } |
Mathieu Chartier | 407f702 | 2014-02-18 14:37:05 -0800 | [diff] [blame] | 415 | // TODO fix thread safety analysis broken by the use of template. This should be |
| 416 | // SHARED_LOCKS_REQUIRED(Locks::mutator_lock_). |
| 417 | template <const bool kVisitClass, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, |
| 418 | typename Visitor, typename JavaLangRefVisitor = VoidFunctor> |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 419 | void VisitReferences(const Visitor& visitor, const JavaLangRefVisitor& ref_visitor) |
Mathieu Chartier | 407f702 | 2014-02-18 14:37:05 -0800 | [diff] [blame] | 420 | NO_THREAD_SAFETY_ANALYSIS; |
| 421 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 422 | protected: |
| 423 | // Accessors for non-Java type fields |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 424 | template<class T, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false> |
| 425 | T GetFieldPtr(MemberOffset field_offset) |
| 426 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame^] | 427 | return GetFieldPtrWithSize<T, kVerifyFlags, kIsVolatile>(field_offset, sizeof(void*)); |
| 428 | } |
| 429 | |
| 430 | template<class T, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, bool kIsVolatile = false> |
| 431 | ALWAYS_INLINE T GetFieldPtrWithSize(MemberOffset field_offset, size_t pointer_size) |
| 432 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 433 | DCHECK(pointer_size == 4 || pointer_size == 8) << pointer_size; |
| 434 | if (pointer_size == 4) { |
| 435 | return reinterpret_cast<T>(GetField32<kVerifyFlags, kIsVolatile>(field_offset)); |
| 436 | } else { |
| 437 | int64_t v = GetField64<kVerifyFlags, kIsVolatile>(field_offset); |
| 438 | // Check that we dont lose any non 0 bits. |
| 439 | DCHECK_EQ(reinterpret_cast<int64_t>(reinterpret_cast<T>(v)), v); |
| 440 | return reinterpret_cast<T>(v); |
| 441 | } |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 442 | } |
| 443 | |
Mathieu Chartier | 407f702 | 2014-02-18 14:37:05 -0800 | [diff] [blame] | 444 | // TODO: Fixme when anotatalysis works with visitors. |
| 445 | template<bool kVisitClass, bool kIsStatic, typename Visitor> |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 446 | void VisitFieldsReferences(uint32_t ref_offsets, const Visitor& visitor) HOT_ATTR |
Mathieu Chartier | 407f702 | 2014-02-18 14:37:05 -0800 | [diff] [blame] | 447 | NO_THREAD_SAFETY_ANALYSIS; |
| 448 | template<bool kVisitClass, typename Visitor> |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 449 | void VisitInstanceFieldsReferences(mirror::Class* klass, const Visitor& visitor) HOT_ATTR |
Mathieu Chartier | 407f702 | 2014-02-18 14:37:05 -0800 | [diff] [blame] | 450 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 451 | template<bool kVisitClass, typename Visitor> |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 452 | void VisitStaticFieldsReferences(mirror::Class* klass, const Visitor& visitor) HOT_ATTR |
Mathieu Chartier | 407f702 | 2014-02-18 14:37:05 -0800 | [diff] [blame] | 453 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 454 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 455 | private: |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 456 | template<typename kSize, bool kIsVolatile> |
| 457 | ALWAYS_INLINE void SetField(MemberOffset field_offset, kSize new_value) |
| 458 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 459 | template<typename kSize, bool kIsVolatile> |
| 460 | ALWAYS_INLINE kSize GetField(MemberOffset field_offset) |
| 461 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 462 | |
Ian Rogers | 04d7aa9 | 2013-03-16 14:29:17 -0700 | [diff] [blame] | 463 | // Verify the type correctness of stores to fields. |
Mathieu Chartier | 61c5ebc | 2014-06-05 17:42:53 -0700 | [diff] [blame] | 464 | // TODO: This can cause thread suspension and isn't moving GC safe. |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 465 | void CheckFieldAssignmentImpl(MemberOffset field_offset, Object* new_value) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 466 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 467 | void CheckFieldAssignment(MemberOffset field_offset, Object* new_value) |
Ian Rogers | 04d7aa9 | 2013-03-16 14:29:17 -0700 | [diff] [blame] | 468 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 469 | if (kCheckFieldAssignments) { |
| 470 | CheckFieldAssignmentImpl(field_offset, new_value); |
| 471 | } |
| 472 | } |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 473 | |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 474 | // Generate an identity hash code. |
Ian Rogers | bbcd30b | 2014-10-30 15:25:36 -0700 | [diff] [blame] | 475 | static uint32_t GenerateIdentityHashCode(); |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 476 | |
Hiroshi Yamauchi | 0fbd6e6 | 2014-07-17 16:16:31 -0700 | [diff] [blame] | 477 | // A utility function that copies an object in a read barrier and |
| 478 | // write barrier-aware way. This is internally used by Clone() and |
| 479 | // Class::CopyOf(). |
| 480 | static Object* CopyObject(Thread* self, mirror::Object* dest, mirror::Object* src, |
| 481 | size_t num_bytes) |
| 482 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 483 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 484 | // The Class representing the type of the object. |
| 485 | HeapReference<Class> klass_; |
| 486 | // Monitor and hash code information. |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 487 | uint32_t monitor_; |
| 488 | |
Hiroshi Yamauchi | 624468c | 2014-03-31 15:14:47 -0700 | [diff] [blame] | 489 | #ifdef USE_BAKER_OR_BROOKS_READ_BARRIER |
| 490 | // 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] | 491 | // instead of Object to go with the alphabetical/by-type field order |
| 492 | // on the Java side. |
Hiroshi Yamauchi | 624468c | 2014-03-31 15:14:47 -0700 | [diff] [blame] | 493 | uint32_t x_rb_ptr_; // For the Baker or Brooks pointer. |
| 494 | 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] | 495 | #endif |
| 496 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 497 | friend class art::ImageWriter; |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 498 | friend class art::Monitor; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 499 | friend struct art::ObjectOffsets; // for verifying offset information |
Hiroshi Yamauchi | 0fbd6e6 | 2014-07-17 16:16:31 -0700 | [diff] [blame] | 500 | friend class CopyObjectVisitor; // for CopyObject(). |
| 501 | friend class CopyClassVisitor; // for CopyObject(). |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 502 | DISALLOW_ALLOCATION(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 503 | DISALLOW_IMPLICIT_CONSTRUCTORS(Object); |
| 504 | }; |
| 505 | |
| 506 | } // namespace mirror |
| 507 | } // namespace art |
| 508 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 509 | #endif // ART_RUNTIME_MIRROR_OBJECT_H_ |