From 956ac1bd1574d4664b6796d69625a0a6a28a8c9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Inf=C3=BChr?= Date: Tue, 24 Jul 2018 16:05:02 +0200 Subject: [PATCH] [heap-profiler] Names for JSGeneratorObject-fields MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add names for fields in JSGeneratorObjects in Heap Snapshot Generator. Bug: chromium:854097 Change-Id: I075acf0821c9d002535b4fdc4ce4ddbb2fc9627c Reviewed-on: https://chromium-review.googlesource.com/1148387 Commit-Queue: Dominik Inführ Reviewed-by: Ulan Degenbaev Cr-Commit-Position: refs/heads/master@{#54652} --- src/objects.h | 1 + src/profiler/heap-snapshot-generator.cc | 16 ++++++++++++++ src/profiler/heap-snapshot-generator.h | 2 ++ test/cctest/test-heap-profiler.cc | 29 +++++++++++++++++++++++++ 4 files changed, 48 insertions(+) diff --git a/src/objects.h b/src/objects.h index 69ecdbcbdc..dcac7ecfc0 100644 --- a/src/objects.h +++ b/src/objects.h @@ -692,6 +692,7 @@ class FixedArrayBase; class PropertyArray; class FunctionLiteral; class FunctionTemplateInfo; +class JSGeneratorObject; class JSAsyncGeneratorObject; class JSGlobalObject; class JSGlobalProxy; diff --git a/src/profiler/heap-snapshot-generator.cc b/src/profiler/heap-snapshot-generator.cc index 53d56c2283..8e5fd746e8 100644 --- a/src/profiler/heap-snapshot-generator.cc +++ b/src/profiler/heap-snapshot-generator.cc @@ -17,6 +17,7 @@ #include "src/objects/api-callbacks.h" #include "src/objects/hash-table-inl.h" #include "src/objects/js-collection-inl.h" +#include "src/objects/js-generator-inl.h" #include "src/objects/js-promise-inl.h" #include "src/objects/js-regexp-inl.h" #include "src/objects/literal-objects-inl.h" @@ -854,6 +855,8 @@ void V8HeapExplorer::ExtractReferences(int entry, HeapObject* obj) { ExtractJSCollectionReferences(entry, JSMap::cast(obj)); } else if (obj->IsJSPromise()) { ExtractJSPromiseReferences(entry, JSPromise::cast(obj)); + } else if (obj->IsJSGeneratorObject()) { + ExtractJSGeneratorObjectReferences(entry, JSGeneratorObject::cast(obj)); } ExtractJSObjectReferences(entry, JSObject::cast(obj)); } else if (obj->IsString()) { @@ -1356,6 +1359,19 @@ void V8HeapExplorer::ExtractJSPromiseReferences(int entry, JSPromise* promise) { JSPromise::kReactionsOrResultOffset); } +void V8HeapExplorer::ExtractJSGeneratorObjectReferences( + int entry, JSGeneratorObject* generator) { + SetInternalReference(generator, entry, "function", generator->function(), + JSGeneratorObject::kFunctionOffset); + SetInternalReference(generator, entry, "context", generator->context(), + JSGeneratorObject::kContextOffset); + SetInternalReference(generator, entry, "receiver", generator->receiver(), + JSGeneratorObject::kReceiverOffset); + SetInternalReference(generator, entry, "parameters_and_registers", + generator->parameters_and_registers(), + JSGeneratorObject::kParametersAndRegistersOffset); +} + void V8HeapExplorer::ExtractFixedArrayReferences(int entry, FixedArray* array) { for (int i = 0, l = array->length(); i < l; ++i) { DCHECK(!HasWeakHeapObjectTag(array->get(i))); diff --git a/src/profiler/heap-snapshot-generator.h b/src/profiler/heap-snapshot-generator.h index 4f4fbee742..1ebb899208 100644 --- a/src/profiler/heap-snapshot-generator.h +++ b/src/profiler/heap-snapshot-generator.h @@ -392,6 +392,8 @@ class V8HeapExplorer : public HeapEntriesAllocator { int entry, ArrayBoilerplateDescription* value); void ExtractJSArrayBufferReferences(int entry, JSArrayBuffer* buffer); void ExtractJSPromiseReferences(int entry, JSPromise* promise); + void ExtractJSGeneratorObjectReferences(int entry, + JSGeneratorObject* generator); void ExtractFixedArrayReferences(int entry, FixedArray* array); void ExtractFeedbackVectorReferences(int entry, FeedbackVector* feedback_vector); diff --git a/test/cctest/test-heap-profiler.cc b/test/cctest/test-heap-profiler.cc index 4b80ccb1f9..033a827ab7 100644 --- a/test/cctest/test-heap-profiler.cc +++ b/test/cctest/test-heap-profiler.cc @@ -2134,6 +2134,35 @@ TEST(AccessorInfo) { CHECK(setter); } +TEST(JSGeneratorObject) { + v8::Isolate* isolate = CcTest::isolate(); + LocalContext env; + v8::HandleScope scope(isolate); + v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler(); + + CompileRun( + "function* foo() { yield 1; }\n" + "g = foo();\n"); + const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); + CHECK(ValidateSnapshot(snapshot)); + const v8::HeapGraphNode* global = GetGlobalObject(snapshot); + const v8::HeapGraphNode* g = + GetProperty(isolate, global, v8::HeapGraphEdge::kProperty, "g"); + CHECK(g); + const v8::HeapGraphNode* function = GetProperty( + env->GetIsolate(), g, v8::HeapGraphEdge::kInternal, "function"); + CHECK(function); + const v8::HeapGraphNode* context = GetProperty( + env->GetIsolate(), g, v8::HeapGraphEdge::kInternal, "context"); + CHECK(context); + const v8::HeapGraphNode* receiver = GetProperty( + env->GetIsolate(), g, v8::HeapGraphEdge::kInternal, "receiver"); + CHECK(receiver); + const v8::HeapGraphNode* parameters_and_registers = + GetProperty(env->GetIsolate(), g, v8::HeapGraphEdge::kInternal, + "parameters_and_registers"); + CHECK(parameters_and_registers); +} bool HasWeakEdge(const v8::HeapGraphNode* node) { for (int i = 0; i < node->GetChildrenCount(); ++i) {