diff options
| -rw-r--r-- | compiler/image_writer.cc | 10 | ||||
| -rw-r--r-- | compiler/image_writer.h | 3 | ||||
| -rw-r--r-- | runtime/class_linker.cc | 5 | ||||
| -rw-r--r-- | runtime/gc/heap.cc | 2 | ||||
| -rw-r--r-- | runtime/jit/jit_code_cache_test.cc | 2 | ||||
| -rw-r--r-- | runtime/length_prefixed_array.h | 10 | ||||
| -rw-r--r-- | runtime/mirror/class.h | 3 | ||||
| -rw-r--r-- | runtime/stride_iterator.h | 13 |
8 files changed, 32 insertions, 16 deletions
diff --git a/compiler/image_writer.cc b/compiler/image_writer.cc index 4ce3129f55..a03ff755ab 100644 --- a/compiler/image_writer.cc +++ b/compiler/image_writer.cc @@ -972,8 +972,10 @@ void ImageWriter::CalculateNewObjectOffsets() { size_t& offset = bin_slot_sizes_[BinTypeForNativeRelocationType(image_method_type)]; native_object_relocations_.emplace(&image_method_array_, NativeObjectRelocation { offset, image_method_type }); - CHECK_EQ(sizeof(image_method_array_), 8u); - offset += sizeof(image_method_array_); + const size_t array_size = LengthPrefixedArray<ArtMethod>::ComputeSize( + 0, ArtMethod::ObjectSize(target_ptr_size_)); + CHECK_ALIGNED(array_size, 8u); + offset += array_size; for (auto* m : image_methods_) { CHECK(m != nullptr); CHECK(m->IsRuntimeMethod()); @@ -1203,7 +1205,7 @@ void ImageWriter::FixupPointerArray(mirror::Object* dst, mirror::PointerArray* a if (elem != nullptr) { auto it = native_object_relocations_.find(elem); if (it == native_object_relocations_.end()) { - if (true) { + if (it->second.IsArtMethodRelocation()) { auto* method = reinterpret_cast<ArtMethod*>(elem); LOG(FATAL) << "No relocation entry for ArtMethod " << PrettyMethod(method) << " @ " << method << " idx=" << i << "/" << num_elements << " with declaring class " @@ -1300,8 +1302,8 @@ void* ImageWriter::NativeLocationInImage(void* obj) { return nullptr; } auto it = native_object_relocations_.find(obj); - const NativeObjectRelocation& relocation = it->second; CHECK(it != native_object_relocations_.end()) << obj; + const NativeObjectRelocation& relocation = it->second; return reinterpret_cast<void*>(image_begin_ + relocation.offset); } diff --git a/compiler/image_writer.h b/compiler/image_writer.h index eb6aa6f346..f4e10cc6ea 100644 --- a/compiler/image_writer.h +++ b/compiler/image_writer.h @@ -381,7 +381,8 @@ class ImageWriter FINAL { // Runtime ArtMethods which aren't reachable from any Class but need to be copied into the image. ArtMethod* image_methods_[ImageHeader::kImageMethodsCount]; - // Fake length prefixed array for image methods. + // Fake length prefixed array for image methods. This array does not contain the actual + // ArtMethods. We only use it for the header and relocation addresses. LengthPrefixedArray<ArtMethod> image_method_array_; // Counters for measurements, used for logging only. diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc index 48dc88d2b1..0886e327d9 100644 --- a/runtime/class_linker.cc +++ b/runtime/class_linker.cc @@ -4973,8 +4973,8 @@ bool ClassLinker::LinkInterfaceMethods(Thread* self, Handle<mirror::Class> klass LengthPrefixedArray<ArtMethod>::ComputeSize(old_method_count, method_size) : 0u; const size_t new_size = LengthPrefixedArray<ArtMethod>::ComputeSize(new_method_count, method_size); - auto* virtuals = new(runtime->GetLinearAlloc()->Realloc( - self, old_virtuals, old_size, new_size))LengthPrefixedArray<ArtMethod>(new_method_count); + auto* virtuals = reinterpret_cast<LengthPrefixedArray<ArtMethod>*>( + runtime->GetLinearAlloc()->Realloc(self, old_virtuals, old_size, new_size)); if (UNLIKELY(virtuals == nullptr)) { self->AssertPendingOOMException(); self->EndAssertNoThreadSuspension(old_cause); @@ -5002,6 +5002,7 @@ bool ClassLinker::LinkInterfaceMethods(Thread* self, Handle<mirror::Class> klass move_table.emplace(mir_method, &*out); ++out; } + virtuals->SetLength(new_method_count); UpdateClassVirtualMethods(klass.Get(), virtuals); // Done copying methods, they are all roots in the class now, so we can end the no thread // suspension assert. diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc index 59e39df9ee..e9d9065e56 100644 --- a/runtime/gc/heap.cc +++ b/runtime/gc/heap.cc @@ -2912,7 +2912,7 @@ class VerifyReferenceCardVisitor { if (!obj->IsObjectArray()) { mirror::Class* klass = is_static ? obj->AsClass() : obj->GetClass(); CHECK(klass != nullptr); - for (ArtField& field : is_static ? klass->GetSFields() : klass->GetIFields()) { + for (ArtField& field : (is_static ? klass->GetSFields() : klass->GetIFields())) { if (field.GetOffset().Int32Value() == offset.Int32Value()) { LOG(ERROR) << (is_static ? "Static " : "") << "field in the live stack is " << PrettyField(&field); diff --git a/runtime/jit/jit_code_cache_test.cc b/runtime/jit/jit_code_cache_test.cc index 555ad7c1d3..a6cbb710af 100644 --- a/runtime/jit/jit_code_cache_test.cc +++ b/runtime/jit/jit_code_cache_test.cc @@ -50,7 +50,7 @@ TEST_F(JitCodeCacheTest, TestCoverage) { ASSERT_TRUE(code_cache->ContainsCodePtr(reserved_code)); ASSERT_EQ(code_cache->NumMethods(), 1u); ClassLinker* const cl = Runtime::Current()->GetClassLinker(); - ArtMethod* method = &cl->AllocArtMethodArray(soa.Self(), 1)->At(0, 0); + ArtMethod* method = &cl->AllocArtMethodArray(soa.Self(), 1)->At(0); ASSERT_FALSE(code_cache->ContainsMethod(method)); method->SetEntryPointFromQuickCompiledCode(reserved_code); ASSERT_TRUE(code_cache->ContainsMethod(method)); diff --git a/runtime/length_prefixed_array.h b/runtime/length_prefixed_array.h index 82176e376d..2b2e8d34d2 100644 --- a/runtime/length_prefixed_array.h +++ b/runtime/length_prefixed_array.h @@ -48,16 +48,22 @@ class LengthPrefixedArray { return offsetof(LengthPrefixedArray<T>, data_) + index * element_size; } + // Alignment is the caller's responsibility. static size_t ComputeSize(size_t num_elements, size_t element_size = sizeof(T)) { - return sizeof(LengthPrefixedArray<T>) + num_elements * element_size; + return OffsetOfElement(num_elements, element_size); } uint64_t Length() const { return length_; } + // Update the length but does not reallocate storage. + void SetLength(uint64_t length) { + length_ = length; + } + private: - uint64_t length_; // 64 bits for padding reasons. + uint64_t length_; // 64 bits for 8 byte alignment of data_. uint8_t data_[0]; }; diff --git a/runtime/mirror/class.h b/runtime/mirror/class.h index f13893658c..513ab37033 100644 --- a/runtime/mirror/class.h +++ b/runtime/mirror/class.h @@ -1205,7 +1205,8 @@ class MANAGED Class FINAL : public Object { // listed in ifields; fields declared by a superclass are listed in // the superclass's Class.ifields. // - // ArtField arrays are allocated as an array of fields, and not an array of fields pointers. + // ArtFields are allocated as a length prefixed ArtField array, and not an array of pointers to + // ArtFields. uint64_t ifields_; // Static fields length-prefixed array. diff --git a/runtime/stride_iterator.h b/runtime/stride_iterator.h index c69f30ed5f..a9da51ba29 100644 --- a/runtime/stride_iterator.h +++ b/runtime/stride_iterator.h @@ -31,7 +31,7 @@ class StrideIterator : public std::iterator<std::forward_iterator_tag, T> { StrideIterator(T* ptr, size_t stride) : ptr_(reinterpret_cast<uintptr_t>(ptr)), - stride_(reinterpret_cast<uintptr_t>(stride)) {} + stride_(stride) {} bool operator==(const StrideIterator& other) const { DCHECK_EQ(stride_, other.stride_); @@ -48,17 +48,22 @@ class StrideIterator : public std::iterator<std::forward_iterator_tag, T> { } StrideIterator operator++(int) { - auto temp = *this; + StrideIterator<T> temp = *this; ptr_ += stride_; return temp; } StrideIterator operator+(ssize_t delta) const { - auto temp = *this; - temp.ptr_ += static_cast<ssize_t>(stride_) * delta; + StrideIterator<T> temp = *this; + temp += delta; return temp; } + StrideIterator& operator+=(ssize_t delta) { + ptr_ += static_cast<ssize_t>(stride_) * delta; + return *this; + } + T& operator*() const { return *reinterpret_cast<T*>(ptr_); } |