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

Side by Side Diff: src/runtime/runtime-test.cc

Issue 2709613008: Merged: [wasm] Embedder can control what buffers wasm compilation works on. (Closed)
Patch Set: Created 3 years, 9 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 // 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 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 Code* target = Code::GetCodeFromTargetAddress(target_address); 460 Code* target = Code::GetCodeFromTargetAddress(target_address);
422 if (target->kind() == target_kind) { 461 if (target->kind() == target_kind) {
423 ++count; 462 ++count;
424 imported_fct = handle(target); 463 imported_fct = handle(target);
425 } 464 }
426 } 465 }
427 CHECK_LE(count, 1); 466 CHECK_LE(count, 1);
428 return isolate->heap()->ToBoolean(count == 1); 467 return isolate->heap()->ToBoolean(count == 1);
429 } 468 }
430 469
470 RUNTIME_FUNCTION(Runtime_SetWasmCompileControls) {
471 HandleScope scope(isolate);
472 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate);
473 CHECK(args.length() == 2);
474 CONVERT_ARG_HANDLE_CHECKED(Smi, block_size, 0);
475 CONVERT_BOOLEAN_ARG_CHECKED(allow_async, 1);
476 WasmCompileControls& ctrl = (*g_PerIsolateWasmControls.Pointer())[v8_isolate];
477 ctrl.AllowAnySizeForAsync = allow_async;
478 ctrl.MaxWasmBufferSize = static_cast<uint32_t>(block_size->value());
479 isolate->set_allow_wasm_compile_callback(IsWasmCompileAllowed);
480 return isolate->heap()->undefined_value();
481 }
482
483 RUNTIME_FUNCTION(Runtime_SetWasmInstantiateControls) {
484 HandleScope scope(isolate);
485 CHECK(args.length() == 0);
486 isolate->set_allow_wasm_instantiate_callback(IsWasmInstantiateAllowed);
487 return isolate->heap()->undefined_value();
488 }
489
431 RUNTIME_FUNCTION(Runtime_NotifyContextDisposed) { 490 RUNTIME_FUNCTION(Runtime_NotifyContextDisposed) {
432 HandleScope scope(isolate); 491 HandleScope scope(isolate);
433 DCHECK_EQ(0, args.length()); 492 DCHECK_EQ(0, args.length());
434 isolate->heap()->NotifyContextDisposed(true); 493 isolate->heap()->NotifyContextDisposed(true);
435 return isolate->heap()->undefined_value(); 494 return isolate->heap()->undefined_value();
436 } 495 }
437 496
438 497
439 RUNTIME_FUNCTION(Runtime_SetAllocationTimeout) { 498 RUNTIME_FUNCTION(Runtime_SetAllocationTimeout) {
440 SealHandleScope shs(isolate); 499 SealHandleScope shs(isolate);
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
855 CHECK(HeapObject::cast(*object)->map()->IsMap()); 914 CHECK(HeapObject::cast(*object)->map()->IsMap());
856 } else { 915 } else {
857 CHECK(object->IsSmi()); 916 CHECK(object->IsSmi());
858 } 917 }
859 #endif 918 #endif
860 return isolate->heap()->ToBoolean(true); 919 return isolate->heap()->ToBoolean(true);
861 } 920 }
862 921
863 } // namespace internal 922 } // namespace internal
864 } // namespace v8 923 } // namespace v8
OLDNEW
« no previous file with comments | « src/runtime/runtime.h ('k') | src/wasm/wasm-js.cc » ('j') | src/wasm/wasm-js.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698