Reviewers: Yury Semikhatsky, svenpanne,
Message:
Folks, could you please take a look.
Description:
Heap snapshot: Update user roots definition.
Do not define an object as a user root if its context is not
present in Global handles.
Please review this at https://codereview.chromium.org/17881005/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files:
M src/heap-snapshot-generator.h
M src/heap-snapshot-generator.cc
M test/cctest/test-heap-profiler.cc
Index: src/heap-snapshot-generator.cc
diff --git a/src/heap-snapshot-generator.cc b/src/heap-snapshot-generator.cc
index
217d1ca25ecfa9dae22b7270b973700c67a2a09f..a4c31121460f729ade5384c9b7f4f6e3044fcec1
100644
--- a/src/heap-snapshot-generator.cc
+++ b/src/heap-snapshot-generator.cc
@@ -961,7 +961,7 @@ void V8HeapExplorer::ExtractReferences(HeapObject* obj)
{
bool extract_indexed_refs = true;
if (obj->IsJSGlobalProxy()) {
- ExtractJSGlobalProxyReferences(JSGlobalProxy::cast(obj));
+ ExtractJSGlobalProxyReferences(entry, JSGlobalProxy::cast(obj));
} else if (obj->IsJSObject()) {
ExtractJSObjectReferences(entry, JSObject::cast(obj));
} else if (obj->IsString()) {
@@ -994,19 +994,11 @@ void V8HeapExplorer::ExtractReferences(HeapObject*
obj) {
}
-void V8HeapExplorer::ExtractJSGlobalProxyReferences(JSGlobalProxy* proxy) {
- // We need to reference JS global objects from snapshot's root.
- // We use JSGlobalProxy because this is what embedder (e.g. browser)
- // uses for the global object.
- Object* object = proxy->map()->prototype();
- bool is_debug_object = false;
-#ifdef ENABLE_DEBUGGER_SUPPORT
- is_debug_object = object->IsGlobalObject() &&
-
Isolate::Current()->debug()->IsDebugGlobal(GlobalObject::cast(object));
-#endif
- if (!is_debug_object) {
- SetUserGlobalReference(object);
- }
+void V8HeapExplorer::ExtractJSGlobalProxyReferences(
+ int entry, JSGlobalProxy* proxy) {
+ SetInternalReference(proxy, entry,
+ "native_context", proxy->native_context(),
+ JSGlobalProxy::kNativeContextOffset);
}
@@ -1760,6 +1752,30 @@ void V8HeapExplorer::SetGcSubrootReference(
snapshot_->gc_subroot(tag)->index(),
child_entry);
}
+
+ // Add a shortcut to JS global object reference at snapshot root.
+ if (child_obj->IsNativeContext()) {
+ Context* context = Context::cast(child_obj);
+ JSObject* proxy = context->global_proxy();
+ if (proxy->IsJSGlobalProxy()) {
+ // We use JSGlobalProxy because that's what embedder (e.g. browser)
+ // uses for the global object.
+ // TODO(alph): consider extracting it as just
proxy->global_object()
+ Object* object = proxy->map()->prototype();
+ if (object->IsJSGlobalObject()) {
+ JSGlobalObject* global = JSGlobalObject::cast(object);
+ CHECK(global == context->global_object());
+ bool is_debug_object = false;
+#ifdef ENABLE_DEBUGGER_SUPPORT
+ is_debug_object =
Isolate::Current()->debug()->IsDebugGlobal(global);
+#endif
+ if (!is_debug_object && !user_roots_.Contains(global)) {
+ user_roots_.Insert(global);
+ SetUserGlobalReference(global);
+ }
+ }
+ }
+ }
}
}
Index: src/heap-snapshot-generator.h
diff --git a/src/heap-snapshot-generator.h b/src/heap-snapshot-generator.h
index
c9a82f0ff03545d761e4d65bcc1e0cff9f5d0977..932f98e5605a02941785c881adb0f4472a340331
100644
--- a/src/heap-snapshot-generator.h
+++ b/src/heap-snapshot-generator.h
@@ -454,7 +454,7 @@ class V8HeapExplorer : public HeapEntriesAllocator {
const char* GetSystemEntryName(HeapObject* object);
void ExtractReferences(HeapObject* obj);
- void ExtractJSGlobalProxyReferences(JSGlobalProxy* proxy);
+ void ExtractJSGlobalProxyReferences(int entry, JSGlobalProxy* proxy);
void ExtractJSObjectReferences(int entry, JSObject* js_obj);
void ExtractStringReferences(int entry, String* obj);
void ExtractContextReferences(int entry, Context* context);
@@ -529,6 +529,7 @@ class V8HeapExplorer : public HeapEntriesAllocator {
SnapshotFillerInterface* filler_;
HeapObjectsSet objects_tags_;
HeapObjectsSet strong_gc_subroot_names_;
+ HeapObjectsSet user_roots_;
v8::HeapProfiler::ObjectNameResolver* global_object_name_resolver_;
static HeapObject* const kGcRootsObject;
Index: test/cctest/test-heap-profiler.cc
diff --git a/test/cctest/test-heap-profiler.cc
b/test/cctest/test-heap-profiler.cc
index
33b0fb9299b4117f1b0a091d739129f2303ebc17..9a9de085aa1f6acbc0e37a6f9fe677197b4a8776
100644
--- a/test/cctest/test-heap-profiler.cc
+++ b/test/cctest/test-heap-profiler.cc
@@ -92,8 +92,9 @@ class NamedEntriesDetector {
static const v8::HeapGraphNode* GetGlobalObject(
const v8::HeapSnapshot* snapshot) {
CHECK_EQ(2, snapshot->GetRoot()->GetChildrenCount());
+ // The 0th-child is (GC Roots), 1st is the user root.
const v8::HeapGraphNode* global_obj =
- snapshot->GetRoot()->GetChild(0)->GetToNode();
+ snapshot->GetRoot()->GetChild(1)->GetToNode();
CHECK_EQ(0, strncmp("Object", const_cast<i::HeapEntry*>(
reinterpret_cast<const i::HeapEntry*>(global_obj))->name(), 6));
return global_obj;
@@ -658,7 +659,8 @@ TEST(HeapSnapshotJSONSerialization) {
" first_edge_indexes[i] = first_edge_index;\n"
" first_edge_index += edge_fields_count *\n"
" parsed.nodes[i * node_fields_count + edge_count_offset];\n"
- "}\n");
+ "}\n"
+ "first_edge_indexes[node_count] = first_edge_index;\n");
CHECK(!meta_analysis_result.IsEmpty());
// A helper function for processing encoded nodes.
@@ -682,7 +684,7 @@ TEST(HeapSnapshotJSONSerialization) {
"GetChildPosByProperty(\n"
" GetChildPosByProperty(\n"
" GetChildPosByProperty("
- " parsed.edges[edge_to_node_offset],"
+ " parsed.edges[edge_fields_count + edge_to_node_offset],"
" \"b\", property_type),\n"
" \"x\", property_type),"
" \"s\", property_type)");
--
--
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/groups/opt_out.