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 for (int i = 0, count = ws_table->GetChildrenCount(); i < count; ++i) { | |
530 const v8::HeapGraphEdge* prop = ws_table->GetChild(i); | |
531 if (prop->GetType() != v8::HeapGraphEdge::kElement) continue; | |
alph
2014/05/22 15:41:40
kWeak
Also check that you've found exactly one.
yurys
2014/05/22 15:47:33
Done.
| |
532 const v8::SnapshotObjectId to_node_id = prop->GetToNode()->GetId(); | |
533 CHECK(to_node_id == k->GetId() || to_node_id == v->GetId()); | |
534 } | |
535 | |
536 const v8::HeapGraphNode* wm = | |
537 GetProperty(global, v8::HeapGraphEdge::kProperty, "wm"); | |
538 CHECK_NE(NULL, wm); | |
539 CHECK_EQ(v8::HeapGraphNode::kObject, wm->GetType()); | |
540 CHECK_EQ(v8_str("WeakMap"), wm->GetName()); | |
541 | |
542 const v8::HeapGraphNode* wm_table = | |
543 GetProperty(wm, v8::HeapGraphEdge::kInternal, "table"); | |
544 CHECK_EQ(v8::HeapGraphNode::kArray, wm_table->GetType()); | |
545 CHECK_GT(wm_table->GetChildrenCount(), 0); | |
546 for (int i = 0, count = wm_table->GetChildrenCount(); i < count; ++i) { | |
547 const v8::HeapGraphEdge* prop = wm_table->GetChild(i); | |
548 if (prop->GetType() != v8::HeapGraphEdge::kElement) continue; | |
alph
2014/05/22 15:41:40
Ditto
yurys
2014/05/22 15:47:33
Done.
| |
549 const v8::SnapshotObjectId to_node_id = prop->GetToNode()->GetId(); | |
550 CHECK(to_node_id == k->GetId() || to_node_id == v->GetId()); | |
551 } | |
552 } | |
553 | |
554 | |
498 TEST(HeapSnapshotInternalReferences) { | 555 TEST(HeapSnapshotInternalReferences) { |
499 v8::Isolate* isolate = CcTest::isolate(); | 556 v8::Isolate* isolate = CcTest::isolate(); |
500 v8::HandleScope scope(isolate); | 557 v8::HandleScope scope(isolate); |
501 v8::Local<v8::ObjectTemplate> global_template = | 558 v8::Local<v8::ObjectTemplate> global_template = |
502 v8::ObjectTemplate::New(isolate); | 559 v8::ObjectTemplate::New(isolate); |
503 global_template->SetInternalFieldCount(2); | 560 global_template->SetInternalFieldCount(2); |
504 LocalContext env(NULL, global_template); | 561 LocalContext env(NULL, global_template); |
505 v8::Handle<v8::Object> global_proxy = env->Global(); | 562 v8::Handle<v8::Object> global_proxy = env->Global(); |
506 v8::Handle<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>(); | 563 v8::Handle<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>(); |
507 CHECK_EQ(2, global->InternalFieldCount()); | 564 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); | 2670 map.AddRange(ToAddress(0x180), 0x80, 6U); |
2614 map.AddRange(ToAddress(0x180), 0x80, 7U); | 2671 map.AddRange(ToAddress(0x180), 0x80, 7U); |
2615 CHECK_EQ(7, map.GetTraceNodeId(ToAddress(0x180))); | 2672 CHECK_EQ(7, map.GetTraceNodeId(ToAddress(0x180))); |
2616 CHECK_EQ(5, map.GetTraceNodeId(ToAddress(0x200))); | 2673 CHECK_EQ(5, map.GetTraceNodeId(ToAddress(0x200))); |
2617 CHECK_EQ(3, static_cast<int>(map.size())); | 2674 CHECK_EQ(3, static_cast<int>(map.size())); |
2618 | 2675 |
2619 map.Clear(); | 2676 map.Clear(); |
2620 CHECK_EQ(0, static_cast<int>(map.size())); | 2677 CHECK_EQ(0, static_cast<int>(map.size())); |
2621 CHECK_EQ(0, map.GetTraceNodeId(ToAddress(0x400))); | 2678 CHECK_EQ(0, map.GetTraceNodeId(ToAddress(0x400))); |
2622 } | 2679 } |
OLD | NEW |