Commit 5a88c047 authored by yangguo's avatar yangguo Committed by Commit bot

[serializer] do not copy code if snapshot is not required to be deterministic.

Code in V8 embeds memory addresses. Upon deserialization, those addresses will
be updated anyways, so it's not important whether the serializer records those
addresses. In order to have a deterministic build, we create a copy of the code
and null out memory addresses and serialize this copy.

For the code cache, we do not care about determinism. By avoiding the copy we
can save some time spent on serialization. For the mandreel script in Octane,
this reduces the serialization time from ~85ms to ~75ms.

R=vogelheim@chromium.org

Review-Url: https://codereview.chromium.org/1991033003
Cr-Commit-Position: refs/heads/master@{#36350}
parent fbf58a5a
......@@ -707,25 +707,27 @@ void Serializer::ObjectSerializer::VisitExternalOneByteString(
}
Address Serializer::ObjectSerializer::PrepareCode() {
// To make snapshots reproducible, we make a copy of the code object
// and wipe all pointers in the copy, which we then serialize.
Code* original = Code::cast(object_);
Code* code = serializer_->CopyCode(original);
Code* code = Code::cast(object_);
if (FLAG_predictable) {
// 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);
int mode_mask = RelocInfo::kCodeTargetMask |
RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT) |
RelocInfo::ModeMask(RelocInfo::EXTERNAL_REFERENCE) |
RelocInfo::ModeMask(RelocInfo::RUNTIME_ENTRY) |
RelocInfo::ModeMask(RelocInfo::INTERNAL_REFERENCE) |
RelocInfo::ModeMask(RelocInfo::INTERNAL_REFERENCE_ENCODED);
for (RelocIterator it(code, 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();
}
// Code age headers are not serializable.
code->MakeYoung(serializer_->isolate());
int mode_mask = RelocInfo::kCodeTargetMask |
RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT) |
RelocInfo::ModeMask(RelocInfo::EXTERNAL_REFERENCE) |
RelocInfo::ModeMask(RelocInfo::RUNTIME_ENTRY) |
RelocInfo::ModeMask(RelocInfo::INTERNAL_REFERENCE) |
RelocInfo::ModeMask(RelocInfo::INTERNAL_REFERENCE_ENCODED);
for (RelocIterator it(code, 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();
return code->address();
}
......
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