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

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

Issue 501323002: Replace our homegrown ARRAY_SIZE() with Chrome's arraysize(). (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 3 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
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 2293 matching lines...) Expand 10 before | Expand all | Expand 10 after
2304 heap_profiler->TakeHeapSnapshot(v8_str("CheckCodeNames")); 2304 heap_profiler->TakeHeapSnapshot(v8_str("CheckCodeNames"));
2305 CHECK(ValidateSnapshot(snapshot)); 2305 CHECK(ValidateSnapshot(snapshot));
2306 2306
2307 const char* stub_path[] = { 2307 const char* stub_path[] = {
2308 "::(GC roots)", 2308 "::(GC roots)",
2309 "::(Strong roots)", 2309 "::(Strong roots)",
2310 "code_stubs::", 2310 "code_stubs::",
2311 "::(ArraySingleArgumentConstructorStub code)" 2311 "::(ArraySingleArgumentConstructorStub code)"
2312 }; 2312 };
2313 const v8::HeapGraphNode* node = GetNodeByPath(snapshot, 2313 const v8::HeapGraphNode* node = GetNodeByPath(snapshot,
2314 stub_path, ARRAY_SIZE(stub_path)); 2314 stub_path, arraysize(stub_path));
2315 CHECK_NE(NULL, node); 2315 CHECK_NE(NULL, node);
2316 2316
2317 const char* builtin_path1[] = { 2317 const char* builtin_path1[] = {
2318 "::(GC roots)", 2318 "::(GC roots)",
2319 "::(Builtins)", 2319 "::(Builtins)",
2320 "::(KeyedLoadIC_Generic builtin)" 2320 "::(KeyedLoadIC_Generic builtin)"
2321 }; 2321 };
2322 node = GetNodeByPath(snapshot, builtin_path1, ARRAY_SIZE(builtin_path1)); 2322 node = GetNodeByPath(snapshot, builtin_path1, arraysize(builtin_path1));
2323 CHECK_NE(NULL, node); 2323 CHECK_NE(NULL, node);
2324 2324
2325 const char* builtin_path2[] = { 2325 const char* builtin_path2[] = {
2326 "::(GC roots)", 2326 "::(GC roots)",
2327 "::(Builtins)", 2327 "::(Builtins)",
2328 "::(CompileUnoptimized builtin)" 2328 "::(CompileUnoptimized builtin)"
2329 }; 2329 };
2330 node = GetNodeByPath(snapshot, builtin_path2, ARRAY_SIZE(builtin_path2)); 2330 node = GetNodeByPath(snapshot, builtin_path2, arraysize(builtin_path2));
2331 CHECK_NE(NULL, node); 2331 CHECK_NE(NULL, node);
2332 v8::String::Utf8Value node_name(node->GetName()); 2332 v8::String::Utf8Value node_name(node->GetName());
2333 CHECK_EQ("(CompileUnoptimized builtin)", *node_name); 2333 CHECK_EQ("(CompileUnoptimized builtin)", *node_name);
2334 } 2334 }
2335 2335
2336 2336
2337 static const char* record_trace_tree_source = 2337 static const char* record_trace_tree_source =
2338 "var topFunctions = [];\n" 2338 "var topFunctions = [];\n"
2339 "var global = this;\n" 2339 "var global = this;\n"
2340 "function generateFunctions(width, depth) {\n" 2340 "function generateFunctions(width, depth) {\n"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
2413 const char* names[] = {""}; 2413 const char* names[] = {""};
2414 AllocationTracker* tracker = 2414 AllocationTracker* tracker =
2415 reinterpret_cast<i::HeapProfiler*>(heap_profiler)->allocation_tracker(); 2415 reinterpret_cast<i::HeapProfiler*>(heap_profiler)->allocation_tracker();
2416 CHECK_NE(NULL, tracker); 2416 CHECK_NE(NULL, tracker);
2417 // Resolve all function locations. 2417 // Resolve all function locations.
2418 tracker->PrepareForSerialization(); 2418 tracker->PrepareForSerialization();
2419 // Print for better diagnostics in case of failure. 2419 // Print for better diagnostics in case of failure.
2420 tracker->trace_tree()->Print(tracker); 2420 tracker->trace_tree()->Print(tracker);
2421 2421
2422 AllocationTraceNode* node = 2422 AllocationTraceNode* node =
2423 FindNode(tracker, Vector<const char*>(names, ARRAY_SIZE(names))); 2423 FindNode(tracker, Vector<const char*>(names, arraysize(names)));
2424 CHECK_NE(NULL, node); 2424 CHECK_NE(NULL, node);
2425 CHECK_GE(node->allocation_count(), 2); 2425 CHECK_GE(node->allocation_count(), 2);
2426 CHECK_GE(node->allocation_size(), 4 * 5); 2426 CHECK_GE(node->allocation_size(), 4 * 5);
2427 heap_profiler->StopTrackingHeapObjects(); 2427 heap_profiler->StopTrackingHeapObjects();
2428 } 2428 }
2429 2429
2430 2430
2431 TEST(TrackHeapAllocations) { 2431 TEST(TrackHeapAllocations) {
2432 v8::HandleScope scope(v8::Isolate::GetCurrent()); 2432 v8::HandleScope scope(v8::Isolate::GetCurrent());
2433 LocalContext env; 2433 LocalContext env;
2434 2434
2435 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 2435 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
2436 heap_profiler->StartTrackingHeapObjects(true); 2436 heap_profiler->StartTrackingHeapObjects(true);
2437 2437
2438 CompileRun(record_trace_tree_source); 2438 CompileRun(record_trace_tree_source);
2439 2439
2440 AllocationTracker* tracker = 2440 AllocationTracker* tracker =
2441 reinterpret_cast<i::HeapProfiler*>(heap_profiler)->allocation_tracker(); 2441 reinterpret_cast<i::HeapProfiler*>(heap_profiler)->allocation_tracker();
2442 CHECK_NE(NULL, tracker); 2442 CHECK_NE(NULL, tracker);
2443 // Resolve all function locations. 2443 // Resolve all function locations.
2444 tracker->PrepareForSerialization(); 2444 tracker->PrepareForSerialization();
2445 // Print for better diagnostics in case of failure. 2445 // Print for better diagnostics in case of failure.
2446 tracker->trace_tree()->Print(tracker); 2446 tracker->trace_tree()->Print(tracker);
2447 2447
2448 const char* names[] = {"", "start", "f_0_0", "f_0_1", "f_0_2"}; 2448 const char* names[] = {"", "start", "f_0_0", "f_0_1", "f_0_2"};
2449 AllocationTraceNode* node = 2449 AllocationTraceNode* node =
2450 FindNode(tracker, Vector<const char*>(names, ARRAY_SIZE(names))); 2450 FindNode(tracker, Vector<const char*>(names, arraysize(names)));
2451 CHECK_NE(NULL, node); 2451 CHECK_NE(NULL, node);
2452 CHECK_GE(node->allocation_count(), 100); 2452 CHECK_GE(node->allocation_count(), 100);
2453 CHECK_GE(node->allocation_size(), 4 * node->allocation_count()); 2453 CHECK_GE(node->allocation_size(), 4 * node->allocation_count());
2454 heap_profiler->StopTrackingHeapObjects(); 2454 heap_profiler->StopTrackingHeapObjects();
2455 } 2455 }
2456 2456
2457 2457
2458 static const char* inline_heap_allocation_source = 2458 static const char* inline_heap_allocation_source =
2459 "function f_0(x) {\n" 2459 "function f_0(x) {\n"
2460 " return f_1(x+1);\n" 2460 " return f_1(x+1);\n"
(...skipping 28 matching lines...) Expand all
2489 2489
2490 AllocationTracker* tracker = 2490 AllocationTracker* tracker =
2491 reinterpret_cast<i::HeapProfiler*>(heap_profiler)->allocation_tracker(); 2491 reinterpret_cast<i::HeapProfiler*>(heap_profiler)->allocation_tracker();
2492 CHECK_NE(NULL, tracker); 2492 CHECK_NE(NULL, tracker);
2493 // Resolve all function locations. 2493 // Resolve all function locations.
2494 tracker->PrepareForSerialization(); 2494 tracker->PrepareForSerialization();
2495 // Print for better diagnostics in case of failure. 2495 // Print for better diagnostics in case of failure.
2496 tracker->trace_tree()->Print(tracker); 2496 tracker->trace_tree()->Print(tracker);
2497 2497
2498 AllocationTraceNode* node = 2498 AllocationTraceNode* node =
2499 FindNode(tracker, Vector<const char*>(names, ARRAY_SIZE(names))); 2499 FindNode(tracker, Vector<const char*>(names, arraysize(names)));
2500 CHECK_NE(NULL, node); 2500 CHECK_NE(NULL, node);
2501 CHECK_GE(node->allocation_count(), 100); 2501 CHECK_GE(node->allocation_count(), 100);
2502 CHECK_GE(node->allocation_size(), 4 * node->allocation_count()); 2502 CHECK_GE(node->allocation_size(), 4 * node->allocation_count());
2503 heap_profiler->StopTrackingHeapObjects(); 2503 heap_profiler->StopTrackingHeapObjects();
2504 } 2504 }
2505 2505
2506 { 2506 {
2507 heap_profiler->StartTrackingHeapObjects(true); 2507 heap_profiler->StartTrackingHeapObjects(true);
2508 2508
2509 // Now check that not all allocations are tracked if we manually reenable 2509 // Now check that not all allocations are tracked if we manually reenable
2510 // inline allocations. 2510 // inline allocations.
2511 CHECK(CcTest::heap()->inline_allocation_disabled()); 2511 CHECK(CcTest::heap()->inline_allocation_disabled());
2512 CcTest::heap()->EnableInlineAllocation(); 2512 CcTest::heap()->EnableInlineAllocation();
2513 2513
2514 CompileRun(inline_heap_allocation_source); 2514 CompileRun(inline_heap_allocation_source);
2515 2515
2516 AllocationTracker* tracker = 2516 AllocationTracker* tracker =
2517 reinterpret_cast<i::HeapProfiler*>(heap_profiler)->allocation_tracker(); 2517 reinterpret_cast<i::HeapProfiler*>(heap_profiler)->allocation_tracker();
2518 CHECK_NE(NULL, tracker); 2518 CHECK_NE(NULL, tracker);
2519 // Resolve all function locations. 2519 // Resolve all function locations.
2520 tracker->PrepareForSerialization(); 2520 tracker->PrepareForSerialization();
2521 // Print for better diagnostics in case of failure. 2521 // Print for better diagnostics in case of failure.
2522 tracker->trace_tree()->Print(tracker); 2522 tracker->trace_tree()->Print(tracker);
2523 2523
2524 AllocationTraceNode* node = 2524 AllocationTraceNode* node =
2525 FindNode(tracker, Vector<const char*>(names, ARRAY_SIZE(names))); 2525 FindNode(tracker, Vector<const char*>(names, arraysize(names)));
2526 CHECK_NE(NULL, node); 2526 CHECK_NE(NULL, node);
2527 CHECK_LT(node->allocation_count(), 100); 2527 CHECK_LT(node->allocation_count(), 100);
2528 2528
2529 CcTest::heap()->DisableInlineAllocation(); 2529 CcTest::heap()->DisableInlineAllocation();
2530 heap_profiler->StopTrackingHeapObjects(); 2530 heap_profiler->StopTrackingHeapObjects();
2531 } 2531 }
2532 } 2532 }
2533 2533
2534 2534
2535 TEST(TrackV8ApiAllocation) { 2535 TEST(TrackV8ApiAllocation) {
2536 v8::HandleScope scope(v8::Isolate::GetCurrent()); 2536 v8::HandleScope scope(v8::Isolate::GetCurrent());
2537 LocalContext env; 2537 LocalContext env;
2538 2538
2539 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 2539 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
2540 const char* names[] = { "(V8 API)" }; 2540 const char* names[] = { "(V8 API)" };
2541 heap_profiler->StartTrackingHeapObjects(true); 2541 heap_profiler->StartTrackingHeapObjects(true);
2542 2542
2543 v8::Handle<v8::Object> o1 = v8::Object::New(env->GetIsolate()); 2543 v8::Handle<v8::Object> o1 = v8::Object::New(env->GetIsolate());
2544 o1->Clone(); 2544 o1->Clone();
2545 2545
2546 AllocationTracker* tracker = 2546 AllocationTracker* tracker =
2547 reinterpret_cast<i::HeapProfiler*>(heap_profiler)->allocation_tracker(); 2547 reinterpret_cast<i::HeapProfiler*>(heap_profiler)->allocation_tracker();
2548 CHECK_NE(NULL, tracker); 2548 CHECK_NE(NULL, tracker);
2549 // Resolve all function locations. 2549 // Resolve all function locations.
2550 tracker->PrepareForSerialization(); 2550 tracker->PrepareForSerialization();
2551 // Print for better diagnostics in case of failure. 2551 // Print for better diagnostics in case of failure.
2552 tracker->trace_tree()->Print(tracker); 2552 tracker->trace_tree()->Print(tracker);
2553 2553
2554 AllocationTraceNode* node = 2554 AllocationTraceNode* node =
2555 FindNode(tracker, Vector<const char*>(names, ARRAY_SIZE(names))); 2555 FindNode(tracker, Vector<const char*>(names, arraysize(names)));
2556 CHECK_NE(NULL, node); 2556 CHECK_NE(NULL, node);
2557 CHECK_GE(node->allocation_count(), 2); 2557 CHECK_GE(node->allocation_count(), 2);
2558 CHECK_GE(node->allocation_size(), 4 * node->allocation_count()); 2558 CHECK_GE(node->allocation_size(), 4 * node->allocation_count());
2559 heap_profiler->StopTrackingHeapObjects(); 2559 heap_profiler->StopTrackingHeapObjects();
2560 } 2560 }
2561 2561
2562 2562
2563 TEST(ArrayBufferAndArrayBufferView) { 2563 TEST(ArrayBufferAndArrayBufferView) {
2564 LocalContext env; 2564 LocalContext env;
2565 v8::HandleScope scope(env->GetIsolate()); 2565 v8::HandleScope scope(env->GetIsolate());
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
2760 map.AddRange(ToAddress(0x180), 0x80, 6U); 2760 map.AddRange(ToAddress(0x180), 0x80, 6U);
2761 map.AddRange(ToAddress(0x180), 0x80, 7U); 2761 map.AddRange(ToAddress(0x180), 0x80, 7U);
2762 CHECK_EQ(7, map.GetTraceNodeId(ToAddress(0x180))); 2762 CHECK_EQ(7, map.GetTraceNodeId(ToAddress(0x180)));
2763 CHECK_EQ(5, map.GetTraceNodeId(ToAddress(0x200))); 2763 CHECK_EQ(5, map.GetTraceNodeId(ToAddress(0x200)));
2764 CHECK_EQ(3, static_cast<int>(map.size())); 2764 CHECK_EQ(3, static_cast<int>(map.size()));
2765 2765
2766 map.Clear(); 2766 map.Clear();
2767 CHECK_EQ(0, static_cast<int>(map.size())); 2767 CHECK_EQ(0, static_cast<int>(map.size()));
2768 CHECK_EQ(0, map.GetTraceNodeId(ToAddress(0x400))); 2768 CHECK_EQ(0, map.GetTraceNodeId(ToAddress(0x400)));
2769 } 2769 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698