| 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 2173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2184 } | 2184 } |
| 2185 } | 2185 } |
| 2186 return node; | 2186 return node; |
| 2187 } | 2187 } |
| 2188 | 2188 |
| 2189 | 2189 |
| 2190 TEST(ArrayGrowLeftTrim) { | 2190 TEST(ArrayGrowLeftTrim) { |
| 2191 LocalContext env; | 2191 LocalContext env; |
| 2192 v8::HandleScope scope(env->GetIsolate()); | 2192 v8::HandleScope scope(env->GetIsolate()); |
| 2193 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 2193 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
| 2194 heap_profiler->StartRecordingHeapAllocations(); | 2194 heap_profiler->StartTrackingHeapObjects(true); |
| 2195 | 2195 |
| 2196 CompileRun( | 2196 CompileRun( |
| 2197 "var a = [];\n" | 2197 "var a = [];\n" |
| 2198 "for (var i = 0; i < 5; ++i)\n" | 2198 "for (var i = 0; i < 5; ++i)\n" |
| 2199 " a[i] = i;\n" | 2199 " a[i] = i;\n" |
| 2200 "for (var i = 0; i < 3; ++i)\n" | 2200 "for (var i = 0; i < 3; ++i)\n" |
| 2201 " a.shift();\n"); | 2201 " a.shift();\n"); |
| 2202 | 2202 |
| 2203 const char* names[] = { "(anonymous function)" }; | 2203 const char* names[] = { "(anonymous function)" }; |
| 2204 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot( | 2204 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot( |
| 2205 v8::String::NewFromUtf8(env->GetIsolate(), "Test1")); | 2205 v8::String::NewFromUtf8(env->GetIsolate(), "Test1")); |
| 2206 i::HeapSnapshotsCollection* collection = ToInternal(snapshot)->collection(); | 2206 i::HeapSnapshotsCollection* collection = ToInternal(snapshot)->collection(); |
| 2207 AllocationTracker* tracker = collection->allocation_tracker(); | 2207 AllocationTracker* tracker = collection->allocation_tracker(); |
| 2208 CHECK_NE(NULL, tracker); | 2208 CHECK_NE(NULL, tracker); |
| 2209 // Resolve all function locations. | 2209 // Resolve all function locations. |
| 2210 tracker->PrepareForSerialization(); | 2210 tracker->PrepareForSerialization(); |
| 2211 // Print for better diagnostics in case of failure. | 2211 // Print for better diagnostics in case of failure. |
| 2212 tracker->trace_tree()->Print(tracker); | 2212 tracker->trace_tree()->Print(tracker); |
| 2213 | 2213 |
| 2214 AllocationTraceNode* node = | 2214 AllocationTraceNode* node = |
| 2215 FindNode(tracker, Vector<const char*>(names, ARRAY_SIZE(names))); | 2215 FindNode(tracker, Vector<const char*>(names, ARRAY_SIZE(names))); |
| 2216 CHECK_NE(NULL, node); | 2216 CHECK_NE(NULL, node); |
| 2217 CHECK_GE(node->allocation_count(), 2); | 2217 CHECK_GE(node->allocation_count(), 2); |
| 2218 CHECK_GE(node->allocation_size(), 4 * 5); | 2218 CHECK_GE(node->allocation_size(), 4 * 5); |
| 2219 heap_profiler->StopRecordingHeapAllocations(); | 2219 heap_profiler->StopTrackingHeapObjects(); |
| 2220 } | 2220 } |
| 2221 | 2221 |
| 2222 | 2222 |
| 2223 TEST(TrackHeapAllocations) { | 2223 TEST(TrackHeapAllocations) { |
| 2224 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 2224 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
| 2225 LocalContext env; | 2225 LocalContext env; |
| 2226 | 2226 |
| 2227 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 2227 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
| 2228 heap_profiler->StartRecordingHeapAllocations(); | 2228 heap_profiler->StartTrackingHeapObjects(true); |
| 2229 | 2229 |
| 2230 CompileRun(record_trace_tree_source); | 2230 CompileRun(record_trace_tree_source); |
| 2231 | 2231 |
| 2232 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot( | 2232 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot( |
| 2233 v8::String::NewFromUtf8(env->GetIsolate(), "Test")); | 2233 v8::String::NewFromUtf8(env->GetIsolate(), "Test")); |
| 2234 i::HeapSnapshotsCollection* collection = ToInternal(snapshot)->collection(); | 2234 i::HeapSnapshotsCollection* collection = ToInternal(snapshot)->collection(); |
| 2235 AllocationTracker* tracker = collection->allocation_tracker(); | 2235 AllocationTracker* tracker = collection->allocation_tracker(); |
| 2236 CHECK_NE(NULL, tracker); | 2236 CHECK_NE(NULL, tracker); |
| 2237 // Resolve all function locations. | 2237 // Resolve all function locations. |
| 2238 tracker->PrepareForSerialization(); | 2238 tracker->PrepareForSerialization(); |
| 2239 // Print for better diagnostics in case of failure. | 2239 // Print for better diagnostics in case of failure. |
| 2240 tracker->trace_tree()->Print(tracker); | 2240 tracker->trace_tree()->Print(tracker); |
| 2241 | 2241 |
| 2242 const char* names[] = | 2242 const char* names[] = |
| 2243 { "(anonymous function)", "start", "f_0_0", "f_0_1", "f_0_2" }; | 2243 { "(anonymous function)", "start", "f_0_0", "f_0_1", "f_0_2" }; |
| 2244 AllocationTraceNode* node = | 2244 AllocationTraceNode* node = |
| 2245 FindNode(tracker, Vector<const char*>(names, ARRAY_SIZE(names))); | 2245 FindNode(tracker, Vector<const char*>(names, ARRAY_SIZE(names))); |
| 2246 CHECK_NE(NULL, node); | 2246 CHECK_NE(NULL, node); |
| 2247 CHECK_GE(node->allocation_count(), 100); | 2247 CHECK_GE(node->allocation_count(), 100); |
| 2248 CHECK_GE(node->allocation_size(), 4 * node->allocation_count()); | 2248 CHECK_GE(node->allocation_size(), 4 * node->allocation_count()); |
| 2249 heap_profiler->StopRecordingHeapAllocations(); | 2249 heap_profiler->StopTrackingHeapObjects(); |
| 2250 } | 2250 } |
| 2251 | 2251 |
| 2252 | 2252 |
| 2253 static const char* inline_heap_allocation_source = | 2253 static const char* inline_heap_allocation_source = |
| 2254 "function f_0(x) {\n" | 2254 "function f_0(x) {\n" |
| 2255 " return f_1(x+1);\n" | 2255 " return f_1(x+1);\n" |
| 2256 "}\n" | 2256 "}\n" |
| 2257 "%NeverOptimizeFunction(f_0);\n" | 2257 "%NeverOptimizeFunction(f_0);\n" |
| 2258 "function f_1(x) {\n" | 2258 "function f_1(x) {\n" |
| 2259 " return new f_2(x+1);\n" | 2259 " return new f_2(x+1);\n" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2271 | 2271 |
| 2272 TEST(TrackBumpPointerAllocations) { | 2272 TEST(TrackBumpPointerAllocations) { |
| 2273 i::FLAG_allow_natives_syntax = true; | 2273 i::FLAG_allow_natives_syntax = true; |
| 2274 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 2274 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
| 2275 LocalContext env; | 2275 LocalContext env; |
| 2276 | 2276 |
| 2277 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 2277 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
| 2278 const char* names[] = { "(anonymous function)", "start", "f_0", "f_1" }; | 2278 const char* names[] = { "(anonymous function)", "start", "f_0", "f_1" }; |
| 2279 // First check that normally all allocations are recorded. | 2279 // First check that normally all allocations are recorded. |
| 2280 { | 2280 { |
| 2281 heap_profiler->StartRecordingHeapAllocations(); | 2281 heap_profiler->StartTrackingHeapObjects(true); |
| 2282 | 2282 |
| 2283 CompileRun(inline_heap_allocation_source); | 2283 CompileRun(inline_heap_allocation_source); |
| 2284 | 2284 |
| 2285 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot( | 2285 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot( |
| 2286 v8::String::NewFromUtf8(env->GetIsolate(), "Test2")); | 2286 v8::String::NewFromUtf8(env->GetIsolate(), "Test2")); |
| 2287 i::HeapSnapshotsCollection* collection = ToInternal(snapshot)->collection(); | 2287 i::HeapSnapshotsCollection* collection = ToInternal(snapshot)->collection(); |
| 2288 AllocationTracker* tracker = collection->allocation_tracker(); | 2288 AllocationTracker* tracker = collection->allocation_tracker(); |
| 2289 CHECK_NE(NULL, tracker); | 2289 CHECK_NE(NULL, tracker); |
| 2290 // Resolve all function locations. | 2290 // Resolve all function locations. |
| 2291 tracker->PrepareForSerialization(); | 2291 tracker->PrepareForSerialization(); |
| 2292 // Print for better diagnostics in case of failure. | 2292 // Print for better diagnostics in case of failure. |
| 2293 tracker->trace_tree()->Print(tracker); | 2293 tracker->trace_tree()->Print(tracker); |
| 2294 | 2294 |
| 2295 AllocationTraceNode* node = | 2295 AllocationTraceNode* node = |
| 2296 FindNode(tracker, Vector<const char*>(names, ARRAY_SIZE(names))); | 2296 FindNode(tracker, Vector<const char*>(names, ARRAY_SIZE(names))); |
| 2297 CHECK_NE(NULL, node); | 2297 CHECK_NE(NULL, node); |
| 2298 CHECK_GE(node->allocation_count(), 100); | 2298 CHECK_GE(node->allocation_count(), 100); |
| 2299 CHECK_GE(node->allocation_size(), 4 * node->allocation_count()); | 2299 CHECK_GE(node->allocation_size(), 4 * node->allocation_count()); |
| 2300 heap_profiler->StopRecordingHeapAllocations(); | 2300 heap_profiler->StopTrackingHeapObjects(); |
| 2301 } | 2301 } |
| 2302 | 2302 |
| 2303 { | 2303 { |
| 2304 heap_profiler->StartRecordingHeapAllocations(); | 2304 heap_profiler->StartTrackingHeapObjects(true); |
| 2305 | 2305 |
| 2306 // Now check that not all allocations are tracked if we manually reenable | 2306 // Now check that not all allocations are tracked if we manually reenable |
| 2307 // inline allocations. | 2307 // inline allocations. |
| 2308 CHECK(CcTest::heap()->inline_allocation_disabled()); | 2308 CHECK(CcTest::heap()->inline_allocation_disabled()); |
| 2309 CcTest::heap()->EnableInlineAllocation(); | 2309 CcTest::heap()->EnableInlineAllocation(); |
| 2310 | 2310 |
| 2311 CompileRun(inline_heap_allocation_source); | 2311 CompileRun(inline_heap_allocation_source); |
| 2312 | 2312 |
| 2313 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot( | 2313 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot( |
| 2314 v8::String::NewFromUtf8(env->GetIsolate(), "Test1")); | 2314 v8::String::NewFromUtf8(env->GetIsolate(), "Test1")); |
| 2315 i::HeapSnapshotsCollection* collection = ToInternal(snapshot)->collection(); | 2315 i::HeapSnapshotsCollection* collection = ToInternal(snapshot)->collection(); |
| 2316 AllocationTracker* tracker = collection->allocation_tracker(); | 2316 AllocationTracker* tracker = collection->allocation_tracker(); |
| 2317 CHECK_NE(NULL, tracker); | 2317 CHECK_NE(NULL, tracker); |
| 2318 // Resolve all function locations. | 2318 // Resolve all function locations. |
| 2319 tracker->PrepareForSerialization(); | 2319 tracker->PrepareForSerialization(); |
| 2320 // Print for better diagnostics in case of failure. | 2320 // Print for better diagnostics in case of failure. |
| 2321 tracker->trace_tree()->Print(tracker); | 2321 tracker->trace_tree()->Print(tracker); |
| 2322 | 2322 |
| 2323 AllocationTraceNode* node = | 2323 AllocationTraceNode* node = |
| 2324 FindNode(tracker, Vector<const char*>(names, ARRAY_SIZE(names))); | 2324 FindNode(tracker, Vector<const char*>(names, ARRAY_SIZE(names))); |
| 2325 CHECK_NE(NULL, node); | 2325 CHECK_NE(NULL, node); |
| 2326 CHECK_LT(node->allocation_count(), 100); | 2326 CHECK_LT(node->allocation_count(), 100); |
| 2327 | 2327 |
| 2328 CcTest::heap()->DisableInlineAllocation(); | 2328 CcTest::heap()->DisableInlineAllocation(); |
| 2329 heap_profiler->StopRecordingHeapAllocations(); | 2329 heap_profiler->StopTrackingHeapObjects(); |
| 2330 } | 2330 } |
| 2331 } | 2331 } |
| OLD | NEW |