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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/V8Initializer.cpp

Issue 2841443005: [Bindings] Create and use V8 context snapshots (Closed)
Patch Set: Work for all comments Created 3 years, 6 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 22 matching lines...) Expand all
33 #include "bindings/core/v8/ScriptController.h" 33 #include "bindings/core/v8/ScriptController.h"
34 #include "bindings/core/v8/ScriptValue.h" 34 #include "bindings/core/v8/ScriptValue.h"
35 #include "bindings/core/v8/SourceLocation.h" 35 #include "bindings/core/v8/SourceLocation.h"
36 #include "bindings/core/v8/UseCounterCallback.h" 36 #include "bindings/core/v8/UseCounterCallback.h"
37 #include "bindings/core/v8/V8BindingForCore.h" 37 #include "bindings/core/v8/V8BindingForCore.h"
38 #include "bindings/core/v8/V8DOMException.h" 38 #include "bindings/core/v8/V8DOMException.h"
39 #include "bindings/core/v8/V8ErrorEvent.h" 39 #include "bindings/core/v8/V8ErrorEvent.h"
40 #include "bindings/core/v8/V8ErrorHandler.h" 40 #include "bindings/core/v8/V8ErrorHandler.h"
41 #include "bindings/core/v8/V8GCController.h" 41 #include "bindings/core/v8/V8GCController.h"
42 #include "bindings/core/v8/V8IdleTaskRunner.h" 42 #include "bindings/core/v8/V8IdleTaskRunner.h"
43 #include "bindings/core/v8/V8SnapshotUtil.h"
43 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" 44 #include "bindings/core/v8/WorkerOrWorkletScriptController.h"
44 #include "core/dom/Document.h" 45 #include "core/dom/Document.h"
45 #include "core/dom/ExecutionContext.h" 46 #include "core/dom/ExecutionContext.h"
46 #include "core/frame/LocalDOMWindow.h" 47 #include "core/frame/LocalDOMWindow.h"
47 #include "core/frame/csp/ContentSecurityPolicy.h" 48 #include "core/frame/csp/ContentSecurityPolicy.h"
48 #include "core/inspector/ConsoleMessage.h" 49 #include "core/inspector/ConsoleMessage.h"
49 #include "core/inspector/MainThreadDebugger.h" 50 #include "core/inspector/MainThreadDebugger.h"
50 #include "core/workers/WorkerGlobalScope.h" 51 #include "core/workers/WorkerGlobalScope.h"
51 #include "platform/EventDispatchForbiddenScope.h" 52 #include "platform/EventDispatchForbiddenScope.h"
52 #include "platform/RuntimeEnabledFeatures.h" 53 #include "platform/RuntimeEnabledFeatures.h"
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 V8PerIsolateData::From(isolate)->SetScriptWrappableVisitor( 374 V8PerIsolateData::From(isolate)->SetScriptWrappableVisitor(
374 std::move(visitor)); 375 std::move(visitor));
375 isolate->SetEmbedderHeapTracer( 376 isolate->SetEmbedderHeapTracer(
376 V8PerIsolateData::From(isolate)->GetScriptWrappableVisitor()); 377 V8PerIsolateData::From(isolate)->GetScriptWrappableVisitor());
377 378
378 isolate->SetMicrotasksPolicy(v8::MicrotasksPolicy::kScoped); 379 isolate->SetMicrotasksPolicy(v8::MicrotasksPolicy::kScoped);
379 380
380 isolate->SetUseCounterCallback(&UseCounterCallback); 381 isolate->SetUseCounterCallback(&UseCounterCallback);
381 isolate->SetWasmModuleCallback(WasmModuleOverride); 382 isolate->SetWasmModuleCallback(WasmModuleOverride);
382 isolate->SetWasmInstanceCallback(WasmInstanceOverride); 383 isolate->SetWasmInstanceCallback(WasmInstanceOverride);
384
385 v8::HandleScope handle_scope(isolate);
386 V8SnapshotUtil::EnsureInterfaceTemplates(isolate);
383 } 387 }
384 388
385 namespace { 389 namespace {
386 390
387 class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator { 391 class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
388 // Allocate() methods return null to signal allocation failure to V8, which 392 // Allocate() methods return null to signal allocation failure to V8, which
389 // should respond by throwing a RangeError, per 393 // should respond by throwing a RangeError, per
390 // http://www.ecma-international.org/ecma-262/6.0/#sec-createbytedatablock. 394 // http://www.ecma-international.org/ecma-262/6.0/#sec-createbytedatablock.
391 void* Allocate(size_t size) override { 395 void* Allocate(size_t size) override {
392 return WTF::ArrayBufferContents::AllocateMemoryOrNull( 396 return WTF::ArrayBufferContents::AllocateMemoryOrNull(
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 WTF::ArrayBufferContents::Initialize(AdjustAmountOfExternalAllocatedMemory); 431 WTF::ArrayBufferContents::Initialize(AdjustAmountOfExternalAllocatedMemory);
428 432
429 DEFINE_STATIC_LOCAL(ArrayBufferAllocator, array_buffer_allocator, ()); 433 DEFINE_STATIC_LOCAL(ArrayBufferAllocator, array_buffer_allocator, ());
430 auto v8_extras_mode = RuntimeEnabledFeatures::ExperimentalV8ExtrasEnabled() 434 auto v8_extras_mode = RuntimeEnabledFeatures::ExperimentalV8ExtrasEnabled()
431 ? gin::IsolateHolder::kStableAndExperimentalV8Extras 435 ? gin::IsolateHolder::kStableAndExperimentalV8Extras
432 : gin::IsolateHolder::kStableV8Extras; 436 : gin::IsolateHolder::kStableV8Extras;
433 gin::IsolateHolder::Initialize(gin::IsolateHolder::kNonStrictMode, 437 gin::IsolateHolder::Initialize(gin::IsolateHolder::kNonStrictMode,
434 v8_extras_mode, &array_buffer_allocator); 438 v8_extras_mode, &array_buffer_allocator);
435 439
436 // NOTE: Some threads (namely utility threads) don't have a scheduler. 440 // NOTE: Some threads (namely utility threads) don't have a scheduler.
437 WebScheduler* scheduler = Platform::Current()->CurrentThread()->Scheduler(); 441 Platform* platform = Platform::Current();
442 WebThread* thread = platform->CurrentThread();
443 WebScheduler* scheduler = thread ? thread->Scheduler() : nullptr;
Yuki 2017/06/20 14:20:11 Why |thread| can be null?
peria 2017/06/21 07:19:16 In taking snapshot process, we have no implementat
444
438 // When timer task runner is used for PerIsolateData, GC tasks are getting 445 // When timer task runner is used for PerIsolateData, GC tasks are getting
439 // throttled and memory usage goes up. For now we're using loading task queue 446 // throttled and memory usage goes up. For now we're using loading task queue
440 // to prevent this. 447 // to prevent this.
441 // TODO(altimin): Consider switching to timerTaskRunner here. 448 // TODO(altimin): Consider switching to timerTaskRunner here.
442 v8::Isolate* isolate = V8PerIsolateData::Initialize( 449 v8::Isolate* isolate = V8PerIsolateData::Initialize(
443 scheduler ? scheduler->LoadingTaskRunner() 450 scheduler ? scheduler->LoadingTaskRunner()
444 : Platform::Current()->CurrentThread()->GetWebTaskRunner()); 451 : thread ? thread->GetWebTaskRunner() : nullptr,
452 V8SnapshotUtil::GetReferenceTable(),
453 platform->IsToTakeV8Snapshot()
454 ? V8PerIsolateData::V8ContextMode::kTakeSnapshot
455 : V8PerIsolateData::V8ContextMode::kUseSnapshot);
445 456
446 InitializeV8Common(isolate); 457 InitializeV8Common(isolate);
447 458
448 isolate->SetOOMErrorHandler(ReportOOMErrorInMainThread); 459 isolate->SetOOMErrorHandler(ReportOOMErrorInMainThread);
449 isolate->SetFatalErrorHandler(ReportFatalErrorInMainThread); 460 isolate->SetFatalErrorHandler(ReportFatalErrorInMainThread);
450 isolate->AddMessageListenerWithErrorLevel( 461 isolate->AddMessageListenerWithErrorLevel(
451 MessageHandlerInMainThread, 462 MessageHandlerInMainThread,
452 v8::Isolate::kMessageError | v8::Isolate::kMessageWarning | 463 v8::Isolate::kMessageError | v8::Isolate::kMessageWarning |
453 v8::Isolate::kMessageInfo | v8::Isolate::kMessageDebug | 464 v8::Isolate::kMessageInfo | v8::Isolate::kMessageDebug |
454 v8::Isolate::kMessageLog); 465 v8::Isolate::kMessageLog);
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 v8::Isolate::kMessageLog); 569 v8::Isolate::kMessageLog);
559 isolate->SetFatalErrorHandler(ReportFatalErrorInWorker); 570 isolate->SetFatalErrorHandler(ReportFatalErrorInWorker);
560 571
561 uint32_t here; 572 uint32_t here;
562 isolate->SetStackLimit(reinterpret_cast<uintptr_t>(&here) - 573 isolate->SetStackLimit(reinterpret_cast<uintptr_t>(&here) -
563 kWorkerMaxStackSize); 574 kWorkerMaxStackSize);
564 isolate->SetPromiseRejectCallback(PromiseRejectHandlerInWorker); 575 isolate->SetPromiseRejectCallback(PromiseRejectHandlerInWorker);
565 } 576 }
566 577
567 } // namespace blink 578 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698