Reviewers: mvstanton,
Description:
Fix debugger-related issues in the code serializer.
[email protected]
Please review this at https://codereview.chromium.org/410883003/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files (+28, -7 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..71bc363cf22830c65196df66c01e6eaeca603d3f
100644
--- a/src/serialize.cc
+++ b/src/serialize.cc
@@ -1962,6 +1962,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");
--
--
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.