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 2159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2170 | 2170 |
2171 const char* names[] = | 2171 const char* names[] = |
2172 { "(anonymous function)", "start", "f_0_0", "f_0_1", "f_0_2" }; | 2172 { "(anonymous function)", "start", "f_0_0", "f_0_1", "f_0_2" }; |
2173 AllocationTraceNode* node = | 2173 AllocationTraceNode* node = |
2174 FindNode(tracker, Vector<const char*>(names, ARRAY_SIZE(names))); | 2174 FindNode(tracker, Vector<const char*>(names, ARRAY_SIZE(names))); |
2175 CHECK_NE(NULL, node); | 2175 CHECK_NE(NULL, node); |
2176 CHECK_GE(node->allocation_count(), 100); | 2176 CHECK_GE(node->allocation_count(), 100); |
2177 CHECK_GE(node->allocation_size(), 4 * node->allocation_count()); | 2177 CHECK_GE(node->allocation_size(), 4 * node->allocation_count()); |
2178 heap_profiler->StopRecordingHeapAllocations(); | 2178 heap_profiler->StopRecordingHeapAllocations(); |
2179 } | 2179 } |
| 2180 |
| 2181 |
| 2182 static const char* inline_heap_allocation_source = |
| 2183 "function f_0(x) {\n" |
| 2184 " try {\n" |
| 2185 " return f_1(x+1);\n" |
| 2186 " } catch (e) {}\n" |
| 2187 "}\n" |
| 2188 "function f_1(x) {\n" |
| 2189 " try {\n" |
| 2190 " return new f_2(x+1);\n" |
| 2191 " } catch (e) {}\n" |
| 2192 "}\n" |
| 2193 "function f_2(x) {\n" |
| 2194 " this.foo = x;\n" |
| 2195 "}\n" |
| 2196 "var instances = [];\n" |
| 2197 "function start() {\n" |
| 2198 " instances.push(f_0(0));\n" |
| 2199 "}\n" |
| 2200 "\n" |
| 2201 "for (var i = 0; i < 100; i++) start();\n"; |
| 2202 |
| 2203 |
| 2204 TEST(TrackInlineHeapAllocations) { |
| 2205 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
| 2206 LocalContext env; |
| 2207 |
| 2208 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
| 2209 heap_profiler->StartRecordingHeapAllocations(); |
| 2210 |
| 2211 CompileRun(inline_heap_allocation_source); |
| 2212 |
| 2213 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot( |
| 2214 v8::String::New("Test")); |
| 2215 i::HeapSnapshotsCollection* collection = ToInternal(snapshot)->collection(); |
| 2216 AllocationTracker* tracker = collection->allocation_tracker(); |
| 2217 CHECK_NE(NULL, tracker); |
| 2218 // Resolve all function locations. |
| 2219 tracker->PrepareForSerialization(); |
| 2220 // Print for better diagnostics in case of failure. |
| 2221 tracker->trace_tree()->Print(tracker); |
| 2222 |
| 2223 const char* names[] = |
| 2224 { "(anonymous function)", "start", "f_0", "f_1" }; |
| 2225 AllocationTraceNode* node = |
| 2226 FindNode(tracker, Vector<const char*>(names, ARRAY_SIZE(names))); |
| 2227 CHECK_NE(NULL, node); |
| 2228 CHECK_GE(node->allocation_count(), 100); |
| 2229 CHECK_GE(node->allocation_size(), 4 * node->allocation_count()); |
| 2230 heap_profiler->StopRecordingHeapAllocations(); |
| 2231 } |
OLD | NEW |