OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/runtime/runtime-utils.h" | 5 #include "src/runtime/runtime-utils.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "src/arguments.h" | 9 #include "src/arguments.h" |
10 #include "src/compiler-dispatcher/optimizing-compile-dispatcher.h" | 10 #include "src/compiler-dispatcher/optimizing-compile-dispatcher.h" |
11 #include "src/compiler.h" | 11 #include "src/compiler.h" |
12 #include "src/deoptimizer.h" | 12 #include "src/deoptimizer.h" |
13 #include "src/frames-inl.h" | 13 #include "src/frames-inl.h" |
14 #include "src/full-codegen/full-codegen.h" | 14 #include "src/full-codegen/full-codegen.h" |
15 #include "src/isolate-inl.h" | 15 #include "src/isolate-inl.h" |
16 #include "src/runtime-profiler.h" | 16 #include "src/runtime-profiler.h" |
17 #include "src/snapshot/code-serializer.h" | 17 #include "src/snapshot/code-serializer.h" |
18 #include "src/snapshot/natives.h" | 18 #include "src/snapshot/natives.h" |
19 #include "src/wasm/wasm-module.h" | 19 #include "src/wasm/wasm-module.h" |
20 #include "src/wasm/wasm-objects.h" | 20 #include "src/wasm/wasm-objects.h" |
21 | 21 |
| 22 namespace { |
| 23 struct WasmCompileControls { |
| 24 uint32_t MaxWasmBufferSize = std::numeric_limits<uint32_t>::max(); |
| 25 bool AllowAnySizeForAsync = true; |
| 26 }; |
| 27 |
| 28 // We need per-isolate controls, because we sometimes run tests in multiple |
| 29 // isolates |
| 30 // concurrently. |
| 31 // To avoid upsetting the static initializer count, we lazy initialize this. |
| 32 v8::base::LazyInstance<std::map<v8::Isolate*, WasmCompileControls>>::type |
| 33 g_PerIsolateWasmControls = LAZY_INSTANCE_INITIALIZER; |
| 34 |
| 35 bool IsWasmCompileAllowed(v8::Isolate* isolate, v8::Local<v8::Value> value, |
| 36 bool is_async) { |
| 37 DCHECK_GT(g_PerIsolateWasmControls.Get().count(isolate), 0); |
| 38 const WasmCompileControls& ctrls = g_PerIsolateWasmControls.Get().at(isolate); |
| 39 return (is_async && ctrls.AllowAnySizeForAsync) || |
| 40 (v8::Local<v8::ArrayBuffer>::Cast(value)->ByteLength() <= |
| 41 ctrls.MaxWasmBufferSize); |
| 42 } |
| 43 |
| 44 // Use the compile controls for instantiation, too |
| 45 bool IsWasmInstantiateAllowed(v8::Isolate* isolate, |
| 46 v8::Local<v8::Value> module_or_bytes, |
| 47 v8::MaybeLocal<v8::Value> ffi, bool is_async) { |
| 48 DCHECK_GT(g_PerIsolateWasmControls.Get().count(isolate), 0); |
| 49 const WasmCompileControls& ctrls = g_PerIsolateWasmControls.Get().at(isolate); |
| 50 if (is_async && ctrls.AllowAnySizeForAsync) return true; |
| 51 if (!module_or_bytes->IsWebAssemblyCompiledModule()) { |
| 52 return IsWasmCompileAllowed(isolate, module_or_bytes, is_async); |
| 53 } |
| 54 v8::Local<v8::WasmCompiledModule> module = |
| 55 v8::Local<v8::WasmCompiledModule>::Cast(module_or_bytes); |
| 56 return static_cast<uint32_t>(module->GetWasmWireBytes()->Length()) <= |
| 57 ctrls.MaxWasmBufferSize; |
| 58 } |
| 59 } // namespace |
| 60 |
22 namespace v8 { | 61 namespace v8 { |
23 namespace internal { | 62 namespace internal { |
24 | 63 |
25 RUNTIME_FUNCTION(Runtime_ConstructDouble) { | 64 RUNTIME_FUNCTION(Runtime_ConstructDouble) { |
26 HandleScope scope(isolate); | 65 HandleScope scope(isolate); |
27 DCHECK_EQ(2, args.length()); | 66 DCHECK_EQ(2, args.length()); |
28 CONVERT_NUMBER_CHECKED(uint32_t, hi, Uint32, args[0]); | 67 CONVERT_NUMBER_CHECKED(uint32_t, hi, Uint32, args[0]); |
29 CONVERT_NUMBER_CHECKED(uint32_t, lo, Uint32, args[1]); | 68 CONVERT_NUMBER_CHECKED(uint32_t, lo, Uint32, args[1]); |
30 uint64_t result = (static_cast<uint64_t>(hi) << 32) | lo; | 69 uint64_t result = (static_cast<uint64_t>(hi) << 32) | lo; |
31 return *isolate->factory()->NewNumber(uint64_to_double(result)); | 70 return *isolate->factory()->NewNumber(uint64_to_double(result)); |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 Code* target = Code::GetCodeFromTargetAddress(target_address); | 461 Code* target = Code::GetCodeFromTargetAddress(target_address); |
423 if (target->kind() == target_kind) { | 462 if (target->kind() == target_kind) { |
424 ++count; | 463 ++count; |
425 imported_fct = handle(target); | 464 imported_fct = handle(target); |
426 } | 465 } |
427 } | 466 } |
428 CHECK_LE(count, 1); | 467 CHECK_LE(count, 1); |
429 return isolate->heap()->ToBoolean(count == 1); | 468 return isolate->heap()->ToBoolean(count == 1); |
430 } | 469 } |
431 | 470 |
| 471 RUNTIME_FUNCTION(Runtime_SetWasmCompileControls) { |
| 472 HandleScope scope(isolate); |
| 473 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); |
| 474 CHECK(args.length() == 2); |
| 475 CONVERT_ARG_HANDLE_CHECKED(Smi, block_size, 0); |
| 476 CONVERT_BOOLEAN_ARG_CHECKED(allow_async, 1); |
| 477 WasmCompileControls& ctrl = (*g_PerIsolateWasmControls.Pointer())[v8_isolate]; |
| 478 ctrl.AllowAnySizeForAsync = allow_async; |
| 479 ctrl.MaxWasmBufferSize = static_cast<uint32_t>(block_size->value()); |
| 480 isolate->set_allow_wasm_compile_callback(IsWasmCompileAllowed); |
| 481 return isolate->heap()->undefined_value(); |
| 482 } |
| 483 |
| 484 RUNTIME_FUNCTION(Runtime_SetWasmInstantiateControls) { |
| 485 HandleScope scope(isolate); |
| 486 CHECK(args.length() == 0); |
| 487 isolate->set_allow_wasm_instantiate_callback(IsWasmInstantiateAllowed); |
| 488 return isolate->heap()->undefined_value(); |
| 489 } |
| 490 |
432 RUNTIME_FUNCTION(Runtime_NotifyContextDisposed) { | 491 RUNTIME_FUNCTION(Runtime_NotifyContextDisposed) { |
433 HandleScope scope(isolate); | 492 HandleScope scope(isolate); |
434 DCHECK_EQ(0, args.length()); | 493 DCHECK_EQ(0, args.length()); |
435 isolate->heap()->NotifyContextDisposed(true); | 494 isolate->heap()->NotifyContextDisposed(true); |
436 return isolate->heap()->undefined_value(); | 495 return isolate->heap()->undefined_value(); |
437 } | 496 } |
438 | 497 |
439 | 498 |
440 RUNTIME_FUNCTION(Runtime_SetAllocationTimeout) { | 499 RUNTIME_FUNCTION(Runtime_SetAllocationTimeout) { |
441 SealHandleScope shs(isolate); | 500 SealHandleScope shs(isolate); |
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
856 CHECK(HeapObject::cast(*object)->map()->IsMap()); | 915 CHECK(HeapObject::cast(*object)->map()->IsMap()); |
857 } else { | 916 } else { |
858 CHECK(object->IsSmi()); | 917 CHECK(object->IsSmi()); |
859 } | 918 } |
860 #endif | 919 #endif |
861 return isolate->heap()->ToBoolean(true); | 920 return isolate->heap()->ToBoolean(true); |
862 } | 921 } |
863 | 922 |
864 } // namespace internal | 923 } // namespace internal |
865 } // namespace v8 | 924 } // namespace v8 |
OLD | NEW |