Revision: 21460
Author: [email protected]
Date: Fri May 23 11:05:22 2014 UTC
Log: Support ES6 weak collections in heap profiler
BUG=chromium:376196
LOG=Y
[email protected], [email protected]
Review URL: https://codereview.chromium.org/294163005
http://code.google.com/p/v8/source/detail?r=21460
Modified:
/branches/bleeding_edge/src/heap-snapshot-generator.cc
/branches/bleeding_edge/src/heap-snapshot-generator.h
/branches/bleeding_edge/test/cctest/test-heap-profiler.cc
=======================================
--- /branches/bleeding_edge/src/heap-snapshot-generator.cc Fri May 23
08:52:05 2014 UTC
+++ /branches/bleeding_edge/src/heap-snapshot-generator.cc Fri May 23
11:05:22 2014 UTC
@@ -1097,6 +1097,10 @@
ExtractJSGlobalProxyReferences(entry, JSGlobalProxy::cast(obj));
} else if (obj->IsJSArrayBuffer()) {
ExtractJSArrayBufferReferences(entry, JSArrayBuffer::cast(obj));
+ } else if (obj->IsJSWeakSet()) {
+ ExtractJSWeakCollectionReferences(entry, JSWeakSet::cast(obj));
+ } else if (obj->IsJSWeakMap()) {
+ ExtractJSWeakCollectionReferences(entry, JSWeakMap::cast(obj));
} else if (obj->IsJSObject()) {
ExtractJSObjectReferences(entry, JSObject::cast(obj));
} else if (obj->IsString()) {
@@ -1254,6 +1258,15 @@
"name", symbol->name(),
Symbol::kNameOffset);
}
+
+
+void V8HeapExplorer::ExtractJSWeakCollectionReferences(
+ int entry, JSWeakCollection* collection) {
+ MarkAsWeakContainer(collection->table());
+ SetInternalReference(collection, entry,
+ "table", collection->table(),
+ JSWeakCollection::kTableOffset);
+}
void V8HeapExplorer::ExtractContextReferences(int entry, Context* context)
{
=======================================
--- /branches/bleeding_edge/src/heap-snapshot-generator.h Thu May 22
11:26:48 2014 UTC
+++ /branches/bleeding_edge/src/heap-snapshot-generator.h Fri May 23
11:05:22 2014 UTC
@@ -370,6 +370,8 @@
void ExtractJSObjectReferences(int entry, JSObject* js_obj);
void ExtractStringReferences(int entry, String* obj);
void ExtractSymbolReferences(int entry, Symbol* symbol);
+ void ExtractJSWeakCollectionReferences(int entry,
+ JSWeakCollection* collection);
void ExtractContextReferences(int entry, Context* context);
void ExtractMapReferences(int entry, Map* map);
void ExtractSharedFunctionInfoReferences(int entry,
=======================================
--- /branches/bleeding_edge/test/cctest/test-heap-profiler.cc Thu May 22
11:26:48 2014 UTC
+++ /branches/bleeding_edge/test/cctest/test-heap-profiler.cc Fri May 23
11:05:22 2014 UTC
@@ -493,6 +493,70 @@
CHECK_NE(NULL, name);
CHECK_EQ(v8_str("mySymbol"), name->GetName());
}
+
+
+TEST(HeapSnapshotWeakCollection) {
+ i::FLAG_harmony_collections = true;
+
+ LocalContext env;
+ v8::HandleScope scope(env->GetIsolate());
+ v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
+
+ CompileRun("k = {}; v = {};\n"
+ "ws = new WeakSet(); ws.add(k); ws.add(v);\n"
+ "wm = new WeakMap(); wm.set(k, v);\n");
+ const v8::HeapSnapshot* snapshot =
+ heap_profiler->TakeHeapSnapshot(v8_str("WeakCollections"));
+ CHECK(ValidateSnapshot(snapshot));
+ const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
+ const v8::HeapGraphNode* k =
+ GetProperty(global, v8::HeapGraphEdge::kProperty, "k");
+ CHECK_NE(NULL, k);
+ const v8::HeapGraphNode* v =
+ GetProperty(global, v8::HeapGraphEdge::kProperty, "v");
+ CHECK_NE(NULL, v);
+
+ const v8::HeapGraphNode* ws =
+ GetProperty(global, v8::HeapGraphEdge::kProperty, "ws");
+ CHECK_NE(NULL, ws);
+ CHECK_EQ(v8::HeapGraphNode::kObject, ws->GetType());
+ CHECK_EQ(v8_str("WeakSet"), ws->GetName());
+
+ const v8::HeapGraphNode* ws_table =
+ GetProperty(ws, v8::HeapGraphEdge::kInternal, "table");
+ CHECK_EQ(v8::HeapGraphNode::kArray, ws_table->GetType());
+ CHECK_GT(ws_table->GetChildrenCount(), 0);
+ int weak_entries = 0;
+ for (int i = 0, count = ws_table->GetChildrenCount(); i < count; ++i) {
+ const v8::HeapGraphEdge* prop = ws_table->GetChild(i);
+ if (prop->GetType() != v8::HeapGraphEdge::kWeak) continue;
+ if (k->GetId() == prop->GetToNode()->GetId()) {
+ ++weak_entries;
+ }
+ }
+ CHECK_EQ(1, weak_entries);
+
+ const v8::HeapGraphNode* wm =
+ GetProperty(global, v8::HeapGraphEdge::kProperty, "wm");
+ CHECK_NE(NULL, wm);
+ CHECK_EQ(v8::HeapGraphNode::kObject, wm->GetType());
+ CHECK_EQ(v8_str("WeakMap"), wm->GetName());
+
+ const v8::HeapGraphNode* wm_table =
+ GetProperty(wm, v8::HeapGraphEdge::kInternal, "table");
+ CHECK_EQ(v8::HeapGraphNode::kArray, wm_table->GetType());
+ CHECK_GT(wm_table->GetChildrenCount(), 0);
+ weak_entries = 0;
+ for (int i = 0, count = wm_table->GetChildrenCount(); i < count; ++i) {
+ const v8::HeapGraphEdge* prop = wm_table->GetChild(i);
+ if (prop->GetType() != v8::HeapGraphEdge::kWeak) continue;
+ const v8::SnapshotObjectId to_node_id = prop->GetToNode()->GetId();
+ if (to_node_id == k->GetId() || to_node_id == v->GetId()) {
+ ++weak_entries;
+ }
+ }
+ CHECK_EQ(2, weak_entries);
+}
TEST(HeapSnapshotInternalReferences) {
--
--
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.