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 718 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 | 729 |
730 TestJSONStream stream; | 730 TestJSONStream stream; |
731 snapshot->Serialize(&stream, v8::HeapSnapshot::kJSON); | 731 snapshot->Serialize(&stream, v8::HeapSnapshot::kJSON); |
732 CHECK_GT(stream.size(), 0); | 732 CHECK_GT(stream.size(), 0); |
733 CHECK_EQ(1, stream.eos_signaled()); | 733 CHECK_EQ(1, stream.eos_signaled()); |
734 i::ScopedVector<char> json(stream.size()); | 734 i::ScopedVector<char> json(stream.size()); |
735 stream.WriteTo(json); | 735 stream.WriteTo(json); |
736 | 736 |
737 // Verify that snapshot string is valid JSON. | 737 // Verify that snapshot string is valid JSON. |
738 AsciiResource json_res(json); | 738 AsciiResource json_res(json); |
739 v8::Local<v8::String> json_string = v8::String::NewExternal(&json_res); | 739 v8::Local<v8::String> json_string = |
| 740 v8::String::NewExternal(env->GetIsolate(), &json_res); |
740 env->Global()->Set(v8_str("json_snapshot"), json_string); | 741 env->Global()->Set(v8_str("json_snapshot"), json_string); |
741 v8::Local<v8::Value> snapshot_parse_result = CompileRun( | 742 v8::Local<v8::Value> snapshot_parse_result = CompileRun( |
742 "var parsed = JSON.parse(json_snapshot); true;"); | 743 "var parsed = JSON.parse(json_snapshot); true;"); |
743 CHECK(!snapshot_parse_result.IsEmpty()); | 744 CHECK(!snapshot_parse_result.IsEmpty()); |
744 | 745 |
745 // Verify that snapshot object has required fields. | 746 // Verify that snapshot object has required fields. |
746 v8::Local<v8::Object> parsed_snapshot = | 747 v8::Local<v8::Object> parsed_snapshot = |
747 env->Global()->Get(v8_str("parsed"))->ToObject(); | 748 env->Global()->Get(v8_str("parsed"))->ToObject(); |
748 CHECK(parsed_snapshot->Has(v8_str("snapshot"))); | 749 CHECK(parsed_snapshot->Has(v8_str("snapshot"))); |
749 CHECK(parsed_snapshot->Has(v8_str("nodes"))); | 750 CHECK(parsed_snapshot->Has(v8_str("nodes"))); |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
997 // Single chunk of data with 0 left entries expected in update. | 998 // Single chunk of data with 0 left entries expected in update. |
998 TestStatsStream stats_update = GetHeapStatsUpdate(heap_profiler); | 999 TestStatsStream stats_update = GetHeapStatsUpdate(heap_profiler); |
999 CHECK_EQ(1, stats_update.intervals_count()); | 1000 CHECK_EQ(1, stats_update.intervals_count()); |
1000 CHECK_EQ(1, stats_update.updates_written()); | 1001 CHECK_EQ(1, stats_update.updates_written()); |
1001 CHECK_EQ(0, stats_update.entries_size()); | 1002 CHECK_EQ(0, stats_update.entries_size()); |
1002 CHECK_EQ(0, stats_update.entries_count()); | 1003 CHECK_EQ(0, stats_update.entries_count()); |
1003 // The only string from the second interval was released. | 1004 // The only string from the second interval was released. |
1004 CHECK_EQ(2, stats_update.first_interval_index()); | 1005 CHECK_EQ(2, stats_update.first_interval_index()); |
1005 } | 1006 } |
1006 | 1007 |
1007 v8::Local<v8::Array> array = v8::Array::New(); | 1008 v8::Local<v8::Array> array = v8::Array::New(env->GetIsolate()); |
1008 CHECK_EQ(0, array->Length()); | 1009 CHECK_EQ(0, array->Length()); |
1009 // Force array's buffer allocation. | 1010 // Force array's buffer allocation. |
1010 array->Set(2, v8_num(7)); | 1011 array->Set(2, v8_num(7)); |
1011 | 1012 |
1012 uint32_t entries_size; | 1013 uint32_t entries_size; |
1013 { | 1014 { |
1014 // Single chunk of data with 2 entries expected in update. | 1015 // Single chunk of data with 2 entries expected in update. |
1015 TestStatsStream stats_update = GetHeapStatsUpdate(heap_profiler); | 1016 TestStatsStream stats_update = GetHeapStatsUpdate(heap_profiler); |
1016 CHECK_EQ(1, stats_update.intervals_count()); | 1017 CHECK_EQ(1, stats_update.intervals_count()); |
1017 CHECK_EQ(1, stats_update.updates_written()); | 1018 CHECK_EQ(1, stats_update.updates_written()); |
(...skipping 996 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2014 GetProperty(foo_func, v8::HeapGraphEdge::kInternal, "code"); | 2015 GetProperty(foo_func, v8::HeapGraphEdge::kInternal, "code"); |
2015 CHECK_NE(NULL, code); | 2016 CHECK_NE(NULL, code); |
2016 } | 2017 } |
2017 | 2018 |
2018 | 2019 |
2019 | 2020 |
2020 class HeapProfilerExtension : public v8::Extension { | 2021 class HeapProfilerExtension : public v8::Extension { |
2021 public: | 2022 public: |
2022 static const char* kName; | 2023 static const char* kName; |
2023 HeapProfilerExtension() : v8::Extension(kName, kSource) { } | 2024 HeapProfilerExtension() : v8::Extension(kName, kSource) { } |
2024 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( | 2025 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunctionTemplate( |
| 2026 v8::Isolate* isolate, |
2025 v8::Handle<v8::String> name); | 2027 v8::Handle<v8::String> name); |
2026 static void FindUntrackedObjects( | 2028 static void FindUntrackedObjects( |
2027 const v8::FunctionCallbackInfo<v8::Value>& args); | 2029 const v8::FunctionCallbackInfo<v8::Value>& args); |
2028 private: | 2030 private: |
2029 static const char* kSource; | 2031 static const char* kSource; |
2030 }; | 2032 }; |
2031 | 2033 |
2032 const char* HeapProfilerExtension::kName = "v8/heap-profiler"; | 2034 const char* HeapProfilerExtension::kName = "v8/heap-profiler"; |
2033 | 2035 |
2034 | 2036 |
2035 const char* HeapProfilerExtension::kSource = | 2037 const char* HeapProfilerExtension::kSource = |
2036 "native function findUntrackedObjects();"; | 2038 "native function findUntrackedObjects();"; |
2037 | 2039 |
2038 | 2040 |
2039 v8::Handle<v8::FunctionTemplate> HeapProfilerExtension::GetNativeFunction( | 2041 v8::Handle<v8::FunctionTemplate> |
2040 v8::Handle<v8::String> name) { | 2042 HeapProfilerExtension::GetNativeFunctionTemplate(v8::Isolate* isolate, |
2041 if (name->Equals(v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), | 2043 v8::Handle<v8::String> name) { |
2042 "findUntrackedObjects"))) { | 2044 if (name->Equals(v8::String::NewFromUtf8(isolate, "findUntrackedObjects"))) { |
2043 return v8::FunctionTemplate::New( | 2045 return v8::FunctionTemplate::New( |
2044 HeapProfilerExtension::FindUntrackedObjects); | 2046 HeapProfilerExtension::FindUntrackedObjects); |
2045 } else { | 2047 } else { |
2046 CHECK(false); | 2048 CHECK(false); |
2047 return v8::Handle<v8::FunctionTemplate>(); | 2049 return v8::Handle<v8::FunctionTemplate>(); |
2048 } | 2050 } |
2049 } | 2051 } |
2050 | 2052 |
2051 | 2053 |
2052 void HeapProfilerExtension::FindUntrackedObjects( | 2054 void HeapProfilerExtension::FindUntrackedObjects( |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2307 | 2309 |
2308 AllocationTraceNode* node = | 2310 AllocationTraceNode* node = |
2309 FindNode(tracker, Vector<const char*>(names, ARRAY_SIZE(names))); | 2311 FindNode(tracker, Vector<const char*>(names, ARRAY_SIZE(names))); |
2310 CHECK_NE(NULL, node); | 2312 CHECK_NE(NULL, node); |
2311 CHECK_LT(node->allocation_count(), 100); | 2313 CHECK_LT(node->allocation_count(), 100); |
2312 | 2314 |
2313 CcTest::heap()->DisableInlineAllocation(); | 2315 CcTest::heap()->DisableInlineAllocation(); |
2314 heap_profiler->StopRecordingHeapAllocations(); | 2316 heap_profiler->StopRecordingHeapAllocations(); |
2315 } | 2317 } |
2316 } | 2318 } |
OLD | NEW |