2016-01-14 09:48:45 +00:00
|
|
|
// Copyright 2016 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#ifndef WASM_RUN_UTILS_H
|
|
|
|
#define WASM_RUN_UTILS_H
|
|
|
|
|
[wasm] Introduce the TrapIf and TrapUnless operators to generate trap code.
Some instructions in WebAssembly trap for some inputs, which means that the
execution is terminated and (at least at the moment) a JavaScript exception is
thrown. Examples for traps are out-of-bounds memory accesses, or integer
divisions by zero.
Without the TrapIf and TrapUnless operators trap check in WebAssembly introduces 5
TurboFan nodes (branch, if_true, if_false, trap-reason constant, trap-position
constant), in addition to the trap condition itself. Additionally, each
WebAssembly function has four TurboFan nodes (merge, effect_phi, 2 phis) whose
number of inputs is linear to the number of trap checks in the function.
Especially for functions with high numbers of trap checks we observe a
significant slowdown in compilation time, down to 0.22 MiB/s in the sqlite
benchmark instead of the average of 3 MiB/s in other benchmarks. By introducing
a TrapIf common operator only a single node is necessary per trap check, in
addition to the trap condition. Also the nodes which are shared between trap
checks (merge, effect_phi, 2 phis) would disappear. First measurements suggest a
speedup of 30-50% on average.
This CL only implements TrapIf and TrapUnless on x64. The implementation is also
hidden behind the --wasm-trap-if flag.
Please take a special look at how the source position is transfered from the
instruction selector to the code generator, and at the context that is used for
the runtime call.
R=titzer@chromium.org
Review-Url: https://codereview.chromium.org/2562393002
Cr-Commit-Position: refs/heads/master@{#41720}
2016-12-15 13:31:29 +00:00
|
|
|
#include <setjmp.h>
|
2016-01-14 09:48:45 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2016-12-16 10:13:11 +00:00
|
|
|
#include <array>
|
2016-07-25 11:12:42 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2016-01-14 09:48:45 +00:00
|
|
|
#include "src/base/utils/random-number-generator.h"
|
2019-05-21 09:30:15 +00:00
|
|
|
#include "src/codegen/optimized-compilation-info.h"
|
This CL enables precise source positions for all V8 compilers. It merges compiler::SourcePosition and internal::SourcePosition to a single class used throughout the codebase. The new internal::SourcePosition instances store an id identifying an inlined function in addition to a script offset.
SourcePosition::InliningId() refers to a the new table DeoptimizationInputData::InliningPositions(), which provides the following data for every inlining id:
- The inlined SharedFunctionInfo as an offset into DeoptimizationInfo::LiteralArray
- The SourcePosition of the inlining. Recursively, this yields the full inlining stack.
Before the Code object is created, the same information can be found in CompilationInfo::inlined_functions().
If SourcePosition::InliningId() is SourcePosition::kNotInlined, it refers to the outer (non-inlined) function.
So every SourcePosition has full information about its inlining stack, as long as the corresponding Code object is known. The internal represenation of a source position is a positive 64bit integer.
All compilers create now appropriate source positions for inlined functions. In the case of Turbofan, this required using AstGraphBuilderWithPositions for inlined functions too. So this class is now moved to a header file.
At the moment, the additional information in source positions is only used in --trace-deopt and --code-comments. The profiler needs to be updated, at the moment it gets the correct script offsets from the deopt info, but the wrong script id from the reconstructed deopt stack, which can lead to wrong outputs. This should be resolved by making the profiler use the new inlining information for deopts.
I activated the inlined deoptimization tests in test-cpu-profiler.cc for Turbofan, changing them to a case where the deopt stack and the inlining position agree. It is currently still broken for other cases.
The following additional changes were necessary:
- The source position table (internal::SourcePositionTableBuilder etc.) supports now 64bit source positions. Encoding source positions in a single 64bit int together with the difference encoding in the source position table results in very little overhead for the inlining id, since only 12% of the source positions in Octane have a changed inlining id.
- The class HPositionInfo was effectively dead code and is now removed.
- SourcePosition has new printing and information facilities, including computing a full inlining stack.
- I had to rename compiler/source-position.{h,cc} to compiler/compiler-source-position-table.{h,cc} to avoid clashes with the new src/source-position.cc file.
- I wrote the new wrapper PodArray for ByteArray. It is a template working with any POD-type. This is used in DeoptimizationInputData::InliningPositions().
- I removed HInlinedFunctionInfo and HGraph::inlined_function_infos, because they were only used for the now obsolete Crankshaft inlining ids.
- Crankshaft managed a list of inlined functions in Lithium: LChunk::inlined_functions. This is an analog structure to CompilationInfo::inlined_functions. So I removed LChunk::inlined_functions and made Crankshaft use CompilationInfo::inlined_functions instead, because this was necessary to register the offsets into the literal array in a uniform way. This is a safe change because LChunk::inlined_functions has no other uses and the functions in CompilationInfo::inlined_functions have a strictly longer lifespan, being created earlier (in Hydrogen already).
BUG=v8:5432
Review-Url: https://codereview.chromium.org/2451853002
Cr-Commit-Position: refs/heads/master@{#40975}
2016-11-14 17:21:37 +00:00
|
|
|
#include "src/compiler/compiler-source-position-table.h"
|
2016-01-14 09:48:45 +00:00
|
|
|
#include "src/compiler/graph-visualizer.h"
|
2016-02-04 09:40:55 +00:00
|
|
|
#include "src/compiler/int64-lowering.h"
|
2016-01-14 09:48:45 +00:00
|
|
|
#include "src/compiler/js-graph.h"
|
2016-02-18 09:55:25 +00:00
|
|
|
#include "src/compiler/node.h"
|
|
|
|
#include "src/compiler/pipeline.h"
|
2016-01-14 09:48:45 +00:00
|
|
|
#include "src/compiler/wasm-compiler.h"
|
2016-10-10 19:00:31 +00:00
|
|
|
#include "src/compiler/zone-stats.h"
|
2017-03-13 22:12:23 +00:00
|
|
|
#include "src/trap-handler/trap-handler.h"
|
2016-12-21 12:42:06 +00:00
|
|
|
#include "src/wasm/function-body-decoder.h"
|
2017-04-25 10:13:10 +00:00
|
|
|
#include "src/wasm/local-decl-encoder.h"
|
2017-12-05 01:47:59 +00:00
|
|
|
#include "src/wasm/wasm-code-manager.h"
|
[wasm] Introduce the TrapIf and TrapUnless operators to generate trap code.
Some instructions in WebAssembly trap for some inputs, which means that the
execution is terminated and (at least at the moment) a JavaScript exception is
thrown. Examples for traps are out-of-bounds memory accesses, or integer
divisions by zero.
Without the TrapIf and TrapUnless operators trap check in WebAssembly introduces 5
TurboFan nodes (branch, if_true, if_false, trap-reason constant, trap-position
constant), in addition to the trap condition itself. Additionally, each
WebAssembly function has four TurboFan nodes (merge, effect_phi, 2 phis) whose
number of inputs is linear to the number of trap checks in the function.
Especially for functions with high numbers of trap checks we observe a
significant slowdown in compilation time, down to 0.22 MiB/s in the sqlite
benchmark instead of the average of 3 MiB/s in other benchmarks. By introducing
a TrapIf common operator only a single node is necessary per trap check, in
addition to the trap condition. Also the nodes which are shared between trap
checks (merge, effect_phi, 2 phis) would disappear. First measurements suggest a
speedup of 30-50% on average.
This CL only implements TrapIf and TrapUnless on x64. The implementation is also
hidden behind the --wasm-trap-if flag.
Please take a special look at how the source position is transfered from the
instruction selector to the code generator, and at the context that is used for
the runtime call.
R=titzer@chromium.org
Review-Url: https://codereview.chromium.org/2562393002
Cr-Commit-Position: refs/heads/master@{#41720}
2016-12-15 13:31:29 +00:00
|
|
|
#include "src/wasm/wasm-external-refs.h"
|
2016-05-25 08:32:37 +00:00
|
|
|
#include "src/wasm/wasm-interpreter.h"
|
2016-01-14 09:48:45 +00:00
|
|
|
#include "src/wasm/wasm-js.h"
|
|
|
|
#include "src/wasm/wasm-module.h"
|
[wasm] Introduce the WasmContext
The WasmContext struct introduced in this CL is used to store the
mem_size and mem_start address of the wasm memory. These variables can
be accessed at C++ level at graph build time (e.g., initialized during
instance building). When the GrowMemory runtime is invoked, the context
variables can be changed in the WasmContext at C++ level so that the
generated code will load the correct values.
This requires to insert a relocatable pointer only in the
JSToWasmWrapper (and in the other wasm entry points), the value is then
passed from function to function as an automatically added additional
parameter. The WasmContext is then dropped when creating an Interpreter
Entry or when invoking a JavaScript function. This removes the need of
patching the generated code at runtime (i.e., when the memory grows)
with respect to WASM_MEMORY_REFERENCE and WASM_MEMORY_SIZE_REFERENCE.
However, we still need to patch the code at instance build time to patch
the JSToWasmWrappers; in fact the address of the WasmContext is not
known during compilation, but only when the instance is built.
The WasmContext address is passed as the first parameter. This has the
advantage of not having to move the WasmContext around if the function
does not use many registers. This CL also changes the wasm calling
convention so that the first parameter register is different from the
return value register. The WasmContext is attached to every
WasmMemoryObject, to share the same context with multiple instances
sharing the same memory. Moreover, the nodes representing the
WasmContext variables are cached in the SSA environment, similarly to
other local variables that might change during execution. The nodes are
created when initializing the SSA environment and refreshed every time a
grow_memory or a function call happens, so that we are sure that they
always represent the correct mem_size and mem_start variables.
This CL also removes the WasmMemorySize runtime (since it's now possible
to directly retrieve mem_size from the context) and simplifies the
GrowMemory runtime (since every instance now has a memory_object).
R=ahaas@chromium.org,clemensh@chromium.org
CC=gdeepti@chromium.org
Change-Id: I3f058e641284f5a1bbbfc35a64c88da6ff08e240
Reviewed-on: https://chromium-review.googlesource.com/671008
Commit-Queue: Enrico Bacis <enricobacis@google.com>
Reviewed-by: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#48209}
2017-09-28 14:59:37 +00:00
|
|
|
#include "src/wasm/wasm-objects-inl.h"
|
2017-09-08 08:39:19 +00:00
|
|
|
#include "src/wasm/wasm-objects.h"
|
2016-01-14 09:48:45 +00:00
|
|
|
#include "src/wasm/wasm-opcodes.h"
|
2018-08-21 15:01:31 +00:00
|
|
|
#include "src/wasm/wasm-tier.h"
|
2017-05-31 13:31:52 +00:00
|
|
|
#include "src/zone/accounting-allocator.h"
|
2016-09-20 16:07:25 +00:00
|
|
|
#include "src/zone/zone.h"
|
2016-02-18 09:55:25 +00:00
|
|
|
|
2016-01-14 09:48:45 +00:00
|
|
|
#include "test/cctest/cctest.h"
|
2016-02-18 09:55:25 +00:00
|
|
|
#include "test/cctest/compiler/call-tester.h"
|
2019-05-07 09:18:58 +00:00
|
|
|
#include "test/cctest/compiler/graph-and-builders.h"
|
2019-01-28 13:59:04 +00:00
|
|
|
#include "test/cctest/compiler/value-helper.h"
|
2017-05-31 13:31:52 +00:00
|
|
|
#include "test/common/wasm/flag-utils.h"
|
2016-01-14 09:48:45 +00:00
|
|
|
|
2017-09-01 12:57:34 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace wasm {
|
|
|
|
|
2019-06-17 09:26:18 +00:00
|
|
|
using base::ReadLittleEndianValue;
|
|
|
|
using base::WriteLittleEndianValue;
|
|
|
|
|
2017-09-01 12:57:34 +00:00
|
|
|
constexpr uint32_t kMaxFunctions = 10;
|
|
|
|
constexpr uint32_t kMaxGlobalsSize = 128;
|
2016-02-18 15:58:02 +00:00
|
|
|
|
2017-09-01 12:57:34 +00:00
|
|
|
using compiler::CallDescriptor;
|
|
|
|
using compiler::MachineTypeForC;
|
|
|
|
using compiler::Node;
|
|
|
|
|
2016-01-14 09:48:45 +00:00
|
|
|
// TODO(titzer): check traps more robustly in tests.
|
2017-12-02 00:30:37 +00:00
|
|
|
// Currently, in tests, we just return 0xDEADBEEF from the function in which
|
2016-01-14 09:48:45 +00:00
|
|
|
// the trap occurs if the runtime context is not available to throw a JavaScript
|
|
|
|
// exception.
|
|
|
|
#define CHECK_TRAP32(x) \
|
2017-12-02 00:30:37 +00:00
|
|
|
CHECK_EQ(0xDEADBEEF, (bit_cast<uint32_t>(x)) & 0xFFFFFFFF)
|
2016-01-14 09:48:45 +00:00
|
|
|
#define CHECK_TRAP64(x) \
|
2017-12-02 00:30:37 +00:00
|
|
|
CHECK_EQ(0xDEADBEEFDEADBEEF, (bit_cast<uint64_t>(x)) & 0xFFFFFFFFFFFFFFFF)
|
2016-01-14 09:48:45 +00:00
|
|
|
#define CHECK_TRAP(x) CHECK_TRAP32(x)
|
|
|
|
|
2016-02-18 09:55:25 +00:00
|
|
|
#define WASM_WRAPPER_RETURN_VALUE 8754
|
|
|
|
|
2016-02-23 16:30:27 +00:00
|
|
|
#define BUILD(r, ...) \
|
|
|
|
do { \
|
|
|
|
byte code[] = {__VA_ARGS__}; \
|
|
|
|
r.Build(code, code + arraysize(code)); \
|
|
|
|
} while (false)
|
|
|
|
|
2018-04-06 10:18:18 +00:00
|
|
|
// For tests that must manually import a JSFunction with source code.
|
|
|
|
struct ManuallyImportedJSFunction {
|
|
|
|
FunctionSig* sig;
|
|
|
|
Handle<JSFunction> js_function;
|
|
|
|
};
|
|
|
|
|
2017-11-28 22:25:36 +00:00
|
|
|
// A Wasm module builder. Globals are pre-set, however, memory and code may be
|
2017-08-07 17:17:06 +00:00
|
|
|
// progressively added by a test. In turn, we piecemeal update the runtime
|
2018-06-27 12:50:53 +00:00
|
|
|
// objects, i.e. {WasmInstanceObject}, {WasmModuleObject} and, if necessary,
|
2017-08-07 17:17:06 +00:00
|
|
|
// the interpreter.
|
2017-08-19 16:34:11 +00:00
|
|
|
class TestingModuleBuilder {
|
2016-01-14 09:48:45 +00:00
|
|
|
public:
|
2018-08-21 15:01:31 +00:00
|
|
|
TestingModuleBuilder(Zone*, ManuallyImportedJSFunction*, ExecutionTier,
|
2018-04-19 10:16:37 +00:00
|
|
|
RuntimeExceptionSupport, LowerSimd);
|
2016-01-14 09:48:45 +00:00
|
|
|
|
2019-07-19 11:10:49 +00:00
|
|
|
void ChangeOriginToAsmjs() { test_module_->origin = kAsmJsSloppyOrigin; }
|
2016-10-27 16:02:24 +00:00
|
|
|
|
2019-02-20 02:02:12 +00:00
|
|
|
byte* AddMemory(uint32_t size, SharedFlag shared = SharedFlag::kNotShared);
|
2016-01-14 09:48:45 +00:00
|
|
|
|
2018-06-04 12:01:49 +00:00
|
|
|
size_t CodeTableLength() const { return native_module_->num_functions(); }
|
[wasm] Consolidate ownership of instantiation/specialization parameters
This CL consolidates ownership of parameters used to compile code (which
we always specialize) in 2 places:
- ModuleEnv for compile-time data
- WasmCompiledModule for runtime data
The parameters in question are: memory size and start; globals start;
address of indirect function tables (and their signatures, respectively);
and address to be used for wasm call sites.
Ideally, we'd collapse this down to one place, however, we need
specialization data to survive serialization. We can achieve this we get off
the GC heap and use a different wasm code serializer.
The CL:
- removes aliasing of parts of the specialization data, and moves
to using ModuleEnv as a token of passing around compile-time data, instead
of a mixture of ModuleEnv, WasmInstance, and some other structures. ModuleEnv
is responsible for providing a consistent view of the specialization data,
e.g. valid memory sizes (multiples of page size), and matching sized function
tables and signatures.
- removes WasmInstance, as its data is now contained by ModuleEnv.
- removes ModuleBytesEnv. We now pass the wire bytes explicitly. They can't
always be assumed as present (e.g. streaming compilation), and probably more
refactoring may need to happen once streaming compilation lands and we
better understand our dependencies.
Change-Id: Id7e6f2cf29e51b5756eee8b6f8827fb1f375e5c3
Reviewed-on: https://chromium-review.googlesource.com/592531
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Ben Titzer <titzer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47229}
2017-08-08 15:04:29 +00:00
|
|
|
|
2016-01-14 09:48:45 +00:00
|
|
|
template <typename T>
|
2016-06-16 22:21:30 +00:00
|
|
|
T* AddMemoryElems(uint32_t count) {
|
2016-01-14 09:48:45 +00:00
|
|
|
AddMemory(count * sizeof(T));
|
|
|
|
return raw_mem_start<T>();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2016-12-16 10:13:11 +00:00
|
|
|
T* AddGlobal(
|
2018-04-24 13:07:51 +00:00
|
|
|
ValueType type = ValueTypes::ValueTypeFor(MachineTypeForC<T>())) {
|
2016-07-21 12:34:28 +00:00
|
|
|
const WasmGlobal* global = AddGlobal(type);
|
Revert "Revert "[wasm] Move the ModuleEnv to compiler and make it immutable.""
This reverts commit e79d4f06fd329ff841c6661cc17dc0f69e27d8b7.
Reason for revert: Fixed compile error
Original change's description:
> Revert "[wasm] Move the ModuleEnv to compiler and make it immutable."
>
> This reverts commit d04660db3f9289617eab2ab494af7ab7c48b9ab3.
>
> Reason for revert: Suspect for blocking the roll:
> https://chromium-review.googlesource.com/c/621191
>
> See:
> https://build.chromium.org/p/tryserver.chromium.win/builders/win_optional_gpu_tests_rel/builds/13583
>
> Original change's description:
> > [wasm] Move the ModuleEnv to compiler and make it immutable.
> >
> > This CL (finally) makes the contract between the compiler and the module
> > environment clear. In order to compile a function, the caller must provide
> > an instance of the compiler::ModuleEnv struct, which contains references
> > to code, function and signature tables, memory start, etc.
> >
> > R=mtrofin@chromium.org,ahaas@chromium.org
> >
> > Bug:
> > Change-Id: I68e44d5da2c5ad44dad402029c2e57f2d5d25b4f
> > Reviewed-on: https://chromium-review.googlesource.com/613880
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47418}
>
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
>
> Change-Id: I60a369a43121720fbb13ea6c2ec6ca948d60a20b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622547
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47451}
TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
Change-Id: Ie0efa6204c41b2cb672586a7ac0a622ca13ce5fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622033
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47453}
2017-08-19 15:55:52 +00:00
|
|
|
return reinterpret_cast<T*>(globals_data_ + global->offset);
|
2016-01-14 09:48:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
byte AddSignature(FunctionSig* sig) {
|
2018-04-26 14:37:05 +00:00
|
|
|
DCHECK_EQ(test_module_->signatures.size(),
|
|
|
|
test_module_->signature_ids.size());
|
|
|
|
test_module_->signatures.push_back(sig);
|
2018-07-12 11:41:34 +00:00
|
|
|
auto canonical_sig_num = test_module_->signature_map.FindOrInsert(*sig);
|
2018-04-26 14:37:05 +00:00
|
|
|
test_module_->signature_ids.push_back(canonical_sig_num);
|
|
|
|
size_t size = test_module_->signatures.size();
|
2017-09-19 11:02:31 +00:00
|
|
|
CHECK_GT(127, size);
|
2016-01-14 09:48:45 +00:00
|
|
|
return static_cast<byte>(size - 1);
|
|
|
|
}
|
|
|
|
|
2019-03-13 19:22:40 +00:00
|
|
|
uint32_t mem_size() { return mem_size_; }
|
|
|
|
|
2016-01-14 09:48:45 +00:00
|
|
|
template <typename T>
|
|
|
|
T* raw_mem_start() {
|
Revert "Revert "[wasm] Move the ModuleEnv to compiler and make it immutable.""
This reverts commit e79d4f06fd329ff841c6661cc17dc0f69e27d8b7.
Reason for revert: Fixed compile error
Original change's description:
> Revert "[wasm] Move the ModuleEnv to compiler and make it immutable."
>
> This reverts commit d04660db3f9289617eab2ab494af7ab7c48b9ab3.
>
> Reason for revert: Suspect for blocking the roll:
> https://chromium-review.googlesource.com/c/621191
>
> See:
> https://build.chromium.org/p/tryserver.chromium.win/builders/win_optional_gpu_tests_rel/builds/13583
>
> Original change's description:
> > [wasm] Move the ModuleEnv to compiler and make it immutable.
> >
> > This CL (finally) makes the contract between the compiler and the module
> > environment clear. In order to compile a function, the caller must provide
> > an instance of the compiler::ModuleEnv struct, which contains references
> > to code, function and signature tables, memory start, etc.
> >
> > R=mtrofin@chromium.org,ahaas@chromium.org
> >
> > Bug:
> > Change-Id: I68e44d5da2c5ad44dad402029c2e57f2d5d25b4f
> > Reviewed-on: https://chromium-review.googlesource.com/613880
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47418}
>
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
>
> Change-Id: I60a369a43121720fbb13ea6c2ec6ca948d60a20b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622547
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47451}
TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
Change-Id: Ie0efa6204c41b2cb672586a7ac0a622ca13ce5fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622033
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47453}
2017-08-19 15:55:52 +00:00
|
|
|
DCHECK(mem_start_);
|
|
|
|
return reinterpret_cast<T*>(mem_start_);
|
2016-01-14 09:48:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
T* raw_mem_end() {
|
Revert "Revert "[wasm] Move the ModuleEnv to compiler and make it immutable.""
This reverts commit e79d4f06fd329ff841c6661cc17dc0f69e27d8b7.
Reason for revert: Fixed compile error
Original change's description:
> Revert "[wasm] Move the ModuleEnv to compiler and make it immutable."
>
> This reverts commit d04660db3f9289617eab2ab494af7ab7c48b9ab3.
>
> Reason for revert: Suspect for blocking the roll:
> https://chromium-review.googlesource.com/c/621191
>
> See:
> https://build.chromium.org/p/tryserver.chromium.win/builders/win_optional_gpu_tests_rel/builds/13583
>
> Original change's description:
> > [wasm] Move the ModuleEnv to compiler and make it immutable.
> >
> > This CL (finally) makes the contract between the compiler and the module
> > environment clear. In order to compile a function, the caller must provide
> > an instance of the compiler::ModuleEnv struct, which contains references
> > to code, function and signature tables, memory start, etc.
> >
> > R=mtrofin@chromium.org,ahaas@chromium.org
> >
> > Bug:
> > Change-Id: I68e44d5da2c5ad44dad402029c2e57f2d5d25b4f
> > Reviewed-on: https://chromium-review.googlesource.com/613880
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47418}
>
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
>
> Change-Id: I60a369a43121720fbb13ea6c2ec6ca948d60a20b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622547
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47451}
TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
Change-Id: Ie0efa6204c41b2cb672586a7ac0a622ca13ce5fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622033
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47453}
2017-08-19 15:55:52 +00:00
|
|
|
DCHECK(mem_start_);
|
|
|
|
return reinterpret_cast<T*>(mem_start_ + mem_size_);
|
2016-01-14 09:48:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
T raw_mem_at(int i) {
|
Revert "Revert "[wasm] Move the ModuleEnv to compiler and make it immutable.""
This reverts commit e79d4f06fd329ff841c6661cc17dc0f69e27d8b7.
Reason for revert: Fixed compile error
Original change's description:
> Revert "[wasm] Move the ModuleEnv to compiler and make it immutable."
>
> This reverts commit d04660db3f9289617eab2ab494af7ab7c48b9ab3.
>
> Reason for revert: Suspect for blocking the roll:
> https://chromium-review.googlesource.com/c/621191
>
> See:
> https://build.chromium.org/p/tryserver.chromium.win/builders/win_optional_gpu_tests_rel/builds/13583
>
> Original change's description:
> > [wasm] Move the ModuleEnv to compiler and make it immutable.
> >
> > This CL (finally) makes the contract between the compiler and the module
> > environment clear. In order to compile a function, the caller must provide
> > an instance of the compiler::ModuleEnv struct, which contains references
> > to code, function and signature tables, memory start, etc.
> >
> > R=mtrofin@chromium.org,ahaas@chromium.org
> >
> > Bug:
> > Change-Id: I68e44d5da2c5ad44dad402029c2e57f2d5d25b4f
> > Reviewed-on: https://chromium-review.googlesource.com/613880
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47418}
>
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
>
> Change-Id: I60a369a43121720fbb13ea6c2ec6ca948d60a20b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622547
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47451}
TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
Change-Id: Ie0efa6204c41b2cb672586a7ac0a622ca13ce5fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622033
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47453}
2017-08-19 15:55:52 +00:00
|
|
|
DCHECK(mem_start_);
|
|
|
|
return ReadMemory(&(reinterpret_cast<T*>(mem_start_)[i]));
|
2016-01-14 09:48:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
T raw_val_at(int i) {
|
Revert "Revert "[wasm] Move the ModuleEnv to compiler and make it immutable.""
This reverts commit e79d4f06fd329ff841c6661cc17dc0f69e27d8b7.
Reason for revert: Fixed compile error
Original change's description:
> Revert "[wasm] Move the ModuleEnv to compiler and make it immutable."
>
> This reverts commit d04660db3f9289617eab2ab494af7ab7c48b9ab3.
>
> Reason for revert: Suspect for blocking the roll:
> https://chromium-review.googlesource.com/c/621191
>
> See:
> https://build.chromium.org/p/tryserver.chromium.win/builders/win_optional_gpu_tests_rel/builds/13583
>
> Original change's description:
> > [wasm] Move the ModuleEnv to compiler and make it immutable.
> >
> > This CL (finally) makes the contract between the compiler and the module
> > environment clear. In order to compile a function, the caller must provide
> > an instance of the compiler::ModuleEnv struct, which contains references
> > to code, function and signature tables, memory start, etc.
> >
> > R=mtrofin@chromium.org,ahaas@chromium.org
> >
> > Bug:
> > Change-Id: I68e44d5da2c5ad44dad402029c2e57f2d5d25b4f
> > Reviewed-on: https://chromium-review.googlesource.com/613880
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47418}
>
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
>
> Change-Id: I60a369a43121720fbb13ea6c2ec6ca948d60a20b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622547
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47451}
TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
Change-Id: Ie0efa6204c41b2cb672586a7ac0a622ca13ce5fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622033
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47453}
2017-08-19 15:55:52 +00:00
|
|
|
return ReadMemory(reinterpret_cast<T*>(mem_start_ + i));
|
2016-06-29 09:25:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void WriteMemory(T* p, T val) {
|
2018-04-13 22:28:05 +00:00
|
|
|
WriteLittleEndianValue<T>(reinterpret_cast<Address>(p), val);
|
2016-06-29 09:25:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
T ReadMemory(T* p) {
|
2018-04-13 22:28:05 +00:00
|
|
|
return ReadLittleEndianValue<T>(reinterpret_cast<Address>(p));
|
2016-01-14 09:48:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Zero-initialize the memory.
|
|
|
|
void BlankMemory() {
|
|
|
|
byte* raw = raw_mem_start<byte>();
|
Revert "Revert "[wasm] Move the ModuleEnv to compiler and make it immutable.""
This reverts commit e79d4f06fd329ff841c6661cc17dc0f69e27d8b7.
Reason for revert: Fixed compile error
Original change's description:
> Revert "[wasm] Move the ModuleEnv to compiler and make it immutable."
>
> This reverts commit d04660db3f9289617eab2ab494af7ab7c48b9ab3.
>
> Reason for revert: Suspect for blocking the roll:
> https://chromium-review.googlesource.com/c/621191
>
> See:
> https://build.chromium.org/p/tryserver.chromium.win/builders/win_optional_gpu_tests_rel/builds/13583
>
> Original change's description:
> > [wasm] Move the ModuleEnv to compiler and make it immutable.
> >
> > This CL (finally) makes the contract between the compiler and the module
> > environment clear. In order to compile a function, the caller must provide
> > an instance of the compiler::ModuleEnv struct, which contains references
> > to code, function and signature tables, memory start, etc.
> >
> > R=mtrofin@chromium.org,ahaas@chromium.org
> >
> > Bug:
> > Change-Id: I68e44d5da2c5ad44dad402029c2e57f2d5d25b4f
> > Reviewed-on: https://chromium-review.googlesource.com/613880
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47418}
>
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
>
> Change-Id: I60a369a43121720fbb13ea6c2ec6ca948d60a20b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622547
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47451}
TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
Change-Id: Ie0efa6204c41b2cb672586a7ac0a622ca13ce5fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622033
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47453}
2017-08-19 15:55:52 +00:00
|
|
|
memset(raw, 0, mem_size_);
|
2016-01-14 09:48:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Pseudo-randomly intialize the memory.
|
|
|
|
void RandomizeMemory(unsigned int seed = 88) {
|
|
|
|
byte* raw = raw_mem_start<byte>();
|
|
|
|
byte* end = raw_mem_end<byte>();
|
|
|
|
v8::base::RandomNumberGenerator rng;
|
|
|
|
rng.SetSeed(seed);
|
|
|
|
rng.NextBytes(raw, end - raw);
|
|
|
|
}
|
|
|
|
|
2017-08-10 12:45:45 +00:00
|
|
|
void SetMaxMemPages(uint32_t maximum_pages) {
|
2018-04-26 14:37:05 +00:00
|
|
|
test_module_->maximum_pages = maximum_pages;
|
[wasm] Introduce the WasmContext
The WasmContext struct introduced in this CL is used to store the
mem_size and mem_start address of the wasm memory. These variables can
be accessed at C++ level at graph build time (e.g., initialized during
instance building). When the GrowMemory runtime is invoked, the context
variables can be changed in the WasmContext at C++ level so that the
generated code will load the correct values.
This requires to insert a relocatable pointer only in the
JSToWasmWrapper (and in the other wasm entry points), the value is then
passed from function to function as an automatically added additional
parameter. The WasmContext is then dropped when creating an Interpreter
Entry or when invoking a JavaScript function. This removes the need of
patching the generated code at runtime (i.e., when the memory grows)
with respect to WASM_MEMORY_REFERENCE and WASM_MEMORY_SIZE_REFERENCE.
However, we still need to patch the code at instance build time to patch
the JSToWasmWrappers; in fact the address of the WasmContext is not
known during compilation, but only when the instance is built.
The WasmContext address is passed as the first parameter. This has the
advantage of not having to move the WasmContext around if the function
does not use many registers. This CL also changes the wasm calling
convention so that the first parameter register is different from the
return value register. The WasmContext is attached to every
WasmMemoryObject, to share the same context with multiple instances
sharing the same memory. Moreover, the nodes representing the
WasmContext variables are cached in the SSA environment, similarly to
other local variables that might change during execution. The nodes are
created when initializing the SSA environment and refreshed every time a
grow_memory or a function call happens, so that we are sure that they
always represent the correct mem_size and mem_start variables.
This CL also removes the WasmMemorySize runtime (since it's now possible
to directly retrieve mem_size from the context) and simplifies the
GrowMemory runtime (since every instance now has a memory_object).
R=ahaas@chromium.org,clemensh@chromium.org
CC=gdeepti@chromium.org
Change-Id: I3f058e641284f5a1bbbfc35a64c88da6ff08e240
Reviewed-on: https://chromium-review.googlesource.com/671008
Commit-Queue: Enrico Bacis <enricobacis@google.com>
Reviewed-by: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#48209}
2017-09-28 14:59:37 +00:00
|
|
|
if (instance_object()->has_memory_object()) {
|
|
|
|
instance_object()->memory_object().set_maximum_pages(maximum_pages);
|
|
|
|
}
|
2017-01-11 17:24:00 +00:00
|
|
|
}
|
|
|
|
|
2018-04-26 14:37:05 +00:00
|
|
|
void SetHasSharedMemory() { test_module_->has_shared_memory = true; }
|
2017-09-14 06:14:48 +00:00
|
|
|
|
2018-06-20 06:33:57 +00:00
|
|
|
enum FunctionType { kImport, kWasm };
|
|
|
|
uint32_t AddFunction(FunctionSig* sig, const char* name, FunctionType type);
|
2016-02-18 15:58:02 +00:00
|
|
|
|
2019-05-22 14:04:36 +00:00
|
|
|
// Freezes the signature map of the module and allocates the storage for
|
|
|
|
// export wrappers.
|
|
|
|
void FreezeSignatureMapAndInitializeWrapperCache();
|
|
|
|
|
2019-01-28 14:23:10 +00:00
|
|
|
// Wrap the code so it can be called as a JS function.
|
2017-09-01 12:57:34 +00:00
|
|
|
Handle<JSFunction> WrapCode(uint32_t index);
|
2016-04-19 12:23:00 +00:00
|
|
|
|
2019-03-21 15:55:09 +00:00
|
|
|
// If function_indexes is {nullptr}, the contents of the table will be
|
|
|
|
// initialized with null functions.
|
2018-01-16 12:25:31 +00:00
|
|
|
void AddIndirectFunctionTable(const uint16_t* function_indexes,
|
2017-09-01 12:57:34 +00:00
|
|
|
uint32_t table_size);
|
2016-07-28 04:56:56 +00:00
|
|
|
|
2017-09-01 12:57:34 +00:00
|
|
|
uint32_t AddBytes(Vector<const byte> bytes);
|
2016-12-19 17:22:55 +00:00
|
|
|
|
2019-01-28 13:59:04 +00:00
|
|
|
uint32_t AddException(FunctionSig* sig);
|
|
|
|
|
2019-03-13 19:22:40 +00:00
|
|
|
uint32_t AddPassiveDataSegment(Vector<const byte> bytes);
|
2019-04-05 19:04:37 +00:00
|
|
|
uint32_t AddPassiveElementSegment(const std::vector<uint32_t>& entries);
|
2019-03-13 19:22:40 +00:00
|
|
|
|
[wasm] Consolidate ownership of instantiation/specialization parameters
This CL consolidates ownership of parameters used to compile code (which
we always specialize) in 2 places:
- ModuleEnv for compile-time data
- WasmCompiledModule for runtime data
The parameters in question are: memory size and start; globals start;
address of indirect function tables (and their signatures, respectively);
and address to be used for wasm call sites.
Ideally, we'd collapse this down to one place, however, we need
specialization data to survive serialization. We can achieve this we get off
the GC heap and use a different wasm code serializer.
The CL:
- removes aliasing of parts of the specialization data, and moves
to using ModuleEnv as a token of passing around compile-time data, instead
of a mixture of ModuleEnv, WasmInstance, and some other structures. ModuleEnv
is responsible for providing a consistent view of the specialization data,
e.g. valid memory sizes (multiples of page size), and matching sized function
tables and signatures.
- removes WasmInstance, as its data is now contained by ModuleEnv.
- removes ModuleBytesEnv. We now pass the wire bytes explicitly. They can't
always be assumed as present (e.g. streaming compilation), and probably more
refactoring may need to happen once streaming compilation lands and we
better understand our dependencies.
Change-Id: Id7e6f2cf29e51b5756eee8b6f8827fb1f375e5c3
Reviewed-on: https://chromium-review.googlesource.com/592531
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Ben Titzer <titzer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47229}
2017-08-08 15:04:29 +00:00
|
|
|
WasmFunction* GetFunctionAt(int index) {
|
2018-04-26 14:37:05 +00:00
|
|
|
return &test_module_->functions[index];
|
[wasm] Consolidate ownership of instantiation/specialization parameters
This CL consolidates ownership of parameters used to compile code (which
we always specialize) in 2 places:
- ModuleEnv for compile-time data
- WasmCompiledModule for runtime data
The parameters in question are: memory size and start; globals start;
address of indirect function tables (and their signatures, respectively);
and address to be used for wasm call sites.
Ideally, we'd collapse this down to one place, however, we need
specialization data to survive serialization. We can achieve this we get off
the GC heap and use a different wasm code serializer.
The CL:
- removes aliasing of parts of the specialization data, and moves
to using ModuleEnv as a token of passing around compile-time data, instead
of a mixture of ModuleEnv, WasmInstance, and some other structures. ModuleEnv
is responsible for providing a consistent view of the specialization data,
e.g. valid memory sizes (multiples of page size), and matching sized function
tables and signatures.
- removes WasmInstance, as its data is now contained by ModuleEnv.
- removes ModuleBytesEnv. We now pass the wire bytes explicitly. They can't
always be assumed as present (e.g. streaming compilation), and probably more
refactoring may need to happen once streaming compilation lands and we
better understand our dependencies.
Change-Id: Id7e6f2cf29e51b5756eee8b6f8827fb1f375e5c3
Reviewed-on: https://chromium-review.googlesource.com/592531
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Ben Titzer <titzer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47229}
2017-08-08 15:04:29 +00:00
|
|
|
}
|
2016-01-21 16:10:53 +00:00
|
|
|
|
2018-05-07 13:37:03 +00:00
|
|
|
WasmInterpreter* interpreter() const { return interpreter_; }
|
|
|
|
bool interpret() const { return interpreter_ != nullptr; }
|
|
|
|
LowerSimd lower_simd() const { return lower_simd_; }
|
|
|
|
Isolate* isolate() const { return isolate_; }
|
|
|
|
Handle<WasmInstanceObject> instance_object() const {
|
|
|
|
return instance_object_;
|
|
|
|
}
|
2018-08-02 09:50:08 +00:00
|
|
|
WasmCode* GetFunctionCode(uint32_t index) const {
|
2019-04-10 14:56:06 +00:00
|
|
|
return native_module_->GetCode(index);
|
2018-05-07 13:37:03 +00:00
|
|
|
}
|
|
|
|
Address globals_start() const {
|
|
|
|
return reinterpret_cast<Address>(globals_data_);
|
2017-11-28 22:25:36 +00:00
|
|
|
}
|
2019-01-28 14:23:10 +00:00
|
|
|
|
|
|
|
void SetExecutable() { native_module_->SetExecutable(true); }
|
Revert "Revert "[wasm] Move the ModuleEnv to compiler and make it immutable.""
This reverts commit e79d4f06fd329ff841c6661cc17dc0f69e27d8b7.
Reason for revert: Fixed compile error
Original change's description:
> Revert "[wasm] Move the ModuleEnv to compiler and make it immutable."
>
> This reverts commit d04660db3f9289617eab2ab494af7ab7c48b9ab3.
>
> Reason for revert: Suspect for blocking the roll:
> https://chromium-review.googlesource.com/c/621191
>
> See:
> https://build.chromium.org/p/tryserver.chromium.win/builders/win_optional_gpu_tests_rel/builds/13583
>
> Original change's description:
> > [wasm] Move the ModuleEnv to compiler and make it immutable.
> >
> > This CL (finally) makes the contract between the compiler and the module
> > environment clear. In order to compile a function, the caller must provide
> > an instance of the compiler::ModuleEnv struct, which contains references
> > to code, function and signature tables, memory start, etc.
> >
> > R=mtrofin@chromium.org,ahaas@chromium.org
> >
> > Bug:
> > Change-Id: I68e44d5da2c5ad44dad402029c2e57f2d5d25b4f
> > Reviewed-on: https://chromium-review.googlesource.com/613880
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47418}
>
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
>
> Change-Id: I60a369a43121720fbb13ea6c2ec6ca948d60a20b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622547
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47451}
TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
Change-Id: Ie0efa6204c41b2cb672586a7ac0a622ca13ce5fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622033
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47453}
2017-08-19 15:55:52 +00:00
|
|
|
|
2018-10-23 11:56:12 +00:00
|
|
|
CompilationEnv CreateCompilationEnv();
|
2016-05-25 08:32:37 +00:00
|
|
|
|
2018-08-21 15:01:31 +00:00
|
|
|
ExecutionTier execution_tier() const { return execution_tier_; }
|
2017-10-25 12:46:43 +00:00
|
|
|
|
2018-04-19 10:16:37 +00:00
|
|
|
RuntimeExceptionSupport runtime_exception_support() const {
|
2017-09-12 12:39:42 +00:00
|
|
|
return runtime_exception_support_;
|
|
|
|
}
|
|
|
|
|
2016-01-14 09:48:45 +00:00
|
|
|
private:
|
2018-04-26 14:37:05 +00:00
|
|
|
std::shared_ptr<WasmModule> test_module_;
|
Revert "Revert "[wasm] Move the ModuleEnv to compiler and make it immutable.""
This reverts commit e79d4f06fd329ff841c6661cc17dc0f69e27d8b7.
Reason for revert: Fixed compile error
Original change's description:
> Revert "[wasm] Move the ModuleEnv to compiler and make it immutable."
>
> This reverts commit d04660db3f9289617eab2ab494af7ab7c48b9ab3.
>
> Reason for revert: Suspect for blocking the roll:
> https://chromium-review.googlesource.com/c/621191
>
> See:
> https://build.chromium.org/p/tryserver.chromium.win/builders/win_optional_gpu_tests_rel/builds/13583
>
> Original change's description:
> > [wasm] Move the ModuleEnv to compiler and make it immutable.
> >
> > This CL (finally) makes the contract between the compiler and the module
> > environment clear. In order to compile a function, the caller must provide
> > an instance of the compiler::ModuleEnv struct, which contains references
> > to code, function and signature tables, memory start, etc.
> >
> > R=mtrofin@chromium.org,ahaas@chromium.org
> >
> > Bug:
> > Change-Id: I68e44d5da2c5ad44dad402029c2e57f2d5d25b4f
> > Reviewed-on: https://chromium-review.googlesource.com/613880
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47418}
>
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
>
> Change-Id: I60a369a43121720fbb13ea6c2ec6ca948d60a20b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622547
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47451}
TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
Change-Id: Ie0efa6204c41b2cb672586a7ac0a622ca13ce5fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622033
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47453}
2017-08-19 15:55:52 +00:00
|
|
|
WasmModule* test_module_ptr_;
|
2016-05-20 08:04:43 +00:00
|
|
|
Isolate* isolate_;
|
2018-08-08 14:54:44 +00:00
|
|
|
WasmFeatures enabled_features_;
|
2018-04-06 10:18:18 +00:00
|
|
|
uint32_t global_offset = 0;
|
|
|
|
byte* mem_start_ = nullptr;
|
|
|
|
uint32_t mem_size_ = 0;
|
2018-12-17 11:52:56 +00:00
|
|
|
alignas(16) byte globals_data_[kMaxGlobalsSize];
|
2018-04-06 10:18:18 +00:00
|
|
|
WasmInterpreter* interpreter_ = nullptr;
|
2018-08-21 15:01:31 +00:00
|
|
|
ExecutionTier execution_tier_;
|
2016-12-19 15:03:13 +00:00
|
|
|
Handle<WasmInstanceObject> instance_object_;
|
2018-04-06 10:18:18 +00:00
|
|
|
NativeModule* native_module_ = nullptr;
|
2018-04-19 10:16:37 +00:00
|
|
|
RuntimeExceptionSupport runtime_exception_support_;
|
2018-01-05 08:43:05 +00:00
|
|
|
LowerSimd lower_simd_;
|
2016-01-14 09:48:45 +00:00
|
|
|
|
2019-03-13 19:22:40 +00:00
|
|
|
// Data segment arrays that are normally allocated on the instance.
|
|
|
|
std::vector<byte> data_segment_data_;
|
|
|
|
std::vector<Address> data_segment_starts_;
|
|
|
|
std::vector<uint32_t> data_segment_sizes_;
|
2019-04-05 19:04:37 +00:00
|
|
|
std::vector<byte> dropped_elem_segments_;
|
2019-03-13 19:22:40 +00:00
|
|
|
|
2017-09-01 12:57:34 +00:00
|
|
|
const WasmGlobal* AddGlobal(ValueType type);
|
2016-12-19 15:03:13 +00:00
|
|
|
|
2017-09-01 12:57:34 +00:00
|
|
|
Handle<WasmInstanceObject> InitInstanceObject();
|
2016-01-14 09:48:45 +00:00
|
|
|
};
|
|
|
|
|
2018-04-19 10:16:37 +00:00
|
|
|
void TestBuildingGraph(Zone* zone, compiler::JSGraph* jsgraph,
|
2018-10-23 11:56:12 +00:00
|
|
|
CompilationEnv* module, FunctionSig* sig,
|
2018-04-19 10:16:37 +00:00
|
|
|
compiler::SourcePositionTable* source_position_table,
|
|
|
|
const byte* start, const byte* end);
|
2016-09-27 20:46:10 +00:00
|
|
|
|
2017-09-01 12:57:34 +00:00
|
|
|
class WasmFunctionWrapper : private compiler::GraphAndBuilders {
|
2016-02-18 09:55:25 +00:00
|
|
|
public:
|
2017-09-01 12:57:34 +00:00
|
|
|
WasmFunctionWrapper(Zone* zone, int num_params);
|
2016-02-18 09:55:25 +00:00
|
|
|
|
2018-02-09 19:19:25 +00:00
|
|
|
void Init(CallDescriptor* call_descriptor, MachineType return_type,
|
2017-09-01 12:57:34 +00:00
|
|
|
Vector<MachineType> param_types);
|
2016-02-18 09:55:25 +00:00
|
|
|
|
2016-12-16 10:13:11 +00:00
|
|
|
template <typename ReturnType, typename... ParamTypes>
|
2018-02-09 19:19:25 +00:00
|
|
|
void Init(CallDescriptor* call_descriptor) {
|
2016-12-16 10:13:11 +00:00
|
|
|
std::array<MachineType, sizeof...(ParamTypes)> param_machine_types{
|
|
|
|
{MachineTypeForC<ParamTypes>()...}};
|
|
|
|
Vector<MachineType> param_vec(param_machine_types.data(),
|
|
|
|
param_machine_types.size());
|
2018-02-09 19:19:25 +00:00
|
|
|
Init(call_descriptor, MachineTypeForC<ReturnType>(), param_vec);
|
2016-12-16 10:13:11 +00:00
|
|
|
}
|
|
|
|
|
2018-08-02 09:50:08 +00:00
|
|
|
void SetInnerCode(WasmCode* code) {
|
2018-04-13 22:28:05 +00:00
|
|
|
intptr_t address = static_cast<intptr_t>(code->instruction_start());
|
2018-03-12 12:49:18 +00:00
|
|
|
compiler::NodeProperties::ChangeOp(
|
|
|
|
inner_code_node_,
|
2018-10-31 14:38:41 +00:00
|
|
|
common()->ExternalConstant(ExternalReference::FromRawAddress(address)));
|
2016-02-18 09:55:25 +00:00
|
|
|
}
|
|
|
|
|
[wasm] Introduce the WasmContext
The WasmContext struct introduced in this CL is used to store the
mem_size and mem_start address of the wasm memory. These variables can
be accessed at C++ level at graph build time (e.g., initialized during
instance building). When the GrowMemory runtime is invoked, the context
variables can be changed in the WasmContext at C++ level so that the
generated code will load the correct values.
This requires to insert a relocatable pointer only in the
JSToWasmWrapper (and in the other wasm entry points), the value is then
passed from function to function as an automatically added additional
parameter. The WasmContext is then dropped when creating an Interpreter
Entry or when invoking a JavaScript function. This removes the need of
patching the generated code at runtime (i.e., when the memory grows)
with respect to WASM_MEMORY_REFERENCE and WASM_MEMORY_SIZE_REFERENCE.
However, we still need to patch the code at instance build time to patch
the JSToWasmWrappers; in fact the address of the WasmContext is not
known during compilation, but only when the instance is built.
The WasmContext address is passed as the first parameter. This has the
advantage of not having to move the WasmContext around if the function
does not use many registers. This CL also changes the wasm calling
convention so that the first parameter register is different from the
return value register. The WasmContext is attached to every
WasmMemoryObject, to share the same context with multiple instances
sharing the same memory. Moreover, the nodes representing the
WasmContext variables are cached in the SSA environment, similarly to
other local variables that might change during execution. The nodes are
created when initializing the SSA environment and refreshed every time a
grow_memory or a function call happens, so that we are sure that they
always represent the correct mem_size and mem_start variables.
This CL also removes the WasmMemorySize runtime (since it's now possible
to directly retrieve mem_size from the context) and simplifies the
GrowMemory runtime (since every instance now has a memory_object).
R=ahaas@chromium.org,clemensh@chromium.org
CC=gdeepti@chromium.org
Change-Id: I3f058e641284f5a1bbbfc35a64c88da6ff08e240
Reviewed-on: https://chromium-review.googlesource.com/671008
Commit-Queue: Enrico Bacis <enricobacis@google.com>
Reviewed-by: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#48209}
2017-09-28 14:59:37 +00:00
|
|
|
const compiler::Operator* IntPtrConstant(intptr_t value) {
|
|
|
|
return machine()->Is32()
|
|
|
|
? common()->Int32Constant(static_cast<int32_t>(value))
|
|
|
|
: common()->Int64Constant(static_cast<int64_t>(value));
|
|
|
|
}
|
|
|
|
|
2018-04-06 10:18:18 +00:00
|
|
|
void SetInstance(Handle<WasmInstanceObject> instance) {
|
|
|
|
compiler::NodeProperties::ChangeOp(context_address_,
|
|
|
|
common()->HeapConstant(instance));
|
[wasm] Introduce the WasmContext
The WasmContext struct introduced in this CL is used to store the
mem_size and mem_start address of the wasm memory. These variables can
be accessed at C++ level at graph build time (e.g., initialized during
instance building). When the GrowMemory runtime is invoked, the context
variables can be changed in the WasmContext at C++ level so that the
generated code will load the correct values.
This requires to insert a relocatable pointer only in the
JSToWasmWrapper (and in the other wasm entry points), the value is then
passed from function to function as an automatically added additional
parameter. The WasmContext is then dropped when creating an Interpreter
Entry or when invoking a JavaScript function. This removes the need of
patching the generated code at runtime (i.e., when the memory grows)
with respect to WASM_MEMORY_REFERENCE and WASM_MEMORY_SIZE_REFERENCE.
However, we still need to patch the code at instance build time to patch
the JSToWasmWrappers; in fact the address of the WasmContext is not
known during compilation, but only when the instance is built.
The WasmContext address is passed as the first parameter. This has the
advantage of not having to move the WasmContext around if the function
does not use many registers. This CL also changes the wasm calling
convention so that the first parameter register is different from the
return value register. The WasmContext is attached to every
WasmMemoryObject, to share the same context with multiple instances
sharing the same memory. Moreover, the nodes representing the
WasmContext variables are cached in the SSA environment, similarly to
other local variables that might change during execution. The nodes are
created when initializing the SSA environment and refreshed every time a
grow_memory or a function call happens, so that we are sure that they
always represent the correct mem_size and mem_start variables.
This CL also removes the WasmMemorySize runtime (since it's now possible
to directly retrieve mem_size from the context) and simplifies the
GrowMemory runtime (since every instance now has a memory_object).
R=ahaas@chromium.org,clemensh@chromium.org
CC=gdeepti@chromium.org
Change-Id: I3f058e641284f5a1bbbfc35a64c88da6ff08e240
Reviewed-on: https://chromium-review.googlesource.com/671008
Commit-Queue: Enrico Bacis <enricobacis@google.com>
Reviewed-by: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#48209}
2017-09-28 14:59:37 +00:00
|
|
|
}
|
|
|
|
|
2017-09-01 12:57:34 +00:00
|
|
|
Handle<Code> GetWrapperCode();
|
2016-02-18 09:55:25 +00:00
|
|
|
|
|
|
|
Signature<MachineType>* signature() const { return signature_; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
Node* inner_code_node_;
|
[wasm] Introduce the WasmContext
The WasmContext struct introduced in this CL is used to store the
mem_size and mem_start address of the wasm memory. These variables can
be accessed at C++ level at graph build time (e.g., initialized during
instance building). When the GrowMemory runtime is invoked, the context
variables can be changed in the WasmContext at C++ level so that the
generated code will load the correct values.
This requires to insert a relocatable pointer only in the
JSToWasmWrapper (and in the other wasm entry points), the value is then
passed from function to function as an automatically added additional
parameter. The WasmContext is then dropped when creating an Interpreter
Entry or when invoking a JavaScript function. This removes the need of
patching the generated code at runtime (i.e., when the memory grows)
with respect to WASM_MEMORY_REFERENCE and WASM_MEMORY_SIZE_REFERENCE.
However, we still need to patch the code at instance build time to patch
the JSToWasmWrappers; in fact the address of the WasmContext is not
known during compilation, but only when the instance is built.
The WasmContext address is passed as the first parameter. This has the
advantage of not having to move the WasmContext around if the function
does not use many registers. This CL also changes the wasm calling
convention so that the first parameter register is different from the
return value register. The WasmContext is attached to every
WasmMemoryObject, to share the same context with multiple instances
sharing the same memory. Moreover, the nodes representing the
WasmContext variables are cached in the SSA environment, similarly to
other local variables that might change during execution. The nodes are
created when initializing the SSA environment and refreshed every time a
grow_memory or a function call happens, so that we are sure that they
always represent the correct mem_size and mem_start variables.
This CL also removes the WasmMemorySize runtime (since it's now possible
to directly retrieve mem_size from the context) and simplifies the
GrowMemory runtime (since every instance now has a memory_object).
R=ahaas@chromium.org,clemensh@chromium.org
CC=gdeepti@chromium.org
Change-Id: I3f058e641284f5a1bbbfc35a64c88da6ff08e240
Reviewed-on: https://chromium-review.googlesource.com/671008
Commit-Queue: Enrico Bacis <enricobacis@google.com>
Reviewed-by: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#48209}
2017-09-28 14:59:37 +00:00
|
|
|
Node* context_address_;
|
2018-06-19 08:09:09 +00:00
|
|
|
MaybeHandle<Code> code_;
|
2016-02-18 09:55:25 +00:00
|
|
|
Signature<MachineType>* signature_;
|
|
|
|
};
|
2016-01-14 09:48:45 +00:00
|
|
|
|
2017-06-09 12:21:52 +00:00
|
|
|
// A helper for compiling wasm functions for testing.
|
2016-12-16 10:13:11 +00:00
|
|
|
// It contains the internal state for compilation (i.e. TurboFan graph) and
|
|
|
|
// interpretation (by adding to the interpreter manually).
|
2017-09-01 12:57:34 +00:00
|
|
|
class WasmFunctionCompiler : public compiler::GraphAndBuilders {
|
2016-01-14 09:48:45 +00:00
|
|
|
public:
|
2017-09-25 16:13:13 +00:00
|
|
|
~WasmFunctionCompiler();
|
|
|
|
|
2017-08-19 16:34:11 +00:00
|
|
|
Isolate* isolate() { return builder_->isolate(); }
|
2016-12-16 10:13:11 +00:00
|
|
|
CallDescriptor* descriptor() {
|
2016-02-18 09:55:25 +00:00
|
|
|
if (descriptor_ == nullptr) {
|
2017-06-27 15:38:52 +00:00
|
|
|
descriptor_ = compiler::GetWasmCallDescriptor(zone(), sig);
|
2016-02-18 09:55:25 +00:00
|
|
|
}
|
2016-12-16 10:13:11 +00:00
|
|
|
return descriptor_;
|
2016-02-18 09:55:25 +00:00
|
|
|
}
|
2016-05-25 08:32:37 +00:00
|
|
|
uint32_t function_index() { return function_->func_index; }
|
2016-01-14 09:48:45 +00:00
|
|
|
|
2017-09-01 12:57:34 +00:00
|
|
|
void Build(const byte* start, const byte* end);
|
2016-01-14 09:48:45 +00:00
|
|
|
|
2016-12-21 13:43:00 +00:00
|
|
|
byte AllocateLocal(ValueType type) {
|
2016-05-17 17:53:46 +00:00
|
|
|
uint32_t index = local_decls.AddLocals(1, type);
|
2016-03-07 21:04:07 +00:00
|
|
|
byte result = static_cast<byte>(index);
|
|
|
|
DCHECK_EQ(index, result);
|
|
|
|
return result;
|
2016-01-14 09:48:45 +00:00
|
|
|
}
|
|
|
|
|
2016-12-16 10:13:11 +00:00
|
|
|
void SetSigIndex(int sig_index) { function_->sig_index = sig_index; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
friend class WasmRunnerBase;
|
|
|
|
|
2017-09-12 12:39:42 +00:00
|
|
|
WasmFunctionCompiler(Zone* zone, FunctionSig* sig,
|
|
|
|
TestingModuleBuilder* builder, const char* name);
|
2016-01-14 09:48:45 +00:00
|
|
|
|
2017-09-01 12:57:34 +00:00
|
|
|
compiler::JSGraph jsgraph;
|
2016-12-16 10:13:11 +00:00
|
|
|
FunctionSig* sig;
|
|
|
|
// The call descriptor is initialized when the function is compiled.
|
|
|
|
CallDescriptor* descriptor_;
|
2017-08-19 16:34:11 +00:00
|
|
|
TestingModuleBuilder* builder_;
|
2016-12-16 10:13:11 +00:00
|
|
|
WasmFunction* function_;
|
|
|
|
LocalDeclEncoder local_decls;
|
2017-09-01 12:57:34 +00:00
|
|
|
compiler::SourcePositionTable source_position_table_;
|
2016-12-16 10:13:11 +00:00
|
|
|
WasmInterpreter* interpreter_;
|
2016-12-15 16:51:11 +00:00
|
|
|
};
|
|
|
|
|
2016-12-16 10:13:11 +00:00
|
|
|
// A helper class to build a module around Wasm bytecode, generate machine
|
2016-01-14 09:48:45 +00:00
|
|
|
// code, and run that code.
|
2016-12-16 10:13:11 +00:00
|
|
|
class WasmRunnerBase : public HandleAndZoneScope {
|
2016-01-14 09:48:45 +00:00
|
|
|
public:
|
2018-04-06 10:18:18 +00:00
|
|
|
WasmRunnerBase(ManuallyImportedJSFunction* maybe_import,
|
2018-08-21 15:01:31 +00:00
|
|
|
ExecutionTier execution_tier, int num_params,
|
2018-04-19 10:16:37 +00:00
|
|
|
RuntimeExceptionSupport runtime_exception_support,
|
2018-01-05 08:43:05 +00:00
|
|
|
LowerSimd lower_simd)
|
2016-12-16 10:13:11 +00:00
|
|
|
: zone_(&allocator_, ZONE_NAME),
|
2018-08-21 15:01:31 +00:00
|
|
|
builder_(&zone_, maybe_import, execution_tier,
|
2018-04-06 10:18:18 +00:00
|
|
|
runtime_exception_support, lower_simd),
|
2017-09-12 12:39:42 +00:00
|
|
|
wrapper_(&zone_, num_params) {}
|
2016-01-14 09:48:45 +00:00
|
|
|
|
2016-02-18 15:58:02 +00:00
|
|
|
// Builds a graph from the given Wasm code and generates the machine
|
2016-01-14 09:48:45 +00:00
|
|
|
// code and call wrapper for that graph. This method must not be called
|
|
|
|
// more than once.
|
|
|
|
void Build(const byte* start, const byte* end) {
|
2016-02-18 15:58:02 +00:00
|
|
|
CHECK(!compiled_);
|
|
|
|
compiled_ = true;
|
2016-12-16 10:13:11 +00:00
|
|
|
functions_[0]->Build(start, end);
|
|
|
|
}
|
2016-01-14 09:48:45 +00:00
|
|
|
|
2016-12-16 10:13:11 +00:00
|
|
|
// Resets the state for building the next function.
|
|
|
|
// The main function called will always be the first function.
|
|
|
|
template <typename ReturnType, typename... ParamTypes>
|
2016-12-19 15:03:13 +00:00
|
|
|
WasmFunctionCompiler& NewFunction(const char* name = nullptr) {
|
|
|
|
return NewFunction(CreateSig<ReturnType, ParamTypes...>(), name);
|
2016-12-16 10:13:11 +00:00
|
|
|
}
|
2016-01-14 09:48:45 +00:00
|
|
|
|
2016-12-16 10:13:11 +00:00
|
|
|
// Resets the state for building the next function.
|
|
|
|
// The main function called will be the last generated function.
|
|
|
|
// Returns the index of the previously built function.
|
2016-12-19 15:03:13 +00:00
|
|
|
WasmFunctionCompiler& NewFunction(FunctionSig* sig,
|
|
|
|
const char* name = nullptr) {
|
2017-09-12 12:39:42 +00:00
|
|
|
functions_.emplace_back(
|
|
|
|
new WasmFunctionCompiler(&zone_, sig, &builder_, name));
|
2019-05-22 14:04:36 +00:00
|
|
|
builder().AddSignature(sig);
|
2016-12-16 10:13:11 +00:00
|
|
|
return *functions_.back();
|
2016-05-25 08:32:37 +00:00
|
|
|
}
|
2016-01-14 09:48:45 +00:00
|
|
|
|
2016-12-21 13:43:00 +00:00
|
|
|
byte AllocateLocal(ValueType type) {
|
2016-12-16 10:13:11 +00:00
|
|
|
return functions_[0]->AllocateLocal(type);
|
2016-01-14 09:48:45 +00:00
|
|
|
}
|
|
|
|
|
2017-01-20 13:50:09 +00:00
|
|
|
uint32_t function_index() { return functions_[0]->function_index(); }
|
2016-12-16 10:13:11 +00:00
|
|
|
WasmFunction* function() { return functions_[0]->function_; }
|
2017-04-28 08:04:11 +00:00
|
|
|
WasmInterpreter* interpreter() {
|
|
|
|
DCHECK(interpret());
|
|
|
|
return functions_[0]->interpreter_;
|
|
|
|
}
|
2016-12-16 10:13:11 +00:00
|
|
|
bool possible_nondeterminism() { return possible_nondeterminism_; }
|
2017-08-19 16:34:11 +00:00
|
|
|
TestingModuleBuilder& builder() { return builder_; }
|
2016-12-16 10:13:11 +00:00
|
|
|
Zone* zone() { return &zone_; }
|
|
|
|
|
2017-08-19 16:34:11 +00:00
|
|
|
bool interpret() { return builder_.interpret(); }
|
2017-04-28 08:04:11 +00:00
|
|
|
|
2017-08-07 11:40:21 +00:00
|
|
|
template <typename ReturnType, typename... ParamTypes>
|
|
|
|
FunctionSig* CreateSig() {
|
|
|
|
std::array<MachineType, sizeof...(ParamTypes)> param_machine_types{
|
|
|
|
{MachineTypeForC<ParamTypes>()...}};
|
|
|
|
Vector<MachineType> param_vec(param_machine_types.data(),
|
|
|
|
param_machine_types.size());
|
|
|
|
return CreateSig(MachineTypeForC<ReturnType>(), param_vec);
|
|
|
|
}
|
|
|
|
|
2016-12-16 10:13:11 +00:00
|
|
|
private:
|
|
|
|
FunctionSig* CreateSig(MachineType return_type,
|
2017-09-01 12:57:34 +00:00
|
|
|
Vector<MachineType> param_types);
|
2016-01-14 09:48:45 +00:00
|
|
|
|
2016-12-16 10:13:11 +00:00
|
|
|
protected:
|
|
|
|
v8::internal::AccountingAllocator allocator_;
|
|
|
|
Zone zone_;
|
2017-08-19 16:34:11 +00:00
|
|
|
TestingModuleBuilder builder_;
|
2016-12-16 10:13:11 +00:00
|
|
|
std::vector<std::unique_ptr<WasmFunctionCompiler>> functions_;
|
|
|
|
WasmFunctionWrapper wrapper_;
|
|
|
|
bool compiled_ = false;
|
|
|
|
bool possible_nondeterminism_ = false;
|
2019-03-07 16:30:53 +00:00
|
|
|
int32_t main_fn_index_ = 0;
|
2016-12-16 10:13:11 +00:00
|
|
|
|
|
|
|
public:
|
2017-02-10 13:11:40 +00:00
|
|
|
// This field has to be static. Otherwise, gcc complains about the use in
|
2016-12-16 10:13:11 +00:00
|
|
|
// the lambda context below.
|
2017-02-10 13:11:40 +00:00
|
|
|
static bool trap_happened;
|
2016-12-16 10:13:11 +00:00
|
|
|
};
|
[wasm] Introduce the TrapIf and TrapUnless operators to generate trap code.
Some instructions in WebAssembly trap for some inputs, which means that the
execution is terminated and (at least at the moment) a JavaScript exception is
thrown. Examples for traps are out-of-bounds memory accesses, or integer
divisions by zero.
Without the TrapIf and TrapUnless operators trap check in WebAssembly introduces 5
TurboFan nodes (branch, if_true, if_false, trap-reason constant, trap-position
constant), in addition to the trap condition itself. Additionally, each
WebAssembly function has four TurboFan nodes (merge, effect_phi, 2 phis) whose
number of inputs is linear to the number of trap checks in the function.
Especially for functions with high numbers of trap checks we observe a
significant slowdown in compilation time, down to 0.22 MiB/s in the sqlite
benchmark instead of the average of 3 MiB/s in other benchmarks. By introducing
a TrapIf common operator only a single node is necessary per trap check, in
addition to the trap condition. Also the nodes which are shared between trap
checks (merge, effect_phi, 2 phis) would disappear. First measurements suggest a
speedup of 30-50% on average.
This CL only implements TrapIf and TrapUnless on x64. The implementation is also
hidden behind the --wasm-trap-if flag.
Please take a special look at how the source position is transfered from the
instruction selector to the code generator, and at the context that is used for
the runtime call.
R=titzer@chromium.org
Review-Url: https://codereview.chromium.org/2562393002
Cr-Commit-Position: refs/heads/master@{#41720}
2016-12-15 13:31:29 +00:00
|
|
|
|
2016-12-16 10:13:11 +00:00
|
|
|
template <typename ReturnType, typename... ParamTypes>
|
|
|
|
class WasmRunner : public WasmRunnerBase {
|
|
|
|
public:
|
2018-08-21 15:01:31 +00:00
|
|
|
WasmRunner(ExecutionTier execution_tier,
|
2018-04-06 10:18:18 +00:00
|
|
|
ManuallyImportedJSFunction* maybe_import = nullptr,
|
2017-09-01 12:57:34 +00:00
|
|
|
const char* main_fn_name = "main",
|
2018-04-19 10:16:37 +00:00
|
|
|
RuntimeExceptionSupport runtime_exception_support =
|
|
|
|
kNoRuntimeExceptionSupport,
|
2018-01-05 08:43:05 +00:00
|
|
|
LowerSimd lower_simd = kNoLowerSimd)
|
2018-08-21 15:01:31 +00:00
|
|
|
: WasmRunnerBase(maybe_import, execution_tier, sizeof...(ParamTypes),
|
2018-01-05 08:43:05 +00:00
|
|
|
runtime_exception_support, lower_simd) {
|
2019-03-07 16:30:53 +00:00
|
|
|
WasmFunctionCompiler& main_fn =
|
|
|
|
NewFunction<ReturnType, ParamTypes...>(main_fn_name);
|
|
|
|
// Non-zero if there is an import.
|
|
|
|
main_fn_index_ = main_fn.function_index();
|
|
|
|
|
2016-12-16 10:13:11 +00:00
|
|
|
if (!interpret()) {
|
2019-03-07 16:30:53 +00:00
|
|
|
wrapper_.Init<ReturnType, ParamTypes...>(main_fn.descriptor());
|
2016-12-16 10:13:11 +00:00
|
|
|
}
|
[wasm] Introduce the TrapIf and TrapUnless operators to generate trap code.
Some instructions in WebAssembly trap for some inputs, which means that the
execution is terminated and (at least at the moment) a JavaScript exception is
thrown. Examples for traps are out-of-bounds memory accesses, or integer
divisions by zero.
Without the TrapIf and TrapUnless operators trap check in WebAssembly introduces 5
TurboFan nodes (branch, if_true, if_false, trap-reason constant, trap-position
constant), in addition to the trap condition itself. Additionally, each
WebAssembly function has four TurboFan nodes (merge, effect_phi, 2 phis) whose
number of inputs is linear to the number of trap checks in the function.
Especially for functions with high numbers of trap checks we observe a
significant slowdown in compilation time, down to 0.22 MiB/s in the sqlite
benchmark instead of the average of 3 MiB/s in other benchmarks. By introducing
a TrapIf common operator only a single node is necessary per trap check, in
addition to the trap condition. Also the nodes which are shared between trap
checks (merge, effect_phi, 2 phis) would disappear. First measurements suggest a
speedup of 30-50% on average.
This CL only implements TrapIf and TrapUnless on x64. The implementation is also
hidden behind the --wasm-trap-if flag.
Please take a special look at how the source position is transfered from the
instruction selector to the code generator, and at the context that is used for
the runtime call.
R=titzer@chromium.org
Review-Url: https://codereview.chromium.org/2562393002
Cr-Commit-Position: refs/heads/master@{#41720}
2016-12-15 13:31:29 +00:00
|
|
|
}
|
|
|
|
|
2018-08-21 15:01:31 +00:00
|
|
|
WasmRunner(ExecutionTier execution_tier, LowerSimd lower_simd)
|
|
|
|
: WasmRunner(execution_tier, nullptr, "main", kNoRuntimeExceptionSupport,
|
2018-04-19 10:16:37 +00:00
|
|
|
lower_simd) {}
|
2018-01-05 08:43:05 +00:00
|
|
|
|
2019-04-05 19:04:37 +00:00
|
|
|
void SetUpTrapCallback() {
|
2017-02-10 13:11:40 +00:00
|
|
|
WasmRunnerBase::trap_happened = false;
|
|
|
|
auto trap_callback = []() -> void {
|
|
|
|
WasmRunnerBase::trap_happened = true;
|
|
|
|
set_trap_callback_for_testing(nullptr);
|
|
|
|
};
|
|
|
|
set_trap_callback_for_testing(trap_callback);
|
2019-04-05 19:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnType Call(ParamTypes... p) {
|
|
|
|
DCHECK(compiled_);
|
|
|
|
if (interpret()) return CallInterpreter(p...);
|
|
|
|
|
|
|
|
ReturnType return_value = static_cast<ReturnType>(0xDEADBEEFDEADBEEF);
|
|
|
|
SetUpTrapCallback();
|
2017-02-10 13:11:40 +00:00
|
|
|
|
2019-03-07 16:30:53 +00:00
|
|
|
wrapper_.SetInnerCode(builder_.GetFunctionCode(main_fn_index_));
|
2018-04-06 10:18:18 +00:00
|
|
|
wrapper_.SetInstance(builder_.instance_object());
|
2019-01-28 14:23:10 +00:00
|
|
|
builder_.SetExecutable();
|
2017-10-16 08:49:45 +00:00
|
|
|
Handle<Code> wrapper_code = wrapper_.GetWrapperCode();
|
2017-09-01 12:57:34 +00:00
|
|
|
compiler::CodeRunner<int32_t> runner(CcTest::InitIsolateOnce(),
|
2017-10-16 08:49:45 +00:00
|
|
|
wrapper_code, wrapper_.signature());
|
2018-04-04 18:30:13 +00:00
|
|
|
int32_t result;
|
|
|
|
{
|
2019-03-27 11:53:26 +00:00
|
|
|
SetThreadInWasmFlag();
|
2018-04-04 18:30:13 +00:00
|
|
|
|
|
|
|
result = runner.Call(static_cast<void*>(&p)...,
|
|
|
|
static_cast<void*>(&return_value));
|
2018-08-29 10:44:11 +00:00
|
|
|
|
2019-03-27 11:53:26 +00:00
|
|
|
ClearThreadInWasmFlag();
|
2018-04-04 18:30:13 +00:00
|
|
|
}
|
2017-02-10 13:11:40 +00:00
|
|
|
CHECK_EQ(WASM_WRAPPER_RETURN_VALUE, result);
|
|
|
|
return WasmRunnerBase::trap_happened
|
2017-12-02 00:30:37 +00:00
|
|
|
? static_cast<ReturnType>(0xDEADBEEFDEADBEEF)
|
2017-02-10 13:11:40 +00:00
|
|
|
: return_value;
|
2016-05-25 08:32:37 +00:00
|
|
|
}
|
|
|
|
|
2016-12-16 10:13:11 +00:00
|
|
|
ReturnType CallInterpreter(ParamTypes... p) {
|
2016-06-09 14:22:05 +00:00
|
|
|
WasmInterpreter::Thread* thread = interpreter()->GetThread(0);
|
|
|
|
thread->Reset();
|
2017-07-14 13:49:01 +00:00
|
|
|
std::array<WasmValue, sizeof...(p)> args{{WasmValue(p)...}};
|
2017-03-14 15:54:43 +00:00
|
|
|
thread->InitFrame(function(), args.data());
|
2019-01-29 10:25:41 +00:00
|
|
|
thread->Run();
|
|
|
|
CHECK_GT(thread->NumInterpretedCalls(), 0);
|
|
|
|
if (thread->state() == WasmInterpreter::FINISHED) {
|
2017-07-14 13:49:01 +00:00
|
|
|
WasmValue val = thread->GetReturnValue();
|
2016-10-20 14:27:23 +00:00
|
|
|
possible_nondeterminism_ |= thread->PossibleNondeterminism();
|
2016-05-25 08:32:37 +00:00
|
|
|
return val.to<ReturnType>();
|
2016-06-09 14:22:05 +00:00
|
|
|
} else if (thread->state() == WasmInterpreter::TRAPPED) {
|
2016-05-25 08:32:37 +00:00
|
|
|
// TODO(titzer): return the correct trap code
|
2017-12-02 00:30:37 +00:00
|
|
|
int64_t result = 0xDEADBEEFDEADBEEF;
|
2016-05-25 08:32:37 +00:00
|
|
|
return static_cast<ReturnType>(result);
|
|
|
|
} else {
|
|
|
|
// TODO(titzer): falling off end
|
2016-12-16 10:13:11 +00:00
|
|
|
return ReturnType{0};
|
2016-05-25 08:32:37 +00:00
|
|
|
}
|
2016-01-14 09:48:45 +00:00
|
|
|
}
|
2017-10-16 08:49:45 +00:00
|
|
|
|
2019-03-18 23:57:16 +00:00
|
|
|
void CheckCallApplyViaJS(double expected, uint32_t function_index,
|
|
|
|
Handle<Object>* buffer, int count) {
|
2019-01-28 16:09:28 +00:00
|
|
|
Isolate* isolate = builder_.isolate();
|
2019-04-05 19:04:37 +00:00
|
|
|
SetUpTrapCallback();
|
2019-01-28 16:09:28 +00:00
|
|
|
if (jsfuncs_.size() <= function_index) {
|
|
|
|
jsfuncs_.resize(function_index + 1);
|
|
|
|
}
|
|
|
|
if (jsfuncs_[function_index].is_null()) {
|
|
|
|
jsfuncs_[function_index] = builder_.WrapCode(function_index);
|
|
|
|
}
|
|
|
|
Handle<JSFunction> jsfunc = jsfuncs_[function_index];
|
|
|
|
Handle<Object> global(isolate->context().global_object(), isolate);
|
|
|
|
MaybeHandle<Object> retval =
|
2019-03-21 15:55:09 +00:00
|
|
|
Execution::TryCall(isolate, jsfunc, global, count, buffer,
|
|
|
|
Execution::MessageHandling::kReport, nullptr);
|
2019-01-28 16:09:28 +00:00
|
|
|
|
2019-04-05 19:04:37 +00:00
|
|
|
if (retval.is_null() || WasmRunnerBase::trap_happened) {
|
2019-03-21 15:55:09 +00:00
|
|
|
CHECK_EQ(expected, static_cast<double>(0xDEADBEEF));
|
2019-01-28 16:09:28 +00:00
|
|
|
} else {
|
2019-03-21 15:55:09 +00:00
|
|
|
Handle<Object> result = retval.ToHandleChecked();
|
|
|
|
if (result->IsSmi()) {
|
|
|
|
CHECK_EQ(expected, Smi::ToInt(*result));
|
|
|
|
} else {
|
|
|
|
CHECK(result->IsHeapNumber());
|
|
|
|
CHECK_DOUBLE_EQ(expected, HeapNumber::cast(*result).value());
|
|
|
|
}
|
2019-01-28 16:09:28 +00:00
|
|
|
}
|
2019-01-29 10:25:41 +00:00
|
|
|
|
|
|
|
if (builder_.interpret()) {
|
|
|
|
CHECK_GT(builder_.interpreter()->GetThread(0)->NumInterpretedCalls(), 0);
|
|
|
|
}
|
2019-01-28 16:09:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CheckCallViaJS(double expected, ParamTypes... p) {
|
|
|
|
Isolate* isolate = builder_.isolate();
|
2019-04-05 19:04:37 +00:00
|
|
|
// MSVC doesn't allow empty arrays, so include a dummy at the end.
|
|
|
|
Handle<Object> buffer[] = {isolate->factory()->NewNumber(p)...,
|
|
|
|
Handle<Object>()};
|
2019-03-18 23:57:16 +00:00
|
|
|
CheckCallApplyViaJS(expected, function()->func_index, buffer, sizeof...(p));
|
2019-01-28 16:09:28 +00:00
|
|
|
}
|
|
|
|
|
2020-01-14 19:53:03 +00:00
|
|
|
void CheckUsedExecutionTier(ExecutionTier expected_tier) {
|
|
|
|
// Liftoff can fail and fallback to Turbofan, so check that the function
|
|
|
|
// gets compiled by the tier requested, to guard against accidental success.
|
|
|
|
CHECK(compiled_);
|
|
|
|
CHECK_EQ(expected_tier, builder_.GetFunctionCode(0)->tier());
|
|
|
|
}
|
|
|
|
|
2017-10-16 08:49:45 +00:00
|
|
|
Handle<Code> GetWrapperCode() { return wrapper_.GetWrapperCode(); }
|
2016-01-14 09:48:45 +00:00
|
|
|
|
2019-01-28 16:09:28 +00:00
|
|
|
private:
|
2019-04-02 10:41:00 +00:00
|
|
|
wasm::WasmCodeRefScope code_ref_scope_;
|
|
|
|
std::vector<Handle<JSFunction>> jsfuncs_;
|
|
|
|
|
2019-03-27 11:53:26 +00:00
|
|
|
void SetThreadInWasmFlag() {
|
|
|
|
*reinterpret_cast<int*>(trap_handler::GetThreadInWasmThreadLocalAddress()) =
|
|
|
|
true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClearThreadInWasmFlag() {
|
|
|
|
*reinterpret_cast<int*>(trap_handler::GetThreadInWasmThreadLocalAddress()) =
|
|
|
|
false;
|
|
|
|
}
|
2019-01-28 16:09:28 +00:00
|
|
|
};
|
2019-01-28 13:59:04 +00:00
|
|
|
|
2016-05-18 15:56:11 +00:00
|
|
|
// A macro to define tests that run in different engine configurations.
|
2019-04-03 15:37:47 +00:00
|
|
|
#define WASM_EXEC_TEST(name) \
|
|
|
|
void RunWasm_##name(ExecutionTier execution_tier); \
|
|
|
|
TEST(RunWasmTurbofan_##name) { RunWasm_##name(ExecutionTier::kTurbofan); } \
|
|
|
|
TEST(RunWasmLiftoff_##name) { RunWasm_##name(ExecutionTier::kLiftoff); } \
|
|
|
|
TEST(RunWasmInterpreter_##name) { \
|
|
|
|
RunWasm_##name(ExecutionTier::kInterpreter); \
|
|
|
|
} \
|
2018-08-21 15:01:31 +00:00
|
|
|
void RunWasm_##name(ExecutionTier execution_tier)
|
|
|
|
|
2019-04-03 15:37:47 +00:00
|
|
|
#define WASM_COMPILED_EXEC_TEST(name) \
|
|
|
|
void RunWasm_##name(ExecutionTier execution_tier); \
|
|
|
|
TEST(RunWasmTurbofan_##name) { RunWasm_##name(ExecutionTier::kTurbofan); } \
|
|
|
|
TEST(RunWasmLiftoff_##name) { RunWasm_##name(ExecutionTier::kLiftoff); } \
|
2018-08-21 15:01:31 +00:00
|
|
|
void RunWasm_##name(ExecutionTier execution_tier)
|
2017-10-25 12:46:43 +00:00
|
|
|
|
2017-09-01 12:57:34 +00:00
|
|
|
} // namespace wasm
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|
2016-01-14 09:48:45 +00:00
|
|
|
|
|
|
|
#endif
|