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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 bool has_A2; | 88 bool has_A2; |
89 bool has_B2; | 89 bool has_B2; |
90 bool has_C2; | 90 bool has_C2; |
91 }; | 91 }; |
92 | 92 |
93 } // namespace | 93 } // namespace |
94 | 94 |
95 | 95 |
96 static const v8::HeapGraphNode* GetGlobalObject( | 96 static const v8::HeapGraphNode* GetGlobalObject( |
97 const v8::HeapSnapshot* snapshot) { | 97 const v8::HeapSnapshot* snapshot) { |
98 CHECK_EQ(2, snapshot->GetRoot()->GetChildrenCount()); | 98 CHECK_EQ(3, snapshot->GetRoot()->GetChildrenCount()); |
99 // The 0th-child is (GC Roots), 1st is the user root. | 99 // The 0th-child is (GC Roots), 1st is code stubs context, 2nd is the user |
| 100 // root. |
100 const v8::HeapGraphNode* global_obj = | 101 const v8::HeapGraphNode* global_obj = |
101 snapshot->GetRoot()->GetChild(1)->GetToNode(); | 102 snapshot->GetRoot()->GetChild(2)->GetToNode(); |
102 CHECK_EQ(0, strncmp("Object", const_cast<i::HeapEntry*>( | 103 CHECK_EQ(0, strncmp("Object", const_cast<i::HeapEntry*>( |
103 reinterpret_cast<const i::HeapEntry*>(global_obj))->name(), 6)); | 104 reinterpret_cast<const i::HeapEntry*>(global_obj))->name(), 6)); |
104 return global_obj; | 105 return global_obj; |
105 } | 106 } |
106 | 107 |
107 | 108 |
108 static const v8::HeapGraphNode* GetProperty(const v8::HeapGraphNode* node, | 109 static const v8::HeapGraphNode* GetProperty(const v8::HeapGraphNode* node, |
109 v8::HeapGraphEdge::Type type, | 110 v8::HeapGraphEdge::Type type, |
110 const char* name) { | 111 const char* name) { |
111 for (int i = 0, count = node->GetChildrenCount(); i < count; ++i) { | 112 for (int i = 0, count = node->GetChildrenCount(); i < count; ++i) { |
(...skipping 841 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
953 int string_index = static_cast<int>( | 954 int string_index = static_cast<int>( |
954 nodes_array->Get(string_obj_pos + 1)->ToNumber(isolate)->Value()); | 955 nodes_array->Get(string_obj_pos + 1)->ToNumber(isolate)->Value()); |
955 CHECK_GT(string_index, 0); | 956 CHECK_GT(string_index, 0); |
956 v8::Local<v8::Object> strings_array = | 957 v8::Local<v8::Object> strings_array = |
957 parsed_snapshot->Get(v8_str("strings"))->ToObject(isolate); | 958 parsed_snapshot->Get(v8_str("strings"))->ToObject(isolate); |
958 v8::Local<v8::String> string = | 959 v8::Local<v8::String> string = |
959 strings_array->Get(string_index)->ToString(isolate); | 960 strings_array->Get(string_index)->ToString(isolate); |
960 v8::Local<v8::String> ref_string = | 961 v8::Local<v8::String> ref_string = |
961 CompileRun(STRING_LITERAL_FOR_TEST)->ToString(isolate); | 962 CompileRun(STRING_LITERAL_FOR_TEST)->ToString(isolate); |
962 #undef STRING_LITERAL_FOR_TEST | 963 #undef STRING_LITERAL_FOR_TEST |
963 CHECK_EQ(0, strcmp(*v8::String::Utf8Value(ref_string), | 964 CHECK_LT(0, strcmp(*v8::String::Utf8Value(ref_string), |
964 *v8::String::Utf8Value(string))); | 965 *v8::String::Utf8Value(string))); |
965 } | 966 } |
966 | 967 |
967 | 968 |
968 TEST(HeapSnapshotJSONSerializationAborting) { | 969 TEST(HeapSnapshotJSONSerializationAborting) { |
969 LocalContext env; | 970 LocalContext env; |
970 v8::HandleScope scope(env->GetIsolate()); | 971 v8::HandleScope scope(env->GetIsolate()); |
971 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 972 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
972 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); | 973 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); |
973 CHECK(ValidateSnapshot(snapshot)); | 974 CHECK(ValidateSnapshot(snapshot)); |
(...skipping 1101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2075 LocalContext env; | 2076 LocalContext env; |
2076 v8::HandleScope scope(env->GetIsolate()); | 2077 v8::HandleScope scope(env->GetIsolate()); |
2077 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 2078 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
2078 | 2079 |
2079 CHECK(CcTest::i_isolate()->debug()->Load()); | 2080 CHECK(CcTest::i_isolate()->debug()->Load()); |
2080 CompileRun("foo = {};"); | 2081 CompileRun("foo = {};"); |
2081 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); | 2082 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); |
2082 CHECK(ValidateSnapshot(snapshot)); | 2083 CHECK(ValidateSnapshot(snapshot)); |
2083 const v8::HeapGraphNode* root = snapshot->GetRoot(); | 2084 const v8::HeapGraphNode* root = snapshot->GetRoot(); |
2084 int globals_count = 0; | 2085 int globals_count = 0; |
| 2086 bool found = false; |
2085 for (int i = 0; i < root->GetChildrenCount(); ++i) { | 2087 for (int i = 0; i < root->GetChildrenCount(); ++i) { |
2086 const v8::HeapGraphEdge* edge = root->GetChild(i); | 2088 const v8::HeapGraphEdge* edge = root->GetChild(i); |
2087 if (edge->GetType() == v8::HeapGraphEdge::kShortcut) { | 2089 if (edge->GetType() == v8::HeapGraphEdge::kShortcut) { |
2088 ++globals_count; | 2090 ++globals_count; |
2089 const v8::HeapGraphNode* global = edge->GetToNode(); | 2091 const v8::HeapGraphNode* global = edge->GetToNode(); |
2090 const v8::HeapGraphNode* foo = | 2092 const v8::HeapGraphNode* foo = |
2091 GetProperty(global, v8::HeapGraphEdge::kProperty, "foo"); | 2093 GetProperty(global, v8::HeapGraphEdge::kProperty, "foo"); |
2092 CHECK(foo); | 2094 if (foo != nullptr) { |
| 2095 found = true; |
| 2096 } |
2093 } | 2097 } |
2094 } | 2098 } |
2095 CHECK_EQ(1, globals_count); | 2099 CHECK_EQ(2, globals_count); |
| 2100 CHECK(found); |
2096 } | 2101 } |
2097 | 2102 |
2098 | 2103 |
2099 TEST(AllStrongGcRootsHaveNames) { | 2104 TEST(AllStrongGcRootsHaveNames) { |
2100 LocalContext env; | 2105 LocalContext env; |
2101 v8::HandleScope scope(env->GetIsolate()); | 2106 v8::HandleScope scope(env->GetIsolate()); |
2102 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); | 2107 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); |
2103 | 2108 |
2104 CompileRun("foo = {};"); | 2109 CompileRun("foo = {};"); |
2105 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); | 2110 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(); |
(...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2756 map.AddRange(ToAddress(0x180), 0x80, 6U); | 2761 map.AddRange(ToAddress(0x180), 0x80, 6U); |
2757 map.AddRange(ToAddress(0x180), 0x80, 7U); | 2762 map.AddRange(ToAddress(0x180), 0x80, 7U); |
2758 CHECK_EQ(7u, map.GetTraceNodeId(ToAddress(0x180))); | 2763 CHECK_EQ(7u, map.GetTraceNodeId(ToAddress(0x180))); |
2759 CHECK_EQ(5u, map.GetTraceNodeId(ToAddress(0x200))); | 2764 CHECK_EQ(5u, map.GetTraceNodeId(ToAddress(0x200))); |
2760 CHECK_EQ(3u, map.size()); | 2765 CHECK_EQ(3u, map.size()); |
2761 | 2766 |
2762 map.Clear(); | 2767 map.Clear(); |
2763 CHECK_EQ(0u, map.size()); | 2768 CHECK_EQ(0u, map.size()); |
2764 CHECK_EQ(0u, map.GetTraceNodeId(ToAddress(0x400))); | 2769 CHECK_EQ(0u, map.GetTraceNodeId(ToAddress(0x400))); |
2765 } | 2770 } |
OLD | NEW |