Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(479)

Side by Side Diff: test/cctest/test-heap-profiler.cc

Issue 380153002: Revert "Support ES6 Map and Set in heap profiler" (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/objects-inl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 } 495 }
496 496
497 497
498 TEST(HeapSnapshotWeakCollection) { 498 TEST(HeapSnapshotWeakCollection) {
499 i::FLAG_harmony_collections = true; 499 i::FLAG_harmony_collections = true;
500 500
501 LocalContext env; 501 LocalContext env;
502 v8::HandleScope scope(env->GetIsolate()); 502 v8::HandleScope scope(env->GetIsolate());
503 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 503 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
504 504
505 CompileRun( 505 CompileRun("k = {}; v = {};\n"
506 "k = {}; v = {}; s = 'str';\n" 506 "ws = new WeakSet(); ws.add(k); ws.add(v);\n"
507 "ws = new WeakSet(); ws.add(k); ws.add(v); ws[s] = s;\n" 507 "wm = new WeakMap(); wm.set(k, v);\n");
508 "wm = new WeakMap(); wm.set(k, v); wm[s] = s;\n");
509 const v8::HeapSnapshot* snapshot = 508 const v8::HeapSnapshot* snapshot =
510 heap_profiler->TakeHeapSnapshot(v8_str("WeakCollections")); 509 heap_profiler->TakeHeapSnapshot(v8_str("WeakCollections"));
511 CHECK(ValidateSnapshot(snapshot)); 510 CHECK(ValidateSnapshot(snapshot));
512 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 511 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
513 const v8::HeapGraphNode* k = 512 const v8::HeapGraphNode* k =
514 GetProperty(global, v8::HeapGraphEdge::kProperty, "k"); 513 GetProperty(global, v8::HeapGraphEdge::kProperty, "k");
515 CHECK_NE(NULL, k); 514 CHECK_NE(NULL, k);
516 const v8::HeapGraphNode* v = 515 const v8::HeapGraphNode* v =
517 GetProperty(global, v8::HeapGraphEdge::kProperty, "v"); 516 GetProperty(global, v8::HeapGraphEdge::kProperty, "v");
518 CHECK_NE(NULL, v); 517 CHECK_NE(NULL, v);
519 const v8::HeapGraphNode* s =
520 GetProperty(global, v8::HeapGraphEdge::kProperty, "s");
521 CHECK_NE(NULL, s);
522 518
523 const v8::HeapGraphNode* ws = 519 const v8::HeapGraphNode* ws =
524 GetProperty(global, v8::HeapGraphEdge::kProperty, "ws"); 520 GetProperty(global, v8::HeapGraphEdge::kProperty, "ws");
525 CHECK_NE(NULL, ws); 521 CHECK_NE(NULL, ws);
526 CHECK_EQ(v8::HeapGraphNode::kObject, ws->GetType()); 522 CHECK_EQ(v8::HeapGraphNode::kObject, ws->GetType());
527 CHECK_EQ(v8_str("WeakSet"), ws->GetName()); 523 CHECK_EQ(v8_str("WeakSet"), ws->GetName());
528 524
529 const v8::HeapGraphNode* ws_table = 525 const v8::HeapGraphNode* ws_table =
530 GetProperty(ws, v8::HeapGraphEdge::kInternal, "table"); 526 GetProperty(ws, v8::HeapGraphEdge::kInternal, "table");
531 CHECK_EQ(v8::HeapGraphNode::kArray, ws_table->GetType()); 527 CHECK_EQ(v8::HeapGraphNode::kArray, ws_table->GetType());
532 CHECK_GT(ws_table->GetChildrenCount(), 0); 528 CHECK_GT(ws_table->GetChildrenCount(), 0);
533 int weak_entries = 0; 529 int weak_entries = 0;
534 for (int i = 0, count = ws_table->GetChildrenCount(); i < count; ++i) { 530 for (int i = 0, count = ws_table->GetChildrenCount(); i < count; ++i) {
535 const v8::HeapGraphEdge* prop = ws_table->GetChild(i); 531 const v8::HeapGraphEdge* prop = ws_table->GetChild(i);
536 if (prop->GetType() != v8::HeapGraphEdge::kWeak) continue; 532 if (prop->GetType() != v8::HeapGraphEdge::kWeak) continue;
537 if (k->GetId() == prop->GetToNode()->GetId()) { 533 if (k->GetId() == prop->GetToNode()->GetId()) {
538 ++weak_entries; 534 ++weak_entries;
539 } 535 }
540 } 536 }
541 CHECK_EQ(1, weak_entries); 537 CHECK_EQ(1, weak_entries);
542 const v8::HeapGraphNode* ws_s =
543 GetProperty(ws, v8::HeapGraphEdge::kProperty, "str");
544 CHECK_NE(NULL, ws_s);
545 CHECK_EQ(static_cast<int>(s->GetId()), static_cast<int>(ws_s->GetId()));
546 538
547 const v8::HeapGraphNode* wm = 539 const v8::HeapGraphNode* wm =
548 GetProperty(global, v8::HeapGraphEdge::kProperty, "wm"); 540 GetProperty(global, v8::HeapGraphEdge::kProperty, "wm");
549 CHECK_NE(NULL, wm); 541 CHECK_NE(NULL, wm);
550 CHECK_EQ(v8::HeapGraphNode::kObject, wm->GetType()); 542 CHECK_EQ(v8::HeapGraphNode::kObject, wm->GetType());
551 CHECK_EQ(v8_str("WeakMap"), wm->GetName()); 543 CHECK_EQ(v8_str("WeakMap"), wm->GetName());
552 544
553 const v8::HeapGraphNode* wm_table = 545 const v8::HeapGraphNode* wm_table =
554 GetProperty(wm, v8::HeapGraphEdge::kInternal, "table"); 546 GetProperty(wm, v8::HeapGraphEdge::kInternal, "table");
555 CHECK_EQ(v8::HeapGraphNode::kArray, wm_table->GetType()); 547 CHECK_EQ(v8::HeapGraphNode::kArray, wm_table->GetType());
556 CHECK_GT(wm_table->GetChildrenCount(), 0); 548 CHECK_GT(wm_table->GetChildrenCount(), 0);
557 weak_entries = 0; 549 weak_entries = 0;
558 for (int i = 0, count = wm_table->GetChildrenCount(); i < count; ++i) { 550 for (int i = 0, count = wm_table->GetChildrenCount(); i < count; ++i) {
559 const v8::HeapGraphEdge* prop = wm_table->GetChild(i); 551 const v8::HeapGraphEdge* prop = wm_table->GetChild(i);
560 if (prop->GetType() != v8::HeapGraphEdge::kWeak) continue; 552 if (prop->GetType() != v8::HeapGraphEdge::kWeak) continue;
561 const v8::SnapshotObjectId to_node_id = prop->GetToNode()->GetId(); 553 const v8::SnapshotObjectId to_node_id = prop->GetToNode()->GetId();
562 if (to_node_id == k->GetId() || to_node_id == v->GetId()) { 554 if (to_node_id == k->GetId() || to_node_id == v->GetId()) {
563 ++weak_entries; 555 ++weak_entries;
564 } 556 }
565 } 557 }
566 CHECK_EQ(2, weak_entries); 558 CHECK_EQ(2, weak_entries);
567 const v8::HeapGraphNode* wm_s =
568 GetProperty(wm, v8::HeapGraphEdge::kProperty, "str");
569 CHECK_NE(NULL, wm_s);
570 CHECK_EQ(static_cast<int>(s->GetId()), static_cast<int>(wm_s->GetId()));
571 } 559 }
572 560
573 561
574 TEST(HeapSnapshotCollection) {
575 i::FLAG_harmony_collections = true;
576
577 LocalContext env;
578 v8::HandleScope scope(env->GetIsolate());
579 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
580
581 CompileRun(
582 "k = {}; v = {}; s = 'str';\n"
583 "set = new Set(); set.add(k); set.add(v); set[s] = s;\n"
584 "map = new Map(); map.set(k, v); map[s] = s;\n");
585 const v8::HeapSnapshot* snapshot =
586 heap_profiler->TakeHeapSnapshot(v8_str("Collections"));
587 CHECK(ValidateSnapshot(snapshot));
588 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
589 const v8::HeapGraphNode* k =
590 GetProperty(global, v8::HeapGraphEdge::kProperty, "k");
591 CHECK_NE(NULL, k);
592 const v8::HeapGraphNode* v =
593 GetProperty(global, v8::HeapGraphEdge::kProperty, "v");
594 CHECK_NE(NULL, v);
595 const v8::HeapGraphNode* s =
596 GetProperty(global, v8::HeapGraphEdge::kProperty, "s");
597 CHECK_NE(NULL, s);
598
599 const v8::HeapGraphNode* set =
600 GetProperty(global, v8::HeapGraphEdge::kProperty, "set");
601 CHECK_NE(NULL, set);
602 CHECK_EQ(v8::HeapGraphNode::kObject, set->GetType());
603 CHECK_EQ(v8_str("Set"), set->GetName());
604
605 const v8::HeapGraphNode* set_table =
606 GetProperty(set, v8::HeapGraphEdge::kInternal, "table");
607 CHECK_EQ(v8::HeapGraphNode::kArray, set_table->GetType());
608 CHECK_GT(set_table->GetChildrenCount(), 0);
609 int entries = 0;
610 for (int i = 0, count = set_table->GetChildrenCount(); i < count; ++i) {
611 const v8::HeapGraphEdge* prop = set_table->GetChild(i);
612 const v8::SnapshotObjectId to_node_id = prop->GetToNode()->GetId();
613 if (to_node_id == k->GetId() || to_node_id == v->GetId()) {
614 ++entries;
615 }
616 }
617 CHECK_EQ(2, entries);
618 const v8::HeapGraphNode* set_s =
619 GetProperty(set, v8::HeapGraphEdge::kProperty, "str");
620 CHECK_NE(NULL, set_s);
621 CHECK_EQ(static_cast<int>(s->GetId()), static_cast<int>(set_s->GetId()));
622
623 const v8::HeapGraphNode* map =
624 GetProperty(global, v8::HeapGraphEdge::kProperty, "map");
625 CHECK_NE(NULL, map);
626 CHECK_EQ(v8::HeapGraphNode::kObject, map->GetType());
627 CHECK_EQ(v8_str("Map"), map->GetName());
628
629 const v8::HeapGraphNode* map_table =
630 GetProperty(map, v8::HeapGraphEdge::kInternal, "table");
631 CHECK_EQ(v8::HeapGraphNode::kArray, map_table->GetType());
632 CHECK_GT(map_table->GetChildrenCount(), 0);
633 entries = 0;
634 for (int i = 0, count = map_table->GetChildrenCount(); i < count; ++i) {
635 const v8::HeapGraphEdge* prop = map_table->GetChild(i);
636 const v8::SnapshotObjectId to_node_id = prop->GetToNode()->GetId();
637 if (to_node_id == k->GetId() || to_node_id == v->GetId()) {
638 ++entries;
639 }
640 }
641 CHECK_EQ(2, entries);
642 const v8::HeapGraphNode* map_s =
643 GetProperty(map, v8::HeapGraphEdge::kProperty, "str");
644 CHECK_NE(NULL, map_s);
645 CHECK_EQ(static_cast<int>(s->GetId()), static_cast<int>(map_s->GetId()));
646 }
647
648
649 TEST(HeapSnapshotInternalReferences) { 562 TEST(HeapSnapshotInternalReferences) {
650 v8::Isolate* isolate = CcTest::isolate(); 563 v8::Isolate* isolate = CcTest::isolate();
651 v8::HandleScope scope(isolate); 564 v8::HandleScope scope(isolate);
652 v8::Local<v8::ObjectTemplate> global_template = 565 v8::Local<v8::ObjectTemplate> global_template =
653 v8::ObjectTemplate::New(isolate); 566 v8::ObjectTemplate::New(isolate);
654 global_template->SetInternalFieldCount(2); 567 global_template->SetInternalFieldCount(2);
655 LocalContext env(NULL, global_template); 568 LocalContext env(NULL, global_template);
656 v8::Handle<v8::Object> global_proxy = env->Global(); 569 v8::Handle<v8::Object> global_proxy = env->Global();
657 v8::Handle<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>(); 570 v8::Handle<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>();
658 CHECK_EQ(2, global->InternalFieldCount()); 571 CHECK_EQ(2, global->InternalFieldCount());
(...skipping 2104 matching lines...) Expand 10 before | Expand all | Expand 10 after
2763 map.AddRange(ToAddress(0x180), 0x80, 6U); 2676 map.AddRange(ToAddress(0x180), 0x80, 6U);
2764 map.AddRange(ToAddress(0x180), 0x80, 7U); 2677 map.AddRange(ToAddress(0x180), 0x80, 7U);
2765 CHECK_EQ(7, map.GetTraceNodeId(ToAddress(0x180))); 2678 CHECK_EQ(7, map.GetTraceNodeId(ToAddress(0x180)));
2766 CHECK_EQ(5, map.GetTraceNodeId(ToAddress(0x200))); 2679 CHECK_EQ(5, map.GetTraceNodeId(ToAddress(0x200)));
2767 CHECK_EQ(3, static_cast<int>(map.size())); 2680 CHECK_EQ(3, static_cast<int>(map.size()));
2768 2681
2769 map.Clear(); 2682 map.Clear();
2770 CHECK_EQ(0, static_cast<int>(map.size())); 2683 CHECK_EQ(0, static_cast<int>(map.size()));
2771 CHECK_EQ(0, map.GetTraceNodeId(ToAddress(0x400))); 2684 CHECK_EQ(0, map.GetTraceNodeId(ToAddress(0x400)));
2772 } 2685 }
OLDNEW
« no previous file with comments | « src/objects-inl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698