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

Side by Side Diff: src/api.cc

Issue 1686233002: Add Scoped Context Info (Isolate) to V8 Traces (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Simplify the test Created 4 years, 10 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 | « include/v8-platform.h ('k') | src/d8.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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 #include "src/property.h" 51 #include "src/property.h"
52 #include "src/property-descriptor.h" 52 #include "src/property-descriptor.h"
53 #include "src/property-details.h" 53 #include "src/property-details.h"
54 #include "src/prototype.h" 54 #include "src/prototype.h"
55 #include "src/runtime/runtime.h" 55 #include "src/runtime/runtime.h"
56 #include "src/runtime-profiler.h" 56 #include "src/runtime-profiler.h"
57 #include "src/simulator.h" 57 #include "src/simulator.h"
58 #include "src/snapshot/natives.h" 58 #include "src/snapshot/natives.h"
59 #include "src/snapshot/snapshot.h" 59 #include "src/snapshot/snapshot.h"
60 #include "src/startup-data-util.h" 60 #include "src/startup-data-util.h"
61 #include "src/tracing/trace-event.h"
61 #include "src/unicode-inl.h" 62 #include "src/unicode-inl.h"
62 #include "src/v8.h" 63 #include "src/v8.h"
63 #include "src/v8threads.h" 64 #include "src/v8threads.h"
64 #include "src/version.h" 65 #include "src/version.h"
65 #include "src/vm-state-inl.h" 66 #include "src/vm-state-inl.h"
66 67
67 68
68 namespace v8 { 69 namespace v8 {
69 70
70 #define LOG_API(isolate, expr) LOG(isolate, ApiEntryCall(expr)) 71 #define LOG_API(isolate, expr) LOG(isolate, ApiEntryCall(expr))
71 72
72 73
73 #define ENTER_V8(isolate) i::VMState<v8::OTHER> __state__((isolate)) 74 #define ENTER_V8(isolate) i::VMState<v8::OTHER> __state__((isolate))
74 75
75 76
76 #define PREPARE_FOR_EXECUTION_GENERIC(isolate, context, function_name, \ 77 #define PREPARE_FOR_EXECUTION_GENERIC(isolate, context, function_name, \
77 bailout_value, HandleScopeClass, \ 78 bailout_value, HandleScopeClass, \
78 do_callback) \ 79 do_callback) \
79 if (IsExecutionTerminatingCheck(isolate)) { \ 80 if (IsExecutionTerminatingCheck(isolate)) { \
80 return bailout_value; \ 81 return bailout_value; \
81 } \ 82 } \
83 TRACE_EVENT_SCOPED_CONTEXT("v8", "Isolate", isolate); \
82 HandleScopeClass handle_scope(isolate); \ 84 HandleScopeClass handle_scope(isolate); \
83 CallDepthScope call_depth_scope(isolate, context, do_callback); \ 85 CallDepthScope call_depth_scope(isolate, context, do_callback); \
84 LOG_API(isolate, function_name); \ 86 LOG_API(isolate, function_name); \
85 ENTER_V8(isolate); \ 87 ENTER_V8(isolate); \
86 bool has_pending_exception = false 88 bool has_pending_exception = false
87 89
88 90
89 #define PREPARE_FOR_EXECUTION_WITH_CONTEXT( \ 91 #define PREPARE_FOR_EXECUTION_WITH_CONTEXT( \
90 context, function_name, bailout_value, HandleScopeClass, do_callback) \ 92 context, function_name, bailout_value, HandleScopeClass, do_callback) \
91 auto isolate = context.IsEmpty() \ 93 auto isolate = context.IsEmpty() \
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 Local<Context> context_; 190 Local<Context> context_;
189 bool escaped_; 191 bool escaped_;
190 bool do_callback_; 192 bool do_callback_;
191 }; 193 };
192 194
193 } // namespace 195 } // namespace
194 196
195 197
196 static ScriptOrigin GetScriptOriginForScript(i::Isolate* isolate, 198 static ScriptOrigin GetScriptOriginForScript(i::Isolate* isolate,
197 i::Handle<i::Script> script) { 199 i::Handle<i::Script> script) {
200 TRACE_EVENT_SCOPED_CONTEXT("v8", "Isolate", isolate);
198 i::Handle<i::Object> scriptName(i::Script::GetNameOrSourceURL(script)); 201 i::Handle<i::Object> scriptName(i::Script::GetNameOrSourceURL(script));
199 i::Handle<i::Object> source_map_url(script->source_mapping_url(), isolate); 202 i::Handle<i::Object> source_map_url(script->source_mapping_url(), isolate);
200 v8::Isolate* v8_isolate = 203 v8::Isolate* v8_isolate =
201 reinterpret_cast<v8::Isolate*>(script->GetIsolate()); 204 reinterpret_cast<v8::Isolate*>(script->GetIsolate());
202 ScriptOriginOptions options(script->origin_options()); 205 ScriptOriginOptions options(script->origin_options());
203 v8::ScriptOrigin origin( 206 v8::ScriptOrigin origin(
204 Utils::ToLocal(scriptName), 207 Utils::ToLocal(scriptName),
205 v8::Integer::New(v8_isolate, script->line_offset()), 208 v8::Integer::New(v8_isolate, script->line_offset()),
206 v8::Integer::New(v8_isolate, script->column_offset()), 209 v8::Integer::New(v8_isolate, script->column_offset()),
207 v8::Boolean::New(v8_isolate, options.IsSharedCrossOrigin()), 210 v8::Boolean::New(v8_isolate, options.IsSharedCrossOrigin()),
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 }; 369 };
367 370
368 } // namespace 371 } // namespace
369 372
370 373
371 StartupData V8::CreateSnapshotDataBlob(const char* custom_source) { 374 StartupData V8::CreateSnapshotDataBlob(const char* custom_source) {
372 i::Isolate* internal_isolate = new i::Isolate(true); 375 i::Isolate* internal_isolate = new i::Isolate(true);
373 ArrayBufferAllocator allocator; 376 ArrayBufferAllocator allocator;
374 internal_isolate->set_array_buffer_allocator(&allocator); 377 internal_isolate->set_array_buffer_allocator(&allocator);
375 Isolate* isolate = reinterpret_cast<Isolate*>(internal_isolate); 378 Isolate* isolate = reinterpret_cast<Isolate*>(internal_isolate);
379 TRACE_EVENT_SCOPED_CONTEXT("v8", "Isolate", isolate);
376 StartupData result = {NULL, 0}; 380 StartupData result = {NULL, 0};
377 { 381 {
378 base::ElapsedTimer timer; 382 base::ElapsedTimer timer;
379 timer.Start(); 383 timer.Start();
380 Isolate::Scope isolate_scope(isolate); 384 Isolate::Scope isolate_scope(isolate);
381 internal_isolate->Init(NULL); 385 internal_isolate->Init(NULL);
382 Persistent<Context> context; 386 Persistent<Context> context;
383 i::Snapshot::Metadata metadata; 387 i::Snapshot::Metadata metadata;
384 { 388 {
385 HandleScope handle_scope(isolate); 389 HandleScope handle_scope(isolate);
(...skipping 1457 matching lines...) Expand 10 before | Expand all | Expand 10 after
1843 auto context = v8_isolate->GetCurrentContext(); 1847 auto context = v8_isolate->GetCurrentContext();
1844 RETURN_TO_LOCAL_UNCHECKED(Compile(context, source, options), Script); 1848 RETURN_TO_LOCAL_UNCHECKED(Compile(context, source, options), Script);
1845 } 1849 }
1846 1850
1847 1851
1848 MaybeLocal<Script> ScriptCompiler::CompileModule(Local<Context> context, 1852 MaybeLocal<Script> ScriptCompiler::CompileModule(Local<Context> context,
1849 Source* source, 1853 Source* source,
1850 CompileOptions options) { 1854 CompileOptions options) {
1851 CHECK(i::FLAG_harmony_modules); 1855 CHECK(i::FLAG_harmony_modules);
1852 auto isolate = context->GetIsolate(); 1856 auto isolate = context->GetIsolate();
1857 TRACE_EVENT_SCOPED_CONTEXT("V8", "Isolate", isolate);
1853 auto maybe = CompileUnboundInternal(isolate, source, options, true); 1858 auto maybe = CompileUnboundInternal(isolate, source, options, true);
1854 Local<UnboundScript> generic; 1859 Local<UnboundScript> generic;
1855 if (!maybe.ToLocal(&generic)) return MaybeLocal<Script>(); 1860 if (!maybe.ToLocal(&generic)) return MaybeLocal<Script>();
1856 v8::Context::Scope scope(context); 1861 v8::Context::Scope scope(context);
1857 return generic->BindToCurrentContext(); 1862 return generic->BindToCurrentContext();
1858 } 1863 }
1859 1864
1860 1865
1861 class IsIdentifierHelper { 1866 class IsIdentifierHelper {
1862 public: 1867 public:
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
2269 void v8::TryCatch::SetCaptureMessage(bool value) { 2274 void v8::TryCatch::SetCaptureMessage(bool value) {
2270 capture_message_ = value; 2275 capture_message_ = value;
2271 } 2276 }
2272 2277
2273 2278
2274 // --- M e s s a g e --- 2279 // --- M e s s a g e ---
2275 2280
2276 2281
2277 Local<String> Message::Get() const { 2282 Local<String> Message::Get() const {
2278 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 2283 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
2284 TRACE_EVENT_SCOPED_CONTEXT("v8", "Isolate", isolate);
2279 ENTER_V8(isolate); 2285 ENTER_V8(isolate);
2280 EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); 2286 EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
2281 i::Handle<i::Object> obj = Utils::OpenHandle(this); 2287 i::Handle<i::Object> obj = Utils::OpenHandle(this);
2282 i::Handle<i::String> raw_result = i::MessageHandler::GetMessage(isolate, obj); 2288 i::Handle<i::String> raw_result = i::MessageHandler::GetMessage(isolate, obj);
2283 Local<String> result = Utils::ToLocal(raw_result); 2289 Local<String> result = Utils::ToLocal(raw_result);
2284 return scope.Escape(result); 2290 return scope.Escape(result);
2285 } 2291 }
2286 2292
2287 2293
2288 ScriptOrigin Message::GetScriptOrigin() const { 2294 ScriptOrigin Message::GetScriptOrigin() const {
2289 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 2295 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
2290 auto message = i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); 2296 auto message = i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this));
2291 auto script_wraper = i::Handle<i::Object>(message->script(), isolate); 2297 auto script_wraper = i::Handle<i::Object>(message->script(), isolate);
2292 auto script_value = i::Handle<i::JSValue>::cast(script_wraper); 2298 auto script_value = i::Handle<i::JSValue>::cast(script_wraper);
2293 i::Handle<i::Script> script(i::Script::cast(script_value->value())); 2299 i::Handle<i::Script> script(i::Script::cast(script_value->value()));
2294 return GetScriptOriginForScript(isolate, script); 2300 return GetScriptOriginForScript(isolate, script);
2295 } 2301 }
2296 2302
2297 2303
2298 v8::Local<Value> Message::GetScriptResourceName() const { 2304 v8::Local<Value> Message::GetScriptResourceName() const {
2299 return GetScriptOrigin().ResourceName(); 2305 return GetScriptOrigin().ResourceName();
2300 } 2306 }
2301 2307
2302 2308
2303 v8::Local<v8::StackTrace> Message::GetStackTrace() const { 2309 v8::Local<v8::StackTrace> Message::GetStackTrace() const {
2304 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 2310 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
2311 TRACE_EVENT_SCOPED_CONTEXT("v8", "Isolate", isolate);
2305 ENTER_V8(isolate); 2312 ENTER_V8(isolate);
2306 EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); 2313 EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
2307 auto message = i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); 2314 auto message = i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this));
2308 i::Handle<i::Object> stackFramesObj(message->stack_frames(), isolate); 2315 i::Handle<i::Object> stackFramesObj(message->stack_frames(), isolate);
2309 if (!stackFramesObj->IsJSArray()) return v8::Local<v8::StackTrace>(); 2316 if (!stackFramesObj->IsJSArray()) return v8::Local<v8::StackTrace>();
2310 auto stackTrace = i::Handle<i::JSArray>::cast(stackFramesObj); 2317 auto stackTrace = i::Handle<i::JSArray>::cast(stackFramesObj);
2311 return scope.Escape(Utils::StackTraceToLocal(stackTrace)); 2318 return scope.Escape(Utils::StackTraceToLocal(stackTrace));
2312 } 2319 }
2313 2320
2314 2321
(...skipping 3188 matching lines...) Expand 10 before | Expand all | Expand 10 after
5503 // Leave V8. 5510 // Leave V8.
5504 5511
5505 return env; 5512 return env;
5506 } 5513 }
5507 5514
5508 Local<Context> v8::Context::New(v8::Isolate* external_isolate, 5515 Local<Context> v8::Context::New(v8::Isolate* external_isolate,
5509 v8::ExtensionConfiguration* extensions, 5516 v8::ExtensionConfiguration* extensions,
5510 v8::Local<ObjectTemplate> global_template, 5517 v8::Local<ObjectTemplate> global_template,
5511 v8::Local<Value> global_object) { 5518 v8::Local<Value> global_object) {
5512 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate); 5519 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate);
5520 TRACE_EVENT_SCOPED_CONTEXT("v8", "Isolate", isolate);
5513 LOG_API(isolate, "Context::New"); 5521 LOG_API(isolate, "Context::New");
5514 i::HandleScope scope(isolate); 5522 i::HandleScope scope(isolate);
5515 ExtensionConfiguration no_extensions; 5523 ExtensionConfiguration no_extensions;
5516 if (extensions == NULL) extensions = &no_extensions; 5524 if (extensions == NULL) extensions = &no_extensions;
5517 i::Handle<i::Context> env = 5525 i::Handle<i::Context> env =
5518 CreateEnvironment(isolate, extensions, global_template, global_object); 5526 CreateEnvironment(isolate, extensions, global_template, global_object);
5519 if (env.is_null()) { 5527 if (env.is_null()) {
5520 if (isolate->has_pending_exception()) { 5528 if (isolate->has_pending_exception()) {
5521 isolate->OptionalRescheduleException(true); 5529 isolate->OptionalRescheduleException(true);
5522 } 5530 }
(...skipping 1618 matching lines...) Expand 10 before | Expand all | Expand 10 after
7141 7149
7142 Isolate* Isolate::GetCurrent() { 7150 Isolate* Isolate::GetCurrent() {
7143 i::Isolate* isolate = i::Isolate::Current(); 7151 i::Isolate* isolate = i::Isolate::Current();
7144 return reinterpret_cast<Isolate*>(isolate); 7152 return reinterpret_cast<Isolate*>(isolate);
7145 } 7153 }
7146 7154
7147 7155
7148 Isolate* Isolate::New(const Isolate::CreateParams& params) { 7156 Isolate* Isolate::New(const Isolate::CreateParams& params) {
7149 i::Isolate* isolate = new i::Isolate(false); 7157 i::Isolate* isolate = new i::Isolate(false);
7150 Isolate* v8_isolate = reinterpret_cast<Isolate*>(isolate); 7158 Isolate* v8_isolate = reinterpret_cast<Isolate*>(isolate);
7159 TRACE_EVENT_SCOPED_CONTEXT("v8", "Isolate", isolate);
7151 CHECK(params.array_buffer_allocator != NULL); 7160 CHECK(params.array_buffer_allocator != NULL);
7152 isolate->set_array_buffer_allocator(params.array_buffer_allocator); 7161 isolate->set_array_buffer_allocator(params.array_buffer_allocator);
7153 if (params.snapshot_blob != NULL) { 7162 if (params.snapshot_blob != NULL) {
7154 isolate->set_snapshot_blob(params.snapshot_blob); 7163 isolate->set_snapshot_blob(params.snapshot_blob);
7155 } else { 7164 } else {
7156 isolate->set_snapshot_blob(i::Snapshot::DefaultSnapshotBlob()); 7165 isolate->set_snapshot_blob(i::Snapshot::DefaultSnapshotBlob());
7157 } 7166 }
7158 if (params.entry_hook) { 7167 if (params.entry_hook) {
7159 isolate->set_function_entry_hook(params.entry_hook); 7168 isolate->set_function_entry_hook(params.entry_hook);
7160 } 7169 }
(...skipping 1393 matching lines...) Expand 10 before | Expand all | Expand 10 after
8554 Address callback_address = 8563 Address callback_address =
8555 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 8564 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
8556 VMState<EXTERNAL> state(isolate); 8565 VMState<EXTERNAL> state(isolate);
8557 ExternalCallbackScope call_scope(isolate, callback_address); 8566 ExternalCallbackScope call_scope(isolate, callback_address);
8558 callback(info); 8567 callback(info);
8559 } 8568 }
8560 8569
8561 8570
8562 } // namespace internal 8571 } // namespace internal
8563 } // namespace v8 8572 } // namespace v8
OLDNEW
« no previous file with comments | « include/v8-platform.h ('k') | src/d8.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698