| Index: test/cctest/test-heap-profiler.cc
|
| diff --git a/test/cctest/test-heap-profiler.cc b/test/cctest/test-heap-profiler.cc
|
| index c04ed9de13bee42711db470fee3ea1fbcb5b0d3a..f1ccc571dabcfef9766da81c7f6a367cef469838 100644
|
| --- a/test/cctest/test-heap-profiler.cc
|
| +++ b/test/cctest/test-heap-profiler.cc
|
| @@ -2216,8 +2216,9 @@ static AllocationTraceNode* FindNode(
|
| Vector<AllocationTraceNode*> children = node->children();
|
| node = NULL;
|
| for (int j = 0; j < children.length(); j++) {
|
| - v8::SnapshotObjectId id = children[j]->function_id();
|
| - AllocationTracker::FunctionInfo* info = tracker->GetFunctionInfo(id);
|
| + unsigned index = children[j]->function_info_index();
|
| + AllocationTracker::FunctionInfo* info =
|
| + tracker->function_info_list()[index];
|
| if (info && strcmp(info->name, name) == 0) {
|
| node = children[j];
|
| break;
|
| @@ -2364,6 +2365,34 @@ TEST(TrackBumpPointerAllocations) {
|
| }
|
|
|
|
|
| +TEST(TrackV8ApiAllocation) {
|
| + v8::HandleScope scope(v8::Isolate::GetCurrent());
|
| + LocalContext env;
|
| +
|
| + v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
|
| + const char* names[] = { "(V8 API)" };
|
| + heap_profiler->StartTrackingHeapObjects(true);
|
| +
|
| + v8::Handle<v8::Object> o1 = v8::Object::New(env->GetIsolate());
|
| + o1->Clone();
|
| +
|
| + AllocationTracker* tracker =
|
| + reinterpret_cast<i::HeapProfiler*>(heap_profiler)->allocation_tracker();
|
| + CHECK_NE(NULL, tracker);
|
| + // Resolve all function locations.
|
| + tracker->PrepareForSerialization();
|
| + // Print for better diagnostics in case of failure.
|
| + tracker->trace_tree()->Print(tracker);
|
| +
|
| + AllocationTraceNode* node =
|
| + FindNode(tracker, Vector<const char*>(names, ARRAY_SIZE(names)));
|
| + CHECK_NE(NULL, node);
|
| + CHECK_GE(node->allocation_count(), 2);
|
| + CHECK_GE(node->allocation_size(), 4 * node->allocation_count());
|
| + heap_profiler->StopTrackingHeapObjects();
|
| +}
|
| +
|
| +
|
| TEST(ArrayBufferAndArrayBufferView) {
|
| LocalContext env;
|
| v8::HandleScope scope(env->GetIsolate());
|
| @@ -2477,3 +2506,63 @@ TEST(BoxObject) {
|
| GetProperty(box_node, v8::HeapGraphEdge::kInternal, "value");
|
| CHECK_NE(NULL, box_value);
|
| }
|
| +
|
| +
|
| +static inline i::Address ToAddress(int n) {
|
| + return reinterpret_cast<i::Address>(n);
|
| +}
|
| +
|
| +
|
| +TEST(AddressToTraceMap) {
|
| + i::AddressToTraceMap map;
|
| +
|
| + CHECK_EQ(0, map.GetTraceNodeId(ToAddress(150)));
|
| +
|
| + // [0x100, 0x200) -> 1
|
| + map.AddRange(ToAddress(0x100), 0x100, 1U);
|
| + CHECK_EQ(0, map.GetTraceNodeId(ToAddress(0x50)));
|
| + CHECK_EQ(1, map.GetTraceNodeId(ToAddress(0x100)));
|
| + CHECK_EQ(1, map.GetTraceNodeId(ToAddress(0x150)));
|
| + CHECK_EQ(0, map.GetTraceNodeId(ToAddress(0x100 + 0x100)));
|
| + CHECK_EQ(1, static_cast<int>(map.size()));
|
| +
|
| + // [0x100, 0x200) -> 1, [0x200, 0x300) -> 2
|
| + map.AddRange(ToAddress(0x200), 0x100, 2U);
|
| + CHECK_EQ(2, map.GetTraceNodeId(ToAddress(0x2a0)));
|
| + CHECK_EQ(2, static_cast<int>(map.size()));
|
| +
|
| + // [0x100, 0x180) -> 1, [0x180, 0x280) -> 3, [0x280, 0x300) -> 2
|
| + map.AddRange(ToAddress(0x180), 0x100, 3U);
|
| + CHECK_EQ(1, map.GetTraceNodeId(ToAddress(0x17F)));
|
| + CHECK_EQ(2, map.GetTraceNodeId(ToAddress(0x280)));
|
| + CHECK_EQ(3, map.GetTraceNodeId(ToAddress(0x180)));
|
| + CHECK_EQ(3, static_cast<int>(map.size()));
|
| +
|
| + // [0x100, 0x180) -> 1, [0x180, 0x280) -> 3, [0x280, 0x300) -> 2,
|
| + // [0x400, 0x500) -> 4
|
| + map.AddRange(ToAddress(0x400), 0x100, 4U);
|
| + CHECK_EQ(1, map.GetTraceNodeId(ToAddress(0x17F)));
|
| + CHECK_EQ(2, map.GetTraceNodeId(ToAddress(0x280)));
|
| + CHECK_EQ(3, map.GetTraceNodeId(ToAddress(0x180)));
|
| + CHECK_EQ(4, map.GetTraceNodeId(ToAddress(0x450)));
|
| + CHECK_EQ(0, map.GetTraceNodeId(ToAddress(0x500)));
|
| + CHECK_EQ(0, map.GetTraceNodeId(ToAddress(0x350)));
|
| + CHECK_EQ(4, static_cast<int>(map.size()));
|
| +
|
| + // [0x100, 0x180) -> 1, [0x180, 0x200) -> 3, [0x200, 0x600) -> 5
|
| + map.AddRange(ToAddress(0x200), 0x400, 5U);
|
| + CHECK_EQ(5, map.GetTraceNodeId(ToAddress(0x200)));
|
| + CHECK_EQ(5, map.GetTraceNodeId(ToAddress(0x400)));
|
| + CHECK_EQ(3, static_cast<int>(map.size()));
|
| +
|
| + // [0x100, 0x180) -> 1, [0x180, 0x200) -> 7, [0x200, 0x600) ->5
|
| + map.AddRange(ToAddress(0x180), 0x80, 6U);
|
| + map.AddRange(ToAddress(0x180), 0x80, 7U);
|
| + CHECK_EQ(7, map.GetTraceNodeId(ToAddress(0x180)));
|
| + CHECK_EQ(5, map.GetTraceNodeId(ToAddress(0x200)));
|
| + CHECK_EQ(3, static_cast<int>(map.size()));
|
| +
|
| + map.Clear();
|
| + CHECK_EQ(0, static_cast<int>(map.size()));
|
| + CHECK_EQ(0, map.GetTraceNodeId(ToAddress(0x400)));
|
| +}
|
|
|