Chromium Code Reviews| 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 std::unique_ptr<platform::tracing::TracingController> tracing_controller; | |
| 2825 if (options.trace_enabled) { | |
| 2826 trace_file.open("v8_trace.json"); | |
| 2827 tracing_controller.reset(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.get()); | |
|
alph
2016/11/03 20:19:27
you can use release right here. it returns raw poi
| |
| 2835 tracing_controller.release(); | |
| 2836 } | |
| 2837 } | |
| 2838 | |
| 2826 v8::V8::InitializePlatform(g_platform); | 2839 v8::V8::InitializePlatform(g_platform); |
| 2827 v8::V8::Initialize(); | 2840 v8::V8::Initialize(); |
| 2828 if (options.natives_blob || options.snapshot_blob) { | 2841 if (options.natives_blob || options.snapshot_blob) { |
| 2829 v8::V8::InitializeExternalStartupData(options.natives_blob, | 2842 v8::V8::InitializeExternalStartupData(options.natives_blob, |
| 2830 options.snapshot_blob); | 2843 options.snapshot_blob); |
| 2831 } else { | 2844 } else { |
| 2832 v8::V8::InitializeExternalStartupData(argv[0]); | 2845 v8::V8::InitializeExternalStartupData(argv[0]); |
| 2833 } | 2846 } |
| 2834 SetFlagsFromString("--trace-hydrogen-file=hydrogen.cfg"); | 2847 SetFlagsFromString("--trace-hydrogen-file=hydrogen.cfg"); |
| 2835 SetFlagsFromString("--trace-turbo-cfg-file=turbo.cfg"); | 2848 SetFlagsFromString("--trace-turbo-cfg-file=turbo.cfg"); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 2850 create_params.constraints.ConfigureDefaults( | 2863 create_params.constraints.ConfigureDefaults( |
| 2851 base::SysInfo::AmountOfPhysicalMemory(), | 2864 base::SysInfo::AmountOfPhysicalMemory(), |
| 2852 base::SysInfo::AmountOfVirtualMemory()); | 2865 base::SysInfo::AmountOfVirtualMemory()); |
| 2853 | 2866 |
| 2854 Shell::counter_map_ = new CounterMap(); | 2867 Shell::counter_map_ = new CounterMap(); |
| 2855 if (i::FLAG_dump_counters || i::FLAG_track_gc_object_stats) { | 2868 if (i::FLAG_dump_counters || i::FLAG_track_gc_object_stats) { |
| 2856 create_params.counter_lookup_callback = LookupCounter; | 2869 create_params.counter_lookup_callback = LookupCounter; |
| 2857 create_params.create_histogram_callback = CreateHistogram; | 2870 create_params.create_histogram_callback = CreateHistogram; |
| 2858 create_params.add_histogram_sample_callback = AddHistogramSample; | 2871 create_params.add_histogram_sample_callback = AddHistogramSample; |
| 2859 } | 2872 } |
| 2873 | |
| 2860 Isolate* isolate = Isolate::New(create_params); | 2874 Isolate* isolate = Isolate::New(create_params); |
| 2861 { | 2875 { |
| 2862 Isolate::Scope scope(isolate); | 2876 Isolate::Scope scope(isolate); |
| 2863 Initialize(isolate); | 2877 Initialize(isolate); |
| 2864 PerIsolateData data(isolate); | 2878 PerIsolateData data(isolate); |
| 2865 | 2879 |
| 2866 if (options.trace_enabled) { | 2880 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; | 2881 platform::tracing::TraceConfig* trace_config; |
| 2876 if (options.trace_config) { | 2882 if (options.trace_config) { |
| 2877 int size = 0; | 2883 int size = 0; |
| 2878 char* trace_config_json_str = | 2884 char* trace_config_json_str = |
| 2879 ReadChars(nullptr, options.trace_config, &size); | 2885 ReadChars(nullptr, options.trace_config, &size); |
| 2880 trace_config = | 2886 trace_config = |
| 2881 tracing::CreateTraceConfigFromJSON(isolate, trace_config_json_str); | 2887 tracing::CreateTraceConfigFromJSON(isolate, trace_config_json_str); |
| 2882 delete[] trace_config_json_str; | 2888 delete[] trace_config_json_str; |
| 2883 } else { | 2889 } else { |
| 2884 trace_config = | 2890 trace_config = |
| 2885 platform::tracing::TraceConfig::CreateDefaultTraceConfig(); | 2891 platform::tracing::TraceConfig::CreateDefaultTraceConfig(); |
| 2886 } | 2892 } |
| 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); | 2893 tracing_controller->StartTracing(trace_config); |
| 2896 } | 2894 } |
| 2897 | 2895 |
| 2898 if (options.dump_heap_constants) { | 2896 if (options.dump_heap_constants) { |
| 2899 DumpHeapConstants(reinterpret_cast<i::Isolate*>(isolate)); | 2897 DumpHeapConstants(reinterpret_cast<i::Isolate*>(isolate)); |
| 2900 return 0; | 2898 return 0; |
| 2901 } | 2899 } |
| 2902 | 2900 |
| 2903 if (options.stress_opt || options.stress_deopt) { | 2901 if (options.stress_opt || options.stress_deopt) { |
| 2904 Testing::SetStressRunType(options.stress_opt | 2902 Testing::SetStressRunType(options.stress_opt |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2946 OnExit(isolate); | 2944 OnExit(isolate); |
| 2947 // Dump basic block profiling data. | 2945 // Dump basic block profiling data. |
| 2948 if (i::BasicBlockProfiler* profiler = | 2946 if (i::BasicBlockProfiler* profiler = |
| 2949 reinterpret_cast<i::Isolate*>(isolate)->basic_block_profiler()) { | 2947 reinterpret_cast<i::Isolate*>(isolate)->basic_block_profiler()) { |
| 2950 i::OFStream os(stdout); | 2948 i::OFStream os(stdout); |
| 2951 os << *profiler; | 2949 os << *profiler; |
| 2952 } | 2950 } |
| 2953 isolate->Dispose(); | 2951 isolate->Dispose(); |
| 2954 V8::Dispose(); | 2952 V8::Dispose(); |
| 2955 V8::ShutdownPlatform(); | 2953 V8::ShutdownPlatform(); |
| 2956 g_platform->RemoveTraceStateObserver( | |
| 2957 reinterpret_cast<Platform::TraceStateObserver*>( | |
| 2958 g_tracing_category_observer.get())); | |
| 2959 delete g_platform; | 2954 delete g_platform; |
| 2960 | 2955 |
| 2961 return result; | 2956 return result; |
| 2962 } | 2957 } |
| 2963 | 2958 |
| 2964 } // namespace v8 | 2959 } // namespace v8 |
| 2965 | 2960 |
| 2966 | 2961 |
| 2967 #ifndef GOOGLE3 | 2962 #ifndef GOOGLE3 |
| 2968 int main(int argc, char* argv[]) { | 2963 int main(int argc, char* argv[]) { |
| 2969 return v8::Shell::Main(argc, argv); | 2964 return v8::Shell::Main(argc, argv); |
| 2970 } | 2965 } |
| 2971 #endif | 2966 #endif |
| OLD | NEW |