Reviewers: yurys, loislo, Yang,
Message:
Could you please take a look.
Description:
Add object hidden properties to heap snapshot
LOG=N
Please review this at https://codereview.chromium.org/171683013/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files (+54, -0 lines):
M src/heap-snapshot-generator.h
M src/heap-snapshot-generator.cc
M src/objects.h
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
b67aa0f3764ad1c190243c98ec4921c2d1c6454d..2e6590d5497ec50db55619c6b7905271ff4894a6
100644
--- a/src/heap-snapshot-generator.cc
+++ b/src/heap-snapshot-generator.cc
@@ -1090,6 +1090,7 @@ void V8HeapExplorer::ExtractJSObjectReferences(
ExtractPropertyReferences(js_obj, entry);
ExtractElementReferences(js_obj, entry);
ExtractInternalReferences(js_obj, entry);
+ ExtractHiddenPropertyReferences(js_obj, entry);
SetPropertyReference(
obj, entry, heap_->proto_string(), js_obj->GetPrototype());
if (obj->IsJSFunction()) {
@@ -1595,6 +1596,31 @@ void
V8HeapExplorer::ExtractPropertyReferences(JSObject* js_obj, int entry) {
}
+void V8HeapExplorer::ExtractHiddenPropertyReferences(JSObject* obj, int
entry) {
+ if (obj->IsJSGlobalProxy()) {
+ // For a proxy, use the prototype as target object.
+ Object* proxy_parent = obj->GetPrototype();
+ // If the proxy is detached, return undefined.
+ if (proxy_parent->IsNull())
+ return;
+ ASSERT(proxy_parent->IsJSGlobalObject());
+ obj = JSObject::cast(proxy_parent);
+ }
+ ASSERT(!obj->IsJSGlobalProxy());
+ Object* inline_value = obj->GetHiddenPropertiesHashTable();
+ if (!inline_value->IsHashTable())
+ return;
+ ObjectHashTable* hashtable = ObjectHashTable::cast(inline_value);
+ int capacity = hashtable->Capacity();
+ for (int i = 0; i < capacity; i++) {
+ Object* k = hashtable->KeyAt(i);
+ if (!k->IsString()) continue;
+ Object* value = hashtable->Lookup(k);
+ SetPropertyReference(obj, entry, String::cast(k), value);
+ }
+}
+
+
bool V8HeapExplorer::ExtractAccessorPairProperty(
JSObject* js_obj, int entry, Object* key, Object* callback_obj) {
if (!callback_obj->IsAccessorPair()) return false;
Index: src/heap-snapshot-generator.h
diff --git a/src/heap-snapshot-generator.h b/src/heap-snapshot-generator.h
index
8717f8f25edccfefe9878b05959897a83578a87e..491790dee0fa5e474fbb4c443bbe86139ef99cb9
100644
--- a/src/heap-snapshot-generator.h
+++ b/src/heap-snapshot-generator.h
@@ -422,6 +422,7 @@ class V8HeapExplorer : public HeapEntriesAllocator {
void ExtractJSArrayBufferReferences(int entry, JSArrayBuffer* buffer);
void ExtractClosureReferences(JSObject* js_obj, int entry);
void ExtractPropertyReferences(JSObject* js_obj, int entry);
+ void ExtractHiddenPropertyReferences(JSObject* obj, int entry);
bool ExtractAccessorPairProperty(JSObject* js_obj, int entry,
Object* key, Object* callback_obj);
void ExtractElementReferences(JSObject* js_obj, int entry);
Index: src/objects.h
diff --git a/src/objects.h b/src/objects.h
index
9f47f8f0721c478c10907636784ed856fc36753f..8f5b17349e6ef03c2362448062c04eef9acf5e45
100644
--- a/src/objects.h
+++ b/src/objects.h
@@ -2737,6 +2737,7 @@ class JSObject: public JSReceiver {
friend class DictionaryElementsAccessor;
friend class JSReceiver;
friend class Object;
+ friend class V8HeapExplorer;
static void UpdateAllocationSite(Handle<JSObject> object,
ElementsKind to_kind);
Index: test/cctest/test-heap-profiler.cc
diff --git a/test/cctest/test-heap-profiler.cc
b/test/cctest/test-heap-profiler.cc
index
c04ed9de13bee42711db470fee3ea1fbcb5b0d3a..7758fdc066cb51c597fcdd544844f1653be4d3ed
100644
--- a/test/cctest/test-heap-profiler.cc
+++ b/test/cctest/test-heap-profiler.cc
@@ -2477,3 +2477,29 @@ TEST(BoxObject) {
GetProperty(box_node, v8::HeapGraphEdge::kInternal, "value");
CHECK_NE(NULL, box_value);
}
+
+
+TEST(JSObjectHiddenProperty) {
+ LocalContext env;
+ v8::Isolate* isolate = env->GetIsolate();
+ v8::HandleScope handle_scope(isolate);
+ v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler();
+
+ v8::Local<v8::Object> an_object = v8::Object::New(isolate);
+ env->Global()->Set(v8_str("an_object"), an_object);
+ CHECK(an_object->SetHiddenValue(v8_str("hidden_key"),
+ v8_str("hidden_value")));
+
+ const v8::HeapSnapshot* snapshot =
+ heap_profiler->TakeHeapSnapshot(v8_str("snapshot"));
+ CHECK(ValidateSnapshot(snapshot));
+ const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
+ const v8::HeapGraphNode* object_node =
+ GetProperty(global, v8::HeapGraphEdge::kProperty, "an_object");
+ CHECK_NE(NULL, object_node);
+ const v8::HeapGraphNode* hidden_node =
+ GetProperty(object_node, v8::HeapGraphEdge::kProperty, "hidden_key");
+ CHECK_NE(NULL, hidden_node);
+ CHECK_EQ(v8::String::NewFromUtf8(env->GetIsolate(), "hidden_value"),
+ hidden_node->GetName());
+}
--
--
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.