Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: src/api.cc

Issue 2187693002: [Tracing] Embed V8 runtime call stats into tracing. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: update Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/api-arguments.cc » ('j') | src/builtins/builtins-utils.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "src/api.h" 5 #include "src/api.h"
6 6
7 #include <string.h> // For memcpy, strlen. 7 #include <string.h> // For memcpy, strlen.
8 #ifdef V8_USE_ADDRESS_SANITIZER 8 #ifdef V8_USE_ADDRESS_SANITIZER
9 #include <sanitizer/asan_interface.h> 9 #include <sanitizer/asan_interface.h>
10 #endif // V8_USE_ADDRESS_SANITIZER 10 #endif // V8_USE_ADDRESS_SANITIZER
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 #include "src/v8.h" 68 #include "src/v8.h"
69 #include "src/v8threads.h" 69 #include "src/v8threads.h"
70 #include "src/version.h" 70 #include "src/version.h"
71 #include "src/vm-state-inl.h" 71 #include "src/vm-state-inl.h"
72 72
73 namespace v8 { 73 namespace v8 {
74 74
75 #define LOG_API(isolate, class_name, function_name) \ 75 #define LOG_API(isolate, class_name, function_name) \
76 i::RuntimeCallTimerScope _runtime_timer( \ 76 i::RuntimeCallTimerScope _runtime_timer( \
77 isolate, &i::RuntimeCallStats::API_##class_name##_##function_name); \ 77 isolate, &i::RuntimeCallStats::API_##class_name##_##function_name); \
78 TRACE_EVENT_RUNTIME_CALL_STATS_TRACING_SCOPED( \
79 isolate, &internal::tracing::TraceEventStatsTable:: \
80 API_##class_name##_##function_name); \
78 LOG(isolate, ApiEntryCall("v8::" #class_name "::" #function_name)) 81 LOG(isolate, ApiEntryCall("v8::" #class_name "::" #function_name))
79 82
80 #define ENTER_V8(isolate) i::VMState<v8::OTHER> __state__((isolate)) 83 #define ENTER_V8(isolate) i::VMState<v8::OTHER> __state__((isolate))
81 84
82 #define PREPARE_FOR_EXECUTION_GENERIC(isolate, context, class_name, \ 85 #define PREPARE_FOR_EXECUTION_GENERIC(isolate, context, class_name, \
83 function_name, bailout_value, \ 86 function_name, bailout_value, \
84 HandleScopeClass, do_callback) \ 87 HandleScopeClass, do_callback) \
85 if (IsExecutionTerminatingCheck(isolate)) { \ 88 if (IsExecutionTerminatingCheck(isolate)) { \
86 return bailout_value; \ 89 return bailout_value; \
87 } \ 90 } \
(...skipping 1806 matching lines...) Expand 10 before | Expand all | Expand 10 after
1894 return Local<String>(); 1897 return Local<String>();
1895 } 1898 }
1896 } 1899 }
1897 1900
1898 1901
1899 MaybeLocal<Value> Script::Run(Local<Context> context) { 1902 MaybeLocal<Value> Script::Run(Local<Context> context) {
1900 PREPARE_FOR_EXECUTION_WITH_CALLBACK(context, Script, Run, Value) 1903 PREPARE_FOR_EXECUTION_WITH_CALLBACK(context, Script, Run, Value)
1901 i::HistogramTimerScope execute_timer(isolate->counters()->execute(), true); 1904 i::HistogramTimerScope execute_timer(isolate->counters()->execute(), true);
1902 i::AggregatingHistogramTimerScope timer(isolate->counters()->compile_lazy()); 1905 i::AggregatingHistogramTimerScope timer(isolate->counters()->compile_lazy());
1903 i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate); 1906 i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate);
1904 TRACE_EVENT0("v8", "V8.Execute"); 1907 TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.Execute");
1905 auto fun = i::Handle<i::JSFunction>::cast(Utils::OpenHandle(this)); 1908 auto fun = i::Handle<i::JSFunction>::cast(Utils::OpenHandle(this));
1906 i::Handle<i::Object> receiver = isolate->global_proxy(); 1909 i::Handle<i::Object> receiver = isolate->global_proxy();
1907 Local<Value> result; 1910 Local<Value> result;
1908 has_pending_exception = 1911 has_pending_exception =
1909 !ToLocal<Value>(i::Execution::Call(isolate, fun, receiver, 0, NULL), 1912 !ToLocal<Value>(i::Execution::Call(isolate, fun, receiver, 0, NULL),
1910 &result); 1913 &result);
1911 RETURN_ON_FAILED_EXECUTION(Value); 1914 RETURN_ON_FAILED_EXECUTION(Value);
1912 RETURN_ESCAPED(result); 1915 RETURN_ESCAPED(result);
1913 } 1916 }
1914 1917
(...skipping 14 matching lines...) Expand all
1929 i::Handle<i::SharedFunctionInfo>(i::JSFunction::cast(*obj)->shared())); 1932 i::Handle<i::SharedFunctionInfo>(i::JSFunction::cast(*obj)->shared()));
1930 } 1933 }
1931 1934
1932 1935
1933 MaybeLocal<UnboundScript> ScriptCompiler::CompileUnboundInternal( 1936 MaybeLocal<UnboundScript> ScriptCompiler::CompileUnboundInternal(
1934 Isolate* v8_isolate, Source* source, CompileOptions options, 1937 Isolate* v8_isolate, Source* source, CompileOptions options,
1935 bool is_module) { 1938 bool is_module) {
1936 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); 1939 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
1937 PREPARE_FOR_EXECUTION_WITH_ISOLATE(isolate, ScriptCompiler, CompileUnbound, 1940 PREPARE_FOR_EXECUTION_WITH_ISOLATE(isolate, ScriptCompiler, CompileUnbound,
1938 UnboundScript); 1941 UnboundScript);
1939 TRACE_EVENT0("v8", "V8.ScriptCompiler"); 1942 TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.ScriptCompiler");
1940 1943
1941 // Don't try to produce any kind of cache when the debugger is loaded. 1944 // Don't try to produce any kind of cache when the debugger is loaded.
1942 if (isolate->debug()->is_loaded() && 1945 if (isolate->debug()->is_loaded() &&
1943 (options == kProduceParserCache || options == kProduceCodeCache)) { 1946 (options == kProduceParserCache || options == kProduceCodeCache)) {
1944 options = kNoCompileOptions; 1947 options = kNoCompileOptions;
1945 } 1948 }
1946 1949
1947 i::ScriptData* script_data = NULL; 1950 i::ScriptData* script_data = NULL;
1948 if (options == kConsumeParserCache || options == kConsumeCodeCache) { 1951 if (options == kConsumeParserCache || options == kConsumeCodeCache) {
1949 DCHECK(source->cached_data); 1952 DCHECK(source->cached_data);
(...skipping 2523 matching lines...) Expand 10 before | Expand all | Expand 10 after
4473 bool v8::Object::IsConstructor() { 4476 bool v8::Object::IsConstructor() {
4474 auto self = Utils::OpenHandle(this); 4477 auto self = Utils::OpenHandle(this);
4475 return self->IsConstructor(); 4478 return self->IsConstructor();
4476 } 4479 }
4477 4480
4478 MaybeLocal<Value> Object::CallAsFunction(Local<Context> context, 4481 MaybeLocal<Value> Object::CallAsFunction(Local<Context> context,
4479 Local<Value> recv, int argc, 4482 Local<Value> recv, int argc,
4480 Local<Value> argv[]) { 4483 Local<Value> argv[]) {
4481 PREPARE_FOR_EXECUTION_WITH_CALLBACK(context, Object, CallAsFunction, Value); 4484 PREPARE_FOR_EXECUTION_WITH_CALLBACK(context, Object, CallAsFunction, Value);
4482 i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate); 4485 i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate);
4483 TRACE_EVENT0("v8", "V8.Execute"); 4486 TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.Execute");
4484 auto self = Utils::OpenHandle(this); 4487 auto self = Utils::OpenHandle(this);
4485 auto recv_obj = Utils::OpenHandle(*recv); 4488 auto recv_obj = Utils::OpenHandle(*recv);
4486 STATIC_ASSERT(sizeof(v8::Local<v8::Value>) == sizeof(i::Object**)); 4489 STATIC_ASSERT(sizeof(v8::Local<v8::Value>) == sizeof(i::Object**));
4487 i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv); 4490 i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv);
4488 Local<Value> result; 4491 Local<Value> result;
4489 has_pending_exception = !ToLocal<Value>( 4492 has_pending_exception = !ToLocal<Value>(
4490 i::Execution::Call(isolate, self, recv_obj, argc, args), &result); 4493 i::Execution::Call(isolate, self, recv_obj, argc, args), &result);
4491 RETURN_ON_FAILED_EXECUTION(Value); 4494 RETURN_ON_FAILED_EXECUTION(Value);
4492 RETURN_ESCAPED(result); 4495 RETURN_ESCAPED(result);
4493 } 4496 }
4494 4497
4495 4498
4496 Local<v8::Value> Object::CallAsFunction(v8::Local<v8::Value> recv, int argc, 4499 Local<v8::Value> Object::CallAsFunction(v8::Local<v8::Value> recv, int argc,
4497 v8::Local<v8::Value> argv[]) { 4500 v8::Local<v8::Value> argv[]) {
4498 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); 4501 auto context = ContextFromHeapObject(Utils::OpenHandle(this));
4499 Local<Value>* argv_cast = reinterpret_cast<Local<Value>*>(argv); 4502 Local<Value>* argv_cast = reinterpret_cast<Local<Value>*>(argv);
4500 RETURN_TO_LOCAL_UNCHECKED(CallAsFunction(context, recv, argc, argv_cast), 4503 RETURN_TO_LOCAL_UNCHECKED(CallAsFunction(context, recv, argc, argv_cast),
4501 Value); 4504 Value);
4502 } 4505 }
4503 4506
4504 4507
4505 MaybeLocal<Value> Object::CallAsConstructor(Local<Context> context, int argc, 4508 MaybeLocal<Value> Object::CallAsConstructor(Local<Context> context, int argc,
4506 Local<Value> argv[]) { 4509 Local<Value> argv[]) {
4507 PREPARE_FOR_EXECUTION_WITH_CALLBACK(context, Object, CallAsConstructor, 4510 PREPARE_FOR_EXECUTION_WITH_CALLBACK(context, Object, CallAsConstructor,
4508 Value); 4511 Value);
4509 i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate); 4512 i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate);
4510 TRACE_EVENT0("v8", "V8.Execute"); 4513 TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.Execute");
4511 auto self = Utils::OpenHandle(this); 4514 auto self = Utils::OpenHandle(this);
4512 STATIC_ASSERT(sizeof(v8::Local<v8::Value>) == sizeof(i::Object**)); 4515 STATIC_ASSERT(sizeof(v8::Local<v8::Value>) == sizeof(i::Object**));
4513 i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv); 4516 i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv);
4514 Local<Value> result; 4517 Local<Value> result;
4515 has_pending_exception = !ToLocal<Value>( 4518 has_pending_exception = !ToLocal<Value>(
4516 i::Execution::New(isolate, self, self, argc, args), &result); 4519 i::Execution::New(isolate, self, self, argc, args), &result);
4517 RETURN_ON_FAILED_EXECUTION(Value); 4520 RETURN_ON_FAILED_EXECUTION(Value);
4518 RETURN_ESCAPED(result); 4521 RETURN_ESCAPED(result);
4519 } 4522 }
4520 4523
(...skipping 29 matching lines...) Expand all
4550 Local<v8::Object> Function::NewInstance() const { 4553 Local<v8::Object> Function::NewInstance() const {
4551 return NewInstance(Isolate::GetCurrent()->GetCurrentContext(), 0, NULL) 4554 return NewInstance(Isolate::GetCurrent()->GetCurrentContext(), 0, NULL)
4552 .FromMaybe(Local<Object>()); 4555 .FromMaybe(Local<Object>());
4553 } 4556 }
4554 4557
4555 4558
4556 MaybeLocal<Object> Function::NewInstance(Local<Context> context, int argc, 4559 MaybeLocal<Object> Function::NewInstance(Local<Context> context, int argc,
4557 v8::Local<v8::Value> argv[]) const { 4560 v8::Local<v8::Value> argv[]) const {
4558 PREPARE_FOR_EXECUTION_WITH_CALLBACK(context, Function, NewInstance, Object); 4561 PREPARE_FOR_EXECUTION_WITH_CALLBACK(context, Function, NewInstance, Object);
4559 i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate); 4562 i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate);
4560 TRACE_EVENT0("v8", "V8.Execute"); 4563 TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.Execute");
4561 auto self = Utils::OpenHandle(this); 4564 auto self = Utils::OpenHandle(this);
4562 STATIC_ASSERT(sizeof(v8::Local<v8::Value>) == sizeof(i::Object**)); 4565 STATIC_ASSERT(sizeof(v8::Local<v8::Value>) == sizeof(i::Object**));
4563 i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv); 4566 i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv);
4564 Local<Object> result; 4567 Local<Object> result;
4565 has_pending_exception = !ToLocal<Object>( 4568 has_pending_exception = !ToLocal<Object>(
4566 i::Execution::New(isolate, self, self, argc, args), &result); 4569 i::Execution::New(isolate, self, self, argc, args), &result);
4567 RETURN_ON_FAILED_EXECUTION(Object); 4570 RETURN_ON_FAILED_EXECUTION(Object);
4568 RETURN_ESCAPED(result); 4571 RETURN_ESCAPED(result);
4569 } 4572 }
4570 4573
4571 4574
4572 Local<v8::Object> Function::NewInstance(int argc, 4575 Local<v8::Object> Function::NewInstance(int argc,
4573 v8::Local<v8::Value> argv[]) const { 4576 v8::Local<v8::Value> argv[]) const {
4574 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); 4577 auto context = ContextFromHeapObject(Utils::OpenHandle(this));
4575 RETURN_TO_LOCAL_UNCHECKED(NewInstance(context, argc, argv), Object); 4578 RETURN_TO_LOCAL_UNCHECKED(NewInstance(context, argc, argv), Object);
4576 } 4579 }
4577 4580
4578 4581
4579 MaybeLocal<v8::Value> Function::Call(Local<Context> context, 4582 MaybeLocal<v8::Value> Function::Call(Local<Context> context,
4580 v8::Local<v8::Value> recv, int argc, 4583 v8::Local<v8::Value> recv, int argc,
4581 v8::Local<v8::Value> argv[]) { 4584 v8::Local<v8::Value> argv[]) {
4582 PREPARE_FOR_EXECUTION_WITH_CALLBACK(context, Function, Call, Value); 4585 PREPARE_FOR_EXECUTION_WITH_CALLBACK(context, Function, Call, Value);
4583 i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate); 4586 i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate);
4584 TRACE_EVENT0("v8", "V8.Execute"); 4587 TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.Execute");
4585 auto self = Utils::OpenHandle(this); 4588 auto self = Utils::OpenHandle(this);
4586 i::Handle<i::Object> recv_obj = Utils::OpenHandle(*recv); 4589 i::Handle<i::Object> recv_obj = Utils::OpenHandle(*recv);
4587 STATIC_ASSERT(sizeof(v8::Local<v8::Value>) == sizeof(i::Object**)); 4590 STATIC_ASSERT(sizeof(v8::Local<v8::Value>) == sizeof(i::Object**));
4588 i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv); 4591 i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv);
4589 Local<Value> result; 4592 Local<Value> result;
4590 has_pending_exception = !ToLocal<Value>( 4593 has_pending_exception = !ToLocal<Value>(
4591 i::Execution::Call(isolate, self, recv_obj, argc, args), &result); 4594 i::Execution::Call(isolate, self, recv_obj, argc, args), &result);
4592 RETURN_ON_FAILED_EXECUTION(Value); 4595 RETURN_ON_FAILED_EXECUTION(Value);
4593 RETURN_ESCAPED(result); 4596 RETURN_ESCAPED(result);
4594 } 4597 }
(...skipping 1160 matching lines...) Expand 10 before | Expand all | Expand 10 after
5755 return result; 5758 return result;
5756 } 5759 }
5757 5760
5758 Local<Context> NewContext(v8::Isolate* external_isolate, 5761 Local<Context> NewContext(v8::Isolate* external_isolate,
5759 v8::ExtensionConfiguration* extensions, 5762 v8::ExtensionConfiguration* extensions,
5760 v8::MaybeLocal<ObjectTemplate> global_template, 5763 v8::MaybeLocal<ObjectTemplate> global_template,
5761 v8::MaybeLocal<Value> global_object, 5764 v8::MaybeLocal<Value> global_object,
5762 size_t context_snapshot_index) { 5765 size_t context_snapshot_index) {
5763 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate); 5766 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate);
5764 LOG_API(isolate, Context, New); 5767 LOG_API(isolate, Context, New);
5768 TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.NewContext");
5765 i::HandleScope scope(isolate); 5769 i::HandleScope scope(isolate);
5766 ExtensionConfiguration no_extensions; 5770 ExtensionConfiguration no_extensions;
5767 if (extensions == NULL) extensions = &no_extensions; 5771 if (extensions == NULL) extensions = &no_extensions;
5768 i::Handle<i::Context> env = 5772 i::Handle<i::Context> env =
5769 CreateEnvironment<i::Context>(isolate, extensions, global_template, 5773 CreateEnvironment<i::Context>(isolate, extensions, global_template,
5770 global_object, context_snapshot_index); 5774 global_object, context_snapshot_index);
5771 if (env.is_null()) { 5775 if (env.is_null()) {
5772 if (isolate->has_pending_exception()) { 5776 if (isolate->has_pending_exception()) {
5773 isolate->OptionalRescheduleException(true); 5777 isolate->OptionalRescheduleException(true);
5774 } 5778 }
(...skipping 3240 matching lines...) Expand 10 before | Expand all | Expand 10 after
9015 9019
9016 9020
9017 void InvokeAccessorGetterCallback( 9021 void InvokeAccessorGetterCallback(
9018 v8::Local<v8::Name> property, 9022 v8::Local<v8::Name> property,
9019 const v8::PropertyCallbackInfo<v8::Value>& info, 9023 const v8::PropertyCallbackInfo<v8::Value>& info,
9020 v8::AccessorNameGetterCallback getter) { 9024 v8::AccessorNameGetterCallback getter) {
9021 // Leaving JavaScript. 9025 // Leaving JavaScript.
9022 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); 9026 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate());
9023 RuntimeCallTimerScope timer(isolate, 9027 RuntimeCallTimerScope timer(isolate,
9024 &RuntimeCallStats::AccessorGetterCallback); 9028 &RuntimeCallStats::AccessorGetterCallback);
9029 TRACE_EVENT_RUNTIME_CALL_STATS_TRACING_SCOPED(
9030 isolate,
9031 &internal::tracing::TraceEventStatsTable::AccessorGetterCallback);
9025 Address getter_address = reinterpret_cast<Address>(reinterpret_cast<intptr_t>( 9032 Address getter_address = reinterpret_cast<Address>(reinterpret_cast<intptr_t>(
9026 getter)); 9033 getter));
9027 VMState<EXTERNAL> state(isolate); 9034 VMState<EXTERNAL> state(isolate);
9028 ExternalCallbackScope call_scope(isolate, getter_address); 9035 ExternalCallbackScope call_scope(isolate, getter_address);
9029 getter(property, info); 9036 getter(property, info);
9030 } 9037 }
9031 9038
9032 9039
9033 void InvokeFunctionCallback(const v8::FunctionCallbackInfo<v8::Value>& info, 9040 void InvokeFunctionCallback(const v8::FunctionCallbackInfo<v8::Value>& info,
9034 v8::FunctionCallback callback) { 9041 v8::FunctionCallback callback) {
9035 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); 9042 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate());
9036 RuntimeCallTimerScope timer(isolate, 9043 RuntimeCallTimerScope timer(isolate,
9037 &RuntimeCallStats::InvokeFunctionCallback); 9044 &RuntimeCallStats::InvokeFunctionCallback);
9045 TRACE_EVENT_RUNTIME_CALL_STATS_TRACING_SCOPED(
9046 isolate,
9047 &internal::tracing::TraceEventStatsTable::InvokeFunctionCallback);
9038 Address callback_address = 9048 Address callback_address =
9039 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 9049 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
9040 VMState<EXTERNAL> state(isolate); 9050 VMState<EXTERNAL> state(isolate);
9041 ExternalCallbackScope call_scope(isolate, callback_address); 9051 ExternalCallbackScope call_scope(isolate, callback_address);
9042 callback(info); 9052 callback(info);
9043 } 9053 }
9044 9054
9045 9055
9046 } // namespace internal 9056 } // namespace internal
9047 } // namespace v8 9057 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/api-arguments.cc » ('j') | src/builtins/builtins-utils.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698