| 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 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 const v8::HeapGraphNode* parent = | 416 const v8::HeapGraphNode* parent = |
| 417 GetProperty(child_string, v8::HeapGraphEdge::kInternal, "parent"); | 417 GetProperty(child_string, v8::HeapGraphEdge::kInternal, "parent"); |
| 418 CHECK_EQ(parent_string, parent); | 418 CHECK_EQ(parent_string, parent); |
| 419 heap_profiler->DeleteAllHeapSnapshots(); | 419 heap_profiler->DeleteAllHeapSnapshots(); |
| 420 } | 420 } |
| 421 | 421 |
| 422 | 422 |
| 423 TEST(HeapSnapshotConsString) { | 423 TEST(HeapSnapshotConsString) { |
| 424 v8::Isolate* isolate = CcTest::isolate(); | 424 v8::Isolate* isolate = CcTest::isolate(); |
| 425 v8::HandleScope scope(isolate); | 425 v8::HandleScope scope(isolate); |
| 426 v8::Local<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); | 426 v8::Local<v8::ObjectTemplate> global_template = |
| 427 v8::ObjectTemplate::New(isolate); |
| 427 global_template->SetInternalFieldCount(1); | 428 global_template->SetInternalFieldCount(1); |
| 428 LocalContext env(NULL, global_template); | 429 LocalContext env(NULL, global_template); |
| 429 v8::Handle<v8::Object> global_proxy = env->Global(); | 430 v8::Handle<v8::Object> global_proxy = env->Global(); |
| 430 v8::Handle<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>(); | 431 v8::Handle<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>(); |
| 431 CHECK_EQ(1, global->InternalFieldCount()); | 432 CHECK_EQ(1, global->InternalFieldCount()); |
| 432 | 433 |
| 433 i::Factory* factory = CcTest::i_isolate()->factory(); | 434 i::Factory* factory = CcTest::i_isolate()->factory(); |
| 434 i::Handle<i::String> first = | 435 i::Handle<i::String> first = |
| 435 factory->NewStringFromAscii(i::CStrVector("0123456789")); | 436 factory->NewStringFromAscii(i::CStrVector("0123456789")); |
| 436 i::Handle<i::String> second = | 437 i::Handle<i::String> second = |
| (...skipping 22 matching lines...) Expand all Loading... |
| 459 CHECK_EQ(v8::HeapGraphNode::kString, second_node->GetType()); | 460 CHECK_EQ(v8::HeapGraphNode::kString, second_node->GetType()); |
| 460 | 461 |
| 461 heap_profiler->DeleteAllHeapSnapshots(); | 462 heap_profiler->DeleteAllHeapSnapshots(); |
| 462 } | 463 } |
| 463 | 464 |
| 464 | 465 |
| 465 | 466 |
| 466 TEST(HeapSnapshotInternalReferences) { | 467 TEST(HeapSnapshotInternalReferences) { |
| 467 v8::Isolate* isolate = CcTest::isolate(); | 468 v8::Isolate* isolate = CcTest::isolate(); |
| 468 v8::HandleScope scope(isolate); | 469 v8::HandleScope scope(isolate); |
| 469 v8::Local<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); | 470 v8::Local<v8::ObjectTemplate> global_template = |
| 471 v8::ObjectTemplate::New(isolate); |
| 470 global_template->SetInternalFieldCount(2); | 472 global_template->SetInternalFieldCount(2); |
| 471 LocalContext env(NULL, global_template); | 473 LocalContext env(NULL, global_template); |
| 472 v8::Handle<v8::Object> global_proxy = env->Global(); | 474 v8::Handle<v8::Object> global_proxy = env->Global(); |
| 473 v8::Handle<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>(); | 475 v8::Handle<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>(); |
| 474 CHECK_EQ(2, global->InternalFieldCount()); | 476 CHECK_EQ(2, global->InternalFieldCount()); |
| 475 v8::Local<v8::Object> obj = v8::Object::New(); | 477 v8::Local<v8::Object> obj = v8::Object::New(isolate); |
| 476 global->SetInternalField(0, v8_num(17)); | 478 global->SetInternalField(0, v8_num(17)); |
| 477 global->SetInternalField(1, obj); | 479 global->SetInternalField(1, obj); |
| 478 v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler(); | 480 v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler(); |
| 479 const v8::HeapSnapshot* snapshot = | 481 const v8::HeapSnapshot* snapshot = |
| 480 heap_profiler->TakeHeapSnapshot(v8_str("internals")); | 482 heap_profiler->TakeHeapSnapshot(v8_str("internals")); |
| 481 CHECK(ValidateSnapshot(snapshot)); | 483 CHECK(ValidateSnapshot(snapshot)); |
| 482 const v8::HeapGraphNode* global_node = GetGlobalObject(snapshot); | 484 const v8::HeapGraphNode* global_node = GetGlobalObject(snapshot); |
| 483 // The first reference will not present, because it's a Smi. | 485 // The first reference will not present, because it's a Smi. |
| 484 CHECK_EQ(NULL, GetProperty(global_node, v8::HeapGraphEdge::kInternal, "0")); | 486 CHECK_EQ(NULL, GetProperty(global_node, v8::HeapGraphEdge::kInternal, "0")); |
| 485 // The second reference is to an object. | 487 // The second reference is to an object. |
| (...skipping 861 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1347 | 1349 |
| 1348 | 1350 |
| 1349 class GraphWithImplicitRefs { | 1351 class GraphWithImplicitRefs { |
| 1350 public: | 1352 public: |
| 1351 static const int kObjectsCount = 4; | 1353 static const int kObjectsCount = 4; |
| 1352 explicit GraphWithImplicitRefs(LocalContext* env) { | 1354 explicit GraphWithImplicitRefs(LocalContext* env) { |
| 1353 CHECK_EQ(NULL, instance_); | 1355 CHECK_EQ(NULL, instance_); |
| 1354 instance_ = this; | 1356 instance_ = this; |
| 1355 isolate_ = (*env)->GetIsolate(); | 1357 isolate_ = (*env)->GetIsolate(); |
| 1356 for (int i = 0; i < kObjectsCount; i++) { | 1358 for (int i = 0; i < kObjectsCount; i++) { |
| 1357 objects_[i].Reset(isolate_, v8::Object::New()); | 1359 objects_[i].Reset(isolate_, v8::Object::New(isolate_)); |
| 1358 } | 1360 } |
| 1359 (*env)->Global()->Set(v8_str("root_object"), | 1361 (*env)->Global()->Set(v8_str("root_object"), |
| 1360 v8::Local<v8::Value>::New(isolate_, objects_[0])); | 1362 v8::Local<v8::Value>::New(isolate_, objects_[0])); |
| 1361 } | 1363 } |
| 1362 ~GraphWithImplicitRefs() { | 1364 ~GraphWithImplicitRefs() { |
| 1363 instance_ = NULL; | 1365 instance_ = NULL; |
| 1364 } | 1366 } |
| 1365 | 1367 |
| 1366 static void gcPrologue(v8::GCType type, v8::GCCallbackFlags flags) { | 1368 static void gcPrologue(v8::GCType type, v8::GCCallbackFlags flags) { |
| 1367 instance_->AddImplicitReferences(); | 1369 instance_->AddImplicitReferences(); |
| (...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1814 } | 1816 } |
| 1815 | 1817 |
| 1816 | 1818 |
| 1817 TEST(WeakGlobalHandle) { | 1819 TEST(WeakGlobalHandle) { |
| 1818 LocalContext env; | 1820 LocalContext env; |
| 1819 v8::HandleScope scope(env->GetIsolate()); | 1821 v8::HandleScope scope(env->GetIsolate()); |
| 1820 | 1822 |
| 1821 CHECK(!HasWeakGlobalHandle()); | 1823 CHECK(!HasWeakGlobalHandle()); |
| 1822 | 1824 |
| 1823 v8::Persistent<v8::Object>* handle = | 1825 v8::Persistent<v8::Object>* handle = |
| 1824 new v8::Persistent<v8::Object>(env->GetIsolate(), v8::Object::New()); | 1826 new v8::Persistent<v8::Object>(env->GetIsolate(), |
| 1827 v8::Object::New(env->GetIsolate())); |
| 1825 handle->SetWeak(handle, PersistentHandleCallback); | 1828 handle->SetWeak(handle, PersistentHandleCallback); |
| 1826 | 1829 |
| 1827 CHECK(HasWeakGlobalHandle()); | 1830 CHECK(HasWeakGlobalHandle()); |
| 1828 } | 1831 } |
| 1829 | 1832 |
| 1830 | 1833 |
| 1831 TEST(SfiAndJsFunctionWeakRefs) { | 1834 TEST(SfiAndJsFunctionWeakRefs) { |
| 1832 LocalContext env; | 1835 LocalContext env; |
| 1833 v8::HandleScope scope(env->GetIsolate()); | 1836 v8::HandleScope scope(env->GetIsolate()); |
| 1834 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 1837 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1988 i::OS::SNPrintF(var_name, "f_%d", i); | 1991 i::OS::SNPrintF(var_name, "f_%d", i); |
| 1989 const v8::HeapGraphNode* f_object = GetProperty( | 1992 const v8::HeapGraphNode* f_object = GetProperty( |
| 1990 context_object, v8::HeapGraphEdge::kContextVariable, var_name.start()); | 1993 context_object, v8::HeapGraphEdge::kContextVariable, var_name.start()); |
| 1991 CHECK_NE(NULL, f_object); | 1994 CHECK_NE(NULL, f_object); |
| 1992 } | 1995 } |
| 1993 } | 1996 } |
| 1994 | 1997 |
| 1995 | 1998 |
| 1996 TEST(AllocationSitesAreVisible) { | 1999 TEST(AllocationSitesAreVisible) { |
| 1997 LocalContext env; | 2000 LocalContext env; |
| 1998 v8::HandleScope scope(env->GetIsolate()); | 2001 v8::Isolate* isolate = env->GetIsolate(); |
| 1999 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 2002 v8::HandleScope scope(isolate); |
| 2003 v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler(); |
| 2000 CompileRun( | 2004 CompileRun( |
| 2001 "fun = function () { var a = [3, 2, 1]; return a; }\n" | 2005 "fun = function () { var a = [3, 2, 1]; return a; }\n" |
| 2002 "fun();"); | 2006 "fun();"); |
| 2003 const v8::HeapSnapshot* snapshot = | 2007 const v8::HeapSnapshot* snapshot = |
| 2004 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); | 2008 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); |
| 2005 CHECK(ValidateSnapshot(snapshot)); | 2009 CHECK(ValidateSnapshot(snapshot)); |
| 2006 | 2010 |
| 2007 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 2011 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
| 2008 CHECK_NE(NULL, global); | 2012 CHECK_NE(NULL, global); |
| 2009 const v8::HeapGraphNode* fun_code = | 2013 const v8::HeapGraphNode* fun_code = |
| (...skipping 22 matching lines...) Expand all Loading... |
| 2032 CHECK_NE(NULL, elements); | 2036 CHECK_NE(NULL, elements); |
| 2033 CHECK_EQ(v8::HeapGraphNode::kArray, elements->GetType()); | 2037 CHECK_EQ(v8::HeapGraphNode::kArray, elements->GetType()); |
| 2034 CHECK_EQ(v8::internal::FixedArray::SizeFor(3), elements->GetSelfSize()); | 2038 CHECK_EQ(v8::internal::FixedArray::SizeFor(3), elements->GetSelfSize()); |
| 2035 | 2039 |
| 2036 v8::Handle<v8::Value> array_val = | 2040 v8::Handle<v8::Value> array_val = |
| 2037 heap_profiler->FindObjectById(transition_info->GetId()); | 2041 heap_profiler->FindObjectById(transition_info->GetId()); |
| 2038 CHECK(array_val->IsArray()); | 2042 CHECK(array_val->IsArray()); |
| 2039 v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(array_val); | 2043 v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(array_val); |
| 2040 // Verify the array is "a" in the code above. | 2044 // Verify the array is "a" in the code above. |
| 2041 CHECK_EQ(3, array->Length()); | 2045 CHECK_EQ(3, array->Length()); |
| 2042 CHECK_EQ(v8::Integer::New(3), array->Get(v8::Integer::New(0))); | 2046 CHECK_EQ(v8::Integer::New(isolate, 3), |
| 2043 CHECK_EQ(v8::Integer::New(2), array->Get(v8::Integer::New(1))); | 2047 array->Get(v8::Integer::New(isolate, 0))); |
| 2044 CHECK_EQ(v8::Integer::New(1), array->Get(v8::Integer::New(2))); | 2048 CHECK_EQ(v8::Integer::New(isolate, 2), |
| 2049 array->Get(v8::Integer::New(isolate, 1))); |
| 2050 CHECK_EQ(v8::Integer::New(isolate, 1), |
| 2051 array->Get(v8::Integer::New(isolate, 2))); |
| 2045 } | 2052 } |
| 2046 | 2053 |
| 2047 | 2054 |
| 2048 TEST(JSFunctionHasCodeLink) { | 2055 TEST(JSFunctionHasCodeLink) { |
| 2049 LocalContext env; | 2056 LocalContext env; |
| 2050 v8::HandleScope scope(env->GetIsolate()); | 2057 v8::HandleScope scope(env->GetIsolate()); |
| 2051 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 2058 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
| 2052 CompileRun("function foo(x, y) { return x + y; }\n"); | 2059 CompileRun("function foo(x, y) { return x + y; }\n"); |
| 2053 const v8::HeapSnapshot* snapshot = | 2060 const v8::HeapSnapshot* snapshot = |
| 2054 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); | 2061 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2356 | 2363 |
| 2357 AllocationTraceNode* node = | 2364 AllocationTraceNode* node = |
| 2358 FindNode(tracker, Vector<const char*>(names, ARRAY_SIZE(names))); | 2365 FindNode(tracker, Vector<const char*>(names, ARRAY_SIZE(names))); |
| 2359 CHECK_NE(NULL, node); | 2366 CHECK_NE(NULL, node); |
| 2360 CHECK_LT(node->allocation_count(), 100); | 2367 CHECK_LT(node->allocation_count(), 100); |
| 2361 | 2368 |
| 2362 CcTest::heap()->DisableInlineAllocation(); | 2369 CcTest::heap()->DisableInlineAllocation(); |
| 2363 heap_profiler->StopTrackingHeapObjects(); | 2370 heap_profiler->StopTrackingHeapObjects(); |
| 2364 } | 2371 } |
| 2365 } | 2372 } |
| OLD | NEW |