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_ARRAY_INL_H_ |
| 18 | #define ART_RUNTIME_MIRROR_OBJECT_ARRAY_INL_H_ |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 19 | |
Vladimir Marko | 80afd02 | 2015-05-19 18:08:00 +0100 | [diff] [blame] | 20 | #include <string> |
| 21 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 22 | #include "object_array.h" |
| 23 | |
Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 24 | #include "array-inl.h" |
Ian Rogers | 576ca0c | 2014-06-06 15:58:22 -0700 | [diff] [blame] | 25 | #include "base/stringprintf.h" |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 26 | #include "gc/heap.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 27 | #include "mirror/class.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 28 | #include "runtime.h" |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 29 | #include "handle_scope-inl.h" |
Sebastien Hertz | 6bdd8f4 | 2013-05-17 14:44:01 +0200 | [diff] [blame] | 30 | #include "thread.h" |
Vladimir Marko | 80afd02 | 2015-05-19 18:08:00 +0100 | [diff] [blame] | 31 | #include "utils.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 32 | |
| 33 | namespace art { |
| 34 | namespace mirror { |
| 35 | |
| 36 | template<class T> |
Mathieu Chartier | cbb2d20 | 2013-11-14 17:45:16 -0800 | [diff] [blame] | 37 | inline ObjectArray<T>* ObjectArray<T>::Alloc(Thread* self, Class* object_array_class, |
| 38 | int32_t length, gc::AllocatorType allocator_type) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 39 | Array* array = Array::Alloc<true>(self, object_array_class, length, |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 40 | ComponentSizeShiftWidth(sizeof(HeapReference<Object>)), |
Hiroshi Yamauchi | f0edfc3 | 2014-09-25 11:46:46 -0700 | [diff] [blame] | 41 | allocator_type); |
Mathieu Chartier | cbb2d20 | 2013-11-14 17:45:16 -0800 | [diff] [blame] | 42 | if (UNLIKELY(array == nullptr)) { |
| 43 | return nullptr; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 44 | } else { |
Hiroshi Yamauchi | f0edfc3 | 2014-09-25 11:46:46 -0700 | [diff] [blame] | 45 | DCHECK_EQ(array->GetClass()->GetComponentSizeShift(), |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 46 | ComponentSizeShiftWidth(sizeof(HeapReference<Object>))); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 47 | return array->AsObjectArray<T>(); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | template<class T> |
Mathieu Chartier | cbb2d20 | 2013-11-14 17:45:16 -0800 | [diff] [blame] | 52 | inline ObjectArray<T>* ObjectArray<T>::Alloc(Thread* self, Class* object_array_class, |
| 53 | int32_t length) { |
| 54 | return Alloc(self, object_array_class, length, |
| 55 | Runtime::Current()->GetHeap()->GetCurrentAllocator()); |
| 56 | } |
| 57 | |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 58 | template<class T> template<VerifyObjectFlags kVerifyFlags, ReadBarrierOption kReadBarrierOption> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 59 | inline T* ObjectArray<T>::Get(int32_t i) { |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 60 | if (!CheckIsValidIndex(i)) { |
Sebastien Hertz | abff643 | 2014-01-27 18:01:39 +0100 | [diff] [blame] | 61 | DCHECK(Thread::Current()->IsExceptionPending()); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 62 | return nullptr; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 63 | } |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 64 | return GetFieldObject<T, kVerifyFlags, kReadBarrierOption>(OffsetOfElement(i)); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 65 | } |
| 66 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 67 | template<class T> template<VerifyObjectFlags kVerifyFlags> |
Sebastien Hertz | 6bdd8f4 | 2013-05-17 14:44:01 +0200 | [diff] [blame] | 68 | inline bool ObjectArray<T>::CheckAssignable(T* object) { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 69 | if (object != nullptr) { |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 70 | Class* element_class = GetClass<kVerifyFlags>()->GetComponentType(); |
Sebastien Hertz | 6bdd8f4 | 2013-05-17 14:44:01 +0200 | [diff] [blame] | 71 | if (UNLIKELY(!object->InstanceOf(element_class))) { |
| 72 | ThrowArrayStoreException(object); |
| 73 | return false; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 74 | } |
Sebastien Hertz | 6bdd8f4 | 2013-05-17 14:44:01 +0200 | [diff] [blame] | 75 | } |
| 76 | return true; |
| 77 | } |
| 78 | |
| 79 | template<class T> |
| 80 | inline void ObjectArray<T>::Set(int32_t i, T* object) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 81 | if (Runtime::Current()->IsActiveTransaction()) { |
| 82 | Set<true>(i, object); |
| 83 | } else { |
| 84 | Set<false>(i, object); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | template<class T> |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 89 | template<bool kTransactionActive, bool kCheckTransaction, VerifyObjectFlags kVerifyFlags> |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 90 | inline void ObjectArray<T>::Set(int32_t i, T* object) { |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 91 | if (CheckIsValidIndex(i) && CheckAssignable<kVerifyFlags>(object)) { |
| 92 | SetFieldObject<kTransactionActive, kCheckTransaction, kVerifyFlags>(OffsetOfElement(i), object); |
Sebastien Hertz | 6bdd8f4 | 2013-05-17 14:44:01 +0200 | [diff] [blame] | 93 | } else { |
| 94 | DCHECK(Thread::Current()->IsExceptionPending()); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 95 | } |
| 96 | } |
| 97 | |
| 98 | template<class T> |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 99 | template<bool kTransactionActive, bool kCheckTransaction, VerifyObjectFlags kVerifyFlags> |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 100 | inline void ObjectArray<T>::SetWithoutChecks(int32_t i, T* object) { |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 101 | DCHECK(CheckIsValidIndex<kVerifyFlags>(i)); |
| 102 | DCHECK(CheckAssignable<static_cast<VerifyObjectFlags>(kVerifyFlags & ~kVerifyThis)>(object)); |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 103 | SetFieldObject<kTransactionActive, kCheckTransaction, kVerifyFlags>(OffsetOfElement(i), object); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | template<class T> |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 107 | template<bool kTransactionActive, bool kCheckTransaction, VerifyObjectFlags kVerifyFlags> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 108 | inline void ObjectArray<T>::SetWithoutChecksAndWriteBarrier(int32_t i, T* object) { |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 109 | DCHECK(CheckIsValidIndex<kVerifyFlags>(i)); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 110 | // TODO: enable this check. It fails when writing the image in ImageWriter::FixupObjectArray. |
Sebastien Hertz | abff643 | 2014-01-27 18:01:39 +0100 | [diff] [blame] | 111 | // DCHECK(CheckAssignable(object)); |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 112 | SetFieldObjectWithoutWriteBarrier<kTransactionActive, kCheckTransaction, kVerifyFlags>( |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 113 | OffsetOfElement(i), object); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | template<class T> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 117 | inline T* ObjectArray<T>::GetWithoutChecks(int32_t i) { |
Sebastien Hertz | abff643 | 2014-01-27 18:01:39 +0100 | [diff] [blame] | 118 | DCHECK(CheckIsValidIndex(i)); |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 119 | return GetFieldObject<T>(OffsetOfElement(i)); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | template<class T> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 123 | inline void ObjectArray<T>::AssignableMemmove(int32_t dst_pos, ObjectArray<T>* src, |
| 124 | int32_t src_pos, int32_t count) { |
| 125 | if (kIsDebugBuild) { |
| 126 | for (int i = 0; i < count; ++i) { |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 127 | // The get will perform the VerifyObject. |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 128 | src->GetWithoutChecks(src_pos + i); |
| 129 | } |
| 130 | } |
| 131 | // Perform the memmove using int memmove then perform the write barrier. |
Roland Levillain | 33d6903 | 2015-06-18 18:20:59 +0100 | [diff] [blame] | 132 | static_assert(sizeof(HeapReference<T>) == sizeof(uint32_t), |
| 133 | "art::mirror::HeapReference<T> and uint32_t have different sizes."); |
Mathieu Chartier | fec13d4 | 2016-10-07 12:59:33 -0700 | [diff] [blame] | 134 | // TODO: Optimize this later? |
| 135 | // We can't use memmove since it does not handle read barriers and may do by per byte copying. |
| 136 | // See b/32012820. |
| 137 | const bool copy_forward = (src != this) || (dst_pos < src_pos) || (dst_pos - src_pos >= count); |
| 138 | if (copy_forward) { |
| 139 | // Forward copy. |
| 140 | for (int i = 0; i < count; ++i) { |
| 141 | // We need a RB here. ObjectArray::GetWithoutChecks() contains a RB. |
| 142 | Object* obj = src->GetWithoutChecks(src_pos + i); |
| 143 | SetWithoutChecksAndWriteBarrier<false>(dst_pos + i, obj); |
Hiroshi Yamauchi | 7971928 | 2014-04-10 12:46:22 -0700 | [diff] [blame] | 144 | } |
| 145 | } else { |
Mathieu Chartier | fec13d4 | 2016-10-07 12:59:33 -0700 | [diff] [blame] | 146 | // Backward copy. |
| 147 | for (int i = count - 1; i >= 0; --i) { |
| 148 | // We need a RB here. ObjectArray::GetWithoutChecks() contains a RB. |
| 149 | Object* obj = src->GetWithoutChecks(src_pos + i); |
| 150 | SetWithoutChecksAndWriteBarrier<false>(dst_pos + i, obj); |
| 151 | } |
Hiroshi Yamauchi | 7971928 | 2014-04-10 12:46:22 -0700 | [diff] [blame] | 152 | } |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 153 | Runtime::Current()->GetHeap()->WriteBarrierArray(this, dst_pos, count); |
| 154 | if (kIsDebugBuild) { |
| 155 | for (int i = 0; i < count; ++i) { |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 156 | // The get will perform the VerifyObject. |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 157 | GetWithoutChecks(dst_pos + i); |
| 158 | } |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | template<class T> |
| 163 | inline void ObjectArray<T>::AssignableMemcpy(int32_t dst_pos, ObjectArray<T>* src, |
| 164 | int32_t src_pos, int32_t count) { |
| 165 | if (kIsDebugBuild) { |
| 166 | for (int i = 0; i < count; ++i) { |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 167 | // The get will perform the VerifyObject. |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 168 | src->GetWithoutChecks(src_pos + i); |
| 169 | } |
| 170 | } |
| 171 | // Perform the memmove using int memcpy then perform the write barrier. |
Roland Levillain | 33d6903 | 2015-06-18 18:20:59 +0100 | [diff] [blame] | 172 | static_assert(sizeof(HeapReference<T>) == sizeof(uint32_t), |
| 173 | "art::mirror::HeapReference<T> and uint32_t have different sizes."); |
Mathieu Chartier | fec13d4 | 2016-10-07 12:59:33 -0700 | [diff] [blame] | 174 | // TODO: Optimize this later? |
| 175 | // We can't use memmove since it does not handle read barriers and may do by per byte copying. |
| 176 | // See b/32012820. |
| 177 | for (int i = 0; i < count; ++i) { |
| 178 | // We need a RB here. ObjectArray::GetWithoutChecks() contains a RB. |
| 179 | T* obj = src->GetWithoutChecks(src_pos + i); |
| 180 | SetWithoutChecksAndWriteBarrier<false>(dst_pos + i, obj); |
Hiroshi Yamauchi | 7971928 | 2014-04-10 12:46:22 -0700 | [diff] [blame] | 181 | } |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 182 | Runtime::Current()->GetHeap()->WriteBarrierArray(this, dst_pos, count); |
| 183 | if (kIsDebugBuild) { |
| 184 | for (int i = 0; i < count; ++i) { |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 185 | // The get will perform the VerifyObject. |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 186 | GetWithoutChecks(dst_pos + i); |
| 187 | } |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | template<class T> |
Andreas Gampe | 85a098a | 2016-03-31 13:30:53 -0700 | [diff] [blame] | 192 | template<bool kTransactionActive> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 193 | inline void ObjectArray<T>::AssignableCheckingMemcpy(int32_t dst_pos, ObjectArray<T>* src, |
| 194 | int32_t src_pos, int32_t count, |
| 195 | bool throw_exception) { |
| 196 | DCHECK_NE(this, src) |
| 197 | << "This case should be handled with memmove that handles overlaps correctly"; |
| 198 | // We want to avoid redundant IsAssignableFrom checks where possible, so we cache a class that |
| 199 | // we know is assignable to the destination array's component type. |
| 200 | Class* dst_class = GetClass()->GetComponentType(); |
| 201 | Class* lastAssignableElementClass = dst_class; |
| 202 | |
| 203 | Object* o = nullptr; |
| 204 | int i = 0; |
| 205 | for (; i < count; ++i) { |
| 206 | // The follow get operations force the objects to be verified. |
Hiroshi Yamauchi | 7971928 | 2014-04-10 12:46:22 -0700 | [diff] [blame] | 207 | // We need a RB here. ObjectArray::GetWithoutChecks() contains a RB. |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 208 | o = src->GetWithoutChecks(src_pos + i); |
| 209 | if (o == nullptr) { |
| 210 | // Null is always assignable. |
Andreas Gampe | 85a098a | 2016-03-31 13:30:53 -0700 | [diff] [blame] | 211 | SetWithoutChecks<kTransactionActive>(dst_pos + i, nullptr); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 212 | } else { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 213 | // TODO: use the underlying class reference to avoid uncompression when not necessary. |
| 214 | Class* o_class = o->GetClass(); |
| 215 | if (LIKELY(lastAssignableElementClass == o_class)) { |
Andreas Gampe | 85a098a | 2016-03-31 13:30:53 -0700 | [diff] [blame] | 216 | SetWithoutChecks<kTransactionActive>(dst_pos + i, o); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 217 | } else if (LIKELY(dst_class->IsAssignableFrom(o_class))) { |
| 218 | lastAssignableElementClass = o_class; |
Andreas Gampe | 85a098a | 2016-03-31 13:30:53 -0700 | [diff] [blame] | 219 | SetWithoutChecks<kTransactionActive>(dst_pos + i, o); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 220 | } else { |
| 221 | // Can't put this element into the array, break to perform write-barrier and throw |
| 222 | // exception. |
| 223 | break; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 224 | } |
| 225 | } |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 226 | } |
| 227 | Runtime::Current()->GetHeap()->WriteBarrierArray(this, dst_pos, count); |
| 228 | if (UNLIKELY(i != count)) { |
| 229 | std::string actualSrcType(PrettyTypeOf(o)); |
| 230 | std::string dstType(PrettyTypeOf(this)); |
| 231 | Thread* self = Thread::Current(); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 232 | if (throw_exception) { |
Nicolas Geoffray | 0aa50ce | 2015-03-10 11:03:29 +0000 | [diff] [blame] | 233 | self->ThrowNewExceptionF("Ljava/lang/ArrayStoreException;", |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 234 | "source[%d] of type %s cannot be stored in destination array of type %s", |
| 235 | src_pos + i, actualSrcType.c_str(), dstType.c_str()); |
| 236 | } else { |
| 237 | LOG(FATAL) << StringPrintf("source[%d] of type %s cannot be stored in destination array of type %s", |
| 238 | src_pos + i, actualSrcType.c_str(), dstType.c_str()); |
| 239 | } |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 240 | } |
| 241 | } |
| 242 | |
| 243 | template<class T> |
| 244 | inline ObjectArray<T>* ObjectArray<T>::CopyOf(Thread* self, int32_t new_length) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 245 | DCHECK_GE(new_length, 0); |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 246 | // We may get copied by a compacting GC. |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 247 | StackHandleScope<1> hs(self); |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 248 | Handle<ObjectArray<T>> h_this(hs.NewHandle(this)); |
Mathieu Chartier | cbb2d20 | 2013-11-14 17:45:16 -0800 | [diff] [blame] | 249 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
| 250 | gc::AllocatorType allocator_type = heap->IsMovableObject(this) ? heap->GetCurrentAllocator() : |
| 251 | heap->GetCurrentNonMovingAllocator(); |
| 252 | ObjectArray<T>* new_array = Alloc(self, GetClass(), new_length, allocator_type); |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 253 | if (LIKELY(new_array != nullptr)) { |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 254 | new_array->AssignableMemcpy(0, h_this.Get(), 0, std::min(h_this->GetLength(), new_length)); |
Ian Rogers | a436fde | 2013-08-27 23:34:06 -0700 | [diff] [blame] | 255 | } |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 256 | return new_array; |
| 257 | } |
| 258 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 259 | template<class T> |
| 260 | inline MemberOffset ObjectArray<T>::OffsetOfElement(int32_t i) { |
| 261 | return MemberOffset(DataOffset(sizeof(HeapReference<Object>)).Int32Value() + |
| 262 | (i * sizeof(HeapReference<Object>))); |
| 263 | } |
| 264 | |
Mathieu Chartier | 059ef3d | 2015-08-18 13:54:21 -0700 | [diff] [blame] | 265 | template<class T> template<typename Visitor> |
Hiroshi Yamauchi | 723e6ce | 2015-10-28 20:59:47 -0700 | [diff] [blame] | 266 | inline void ObjectArray<T>::VisitReferences(const Visitor& visitor) { |
Mathieu Chartier | 407f702 | 2014-02-18 14:37:05 -0800 | [diff] [blame] | 267 | const size_t length = static_cast<size_t>(GetLength()); |
| 268 | for (size_t i = 0; i < length; ++i) { |
| 269 | visitor(this, OffsetOfElement(i), false); |
| 270 | } |
| 271 | } |
| 272 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 273 | } // namespace mirror |
| 274 | } // namespace art |
| 275 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 276 | #endif // ART_RUNTIME_MIRROR_OBJECT_ARRAY_INL_H_ |