Commit 87513237 authored by yurys@chromium.org's avatar yurys@chromium.org

Add support for ES6 Symbol in heap profiler

Heap profiler will create a node with name Symbol and type kSymbol.

BUG=chromium:376194
LOG=Y
R=loislo@chromium.org, yangguo@chromium.org

Review URL: https://codereview.chromium.org/290013004

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@21433 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent acec7363
......@@ -219,19 +219,20 @@ class V8_EXPORT HeapGraphEdge {
class V8_EXPORT HeapGraphNode {
public:
enum Type {
kHidden = 0, // Hidden node, may be filtered when shown to user.
kArray = 1, // An array of elements.
kString = 2, // A string.
kObject = 3, // A JS object (except for arrays and strings).
kCode = 4, // Compiled code.
kClosure = 5, // Function closure.
kRegExp = 6, // RegExp.
kHeapNumber = 7, // Number stored in the heap.
kNative = 8, // Native object (not from V8 heap).
kSynthetic = 9, // Synthetic object, usualy used for grouping
// snapshot items together.
kConsString = 10, // Concatenated string. A pair of pointers to strings.
kSlicedString = 11 // Sliced string. A fragment of another string.
kHidden = 0, // Hidden node, may be filtered when shown to user.
kArray = 1, // An array of elements.
kString = 2, // A string.
kObject = 3, // A JS object (except for arrays and strings).
kCode = 4, // Compiled code.
kClosure = 5, // Function closure.
kRegExp = 6, // RegExp.
kHeapNumber = 7, // Number stored in the heap.
kNative = 8, // Native object (not from V8 heap).
kSynthetic = 9, // Synthetic object, usualy used for grouping
// snapshot items together.
kConsString = 10, // Concatenated string. A pair of pointers to strings.
kSlicedString = 11, // Sliced string. A fragment of another string.
kSymbol = 12 // A Symbol (ES6).
};
/** Returns node type (see HeapGraphNode::Type). */
......
......@@ -155,6 +155,7 @@ const char* HeapEntry::TypeAsString() {
case kSynthetic: return "/synthetic/";
case kConsString: return "/concatenated string/";
case kSlicedString: return "/sliced string/";
case kSymbol: return "/symbol/";
default: return "???";
}
}
......@@ -851,6 +852,8 @@ HeapEntry* V8HeapExplorer::AddEntry(HeapObject* object) {
return AddEntry(object,
HeapEntry::kString,
names_->GetName(String::cast(object)));
} else if (object->IsSymbol()) {
return AddEntry(object, HeapEntry::kSymbol, "symbol");
} else if (object->IsCode()) {
return AddEntry(object, HeapEntry::kCode, "");
} else if (object->IsSharedFunctionInfo()) {
......@@ -1098,6 +1101,8 @@ bool V8HeapExplorer::ExtractReferencesPass1(int entry, HeapObject* obj) {
ExtractJSObjectReferences(entry, JSObject::cast(obj));
} else if (obj->IsString()) {
ExtractStringReferences(entry, String::cast(obj));
} else if (obj->IsSymbol()) {
ExtractSymbolReferences(entry, Symbol::cast(obj));
} else if (obj->IsMap()) {
ExtractMapReferences(entry, Map::cast(obj));
} else if (obj->IsSharedFunctionInfo()) {
......@@ -1244,6 +1249,13 @@ void V8HeapExplorer::ExtractStringReferences(int entry, String* string) {
}
void V8HeapExplorer::ExtractSymbolReferences(int entry, Symbol* symbol) {
SetInternalReference(symbol, entry,
"name", symbol->name(),
Symbol::kNameOffset);
}
void V8HeapExplorer::ExtractContextReferences(int entry, Context* context) {
if (context == context->declaration_context()) {
ScopeInfo* scope_info = context->closure()->shared()->scope_info();
......
......@@ -83,7 +83,8 @@ class HeapEntry BASE_EMBEDDED {
kNative = v8::HeapGraphNode::kNative,
kSynthetic = v8::HeapGraphNode::kSynthetic,
kConsString = v8::HeapGraphNode::kConsString,
kSlicedString = v8::HeapGraphNode::kSlicedString
kSlicedString = v8::HeapGraphNode::kSlicedString,
kSymbol = v8::HeapGraphNode::kSymbol
};
static const int kNoEntry;
......@@ -368,6 +369,7 @@ class V8HeapExplorer : public HeapEntriesAllocator {
void ExtractJSGlobalProxyReferences(int entry, JSGlobalProxy* proxy);
void ExtractJSObjectReferences(int entry, JSObject* js_obj);
void ExtractStringReferences(int entry, String* obj);
void ExtractSymbolReferences(int entry, Symbol* symbol);
void ExtractContextReferences(int entry, Context* context);
void ExtractMapReferences(int entry, Map* map);
void ExtractSharedFunctionInfoReferences(int entry,
......
......@@ -471,6 +471,29 @@ TEST(HeapSnapshotConsString) {
}
TEST(HeapSnapshotSymbol) {
i::FLAG_harmony_symbols = true;
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
CompileRun("a = Symbol('mySymbol');\n");
const v8::HeapSnapshot* snapshot =
heap_profiler->TakeHeapSnapshot(v8_str("Symbol"));
CHECK(ValidateSnapshot(snapshot));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
const v8::HeapGraphNode* a =
GetProperty(global, v8::HeapGraphEdge::kProperty, "a");
CHECK_NE(NULL, a);
CHECK_EQ(a->GetType(), v8::HeapGraphNode::kSymbol);
CHECK_EQ(v8_str("symbol"), a->GetName());
const v8::HeapGraphNode* name =
GetProperty(a, v8::HeapGraphEdge::kInternal, "name");
CHECK_NE(NULL, name);
CHECK_EQ(v8_str("mySymbol"), name->GetName());
}
TEST(HeapSnapshotInternalReferences) {
v8::Isolate* isolate = CcTest::isolate();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment