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

Side by Side Diff: src/api.cc

Issue 1704253002: Reland: Add Scoped Context Info (Isolate) to V8 Traces (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 73
74 #define ENTER_V8(isolate) i::VMState<v8::OTHER> __state__((isolate)) 74 #define ENTER_V8(isolate) i::VMState<v8::OTHER> __state__((isolate))
75 75
76 76
77 #define PREPARE_FOR_EXECUTION_GENERIC(isolate, context, function_name, \ 77 #define PREPARE_FOR_EXECUTION_GENERIC(isolate, context, function_name, \
78 bailout_value, HandleScopeClass, \ 78 bailout_value, HandleScopeClass, \
79 do_callback) \ 79 do_callback) \
80 if (IsExecutionTerminatingCheck(isolate)) { \ 80 if (IsExecutionTerminatingCheck(isolate)) { \
81 return bailout_value; \ 81 return bailout_value; \
82 } \ 82 } \
83 TRACE_EVENT_SCOPED_CONTEXT("v8", "Isolate", isolate); \
83 HandleScopeClass handle_scope(isolate); \ 84 HandleScopeClass handle_scope(isolate); \
84 CallDepthScope call_depth_scope(isolate, context, do_callback); \ 85 CallDepthScope call_depth_scope(isolate, context, do_callback); \
85 LOG_API(isolate, function_name); \ 86 LOG_API(isolate, function_name); \
86 ENTER_V8(isolate); \ 87 ENTER_V8(isolate); \
87 bool has_pending_exception = false 88 bool has_pending_exception = false
88 89
89 90
90 #define PREPARE_FOR_EXECUTION_WITH_CONTEXT( \ 91 #define PREPARE_FOR_EXECUTION_WITH_CONTEXT( \
91 context, function_name, bailout_value, HandleScopeClass, do_callback) \ 92 context, function_name, bailout_value, HandleScopeClass, do_callback) \
92 auto isolate = context.IsEmpty() \ 93 auto isolate = context.IsEmpty() \
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 Local<Context> context_; 190 Local<Context> context_;
190 bool escaped_; 191 bool escaped_;
191 bool do_callback_; 192 bool do_callback_;
192 }; 193 };
193 194
194 } // namespace 195 } // namespace
195 196
196 197
197 static ScriptOrigin GetScriptOriginForScript(i::Isolate* isolate, 198 static ScriptOrigin GetScriptOriginForScript(i::Isolate* isolate,
198 i::Handle<i::Script> script) { 199 i::Handle<i::Script> script) {
200 TRACE_EVENT_SCOPED_CONTEXT("v8", "Isolate", isolate);
199 i::Handle<i::Object> scriptName(i::Script::GetNameOrSourceURL(script)); 201 i::Handle<i::Object> scriptName(i::Script::GetNameOrSourceURL(script));
200 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);
201 v8::Isolate* v8_isolate = 203 v8::Isolate* v8_isolate =
202 reinterpret_cast<v8::Isolate*>(script->GetIsolate()); 204 reinterpret_cast<v8::Isolate*>(script->GetIsolate());
203 ScriptOriginOptions options(script->origin_options()); 205 ScriptOriginOptions options(script->origin_options());
204 v8::ScriptOrigin origin( 206 v8::ScriptOrigin origin(
205 Utils::ToLocal(scriptName), 207 Utils::ToLocal(scriptName),
206 v8::Integer::New(v8_isolate, script->line_offset()), 208 v8::Integer::New(v8_isolate, script->line_offset()),
207 v8::Integer::New(v8_isolate, script->column_offset()), 209 v8::Integer::New(v8_isolate, script->column_offset()),
208 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
367 }; 369 };
368 370
369 } // namespace 371 } // namespace
370 372
371 373
372 StartupData V8::CreateSnapshotDataBlob(const char* custom_source) { 374 StartupData V8::CreateSnapshotDataBlob(const char* custom_source) {
373 i::Isolate* internal_isolate = new i::Isolate(true); 375 i::Isolate* internal_isolate = new i::Isolate(true);
374 ArrayBufferAllocator allocator; 376 ArrayBufferAllocator allocator;
375 internal_isolate->set_array_buffer_allocator(&allocator); 377 internal_isolate->set_array_buffer_allocator(&allocator);
376 Isolate* isolate = reinterpret_cast<Isolate*>(internal_isolate); 378 Isolate* isolate = reinterpret_cast<Isolate*>(internal_isolate);
379 TRACE_EVENT_SCOPED_CONTEXT("v8", "Isolate", isolate);
377 StartupData result = {NULL, 0}; 380 StartupData result = {NULL, 0};
378 { 381 {
379 base::ElapsedTimer timer; 382 base::ElapsedTimer timer;
380 timer.Start(); 383 timer.Start();
381 Isolate::Scope isolate_scope(isolate); 384 Isolate::Scope isolate_scope(isolate);
382 internal_isolate->Init(NULL); 385 internal_isolate->Init(NULL);
383 Persistent<Context> context; 386 Persistent<Context> context;
384 i::Snapshot::Metadata metadata; 387 i::Snapshot::Metadata metadata;
385 { 388 {
386 HandleScope handle_scope(isolate); 389 HandleScope handle_scope(isolate);
(...skipping 1434 matching lines...) Expand 10 before | Expand all | Expand 10 after
1821 auto context = v8_isolate->GetCurrentContext(); 1824 auto context = v8_isolate->GetCurrentContext();
1822 RETURN_TO_LOCAL_UNCHECKED(Compile(context, source, options), Script); 1825 RETURN_TO_LOCAL_UNCHECKED(Compile(context, source, options), Script);
1823 } 1826 }
1824 1827
1825 1828
1826 MaybeLocal<Script> ScriptCompiler::CompileModule(Local<Context> context, 1829 MaybeLocal<Script> ScriptCompiler::CompileModule(Local<Context> context,
1827 Source* source, 1830 Source* source,
1828 CompileOptions options) { 1831 CompileOptions options) {
1829 CHECK(i::FLAG_harmony_modules); 1832 CHECK(i::FLAG_harmony_modules);
1830 auto isolate = context->GetIsolate(); 1833 auto isolate = context->GetIsolate();
1834 TRACE_EVENT_SCOPED_CONTEXT("V8", "Isolate", isolate);
1831 auto maybe = CompileUnboundInternal(isolate, source, options, true); 1835 auto maybe = CompileUnboundInternal(isolate, source, options, true);
1832 Local<UnboundScript> generic; 1836 Local<UnboundScript> generic;
1833 if (!maybe.ToLocal(&generic)) return MaybeLocal<Script>(); 1837 if (!maybe.ToLocal(&generic)) return MaybeLocal<Script>();
1834 v8::Context::Scope scope(context); 1838 v8::Context::Scope scope(context);
1835 return generic->BindToCurrentContext(); 1839 return generic->BindToCurrentContext();
1836 } 1840 }
1837 1841
1838 1842
1839 class IsIdentifierHelper { 1843 class IsIdentifierHelper {
1840 public: 1844 public:
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
2247 void v8::TryCatch::SetCaptureMessage(bool value) { 2251 void v8::TryCatch::SetCaptureMessage(bool value) {
2248 capture_message_ = value; 2252 capture_message_ = value;
2249 } 2253 }
2250 2254
2251 2255
2252 // --- M e s s a g e --- 2256 // --- M e s s a g e ---
2253 2257
2254 2258
2255 Local<String> Message::Get() const { 2259 Local<String> Message::Get() const {
2256 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 2260 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
2261 TRACE_EVENT_SCOPED_CONTEXT("v8", "Isolate", isolate);
2257 ENTER_V8(isolate); 2262 ENTER_V8(isolate);
2258 EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); 2263 EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
2259 i::Handle<i::Object> obj = Utils::OpenHandle(this); 2264 i::Handle<i::Object> obj = Utils::OpenHandle(this);
2260 i::Handle<i::String> raw_result = i::MessageHandler::GetMessage(isolate, obj); 2265 i::Handle<i::String> raw_result = i::MessageHandler::GetMessage(isolate, obj);
2261 Local<String> result = Utils::ToLocal(raw_result); 2266 Local<String> result = Utils::ToLocal(raw_result);
2262 return scope.Escape(result); 2267 return scope.Escape(result);
2263 } 2268 }
2264 2269
2265 2270
2266 ScriptOrigin Message::GetScriptOrigin() const { 2271 ScriptOrigin Message::GetScriptOrigin() const {
2267 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 2272 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
2268 auto message = i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); 2273 auto message = i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this));
2269 auto script_wraper = i::Handle<i::Object>(message->script(), isolate); 2274 auto script_wraper = i::Handle<i::Object>(message->script(), isolate);
2270 auto script_value = i::Handle<i::JSValue>::cast(script_wraper); 2275 auto script_value = i::Handle<i::JSValue>::cast(script_wraper);
2271 i::Handle<i::Script> script(i::Script::cast(script_value->value())); 2276 i::Handle<i::Script> script(i::Script::cast(script_value->value()));
2272 return GetScriptOriginForScript(isolate, script); 2277 return GetScriptOriginForScript(isolate, script);
2273 } 2278 }
2274 2279
2275 2280
2276 v8::Local<Value> Message::GetScriptResourceName() const { 2281 v8::Local<Value> Message::GetScriptResourceName() const {
2277 return GetScriptOrigin().ResourceName(); 2282 return GetScriptOrigin().ResourceName();
2278 } 2283 }
2279 2284
2280 2285
2281 v8::Local<v8::StackTrace> Message::GetStackTrace() const { 2286 v8::Local<v8::StackTrace> Message::GetStackTrace() const {
2282 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 2287 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
2288 TRACE_EVENT_SCOPED_CONTEXT("v8", "Isolate", isolate);
2283 ENTER_V8(isolate); 2289 ENTER_V8(isolate);
2284 EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); 2290 EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
2285 auto message = i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); 2291 auto message = i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this));
2286 i::Handle<i::Object> stackFramesObj(message->stack_frames(), isolate); 2292 i::Handle<i::Object> stackFramesObj(message->stack_frames(), isolate);
2287 if (!stackFramesObj->IsJSArray()) return v8::Local<v8::StackTrace>(); 2293 if (!stackFramesObj->IsJSArray()) return v8::Local<v8::StackTrace>();
2288 auto stackTrace = i::Handle<i::JSArray>::cast(stackFramesObj); 2294 auto stackTrace = i::Handle<i::JSArray>::cast(stackFramesObj);
2289 return scope.Escape(Utils::StackTraceToLocal(stackTrace)); 2295 return scope.Escape(Utils::StackTraceToLocal(stackTrace));
2290 } 2296 }
2291 2297
2292 2298
(...skipping 3211 matching lines...) Expand 10 before | Expand all | Expand 10 after
5504 // Leave V8. 5510 // Leave V8.
5505 5511
5506 return env; 5512 return env;
5507 } 5513 }
5508 5514
5509 Local<Context> v8::Context::New(v8::Isolate* external_isolate, 5515 Local<Context> v8::Context::New(v8::Isolate* external_isolate,
5510 v8::ExtensionConfiguration* extensions, 5516 v8::ExtensionConfiguration* extensions,
5511 v8::Local<ObjectTemplate> global_template, 5517 v8::Local<ObjectTemplate> global_template,
5512 v8::Local<Value> global_object) { 5518 v8::Local<Value> global_object) {
5513 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);
5514 LOG_API(isolate, "Context::New"); 5521 LOG_API(isolate, "Context::New");
5515 i::HandleScope scope(isolate); 5522 i::HandleScope scope(isolate);
5516 ExtensionConfiguration no_extensions; 5523 ExtensionConfiguration no_extensions;
5517 if (extensions == NULL) extensions = &no_extensions; 5524 if (extensions == NULL) extensions = &no_extensions;
5518 i::Handle<i::Context> env = 5525 i::Handle<i::Context> env =
5519 CreateEnvironment(isolate, extensions, global_template, global_object); 5526 CreateEnvironment(isolate, extensions, global_template, global_object);
5520 if (env.is_null()) { 5527 if (env.is_null()) {
5521 if (isolate->has_pending_exception()) { 5528 if (isolate->has_pending_exception()) {
5522 isolate->OptionalRescheduleException(true); 5529 isolate->OptionalRescheduleException(true);
5523 } 5530 }
(...skipping 1618 matching lines...) Expand 10 before | Expand all | Expand 10 after
7142 7149
7143 Isolate* Isolate::GetCurrent() { 7150 Isolate* Isolate::GetCurrent() {
7144 i::Isolate* isolate = i::Isolate::Current(); 7151 i::Isolate* isolate = i::Isolate::Current();
7145 return reinterpret_cast<Isolate*>(isolate); 7152 return reinterpret_cast<Isolate*>(isolate);
7146 } 7153 }
7147 7154
7148 7155
7149 Isolate* Isolate::New(const Isolate::CreateParams& params) { 7156 Isolate* Isolate::New(const Isolate::CreateParams& params) {
7150 i::Isolate* isolate = new i::Isolate(false); 7157 i::Isolate* isolate = new i::Isolate(false);
7151 Isolate* v8_isolate = reinterpret_cast<Isolate*>(isolate); 7158 Isolate* v8_isolate = reinterpret_cast<Isolate*>(isolate);
7159 TRACE_EVENT_SCOPED_CONTEXT("v8", "Isolate", isolate);
7152 CHECK(params.array_buffer_allocator != NULL); 7160 CHECK(params.array_buffer_allocator != NULL);
7153 isolate->set_array_buffer_allocator(params.array_buffer_allocator); 7161 isolate->set_array_buffer_allocator(params.array_buffer_allocator);
7154 if (params.snapshot_blob != NULL) { 7162 if (params.snapshot_blob != NULL) {
7155 isolate->set_snapshot_blob(params.snapshot_blob); 7163 isolate->set_snapshot_blob(params.snapshot_blob);
7156 } else { 7164 } else {
7157 isolate->set_snapshot_blob(i::Snapshot::DefaultSnapshotBlob()); 7165 isolate->set_snapshot_blob(i::Snapshot::DefaultSnapshotBlob());
7158 } 7166 }
7159 if (params.entry_hook) { 7167 if (params.entry_hook) {
7160 isolate->set_function_entry_hook(params.entry_hook); 7168 isolate->set_function_entry_hook(params.entry_hook);
7161 } 7169 }
(...skipping 1394 matching lines...) Expand 10 before | Expand all | Expand 10 after
8556 Address callback_address = 8564 Address callback_address =
8557 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 8565 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
8558 VMState<EXTERNAL> state(isolate); 8566 VMState<EXTERNAL> state(isolate);
8559 ExternalCallbackScope call_scope(isolate, callback_address); 8567 ExternalCallbackScope call_scope(isolate, callback_address);
8560 callback(info); 8568 callback(info);
8561 } 8569 }
8562 8570
8563 8571
8564 } // namespace internal 8572 } // namespace internal
8565 } // namespace v8 8573 } // 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