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

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: Fix memory leak 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') | no next file with comments »
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 1735 matching lines...) Expand 10 before | Expand all | Expand 10 after
1823 return Local<String>(); 1826 return Local<String>();
1824 } 1827 }
1825 } 1828 }
1826 1829
1827 1830
1828 MaybeLocal<Value> Script::Run(Local<Context> context) { 1831 MaybeLocal<Value> Script::Run(Local<Context> context) {
1829 PREPARE_FOR_EXECUTION_WITH_CALLBACK(context, Script, Run, Value) 1832 PREPARE_FOR_EXECUTION_WITH_CALLBACK(context, Script, Run, Value)
1830 i::HistogramTimerScope execute_timer(isolate->counters()->execute(), true); 1833 i::HistogramTimerScope execute_timer(isolate->counters()->execute(), true);
1831 i::AggregatingHistogramTimerScope timer(isolate->counters()->compile_lazy()); 1834 i::AggregatingHistogramTimerScope timer(isolate->counters()->compile_lazy());
1832 i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate); 1835 i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate);
1833 TRACE_EVENT0("v8", "V8.Execute"); 1836 TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.Execute");
1834 auto fun = i::Handle<i::JSFunction>::cast(Utils::OpenHandle(this)); 1837 auto fun = i::Handle<i::JSFunction>::cast(Utils::OpenHandle(this));
1835 i::Handle<i::Object> receiver = isolate->global_proxy(); 1838 i::Handle<i::Object> receiver = isolate->global_proxy();
1836 Local<Value> result; 1839 Local<Value> result;
1837 has_pending_exception = 1840 has_pending_exception =
1838 !ToLocal<Value>(i::Execution::Call(isolate, fun, receiver, 0, NULL), 1841 !ToLocal<Value>(i::Execution::Call(isolate, fun, receiver, 0, NULL),
1839 &result); 1842 &result);
1840 RETURN_ON_FAILED_EXECUTION(Value); 1843 RETURN_ON_FAILED_EXECUTION(Value);
1841 RETURN_ESCAPED(result); 1844 RETURN_ESCAPED(result);
1842 } 1845 }
1843 1846
(...skipping 14 matching lines...) Expand all
1858 i::Handle<i::SharedFunctionInfo>(i::JSFunction::cast(*obj)->shared())); 1861 i::Handle<i::SharedFunctionInfo>(i::JSFunction::cast(*obj)->shared()));
1859 } 1862 }
1860 1863
1861 1864
1862 MaybeLocal<UnboundScript> ScriptCompiler::CompileUnboundInternal( 1865 MaybeLocal<UnboundScript> ScriptCompiler::CompileUnboundInternal(
1863 Isolate* v8_isolate, Source* source, CompileOptions options, 1866 Isolate* v8_isolate, Source* source, CompileOptions options,
1864 bool is_module) { 1867 bool is_module) {
1865 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); 1868 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
1866 PREPARE_FOR_EXECUTION_WITH_ISOLATE(isolate, ScriptCompiler, CompileUnbound, 1869 PREPARE_FOR_EXECUTION_WITH_ISOLATE(isolate, ScriptCompiler, CompileUnbound,
1867 UnboundScript); 1870 UnboundScript);
1868 TRACE_EVENT0("v8", "V8.ScriptCompiler"); 1871 TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.ScriptCompiler");
1869 1872
1870 // Don't try to produce any kind of cache when the debugger is loaded. 1873 // Don't try to produce any kind of cache when the debugger is loaded.
1871 if (isolate->debug()->is_loaded() && 1874 if (isolate->debug()->is_loaded() &&
1872 (options == kProduceParserCache || options == kProduceCodeCache)) { 1875 (options == kProduceParserCache || options == kProduceCodeCache)) {
1873 options = kNoCompileOptions; 1876 options = kNoCompileOptions;
1874 } 1877 }
1875 1878
1876 i::ScriptData* script_data = NULL; 1879 i::ScriptData* script_data = NULL;
1877 if (options == kConsumeParserCache || options == kConsumeCodeCache) { 1880 if (options == kConsumeParserCache || options == kConsumeCodeCache) {
1878 DCHECK(source->cached_data); 1881 DCHECK(source->cached_data);
(...skipping 2521 matching lines...) Expand 10 before | Expand all | Expand 10 after
4400 bool v8::Object::IsConstructor() { 4403 bool v8::Object::IsConstructor() {
4401 auto self = Utils::OpenHandle(this); 4404 auto self = Utils::OpenHandle(this);
4402 return self->IsConstructor(); 4405 return self->IsConstructor();
4403 } 4406 }
4404 4407
4405 MaybeLocal<Value> Object::CallAsFunction(Local<Context> context, 4408 MaybeLocal<Value> Object::CallAsFunction(Local<Context> context,
4406 Local<Value> recv, int argc, 4409 Local<Value> recv, int argc,
4407 Local<Value> argv[]) { 4410 Local<Value> argv[]) {
4408 PREPARE_FOR_EXECUTION_WITH_CALLBACK(context, Object, CallAsFunction, Value); 4411 PREPARE_FOR_EXECUTION_WITH_CALLBACK(context, Object, CallAsFunction, Value);
4409 i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate); 4412 i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate);
4410 TRACE_EVENT0("v8", "V8.Execute"); 4413 TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.Execute");
4411 auto self = Utils::OpenHandle(this); 4414 auto self = Utils::OpenHandle(this);
4412 auto recv_obj = Utils::OpenHandle(*recv); 4415 auto recv_obj = Utils::OpenHandle(*recv);
4413 STATIC_ASSERT(sizeof(v8::Local<v8::Value>) == sizeof(i::Object**)); 4416 STATIC_ASSERT(sizeof(v8::Local<v8::Value>) == sizeof(i::Object**));
4414 i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv); 4417 i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv);
4415 Local<Value> result; 4418 Local<Value> result;
4416 has_pending_exception = !ToLocal<Value>( 4419 has_pending_exception = !ToLocal<Value>(
4417 i::Execution::Call(isolate, self, recv_obj, argc, args), &result); 4420 i::Execution::Call(isolate, self, recv_obj, argc, args), &result);
4418 RETURN_ON_FAILED_EXECUTION(Value); 4421 RETURN_ON_FAILED_EXECUTION(Value);
4419 RETURN_ESCAPED(result); 4422 RETURN_ESCAPED(result);
4420 } 4423 }
4421 4424
4422 4425
4423 Local<v8::Value> Object::CallAsFunction(v8::Local<v8::Value> recv, int argc, 4426 Local<v8::Value> Object::CallAsFunction(v8::Local<v8::Value> recv, int argc,
4424 v8::Local<v8::Value> argv[]) { 4427 v8::Local<v8::Value> argv[]) {
4425 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); 4428 auto context = ContextFromHeapObject(Utils::OpenHandle(this));
4426 Local<Value>* argv_cast = reinterpret_cast<Local<Value>*>(argv); 4429 Local<Value>* argv_cast = reinterpret_cast<Local<Value>*>(argv);
4427 RETURN_TO_LOCAL_UNCHECKED(CallAsFunction(context, recv, argc, argv_cast), 4430 RETURN_TO_LOCAL_UNCHECKED(CallAsFunction(context, recv, argc, argv_cast),
4428 Value); 4431 Value);
4429 } 4432 }
4430 4433
4431 4434
4432 MaybeLocal<Value> Object::CallAsConstructor(Local<Context> context, int argc, 4435 MaybeLocal<Value> Object::CallAsConstructor(Local<Context> context, int argc,
4433 Local<Value> argv[]) { 4436 Local<Value> argv[]) {
4434 PREPARE_FOR_EXECUTION_WITH_CALLBACK(context, Object, CallAsConstructor, 4437 PREPARE_FOR_EXECUTION_WITH_CALLBACK(context, Object, CallAsConstructor,
4435 Value); 4438 Value);
4436 i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate); 4439 i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate);
4437 TRACE_EVENT0("v8", "V8.Execute"); 4440 TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.Execute");
4438 auto self = Utils::OpenHandle(this); 4441 auto self = Utils::OpenHandle(this);
4439 STATIC_ASSERT(sizeof(v8::Local<v8::Value>) == sizeof(i::Object**)); 4442 STATIC_ASSERT(sizeof(v8::Local<v8::Value>) == sizeof(i::Object**));
4440 i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv); 4443 i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv);
4441 Local<Value> result; 4444 Local<Value> result;
4442 has_pending_exception = !ToLocal<Value>( 4445 has_pending_exception = !ToLocal<Value>(
4443 i::Execution::New(isolate, self, self, argc, args), &result); 4446 i::Execution::New(isolate, self, self, argc, args), &result);
4444 RETURN_ON_FAILED_EXECUTION(Value); 4447 RETURN_ON_FAILED_EXECUTION(Value);
4445 RETURN_ESCAPED(result); 4448 RETURN_ESCAPED(result);
4446 } 4449 }
4447 4450
(...skipping 29 matching lines...) Expand all
4477 Local<v8::Object> Function::NewInstance() const { 4480 Local<v8::Object> Function::NewInstance() const {
4478 return NewInstance(Isolate::GetCurrent()->GetCurrentContext(), 0, NULL) 4481 return NewInstance(Isolate::GetCurrent()->GetCurrentContext(), 0, NULL)
4479 .FromMaybe(Local<Object>()); 4482 .FromMaybe(Local<Object>());
4480 } 4483 }
4481 4484
4482 4485
4483 MaybeLocal<Object> Function::NewInstance(Local<Context> context, int argc, 4486 MaybeLocal<Object> Function::NewInstance(Local<Context> context, int argc,
4484 v8::Local<v8::Value> argv[]) const { 4487 v8::Local<v8::Value> argv[]) const {
4485 PREPARE_FOR_EXECUTION_WITH_CALLBACK(context, Function, NewInstance, Object); 4488 PREPARE_FOR_EXECUTION_WITH_CALLBACK(context, Function, NewInstance, Object);
4486 i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate); 4489 i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate);
4487 TRACE_EVENT0("v8", "V8.Execute"); 4490 TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.Execute");
4488 auto self = Utils::OpenHandle(this); 4491 auto self = Utils::OpenHandle(this);
4489 STATIC_ASSERT(sizeof(v8::Local<v8::Value>) == sizeof(i::Object**)); 4492 STATIC_ASSERT(sizeof(v8::Local<v8::Value>) == sizeof(i::Object**));
4490 i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv); 4493 i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv);
4491 Local<Object> result; 4494 Local<Object> result;
4492 has_pending_exception = !ToLocal<Object>( 4495 has_pending_exception = !ToLocal<Object>(
4493 i::Execution::New(isolate, self, self, argc, args), &result); 4496 i::Execution::New(isolate, self, self, argc, args), &result);
4494 RETURN_ON_FAILED_EXECUTION(Object); 4497 RETURN_ON_FAILED_EXECUTION(Object);
4495 RETURN_ESCAPED(result); 4498 RETURN_ESCAPED(result);
4496 } 4499 }
4497 4500
4498 4501
4499 Local<v8::Object> Function::NewInstance(int argc, 4502 Local<v8::Object> Function::NewInstance(int argc,
4500 v8::Local<v8::Value> argv[]) const { 4503 v8::Local<v8::Value> argv[]) const {
4501 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); 4504 auto context = ContextFromHeapObject(Utils::OpenHandle(this));
4502 RETURN_TO_LOCAL_UNCHECKED(NewInstance(context, argc, argv), Object); 4505 RETURN_TO_LOCAL_UNCHECKED(NewInstance(context, argc, argv), Object);
4503 } 4506 }
4504 4507
4505 4508
4506 MaybeLocal<v8::Value> Function::Call(Local<Context> context, 4509 MaybeLocal<v8::Value> Function::Call(Local<Context> context,
4507 v8::Local<v8::Value> recv, int argc, 4510 v8::Local<v8::Value> recv, int argc,
4508 v8::Local<v8::Value> argv[]) { 4511 v8::Local<v8::Value> argv[]) {
4509 PREPARE_FOR_EXECUTION_WITH_CALLBACK(context, Function, Call, Value); 4512 PREPARE_FOR_EXECUTION_WITH_CALLBACK(context, Function, Call, Value);
4510 i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate); 4513 i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate);
4511 TRACE_EVENT0("v8", "V8.Execute"); 4514 TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.Execute");
4512 auto self = Utils::OpenHandle(this); 4515 auto self = Utils::OpenHandle(this);
4513 i::Handle<i::Object> recv_obj = Utils::OpenHandle(*recv); 4516 i::Handle<i::Object> recv_obj = Utils::OpenHandle(*recv);
4514 STATIC_ASSERT(sizeof(v8::Local<v8::Value>) == sizeof(i::Object**)); 4517 STATIC_ASSERT(sizeof(v8::Local<v8::Value>) == sizeof(i::Object**));
4515 i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv); 4518 i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv);
4516 Local<Value> result; 4519 Local<Value> result;
4517 has_pending_exception = !ToLocal<Value>( 4520 has_pending_exception = !ToLocal<Value>(
4518 i::Execution::Call(isolate, self, recv_obj, argc, args), &result); 4521 i::Execution::Call(isolate, self, recv_obj, argc, args), &result);
4519 RETURN_ON_FAILED_EXECUTION(Value); 4522 RETURN_ON_FAILED_EXECUTION(Value);
4520 RETURN_ESCAPED(result); 4523 RETURN_ESCAPED(result);
4521 } 4524 }
(...skipping 1177 matching lines...) Expand 10 before | Expand all | Expand 10 after
5699 return result; 5702 return result;
5700 } 5703 }
5701 5704
5702 Local<Context> NewContext(v8::Isolate* external_isolate, 5705 Local<Context> NewContext(v8::Isolate* external_isolate,
5703 v8::ExtensionConfiguration* extensions, 5706 v8::ExtensionConfiguration* extensions,
5704 v8::MaybeLocal<ObjectTemplate> global_template, 5707 v8::MaybeLocal<ObjectTemplate> global_template,
5705 v8::MaybeLocal<Value> global_object, 5708 v8::MaybeLocal<Value> global_object,
5706 size_t context_snapshot_index) { 5709 size_t context_snapshot_index) {
5707 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate); 5710 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate);
5708 LOG_API(isolate, Context, New); 5711 LOG_API(isolate, Context, New);
5712 TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.NewContext");
5709 i::HandleScope scope(isolate); 5713 i::HandleScope scope(isolate);
5710 ExtensionConfiguration no_extensions; 5714 ExtensionConfiguration no_extensions;
5711 if (extensions == NULL) extensions = &no_extensions; 5715 if (extensions == NULL) extensions = &no_extensions;
5712 i::Handle<i::Context> env = 5716 i::Handle<i::Context> env =
5713 CreateEnvironment<i::Context>(isolate, extensions, global_template, 5717 CreateEnvironment<i::Context>(isolate, extensions, global_template,
5714 global_object, context_snapshot_index); 5718 global_object, context_snapshot_index);
5715 if (env.is_null()) { 5719 if (env.is_null()) {
5716 if (isolate->has_pending_exception()) { 5720 if (isolate->has_pending_exception()) {
5717 isolate->OptionalRescheduleException(true); 5721 isolate->OptionalRescheduleException(true);
5718 } 5722 }
(...skipping 3242 matching lines...) Expand 10 before | Expand all | Expand 10 after
8961 8965
8962 8966
8963 void InvokeAccessorGetterCallback( 8967 void InvokeAccessorGetterCallback(
8964 v8::Local<v8::Name> property, 8968 v8::Local<v8::Name> property,
8965 const v8::PropertyCallbackInfo<v8::Value>& info, 8969 const v8::PropertyCallbackInfo<v8::Value>& info,
8966 v8::AccessorNameGetterCallback getter) { 8970 v8::AccessorNameGetterCallback getter) {
8967 // Leaving JavaScript. 8971 // Leaving JavaScript.
8968 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); 8972 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate());
8969 RuntimeCallTimerScope timer(isolate, 8973 RuntimeCallTimerScope timer(isolate,
8970 &RuntimeCallStats::AccessorGetterCallback); 8974 &RuntimeCallStats::AccessorGetterCallback);
8975 TRACE_EVENT_RUNTIME_CALL_STATS_TRACING_SCOPED(
8976 isolate,
8977 &internal::tracing::TraceEventStatsTable::AccessorGetterCallback);
8971 Address getter_address = reinterpret_cast<Address>(reinterpret_cast<intptr_t>( 8978 Address getter_address = reinterpret_cast<Address>(reinterpret_cast<intptr_t>(
8972 getter)); 8979 getter));
8973 VMState<EXTERNAL> state(isolate); 8980 VMState<EXTERNAL> state(isolate);
8974 ExternalCallbackScope call_scope(isolate, getter_address); 8981 ExternalCallbackScope call_scope(isolate, getter_address);
8975 getter(property, info); 8982 getter(property, info);
8976 } 8983 }
8977 8984
8978 8985
8979 void InvokeFunctionCallback(const v8::FunctionCallbackInfo<v8::Value>& info, 8986 void InvokeFunctionCallback(const v8::FunctionCallbackInfo<v8::Value>& info,
8980 v8::FunctionCallback callback) { 8987 v8::FunctionCallback callback) {
8981 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); 8988 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate());
8982 RuntimeCallTimerScope timer(isolate, 8989 RuntimeCallTimerScope timer(isolate,
8983 &RuntimeCallStats::InvokeFunctionCallback); 8990 &RuntimeCallStats::InvokeFunctionCallback);
8991 TRACE_EVENT_RUNTIME_CALL_STATS_TRACING_SCOPED(
8992 isolate,
8993 &internal::tracing::TraceEventStatsTable::InvokeFunctionCallback);
8984 Address callback_address = 8994 Address callback_address =
8985 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 8995 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
8986 VMState<EXTERNAL> state(isolate); 8996 VMState<EXTERNAL> state(isolate);
8987 ExternalCallbackScope call_scope(isolate, callback_address); 8997 ExternalCallbackScope call_scope(isolate, callback_address);
8988 callback(info); 8998 callback(info);
8989 } 8999 }
8990 9000
8991 9001
8992 } // namespace internal 9002 } // namespace internal
8993 } // namespace v8 9003 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/api-arguments.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698