Commit f3fd0b3c authored by Igor Sheludko's avatar Igor Sheludko Committed by Commit Bot

[ptr-compr] Make Code serialization pointer compression friendly

Bug: v8:7703
Change-Id: I47e6971bc99186cb6861164ec2a246ebcd770219
Reviewed-on: https://chromium-review.googlesource.com/c/1349230Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57780}
parent 82f99331
......@@ -322,8 +322,7 @@ byte* Code::relocation_start() const {
}
byte* Code::relocation_end() const {
return unchecked_relocation_info()->GetDataStartAddress() +
unchecked_relocation_info()->length();
return unchecked_relocation_info()->GetDataEndAddress();
}
int Code::relocation_size() const {
......
......@@ -487,6 +487,10 @@ byte* ByteArray::GetDataStartAddress() {
return reinterpret_cast<byte*>(address() + kHeaderSize);
}
byte* ByteArray::GetDataEndAddress() {
return GetDataStartAddress() + length();
}
template <class T>
PodArray<T>* PodArray<T>::cast(Object* object) {
DCHECK(object->IsByteArray());
......
......@@ -645,6 +645,8 @@ class ByteArray : public FixedArrayBase {
// Returns data start address.
inline byte* GetDataStartAddress();
// Returns address of the past-the-end element.
inline byte* GetDataEndAddress();
inline int DataSize() const;
......
......@@ -281,9 +281,13 @@ void RelocIterator::next() {
}
RelocIterator::RelocIterator(Code code, int mode_mask)
: RelocIterator(code, code->unchecked_relocation_info(), mode_mask) {}
RelocIterator::RelocIterator(Code code, ByteArray* relocation_info,
int mode_mask)
: RelocIterator(code, code->raw_instruction_start(), code->constant_pool(),
code->relocation_end(), code->relocation_start(),
mode_mask) {}
relocation_info->GetDataEndAddress(),
relocation_info->GetDataStartAddress(), mode_mask) {}
RelocIterator::RelocIterator(const CodeReference code_reference, int mode_mask)
: RelocIterator(Code(), code_reference.instruction_start(),
......
......@@ -382,6 +382,7 @@ class RelocIterator : public Malloced {
// Relocation information with mode k is included in the
// iteration iff bit k of mode_mask is set.
explicit RelocIterator(Code code, int mode_mask = -1);
explicit RelocIterator(Code code, ByteArray* relocation_info, int mode_mask);
explicit RelocIterator(EmbeddedData* embedded_data, Code code, int mode_mask);
explicit RelocIterator(const CodeDesc& desc, int mode_mask = -1);
explicit RelocIterator(const CodeReference code_reference,
......
......@@ -926,10 +926,10 @@ int Serializer::ObjectSerializer::SkipTo(Address to) {
void Serializer::ObjectSerializer::OutputCode(int size) {
DCHECK_EQ(kPointerSize, bytes_processed_so_far_);
Code code = Code::cast(object_);
Code on_heap_code = Code::cast(object_);
// To make snapshots reproducible, we make a copy of the code object
// and wipe all pointers in the copy, which we then serialize.
code = serializer_->CopyCode(code);
Code off_heap_code = serializer_->CopyCode(on_heap_code);
int mode_mask = RelocInfo::ModeMask(RelocInfo::CODE_TARGET) |
RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT) |
RelocInfo::ModeMask(RelocInfo::EXTERNAL_REFERENCE) |
......@@ -937,15 +937,20 @@ void Serializer::ObjectSerializer::OutputCode(int size) {
RelocInfo::ModeMask(RelocInfo::INTERNAL_REFERENCE_ENCODED) |
RelocInfo::ModeMask(RelocInfo::OFF_HEAP_TARGET) |
RelocInfo::ModeMask(RelocInfo::RUNTIME_ENTRY);
for (RelocIterator it(code, mode_mask); !it.done(); it.next()) {
// With enabled pointer compression normal accessors no longer work for
// off-heap objects, so we have to get the relocation info data via the
// on-heap code object.
ByteArray* relocation_info = on_heap_code->unchecked_relocation_info();
for (RelocIterator it(off_heap_code, relocation_info, mode_mask); !it.done();
it.next()) {
RelocInfo* rinfo = it.rinfo();
rinfo->WipeOut();
}
// We need to wipe out the header fields *after* wiping out the
// relocations, because some of these fields are needed for the latter.
code->WipeOutHeader();
off_heap_code->WipeOutHeader();
Address start = code->address() + Code::kDataStart;
Address start = off_heap_code->address() + Code::kDataStart;
int bytes_to_output = size - Code::kDataStart;
sink_->Put(kVariableRawCode, "VariableRawCode");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment