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

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

Issue 119753008: Revert r18451 "Revert r18449 "Reland r18383: More API cleanup." and r18450 "Unbreak build."" since … (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 11 months 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-object-observe.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 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 465
466 TEST(HeapSnapshotInternalReferences) { 466 TEST(HeapSnapshotInternalReferences) {
467 v8::Isolate* isolate = CcTest::isolate(); 467 v8::Isolate* isolate = CcTest::isolate();
468 v8::HandleScope scope(isolate); 468 v8::HandleScope scope(isolate);
469 v8::Local<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 469 v8::Local<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
470 global_template->SetInternalFieldCount(2); 470 global_template->SetInternalFieldCount(2);
471 LocalContext env(NULL, global_template); 471 LocalContext env(NULL, global_template);
472 v8::Handle<v8::Object> global_proxy = env->Global(); 472 v8::Handle<v8::Object> global_proxy = env->Global();
473 v8::Handle<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>(); 473 v8::Handle<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>();
474 CHECK_EQ(2, global->InternalFieldCount()); 474 CHECK_EQ(2, global->InternalFieldCount());
475 v8::Local<v8::Object> obj = v8::Object::New(); 475 v8::Local<v8::Object> obj = v8::Object::New(isolate);
476 global->SetInternalField(0, v8_num(17)); 476 global->SetInternalField(0, v8_num(17));
477 global->SetInternalField(1, obj); 477 global->SetInternalField(1, obj);
478 v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler(); 478 v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler();
479 const v8::HeapSnapshot* snapshot = 479 const v8::HeapSnapshot* snapshot =
480 heap_profiler->TakeHeapSnapshot(v8_str("internals")); 480 heap_profiler->TakeHeapSnapshot(v8_str("internals"));
481 CHECK(ValidateSnapshot(snapshot)); 481 CHECK(ValidateSnapshot(snapshot));
482 const v8::HeapGraphNode* global_node = GetGlobalObject(snapshot); 482 const v8::HeapGraphNode* global_node = GetGlobalObject(snapshot);
483 // The first reference will not present, because it's a Smi. 483 // The first reference will not present, because it's a Smi.
484 CHECK_EQ(NULL, GetProperty(global_node, v8::HeapGraphEdge::kInternal, "0")); 484 CHECK_EQ(NULL, GetProperty(global_node, v8::HeapGraphEdge::kInternal, "0"));
485 // The second reference is to an object. 485 // The second reference is to an object.
(...skipping 861 matching lines...) Expand 10 before | Expand all | Expand 10 after
1347 1347
1348 1348
1349 class GraphWithImplicitRefs { 1349 class GraphWithImplicitRefs {
1350 public: 1350 public:
1351 static const int kObjectsCount = 4; 1351 static const int kObjectsCount = 4;
1352 explicit GraphWithImplicitRefs(LocalContext* env) { 1352 explicit GraphWithImplicitRefs(LocalContext* env) {
1353 CHECK_EQ(NULL, instance_); 1353 CHECK_EQ(NULL, instance_);
1354 instance_ = this; 1354 instance_ = this;
1355 isolate_ = (*env)->GetIsolate(); 1355 isolate_ = (*env)->GetIsolate();
1356 for (int i = 0; i < kObjectsCount; i++) { 1356 for (int i = 0; i < kObjectsCount; i++) {
1357 objects_[i].Reset(isolate_, v8::Object::New()); 1357 objects_[i].Reset(isolate_, v8::Object::New(isolate_));
1358 } 1358 }
1359 (*env)->Global()->Set(v8_str("root_object"), 1359 (*env)->Global()->Set(v8_str("root_object"),
1360 v8::Local<v8::Value>::New(isolate_, objects_[0])); 1360 v8::Local<v8::Value>::New(isolate_, objects_[0]));
1361 } 1361 }
1362 ~GraphWithImplicitRefs() { 1362 ~GraphWithImplicitRefs() {
1363 instance_ = NULL; 1363 instance_ = NULL;
1364 } 1364 }
1365 1365
1366 static void gcPrologue(v8::GCType type, v8::GCCallbackFlags flags) { 1366 static void gcPrologue(v8::GCType type, v8::GCCallbackFlags flags) {
1367 instance_->AddImplicitReferences(); 1367 instance_->AddImplicitReferences();
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
1814 } 1814 }
1815 1815
1816 1816
1817 TEST(WeakGlobalHandle) { 1817 TEST(WeakGlobalHandle) {
1818 LocalContext env; 1818 LocalContext env;
1819 v8::HandleScope scope(env->GetIsolate()); 1819 v8::HandleScope scope(env->GetIsolate());
1820 1820
1821 CHECK(!HasWeakGlobalHandle()); 1821 CHECK(!HasWeakGlobalHandle());
1822 1822
1823 v8::Persistent<v8::Object>* handle = 1823 v8::Persistent<v8::Object>* handle =
1824 new v8::Persistent<v8::Object>(env->GetIsolate(), v8::Object::New()); 1824 new v8::Persistent<v8::Object>(env->GetIsolate(),
1825 v8::Object::New(env->GetIsolate()));
1825 handle->SetWeak(handle, PersistentHandleCallback); 1826 handle->SetWeak(handle, PersistentHandleCallback);
1826 1827
1827 CHECK(HasWeakGlobalHandle()); 1828 CHECK(HasWeakGlobalHandle());
1828 } 1829 }
1829 1830
1830 1831
1831 TEST(SfiAndJsFunctionWeakRefs) { 1832 TEST(SfiAndJsFunctionWeakRefs) {
1832 LocalContext env; 1833 LocalContext env;
1833 v8::HandleScope scope(env->GetIsolate()); 1834 v8::HandleScope scope(env->GetIsolate());
1834 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 1835 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
1988 i::OS::SNPrintF(var_name, "f_%d", i); 1989 i::OS::SNPrintF(var_name, "f_%d", i);
1989 const v8::HeapGraphNode* f_object = GetProperty( 1990 const v8::HeapGraphNode* f_object = GetProperty(
1990 context_object, v8::HeapGraphEdge::kContextVariable, var_name.start()); 1991 context_object, v8::HeapGraphEdge::kContextVariable, var_name.start());
1991 CHECK_NE(NULL, f_object); 1992 CHECK_NE(NULL, f_object);
1992 } 1993 }
1993 } 1994 }
1994 1995
1995 1996
1996 TEST(AllocationSitesAreVisible) { 1997 TEST(AllocationSitesAreVisible) {
1997 LocalContext env; 1998 LocalContext env;
1998 v8::HandleScope scope(env->GetIsolate()); 1999 v8::Isolate* isolate = env->GetIsolate();
1999 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 2000 v8::HandleScope scope(isolate);
2001 v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler();
2000 CompileRun( 2002 CompileRun(
2001 "fun = function () { var a = [3, 2, 1]; return a; }\n" 2003 "fun = function () { var a = [3, 2, 1]; return a; }\n"
2002 "fun();"); 2004 "fun();");
2003 const v8::HeapSnapshot* snapshot = 2005 const v8::HeapSnapshot* snapshot =
2004 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); 2006 heap_profiler->TakeHeapSnapshot(v8_str("snapshot"));
2005 CHECK(ValidateSnapshot(snapshot)); 2007 CHECK(ValidateSnapshot(snapshot));
2006 2008
2007 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 2009 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
2008 CHECK_NE(NULL, global); 2010 CHECK_NE(NULL, global);
2009 const v8::HeapGraphNode* fun_code = 2011 const v8::HeapGraphNode* fun_code =
(...skipping 22 matching lines...) Expand all
2032 CHECK_NE(NULL, elements); 2034 CHECK_NE(NULL, elements);
2033 CHECK_EQ(v8::HeapGraphNode::kArray, elements->GetType()); 2035 CHECK_EQ(v8::HeapGraphNode::kArray, elements->GetType());
2034 CHECK_EQ(v8::internal::FixedArray::SizeFor(3), elements->GetSelfSize()); 2036 CHECK_EQ(v8::internal::FixedArray::SizeFor(3), elements->GetSelfSize());
2035 2037
2036 v8::Handle<v8::Value> array_val = 2038 v8::Handle<v8::Value> array_val =
2037 heap_profiler->FindObjectById(transition_info->GetId()); 2039 heap_profiler->FindObjectById(transition_info->GetId());
2038 CHECK(array_val->IsArray()); 2040 CHECK(array_val->IsArray());
2039 v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(array_val); 2041 v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(array_val);
2040 // Verify the array is "a" in the code above. 2042 // Verify the array is "a" in the code above.
2041 CHECK_EQ(3, array->Length()); 2043 CHECK_EQ(3, array->Length());
2042 CHECK_EQ(v8::Integer::New(3), array->Get(v8::Integer::New(0))); 2044 CHECK_EQ(v8::Integer::New(isolate, 3),
2043 CHECK_EQ(v8::Integer::New(2), array->Get(v8::Integer::New(1))); 2045 array->Get(v8::Integer::New(isolate, 0)));
2044 CHECK_EQ(v8::Integer::New(1), array->Get(v8::Integer::New(2))); 2046 CHECK_EQ(v8::Integer::New(isolate, 2),
2047 array->Get(v8::Integer::New(isolate, 1)));
2048 CHECK_EQ(v8::Integer::New(isolate, 1),
2049 array->Get(v8::Integer::New(isolate, 2)));
2045 } 2050 }
2046 2051
2047 2052
2048 TEST(JSFunctionHasCodeLink) { 2053 TEST(JSFunctionHasCodeLink) {
2049 LocalContext env; 2054 LocalContext env;
2050 v8::HandleScope scope(env->GetIsolate()); 2055 v8::HandleScope scope(env->GetIsolate());
2051 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 2056 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
2052 CompileRun("function foo(x, y) { return x + y; }\n"); 2057 CompileRun("function foo(x, y) { return x + y; }\n");
2053 const v8::HeapSnapshot* snapshot = 2058 const v8::HeapSnapshot* snapshot =
2054 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); 2059 heap_profiler->TakeHeapSnapshot(v8_str("snapshot"));
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
2356 2361
2357 AllocationTraceNode* node = 2362 AllocationTraceNode* node =
2358 FindNode(tracker, Vector<const char*>(names, ARRAY_SIZE(names))); 2363 FindNode(tracker, Vector<const char*>(names, ARRAY_SIZE(names)));
2359 CHECK_NE(NULL, node); 2364 CHECK_NE(NULL, node);
2360 CHECK_LT(node->allocation_count(), 100); 2365 CHECK_LT(node->allocation_count(), 100);
2361 2366
2362 CcTest::heap()->DisableInlineAllocation(); 2367 CcTest::heap()->DisableInlineAllocation();
2363 heap_profiler->StopTrackingHeapObjects(); 2368 heap_profiler->StopTrackingHeapObjects();
2364 } 2369 }
2365 } 2370 }
OLDNEW
« no previous file with comments | « test/cctest/test-heap.cc ('k') | test/cctest/test-object-observe.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698