| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // | 2 // |
| 3 // Tests for heap profiler | 3 // Tests for heap profiler |
| 4 | 4 |
| 5 #include "v8.h" | 5 #include "v8.h" |
| 6 | 6 |
| 7 #include "cctest.h" | 7 #include "cctest.h" |
| 8 #include "heap-profiler.h" | 8 #include "heap-profiler.h" |
| 9 #include "snapshot.h" | 9 #include "snapshot.h" |
| 10 #include "utils-inl.h" | 10 #include "utils-inl.h" |
| 11 #include "../include/v8-profiler.h" | 11 #include "../include/v8-profiler.h" |
| 12 | 12 |
| 13 namespace i = v8::internal; | |
| 14 | |
| 15 namespace { | 13 namespace { |
| 16 | 14 |
| 17 class NamedEntriesDetector { | 15 class NamedEntriesDetector { |
| 18 public: | 16 public: |
| 19 NamedEntriesDetector() | 17 NamedEntriesDetector() |
| 20 : has_A2(false), has_B2(false), has_C2(false) { | 18 : has_A2(false), has_B2(false), has_C2(false) { |
| 21 } | 19 } |
| 22 | 20 |
| 23 void Apply(i::HeapEntry** entry_ptr) { | 21 void Apply(i::HeapEntry** entry_ptr) { |
| 24 if (IsReachableNodeWithName(*entry_ptr, "A2")) has_A2 = true; | 22 if (IsReachableNodeWithName(*entry_ptr, "A2")) has_A2 = true; |
| (...skipping 859 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 884 CHECK_NE(NULL, global); | 882 CHECK_NE(NULL, global); |
| 885 // Verify that we can find this object by iteration. | 883 // Verify that we can find this object by iteration. |
| 886 const int nodes_count = snapshot->GetNodesCount(); | 884 const int nodes_count = snapshot->GetNodesCount(); |
| 887 int count = 0; | 885 int count = 0; |
| 888 for (int i = 0; i < nodes_count; ++i) { | 886 for (int i = 0; i < nodes_count; ++i) { |
| 889 if (snapshot->GetNode(i) == global) | 887 if (snapshot->GetNode(i) == global) |
| 890 ++count; | 888 ++count; |
| 891 } | 889 } |
| 892 CHECK_EQ(1, count); | 890 CHECK_EQ(1, count); |
| 893 } | 891 } |
| 892 |
| 893 |
| 894 static int StringCmp(const char* ref, i::String* act) { |
| 895 i::SmartPointer<char> s_act = act->ToCString(); |
| 896 int result = strcmp(ref, *s_act); |
| 897 if (result != 0) |
| 898 fprintf(stderr, "Expected: \"%s\", Actual: \"%s\"\n", ref, *s_act); |
| 899 return result; |
| 900 } |
| 901 |
| 902 |
| 903 TEST(GetConstructorName) { |
| 904 v8::HandleScope scope; |
| 905 LocalContext env; |
| 906 |
| 907 CompileRun( |
| 908 "function Constructor1() {};\n" |
| 909 "var obj1 = new Constructor1();\n" |
| 910 "var Constructor2 = function() {};\n" |
| 911 "var obj2 = new Constructor2();\n" |
| 912 "var obj3 = {};\n" |
| 913 "obj3.constructor = function Constructor3() {};\n" |
| 914 "var obj4 = {};\n" |
| 915 "// Slow properties\n" |
| 916 "for (var i=0; i<2000; ++i) obj4[\"p\" + i] = i;\n" |
| 917 "obj4.constructor = function Constructor4() {};\n" |
| 918 "var obj5 = {};\n" |
| 919 "var obj6 = {};\n" |
| 920 "obj6.constructor = 6;"); |
| 921 v8::Local<v8::Object> js_global = |
| 922 env->Global()->GetPrototype().As<v8::Object>(); |
| 923 v8::Local<v8::Object> obj1 = js_global->Get(v8_str("obj1")).As<v8::Object>(); |
| 924 i::Handle<i::JSObject> js_obj1 = v8::Utils::OpenHandle(*obj1); |
| 925 CHECK_EQ(0, StringCmp( |
| 926 "Constructor1", i::V8HeapExplorer::GetConstructorName(*js_obj1))); |
| 927 v8::Local<v8::Object> obj2 = js_global->Get(v8_str("obj2")).As<v8::Object>(); |
| 928 i::Handle<i::JSObject> js_obj2 = v8::Utils::OpenHandle(*obj2); |
| 929 CHECK_EQ(0, StringCmp( |
| 930 "Constructor2", i::V8HeapExplorer::GetConstructorName(*js_obj2))); |
| 931 v8::Local<v8::Object> obj3 = js_global->Get(v8_str("obj3")).As<v8::Object>(); |
| 932 i::Handle<i::JSObject> js_obj3 = v8::Utils::OpenHandle(*obj3); |
| 933 CHECK_EQ(0, StringCmp( |
| 934 "Constructor3", i::V8HeapExplorer::GetConstructorName(*js_obj3))); |
| 935 v8::Local<v8::Object> obj4 = js_global->Get(v8_str("obj4")).As<v8::Object>(); |
| 936 i::Handle<i::JSObject> js_obj4 = v8::Utils::OpenHandle(*obj4); |
| 937 CHECK_EQ(0, StringCmp( |
| 938 "Constructor4", i::V8HeapExplorer::GetConstructorName(*js_obj4))); |
| 939 v8::Local<v8::Object> obj5 = js_global->Get(v8_str("obj5")).As<v8::Object>(); |
| 940 i::Handle<i::JSObject> js_obj5 = v8::Utils::OpenHandle(*obj5); |
| 941 CHECK_EQ(0, StringCmp( |
| 942 "Object", i::V8HeapExplorer::GetConstructorName(*js_obj5))); |
| 943 v8::Local<v8::Object> obj6 = js_global->Get(v8_str("obj6")).As<v8::Object>(); |
| 944 i::Handle<i::JSObject> js_obj6 = v8::Utils::OpenHandle(*obj6); |
| 945 CHECK_EQ(0, StringCmp( |
| 946 "Object", i::V8HeapExplorer::GetConstructorName(*js_obj6))); |
| 947 } |
| OLD | NEW |