OLD | NEW |
---|---|
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 17 matching lines...) Expand all Loading... | |
28 #include <memory> | 28 #include <memory> |
29 | 29 |
30 #include "bindings/core/v8/BindingSecurity.h" | 30 #include "bindings/core/v8/BindingSecurity.h" |
31 #include "bindings/core/v8/RejectedPromises.h" | 31 #include "bindings/core/v8/RejectedPromises.h" |
32 #include "bindings/core/v8/RetainedDOMInfo.h" | 32 #include "bindings/core/v8/RetainedDOMInfo.h" |
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/V8ContextSnapshot.h" | |
38 #include "bindings/core/v8/V8DOMException.h" | 39 #include "bindings/core/v8/V8DOMException.h" |
39 #include "bindings/core/v8/V8ErrorEvent.h" | 40 #include "bindings/core/v8/V8ErrorEvent.h" |
40 #include "bindings/core/v8/V8ErrorHandler.h" | 41 #include "bindings/core/v8/V8ErrorHandler.h" |
41 #include "bindings/core/v8/V8GCController.h" | 42 #include "bindings/core/v8/V8GCController.h" |
42 #include "bindings/core/v8/V8IdleTaskRunner.h" | 43 #include "bindings/core/v8/V8IdleTaskRunner.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" |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
381 V8PerIsolateData::From(isolate)->SetScriptWrappableVisitor( | 382 V8PerIsolateData::From(isolate)->SetScriptWrappableVisitor( |
382 std::move(visitor)); | 383 std::move(visitor)); |
383 isolate->SetEmbedderHeapTracer( | 384 isolate->SetEmbedderHeapTracer( |
384 V8PerIsolateData::From(isolate)->GetScriptWrappableVisitor()); | 385 V8PerIsolateData::From(isolate)->GetScriptWrappableVisitor()); |
385 | 386 |
386 isolate->SetMicrotasksPolicy(v8::MicrotasksPolicy::kScoped); | 387 isolate->SetMicrotasksPolicy(v8::MicrotasksPolicy::kScoped); |
387 | 388 |
388 isolate->SetUseCounterCallback(&UseCounterCallback); | 389 isolate->SetUseCounterCallback(&UseCounterCallback); |
389 isolate->SetWasmModuleCallback(WasmModuleOverride); | 390 isolate->SetWasmModuleCallback(WasmModuleOverride); |
390 isolate->SetWasmInstanceCallback(WasmInstanceOverride); | 391 isolate->SetWasmInstanceCallback(WasmInstanceOverride); |
392 | |
393 V8ContextSnapshot::EnsureInterfaceTemplates(isolate); | |
391 } | 394 } |
392 | 395 |
393 namespace { | 396 namespace { |
394 | 397 |
395 class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator { | 398 class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator { |
396 // Allocate() methods return null to signal allocation failure to V8, which | 399 // Allocate() methods return null to signal allocation failure to V8, which |
397 // should respond by throwing a RangeError, per | 400 // should respond by throwing a RangeError, per |
398 // http://www.ecma-international.org/ecma-262/6.0/#sec-createbytedatablock. | 401 // http://www.ecma-international.org/ecma-262/6.0/#sec-createbytedatablock. |
399 void* Allocate(size_t size) override { | 402 void* Allocate(size_t size) override { |
400 return WTF::ArrayBufferContents::AllocateMemoryOrNull( | 403 return WTF::ArrayBufferContents::AllocateMemoryOrNull( |
(...skipping 21 matching lines...) Expand all Loading... | |
422 | 425 |
423 process_total += diff; | 426 process_total += diff; |
424 DCHECK_GE(process_total, 0) | 427 DCHECK_GE(process_total, 0) |
425 << "total amount = " << process_total << ", diff = " << diff; | 428 << "total amount = " << process_total << ", diff = " << diff; |
426 } | 429 } |
427 #endif | 430 #endif |
428 | 431 |
429 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(diff); | 432 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(diff); |
430 } | 433 } |
431 | 434 |
432 void V8Initializer::InitializeMainThread() { | 435 void V8Initializer::InitializeMainThread(intptr_t* reference_table) { |
433 DCHECK(IsMainThread()); | 436 DCHECK(IsMainThread()); |
434 | 437 |
435 WTF::ArrayBufferContents::Initialize(AdjustAmountOfExternalAllocatedMemory); | 438 WTF::ArrayBufferContents::Initialize(AdjustAmountOfExternalAllocatedMemory); |
436 | 439 |
437 DEFINE_STATIC_LOCAL(ArrayBufferAllocator, array_buffer_allocator, ()); | 440 DEFINE_STATIC_LOCAL(ArrayBufferAllocator, array_buffer_allocator, ()); |
438 auto v8_extras_mode = RuntimeEnabledFeatures::ExperimentalV8ExtrasEnabled() | 441 auto v8_extras_mode = RuntimeEnabledFeatures::ExperimentalV8ExtrasEnabled() |
439 ? gin::IsolateHolder::kStableAndExperimentalV8Extras | 442 ? gin::IsolateHolder::kStableAndExperimentalV8Extras |
440 : gin::IsolateHolder::kStableV8Extras; | 443 : gin::IsolateHolder::kStableV8Extras; |
441 gin::IsolateHolder::Initialize(gin::IsolateHolder::kNonStrictMode, | 444 gin::IsolateHolder::Initialize(gin::IsolateHolder::kNonStrictMode, |
442 v8_extras_mode, &array_buffer_allocator); | 445 v8_extras_mode, &array_buffer_allocator); |
443 | 446 |
444 // NOTE: Some threads (namely utility threads) don't have a scheduler. | 447 // NOTE: Some threads (namely utility threads) don't have a scheduler. |
445 WebScheduler* scheduler = Platform::Current()->CurrentThread()->Scheduler(); | 448 WebScheduler* scheduler = Platform::Current()->CurrentThread()->Scheduler(); |
449 | |
450 V8PerIsolateData::V8ContextSnapshotMode v8_context_snapshot_mode = | |
451 Platform::Current()->IsTakingV8ContextSnapshot() | |
452 ? V8PerIsolateData::V8ContextSnapshotMode::kTakeSnapshot | |
453 : V8PerIsolateData::V8ContextSnapshotMode::kUseSnapshot; | |
454 if (v8_context_snapshot_mode == | |
455 V8PerIsolateData::V8ContextSnapshotMode::kUseSnapshot && | |
456 !RuntimeEnabledFeatures::V8ContextSnapshotEnabled()) { | |
457 v8_context_snapshot_mode = | |
458 V8PerIsolateData::V8ContextSnapshotMode::kDontUseSnapshot; | |
459 reference_table = nullptr; | |
haraken
2017/07/10 06:52:08
Why do we need to set nullptr to reference_table?
peria
2017/07/10 10:18:43
To avoid http://crbug.com/v8/6433
| |
460 } | |
461 V8ContextSnapshot::SetReferenceTable(reference_table); | |
462 | |
446 // When timer task runner is used for PerIsolateData, GC tasks are getting | 463 // When timer task runner is used for PerIsolateData, GC tasks are getting |
447 // throttled and memory usage goes up. For now we're using loading task queue | 464 // throttled and memory usage goes up. For now we're using loading task queue |
448 // to prevent this. | 465 // to prevent this. |
449 // TODO(altimin): Consider switching to timerTaskRunner here. | 466 // TODO(altimin): Consider switching to timerTaskRunner here. |
450 v8::Isolate* isolate = V8PerIsolateData::Initialize( | 467 v8::Isolate* isolate = V8PerIsolateData::Initialize( |
451 scheduler ? scheduler->LoadingTaskRunner() | 468 scheduler ? scheduler->LoadingTaskRunner() |
452 : Platform::Current()->CurrentThread()->GetWebTaskRunner()); | 469 : Platform::Current()->CurrentThread()->GetWebTaskRunner(), |
470 reference_table, v8_context_snapshot_mode); | |
453 | 471 |
454 InitializeV8Common(isolate); | 472 InitializeV8Common(isolate); |
455 | 473 |
456 isolate->SetOOMErrorHandler(ReportOOMErrorInMainThread); | 474 isolate->SetOOMErrorHandler(ReportOOMErrorInMainThread); |
457 isolate->SetFatalErrorHandler(ReportFatalErrorInMainThread); | 475 isolate->SetFatalErrorHandler(ReportFatalErrorInMainThread); |
458 isolate->AddMessageListenerWithErrorLevel( | 476 isolate->AddMessageListenerWithErrorLevel( |
459 MessageHandlerInMainThread, | 477 MessageHandlerInMainThread, |
460 v8::Isolate::kMessageError | v8::Isolate::kMessageWarning | | 478 v8::Isolate::kMessageError | v8::Isolate::kMessageWarning | |
461 v8::Isolate::kMessageInfo | v8::Isolate::kMessageDebug | | 479 v8::Isolate::kMessageInfo | v8::Isolate::kMessageDebug | |
462 v8::Isolate::kMessageLog); | 480 v8::Isolate::kMessageLog); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
566 v8::Isolate::kMessageLog); | 584 v8::Isolate::kMessageLog); |
567 isolate->SetFatalErrorHandler(ReportFatalErrorInWorker); | 585 isolate->SetFatalErrorHandler(ReportFatalErrorInWorker); |
568 | 586 |
569 uint32_t here; | 587 uint32_t here; |
570 isolate->SetStackLimit(reinterpret_cast<uintptr_t>(&here) - | 588 isolate->SetStackLimit(reinterpret_cast<uintptr_t>(&here) - |
571 kWorkerMaxStackSize); | 589 kWorkerMaxStackSize); |
572 isolate->SetPromiseRejectCallback(PromiseRejectHandlerInWorker); | 590 isolate->SetPromiseRejectCallback(PromiseRejectHandlerInWorker); |
573 } | 591 } |
574 | 592 |
575 } // namespace blink | 593 } // namespace blink |
OLD | NEW |