OLD | NEW |
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 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 CHECK_NE(NULL, a); | 488 CHECK_NE(NULL, a); |
489 CHECK_EQ(a->GetType(), v8::HeapGraphNode::kSymbol); | 489 CHECK_EQ(a->GetType(), v8::HeapGraphNode::kSymbol); |
490 CHECK_EQ(v8_str("symbol"), a->GetName()); | 490 CHECK_EQ(v8_str("symbol"), a->GetName()); |
491 const v8::HeapGraphNode* name = | 491 const v8::HeapGraphNode* name = |
492 GetProperty(a, v8::HeapGraphEdge::kInternal, "name"); | 492 GetProperty(a, v8::HeapGraphEdge::kInternal, "name"); |
493 CHECK_NE(NULL, name); | 493 CHECK_NE(NULL, name); |
494 CHECK_EQ(v8_str("mySymbol"), name->GetName()); | 494 CHECK_EQ(v8_str("mySymbol"), name->GetName()); |
495 } | 495 } |
496 | 496 |
497 | 497 |
| 498 TEST(HeapSnapshotWeakCollection) { |
| 499 i::FLAG_harmony_collections = true; |
| 500 |
| 501 LocalContext env; |
| 502 v8::HandleScope scope(env->GetIsolate()); |
| 503 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
| 504 |
| 505 CompileRun("k = {}; v = {};\n" |
| 506 "ws = new WeakSet(); ws.add(k); ws.add(v);\n" |
| 507 "wm = new WeakMap(); wm.set(k, v);\n"); |
| 508 const v8::HeapSnapshot* snapshot = |
| 509 heap_profiler->TakeHeapSnapshot(v8_str("WeakCollections")); |
| 510 CHECK(ValidateSnapshot(snapshot)); |
| 511 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
| 512 const v8::HeapGraphNode* k = |
| 513 GetProperty(global, v8::HeapGraphEdge::kProperty, "k"); |
| 514 CHECK_NE(NULL, k); |
| 515 const v8::HeapGraphNode* v = |
| 516 GetProperty(global, v8::HeapGraphEdge::kProperty, "v"); |
| 517 CHECK_NE(NULL, v); |
| 518 |
| 519 const v8::HeapGraphNode* ws = |
| 520 GetProperty(global, v8::HeapGraphEdge::kProperty, "ws"); |
| 521 CHECK_NE(NULL, ws); |
| 522 CHECK_EQ(v8::HeapGraphNode::kObject, ws->GetType()); |
| 523 CHECK_EQ(v8_str("WeakSet"), ws->GetName()); |
| 524 |
| 525 const v8::HeapGraphNode* ws_table = |
| 526 GetProperty(ws, v8::HeapGraphEdge::kInternal, "table"); |
| 527 CHECK_EQ(v8::HeapGraphNode::kArray, ws_table->GetType()); |
| 528 CHECK_GT(ws_table->GetChildrenCount(), 0); |
| 529 int weak_entries = 0; |
| 530 for (int i = 0, count = ws_table->GetChildrenCount(); i < count; ++i) { |
| 531 const v8::HeapGraphEdge* prop = ws_table->GetChild(i); |
| 532 if (prop->GetType() != v8::HeapGraphEdge::kWeak) continue; |
| 533 if (k->GetId() == prop->GetToNode()->GetId()) { |
| 534 ++weak_entries; |
| 535 } |
| 536 } |
| 537 CHECK_EQ(1, weak_entries); |
| 538 |
| 539 const v8::HeapGraphNode* wm = |
| 540 GetProperty(global, v8::HeapGraphEdge::kProperty, "wm"); |
| 541 CHECK_NE(NULL, wm); |
| 542 CHECK_EQ(v8::HeapGraphNode::kObject, wm->GetType()); |
| 543 CHECK_EQ(v8_str("WeakMap"), wm->GetName()); |
| 544 |
| 545 const v8::HeapGraphNode* wm_table = |
| 546 GetProperty(wm, v8::HeapGraphEdge::kInternal, "table"); |
| 547 CHECK_EQ(v8::HeapGraphNode::kArray, wm_table->GetType()); |
| 548 CHECK_GT(wm_table->GetChildrenCount(), 0); |
| 549 weak_entries = 0; |
| 550 for (int i = 0, count = wm_table->GetChildrenCount(); i < count; ++i) { |
| 551 const v8::HeapGraphEdge* prop = wm_table->GetChild(i); |
| 552 if (prop->GetType() != v8::HeapGraphEdge::kWeak) continue; |
| 553 const v8::SnapshotObjectId to_node_id = prop->GetToNode()->GetId(); |
| 554 if (to_node_id == k->GetId() || to_node_id == v->GetId()) { |
| 555 ++weak_entries; |
| 556 } |
| 557 } |
| 558 CHECK_EQ(2, weak_entries); |
| 559 } |
| 560 |
| 561 |
498 TEST(HeapSnapshotInternalReferences) { | 562 TEST(HeapSnapshotInternalReferences) { |
499 v8::Isolate* isolate = CcTest::isolate(); | 563 v8::Isolate* isolate = CcTest::isolate(); |
500 v8::HandleScope scope(isolate); | 564 v8::HandleScope scope(isolate); |
501 v8::Local<v8::ObjectTemplate> global_template = | 565 v8::Local<v8::ObjectTemplate> global_template = |
502 v8::ObjectTemplate::New(isolate); | 566 v8::ObjectTemplate::New(isolate); |
503 global_template->SetInternalFieldCount(2); | 567 global_template->SetInternalFieldCount(2); |
504 LocalContext env(NULL, global_template); | 568 LocalContext env(NULL, global_template); |
505 v8::Handle<v8::Object> global_proxy = env->Global(); | 569 v8::Handle<v8::Object> global_proxy = env->Global(); |
506 v8::Handle<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>(); | 570 v8::Handle<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>(); |
507 CHECK_EQ(2, global->InternalFieldCount()); | 571 CHECK_EQ(2, global->InternalFieldCount()); |
(...skipping 2105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2613 map.AddRange(ToAddress(0x180), 0x80, 6U); | 2677 map.AddRange(ToAddress(0x180), 0x80, 6U); |
2614 map.AddRange(ToAddress(0x180), 0x80, 7U); | 2678 map.AddRange(ToAddress(0x180), 0x80, 7U); |
2615 CHECK_EQ(7, map.GetTraceNodeId(ToAddress(0x180))); | 2679 CHECK_EQ(7, map.GetTraceNodeId(ToAddress(0x180))); |
2616 CHECK_EQ(5, map.GetTraceNodeId(ToAddress(0x200))); | 2680 CHECK_EQ(5, map.GetTraceNodeId(ToAddress(0x200))); |
2617 CHECK_EQ(3, static_cast<int>(map.size())); | 2681 CHECK_EQ(3, static_cast<int>(map.size())); |
2618 | 2682 |
2619 map.Clear(); | 2683 map.Clear(); |
2620 CHECK_EQ(0, static_cast<int>(map.size())); | 2684 CHECK_EQ(0, static_cast<int>(map.size())); |
2621 CHECK_EQ(0, map.GetTraceNodeId(ToAddress(0x400))); | 2685 CHECK_EQ(0, map.GetTraceNodeId(ToAddress(0x400))); |
2622 } | 2686 } |
OLD | NEW |