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

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

Issue 83343002: Remove usage of deprecated APIs from cctests (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 1 month 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
« no previous file with comments | « test/cctest/test-heap.cc ('k') | test/cctest/test-lockers.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 "function myFunction(a, b) { this.a = a; this.b = b; }\n" 248 "function myFunction(a, b) { this.a = a; this.b = b; }\n"
249 "function AAAAA() {}\n" 249 "function AAAAA() {}\n"
250 "boundFunction = myFunction.bind(new AAAAA(), 20, new Number(12)); \n"); 250 "boundFunction = myFunction.bind(new AAAAA(), 20, new Number(12)); \n");
251 const v8::HeapSnapshot* snapshot = 251 const v8::HeapSnapshot* snapshot =
252 heap_profiler->TakeHeapSnapshot(v8_str("sizes")); 252 heap_profiler->TakeHeapSnapshot(v8_str("sizes"));
253 CHECK(ValidateSnapshot(snapshot)); 253 CHECK(ValidateSnapshot(snapshot));
254 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 254 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
255 const v8::HeapGraphNode* f = 255 const v8::HeapGraphNode* f =
256 GetProperty(global, v8::HeapGraphEdge::kProperty, "boundFunction"); 256 GetProperty(global, v8::HeapGraphEdge::kProperty, "boundFunction");
257 CHECK(f); 257 CHECK(f);
258 CHECK_EQ(v8::String::New("native_bind"), f->GetName()); 258 CHECK_EQ(v8::String::NewFromUtf8(env->GetIsolate(), "native_bind"),
259 f->GetName());
259 const v8::HeapGraphNode* bindings = 260 const v8::HeapGraphNode* bindings =
260 GetProperty(f, v8::HeapGraphEdge::kInternal, "bindings"); 261 GetProperty(f, v8::HeapGraphEdge::kInternal, "bindings");
261 CHECK_NE(NULL, bindings); 262 CHECK_NE(NULL, bindings);
262 CHECK_EQ(v8::HeapGraphNode::kArray, bindings->GetType()); 263 CHECK_EQ(v8::HeapGraphNode::kArray, bindings->GetType());
263 CHECK_EQ(4, bindings->GetChildrenCount()); 264 CHECK_EQ(4, bindings->GetChildrenCount());
264 265
265 const v8::HeapGraphNode* bound_this = GetProperty( 266 const v8::HeapGraphNode* bound_this = GetProperty(
266 f, v8::HeapGraphEdge::kShortcut, "bound_this"); 267 f, v8::HeapGraphEdge::kShortcut, "bound_this");
267 CHECK(bound_this); 268 CHECK(bound_this);
268 CHECK_EQ(v8::HeapGraphNode::kObject, bound_this->GetType()); 269 CHECK_EQ(v8::HeapGraphNode::kObject, bound_this->GetType());
(...skipping 807 matching lines...) Expand 10 before | Expand all | Expand 10 after
1076 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 1077 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
1077 CompileRun("globalObject = {};\n"); 1078 CompileRun("globalObject = {};\n");
1078 const v8::HeapSnapshot* snapshot = 1079 const v8::HeapSnapshot* snapshot =
1079 heap_profiler->TakeHeapSnapshot(v8_str("get_snapshot_object_id")); 1080 heap_profiler->TakeHeapSnapshot(v8_str("get_snapshot_object_id"));
1080 CHECK(ValidateSnapshot(snapshot)); 1081 CHECK(ValidateSnapshot(snapshot));
1081 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 1082 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
1082 const v8::HeapGraphNode* global_object = 1083 const v8::HeapGraphNode* global_object =
1083 GetProperty(global, v8::HeapGraphEdge::kProperty, "globalObject"); 1084 GetProperty(global, v8::HeapGraphEdge::kProperty, "globalObject");
1084 CHECK(global_object); 1085 CHECK(global_object);
1085 1086
1086 v8::Local<v8::Value> globalObjectHandle = 1087 v8::Local<v8::Value> globalObjectHandle = env->Global()->Get(
1087 env->Global()->Get(v8::String::New("globalObject")); 1088 v8::String::NewFromUtf8(env->GetIsolate(), "globalObject"));
1088 CHECK(!globalObjectHandle.IsEmpty()); 1089 CHECK(!globalObjectHandle.IsEmpty());
1089 CHECK(globalObjectHandle->IsObject()); 1090 CHECK(globalObjectHandle->IsObject());
1090 1091
1091 v8::SnapshotObjectId id = heap_profiler->GetObjectId(globalObjectHandle); 1092 v8::SnapshotObjectId id = heap_profiler->GetObjectId(globalObjectHandle);
1092 CHECK_NE(static_cast<int>(v8::HeapProfiler::kUnknownObjectId), 1093 CHECK_NE(static_cast<int>(v8::HeapProfiler::kUnknownObjectId),
1093 id); 1094 id);
1094 CHECK_EQ(static_cast<int>(id), global_object->GetId()); 1095 CHECK_EQ(static_cast<int>(id), global_object->GetId());
1095 } 1096 }
1096 1097
1097 1098
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after
1712 heap_profiler->TakeHeapSnapshot(v8_str("HiddenPropertiesFastCase1")); 1713 heap_profiler->TakeHeapSnapshot(v8_str("HiddenPropertiesFastCase1"));
1713 CHECK(ValidateSnapshot(snapshot)); 1714 CHECK(ValidateSnapshot(snapshot));
1714 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 1715 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
1715 const v8::HeapGraphNode* c = 1716 const v8::HeapGraphNode* c =
1716 GetProperty(global, v8::HeapGraphEdge::kProperty, "c"); 1717 GetProperty(global, v8::HeapGraphEdge::kProperty, "c");
1717 CHECK_NE(NULL, c); 1718 CHECK_NE(NULL, c);
1718 const v8::HeapGraphNode* hidden_props = 1719 const v8::HeapGraphNode* hidden_props =
1719 GetProperty(c, v8::HeapGraphEdge::kInternal, "hidden_properties"); 1720 GetProperty(c, v8::HeapGraphEdge::kInternal, "hidden_properties");
1720 CHECK_EQ(NULL, hidden_props); 1721 CHECK_EQ(NULL, hidden_props);
1721 1722
1722 v8::Handle<v8::Value> cHandle = env->Global()->Get(v8::String::New("c")); 1723 v8::Handle<v8::Value> cHandle =
1724 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "c"));
1723 CHECK(!cHandle.IsEmpty() && cHandle->IsObject()); 1725 CHECK(!cHandle.IsEmpty() && cHandle->IsObject());
1724 cHandle->ToObject()->SetHiddenValue(v8_str("key"), v8_str("val")); 1726 cHandle->ToObject()->SetHiddenValue(v8_str("key"), v8_str("val"));
1725 1727
1726 snapshot = heap_profiler->TakeHeapSnapshot( 1728 snapshot = heap_profiler->TakeHeapSnapshot(
1727 v8_str("HiddenPropertiesFastCase2")); 1729 v8_str("HiddenPropertiesFastCase2"));
1728 CHECK(ValidateSnapshot(snapshot)); 1730 CHECK(ValidateSnapshot(snapshot));
1729 global = GetGlobalObject(snapshot); 1731 global = GetGlobalObject(snapshot);
1730 c = GetProperty(global, v8::HeapGraphEdge::kProperty, "c"); 1732 c = GetProperty(global, v8::HeapGraphEdge::kProperty, "c");
1731 CHECK_NE(NULL, c); 1733 CHECK_NE(NULL, c);
1732 hidden_props = GetProperty(c, v8::HeapGraphEdge::kInternal, 1734 hidden_props = GetProperty(c, v8::HeapGraphEdge::kInternal,
(...skipping 23 matching lines...) Expand all
1756 const v8::HeapGraphNode* global_handles = GetNode( 1758 const v8::HeapGraphNode* global_handles = GetNode(
1757 gc_roots, v8::HeapGraphNode::kSynthetic, "(Global handles)"); 1759 gc_roots, v8::HeapGraphNode::kSynthetic, "(Global handles)");
1758 CHECK_NE(NULL, global_handles); 1760 CHECK_NE(NULL, global_handles);
1759 return HasWeakEdge(global_handles); 1761 return HasWeakEdge(global_handles);
1760 } 1762 }
1761 1763
1762 1764
1763 static void PersistentHandleCallback(v8::Isolate* isolate, 1765 static void PersistentHandleCallback(v8::Isolate* isolate,
1764 v8::Persistent<v8::Value>* handle, 1766 v8::Persistent<v8::Value>* handle,
1765 void*) { 1767 void*) {
1766 handle->Dispose(); 1768 handle->Reset();
1767 } 1769 }
1768 1770
1769 1771
1770 TEST(WeakGlobalHandle) { 1772 TEST(WeakGlobalHandle) {
1771 LocalContext env; 1773 LocalContext env;
1772 v8::HandleScope scope(env->GetIsolate()); 1774 v8::HandleScope scope(env->GetIsolate());
1773 1775
1774 CHECK(!HasWeakGlobalHandle()); 1776 CHECK(!HasWeakGlobalHandle());
1775 1777
1776 v8::Persistent<v8::Object> handle(env->GetIsolate(), v8::Object::New()); 1778 v8::Persistent<v8::Object> handle(env->GetIsolate(), v8::Object::New());
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
2029 2031
2030 const char* HeapProfilerExtension::kName = "v8/heap-profiler"; 2032 const char* HeapProfilerExtension::kName = "v8/heap-profiler";
2031 2033
2032 2034
2033 const char* HeapProfilerExtension::kSource = 2035 const char* HeapProfilerExtension::kSource =
2034 "native function findUntrackedObjects();"; 2036 "native function findUntrackedObjects();";
2035 2037
2036 2038
2037 v8::Handle<v8::FunctionTemplate> HeapProfilerExtension::GetNativeFunction( 2039 v8::Handle<v8::FunctionTemplate> HeapProfilerExtension::GetNativeFunction(
2038 v8::Handle<v8::String> name) { 2040 v8::Handle<v8::String> name) {
2039 if (name->Equals(v8::String::New("findUntrackedObjects"))) { 2041 if (name->Equals(v8::String::NewFromUtf8(v8::Isolate::GetCurrent(),
2042 "findUntrackedObjects"))) {
2040 return v8::FunctionTemplate::New( 2043 return v8::FunctionTemplate::New(
2041 HeapProfilerExtension::FindUntrackedObjects); 2044 HeapProfilerExtension::FindUntrackedObjects);
2042 } else { 2045 } else {
2043 CHECK(false); 2046 CHECK(false);
2044 return v8::Handle<v8::FunctionTemplate>(); 2047 return v8::Handle<v8::FunctionTemplate>();
2045 } 2048 }
2046 } 2049 }
2047 2050
2048 2051
2049 void HeapProfilerExtension::FindUntrackedObjects( 2052 void HeapProfilerExtension::FindUntrackedObjects(
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
2205 TEST(TrackHeapAllocations) { 2208 TEST(TrackHeapAllocations) {
2206 v8::HandleScope scope(v8::Isolate::GetCurrent()); 2209 v8::HandleScope scope(v8::Isolate::GetCurrent());
2207 LocalContext env; 2210 LocalContext env;
2208 2211
2209 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 2212 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
2210 heap_profiler->StartRecordingHeapAllocations(); 2213 heap_profiler->StartRecordingHeapAllocations();
2211 2214
2212 CompileRun(record_trace_tree_source); 2215 CompileRun(record_trace_tree_source);
2213 2216
2214 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot( 2217 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(
2215 v8::String::New("Test")); 2218 v8::String::NewFromUtf8(env->GetIsolate(), "Test"));
2216 i::HeapSnapshotsCollection* collection = ToInternal(snapshot)->collection(); 2219 i::HeapSnapshotsCollection* collection = ToInternal(snapshot)->collection();
2217 AllocationTracker* tracker = collection->allocation_tracker(); 2220 AllocationTracker* tracker = collection->allocation_tracker();
2218 CHECK_NE(NULL, tracker); 2221 CHECK_NE(NULL, tracker);
2219 // Resolve all function locations. 2222 // Resolve all function locations.
2220 tracker->PrepareForSerialization(); 2223 tracker->PrepareForSerialization();
2221 // Print for better diagnostics in case of failure. 2224 // Print for better diagnostics in case of failure.
2222 tracker->trace_tree()->Print(tracker); 2225 tracker->trace_tree()->Print(tracker);
2223 2226
2224 const char* names[] = 2227 const char* names[] =
2225 { "(anonymous function)", "start", "f_0_0", "f_0_1", "f_0_2" }; 2228 { "(anonymous function)", "start", "f_0_0", "f_0_1", "f_0_2" };
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2258 2261
2259 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 2262 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
2260 const char* names[] = { "(anonymous function)", "start", "f_0", "f_1" }; 2263 const char* names[] = { "(anonymous function)", "start", "f_0", "f_1" };
2261 // First check that normally all allocations are recorded. 2264 // First check that normally all allocations are recorded.
2262 { 2265 {
2263 heap_profiler->StartRecordingHeapAllocations(); 2266 heap_profiler->StartRecordingHeapAllocations();
2264 2267
2265 CompileRun(inline_heap_allocation_source); 2268 CompileRun(inline_heap_allocation_source);
2266 2269
2267 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot( 2270 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(
2268 v8::String::New("Test2")); 2271 v8::String::NewFromUtf8(env->GetIsolate(), "Test2"));
2269 i::HeapSnapshotsCollection* collection = ToInternal(snapshot)->collection(); 2272 i::HeapSnapshotsCollection* collection = ToInternal(snapshot)->collection();
2270 AllocationTracker* tracker = collection->allocation_tracker(); 2273 AllocationTracker* tracker = collection->allocation_tracker();
2271 CHECK_NE(NULL, tracker); 2274 CHECK_NE(NULL, tracker);
2272 // Resolve all function locations. 2275 // Resolve all function locations.
2273 tracker->PrepareForSerialization(); 2276 tracker->PrepareForSerialization();
2274 // Print for better diagnostics in case of failure. 2277 // Print for better diagnostics in case of failure.
2275 tracker->trace_tree()->Print(tracker); 2278 tracker->trace_tree()->Print(tracker);
2276 2279
2277 AllocationTraceNode* node = 2280 AllocationTraceNode* node =
2278 FindNode(tracker, Vector<const char*>(names, ARRAY_SIZE(names))); 2281 FindNode(tracker, Vector<const char*>(names, ARRAY_SIZE(names)));
2279 CHECK_NE(NULL, node); 2282 CHECK_NE(NULL, node);
2280 CHECK_GE(node->allocation_count(), 100); 2283 CHECK_GE(node->allocation_count(), 100);
2281 CHECK_GE(node->allocation_size(), 4 * node->allocation_count()); 2284 CHECK_GE(node->allocation_size(), 4 * node->allocation_count());
2282 heap_profiler->StopRecordingHeapAllocations(); 2285 heap_profiler->StopRecordingHeapAllocations();
2283 } 2286 }
2284 2287
2285 { 2288 {
2286 heap_profiler->StartRecordingHeapAllocations(); 2289 heap_profiler->StartRecordingHeapAllocations();
2287 2290
2288 // Now check that not all allocations are tracked if we manually reenable 2291 // Now check that not all allocations are tracked if we manually reenable
2289 // inline allocations. 2292 // inline allocations.
2290 CHECK(CcTest::heap()->inline_allocation_disabled()); 2293 CHECK(CcTest::heap()->inline_allocation_disabled());
2291 CcTest::heap()->EnableInlineAllocation(); 2294 CcTest::heap()->EnableInlineAllocation();
2292 2295
2293 CompileRun(inline_heap_allocation_source); 2296 CompileRun(inline_heap_allocation_source);
2294 2297
2295 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot( 2298 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(
2296 v8::String::New("Test1")); 2299 v8::String::NewFromUtf8(env->GetIsolate(), "Test1"));
2297 i::HeapSnapshotsCollection* collection = ToInternal(snapshot)->collection(); 2300 i::HeapSnapshotsCollection* collection = ToInternal(snapshot)->collection();
2298 AllocationTracker* tracker = collection->allocation_tracker(); 2301 AllocationTracker* tracker = collection->allocation_tracker();
2299 CHECK_NE(NULL, tracker); 2302 CHECK_NE(NULL, tracker);
2300 // Resolve all function locations. 2303 // Resolve all function locations.
2301 tracker->PrepareForSerialization(); 2304 tracker->PrepareForSerialization();
2302 // Print for better diagnostics in case of failure. 2305 // Print for better diagnostics in case of failure.
2303 tracker->trace_tree()->Print(tracker); 2306 tracker->trace_tree()->Print(tracker);
2304 2307
2305 AllocationTraceNode* node = 2308 AllocationTraceNode* node =
2306 FindNode(tracker, Vector<const char*>(names, ARRAY_SIZE(names))); 2309 FindNode(tracker, Vector<const char*>(names, ARRAY_SIZE(names)));
2307 CHECK_NE(NULL, node); 2310 CHECK_NE(NULL, node);
2308 CHECK_LT(node->allocation_count(), 100); 2311 CHECK_LT(node->allocation_count(), 100);
2309 2312
2310 CcTest::heap()->DisableInlineAllocation(); 2313 CcTest::heap()->DisableInlineAllocation();
2311 heap_profiler->StopRecordingHeapAllocations(); 2314 heap_profiler->StopRecordingHeapAllocations();
2312 } 2315 }
2313 } 2316 }
OLDNEW
« no previous file with comments | « test/cctest/test-heap.cc ('k') | test/cctest/test-lockers.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698