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 | |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 17 | #include <ctime> |
| 18 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 19 | #include "object.h" |
| 20 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 21 | #include "art_field.h" |
| 22 | #include "art_field-inl.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 23 | #include "array-inl.h" |
| 24 | #include "class.h" |
| 25 | #include "class-inl.h" |
Ian Rogers | 04d7aa9 | 2013-03-16 14:29:17 -0700 | [diff] [blame] | 26 | #include "class_linker-inl.h" |
Elliott Hughes | 956af0f | 2014-12-11 14:34:28 -0800 | [diff] [blame] | 27 | #include "dex_file-inl.h" |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 28 | #include "gc/accounting/card_table-inl.h" |
| 29 | #include "gc/heap.h" |
Ian Rogers | 04d7aa9 | 2013-03-16 14:29:17 -0700 | [diff] [blame] | 30 | #include "iftable-inl.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 31 | #include "monitor.h" |
| 32 | #include "object-inl.h" |
Ian Rogers | 04d7aa9 | 2013-03-16 14:29:17 -0700 | [diff] [blame] | 33 | #include "object_array-inl.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 34 | #include "runtime.h" |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 35 | #include "handle_scope-inl.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 36 | #include "throwable.h" |
| 37 | #include "well_known_classes.h" |
| 38 | |
| 39 | namespace art { |
| 40 | namespace mirror { |
| 41 | |
tony.ys_liu | 7380c31 | 2015-01-16 19:16:45 +0800 | [diff] [blame] | 42 | Atomic<uint32_t> Object::hash_code_seed(987654321U + std::time(nullptr)); |
| 43 | |
Hiroshi Yamauchi | 7971928 | 2014-04-10 12:46:22 -0700 | [diff] [blame] | 44 | class CopyReferenceFieldsWithReadBarrierVisitor { |
| 45 | public: |
| 46 | explicit CopyReferenceFieldsWithReadBarrierVisitor(Object* dest_obj) |
| 47 | : dest_obj_(dest_obj) {} |
| 48 | |
| 49 | void operator()(Object* obj, MemberOffset offset, bool /* is_static */) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 50 | ALWAYS_INLINE REQUIRES_SHARED(Locks::mutator_lock_) { |
Hiroshi Yamauchi | 7971928 | 2014-04-10 12:46:22 -0700 | [diff] [blame] | 51 | // GetFieldObject() contains a RB. |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 52 | Object* ref = obj->GetFieldObject<Object>(offset); |
Hiroshi Yamauchi | 7971928 | 2014-04-10 12:46:22 -0700 | [diff] [blame] | 53 | // No WB here as a large object space does not have a card table |
| 54 | // coverage. Instead, cards will be marked separately. |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 55 | dest_obj_->SetFieldObjectWithoutWriteBarrier<false, false>(offset, ref); |
Hiroshi Yamauchi | 7971928 | 2014-04-10 12:46:22 -0700 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | void operator()(mirror::Class* klass, mirror::Reference* ref) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 59 | ALWAYS_INLINE REQUIRES_SHARED(Locks::mutator_lock_) { |
Hiroshi Yamauchi | 7971928 | 2014-04-10 12:46:22 -0700 | [diff] [blame] | 60 | // Copy java.lang.ref.Reference.referent which isn't visited in |
| 61 | // Object::VisitReferences(). |
Fred Shih | 4ee7a66 | 2014-07-11 09:59:27 -0700 | [diff] [blame] | 62 | DCHECK(klass->IsTypeOfReferenceClass()); |
Hiroshi Yamauchi | 7971928 | 2014-04-10 12:46:22 -0700 | [diff] [blame] | 63 | this->operator()(ref, mirror::Reference::ReferentOffset(), false); |
| 64 | } |
| 65 | |
Mathieu Chartier | da7c650 | 2015-07-23 16:01:26 -0700 | [diff] [blame] | 66 | // Unused since we don't copy class native roots. |
| 67 | void VisitRootIfNonNull(mirror::CompressedReference<mirror::Object>* root ATTRIBUTE_UNUSED) |
| 68 | const {} |
| 69 | void VisitRoot(mirror::CompressedReference<mirror::Object>* root ATTRIBUTE_UNUSED) const {} |
| 70 | |
Hiroshi Yamauchi | 7971928 | 2014-04-10 12:46:22 -0700 | [diff] [blame] | 71 | private: |
| 72 | Object* const dest_obj_; |
| 73 | }; |
| 74 | |
Mathieu Chartier | 0353698 | 2016-10-07 10:51:53 -0700 | [diff] [blame^] | 75 | Object* Object::CopyObject(Thread* self, |
| 76 | mirror::Object* dest, |
| 77 | mirror::Object* src, |
Hiroshi Yamauchi | 0fbd6e6 | 2014-07-17 16:16:31 -0700 | [diff] [blame] | 78 | size_t num_bytes) { |
Mathieu Chartier | 0353698 | 2016-10-07 10:51:53 -0700 | [diff] [blame^] | 79 | // Copy instance data. Don't assume memcpy copies by words (b/32012820). |
| 80 | { |
| 81 | const size_t offset = sizeof(Object); |
| 82 | uint8_t* src_bytes = reinterpret_cast<uint8_t*>(src) + offset; |
| 83 | uint8_t* dst_bytes = reinterpret_cast<uint8_t*>(dest) + offset; |
| 84 | num_bytes -= offset; |
| 85 | DCHECK_ALIGNED(src_bytes, sizeof(uintptr_t)); |
| 86 | DCHECK_ALIGNED(dst_bytes, sizeof(uintptr_t)); |
| 87 | // Use word sized copies to begin. |
| 88 | while (num_bytes >= sizeof(uintptr_t)) { |
| 89 | *reinterpret_cast<uintptr_t*>(dst_bytes) = *reinterpret_cast<uintptr_t*>(src_bytes); |
| 90 | src_bytes += sizeof(uintptr_t); |
| 91 | dst_bytes += sizeof(uintptr_t); |
| 92 | num_bytes -= sizeof(uintptr_t); |
| 93 | } |
| 94 | // Copy possible 32 bit word. |
| 95 | if (sizeof(uintptr_t) != sizeof(uint32_t) && num_bytes >= sizeof(uint32_t)) { |
| 96 | *reinterpret_cast<uint32_t*>(dst_bytes) = *reinterpret_cast<uint32_t*>(src_bytes); |
| 97 | src_bytes += sizeof(uint32_t); |
| 98 | dst_bytes += sizeof(uint32_t); |
| 99 | num_bytes -= sizeof(uint32_t); |
| 100 | } |
| 101 | // Copy remaining bytes, avoid going past the end of num_bytes since there may be a redzone |
| 102 | // there. |
| 103 | while (num_bytes > 0) { |
| 104 | *reinterpret_cast<uint8_t*>(dst_bytes) = *reinterpret_cast<uint8_t*>(src_bytes); |
| 105 | src_bytes += sizeof(uint8_t); |
| 106 | dst_bytes += sizeof(uint8_t); |
| 107 | num_bytes -= sizeof(uint8_t); |
| 108 | } |
| 109 | } |
| 110 | |
Hiroshi Yamauchi | 2cd334a | 2015-01-09 14:03:35 -0800 | [diff] [blame] | 111 | if (kUseReadBarrier) { |
Mathieu Chartier | 0353698 | 2016-10-07 10:51:53 -0700 | [diff] [blame^] | 112 | // We need a RB here. After copying the whole object above, copy references fields one by one |
| 113 | // again with a RB to make sure there are no from space refs. TODO: Optimize this later? |
Hiroshi Yamauchi | 7971928 | 2014-04-10 12:46:22 -0700 | [diff] [blame] | 114 | CopyReferenceFieldsWithReadBarrierVisitor visitor(dest); |
Mathieu Chartier | 059ef3d | 2015-08-18 13:54:21 -0700 | [diff] [blame] | 115 | src->VisitReferences(visitor, visitor); |
Hiroshi Yamauchi | 7971928 | 2014-04-10 12:46:22 -0700 | [diff] [blame] | 116 | } |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 117 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 118 | // Perform write barriers on copied object references. |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 119 | Class* c = src->GetClass(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 120 | if (c->IsArrayClass()) { |
| 121 | if (!c->GetComponentType()->IsPrimitive()) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 122 | ObjectArray<Object>* array = dest->AsObjectArray<Object>(); |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 123 | heap->WriteBarrierArray(dest, 0, array->GetLength()); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 124 | } |
| 125 | } else { |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 126 | heap->WriteBarrierEveryFieldOf(dest); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 127 | } |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 128 | if (c->IsFinalizable()) { |
Mathieu Chartier | 8668c3c | 2014-04-24 16:48:11 -0700 | [diff] [blame] | 129 | heap->AddFinalizerReference(self, &dest); |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 130 | } |
| 131 | return dest; |
| 132 | } |
| 133 | |
Hiroshi Yamauchi | 4cd662e | 2014-04-03 16:28:10 -0700 | [diff] [blame] | 134 | // An allocation pre-fence visitor that copies the object. |
| 135 | class CopyObjectVisitor { |
| 136 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 137 | CopyObjectVisitor(Thread* self, Handle<Object>* orig, size_t num_bytes) |
Hiroshi Yamauchi | 4cd662e | 2014-04-03 16:28:10 -0700 | [diff] [blame] | 138 | : self_(self), orig_(orig), num_bytes_(num_bytes) { |
| 139 | } |
| 140 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 141 | void operator()(Object* obj, size_t usable_size ATTRIBUTE_UNUSED) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 142 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Hiroshi Yamauchi | 0fbd6e6 | 2014-07-17 16:16:31 -0700 | [diff] [blame] | 143 | Object::CopyObject(self_, obj, orig_->Get(), num_bytes_); |
Hiroshi Yamauchi | 4cd662e | 2014-04-03 16:28:10 -0700 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | private: |
| 147 | Thread* const self_; |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 148 | Handle<Object>* const orig_; |
Hiroshi Yamauchi | 4cd662e | 2014-04-03 16:28:10 -0700 | [diff] [blame] | 149 | const size_t num_bytes_; |
| 150 | DISALLOW_COPY_AND_ASSIGN(CopyObjectVisitor); |
| 151 | }; |
| 152 | |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 153 | Object* Object::Clone(Thread* self) { |
| 154 | CHECK(!IsClass()) << "Can't clone classes."; |
| 155 | // Object::SizeOf gets the right size even if we're an array. Using c->AllocObject() here would |
| 156 | // be wrong. |
| 157 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
| 158 | size_t num_bytes = SizeOf(); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 159 | StackHandleScope<1> hs(self); |
| 160 | Handle<Object> this_object(hs.NewHandle(this)); |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 161 | Object* copy; |
Hiroshi Yamauchi | 4cd662e | 2014-04-03 16:28:10 -0700 | [diff] [blame] | 162 | CopyObjectVisitor visitor(self, &this_object, num_bytes); |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 163 | if (heap->IsMovableObject(this)) { |
Hiroshi Yamauchi | 4cd662e | 2014-04-03 16:28:10 -0700 | [diff] [blame] | 164 | copy = heap->AllocObject<true>(self, GetClass(), num_bytes, visitor); |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 165 | } else { |
Hiroshi Yamauchi | 4cd662e | 2014-04-03 16:28:10 -0700 | [diff] [blame] | 166 | copy = heap->AllocNonMovableObject<true>(self, GetClass(), num_bytes, visitor); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 167 | } |
Mathieu Chartier | 0732d59 | 2013-11-06 11:02:50 -0800 | [diff] [blame] | 168 | return copy; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 169 | } |
| 170 | |
Ian Rogers | bbcd30b | 2014-10-30 15:25:36 -0700 | [diff] [blame] | 171 | uint32_t Object::GenerateIdentityHashCode() { |
Ian Rogers | bbcd30b | 2014-10-30 15:25:36 -0700 | [diff] [blame] | 172 | uint32_t expected_value, new_value; |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 173 | do { |
tony.ys_liu | 7380c31 | 2015-01-16 19:16:45 +0800 | [diff] [blame] | 174 | expected_value = hash_code_seed.LoadRelaxed(); |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 175 | new_value = expected_value * 1103515245 + 12345; |
tony.ys_liu | 7380c31 | 2015-01-16 19:16:45 +0800 | [diff] [blame] | 176 | } while (!hash_code_seed.CompareExchangeWeakRelaxed(expected_value, new_value) || |
| 177 | (expected_value & LockWord::kHashMask) == 0); |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 178 | return expected_value & LockWord::kHashMask; |
| 179 | } |
| 180 | |
tony.ys_liu | 7380c31 | 2015-01-16 19:16:45 +0800 | [diff] [blame] | 181 | void Object::SetHashCodeSeed(uint32_t new_seed) { |
| 182 | hash_code_seed.StoreRelaxed(new_seed); |
| 183 | } |
| 184 | |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 185 | int32_t Object::IdentityHashCode() const { |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 186 | mirror::Object* current_this = const_cast<mirror::Object*>(this); |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 187 | while (true) { |
Mathieu Chartier | 4d7f61d | 2014-04-17 14:43:39 -0700 | [diff] [blame] | 188 | LockWord lw = current_this->GetLockWord(false); |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 189 | switch (lw.GetState()) { |
| 190 | case LockWord::kUnlocked: { |
| 191 | // Try to compare and swap in a new hash, if we succeed we will return the hash on the next |
| 192 | // loop iteration. |
Mathieu Chartier | 36a270a | 2016-07-28 18:08:51 -0700 | [diff] [blame] | 193 | LockWord hash_word = LockWord::FromHashCode(GenerateIdentityHashCode(), lw.GCState()); |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 194 | DCHECK_EQ(hash_word.GetState(), LockWord::kHashCode); |
Hans Boehm | d843443 | 2014-07-11 09:56:07 -0700 | [diff] [blame] | 195 | if (const_cast<Object*>(this)->CasLockWordWeakRelaxed(lw, hash_word)) { |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 196 | return hash_word.GetHashCode(); |
| 197 | } |
| 198 | break; |
| 199 | } |
| 200 | case LockWord::kThinLocked: { |
Ian Rogers | 43c69cc | 2014-08-15 11:09:28 -0700 | [diff] [blame] | 201 | // Inflate the thin lock to a monitor and stick the hash code inside of the monitor. May |
| 202 | // fail spuriously. |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 203 | Thread* self = Thread::Current(); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 204 | StackHandleScope<1> hs(self); |
| 205 | Handle<mirror::Object> h_this(hs.NewHandle(current_this)); |
| 206 | Monitor::InflateThinLocked(self, h_this, lw, GenerateIdentityHashCode()); |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 207 | // A GC may have occurred when we switched to kBlocked. |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 208 | current_this = h_this.Get(); |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 209 | break; |
| 210 | } |
| 211 | case LockWord::kFatLocked: { |
Roland Levillain | 5120923 | 2016-03-11 16:27:27 +0000 | [diff] [blame] | 212 | // Already inflated, return the hash stored in the monitor. |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 213 | Monitor* monitor = lw.FatLockMonitor(); |
| 214 | DCHECK(monitor != nullptr); |
| 215 | return monitor->GetHashCode(); |
| 216 | } |
| 217 | case LockWord::kHashCode: { |
| 218 | return lw.GetHashCode(); |
| 219 | } |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 220 | default: { |
| 221 | LOG(FATAL) << "Invalid state during hashcode " << lw.GetState(); |
| 222 | break; |
| 223 | } |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 224 | } |
| 225 | } |
Ian Rogers | 0714083 | 2014-09-30 15:43:59 -0700 | [diff] [blame] | 226 | UNREACHABLE(); |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 227 | } |
| 228 | |
Mathieu Chartier | a058fdf | 2016-10-06 15:13:58 -0700 | [diff] [blame] | 229 | void Object::CheckFieldAssignmentImpl(MemberOffset field_offset, ObjPtr<Object> new_value) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 230 | Class* c = GetClass(); |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 231 | Runtime* runtime = Runtime::Current(); |
| 232 | if (runtime->GetClassLinker() == nullptr || !runtime->IsStarted() || |
| 233 | !runtime->GetHeap()->IsObjectValidationEnabled() || !c->IsResolved()) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 234 | return; |
| 235 | } |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 236 | for (Class* cur = c; cur != nullptr; cur = cur->GetSuperClass()) { |
Mathieu Chartier | 54d220e | 2015-07-30 16:20:06 -0700 | [diff] [blame] | 237 | for (ArtField& field : cur->GetIFields()) { |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 238 | StackHandleScope<1> hs(Thread::Current()); |
| 239 | Handle<Object> h_object(hs.NewHandle(new_value)); |
Mathieu Chartier | 54d220e | 2015-07-30 16:20:06 -0700 | [diff] [blame] | 240 | if (field.GetOffset().Int32Value() == field_offset.Int32Value()) { |
| 241 | CHECK_NE(field.GetTypeAsPrimitiveType(), Primitive::kPrimNot); |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 242 | // TODO: resolve the field type for moving GC. |
Mathieu Chartier | 3398c78 | 2016-09-30 10:27:43 -0700 | [diff] [blame] | 243 | ObjPtr<mirror::Class> field_type = field.GetType<!kMovingCollector>(); |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 244 | if (field_type != nullptr) { |
| 245 | CHECK(field_type->IsAssignableFrom(new_value->GetClass())); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 246 | } |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 247 | return; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 248 | } |
| 249 | } |
| 250 | } |
| 251 | if (c->IsArrayClass()) { |
| 252 | // Bounds and assign-ability done in the array setter. |
| 253 | return; |
| 254 | } |
| 255 | if (IsClass()) { |
Mathieu Chartier | 54d220e | 2015-07-30 16:20:06 -0700 | [diff] [blame] | 256 | for (ArtField& field : AsClass()->GetSFields()) { |
| 257 | if (field.GetOffset().Int32Value() == field_offset.Int32Value()) { |
| 258 | CHECK_NE(field.GetTypeAsPrimitiveType(), Primitive::kPrimNot); |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 259 | // TODO: resolve the field type for moving GC. |
Mathieu Chartier | 3398c78 | 2016-09-30 10:27:43 -0700 | [diff] [blame] | 260 | ObjPtr<mirror::Class> field_type = field.GetType<!kMovingCollector>(); |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 261 | if (field_type != nullptr) { |
| 262 | CHECK(field_type->IsAssignableFrom(new_value->GetClass())); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 263 | } |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 264 | return; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 265 | } |
| 266 | } |
| 267 | } |
| 268 | LOG(FATAL) << "Failed to find field for assignment to " << reinterpret_cast<void*>(this) |
| 269 | << " of type " << PrettyDescriptor(c) << " at offset " << field_offset; |
Ian Rogers | 08f1f50 | 2014-12-02 15:04:37 -0800 | [diff] [blame] | 270 | UNREACHABLE(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 271 | } |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 272 | |
Hiroshi Yamauchi | eb2baaf | 2015-05-13 21:14:22 -0700 | [diff] [blame] | 273 | ArtField* Object::FindFieldByOffset(MemberOffset offset) { |
| 274 | return IsClass() ? ArtField::FindStaticFieldWithOffset(AsClass(), offset.Uint32Value()) |
| 275 | : ArtField::FindInstanceFieldWithOffset(GetClass(), offset.Uint32Value()); |
| 276 | } |
| 277 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 278 | } // namespace mirror |
| 279 | } // namespace art |