Reviewers: mvstanton,
Description:
Add and move DisallowHeapAllocation scope.
The move is necessary since Heap::ReserveSpace called from
DeserializePartial may allocate.
[email protected]
Please review this at https://codereview.chromium.org/413663003/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files (+31, -8 lines):
M src/compiler.cc
M src/debug.cc
M src/objects.h
M src/objects.cc
M src/serialize.cc
Index: src/compiler.cc
diff --git a/src/compiler.cc b/src/compiler.cc
index
8d59dbca2dc90c185eb9eede87562f6bdf69387e..b1a7f6ef26cf7510d4d8b11669508867319c659c
100644
--- a/src/compiler.cc
+++ b/src/compiler.cc
@@ -961,7 +961,8 @@ Handle<SharedFunctionInfo> Compiler::CompileScript(
Handle<SharedFunctionInfo> result;
if (extension == NULL) {
if (FLAG_serialize_toplevel &&
- compile_options == ScriptCompiler::kConsumeCodeCache) {
+ compile_options == ScriptCompiler::kConsumeCodeCache &&
+ !isolate->debug()->is_loaded()) {
return CodeSerializer::Deserialize(isolate, *cached_data, source);
} else {
maybe_result = compilation_cache->LookupScript(
Index: src/debug.cc
diff --git a/src/debug.cc b/src/debug.cc
index
e908126d895c3132c82ffe8f0aa1ecc606aac36c..f3ef93c6b9ac8ce23275c0685277c15be671c1d6
100644
--- a/src/debug.cc
+++ b/src/debug.cc
@@ -622,7 +622,14 @@ void ScriptCache::Add(Handle<Script> script) {
HashMap::Entry* entry =
HashMap::Lookup(reinterpret_cast<void*>(id), Hash(id), true);
if (entry->value != NULL) {
- ASSERT(*script == *reinterpret_cast<Script**>(entry->value));
+#ifdef DEBUG
+ // The code deserializer may introduce duplicate Script objects.
+ // Assert that the Script objects with the same id have the same name.
+ Handle<Script> found(reinterpret_cast<Script**>(entry->value));
+ ASSERT(script->id() == found->id());
+ ASSERT(!script->name()->IsString() ||
+
String::cast(script->name())->Equals(String::cast(found->name())));
+#endif
return;
}
// Globalize the script object, make it weak and use the location of the
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index
0f9ea21d378b541e211b3939028ffeac31b49f37..b61175c98fdad763ac4f2ecf2bc44357c89e7ce0
100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -10284,16 +10284,21 @@ Handle<Object>
Script::GetNameOrSourceURL(Handle<Script> script) {
// collector will call the weak callback on the global handle
// associated with the wrapper and get rid of both the wrapper and the
// handle.
-static void ClearWrapperCache(
+static void ClearWrapperCacheWeakCallback(
const v8::WeakCallbackData<v8::Value, void>& data) {
Object** location = reinterpret_cast<Object**>(data.GetParameter());
JSValue* wrapper = JSValue::cast(*location);
- Foreign* foreign = Script::cast(wrapper->value())->wrapper();
+ Script::cast(wrapper->value())->ClearWrapperCache();
+}
+
+
+void Script::ClearWrapperCache() {
+ Foreign* foreign = wrapper();
+ Object** location =
reinterpret_cast<Object**>(foreign->foreign_address());
ASSERT_EQ(foreign->foreign_address(),
reinterpret_cast<Address>(location));
foreign->set_foreign_address(0);
GlobalHandles::Destroy(location);
- Isolate* isolate = reinterpret_cast<Isolate*>(data.GetIsolate());
- isolate->counters()->script_wrappers()->Decrement();
+ GetIsolate()->counters()->script_wrappers()->Decrement();
}
@@ -10318,7 +10323,7 @@ Handle<JSObject> Script::GetWrapper(Handle<Script>
script) {
Handle<Object> handle = isolate->global_handles()->Create(*result);
GlobalHandles::MakeWeak(handle.location(),
reinterpret_cast<void*>(handle.location()),
- &ClearWrapperCache);
+ &ClearWrapperCacheWeakCallback);
script->wrapper()->set_foreign_address(
reinterpret_cast<Address>(handle.location()));
return result;
Index: src/objects.h
diff --git a/src/objects.h b/src/objects.h
index
629a951314d16f947d4908636f5ade363e433cfa..e32b51d2ff06cff2fb9a5fbb9f0704fdf094fb58
100644
--- a/src/objects.h
+++ b/src/objects.h
@@ -6934,6 +6934,7 @@ class Script: public Struct {
// Get the JS object wrapping the given script; create it if none exists.
static Handle<JSObject> GetWrapper(Handle<Script> script);
+ void ClearWrapperCache();
// Dispatched behavior.
DECLARE_PRINTER(Script)
Index: src/serialize.cc
diff --git a/src/serialize.cc b/src/serialize.cc
index
4156dfbf626fef88ebe2ec6c55f84240bf8a869e..ebc453ccc2d3a61ab3c9f02a566ace8e7831f2f8
100644
--- a/src/serialize.cc
+++ b/src/serialize.cc
@@ -792,6 +792,8 @@ void Deserializer::DeserializePartial(Isolate* isolate,
Object** root) {
external_reference_decoder_ = new ExternalReferenceDecoder(isolate);
}
+ DisallowHeapAllocation no_gc;
+
// Keep track of the code space start and end pointers in case new
// code objects were unserialized
OldSpace* code_space = isolate_->heap()->code_space();
@@ -1909,6 +1911,7 @@ ScriptData* CodeSerializer::Serialize(Isolate*
isolate,
List<byte> payload;
ListSnapshotSink list_sink(&payload);
CodeSerializer cs(isolate, &list_sink, *source);
+ DisallowHeapAllocation no_gc;
Object** location = Handle<Object>::cast(info).location();
cs.VisitPointer(location);
cs.Pad();
@@ -1962,6 +1965,13 @@ void CodeSerializer::SerializeObject(Object* o,
HowToCode how_to_code,
return;
}
+ if (heap_object->IsScript()) {
+ // The wrapper cache uses a Foreign object to point to a global handle.
+ // However, the object visitor expects foreign objects to point to
external
+ // references. Clear the cache to avoid this issue.
+ Script::cast(heap_object)->ClearWrapperCache();
+ }
+
if (skip != 0) {
sink_->Put(kSkip, "SkipFromSerializeObject");
sink_->PutInt(skip, "SkipDistanceFromSerializeObject");
@@ -2016,7 +2026,6 @@ Handle<SharedFunctionInfo>
CodeSerializer::Deserialize(Isolate* isolate,
for (int i = NEW_SPACE; i <= PROPERTY_CELL_SPACE; i++) {
deserializer.set_reservation(i, scd.GetReservation(i));
}
- DisallowHeapAllocation no_gc;
// Prepare and register list of attached objects.
Vector<Object*> attached_objects = Vector<Object*>::New(1);
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.