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 2037 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2048 CHECK(false); | 2048 CHECK(false); |
2049 return v8::Handle<v8::FunctionTemplate>(); | 2049 return v8::Handle<v8::FunctionTemplate>(); |
2050 } | 2050 } |
2051 } | 2051 } |
2052 | 2052 |
2053 | 2053 |
2054 void HeapProfilerExtension::FindUntrackedObjects( | 2054 void HeapProfilerExtension::FindUntrackedObjects( |
2055 const v8::FunctionCallbackInfo<v8::Value>& args) { | 2055 const v8::FunctionCallbackInfo<v8::Value>& args) { |
2056 i::HeapProfiler* heap_profiler = | 2056 i::HeapProfiler* heap_profiler = |
2057 reinterpret_cast<i::HeapProfiler*>(args.GetIsolate()->GetHeapProfiler()); | 2057 reinterpret_cast<i::HeapProfiler*>(args.GetIsolate()->GetHeapProfiler()); |
2058 int untracked_objects = heap_profiler->FindUntrackedObjects(); | 2058 int untracked_objects = |
| 2059 heap_profiler->heap_object_map()->FindUntrackedObjects(); |
2059 args.GetReturnValue().Set(untracked_objects); | 2060 args.GetReturnValue().Set(untracked_objects); |
2060 CHECK_EQ(0, untracked_objects); | 2061 CHECK_EQ(0, untracked_objects); |
2061 } | 2062 } |
2062 | 2063 |
2063 | 2064 |
2064 static HeapProfilerExtension kHeapProfilerExtension; | 2065 static HeapProfilerExtension kHeapProfilerExtension; |
2065 v8::DeclareExtension kHeapProfilerExtensionDeclaration( | 2066 v8::DeclareExtension kHeapProfilerExtensionDeclaration( |
2066 &kHeapProfilerExtension); | 2067 &kHeapProfilerExtension); |
2067 | 2068 |
2068 | 2069 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2154 "var instances = [];\n" | 2155 "var instances = [];\n" |
2155 "function start() {\n" | 2156 "function start() {\n" |
2156 " for (var i = 0; i < width; i++) {\n" | 2157 " for (var i = 0; i < width; i++) {\n" |
2157 " instances.push(topFunctions[i](0));\n" | 2158 " instances.push(topFunctions[i](0));\n" |
2158 " }\n" | 2159 " }\n" |
2159 "}\n" | 2160 "}\n" |
2160 "\n" | 2161 "\n" |
2161 "for (var i = 0; i < 100; i++) start();\n"; | 2162 "for (var i = 0; i < 100; i++) start();\n"; |
2162 | 2163 |
2163 | 2164 |
2164 static i::HeapSnapshot* ToInternal(const v8::HeapSnapshot* snapshot) { | |
2165 return const_cast<i::HeapSnapshot*>( | |
2166 reinterpret_cast<const i::HeapSnapshot*>(snapshot)); | |
2167 } | |
2168 | |
2169 | |
2170 static AllocationTraceNode* FindNode( | 2165 static AllocationTraceNode* FindNode( |
2171 AllocationTracker* tracker, const Vector<const char*>& names) { | 2166 AllocationTracker* tracker, const Vector<const char*>& names) { |
2172 AllocationTraceNode* node = tracker->trace_tree()->root(); | 2167 AllocationTraceNode* node = tracker->trace_tree()->root(); |
2173 for (int i = 0; node != NULL && i < names.length(); i++) { | 2168 for (int i = 0; node != NULL && i < names.length(); i++) { |
2174 const char* name = names[i]; | 2169 const char* name = names[i]; |
2175 Vector<AllocationTraceNode*> children = node->children(); | 2170 Vector<AllocationTraceNode*> children = node->children(); |
2176 node = NULL; | 2171 node = NULL; |
2177 for (int j = 0; j < children.length(); j++) { | 2172 for (int j = 0; j < children.length(); j++) { |
2178 v8::SnapshotObjectId id = children[j]->function_id(); | 2173 v8::SnapshotObjectId id = children[j]->function_id(); |
2179 AllocationTracker::FunctionInfo* info = tracker->GetFunctionInfo(id); | 2174 AllocationTracker::FunctionInfo* info = tracker->GetFunctionInfo(id); |
(...skipping 14 matching lines...) Expand all Loading... |
2194 heap_profiler->StartTrackingHeapObjects(true); | 2189 heap_profiler->StartTrackingHeapObjects(true); |
2195 | 2190 |
2196 CompileRun( | 2191 CompileRun( |
2197 "var a = [];\n" | 2192 "var a = [];\n" |
2198 "for (var i = 0; i < 5; ++i)\n" | 2193 "for (var i = 0; i < 5; ++i)\n" |
2199 " a[i] = i;\n" | 2194 " a[i] = i;\n" |
2200 "for (var i = 0; i < 3; ++i)\n" | 2195 "for (var i = 0; i < 3; ++i)\n" |
2201 " a.shift();\n"); | 2196 " a.shift();\n"); |
2202 | 2197 |
2203 const char* names[] = { "(anonymous function)" }; | 2198 const char* names[] = { "(anonymous function)" }; |
2204 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot( | 2199 AllocationTracker* tracker = |
2205 v8::String::NewFromUtf8(env->GetIsolate(), "Test1")); | 2200 reinterpret_cast<i::HeapProfiler*>(heap_profiler)->allocation_tracker(); |
2206 i::HeapSnapshotsCollection* collection = ToInternal(snapshot)->collection(); | |
2207 AllocationTracker* tracker = collection->allocation_tracker(); | |
2208 CHECK_NE(NULL, tracker); | 2201 CHECK_NE(NULL, tracker); |
2209 // Resolve all function locations. | 2202 // Resolve all function locations. |
2210 tracker->PrepareForSerialization(); | 2203 tracker->PrepareForSerialization(); |
2211 // Print for better diagnostics in case of failure. | 2204 // Print for better diagnostics in case of failure. |
2212 tracker->trace_tree()->Print(tracker); | 2205 tracker->trace_tree()->Print(tracker); |
2213 | 2206 |
2214 AllocationTraceNode* node = | 2207 AllocationTraceNode* node = |
2215 FindNode(tracker, Vector<const char*>(names, ARRAY_SIZE(names))); | 2208 FindNode(tracker, Vector<const char*>(names, ARRAY_SIZE(names))); |
2216 CHECK_NE(NULL, node); | 2209 CHECK_NE(NULL, node); |
2217 CHECK_GE(node->allocation_count(), 2); | 2210 CHECK_GE(node->allocation_count(), 2); |
2218 CHECK_GE(node->allocation_size(), 4 * 5); | 2211 CHECK_GE(node->allocation_size(), 4 * 5); |
2219 heap_profiler->StopTrackingHeapObjects(); | 2212 heap_profiler->StopTrackingHeapObjects(); |
2220 } | 2213 } |
2221 | 2214 |
2222 | 2215 |
2223 TEST(TrackHeapAllocations) { | 2216 TEST(TrackHeapAllocations) { |
2224 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 2217 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
2225 LocalContext env; | 2218 LocalContext env; |
2226 | 2219 |
2227 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 2220 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
2228 heap_profiler->StartTrackingHeapObjects(true); | 2221 heap_profiler->StartTrackingHeapObjects(true); |
2229 | 2222 |
2230 CompileRun(record_trace_tree_source); | 2223 CompileRun(record_trace_tree_source); |
2231 | 2224 |
2232 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot( | 2225 AllocationTracker* tracker = |
2233 v8::String::NewFromUtf8(env->GetIsolate(), "Test")); | 2226 reinterpret_cast<i::HeapProfiler*>(heap_profiler)->allocation_tracker(); |
2234 i::HeapSnapshotsCollection* collection = ToInternal(snapshot)->collection(); | |
2235 AllocationTracker* tracker = collection->allocation_tracker(); | |
2236 CHECK_NE(NULL, tracker); | 2227 CHECK_NE(NULL, tracker); |
2237 // Resolve all function locations. | 2228 // Resolve all function locations. |
2238 tracker->PrepareForSerialization(); | 2229 tracker->PrepareForSerialization(); |
2239 // Print for better diagnostics in case of failure. | 2230 // Print for better diagnostics in case of failure. |
2240 tracker->trace_tree()->Print(tracker); | 2231 tracker->trace_tree()->Print(tracker); |
2241 | 2232 |
2242 const char* names[] = | 2233 const char* names[] = |
2243 { "(anonymous function)", "start", "f_0_0", "f_0_1", "f_0_2" }; | 2234 { "(anonymous function)", "start", "f_0_0", "f_0_1", "f_0_2" }; |
2244 AllocationTraceNode* node = | 2235 AllocationTraceNode* node = |
2245 FindNode(tracker, Vector<const char*>(names, ARRAY_SIZE(names))); | 2236 FindNode(tracker, Vector<const char*>(names, ARRAY_SIZE(names))); |
(...skipping 29 matching lines...) Expand all Loading... |
2275 LocalContext env; | 2266 LocalContext env; |
2276 | 2267 |
2277 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 2268 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
2278 const char* names[] = { "(anonymous function)", "start", "f_0", "f_1" }; | 2269 const char* names[] = { "(anonymous function)", "start", "f_0", "f_1" }; |
2279 // First check that normally all allocations are recorded. | 2270 // First check that normally all allocations are recorded. |
2280 { | 2271 { |
2281 heap_profiler->StartTrackingHeapObjects(true); | 2272 heap_profiler->StartTrackingHeapObjects(true); |
2282 | 2273 |
2283 CompileRun(inline_heap_allocation_source); | 2274 CompileRun(inline_heap_allocation_source); |
2284 | 2275 |
2285 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot( | 2276 AllocationTracker* tracker = |
2286 v8::String::NewFromUtf8(env->GetIsolate(), "Test2")); | 2277 reinterpret_cast<i::HeapProfiler*>(heap_profiler)->allocation_tracker(); |
2287 i::HeapSnapshotsCollection* collection = ToInternal(snapshot)->collection(); | |
2288 AllocationTracker* tracker = collection->allocation_tracker(); | |
2289 CHECK_NE(NULL, tracker); | 2278 CHECK_NE(NULL, tracker); |
2290 // Resolve all function locations. | 2279 // Resolve all function locations. |
2291 tracker->PrepareForSerialization(); | 2280 tracker->PrepareForSerialization(); |
2292 // Print for better diagnostics in case of failure. | 2281 // Print for better diagnostics in case of failure. |
2293 tracker->trace_tree()->Print(tracker); | 2282 tracker->trace_tree()->Print(tracker); |
2294 | 2283 |
2295 AllocationTraceNode* node = | 2284 AllocationTraceNode* node = |
2296 FindNode(tracker, Vector<const char*>(names, ARRAY_SIZE(names))); | 2285 FindNode(tracker, Vector<const char*>(names, ARRAY_SIZE(names))); |
2297 CHECK_NE(NULL, node); | 2286 CHECK_NE(NULL, node); |
2298 CHECK_GE(node->allocation_count(), 100); | 2287 CHECK_GE(node->allocation_count(), 100); |
2299 CHECK_GE(node->allocation_size(), 4 * node->allocation_count()); | 2288 CHECK_GE(node->allocation_size(), 4 * node->allocation_count()); |
2300 heap_profiler->StopTrackingHeapObjects(); | 2289 heap_profiler->StopTrackingHeapObjects(); |
2301 } | 2290 } |
2302 | 2291 |
2303 { | 2292 { |
2304 heap_profiler->StartTrackingHeapObjects(true); | 2293 heap_profiler->StartTrackingHeapObjects(true); |
2305 | 2294 |
2306 // Now check that not all allocations are tracked if we manually reenable | 2295 // Now check that not all allocations are tracked if we manually reenable |
2307 // inline allocations. | 2296 // inline allocations. |
2308 CHECK(CcTest::heap()->inline_allocation_disabled()); | 2297 CHECK(CcTest::heap()->inline_allocation_disabled()); |
2309 CcTest::heap()->EnableInlineAllocation(); | 2298 CcTest::heap()->EnableInlineAllocation(); |
2310 | 2299 |
2311 CompileRun(inline_heap_allocation_source); | 2300 CompileRun(inline_heap_allocation_source); |
2312 | 2301 |
2313 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot( | 2302 AllocationTracker* tracker = |
2314 v8::String::NewFromUtf8(env->GetIsolate(), "Test1")); | 2303 reinterpret_cast<i::HeapProfiler*>(heap_profiler)->allocation_tracker(); |
2315 i::HeapSnapshotsCollection* collection = ToInternal(snapshot)->collection(); | |
2316 AllocationTracker* tracker = collection->allocation_tracker(); | |
2317 CHECK_NE(NULL, tracker); | 2304 CHECK_NE(NULL, tracker); |
2318 // Resolve all function locations. | 2305 // Resolve all function locations. |
2319 tracker->PrepareForSerialization(); | 2306 tracker->PrepareForSerialization(); |
2320 // Print for better diagnostics in case of failure. | 2307 // Print for better diagnostics in case of failure. |
2321 tracker->trace_tree()->Print(tracker); | 2308 tracker->trace_tree()->Print(tracker); |
2322 | 2309 |
2323 AllocationTraceNode* node = | 2310 AllocationTraceNode* node = |
2324 FindNode(tracker, Vector<const char*>(names, ARRAY_SIZE(names))); | 2311 FindNode(tracker, Vector<const char*>(names, ARRAY_SIZE(names))); |
2325 CHECK_NE(NULL, node); | 2312 CHECK_NE(NULL, node); |
2326 CHECK_LT(node->allocation_count(), 100); | 2313 CHECK_LT(node->allocation_count(), 100); |
2327 | 2314 |
2328 CcTest::heap()->DisableInlineAllocation(); | 2315 CcTest::heap()->DisableInlineAllocation(); |
2329 heap_profiler->StopTrackingHeapObjects(); | 2316 heap_profiler->StopTrackingHeapObjects(); |
2330 } | 2317 } |
2331 } | 2318 } |
OLD | NEW |