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 2212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2223 | 2223 |
2224 const char* names[] = | 2224 const char* names[] = |
2225 { "(anonymous function)", "start", "f_0_0", "f_0_1", "f_0_2" }; | 2225 { "(anonymous function)", "start", "f_0_0", "f_0_1", "f_0_2" }; |
2226 AllocationTraceNode* node = | 2226 AllocationTraceNode* node = |
2227 FindNode(tracker, Vector<const char*>(names, ARRAY_SIZE(names))); | 2227 FindNode(tracker, Vector<const char*>(names, ARRAY_SIZE(names))); |
2228 CHECK_NE(NULL, node); | 2228 CHECK_NE(NULL, node); |
2229 CHECK_GE(node->allocation_count(), 100); | 2229 CHECK_GE(node->allocation_count(), 100); |
2230 CHECK_GE(node->allocation_size(), 4 * node->allocation_count()); | 2230 CHECK_GE(node->allocation_size(), 4 * node->allocation_count()); |
2231 heap_profiler->StopRecordingHeapAllocations(); | 2231 heap_profiler->StopRecordingHeapAllocations(); |
2232 } | 2232 } |
| 2233 |
| 2234 |
| 2235 static const char* inline_heap_allocation_source = |
| 2236 "function f_0(x) {\n" |
| 2237 " return f_1(x+1);\n" |
| 2238 "}\n" |
| 2239 "%NeverOptimizeFunction(f_0);\n" |
| 2240 "function f_1(x) {\n" |
| 2241 " return new f_2(x+1);\n" |
| 2242 "}\n" |
| 2243 "function f_2(x) {\n" |
| 2244 " this.foo = x;\n" |
| 2245 "}\n" |
| 2246 "var instances = [];\n" |
| 2247 "function start() {\n" |
| 2248 " instances.push(f_0(0));\n" |
| 2249 "}\n" |
| 2250 "\n" |
| 2251 "for (var i = 0; i < 100; i++) start();\n"; |
| 2252 |
| 2253 |
| 2254 TEST(TrackBumpPointerAllocations) { |
| 2255 i::FLAG_allow_natives_syntax = true; |
| 2256 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
| 2257 LocalContext env; |
| 2258 |
| 2259 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
| 2260 const char* names[] = { "(anonymous function)", "start", "f_0", "f_1" }; |
| 2261 // First check that normally all allocations are recorded. |
| 2262 { |
| 2263 heap_profiler->StartRecordingHeapAllocations(); |
| 2264 |
| 2265 CompileRun(inline_heap_allocation_source); |
| 2266 |
| 2267 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot( |
| 2268 v8::String::New("Test2")); |
| 2269 i::HeapSnapshotsCollection* collection = ToInternal(snapshot)->collection(); |
| 2270 AllocationTracker* tracker = collection->allocation_tracker(); |
| 2271 CHECK_NE(NULL, tracker); |
| 2272 // Resolve all function locations. |
| 2273 tracker->PrepareForSerialization(); |
| 2274 // Print for better diagnostics in case of failure. |
| 2275 tracker->trace_tree()->Print(tracker); |
| 2276 |
| 2277 AllocationTraceNode* node = |
| 2278 FindNode(tracker, Vector<const char*>(names, ARRAY_SIZE(names))); |
| 2279 CHECK_NE(NULL, node); |
| 2280 CHECK_GE(node->allocation_count(), 100); |
| 2281 CHECK_GE(node->allocation_size(), 4 * node->allocation_count()); |
| 2282 heap_profiler->StopRecordingHeapAllocations(); |
| 2283 } |
| 2284 |
| 2285 { |
| 2286 heap_profiler->StartRecordingHeapAllocations(); |
| 2287 |
| 2288 // Now check that not all allocations are tracked if we manually reenable |
| 2289 // inline allocations. |
| 2290 CHECK(CcTest::heap()->inline_allocation_disabled()); |
| 2291 CcTest::heap()->EnableInlineAllocation(); |
| 2292 |
| 2293 CompileRun(inline_heap_allocation_source); |
| 2294 |
| 2295 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot( |
| 2296 v8::String::New("Test1")); |
| 2297 i::HeapSnapshotsCollection* collection = ToInternal(snapshot)->collection(); |
| 2298 AllocationTracker* tracker = collection->allocation_tracker(); |
| 2299 CHECK_NE(NULL, tracker); |
| 2300 // Resolve all function locations. |
| 2301 tracker->PrepareForSerialization(); |
| 2302 // Print for better diagnostics in case of failure. |
| 2303 tracker->trace_tree()->Print(tracker); |
| 2304 |
| 2305 AllocationTraceNode* node = |
| 2306 FindNode(tracker, Vector<const char*>(names, ARRAY_SIZE(names))); |
| 2307 CHECK_NE(NULL, node); |
| 2308 CHECK_LT(node->allocation_count(), 100); |
| 2309 |
| 2310 CcTest::heap()->DisableInlineAllocation(); |
| 2311 heap_profiler->StopRecordingHeapAllocations(); |
| 2312 } |
| 2313 } |
OLD | NEW |