Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(653)

Unified Diff: src/serialize.cc

Issue 1005183006: Serializer: serialize internal references via object visitor. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: platform ports Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/serialize.h ('k') | src/x64/assembler-x64.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/serialize.cc
diff --git a/src/serialize.cc b/src/serialize.cc
index 00405dda91a2999739b6fa45fcff3ce435c90e35..7034ac1ae7999f34fbce30940becbfae229351c5 100644
--- a/src/serialize.cc
+++ b/src/serialize.cc
@@ -788,25 +788,13 @@ void Deserializer::ReadObject(int space_number, Object** write_back) {
#ifdef DEBUG
if (obj->IsCode()) {
DCHECK(space_number == CODE_SPACE || space_number == LO_SPACE);
+#ifdef VERIFY_HEAP
+ obj->ObjectVerify();
+#endif // VERIFY_HEAP
} else {
DCHECK(space_number != CODE_SPACE);
}
-#endif
-
- if (obj->IsCode()) {
- // Turn internal references encoded as offsets back to absolute addresses.
- Code* code = Code::cast(obj);
- Address entry = code->entry();
- int mode_mask = 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();
- intptr_t offset =
- reinterpret_cast<intptr_t>(rinfo->target_internal_reference());
- DCHECK(0 <= offset && offset <= code->instruction_size());
- rinfo->set_target_internal_reference(entry + offset);
- }
- }
+#endif // DEBUG
}
@@ -1185,6 +1173,21 @@ void Deserializer::ReadData(Object** current, Object** limit, int source_space,
break;
}
+ case kInternalReference: {
+ // Internal reference address is not encoded via skip, but by offset
+ // from code entry.
+ int pc_offset = source_.GetInt();
+ int target_offset = source_.GetInt();
+ Code* code =
+ Code::cast(HeapObject::FromAddress(current_object_address));
+ DCHECK(0 <= pc_offset && pc_offset <= code->instruction_size());
+ DCHECK(0 <= target_offset && target_offset <= code->instruction_size());
+ Address pc = code->entry() + pc_offset;
+ Address target = code->entry() + target_offset;
+ Assembler::deserialization_set_target_internal_reference_at(pc, target);
+ break;
+ }
+
case kNativesStringResource: {
DCHECK(!isolate_->heap()->deserialization_complete());
int index = source_.Get();
@@ -1872,6 +1875,27 @@ void Serializer::ObjectSerializer::VisitExternalReference(RelocInfo* rinfo) {
}
+void Serializer::ObjectSerializer::VisitInternalReference(RelocInfo* rinfo) {
+ DCHECK(code_object_ && code_has_been_output_);
+ // We do not use skip from last patched pc to find the pc to patch, since
+ // target_address_address may not return addresses in ascending order when
+ // used for internal references. External references may be stored at the
+ // end of the code in the constant pool, whereas internal references are
+ // inline. That would cause the skip to be negative. Instead, we store the
+ // offset from code entry.
+ Address entry = Code::cast(object_)->entry();
+ intptr_t pc_offset = rinfo->target_internal_reference_address() - entry;
+ intptr_t target_offset = rinfo->target_internal_reference() - entry;
+ DCHECK(0 <= pc_offset &&
+ pc_offset <= Code::cast(object_)->instruction_size());
+ DCHECK(0 <= target_offset &&
+ target_offset <= Code::cast(object_)->instruction_size());
+ sink_->Put(kInternalReference, "InternalRef");
+ sink_->PutInt(static_cast<uintptr_t>(pc_offset), "internal ref address");
+ sink_->PutInt(static_cast<uintptr_t>(target_offset), "internal ref value");
+}
+
+
void Serializer::ObjectSerializer::VisitRuntimeEntry(RelocInfo* rinfo) {
int skip = OutputRawData(rinfo->target_address_address(),
kCanReturnSkipInsteadOfSkipping);
@@ -1947,7 +1971,6 @@ Address Serializer::ObjectSerializer::PrepareCode() {
Code* code = serializer_->CopyCode(original);
// Code age headers are not serializable.
code->MakeYoung(serializer_->isolate());
- Address entry = original->entry();
int mode_mask = RelocInfo::kCodeTargetMask |
RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT) |
RelocInfo::ModeMask(RelocInfo::EXTERNAL_REFERENCE) |
@@ -1956,15 +1979,7 @@ Address Serializer::ObjectSerializer::PrepareCode() {
RelocInfo::ModeMask(RelocInfo::INTERNAL_REFERENCE_ENCODED);
for (RelocIterator it(code, mode_mask); !it.done(); it.next()) {
RelocInfo* rinfo = it.rinfo();
- RelocInfo::Mode rmode = rinfo->rmode();
- if (RelocInfo::IsInternalReference(rmode) ||
- RelocInfo::IsInternalReferenceEncoded(rmode)) {
- // Convert internal references to relative offsets.
- Address target = rinfo->target_internal_reference();
- intptr_t offset = target - entry;
- DCHECK(0 <= offset && offset <= original->instruction_size());
- rinfo->set_target_internal_reference(reinterpret_cast<Address>(offset));
- } else if (!(FLAG_enable_ool_constant_pool && rinfo->IsInConstantPool())) {
+ if (!(FLAG_enable_ool_constant_pool && rinfo->IsInConstantPool())) {
rinfo->WipeOut();
}
}
@@ -2335,7 +2350,6 @@ MaybeHandle<SharedFunctionInfo> CodeSerializer::Deserialize(
isolate->logger()->CodeCreateEvent(Logger::SCRIPT_TAG, result->code(),
*result, NULL, name);
}
-
return scope.CloseAndEscape(result);
}
« no previous file with comments | « src/serialize.h ('k') | src/x64/assembler-x64.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698