Remove the relocations section from the image.
This section was unused since
https://android-review.googlesource.com/771001 .
This partially reverts commits
6121aa69098e3496cf1a81bf3e5e7ae70f66eacb
ca8de0a70eab62707f3c71a211093f340fdcd5f4
and cleans up.
Prebuilt sizes for aosp_taimen-userdebug:
- before:
arm/boot*.art: 14951820
arm64/boot*.art: 19398428
oat/arm64/services.art: 526138
- after:
arm/boot*.art: 14503936 (-437KiB)
arm64/boot*.art: 18817024 (-568KiB)
oat/arm64/services.art: 499712 (-26KiB)
Test: m test-art-host-gtest
Test: testrunner.py --host --optimizing
Test: Pixel 2 XL boots.
Test: m test-art-target-gtest
Test: testrunner.py --target --optimizing
Bug: 77856493
Change-Id: Ib44cd00cf3944e93e2d61ca8df381993cfeff130
diff --git a/dex2oat/linker/image_writer.cc b/dex2oat/linker/image_writer.cc
index 6410c7a..ddc9f43 100644
--- a/dex2oat/linker/image_writer.cc
+++ b/dex2oat/linker/image_writer.cc
@@ -27,7 +27,6 @@
#include "art_field-inl.h"
#include "art_method-inl.h"
-#include "base/bit_memory_region.h"
#include "base/callee_save_type.h"
#include "base/enums.h"
#include "base/globals.h"
@@ -88,14 +87,6 @@
namespace art {
namespace linker {
-static inline size_t RelocationIndex(size_t relocation_offset, PointerSize target_ptr_size) {
- static_assert(sizeof(GcRoot<mirror::Object>) == sizeof(mirror::HeapReference<mirror::Object>),
- "Expecting heap GC roots and references to have the same size.");
- DCHECK_LE(sizeof(GcRoot<mirror::Object>), static_cast<size_t>(target_ptr_size));
- DCHECK_ALIGNED(relocation_offset, sizeof(GcRoot<mirror::Object>));
- return relocation_offset / sizeof(GcRoot<mirror::Object>);
-}
-
static ArrayRef<const uint8_t> MaybeCompressData(ArrayRef<const uint8_t> source,
ImageHeader::StorageMode image_storage_mode,
/*out*/ std::vector<uint8_t>* storage) {
@@ -672,22 +663,6 @@
return false;
}
- // Write out relocations.
- size_t relocations_position_in_file = bitmap_position_in_file + bitmap_section.Size();
- ArrayRef<const uint8_t> relocations = MaybeCompressData(
- ArrayRef<const uint8_t>(image_info.relocation_bitmap_),
- image_storage_mode_,
- &compressed_data);
- image_header->sections_[ImageHeader::kSectionImageRelocations] =
- ImageSection(bitmap_section.Offset() + bitmap_section.Size(), relocations.size());
- if (!image_file->PwriteFully(relocations.data(),
- relocations.size(),
- relocations_position_in_file)) {
- PLOG(ERROR) << "Failed to write image file relocations " << image_filename;
- image_file->Erase();
- return false;
- }
-
int err = image_file->Flush();
if (err < 0) {
PLOG(ERROR) << "Failed to flush image file " << image_filename << " with result " << err;
@@ -708,9 +683,7 @@
}
if (VLOG_IS_ON(compiler)) {
- size_t separately_written_section_size = bitmap_section.Size() +
- image_header->GetImageRelocationsSection().Size() +
- sizeof(ImageHeader);
+ size_t separately_written_section_size = bitmap_section.Size() + sizeof(ImageHeader);
size_t total_uncompressed_size = raw_image_data.size() + separately_written_section_size,
total_compressed_size = image_data.size() + separately_written_section_size;
@@ -721,7 +694,7 @@
}
}
- CHECK_EQ(relocations_position_in_file + relocations.size(),
+ CHECK_EQ(bitmap_position_in_file + bitmap_section.Size(),
static_cast<size_t>(image_file->GetLength()));
if (image_file->FlushCloseOrErase() != 0) {
@@ -2366,8 +2339,6 @@
const size_t bitmap_bytes = image_info.image_bitmap_->Size();
auto* bitmap_section = §ions[ImageHeader::kSectionImageBitmap];
*bitmap_section = ImageSection(RoundUp(image_end, kPageSize), RoundUp(bitmap_bytes, kPageSize));
- // The relocations section shall be finished later as we do not know its actual size yet.
-
if (VLOG_IS_ON(compiler)) {
LOG(INFO) << "Creating header for " << oat_filenames_[oat_index];
size_t idx = 0;
@@ -2394,7 +2365,7 @@
// Create the header, leave 0 for data size since we will fill this in as we are writing the
// image.
- ImageHeader* header = new (image_info.image_.Begin()) ImageHeader(
+ new (image_info.image_.Begin()) ImageHeader(
PointerToLowMemUInt32(image_info.image_begin_),
image_end,
sections.data(),
@@ -2411,28 +2382,6 @@
static_cast<uint32_t>(target_ptr_size_),
image_storage_mode_,
/*data_size*/0u);
-
- // Resize relocation bitmap for recording reference/pointer relocations.
- size_t number_of_relocation_locations = RelocationIndex(image_end, target_ptr_size_);
- DCHECK(image_info.relocation_bitmap_.empty());
- image_info.relocation_bitmap_.resize(
- BitsToBytesRoundUp(number_of_relocation_locations * (compile_app_image_ ? 2u : 1u)));
- // Record header relocations.
- RecordImageRelocation(&header->image_begin_, oat_index);
- RecordImageRelocation(&header->oat_file_begin_, oat_index);
- RecordImageRelocation(&header->oat_data_begin_, oat_index);
- RecordImageRelocation(&header->oat_data_end_, oat_index);
- RecordImageRelocation(&header->oat_file_end_, oat_index);
- if (compile_app_image_) {
- RecordImageRelocation(&header->boot_image_begin_, oat_index, /* app_to_boot_image */ true);
- RecordImageRelocation(&header->boot_oat_begin_, oat_index, /* app_to_boot_image */ true);
- } else {
- DCHECK_EQ(header->boot_image_begin_, 0u);
- DCHECK_EQ(header->boot_oat_begin_, 0u);
- }
- RecordImageRelocation(&header->image_roots_, oat_index);
- // Skip non-null check for `patch_delta_` as it is actually 0 but still needs to be recorded.
- RecordImageRelocation</* kCheckNotNull */ false>(&header->patch_delta_, oat_index);
}
ArtMethod* ImageWriter::GetImageMethodAddress(ArtMethod* method) {
@@ -2492,28 +2441,23 @@
ImageWriter* const image_writer_;
};
-void ImageWriter::CopyAndFixupImTable(ImTable* orig, ImTable* copy, size_t oat_index) {
+void ImageWriter::CopyAndFixupImTable(ImTable* orig, ImTable* copy) {
for (size_t i = 0; i < ImTable::kSize; ++i) {
ArtMethod* method = orig->Get(i, target_ptr_size_);
void** address = reinterpret_cast<void**>(copy->AddressOfElement(i, target_ptr_size_));
- CopyAndFixupPointer(address, method, oat_index);
+ CopyAndFixupPointer(address, method);
DCHECK_EQ(copy->Get(i, target_ptr_size_), NativeLocationInImage(method));
}
}
-void ImageWriter::CopyAndFixupImtConflictTable(ImtConflictTable* orig,
- ImtConflictTable* copy,
- size_t oat_index) {
+void ImageWriter::CopyAndFixupImtConflictTable(ImtConflictTable* orig, ImtConflictTable* copy) {
const size_t count = orig->NumEntries(target_ptr_size_);
for (size_t i = 0; i < count; ++i) {
ArtMethod* interface_method = orig->GetInterfaceMethod(i, target_ptr_size_);
ArtMethod* implementation_method = orig->GetImplementationMethod(i, target_ptr_size_);
- CopyAndFixupPointer(copy->AddressOfInterfaceMethod(i, target_ptr_size_),
- interface_method,
- oat_index);
- CopyAndFixupPointer(copy->AddressOfImplementationMethod(i, target_ptr_size_),
- implementation_method,
- oat_index);
+ CopyAndFixupPointer(copy->AddressOfInterfaceMethod(i, target_ptr_size_), interface_method);
+ CopyAndFixupPointer(
+ copy->AddressOfImplementationMethod(i, target_ptr_size_), implementation_method);
DCHECK_EQ(copy->GetInterfaceMethod(i, target_ptr_size_),
NativeLocationInImage(interface_method));
DCHECK_EQ(copy->GetImplementationMethod(i, target_ptr_size_),
@@ -2538,8 +2482,7 @@
memcpy(dest, pair.first, sizeof(ArtField));
CopyAndFixupReference(
reinterpret_cast<ArtField*>(dest)->GetDeclaringClassAddressWithoutBarrier(),
- reinterpret_cast<ArtField*>(pair.first)->GetDeclaringClass(),
- oat_index);
+ reinterpret_cast<ArtField*>(pair.first)->GetDeclaringClass());
break;
}
case NativeObjectRelocationType::kRuntimeMethod:
@@ -2572,15 +2515,14 @@
case NativeObjectRelocationType::kIMTable: {
ImTable* orig_imt = reinterpret_cast<ImTable*>(pair.first);
ImTable* dest_imt = reinterpret_cast<ImTable*>(dest);
- CopyAndFixupImTable(orig_imt, dest_imt, oat_index);
+ CopyAndFixupImTable(orig_imt, dest_imt);
break;
}
case NativeObjectRelocationType::kIMTConflictTable: {
auto* orig_table = reinterpret_cast<ImtConflictTable*>(pair.first);
CopyAndFixupImtConflictTable(
orig_table,
- new(dest)ImtConflictTable(orig_table->NumEntries(target_ptr_size_), target_ptr_size_),
- oat_index);
+ new(dest)ImtConflictTable(orig_table->NumEntries(target_ptr_size_), target_ptr_size_));
break;
}
}
@@ -2590,10 +2532,8 @@
for (size_t i = 0; i < ImageHeader::kImageMethodsCount; ++i) {
ArtMethod* method = image_methods_[i];
CHECK(method != nullptr);
- CopyAndFixupPointer(reinterpret_cast<void**>(&image_header->image_methods_[i]),
- method,
- oat_index,
- PointerSize::k32);
+ CopyAndFixupPointer(
+ reinterpret_cast<void**>(&image_header->image_methods_[i]), method, PointerSize::k32);
}
FixupRootVisitor root_visitor(this);
@@ -2618,9 +2558,6 @@
MutexLock lock(Thread::Current(), *Locks::intern_table_lock_);
DCHECK(!temp_intern_table.strong_interns_.tables_.empty());
DCHECK(!temp_intern_table.strong_interns_.tables_[0].empty()); // Inserted at the beginning.
- for (const GcRoot<mirror::String>& slot : temp_intern_table.strong_interns_.tables_[0]) {
- RecordImageRelocation(&slot, oat_index);
- }
}
// Write the class table(s) into the image. class_table_bytes_ may be 0 if there are multiple
// class loaders. Writing multiple class tables into the image is currently unsupported.
@@ -2649,9 +2586,6 @@
ReaderMutexLock lock(self, temp_class_table.lock_);
DCHECK(!temp_class_table.classes_.empty());
DCHECK(!temp_class_table.classes_[0].empty()); // The ClassSet was inserted at the beginning.
- for (const ClassTable::TableSlot& slot : temp_class_table.classes_[0]) {
- RecordImageRelocation(&slot, oat_index);
- }
}
}
@@ -2668,15 +2602,13 @@
void ImageWriter::FixupPointerArray(mirror::Object* dst,
mirror::PointerArray* arr,
mirror::Class* klass,
- Bin array_type,
- size_t oat_index) {
+ Bin array_type) {
CHECK(klass->IsArrayClass());
CHECK(arr->IsIntArray() || arr->IsLongArray()) << klass->PrettyClass() << " " << arr;
// Fixup int and long pointers for the ArtMethod or ArtField arrays.
const size_t num_elements = arr->GetLength();
- CopyAndFixupReference(dst->GetFieldObjectReferenceAddr<kVerifyNone>(Class::ClassOffset()),
- arr->GetClass(),
- oat_index);
+ CopyAndFixupReference(
+ dst->GetFieldObjectReferenceAddr<kVerifyNone>(Class::ClassOffset()), arr->GetClass());
auto* dest_array = down_cast<mirror::PointerArray*>(dst);
for (size_t i = 0, count = num_elements; i < count; ++i) {
void* elem = arr->GetElementPtrSize<void*>(i, target_ptr_size_);
@@ -2698,7 +2630,7 @@
UNREACHABLE();
}
}
- CopyAndFixupPointer(dest_array->ElementAddress(i, target_ptr_size_), elem, oat_index);
+ CopyAndFixupPointer(dest_array->ElementAddress(i, target_ptr_size_), elem);
}
}
@@ -2729,14 +2661,14 @@
// safe since we mark all of the objects that may reference non immune objects as gray.
CHECK(dst->AtomicSetMarkBit(0, 1));
}
- FixupObject(obj, dst, oat_index);
+ FixupObject(obj, dst);
}
// Rewrite all the references in the copied object to point to their image address equivalent
class ImageWriter::FixupVisitor {
public:
- FixupVisitor(ImageWriter* image_writer, Object* copy, size_t oat_index)
- : image_writer_(image_writer), copy_(copy), oat_index_(oat_index) {
+ FixupVisitor(ImageWriter* image_writer, Object* copy)
+ : image_writer_(image_writer), copy_(copy) {
}
// Ignore class roots since we don't have a way to map them to the destination. These are handled
@@ -2751,9 +2683,7 @@
ObjPtr<Object> ref = obj->GetFieldObject<Object, kVerifyNone>(offset);
// Copy the reference and record the fixup if necessary.
image_writer_->CopyAndFixupReference(
- copy_->GetFieldObjectReferenceAddr<kVerifyNone>(offset),
- ref.Ptr(),
- oat_index_);
+ copy_->GetFieldObjectReferenceAddr<kVerifyNone>(offset), ref);
}
// java.lang.ref.Reference visitor.
@@ -2766,13 +2696,12 @@
protected:
ImageWriter* const image_writer_;
mirror::Object* const copy_;
- size_t oat_index_;
};
class ImageWriter::FixupClassVisitor final : public FixupVisitor {
public:
- FixupClassVisitor(ImageWriter* image_writer, Object* copy, size_t oat_index)
- : FixupVisitor(image_writer, copy, oat_index) {}
+ FixupClassVisitor(ImageWriter* image_writer, Object* copy)
+ : FixupVisitor(image_writer, copy) {}
void operator()(ObjPtr<Object> obj, MemberOffset offset, bool is_static ATTRIBUTE_UNUSED) const
REQUIRES(Locks::mutator_lock_, Locks::heap_bitmap_lock_) {
@@ -2828,14 +2757,13 @@
class ImageWriter::NativeLocationVisitor {
public:
- NativeLocationVisitor(ImageWriter* image_writer, size_t oat_index)
- : image_writer_(image_writer),
- oat_index_(oat_index) {}
+ explicit NativeLocationVisitor(ImageWriter* image_writer)
+ : image_writer_(image_writer) {}
template <typename T>
T* operator()(T* ptr, void** dest_addr) const REQUIRES_SHARED(Locks::mutator_lock_) {
if (ptr != nullptr) {
- image_writer_->CopyAndFixupPointer(dest_addr, ptr, oat_index_);
+ image_writer_->CopyAndFixupPointer(dest_addr, ptr);
}
// TODO: The caller shall overwrite the value stored by CopyAndFixupPointer()
// with the value we return here. We should try to avoid the duplicate work.
@@ -2844,12 +2772,11 @@
private:
ImageWriter* const image_writer_;
- const size_t oat_index_;
};
-void ImageWriter::FixupClass(mirror::Class* orig, mirror::Class* copy, size_t oat_index) {
- orig->FixupNativePointers(copy, target_ptr_size_, NativeLocationVisitor(this, oat_index));
- FixupClassVisitor visitor(this, copy, oat_index);
+void ImageWriter::FixupClass(mirror::Class* orig, mirror::Class* copy) {
+ orig->FixupNativePointers(copy, target_ptr_size_, NativeLocationVisitor(this));
+ FixupClassVisitor visitor(this, copy);
ObjPtr<mirror::Object>(orig)->VisitReferences(visitor, visitor);
if (kBitstringSubtypeCheckEnabled && compile_app_image_) {
@@ -2877,7 +2804,7 @@
copy->SetClinitThreadId(static_cast<pid_t>(0));
}
-void ImageWriter::FixupObject(Object* orig, Object* copy, size_t oat_index) {
+void ImageWriter::FixupObject(Object* orig, Object* copy) {
DCHECK(orig != nullptr);
DCHECK(copy != nullptr);
if (kUseBakerReadBarrier) {
@@ -2889,13 +2816,13 @@
auto it = pointer_arrays_.find(down_cast<mirror::PointerArray*>(orig));
if (it != pointer_arrays_.end()) {
// Should only need to fixup every pointer array exactly once.
- FixupPointerArray(copy, down_cast<mirror::PointerArray*>(orig), klass, it->second, oat_index);
+ FixupPointerArray(copy, down_cast<mirror::PointerArray*>(orig), klass, it->second);
pointer_arrays_.erase(it);
return;
}
}
if (orig->IsClass()) {
- FixupClass(orig->AsClass<kVerifyNone>(), down_cast<mirror::Class*>(copy), oat_index);
+ FixupClass(orig->AsClass<kVerifyNone>(), down_cast<mirror::Class*>(copy));
} else {
ObjPtr<mirror::ObjectArray<mirror::Class>> class_roots =
Runtime::Current()->GetClassLinker()->GetClassRoots();
@@ -2905,11 +2832,9 @@
auto* dest = down_cast<mirror::Executable*>(copy);
auto* src = down_cast<mirror::Executable*>(orig);
ArtMethod* src_method = src->GetArtMethod();
- CopyAndFixupPointer(dest, mirror::Executable::ArtMethodOffset(), src_method, oat_index);
+ CopyAndFixupPointer(dest, mirror::Executable::ArtMethodOffset(), src_method);
} else if (klass == GetClassRoot<mirror::DexCache>(class_roots)) {
- FixupDexCache(down_cast<mirror::DexCache*>(orig),
- down_cast<mirror::DexCache*>(copy),
- oat_index);
+ FixupDexCache(down_cast<mirror::DexCache*>(orig), down_cast<mirror::DexCache*>(copy));
} else if (klass->IsClassLoaderClass()) {
mirror::ClassLoader* copy_loader = down_cast<mirror::ClassLoader*>(copy);
// If src is a ClassLoader, set the class table to null so that it gets recreated by the
@@ -2920,7 +2845,7 @@
// roots.
copy_loader->SetAllocator(nullptr);
}
- FixupVisitor visitor(this, copy, oat_index);
+ FixupVisitor visitor(this, copy);
orig->VisitReferences(visitor, visitor);
}
}
@@ -2928,8 +2853,7 @@
template <typename T>
void ImageWriter::FixupDexCacheArrayEntry(std::atomic<mirror::DexCachePair<T>>* orig_array,
std::atomic<mirror::DexCachePair<T>>* new_array,
- uint32_t array_index,
- size_t oat_index) {
+ uint32_t array_index) {
static_assert(sizeof(std::atomic<mirror::DexCachePair<T>>) == sizeof(mirror::DexCachePair<T>),
"Size check for removing std::atomic<>.");
mirror::DexCachePair<T>* orig_pair =
@@ -2937,15 +2861,14 @@
mirror::DexCachePair<T>* new_pair =
reinterpret_cast<mirror::DexCachePair<T>*>(&new_array[array_index]);
CopyAndFixupReference(
- new_pair->object.AddressWithoutBarrier(), orig_pair->object.Read(), oat_index);
+ new_pair->object.AddressWithoutBarrier(), orig_pair->object.Read());
new_pair->index = orig_pair->index;
}
template <typename T>
void ImageWriter::FixupDexCacheArrayEntry(std::atomic<mirror::NativeDexCachePair<T>>* orig_array,
std::atomic<mirror::NativeDexCachePair<T>>* new_array,
- uint32_t array_index,
- size_t oat_index) {
+ uint32_t array_index) {
static_assert(
sizeof(std::atomic<mirror::NativeDexCachePair<T>>) == sizeof(mirror::NativeDexCachePair<T>),
"Size check for removing std::atomic<>.");
@@ -2956,9 +2879,8 @@
reinterpret_cast<DexCache::ConversionPair64*>(new_array) + array_index;
*new_pair = *orig_pair; // Copy original value and index.
if (orig_pair->first != 0u) {
- CopyAndFixupPointer(reinterpret_cast<void**>(&new_pair->first),
- reinterpret_cast64<void*>(orig_pair->first),
- oat_index);
+ CopyAndFixupPointer(
+ reinterpret_cast<void**>(&new_pair->first), reinterpret_cast64<void*>(orig_pair->first));
}
} else {
DexCache::ConversionPair32* orig_pair =
@@ -2967,26 +2889,22 @@
reinterpret_cast<DexCache::ConversionPair32*>(new_array) + array_index;
*new_pair = *orig_pair; // Copy original value and index.
if (orig_pair->first != 0u) {
- CopyAndFixupPointer(reinterpret_cast<void**>(&new_pair->first),
- reinterpret_cast32<void*>(orig_pair->first),
- oat_index);
+ CopyAndFixupPointer(
+ reinterpret_cast<void**>(&new_pair->first), reinterpret_cast32<void*>(orig_pair->first));
}
}
}
void ImageWriter::FixupDexCacheArrayEntry(GcRoot<mirror::CallSite>* orig_array,
GcRoot<mirror::CallSite>* new_array,
- uint32_t array_index,
- size_t oat_index) {
- CopyAndFixupReference(new_array[array_index].AddressWithoutBarrier(),
- orig_array[array_index].Read(),
- oat_index);
+ uint32_t array_index) {
+ CopyAndFixupReference(
+ new_array[array_index].AddressWithoutBarrier(), orig_array[array_index].Read());
}
template <typename EntryType>
void ImageWriter::FixupDexCacheArray(DexCache* orig_dex_cache,
DexCache* copy_dex_cache,
- size_t oat_index,
MemberOffset array_offset,
uint32_t size) {
EntryType* orig_array = orig_dex_cache->GetFieldPtr64<EntryType*>(array_offset);
@@ -2994,45 +2912,37 @@
if (orig_array != nullptr) {
// Though the DexCache array fields are usually treated as native pointers, we clear
// the top 32 bits for 32-bit targets.
- CopyAndFixupPointer(copy_dex_cache, array_offset, orig_array, oat_index, PointerSize::k64);
+ CopyAndFixupPointer(copy_dex_cache, array_offset, orig_array, PointerSize::k64);
EntryType* new_array = NativeCopyLocation(orig_array);
for (uint32_t i = 0; i != size; ++i) {
- FixupDexCacheArrayEntry(orig_array, new_array, i, oat_index);
+ FixupDexCacheArrayEntry(orig_array, new_array, i);
}
}
}
-void ImageWriter::FixupDexCache(DexCache* orig_dex_cache,
- DexCache* copy_dex_cache,
- size_t oat_index) {
+void ImageWriter::FixupDexCache(DexCache* orig_dex_cache, DexCache* copy_dex_cache) {
FixupDexCacheArray<mirror::StringDexCacheType>(orig_dex_cache,
copy_dex_cache,
- oat_index,
DexCache::StringsOffset(),
orig_dex_cache->NumStrings());
FixupDexCacheArray<mirror::TypeDexCacheType>(orig_dex_cache,
copy_dex_cache,
- oat_index,
DexCache::ResolvedTypesOffset(),
orig_dex_cache->NumResolvedTypes());
FixupDexCacheArray<mirror::MethodDexCacheType>(orig_dex_cache,
copy_dex_cache,
- oat_index,
DexCache::ResolvedMethodsOffset(),
orig_dex_cache->NumResolvedMethods());
FixupDexCacheArray<mirror::FieldDexCacheType>(orig_dex_cache,
copy_dex_cache,
- oat_index,
DexCache::ResolvedFieldsOffset(),
orig_dex_cache->NumResolvedFields());
FixupDexCacheArray<mirror::MethodTypeDexCacheType>(orig_dex_cache,
copy_dex_cache,
- oat_index,
DexCache::ResolvedMethodTypesOffset(),
orig_dex_cache->NumResolvedMethodTypes());
FixupDexCacheArray<GcRoot<mirror::CallSite>>(orig_dex_cache,
copy_dex_cache,
- oat_index,
DexCache::ResolvedCallSitesOffset(),
orig_dex_cache->NumResolvedCallSites());
@@ -3141,9 +3051,8 @@
memcpy(copy, orig, ArtMethod::Size(target_ptr_size_));
- CopyAndFixupReference(copy->GetDeclaringClassAddressWithoutBarrier(),
- orig->GetDeclaringClassUnchecked(),
- oat_index);
+ CopyAndFixupReference(
+ copy->GetDeclaringClassAddressWithoutBarrier(), orig->GetDeclaringClassUnchecked());
// OatWriter replaces the code_ with an offset value. Here we re-adjust to a pointer relative to
// oat_begin_
@@ -3156,7 +3065,7 @@
if (orig_table != nullptr) {
// Special IMT conflict method, normal IMT conflict method or unimplemented IMT method.
quick_code = GetOatAddress(StubType::kQuickIMTConflictTrampoline);
- CopyAndFixupPointer(copy, ArtMethod::DataOffset(target_ptr_size_), orig_table, oat_index);
+ CopyAndFixupPointer(copy, ArtMethod::DataOffset(target_ptr_size_), orig_table);
} else if (UNLIKELY(orig == runtime->GetResolutionMethod())) {
quick_code = GetOatAddress(StubType::kQuickResolutionTrampoline);
} else {
@@ -3190,9 +3099,6 @@
// Note this is not the code_ pointer, that is handled above.
copy->SetEntryPointFromJniPtrSize(
GetOatAddress(StubType::kJNIDlsymLookup), target_ptr_size_);
- MemberOffset offset = ArtMethod::EntryPointFromJniOffset(target_ptr_size_);
- const void* dest = reinterpret_cast<const uint8_t*>(copy) + offset.Uint32Value();
- RecordImageRelocation(dest, oat_index, /* app_to_boot_image */ compile_app_image_);
} else {
CHECK(copy->GetDataPtrSize(target_ptr_size_) == nullptr);
}
@@ -3200,9 +3106,6 @@
}
if (quick_code != nullptr) {
copy->SetEntryPointFromQuickCompiledCodePtrSize(quick_code, target_ptr_size_);
- MemberOffset offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(target_ptr_size_);
- const void* dest = reinterpret_cast<const uint8_t*>(copy) + offset.Uint32Value();
- RecordImageRelocation(dest, oat_index, /* app_to_boot_image */ IsInBootOatFile(quick_code));
}
}
@@ -3366,55 +3269,15 @@
: intern_table_(new InternTable),
class_table_(new ClassTable) {}
-template <bool kCheckNotNull /* = true */>
-void ImageWriter::RecordImageRelocation(const void* dest,
- size_t oat_index,
- bool app_to_boot_image /* = false */) {
- // Check that we're not recording a relocation for null.
- if (kCheckNotNull) {
- DCHECK(reinterpret_cast<const uint32_t*>(dest)[0] != 0u);
- }
- // Calculate the offset within the image.
- ImageInfo* image_info = &image_infos_[oat_index];
- DCHECK(image_info->image_.HasAddress(dest))
- << "MemMap range " << static_cast<const void*>(image_info->image_.Begin())
- << "-" << static_cast<const void*>(image_info->image_.End())
- << " does not contain " << dest;
- size_t offset = reinterpret_cast<const uint8_t*>(dest) - image_info->image_.Begin();
- ImageHeader* const image_header = reinterpret_cast<ImageHeader*>(image_info->image_.Begin());
- size_t image_end = image_header->GetClassTableSection().End();
- DCHECK_LT(offset, image_end);
- // Calculate the location index.
- size_t size = RelocationIndex(image_end, target_ptr_size_);
- size_t index = RelocationIndex(offset, target_ptr_size_);
- if (app_to_boot_image) {
- index += size;
- }
- // Mark the location in the bitmap.
- DCHECK(compile_app_image_ || !app_to_boot_image);
- MemoryRegion region(image_info->relocation_bitmap_.data(), image_info->relocation_bitmap_.size());
- BitMemoryRegion bit_region(region, /* bit_offset */ 0u, compile_app_image_ ? 2u * size : size);
- DCHECK(!bit_region.LoadBit(index));
- bit_region.StoreBit(index, /* value*/ true);
-}
-
template <typename DestType>
-void ImageWriter::CopyAndFixupReference(DestType* dest,
- ObjPtr<mirror::Object> src,
- size_t oat_index) {
+void ImageWriter::CopyAndFixupReference(DestType* dest, ObjPtr<mirror::Object> src) {
static_assert(std::is_same<DestType, mirror::CompressedReference<mirror::Object>>::value ||
std::is_same<DestType, mirror::HeapReference<mirror::Object>>::value,
"DestType must be a Compressed-/HeapReference<Object>.");
dest->Assign(GetImageAddress(src.Ptr()));
- if (src != nullptr) {
- RecordImageRelocation(dest, oat_index, /* app_to_boot_image */ IsInBootImage(src.Ptr()));
- }
}
-void ImageWriter::CopyAndFixupPointer(void** target,
- void* value,
- size_t oat_index,
- PointerSize pointer_size) {
+void ImageWriter::CopyAndFixupPointer(void** target, void* value, PointerSize pointer_size) {
void* new_value = NativeLocationInImage(value);
if (pointer_size == PointerSize::k32) {
*reinterpret_cast<uint32_t*>(target) = reinterpret_cast32<uint32_t>(new_value);
@@ -3422,24 +3285,22 @@
*reinterpret_cast<uint64_t*>(target) = reinterpret_cast64<uint64_t>(new_value);
}
DCHECK(value != nullptr);
- RecordImageRelocation(target, oat_index, /* app_to_boot_image */ IsInBootImage(value));
}
-void ImageWriter::CopyAndFixupPointer(void** target, void* value, size_t oat_index)
+void ImageWriter::CopyAndFixupPointer(void** target, void* value)
REQUIRES_SHARED(Locks::mutator_lock_) {
- CopyAndFixupPointer(target, value, oat_index, target_ptr_size_);
+ CopyAndFixupPointer(target, value, target_ptr_size_);
}
void ImageWriter::CopyAndFixupPointer(
- void* object, MemberOffset offset, void* value, size_t oat_index, PointerSize pointer_size) {
+ void* object, MemberOffset offset, void* value, PointerSize pointer_size) {
void** target =
reinterpret_cast<void**>(reinterpret_cast<uint8_t*>(object) + offset.Uint32Value());
- return CopyAndFixupPointer(target, value, oat_index, pointer_size);
+ return CopyAndFixupPointer(target, value, pointer_size);
}
-void ImageWriter::CopyAndFixupPointer(
- void* object, MemberOffset offset, void* value, size_t oat_index) {
- return CopyAndFixupPointer(object, offset, value, oat_index, target_ptr_size_);
+void ImageWriter::CopyAndFixupPointer(void* object, MemberOffset offset, void* value) {
+ return CopyAndFixupPointer(object, offset, value, target_ptr_size_);
}
} // namespace linker
diff --git a/dex2oat/linker/image_writer.h b/dex2oat/linker/image_writer.h
index 93e4be5..6f43527 100644
--- a/dex2oat/linker/image_writer.h
+++ b/dex2oat/linker/image_writer.h
@@ -289,7 +289,7 @@
* Creates ImageSection objects that describe most of the sections of a
* boot or AppImage. The following sections are not included:
* - ImageHeader::kSectionImageBitmap
- * - ImageHeader::kSectionImageRelocations
+ * - ImageHeader::kSectionStringReferenceOffsets
*
* In addition, the ImageHeader is not covered here.
*
@@ -397,12 +397,6 @@
// Class table associated with this image for serialization.
std::unique_ptr<ClassTable> class_table_;
-
- // Relocations of references/pointers. For boot image, it contains one bit
- // for each location that can be relocated. For app image, it contains twice
- // that many bits, first half contains relocations within this image and the
- // second half contains relocations for references to the boot image.
- std::vector<uint8_t> relocation_bitmap_;
};
// We use the lock word to store the offset of the object in the image.
@@ -496,11 +490,9 @@
void CopyAndFixupObject(mirror::Object* obj) REQUIRES_SHARED(Locks::mutator_lock_);
void CopyAndFixupMethod(ArtMethod* orig, ArtMethod* copy, size_t oat_index)
REQUIRES_SHARED(Locks::mutator_lock_);
- void CopyAndFixupImTable(ImTable* orig, ImTable* copy, size_t oat_index)
+ void CopyAndFixupImTable(ImTable* orig, ImTable* copy)
REQUIRES_SHARED(Locks::mutator_lock_);
- void CopyAndFixupImtConflictTable(ImtConflictTable* orig,
- ImtConflictTable* copy,
- size_t oat_index)
+ void CopyAndFixupImtConflictTable(ImtConflictTable* orig, ImtConflictTable* copy)
REQUIRES_SHARED(Locks::mutator_lock_);
/*
@@ -517,45 +509,37 @@
*/
void CopyMetadata();
- template <bool kCheckNotNull = true>
- void RecordImageRelocation(const void* dest, size_t oat_index, bool app_to_boot_image = false);
- void FixupClass(mirror::Class* orig, mirror::Class* copy, size_t oat_index)
+ void FixupClass(mirror::Class* orig, mirror::Class* copy)
REQUIRES_SHARED(Locks::mutator_lock_);
- void FixupObject(mirror::Object* orig, mirror::Object* copy, size_t oat_index)
+ void FixupObject(mirror::Object* orig, mirror::Object* copy)
REQUIRES_SHARED(Locks::mutator_lock_);
template <typename T>
void FixupDexCacheArrayEntry(std::atomic<mirror::DexCachePair<T>>* orig_array,
std::atomic<mirror::DexCachePair<T>>* new_array,
- uint32_t array_index,
- size_t oat_index)
+ uint32_t array_index)
REQUIRES_SHARED(Locks::mutator_lock_);
template <typename T>
void FixupDexCacheArrayEntry(std::atomic<mirror::NativeDexCachePair<T>>* orig_array,
std::atomic<mirror::NativeDexCachePair<T>>* new_array,
- uint32_t array_index,
- size_t oat_index)
+ uint32_t array_index)
REQUIRES_SHARED(Locks::mutator_lock_);
void FixupDexCacheArrayEntry(GcRoot<mirror::CallSite>* orig_array,
GcRoot<mirror::CallSite>* new_array,
- uint32_t array_index,
- size_t oat_index)
+ uint32_t array_index)
REQUIRES_SHARED(Locks::mutator_lock_);
template <typename EntryType>
void FixupDexCacheArray(mirror::DexCache* orig_dex_cache,
mirror::DexCache* copy_dex_cache,
- size_t oat_index,
MemberOffset array_offset,
uint32_t size)
REQUIRES_SHARED(Locks::mutator_lock_);
void FixupDexCache(mirror::DexCache* orig_dex_cache,
- mirror::DexCache* copy_dex_cache,
- size_t oat_index)
+ mirror::DexCache* copy_dex_cache)
REQUIRES_SHARED(Locks::mutator_lock_);
void FixupPointerArray(mirror::Object* dst,
mirror::PointerArray* arr,
mirror::Class* klass,
- Bin array_type,
- size_t oat_index)
+ Bin array_type)
REQUIRES_SHARED(Locks::mutator_lock_);
// Get quick code for non-resolution/imt_conflict/abstract method.
@@ -711,18 +695,18 @@
// Copy a reference and record image relocation.
template <typename DestType>
- void CopyAndFixupReference(DestType* dest, ObjPtr<mirror::Object> src, size_t oat_index)
+ void CopyAndFixupReference(DestType* dest, ObjPtr<mirror::Object> src)
REQUIRES_SHARED(Locks::mutator_lock_);
// Copy a native pointer and record image relocation.
- void CopyAndFixupPointer(void** target, void* value, size_t oat_index, PointerSize pointer_size)
+ void CopyAndFixupPointer(void** target, void* value, PointerSize pointer_size)
REQUIRES_SHARED(Locks::mutator_lock_);
- void CopyAndFixupPointer(void** target, void* value, size_t oat_index)
+ void CopyAndFixupPointer(void** target, void* value)
REQUIRES_SHARED(Locks::mutator_lock_);
void CopyAndFixupPointer(
- void* object, MemberOffset offset, void* value, size_t oat_index, PointerSize pointer_size)
+ void* object, MemberOffset offset, void* value, PointerSize pointer_size)
REQUIRES_SHARED(Locks::mutator_lock_);
- void CopyAndFixupPointer(void* object, MemberOffset offset, void* value, size_t oat_index)
+ void CopyAndFixupPointer(void* object, MemberOffset offset, void* value)
REQUIRES_SHARED(Locks::mutator_lock_);
/*
diff --git a/oatdump/oatdump.cc b/oatdump/oatdump.cc
index 467542d..86a36f2 100644
--- a/oatdump/oatdump.cc
+++ b/oatdump/oatdump.cc
@@ -1954,7 +1954,6 @@
const auto& intern_section = image_header_.GetInternedStringsSection();
const auto& class_table_section = image_header_.GetClassTableSection();
const auto& bitmap_section = image_header_.GetImageBitmapSection();
- const auto& relocations_section = image_header_.GetImageRelocationsSection();
stats_.header_bytes = header_bytes;
@@ -1994,11 +1993,7 @@
CHECK_ALIGNED(bitmap_section.Offset(), kPageSize);
stats_.alignment_bytes += RoundUp(bitmap_offset, kPageSize) - bitmap_offset;
- // There should be no space between the bitmap and relocations.
- CHECK_EQ(bitmap_section.Offset() + bitmap_section.Size(), relocations_section.Offset());
-
stats_.bitmap_bytes += bitmap_section.Size();
- stats_.relocations_bytes += relocations_section.Size();
stats_.art_field_bytes += field_section.Size();
stats_.art_method_bytes += method_section.Size();
stats_.dex_cache_arrays_bytes += dex_cache_arrays_section.Size();
@@ -2431,7 +2426,6 @@
size_t interned_strings_bytes;
size_t class_table_bytes;
size_t bitmap_bytes;
- size_t relocations_bytes;
size_t alignment_bytes;
size_t managed_code_bytes;
@@ -2461,7 +2455,6 @@
interned_strings_bytes(0),
class_table_bytes(0),
bitmap_bytes(0),
- relocations_bytes(0),
alignment_bytes(0),
managed_code_bytes(0),
managed_code_bytes_ignoring_deduplication(0),
@@ -2625,7 +2618,6 @@
"interned_string_bytes = %8zd (%2.0f%% of art file bytes)\n"
"class_table_bytes = %8zd (%2.0f%% of art file bytes)\n"
"bitmap_bytes = %8zd (%2.0f%% of art file bytes)\n"
- "relocations_bytes = %8zd (%2.0f%% of art file bytes)\n"
"alignment_bytes = %8zd (%2.0f%% of art file bytes)\n\n",
header_bytes, PercentOfFileBytes(header_bytes),
object_bytes, PercentOfFileBytes(object_bytes),
@@ -2637,13 +2629,12 @@
PercentOfFileBytes(interned_strings_bytes),
class_table_bytes, PercentOfFileBytes(class_table_bytes),
bitmap_bytes, PercentOfFileBytes(bitmap_bytes),
- relocations_bytes, PercentOfFileBytes(relocations_bytes),
alignment_bytes, PercentOfFileBytes(alignment_bytes))
<< std::flush;
CHECK_EQ(file_bytes,
header_bytes + object_bytes + art_field_bytes + art_method_bytes +
dex_cache_arrays_bytes + interned_strings_bytes + class_table_bytes +
- bitmap_bytes + relocations_bytes + alignment_bytes);
+ bitmap_bytes + alignment_bytes);
}
os << "object_bytes breakdown:\n";
diff --git a/runtime/gc/space/image_space.cc b/runtime/gc/space/image_space.cc
index 6e6023d..9e67957 100644
--- a/runtime/gc/space/image_space.cc
+++ b/runtime/gc/space/image_space.cc
@@ -509,21 +509,11 @@
const size_t image_bitmap_offset = RoundUp(sizeof(ImageHeader) + image_header->GetDataSize(),
kPageSize);
const size_t end_of_bitmap = image_bitmap_offset + bitmap_section.Size();
- const ImageSection& relocations_section = image_header->GetImageRelocationsSection();
- if (relocations_section.Offset() != bitmap_section.Offset() + bitmap_section.Size()) {
+ if (end_of_bitmap != image_file_size) {
*error_msg = StringPrintf(
- "Relocations do not start immediately after bitmap: %u vs. %u + %u.",
- relocations_section.Offset(),
- bitmap_section.Offset(),
- bitmap_section.Size());
- return nullptr;
- }
- const size_t end_of_relocations = end_of_bitmap + relocations_section.Size();
- if (end_of_relocations != image_file_size) {
- *error_msg = StringPrintf(
- "Image file size does not equal end of relocations: size=%" PRIu64 " vs. %zu.",
+ "Image file size does not equal end of bitmap: size=%" PRIu64 " vs. %zu.",
image_file_size,
- end_of_relocations);
+ end_of_bitmap);
return nullptr;
}
diff --git a/runtime/image.cc b/runtime/image.cc
index a4351d0..e7f4486 100644
--- a/runtime/image.cc
+++ b/runtime/image.cc
@@ -26,7 +26,7 @@
namespace art {
const uint8_t ImageHeader::kImageMagic[] = { 'a', 'r', 't', '\n' };
-const uint8_t ImageHeader::kImageVersion[] = { '0', '6', '4', '\0' }; // Remove PIC flags.
+const uint8_t ImageHeader::kImageVersion[] = { '0', '6', '5', '\0' }; // Remove relocation section.
ImageHeader::ImageHeader(uint32_t image_begin,
uint32_t image_size,
diff --git a/runtime/image.h b/runtime/image.h
index bd8bc28..0496650 100644
--- a/runtime/image.h
+++ b/runtime/image.h
@@ -237,7 +237,6 @@
kSectionClassTable,
kSectionStringReferenceOffsets,
kSectionImageBitmap,
- kSectionImageRelocations,
kSectionCount, // Number of elements in enum.
};
@@ -294,10 +293,6 @@
return GetImageSection(kSectionImageBitmap);
}
- const ImageSection& GetImageRelocationsSection() const {
- return GetImageSection(kSectionImageRelocations);
- }
-
const ImageSection& GetImageStringReferenceOffsetsSection() const {
return GetImageSection(kSectionStringReferenceOffsets);
}