OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <errno.h> | 5 #include <errno.h> |
6 #include <stdlib.h> | 6 #include <stdlib.h> |
7 #include <string.h> | 7 #include <string.h> |
8 #include <sys/stat.h> | 8 #include <sys/stat.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
11 #include <fstream> | 11 #include <fstream> |
12 #include <unordered_map> | 12 #include <unordered_map> |
13 #include <utility> | 13 #include <utility> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #ifdef ENABLE_VTUNE_JIT_INTERFACE | 16 #ifdef ENABLE_VTUNE_JIT_INTERFACE |
17 #include "src/third_party/vtune/v8-vtune.h" | 17 #include "src/third_party/vtune/v8-vtune.h" |
18 #endif | 18 #endif |
19 | 19 |
20 #include "src/d8.h" | 20 #include "src/d8.h" |
21 #include "src/ostreams.h" | 21 #include "src/ostreams.h" |
22 | 22 |
23 #include "include/libplatform/libplatform.h" | 23 #include "include/libplatform/libplatform.h" |
24 #include "include/libplatform/v8-tracing.h" | 24 #include "include/libplatform/v8-tracing.h" |
25 #include "include/v8-tracing.h" | |
26 #include "src/api.h" | 25 #include "src/api.h" |
27 #include "src/base/cpu.h" | 26 #include "src/base/cpu.h" |
28 #include "src/base/debug/stack_trace.h" | 27 #include "src/base/debug/stack_trace.h" |
29 #include "src/base/logging.h" | 28 #include "src/base/logging.h" |
30 #include "src/base/platform/platform.h" | 29 #include "src/base/platform/platform.h" |
31 #include "src/base/sys-info.h" | 30 #include "src/base/sys-info.h" |
32 #include "src/basic-block-profiler.h" | 31 #include "src/basic-block-profiler.h" |
33 #include "src/interpreter/interpreter.h" | 32 #include "src/interpreter/interpreter.h" |
34 #include "src/snapshot/natives.h" | 33 #include "src/snapshot/natives.h" |
35 #include "src/utils.h" | 34 #include "src/utils.h" |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 } | 145 } |
147 | 146 |
148 private: | 147 private: |
149 double synthetic_time_in_sec_ = 0.0; | 148 double synthetic_time_in_sec_ = 0.0; |
150 | 149 |
151 DISALLOW_COPY_AND_ASSIGN(PredictablePlatform); | 150 DISALLOW_COPY_AND_ASSIGN(PredictablePlatform); |
152 }; | 151 }; |
153 | 152 |
154 | 153 |
155 v8::Platform* g_platform = NULL; | 154 v8::Platform* g_platform = NULL; |
156 std::unique_ptr<tracing::TracingCategoryObserver> g_tracing_category_observer; | |
157 | 155 |
158 static Local<Value> Throw(Isolate* isolate, const char* message) { | 156 static Local<Value> Throw(Isolate* isolate, const char* message) { |
159 return isolate->ThrowException( | 157 return isolate->ThrowException( |
160 String::NewFromUtf8(isolate, message, NewStringType::kNormal) | 158 String::NewFromUtf8(isolate, message, NewStringType::kNormal) |
161 .ToLocalChecked()); | 159 .ToLocalChecked()); |
162 } | 160 } |
163 | 161 |
164 | 162 |
165 bool FindInObjectList(Local<Object> object, const Shell::ObjectList& list) { | 163 bool FindInObjectList(Local<Object> object, const Shell::ObjectList& list) { |
166 for (int i = 0; i < list.length(); ++i) { | 164 for (int i = 0; i < list.length(); ++i) { |
(...skipping 2649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2816 _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); | 2814 _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); |
2817 _set_error_mode(_OUT_TO_STDERR); | 2815 _set_error_mode(_OUT_TO_STDERR); |
2818 #endif // defined(_MSC_VER) | 2816 #endif // defined(_MSC_VER) |
2819 #endif // defined(_WIN32) || defined(_WIN64) | 2817 #endif // defined(_WIN32) || defined(_WIN64) |
2820 if (!SetOptions(argc, argv)) return 1; | 2818 if (!SetOptions(argc, argv)) return 1; |
2821 v8::V8::InitializeICUDefaultLocation(argv[0], options.icu_data_file); | 2819 v8::V8::InitializeICUDefaultLocation(argv[0], options.icu_data_file); |
2822 g_platform = i::FLAG_verify_predictable | 2820 g_platform = i::FLAG_verify_predictable |
2823 ? new PredictablePlatform() | 2821 ? new PredictablePlatform() |
2824 : v8::platform::CreateDefaultPlatform(); | 2822 : v8::platform::CreateDefaultPlatform(); |
2825 | 2823 |
2824 platform::tracing::TracingController* tracing_controller = nullptr; | |
2825 if (options.trace_enabled) { | |
2826 trace_file.open("v8_trace.json"); | |
2827 tracing_controller = new platform::tracing::TracingController(); | |
2828 platform::tracing::TraceBuffer* trace_buffer = | |
2829 platform::tracing::TraceBuffer::CreateTraceBufferRingBuffer( | |
2830 platform::tracing::TraceBuffer::kRingBufferChunks, | |
2831 platform::tracing::TraceWriter::CreateJSONTraceWriter(trace_file)); | |
2832 tracing_controller->Initialize(trace_buffer); | |
2833 if (!i::FLAG_verify_predictable) { | |
2834 platform::SetTracingController(g_platform, tracing_controller); | |
alph
2016/11/02 20:18:23
who is responsible for deleting tracing_controller
lpy
2016/11/02 21:52:27
Done.
| |
2835 } | |
2836 } | |
2837 | |
2826 v8::V8::InitializePlatform(g_platform); | 2838 v8::V8::InitializePlatform(g_platform); |
2827 v8::V8::Initialize(); | 2839 v8::V8::Initialize(); |
2828 if (options.natives_blob || options.snapshot_blob) { | 2840 if (options.natives_blob || options.snapshot_blob) { |
2829 v8::V8::InitializeExternalStartupData(options.natives_blob, | 2841 v8::V8::InitializeExternalStartupData(options.natives_blob, |
2830 options.snapshot_blob); | 2842 options.snapshot_blob); |
2831 } else { | 2843 } else { |
2832 v8::V8::InitializeExternalStartupData(argv[0]); | 2844 v8::V8::InitializeExternalStartupData(argv[0]); |
2833 } | 2845 } |
2834 SetFlagsFromString("--trace-hydrogen-file=hydrogen.cfg"); | 2846 SetFlagsFromString("--trace-hydrogen-file=hydrogen.cfg"); |
2835 SetFlagsFromString("--trace-turbo-cfg-file=turbo.cfg"); | 2847 SetFlagsFromString("--trace-turbo-cfg-file=turbo.cfg"); |
(...skipping 14 matching lines...) Expand all Loading... | |
2850 create_params.constraints.ConfigureDefaults( | 2862 create_params.constraints.ConfigureDefaults( |
2851 base::SysInfo::AmountOfPhysicalMemory(), | 2863 base::SysInfo::AmountOfPhysicalMemory(), |
2852 base::SysInfo::AmountOfVirtualMemory()); | 2864 base::SysInfo::AmountOfVirtualMemory()); |
2853 | 2865 |
2854 Shell::counter_map_ = new CounterMap(); | 2866 Shell::counter_map_ = new CounterMap(); |
2855 if (i::FLAG_dump_counters || i::FLAG_track_gc_object_stats) { | 2867 if (i::FLAG_dump_counters || i::FLAG_track_gc_object_stats) { |
2856 create_params.counter_lookup_callback = LookupCounter; | 2868 create_params.counter_lookup_callback = LookupCounter; |
2857 create_params.create_histogram_callback = CreateHistogram; | 2869 create_params.create_histogram_callback = CreateHistogram; |
2858 create_params.add_histogram_sample_callback = AddHistogramSample; | 2870 create_params.add_histogram_sample_callback = AddHistogramSample; |
2859 } | 2871 } |
2872 | |
2860 Isolate* isolate = Isolate::New(create_params); | 2873 Isolate* isolate = Isolate::New(create_params); |
2861 { | 2874 { |
2862 Isolate::Scope scope(isolate); | 2875 Isolate::Scope scope(isolate); |
2863 Initialize(isolate); | 2876 Initialize(isolate); |
2864 PerIsolateData data(isolate); | 2877 PerIsolateData data(isolate); |
2865 | 2878 |
2866 if (options.trace_enabled) { | 2879 if (options.trace_enabled) { |
2867 trace_file.open("v8_trace.json"); | |
2868 platform::tracing::TracingController* tracing_controller = | |
2869 new platform::tracing::TracingController(); | |
2870 platform::tracing::TraceBuffer* trace_buffer = | |
2871 platform::tracing::TraceBuffer::CreateTraceBufferRingBuffer( | |
2872 platform::tracing::TraceBuffer::kRingBufferChunks, | |
2873 platform::tracing::TraceWriter::CreateJSONTraceWriter( | |
2874 trace_file)); | |
2875 platform::tracing::TraceConfig* trace_config; | 2880 platform::tracing::TraceConfig* trace_config; |
2876 if (options.trace_config) { | 2881 if (options.trace_config) { |
2877 int size = 0; | 2882 int size = 0; |
2878 char* trace_config_json_str = | 2883 char* trace_config_json_str = |
2879 ReadChars(nullptr, options.trace_config, &size); | 2884 ReadChars(nullptr, options.trace_config, &size); |
2880 trace_config = | 2885 trace_config = |
2881 tracing::CreateTraceConfigFromJSON(isolate, trace_config_json_str); | 2886 tracing::CreateTraceConfigFromJSON(isolate, trace_config_json_str); |
2882 delete[] trace_config_json_str; | 2887 delete[] trace_config_json_str; |
2883 } else { | 2888 } else { |
2884 trace_config = | 2889 trace_config = |
2885 platform::tracing::TraceConfig::CreateDefaultTraceConfig(); | 2890 platform::tracing::TraceConfig::CreateDefaultTraceConfig(); |
2886 } | 2891 } |
2887 tracing_controller->Initialize(trace_buffer); | |
2888 if (!i::FLAG_verify_predictable) { | |
2889 platform::SetTracingController(g_platform, tracing_controller); | |
2890 } | |
2891 g_tracing_category_observer = tracing::TracingCategoryObserver::Create(); | |
2892 g_platform->AddTraceStateObserver( | |
2893 reinterpret_cast<Platform::TraceStateObserver*>( | |
2894 g_tracing_category_observer.get())); | |
2895 tracing_controller->StartTracing(trace_config); | 2892 tracing_controller->StartTracing(trace_config); |
2896 } | 2893 } |
2897 | 2894 |
2898 if (options.dump_heap_constants) { | 2895 if (options.dump_heap_constants) { |
2899 DumpHeapConstants(reinterpret_cast<i::Isolate*>(isolate)); | 2896 DumpHeapConstants(reinterpret_cast<i::Isolate*>(isolate)); |
2900 return 0; | 2897 return 0; |
2901 } | 2898 } |
2902 | 2899 |
2903 if (options.stress_opt || options.stress_deopt) { | 2900 if (options.stress_opt || options.stress_deopt) { |
2904 Testing::SetStressRunType(options.stress_opt | 2901 Testing::SetStressRunType(options.stress_opt |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2946 OnExit(isolate); | 2943 OnExit(isolate); |
2947 // Dump basic block profiling data. | 2944 // Dump basic block profiling data. |
2948 if (i::BasicBlockProfiler* profiler = | 2945 if (i::BasicBlockProfiler* profiler = |
2949 reinterpret_cast<i::Isolate*>(isolate)->basic_block_profiler()) { | 2946 reinterpret_cast<i::Isolate*>(isolate)->basic_block_profiler()) { |
2950 i::OFStream os(stdout); | 2947 i::OFStream os(stdout); |
2951 os << *profiler; | 2948 os << *profiler; |
2952 } | 2949 } |
2953 isolate->Dispose(); | 2950 isolate->Dispose(); |
2954 V8::Dispose(); | 2951 V8::Dispose(); |
2955 V8::ShutdownPlatform(); | 2952 V8::ShutdownPlatform(); |
2956 g_platform->RemoveTraceStateObserver( | |
2957 reinterpret_cast<Platform::TraceStateObserver*>( | |
2958 g_tracing_category_observer.get())); | |
2959 delete g_platform; | 2953 delete g_platform; |
2960 | 2954 |
2961 return result; | 2955 return result; |
2962 } | 2956 } |
2963 | 2957 |
2964 } // namespace v8 | 2958 } // namespace v8 |
2965 | 2959 |
2966 | 2960 |
2967 #ifndef GOOGLE3 | 2961 #ifndef GOOGLE3 |
2968 int main(int argc, char* argv[]) { | 2962 int main(int argc, char* argv[]) { |
2969 return v8::Shell::Main(argc, argv); | 2963 return v8::Shell::Main(argc, argv); |
2970 } | 2964 } |
2971 #endif | 2965 #endif |
OLD | NEW |