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

Unified Diff: src/serialize.cc

Issue 957703003: Tweak memory management in the serializer. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 10 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') | no next file » | 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 05a54188b86cfbeef9bc010a083fcad001d9adb5..8f3888cc431f6ee753f4f4b66b3b9e91c5876e89 100644
--- a/src/serialize.cc
+++ b/src/serialize.cc
@@ -706,8 +706,8 @@ MaybeHandle<Object> Deserializer::DeserializePartial(
return MaybeHandle<Object>();
}
- Vector<Handle<Object> > attached_objects = Vector<Handle<Object> >::New(1);
- attached_objects[kGlobalProxyReference] = global_proxy;
+ Handle<Object> global_proxy_object = global_proxy;
+ Vector<Handle<Object> > attached_objects(&global_proxy_object, 1);
SetAttachedObjects(attached_objects);
vogelheim 2015/02/25 14:00:19 I don't get this. My understanding is: - SetAttac
Yang 2015/02/25 16:06:21 You are right. It will indeed go out of scope, tho
DisallowHeapAllocation no_gc;
@@ -753,7 +753,6 @@ Deserializer::~Deserializer() {
delete external_reference_decoder_;
external_reference_decoder_ = NULL;
}
- attached_objects_.Dispose();
}
@@ -1378,6 +1377,7 @@ Serializer::Serializer(Isolate* isolate, SnapshotByteSink* sink)
Serializer::~Serializer() {
delete external_reference_encoder_;
if (code_address_map_ != NULL) delete code_address_map_;
+ code_buffer_.Dispose();
}
@@ -2044,14 +2044,16 @@ void Serializer::ObjectSerializer::VisitExternalOneByteString(
}
-static Code* CloneCodeObject(HeapObject* code) {
- Address copy = new byte[code->Size()];
- MemCopy(copy, code->address(), code->Size());
- return Code::cast(HeapObject::FromAddress(copy));
-}
-
-
-static void WipeOutRelocations(Code* code) {
+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_);
+ int size = original->CodeSize();
+ Address copy = serializer_->GetCodeBuffer(size);
+ MemCopy(copy, original->address(), size);
+ Code* code = Code::cast(HeapObject::FromAddress(copy));
+ // Code age headers are not serializable.
+ code->MakeYoung(serializer_->isolate());
int mode_mask =
RelocInfo::kCodeTargetMask |
RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT) |
@@ -2062,6 +2064,10 @@ static void WipeOutRelocations(Code* code) {
it.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();
}
@@ -2099,17 +2105,7 @@ int Serializer::ObjectSerializer::OutputRawData(
sink_->PutInt(bytes_to_output, "length");
}
- // To make snapshots reproducible, we need to wipe out all pointers in code.
- if (code_object_) {
- Code* code = CloneCodeObject(object_);
- // Code age headers are not serializable.
- code->MakeYoung(serializer_->isolate());
- WipeOutRelocations(code);
- // 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();
- object_start = code->address();
- }
+ if (code_object_) object_start = PrepareCode();
const char* description = code_object_ ? "Code" : "Byte";
#ifdef MEMORY_SANITIZER
@@ -2117,7 +2113,6 @@ int Serializer::ObjectSerializer::OutputRawData(
MSAN_MEMORY_IS_INITIALIZED(object_start + base, bytes_to_output);
#endif // MEMORY_SANITIZER
sink_->PutRaw(object_start + base, bytes_to_output, description);
- if (code_object_) delete[] object_start;
}
if (to_skip != 0 && return_skip == kIgnoringReturn) {
sink_->Put(kSkip, "Skip");
@@ -2416,8 +2411,11 @@ MaybeHandle<SharedFunctionInfo> CodeSerializer::Deserialize(
deserializer.SetAttachedObjects(attached_objects);
// Deserialize.
+ MaybeHandle<SharedFunctionInfo> maybe = deserializer.DeserializeCode(isolate);
+ attached_objects.Dispose();
+
Handle<SharedFunctionInfo> result;
- if (!deserializer.DeserializeCode(isolate).ToHandle(&result)) {
+ if (!maybe.ToHandle(&result)) {
// Deserializing may fail if the reservations cannot be fulfilled.
if (FLAG_profile_deserialization) PrintF("[Deserializing failed]\n");
return MaybeHandle<SharedFunctionInfo>();
« no previous file with comments | « src/serialize.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698