From 1d31558f541161725fdc5adc76decfd7806c29b2 Mon Sep 17 00:00:00 2001 From: Clemens Backes Date: Tue, 23 Jun 2020 09:48:53 +0200 Subject: [PATCH] [wasm] Move interpreter to test directory The interpreter is not used in production code any more, hence move it from src/wasm to test/common/wasm. It's still used in unit tests, cctests, and in fuzzers. Because of this move, a few more methods had to be exported via V8_EXPORT_PRIVATE. R=ahaas@chromium.org, yangguo@chromium.org Bug: v8:10389 Change-Id: If626b940a721146c596fd7df4faaea633e710272 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2257226 Commit-Queue: Clemens Backes Reviewed-by: Yang Guo Reviewed-by: Andreas Haas Cr-Commit-Position: refs/heads/master@{#68480} --- BUILD.gn | 14 +++++----- src/debug/debug-frames.cc | 1 - src/execution/futex-emulation.h | 17 +++++++----- src/heap/heap.h | 5 ++-- src/wasm/function-body-decoder-impl.h | 3 ++- src/wasm/function-body-decoder.h | 7 ++--- src/wasm/memory-tracing.h | 6 +++-- src/wasm/module-compiler.h | 3 ++- src/wasm/wasm-debug-evaluate.h | 1 - src/wasm/wasm-debug.cc | 1 - src/wasm/wasm-objects.h | 27 +++++++++---------- test/cctest/BUILD.gn | 2 +- test/cctest/wasm/test-run-wasm-interpreter.cc | 2 +- test/cctest/wasm/test-wasm-debug-evaluate.cc | 1 - test/cctest/wasm/wasm-run-utils.h | 4 +-- {src => test/common}/wasm/wasm-interpreter.cc | 4 +-- {src => test/common}/wasm/wasm-interpreter.h | 2 +- test/common/wasm/wasm-module-runner.cc | 2 +- test/common/wasm/wasm-module-runner.h | 1 - test/fuzzer/wasm-code.cc | 1 - test/fuzzer/wasm-compile.cc | 1 - test/fuzzer/wasm-fuzzer-common.h | 3 ++- test/unittests/BUILD.gn | 1 + .../wasm/control-transfer-unittest.cc | 8 +++--- 24 files changed, 59 insertions(+), 58 deletions(-) rename {src => test/common}/wasm/wasm-interpreter.cc (99%) rename {src => test/common}/wasm/wasm-interpreter.h (99%) diff --git a/BUILD.gn b/BUILD.gn index 32520eac39..6ac9e37d04 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -3197,8 +3197,6 @@ v8_source_set("v8_base_without_compiler") { "src/wasm/wasm-features.h", "src/wasm/wasm-import-wrapper-cache.cc", "src/wasm/wasm-import-wrapper-cache.h", - "src/wasm/wasm-interpreter.cc", - "src/wasm/wasm-interpreter.h", "src/wasm/wasm-js.cc", "src/wasm/wasm-js.h", "src/wasm/wasm-limits.h", @@ -4862,8 +4860,10 @@ v8_source_set("regexp_fuzzer") { v8_fuzzer("regexp_fuzzer") { } -v8_source_set("wasm_module_runner") { +v8_source_set("wasm_test_common") { sources = [ + "test/common/wasm/wasm-interpreter.cc", + "test/common/wasm/wasm-interpreter.h", "test/common/wasm/wasm-module-runner.cc", "test/common/wasm/wasm-module-runner.h", ] @@ -4888,7 +4888,7 @@ v8_source_set("wasm_fuzzer") { deps = [ ":fuzzer_support", ":lib_wasm_fuzzer_common", - ":wasm_module_runner", + ":wasm_test_common", ] configs = [ @@ -4906,7 +4906,7 @@ v8_source_set("wasm_async_fuzzer") { deps = [ ":fuzzer_support", ":lib_wasm_fuzzer_common", - ":wasm_module_runner", + ":wasm_test_common", ] configs = [ @@ -4927,7 +4927,7 @@ v8_source_set("wasm_code_fuzzer") { deps = [ ":fuzzer_support", ":lib_wasm_fuzzer_common", - ":wasm_module_runner", + ":wasm_test_common", ] configs = [ @@ -4968,7 +4968,7 @@ v8_source_set("wasm_compile_fuzzer") { deps = [ ":fuzzer_support", ":lib_wasm_fuzzer_common", - ":wasm_module_runner", + ":wasm_test_common", ] configs = [ diff --git a/src/debug/debug-frames.cc b/src/debug/debug-frames.cc index 3f79f5ee3f..d0ee6bda42 100644 --- a/src/debug/debug-frames.cc +++ b/src/debug/debug-frames.cc @@ -6,7 +6,6 @@ #include "src/builtins/accessors.h" #include "src/execution/frames-inl.h" -#include "src/wasm/wasm-interpreter.h" #include "src/wasm/wasm-objects-inl.h" namespace v8 { diff --git a/src/execution/futex-emulation.h b/src/execution/futex-emulation.h index e65c2fc362..03ad310fd2 100644 --- a/src/execution/futex-emulation.h +++ b/src/execution/futex-emulation.h @@ -126,20 +126,25 @@ class FutexEmulation : public AllStatic { // Same as WaitJs above except it returns 0 (ok), 1 (not equal) and 2 (timed // out) as expected by Wasm. - static Object WaitWasm32(Isolate* isolate, Handle array_buffer, - size_t addr, int32_t value, int64_t rel_timeout_ns); + V8_EXPORT_PRIVATE static Object WaitWasm32(Isolate* isolate, + Handle array_buffer, + size_t addr, int32_t value, + int64_t rel_timeout_ns); // Same as Wait32 above except it checks for an int64_t value in the // array_buffer. - static Object WaitWasm64(Isolate* isolate, Handle array_buffer, - size_t addr, int64_t value, int64_t rel_timeout_ns); + V8_EXPORT_PRIVATE static Object WaitWasm64(Isolate* isolate, + Handle array_buffer, + size_t addr, int64_t value, + int64_t rel_timeout_ns); // Wake |num_waiters_to_wake| threads that are waiting on the given |addr|. // |num_waiters_to_wake| can be kWakeAll, in which case all waiters are // woken. The rest of the waiters will continue to wait. The return value is // the number of woken waiters. - static Object Wake(Handle array_buffer, size_t addr, - uint32_t num_waiters_to_wake); + V8_EXPORT_PRIVATE static Object Wake(Handle array_buffer, + size_t addr, + uint32_t num_waiters_to_wake); // Return the number of threads waiting on |addr|. Should only be used for // testing. diff --git a/src/heap/heap.h b/src/heap/heap.h index 9b57539da4..91214f4039 100644 --- a/src/heap/heap.h +++ b/src/heap/heap.h @@ -460,8 +460,9 @@ class Heap { // Move len non-weak tagged elements from src_slot to dst_slot of dst_object. // The source and destination memory ranges can overlap. - void MoveRange(HeapObject dst_object, ObjectSlot dst_slot, - ObjectSlot src_slot, int len, WriteBarrierMode mode); + V8_EXPORT_PRIVATE void MoveRange(HeapObject dst_object, ObjectSlot dst_slot, + ObjectSlot src_slot, int len, + WriteBarrierMode mode); // Copy len non-weak tagged elements from src_slot to dst_slot of dst_object. // The source and destination memory ranges must not overlap. diff --git a/src/wasm/function-body-decoder-impl.h b/src/wasm/function-body-decoder-impl.h index fe614ff874..90a7696eff 100644 --- a/src/wasm/function-body-decoder-impl.h +++ b/src/wasm/function-body-decoder-impl.h @@ -1665,7 +1665,8 @@ class WasmDecoder : public Decoder { } } - std::pair StackEffect(const byte* pc) { + // TODO(clemensb): This is only used by the interpreter; move there. + V8_EXPORT_PRIVATE std::pair StackEffect(const byte* pc) { WasmOpcode opcode = static_cast(*pc); // Handle "simple" opcodes with a fixed signature first. const FunctionSig* sig = WasmOpcodes::Signature(opcode); diff --git a/src/wasm/function-body-decoder.h b/src/wasm/function-body-decoder.h index 3eb42b8050..2e14d844fa 100644 --- a/src/wasm/function-body-decoder.h +++ b/src/wasm/function-body-decoder.h @@ -82,9 +82,10 @@ V8_EXPORT_PRIVATE unsigned OpcodeLength(const byte* pc, const byte* end); // Be cautious with control opcodes: This function only covers their immediate, // local stack effect (e.g. BrIf pops 1, Br pops 0). Those opcodes can have // non-local stack effect though, which are not covered here. -std::pair StackEffect(const WasmModule* module, - const FunctionSig* sig, - const byte* pc, const byte* end); +// TODO(clemensb): This is only used by the interpreter; move there. +V8_EXPORT_PRIVATE std::pair StackEffect( + const WasmModule* module, const FunctionSig* sig, const byte* pc, + const byte* end); // A simple forward iterator for bytecodes. class V8_EXPORT_PRIVATE BytecodeIterator : public NON_EXPORTED_BASE(Decoder) { diff --git a/src/wasm/memory-tracing.h b/src/wasm/memory-tracing.h index 15457399c1..9ea605b356 100644 --- a/src/wasm/memory-tracing.h +++ b/src/wasm/memory-tracing.h @@ -30,8 +30,10 @@ struct MemoryTracingInfo { // Callback for tracing a memory operation for debugging. // Triggered by --wasm-trace-memory. -void TraceMemoryOperation(ExecutionTier, const MemoryTracingInfo* info, - int func_index, int position, uint8_t* mem_start); +V8_EXPORT_PRIVATE void TraceMemoryOperation(ExecutionTier, + const MemoryTracingInfo* info, + int func_index, int position, + uint8_t* mem_start); } // namespace wasm } // namespace internal diff --git a/src/wasm/module-compiler.h b/src/wasm/module-compiler.h index a3fc4037a2..845e7a343b 100644 --- a/src/wasm/module-compiler.h +++ b/src/wasm/module-compiler.h @@ -63,7 +63,8 @@ WasmCode* CompileImportWrapper( // Triggered by the WasmCompileLazy builtin. The return value indicates whether // compilation was successful. Lazy compilation can fail only if validation is // also lazy. -bool CompileLazy(Isolate*, NativeModule*, int func_index); +// TODO(clemensb): Stop calling this from the interpreter, and don't export. +V8_EXPORT_PRIVATE bool CompileLazy(Isolate*, NativeModule*, int func_index); int GetMaxBackgroundTasks(); diff --git a/src/wasm/wasm-debug-evaluate.h b/src/wasm/wasm-debug-evaluate.h index 31eba51a3c..f4e3aef175 100644 --- a/src/wasm/wasm-debug-evaluate.h +++ b/src/wasm/wasm-debug-evaluate.h @@ -7,7 +7,6 @@ #include "src/base/macros.h" #include "src/handles/maybe-handles.h" -#include "src/wasm/wasm-interpreter.h" #include "src/wasm/wasm-objects.h" namespace v8 { diff --git a/src/wasm/wasm-debug.cc b/src/wasm/wasm-debug.cc index b0b4948be1..6502bf9bce 100644 --- a/src/wasm/wasm-debug.cc +++ b/src/wasm/wasm-debug.cc @@ -20,7 +20,6 @@ #include "src/wasm/baseline/liftoff-register.h" #include "src/wasm/module-decoder.h" #include "src/wasm/wasm-code-manager.h" -#include "src/wasm/wasm-interpreter.h" #include "src/wasm/wasm-limits.h" #include "src/wasm/wasm-module.h" #include "src/wasm/wasm-objects-inl.h" diff --git a/src/wasm/wasm-objects.h b/src/wasm/wasm-objects.h index 6a3870c3b1..f8ead0fe3e 100644 --- a/src/wasm/wasm-objects.h +++ b/src/wasm/wasm-objects.h @@ -66,7 +66,7 @@ class Managed; // - object = target instance, if a Wasm function, tuple if imported // - sig_id = signature id of function // - target = entrypoint to Wasm code or import wrapper code -class IndirectFunctionTableEntry { +class V8_EXPORT_PRIVATE IndirectFunctionTableEntry { public: inline IndirectFunctionTableEntry(Handle, int table_index, int entry_index); @@ -75,9 +75,8 @@ class IndirectFunctionTableEntry { int entry_index); void clear(); - V8_EXPORT_PRIVATE void Set(int sig_id, - Handle target_instance, - int target_func_index); + void Set(int sig_id, Handle target_instance, + int target_func_index); void Set(int sig_id, Address call_target, Object ref); Object object_ref() const; @@ -366,7 +365,7 @@ class WasmGlobalObject : public JSObject { }; // Representation of a WebAssembly.Instance JavaScript-level object. -class WasmInstanceObject : public JSObject { +class V8_EXPORT_PRIVATE WasmInstanceObject : public JSObject { public: DECL_CAST(WasmInstanceObject) @@ -483,16 +482,15 @@ class WasmInstanceObject : public JSObject { kWasmExternalFunctionsOffset, kManagedObjectMapsOffset}; - V8_EXPORT_PRIVATE const wasm::WasmModule* module(); + const wasm::WasmModule* module(); - V8_EXPORT_PRIVATE static bool EnsureIndirectFunctionTableWithMinimumSize( + static bool EnsureIndirectFunctionTableWithMinimumSize( Handle instance, int table_index, uint32_t minimum_size); - V8_EXPORT_PRIVATE void SetRawMemory(byte* mem_start, size_t mem_size); + void SetRawMemory(byte* mem_start, size_t mem_size); - V8_EXPORT_PRIVATE static Handle New( - Isolate*, Handle); + static Handle New(Isolate*, Handle); Address GetCallTarget(uint32_t func_index); @@ -526,10 +524,9 @@ class WasmInstanceObject : public JSObject { // cache of the given {instance}, or creates a new {WasmExportedFunction} if // it does not exist yet. The new {WasmExportedFunction} is added to the // cache of the {instance} immediately. - V8_EXPORT_PRIVATE static Handle - GetOrCreateWasmExternalFunction(Isolate* isolate, - Handle instance, - int function_index); + static Handle GetOrCreateWasmExternalFunction( + Isolate* isolate, Handle instance, + int function_index); static void SetWasmExternalFunction(Isolate* isolate, Handle instance, @@ -614,7 +611,7 @@ class WasmExceptionObject : public JSObject { }; // A Wasm exception that has been thrown out of Wasm code. -class WasmExceptionPackage : public JSReceiver { +class V8_EXPORT_PRIVATE WasmExceptionPackage : public JSReceiver { public: static Handle New( Isolate* isolate, Handle exception_tag, diff --git a/test/cctest/BUILD.gn b/test/cctest/BUILD.gn index 208df35ed0..a55451c6c9 100644 --- a/test/cctest/BUILD.gn +++ b/test/cctest/BUILD.gn @@ -406,7 +406,7 @@ v8_source_set("cctest_sources") { "../..:v8_for_testing", "../..:v8_libbase", "../..:v8_libplatform", - "../..:wasm_module_runner", + "../..:wasm_test_common", "../../tools/debug_helper:v8_debug_helper", "//build/win:default_exe_manifest", ] diff --git a/test/cctest/wasm/test-run-wasm-interpreter.cc b/test/cctest/wasm/test-run-wasm-interpreter.cc index 11984f1f7e..0c9658fc0f 100644 --- a/test/cctest/wasm/test-run-wasm-interpreter.cc +++ b/test/cctest/wasm/test-run-wasm-interpreter.cc @@ -9,11 +9,11 @@ #include #include "src/codegen/assembler-inl.h" -#include "src/wasm/wasm-interpreter.h" #include "test/cctest/cctest.h" #include "test/cctest/compiler/value-helper.h" #include "test/cctest/wasm/wasm-run-utils.h" #include "test/common/wasm/test-signatures.h" +#include "test/common/wasm/wasm-interpreter.h" #include "test/common/wasm/wasm-macro-gen.h" namespace v8 { diff --git a/test/cctest/wasm/test-wasm-debug-evaluate.cc b/test/cctest/wasm/test-wasm-debug-evaluate.cc index e05e93e0c0..b83065d59c 100644 --- a/test/cctest/wasm/test-wasm-debug-evaluate.cc +++ b/test/cctest/wasm/test-wasm-debug-evaluate.cc @@ -23,7 +23,6 @@ #include "src/wasm/wasm-constants.h" #include "src/wasm/wasm-debug-evaluate.h" #include "src/wasm/wasm-debug.h" -#include "src/wasm/wasm-interpreter.h" #include "src/wasm/wasm-module-builder.h" #include "src/wasm/wasm-module.h" #include "src/wasm/wasm-objects-inl.h" diff --git a/test/cctest/wasm/wasm-run-utils.h b/test/cctest/wasm/wasm-run-utils.h index f2a15ffc4a..e5635688a4 100644 --- a/test/cctest/wasm/wasm-run-utils.h +++ b/test/cctest/wasm/wasm-run-utils.h @@ -9,6 +9,7 @@ #include #include #include + #include #include @@ -27,7 +28,6 @@ #include "src/wasm/local-decl-encoder.h" #include "src/wasm/wasm-code-manager.h" #include "src/wasm/wasm-external-refs.h" -#include "src/wasm/wasm-interpreter.h" #include "src/wasm/wasm-js.h" #include "src/wasm/wasm-module.h" #include "src/wasm/wasm-objects-inl.h" @@ -36,12 +36,12 @@ #include "src/wasm/wasm-tier.h" #include "src/zone/accounting-allocator.h" #include "src/zone/zone.h" - #include "test/cctest/cctest.h" #include "test/cctest/compiler/call-tester.h" #include "test/cctest/compiler/graph-and-builders.h" #include "test/cctest/compiler/value-helper.h" #include "test/common/wasm/flag-utils.h" +#include "test/common/wasm/wasm-interpreter.h" namespace v8 { namespace internal { diff --git a/src/wasm/wasm-interpreter.cc b/test/common/wasm/wasm-interpreter.cc similarity index 99% rename from src/wasm/wasm-interpreter.cc rename to test/common/wasm/wasm-interpreter.cc index 6b64acb49e..009bb5f6a4 100644 --- a/src/wasm/wasm-interpreter.cc +++ b/test/common/wasm/wasm-interpreter.cc @@ -2,11 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "test/common/wasm/wasm-interpreter.h" + #include #include -#include "src/wasm/wasm-interpreter.h" - #include "src/base/overflowing-math.h" #include "src/codegen/assembler-inl.h" #include "src/compiler/wasm-compiler.h" diff --git a/src/wasm/wasm-interpreter.h b/test/common/wasm/wasm-interpreter.h similarity index 99% rename from src/wasm/wasm-interpreter.h rename to test/common/wasm/wasm-interpreter.h index e022a3e87d..6636d49f0d 100644 --- a/src/wasm/wasm-interpreter.h +++ b/test/common/wasm/wasm-interpreter.h @@ -42,7 +42,7 @@ struct ControlTransferEntry { using ControlTransferMap = ZoneMap; // An interpreter capable of executing WebAssembly. -class V8_EXPORT_PRIVATE WasmInterpreter { +class WasmInterpreter { public: // State machine for the interpreter: // +----------------------------------------------------------+ diff --git a/test/common/wasm/wasm-module-runner.cc b/test/common/wasm/wasm-module-runner.cc index 2332d8f913..eb5c39110f 100644 --- a/test/common/wasm/wasm-module-runner.cc +++ b/test/common/wasm/wasm-module-runner.cc @@ -11,11 +11,11 @@ #include "src/objects/property-descriptor.h" #include "src/wasm/module-decoder.h" #include "src/wasm/wasm-engine.h" -#include "src/wasm/wasm-interpreter.h" #include "src/wasm/wasm-js.h" #include "src/wasm/wasm-module.h" #include "src/wasm/wasm-objects.h" #include "src/wasm/wasm-result.h" +#include "test/common/wasm/wasm-interpreter.h" namespace v8 { namespace internal { diff --git a/test/common/wasm/wasm-module-runner.h b/test/common/wasm/wasm-module-runner.h index e78b852a7e..9f656cd94b 100644 --- a/test/common/wasm/wasm-module-runner.h +++ b/test/common/wasm/wasm-module-runner.h @@ -7,7 +7,6 @@ #include "src/execution/isolate.h" #include "src/objects/objects.h" -#include "src/wasm/wasm-interpreter.h" #include "src/wasm/wasm-module.h" #include "src/wasm/wasm-objects.h" #include "src/wasm/wasm-result.h" diff --git a/test/fuzzer/wasm-code.cc b/test/fuzzer/wasm-code.cc index b97f96a302..e5d3bbe8e7 100644 --- a/test/fuzzer/wasm-code.cc +++ b/test/fuzzer/wasm-code.cc @@ -8,7 +8,6 @@ #include "src/execution/isolate.h" #include "src/objects/objects-inl.h" #include "src/objects/objects.h" -#include "src/wasm/wasm-interpreter.h" #include "src/wasm/wasm-module-builder.h" #include "test/common/wasm/test-signatures.h" #include "test/fuzzer/wasm-fuzzer-common.h" diff --git a/test/fuzzer/wasm-compile.cc b/test/fuzzer/wasm-compile.cc index 6bc356951d..0c269d4a02 100644 --- a/test/fuzzer/wasm-compile.cc +++ b/test/fuzzer/wasm-compile.cc @@ -13,7 +13,6 @@ #include "src/objects/objects-inl.h" #include "src/objects/objects.h" #include "src/utils/ostreams.h" -#include "src/wasm/wasm-interpreter.h" #include "src/wasm/wasm-module-builder.h" #include "src/wasm/wasm-module.h" #include "src/wasm/wasm-opcodes.h" diff --git a/test/fuzzer/wasm-fuzzer-common.h b/test/fuzzer/wasm-fuzzer-common.h index bca9a2c433..3c6d7c3752 100644 --- a/test/fuzzer/wasm-fuzzer-common.h +++ b/test/fuzzer/wasm-fuzzer-common.h @@ -7,11 +7,12 @@ #include #include + #include #include "src/wasm/module-decoder.h" -#include "src/wasm/wasm-interpreter.h" #include "src/wasm/wasm-module-builder.h" +#include "test/common/wasm/wasm-interpreter.h" namespace v8 { namespace internal { diff --git a/test/unittests/BUILD.gn b/test/unittests/BUILD.gn index 75987f1a16..b42d09d760 100644 --- a/test/unittests/BUILD.gn +++ b/test/unittests/BUILD.gn @@ -392,6 +392,7 @@ v8_source_set("unittests_sources") { "../..:v8_for_testing", "../..:v8_libbase", "../..:v8_libplatform", + "../..:wasm_test_common", "../../third_party/inspector_protocol:crdtp_test", "//build/win:default_exe_manifest", "//testing/gmock", diff --git a/test/unittests/wasm/control-transfer-unittest.cc b/test/unittests/wasm/control-transfer-unittest.cc index 54f22135f1..1c22d8afd0 100644 --- a/test/unittests/wasm/control-transfer-unittest.cc +++ b/test/unittests/wasm/control-transfer-unittest.cc @@ -2,14 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "src/init/v8.h" +#include "test/common/wasm/wasm-interpreter.h" +#include "test/common/wasm/wasm-macro-gen.h" #include "test/unittests/test-utils.h" #include "testing/gmock/include/gmock/gmock.h" -#include "src/init/v8.h" -#include "src/wasm/wasm-interpreter.h" - -#include "test/common/wasm/wasm-macro-gen.h" - using testing::MakeMatcher; using testing::Matcher; using testing::MatcherInterface;