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

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

Issue 2699843003: [wasm] Embedder can control what buffers wasm compilation works on. (Closed)
Patch Set: RangeError Created 3 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
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 } g_WasmCompileControls;
27
28 bool IsWasmCompileAllowed(v8::Local<v8::Value> value, bool is_async) {
29 return (is_async && g_WasmCompileControls.AllowAnySizeForAsync) ||
30 (v8::Local<v8::ArrayBuffer>::Cast(value)->ByteLength() <=
31 g_WasmCompileControls.MaxWasmBufferSize);
32 }
33
34 // Use the compile controls for instantiation, too
35 bool IsWasmInstantiateAllowed(v8::Local<v8::WasmCompiledModule> module,
36 v8::Local<v8::Value> ffi, bool is_async) {
37 return (is_async && g_WasmCompileControls.AllowAnySizeForAsync) ||
38 (static_cast<uint32_t>(module->GetWasmWireBytes()->Length()) <=
39 g_WasmCompileControls.MaxWasmBufferSize);
40 }
41 } // namespace
42
22 namespace v8 { 43 namespace v8 {
23 namespace internal { 44 namespace internal {
24 45
25 RUNTIME_FUNCTION(Runtime_ConstructDouble) { 46 RUNTIME_FUNCTION(Runtime_ConstructDouble) {
26 HandleScope scope(isolate); 47 HandleScope scope(isolate);
27 DCHECK_EQ(2, args.length()); 48 DCHECK_EQ(2, args.length());
28 CONVERT_NUMBER_CHECKED(uint32_t, hi, Uint32, args[0]); 49 CONVERT_NUMBER_CHECKED(uint32_t, hi, Uint32, args[0]);
29 CONVERT_NUMBER_CHECKED(uint32_t, lo, Uint32, args[1]); 50 CONVERT_NUMBER_CHECKED(uint32_t, lo, Uint32, args[1]);
30 uint64_t result = (static_cast<uint64_t>(hi) << 32) | lo; 51 uint64_t result = (static_cast<uint64_t>(hi) << 32) | lo;
31 return *isolate->factory()->NewNumber(uint64_to_double(result)); 52 return *isolate->factory()->NewNumber(uint64_to_double(result));
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 Code* target = Code::GetCodeFromTargetAddress(target_address); 443 Code* target = Code::GetCodeFromTargetAddress(target_address);
423 if (target->kind() == target_kind) { 444 if (target->kind() == target_kind) {
424 ++count; 445 ++count;
425 imported_fct = handle(target); 446 imported_fct = handle(target);
426 } 447 }
427 } 448 }
428 CHECK_LE(count, 1); 449 CHECK_LE(count, 1);
429 return isolate->heap()->ToBoolean(count == 1); 450 return isolate->heap()->ToBoolean(count == 1);
430 } 451 }
431 452
453 RUNTIME_FUNCTION(Runtime_SetWasmCompileControls) {
454 HandleScope scope(isolate);
455 CHECK(args.length() == 2);
456 CONVERT_ARG_HANDLE_CHECKED(Smi, block_size, 0);
457 CONVERT_BOOLEAN_ARG_CHECKED(allow_async, 1);
458 g_WasmCompileControls.AllowAnySizeForAsync = allow_async;
459 g_WasmCompileControls.MaxWasmBufferSize =
460 static_cast<uint32_t>(block_size->value());
461 isolate->set_allow_wasm_compile_callback(IsWasmCompileAllowed);
462 return isolate->heap()->undefined_value();
463 }
464
465 RUNTIME_FUNCTION(Runtime_SetWasmInstantiateControls) {
466 HandleScope scope(isolate);
467 CHECK(args.length() == 0);
468 isolate->set_allow_wasm_instantiate_callback(IsWasmInstantiateAllowed);
469 return isolate->heap()->undefined_value();
470 }
471
432 RUNTIME_FUNCTION(Runtime_NotifyContextDisposed) { 472 RUNTIME_FUNCTION(Runtime_NotifyContextDisposed) {
433 HandleScope scope(isolate); 473 HandleScope scope(isolate);
434 DCHECK_EQ(0, args.length()); 474 DCHECK_EQ(0, args.length());
435 isolate->heap()->NotifyContextDisposed(true); 475 isolate->heap()->NotifyContextDisposed(true);
436 return isolate->heap()->undefined_value(); 476 return isolate->heap()->undefined_value();
437 } 477 }
438 478
439 479
440 RUNTIME_FUNCTION(Runtime_SetAllocationTimeout) { 480 RUNTIME_FUNCTION(Runtime_SetAllocationTimeout) {
441 SealHandleScope shs(isolate); 481 SealHandleScope shs(isolate);
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
856 CHECK(HeapObject::cast(*object)->map()->IsMap()); 896 CHECK(HeapObject::cast(*object)->map()->IsMap());
857 } else { 897 } else {
858 CHECK(object->IsSmi()); 898 CHECK(object->IsSmi());
859 } 899 }
860 #endif 900 #endif
861 return isolate->heap()->ToBoolean(true); 901 return isolate->heap()->ToBoolean(true);
862 } 902 }
863 903
864 } // namespace internal 904 } // namespace internal
865 } // namespace v8 905 } // 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