v8/test/cctest/wasm/wasm-run-utils.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

645 lines
22 KiB
C
Raw Normal View History

// 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>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <array>
#include <memory>
#include "src/base/utils/random-number-generator.h"
#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"
#include "src/compiler/graph-visualizer.h"
#include "src/compiler/int64-lowering.h"
#include "src/compiler/js-graph.h"
#include "src/compiler/node.h"
#include "src/compiler/pipeline.h"
#include "src/compiler/wasm-compiler.h"
#include "src/compiler/zone-stats.h"
[wasm] Initial signal handler This is basically the minimum viable signal handler for Wasm bounds checks. It includes the TLS check and the fine grained instructions checks. These two checks provide most of the safety for the signal handler. Future CLs will add code range and data range checks for more robustness. The trap handling code and data structures are all in src/trap-handler, with the code that actually runs in the signal handler confined to src/trap-handler/signal-handler.cc. This changes adds a new V8 API that the embedder should call from a signal handler that will give V8 the chance to handle the fault first. For hosts that do not want to implement their own signal handler, we include the option to install a simple one. This simple handler is also used for the tests. When a Wasm module is instantiated, information about each function is passed to the trap handler, which is used to classify faults. These are removed during the instance finalizer. Several future enhancements are planned before turning this on by default. Obviously, the additional checks will be added to MaybeHandleFault. We are also planning to add a two-level CodeObjectData table that is grouped by isolates to make cleanup easier and also reduce potential for contending on a single data structure. BUG= https://bugs.chromium.org/p/v8/issues/detail?id=5277 Review-Url: https://codereview.chromium.org/2371833007 Cr-Original-Original-Commit-Position: refs/heads/master@{#43523} Committed: https://chromium.googlesource.com/v8/v8/+/a5af7fe9ee388a636675f4a6872b1d34fa7d1a7a Review-Url: https://codereview.chromium.org/2371833007 Cr-Original-Commit-Position: refs/heads/master@{#43755} Committed: https://chromium.googlesource.com/v8/v8/+/338622d7cae787a63cece1f2e79a8b030023940b Review-Url: https://codereview.chromium.org/2371833007 Cr-Commit-Position: refs/heads/master@{#43759}
2017-03-13 22:12:23 +00:00
#include "src/trap-handler/trap-handler.h"
#include "src/wasm/function-body-decoder.h"
#include "src/wasm/local-decl-encoder.h"
#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"
#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"
#include "src/wasm/wasm-objects.h"
#include "src/wasm/wasm-opcodes.h"
#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 {
namespace wasm {
enum class TestExecutionTier : int8_t {
kLiftoff = static_cast<int8_t>(ExecutionTier::kLiftoff),
kTurbofan = static_cast<int8_t>(ExecutionTier::kTurbofan),
kInterpreter
};
static_assert(
std::is_same<std::underlying_type<ExecutionTier>::type,
std::underlying_type<TestExecutionTier>::type>::value,
"enum types match");
using base::ReadLittleEndianValue;
using base::WriteLittleEndianValue;
constexpr uint32_t kMaxFunctions = 10;
constexpr uint32_t kMaxGlobalsSize = 128;
using compiler::CallDescriptor;
using compiler::MachineTypeForC;
using compiler::Node;
// TODO(titzer): check traps more robustly in tests.
// Currently, in tests, we just return 0xDEADBEEF from the function in which
// the trap occurs if the runtime context is not available to throw a JavaScript
// exception.
#define CHECK_TRAP32(x) \
CHECK_EQ(0xDEADBEEF, (bit_cast<uint32_t>(x)) & 0xFFFFFFFF)
#define CHECK_TRAP64(x) \
CHECK_EQ(0xDEADBEEFDEADBEEF, (bit_cast<uint64_t>(x)) & 0xFFFFFFFFFFFFFFFF)
#define CHECK_TRAP(x) CHECK_TRAP32(x)
#define WASM_WRAPPER_RETURN_VALUE 8754
#define BUILD(r, ...) \
do { \
byte code[] = {__VA_ARGS__}; \
r.Build(code, code + arraysize(code)); \
} while (false)
// For tests that must manually import a JSFunction with source code.
struct ManuallyImportedJSFunction {
const FunctionSig* sig;
Handle<JSFunction> js_function;
};
Revert "Revert "[wasm] JIT using WasmCodeManager"" This reverts commit b301203e5aec9c8ff32f93aa31f8d764311e6e6e. Reason for revert: Fixed issues on arm. Original change's description: > Revert "[wasm] JIT using WasmCodeManager" > > This reverts commit d4c8393c1cc9cf3e2b19daabc3a161ff18d596cb. > > Reason for revert: Breaks ARM hardware: > https://build.chromium.org/p/client.v8.ports/builders/V8%20Arm%20-%20debug/builds/5268 > > Original change's description: > > [wasm] JIT using WasmCodeManager > > > > This is the first step towards wasm code sharing. This CL moves wasm > > code generation outside the JavaScript GC heap using the previously - > > introduced WasmCodeManager (all this, behind the --wasm-jit-to-native > > flag). > > > > See design document: go/wasm-on-native-heap-stage-1 > > > > This CL doesn't change other wasm architectural invariants. We still > > have per-Isolate wasm code generation, and per-wasm module instance > > code specialization. > > > > Bug:v8:6876 > > > > Cq-Include-Trybots: master.tryserver.chromium.linux:linux_chromium_rel_ng > > Change-Id: I1e08cecad75f93fb081545c31228a4568be276d3 > > Reviewed-on: https://chromium-review.googlesource.com/674086 > > Reviewed-by: Ben Titzer <titzer@chromium.org> > > Reviewed-by: Eric Holk <eholk@chromium.org> > > Cr-Commit-Position: refs/heads/master@{#49689} > > TBR=bradnelson@chromium.org,titzer@chromium.org,mtrofin@chromium.org,eholk@chromium.org > > Change-Id: I89af1ea5decd841bc12cd2ceaf74d32bc4433885 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: v8:6876 > Cq-Include-Trybots: master.tryserver.chromium.linux:linux_chromium_rel_ng > Reviewed-on: https://chromium-review.googlesource.com/794690 > Reviewed-by: Michael Achenbach <machenbach@chromium.org> > Commit-Queue: Michael Achenbach <machenbach@chromium.org> > Cr-Commit-Position: refs/heads/master@{#49691} TBR=bradnelson@chromium.org,machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,eholk@chromium.org Change-Id: I1b07638d1bb2ba0664305b4b2dcfc1342dc8444f No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: v8:6876 Cq-Include-Trybots: master.tryserver.chromium.linux:linux_chromium_rel_ng Reviewed-on: https://chromium-review.googlesource.com/794434 Commit-Queue: Mircea Trofin <mtrofin@chromium.org> Reviewed-by: Mircea Trofin <mtrofin@chromium.org> Cr-Commit-Position: refs/heads/master@{#49692}
2017-11-28 22:25:36 +00:00
// A Wasm module builder. Globals are pre-set, however, memory and code may be
// progressively added by a test. In turn, we piecemeal update the runtime
// objects, i.e. {WasmInstanceObject}, {WasmModuleObject} and, if necessary,
// the interpreter.
Revert "Revert "[wasm] Rename TestingModule to TestingModuleBuilder."" This reverts commit 3913bde18848f95df41dc42627b826cb41231894. Reason for revert: Reason for revert fixed. Original change's description: > Revert "[wasm] Rename TestingModule to TestingModuleBuilder." > > This reverts commit ed06fc9127d2f965ece485293d2bc67fc6e0fb53. > > Reason for revert: Need to revert previous CL > > Original change's description: > > [wasm] Rename TestingModule to TestingModuleBuilder. > > > > This is a followup to moving the ModuleEnv to the compiler directory and > > making it immutable. > > > > R=​mtrofin@chromium.org, ahaas@chromium.org > > > > Bug: > > Change-Id: I0f5ec1b697bdcfad0b4dc2bca577cc0f40de8dc0 > > Reviewed-on: https://chromium-review.googlesource.com/616762 > > Commit-Queue: Ben Titzer <titzer@chromium.org> > > Reviewed-by: Mircea Trofin <mtrofin@chromium.org> > > Reviewed-by: Andreas Haas <ahaas@chromium.org> > > Cr-Commit-Position: refs/heads/master@{#47419} > > TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org > > Change-Id: I9b3b379e89f523c2fcf205a1d268aa294bbc44ff > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://chromium-review.googlesource.com/622567 > Reviewed-by: Michael Achenbach <machenbach@chromium.org> > Commit-Queue: Michael Achenbach <machenbach@chromium.org> > Cr-Commit-Position: refs/heads/master@{#47448} TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org Change-Id: Idce6f1ca8ed0ea80edb50292e9b6e2d7712f29cf No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://chromium-review.googlesource.com/622034 Reviewed-by: Mircea Trofin <mtrofin@chromium.org> Commit-Queue: Mircea Trofin <mtrofin@chromium.org> Cr-Commit-Position: refs/heads/master@{#47454}
2017-08-19 16:34:11 +00:00
class TestingModuleBuilder {
public:
TestingModuleBuilder(Zone*, ManuallyImportedJSFunction*, TestExecutionTier,
RuntimeExceptionSupport, LowerSimd);
Reland "Reland "[wasm] Cache streaming compilation result"" This is a reland of 9781aa076f333ca27094a4d92beb8194af0051a1 Original change's description: > Reland "[wasm] Cache streaming compilation result" > > This is a reland of 015f379aa1f90168fe07a1c078ff5aae43a7915a > > Original change's description: > > [wasm] Cache streaming compilation result > > > > Before compiling the code section, check whether the > > bytes received so far match a cached module. If they do, delay > > compilation until we receive the full bytes, since we are likely to find > > a cache entry for them. > > > > R=clemensb@chromium.org > > > > Bug: v8:6847 > > Change-Id: Ie5170d1274da3da6d52ff1b408abc7cb441bbe3c > > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2002823 > > Commit-Queue: Thibaud Michaud <thibaudm@chromium.org> > > Reviewed-by: Clemens Backes <clemensb@chromium.org> > > Cr-Commit-Position: refs/heads/master@{#66000} > > Bug: v8:6847 > Change-Id: I0b5acffa01aeb7dade3dc966392814383d900015 > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2022951 > Commit-Queue: Thibaud Michaud <thibaudm@chromium.org> > Reviewed-by: Clemens Backes <clemensb@chromium.org> > Cr-Commit-Position: refs/heads/master@{#66047} Bug: v8:6847 Change-Id: I272f56eee28010f34cc99df475164581c8b63036 Cq-Include-Trybots: luci.v8.try:v8_linux64_tsan_rel Cq-Include-Trybots: luci.v8.try:v8_linux64_msan_rel Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2030741 Commit-Queue: Thibaud Michaud <thibaudm@chromium.org> Reviewed-by: Clemens Backes <clemensb@chromium.org> Cr-Commit-Position: refs/heads/master@{#66081}
2020-02-03 12:13:26 +00:00
~TestingModuleBuilder();
void ChangeOriginToAsmjs() { test_module_->origin = kAsmJsSloppyOrigin; }
byte* AddMemory(uint32_t size, SharedFlag shared = SharedFlag::kNotShared);
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
template <typename T>
T* AddMemoryElems(uint32_t count) {
AddMemory(count * sizeof(T));
return raw_mem_start<T>();
}
template <typename T>
T* AddGlobal(ValueType type = ValueType::For(MachineTypeForC<T>())) {
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);
}
byte AddSignature(const FunctionSig* sig) {
// TODO(7748): This will need updating for struct/array types support.
DCHECK_EQ(test_module_->types.size(), test_module_->signature_ids.size());
test_module_->add_signature(sig);
size_t size = test_module_->types.size();
CHECK_GT(127, size);
return static_cast<byte>(size - 1);
}
uint32_t mem_size() { return mem_size_; }
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_);
}
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_);
}
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]));
}
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));
}
template <typename T>
void WriteMemory(T* p, T val) {
WriteLittleEndianValue<T>(reinterpret_cast<Address>(p), val);
}
template <typename T>
T ReadMemory(T* p) {
return ReadLittleEndianValue<T>(reinterpret_cast<Address>(p));
}
// 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_);
}
// 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);
}
void SetMaxMemPages(uint32_t maximum_pages) {
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);
}
}
void SetHasSharedMemory() { test_module_->has_shared_memory = true; }
enum FunctionType { kImport, kWasm };
uint32_t AddFunction(const FunctionSig* sig, const char* name,
FunctionType type);
// Freezes the signature map of the module and allocates the storage for
// export wrappers.
void FreezeSignatureMapAndInitializeWrapperCache();
// Wrap the code so it can be called as a JS function.
Handle<JSFunction> WrapCode(uint32_t index);
// If function_indexes is {nullptr}, the contents of the table will be
// initialized with null functions.
void AddIndirectFunctionTable(const uint16_t* function_indexes,
uint32_t table_size);
uint32_t AddBytes(Vector<const byte> bytes);
uint32_t AddException(const FunctionSig* sig);
uint32_t AddPassiveDataSegment(Vector<const byte> bytes);
uint32_t AddPassiveElementSegment(const std::vector<uint32_t>& entries);
[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) {
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
}
WasmInterpreter* interpreter() const { return interpreter_.get(); }
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_;
}
WasmCode* GetFunctionCode(uint32_t index) const {
return native_module_->GetCode(index);
}
Address globals_start() const {
return reinterpret_cast<Address>(globals_data_);
Revert "Revert "[wasm] JIT using WasmCodeManager"" This reverts commit b301203e5aec9c8ff32f93aa31f8d764311e6e6e. Reason for revert: Fixed issues on arm. Original change's description: > Revert "[wasm] JIT using WasmCodeManager" > > This reverts commit d4c8393c1cc9cf3e2b19daabc3a161ff18d596cb. > > Reason for revert: Breaks ARM hardware: > https://build.chromium.org/p/client.v8.ports/builders/V8%20Arm%20-%20debug/builds/5268 > > Original change's description: > > [wasm] JIT using WasmCodeManager > > > > This is the first step towards wasm code sharing. This CL moves wasm > > code generation outside the JavaScript GC heap using the previously - > > introduced WasmCodeManager (all this, behind the --wasm-jit-to-native > > flag). > > > > See design document: go/wasm-on-native-heap-stage-1 > > > > This CL doesn't change other wasm architectural invariants. We still > > have per-Isolate wasm code generation, and per-wasm module instance > > code specialization. > > > > Bug:v8:6876 > > > > Cq-Include-Trybots: master.tryserver.chromium.linux:linux_chromium_rel_ng > > Change-Id: I1e08cecad75f93fb081545c31228a4568be276d3 > > Reviewed-on: https://chromium-review.googlesource.com/674086 > > Reviewed-by: Ben Titzer <titzer@chromium.org> > > Reviewed-by: Eric Holk <eholk@chromium.org> > > Cr-Commit-Position: refs/heads/master@{#49689} > > TBR=bradnelson@chromium.org,titzer@chromium.org,mtrofin@chromium.org,eholk@chromium.org > > Change-Id: I89af1ea5decd841bc12cd2ceaf74d32bc4433885 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: v8:6876 > Cq-Include-Trybots: master.tryserver.chromium.linux:linux_chromium_rel_ng > Reviewed-on: https://chromium-review.googlesource.com/794690 > Reviewed-by: Michael Achenbach <machenbach@chromium.org> > Commit-Queue: Michael Achenbach <machenbach@chromium.org> > Cr-Commit-Position: refs/heads/master@{#49691} TBR=bradnelson@chromium.org,machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,eholk@chromium.org Change-Id: I1b07638d1bb2ba0664305b4b2dcfc1342dc8444f No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: v8:6876 Cq-Include-Trybots: master.tryserver.chromium.linux:linux_chromium_rel_ng Reviewed-on: https://chromium-review.googlesource.com/794434 Commit-Queue: Mircea Trofin <mtrofin@chromium.org> Reviewed-by: Mircea Trofin <mtrofin@chromium.org> Cr-Commit-Position: refs/heads/master@{#49692}
2017-11-28 22:25:36 +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
void TierDown() {
Reland "[wasm][debug] Fix tier down for multiple isolates" This is a reland of 902f48bddad82337349ea3bc5029b38d9ffec11a, fixed to avoid lock inversion problems detected by TSan. Original change's description: > [wasm][debug] Fix tier down for multiple isolates > > If multiple isolates are using the same module, we need to keep it > tiered down as long as any isolate still has a debugger open. > Also, we cannot short-cut the {NativeModule::TierDown} method, since the > previously triggered tier down might not have finished yet. > For now, each isolate starts an independent tier down (i.e. a full > recompilation). We could optimize this later by skipping functions that > are already tiered down, or are already scheduled for tier down, but we > still need to wait for tier-down to finish on each isolate. > > R=thibaudm@chromium.org > > Bug: v8:10359 > Change-Id: I7ea6a6f5d3977e48718ac5bc94f9831541f6173f > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2190758 > Commit-Queue: Clemens Backes <clemensb@chromium.org> > Reviewed-by: Thibaud Michaud <thibaudm@chromium.org> > Cr-Commit-Position: refs/heads/master@{#67716} Bug: v8:10359 Cq-Include-Trybots: luci.v8.try:v8_linux64_tsan_rel Cq-Include-Trybots: luci.v8.try:v8_linux64_tsan_isolates_rel_ng Change-Id: Ie98cf073fc79e5c6991df6d4466de7b560274070 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2194451 Commit-Queue: Clemens Backes <clemensb@chromium.org> Reviewed-by: Thibaud Michaud <thibaudm@chromium.org> Cr-Commit-Position: refs/heads/master@{#67754}
2020-05-12 14:50:31 +00:00
native_module_->SetTieringState(kTieredDown);
native_module_->RecompileForTiering();
execution_tier_ = TestExecutionTier::kLiftoff;
}
CompilationEnv CreateCompilationEnv();
ExecutionTier execution_tier() const {
switch (execution_tier_) {
case TestExecutionTier::kTurbofan:
return ExecutionTier::kTurbofan;
case TestExecutionTier::kLiftoff:
return ExecutionTier::kLiftoff;
default:
UNREACHABLE();
}
}
RuntimeExceptionSupport runtime_exception_support() const {
return runtime_exception_support_;
}
private:
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_;
Isolate* isolate_;
WasmFeatures enabled_features_;
uint32_t global_offset = 0;
byte* mem_start_ = nullptr;
uint32_t mem_size_ = 0;
alignas(16) byte globals_data_[kMaxGlobalsSize];
std::unique_ptr<WasmInterpreter> interpreter_;
TestExecutionTier execution_tier_;
Handle<WasmInstanceObject> instance_object_;
NativeModule* native_module_ = nullptr;
RuntimeExceptionSupport runtime_exception_support_;
LowerSimd lower_simd_;
// 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_;
std::vector<byte> dropped_elem_segments_;
const WasmGlobal* AddGlobal(ValueType type);
Handle<WasmInstanceObject> InitInstanceObject();
};
void TestBuildingGraph(Zone* zone, compiler::JSGraph* jsgraph,
CompilationEnv* module, const FunctionSig* sig,
compiler::SourcePositionTable* source_position_table,
const byte* start, const byte* end);
class WasmFunctionWrapper : private compiler::GraphAndBuilders {
public:
WasmFunctionWrapper(Zone* zone, int num_params);
void Init(CallDescriptor* call_descriptor, MachineType return_type,
Vector<MachineType> param_types);
template <typename ReturnType, typename... ParamTypes>
void Init(CallDescriptor* call_descriptor) {
std::array<MachineType, sizeof...(ParamTypes)> param_machine_types{
{MachineTypeForC<ParamTypes>()...}};
Vector<MachineType> param_vec(param_machine_types.data(),
param_machine_types.size());
Init(call_descriptor, MachineTypeForC<ReturnType>(), param_vec);
}
void SetInnerCode(WasmCode* code) {
intptr_t address = static_cast<intptr_t>(code->instruction_start());
compiler::NodeProperties::ChangeOp(
inner_code_node_,
common()->ExternalConstant(ExternalReference::FromRawAddress(address)));
}
[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));
}
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
}
Handle<Code> GetWrapperCode();
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_;
MaybeHandle<Code> code_;
Signature<MachineType>* signature_;
};
// A helper for compiling wasm functions for testing.
// It contains the internal state for compilation (i.e. TurboFan graph) and
// interpretation (by adding to the interpreter manually).
class WasmFunctionCompiler : public compiler::GraphAndBuilders {
public:
~WasmFunctionCompiler();
Revert "Revert "[wasm] Rename TestingModule to TestingModuleBuilder."" This reverts commit 3913bde18848f95df41dc42627b826cb41231894. Reason for revert: Reason for revert fixed. Original change's description: > Revert "[wasm] Rename TestingModule to TestingModuleBuilder." > > This reverts commit ed06fc9127d2f965ece485293d2bc67fc6e0fb53. > > Reason for revert: Need to revert previous CL > > Original change's description: > > [wasm] Rename TestingModule to TestingModuleBuilder. > > > > This is a followup to moving the ModuleEnv to the compiler directory and > > making it immutable. > > > > R=​mtrofin@chromium.org, ahaas@chromium.org > > > > Bug: > > Change-Id: I0f5ec1b697bdcfad0b4dc2bca577cc0f40de8dc0 > > Reviewed-on: https://chromium-review.googlesource.com/616762 > > Commit-Queue: Ben Titzer <titzer@chromium.org> > > Reviewed-by: Mircea Trofin <mtrofin@chromium.org> > > Reviewed-by: Andreas Haas <ahaas@chromium.org> > > Cr-Commit-Position: refs/heads/master@{#47419} > > TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org > > Change-Id: I9b3b379e89f523c2fcf205a1d268aa294bbc44ff > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://chromium-review.googlesource.com/622567 > Reviewed-by: Michael Achenbach <machenbach@chromium.org> > Commit-Queue: Michael Achenbach <machenbach@chromium.org> > Cr-Commit-Position: refs/heads/master@{#47448} TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org Change-Id: Idce6f1ca8ed0ea80edb50292e9b6e2d7712f29cf No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://chromium-review.googlesource.com/622034 Reviewed-by: Mircea Trofin <mtrofin@chromium.org> Commit-Queue: Mircea Trofin <mtrofin@chromium.org> Cr-Commit-Position: refs/heads/master@{#47454}
2017-08-19 16:34:11 +00:00
Isolate* isolate() { return builder_->isolate(); }
CallDescriptor* descriptor() {
if (descriptor_ == nullptr) {
descriptor_ = compiler::GetWasmCallDescriptor(zone(), sig);
}
return descriptor_;
}
uint32_t function_index() { return function_->func_index; }
void Build(const byte* start, const byte* end);
byte AllocateLocal(ValueType type) {
uint32_t index = local_decls.AddLocals(1, type);
byte result = static_cast<byte>(index);
DCHECK_EQ(index, result);
return result;
}
void SetSigIndex(int sig_index) { function_->sig_index = sig_index; }
private:
friend class WasmRunnerBase;
WasmFunctionCompiler(Zone* zone, const FunctionSig* sig,
TestingModuleBuilder* builder, const char* name);
compiler::JSGraph jsgraph;
const FunctionSig* sig;
// The call descriptor is initialized when the function is compiled.
CallDescriptor* descriptor_;
Revert "Revert "[wasm] Rename TestingModule to TestingModuleBuilder."" This reverts commit 3913bde18848f95df41dc42627b826cb41231894. Reason for revert: Reason for revert fixed. Original change's description: > Revert "[wasm] Rename TestingModule to TestingModuleBuilder." > > This reverts commit ed06fc9127d2f965ece485293d2bc67fc6e0fb53. > > Reason for revert: Need to revert previous CL > > Original change's description: > > [wasm] Rename TestingModule to TestingModuleBuilder. > > > > This is a followup to moving the ModuleEnv to the compiler directory and > > making it immutable. > > > > R=​mtrofin@chromium.org, ahaas@chromium.org > > > > Bug: > > Change-Id: I0f5ec1b697bdcfad0b4dc2bca577cc0f40de8dc0 > > Reviewed-on: https://chromium-review.googlesource.com/616762 > > Commit-Queue: Ben Titzer <titzer@chromium.org> > > Reviewed-by: Mircea Trofin <mtrofin@chromium.org> > > Reviewed-by: Andreas Haas <ahaas@chromium.org> > > Cr-Commit-Position: refs/heads/master@{#47419} > > TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org > > Change-Id: I9b3b379e89f523c2fcf205a1d268aa294bbc44ff > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://chromium-review.googlesource.com/622567 > Reviewed-by: Michael Achenbach <machenbach@chromium.org> > Commit-Queue: Michael Achenbach <machenbach@chromium.org> > Cr-Commit-Position: refs/heads/master@{#47448} TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org Change-Id: Idce6f1ca8ed0ea80edb50292e9b6e2d7712f29cf No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://chromium-review.googlesource.com/622034 Reviewed-by: Mircea Trofin <mtrofin@chromium.org> Commit-Queue: Mircea Trofin <mtrofin@chromium.org> Cr-Commit-Position: refs/heads/master@{#47454}
2017-08-19 16:34:11 +00:00
TestingModuleBuilder* builder_;
WasmFunction* function_;
LocalDeclEncoder local_decls;
compiler::SourcePositionTable source_position_table_;
WasmInterpreter* interpreter_;
};
// A helper class to build a module around Wasm bytecode, generate machine
// code, and run that code.
class WasmRunnerBase : public InitializedHandleScope {
public:
WasmRunnerBase(ManuallyImportedJSFunction* maybe_import,
TestExecutionTier execution_tier, int num_params,
RuntimeExceptionSupport runtime_exception_support,
LowerSimd lower_simd)
: zone_(&allocator_, ZONE_NAME, kCompressGraphZone),
builder_(&zone_, maybe_import, execution_tier,
runtime_exception_support, lower_simd),
wrapper_(&zone_, num_params) {}
// Builds a graph from the given Wasm code and generates the machine
// code and call wrapper for that graph. This method must not be called
// more than once.
void Build(const byte* start, const byte* end) {
CHECK(!compiled_);
compiled_ = true;
functions_[0]->Build(start, end);
}
// Resets the state for building the next function.
// The main function called will always be the first function.
template <typename ReturnType, typename... ParamTypes>
WasmFunctionCompiler& NewFunction(const char* name = nullptr) {
return NewFunction(CreateSig<ReturnType, ParamTypes...>(), name);
}
// 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.
WasmFunctionCompiler& NewFunction(const FunctionSig* sig,
const char* name = nullptr) {
functions_.emplace_back(
new WasmFunctionCompiler(&zone_, sig, &builder_, name));
builder().AddSignature(sig);
return *functions_.back();
}
byte AllocateLocal(ValueType type) {
return functions_[0]->AllocateLocal(type);
}
uint32_t function_index() { return functions_[0]->function_index(); }
WasmFunction* function() { return functions_[0]->function_; }
WasmInterpreter* interpreter() {
DCHECK(interpret());
return functions_[0]->interpreter_;
}
bool possible_nondeterminism() { return possible_nondeterminism_; }
Revert "Revert "[wasm] Rename TestingModule to TestingModuleBuilder."" This reverts commit 3913bde18848f95df41dc42627b826cb41231894. Reason for revert: Reason for revert fixed. Original change's description: > Revert "[wasm] Rename TestingModule to TestingModuleBuilder." > > This reverts commit ed06fc9127d2f965ece485293d2bc67fc6e0fb53. > > Reason for revert: Need to revert previous CL > > Original change's description: > > [wasm] Rename TestingModule to TestingModuleBuilder. > > > > This is a followup to moving the ModuleEnv to the compiler directory and > > making it immutable. > > > > R=​mtrofin@chromium.org, ahaas@chromium.org > > > > Bug: > > Change-Id: I0f5ec1b697bdcfad0b4dc2bca577cc0f40de8dc0 > > Reviewed-on: https://chromium-review.googlesource.com/616762 > > Commit-Queue: Ben Titzer <titzer@chromium.org> > > Reviewed-by: Mircea Trofin <mtrofin@chromium.org> > > Reviewed-by: Andreas Haas <ahaas@chromium.org> > > Cr-Commit-Position: refs/heads/master@{#47419} > > TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org > > Change-Id: I9b3b379e89f523c2fcf205a1d268aa294bbc44ff > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://chromium-review.googlesource.com/622567 > Reviewed-by: Michael Achenbach <machenbach@chromium.org> > Commit-Queue: Michael Achenbach <machenbach@chromium.org> > Cr-Commit-Position: refs/heads/master@{#47448} TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org Change-Id: Idce6f1ca8ed0ea80edb50292e9b6e2d7712f29cf No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://chromium-review.googlesource.com/622034 Reviewed-by: Mircea Trofin <mtrofin@chromium.org> Commit-Queue: Mircea Trofin <mtrofin@chromium.org> Cr-Commit-Position: refs/heads/master@{#47454}
2017-08-19 16:34:11 +00:00
TestingModuleBuilder& builder() { return builder_; }
Zone* zone() { return &zone_; }
Revert "Revert "[wasm] Rename TestingModule to TestingModuleBuilder."" This reverts commit 3913bde18848f95df41dc42627b826cb41231894. Reason for revert: Reason for revert fixed. Original change's description: > Revert "[wasm] Rename TestingModule to TestingModuleBuilder." > > This reverts commit ed06fc9127d2f965ece485293d2bc67fc6e0fb53. > > Reason for revert: Need to revert previous CL > > Original change's description: > > [wasm] Rename TestingModule to TestingModuleBuilder. > > > > This is a followup to moving the ModuleEnv to the compiler directory and > > making it immutable. > > > > R=​mtrofin@chromium.org, ahaas@chromium.org > > > > Bug: > > Change-Id: I0f5ec1b697bdcfad0b4dc2bca577cc0f40de8dc0 > > Reviewed-on: https://chromium-review.googlesource.com/616762 > > Commit-Queue: Ben Titzer <titzer@chromium.org> > > Reviewed-by: Mircea Trofin <mtrofin@chromium.org> > > Reviewed-by: Andreas Haas <ahaas@chromium.org> > > Cr-Commit-Position: refs/heads/master@{#47419} > > TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org > > Change-Id: I9b3b379e89f523c2fcf205a1d268aa294bbc44ff > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://chromium-review.googlesource.com/622567 > Reviewed-by: Michael Achenbach <machenbach@chromium.org> > Commit-Queue: Michael Achenbach <machenbach@chromium.org> > Cr-Commit-Position: refs/heads/master@{#47448} TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org Change-Id: Idce6f1ca8ed0ea80edb50292e9b6e2d7712f29cf No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://chromium-review.googlesource.com/622034 Reviewed-by: Mircea Trofin <mtrofin@chromium.org> Commit-Queue: Mircea Trofin <mtrofin@chromium.org> Cr-Commit-Position: refs/heads/master@{#47454}
2017-08-19 16:34:11 +00:00
bool interpret() { return builder_.interpret(); }
void TierDown() { builder_.TierDown(); }
template <typename ReturnType, typename... ParamTypes>
FunctionSig* CreateSig() {
return WasmRunnerBase::CreateSig<ReturnType, ParamTypes...>(&zone_);
}
template <typename ReturnType, typename... ParamTypes>
static FunctionSig* CreateSig(Zone* zone) {
std::array<MachineType, sizeof...(ParamTypes)> param_machine_types{
{MachineTypeForC<ParamTypes>()...}};
Vector<MachineType> param_vec(param_machine_types.data(),
param_machine_types.size());
return CreateSig(zone, MachineTypeForC<ReturnType>(), param_vec);
}
private:
static FunctionSig* CreateSig(Zone* zone, MachineType return_type,
Vector<MachineType> param_types);
protected:
v8::internal::AccountingAllocator allocator_;
Zone zone_;
Revert "Revert "[wasm] Rename TestingModule to TestingModuleBuilder."" This reverts commit 3913bde18848f95df41dc42627b826cb41231894. Reason for revert: Reason for revert fixed. Original change's description: > Revert "[wasm] Rename TestingModule to TestingModuleBuilder." > > This reverts commit ed06fc9127d2f965ece485293d2bc67fc6e0fb53. > > Reason for revert: Need to revert previous CL > > Original change's description: > > [wasm] Rename TestingModule to TestingModuleBuilder. > > > > This is a followup to moving the ModuleEnv to the compiler directory and > > making it immutable. > > > > R=​mtrofin@chromium.org, ahaas@chromium.org > > > > Bug: > > Change-Id: I0f5ec1b697bdcfad0b4dc2bca577cc0f40de8dc0 > > Reviewed-on: https://chromium-review.googlesource.com/616762 > > Commit-Queue: Ben Titzer <titzer@chromium.org> > > Reviewed-by: Mircea Trofin <mtrofin@chromium.org> > > Reviewed-by: Andreas Haas <ahaas@chromium.org> > > Cr-Commit-Position: refs/heads/master@{#47419} > > TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org > > Change-Id: I9b3b379e89f523c2fcf205a1d268aa294bbc44ff > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://chromium-review.googlesource.com/622567 > Reviewed-by: Michael Achenbach <machenbach@chromium.org> > Commit-Queue: Michael Achenbach <machenbach@chromium.org> > Cr-Commit-Position: refs/heads/master@{#47448} TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org Change-Id: Idce6f1ca8ed0ea80edb50292e9b6e2d7712f29cf No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://chromium-review.googlesource.com/622034 Reviewed-by: Mircea Trofin <mtrofin@chromium.org> Commit-Queue: Mircea Trofin <mtrofin@chromium.org> Cr-Commit-Position: refs/heads/master@{#47454}
2017-08-19 16:34:11 +00:00
TestingModuleBuilder builder_;
std::vector<std::unique_ptr<WasmFunctionCompiler>> functions_;
WasmFunctionWrapper wrapper_;
bool compiled_ = false;
bool possible_nondeterminism_ = false;
int32_t main_fn_index_ = 0;
public:
// This field has to be static. Otherwise, gcc complains about the use in
// the lambda context below.
static bool trap_happened;
};
[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
template <typename ReturnType, typename... ParamTypes>
class WasmRunner : public WasmRunnerBase {
public:
WasmRunner(TestExecutionTier execution_tier,
ManuallyImportedJSFunction* maybe_import = nullptr,
const char* main_fn_name = "main",
RuntimeExceptionSupport runtime_exception_support =
kNoRuntimeExceptionSupport,
LowerSimd lower_simd = kNoLowerSimd)
: WasmRunnerBase(maybe_import, execution_tier, sizeof...(ParamTypes),
runtime_exception_support, lower_simd) {
WasmFunctionCompiler& main_fn =
NewFunction<ReturnType, ParamTypes...>(main_fn_name);
// Non-zero if there is an import.
main_fn_index_ = main_fn.function_index();
if (!interpret()) {
wrapper_.Init<ReturnType, ParamTypes...>(main_fn.descriptor());
}
[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
}
WasmRunner(TestExecutionTier execution_tier, LowerSimd lower_simd)
: WasmRunner(execution_tier, nullptr, "main", kNoRuntimeExceptionSupport,
lower_simd) {}
void SetUpTrapCallback() {
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);
}
ReturnType Call(ParamTypes... p) {
DCHECK(compiled_);
if (interpret()) return CallInterpreter(p...);
ReturnType return_value = static_cast<ReturnType>(0xDEADBEEFDEADBEEF);
SetUpTrapCallback();
wrapper_.SetInnerCode(builder_.GetFunctionCode(main_fn_index_));
wrapper_.SetInstance(builder_.instance_object());
builder_.SetExecutable();
Handle<Code> wrapper_code = wrapper_.GetWrapperCode();
compiler::CodeRunner<int32_t> runner(CcTest::InitIsolateOnce(),
wrapper_code, wrapper_.signature());
int32_t result;
{
SetThreadInWasmFlag();
result = runner.Call(static_cast<void*>(&p)...,
static_cast<void*>(&return_value));
ClearThreadInWasmFlag();
}
CHECK_EQ(WASM_WRAPPER_RETURN_VALUE, result);
return WasmRunnerBase::trap_happened
? static_cast<ReturnType>(0xDEADBEEFDEADBEEF)
: return_value;
}
ReturnType CallInterpreter(ParamTypes... p) {
interpreter()->Reset();
std::array<WasmValue, sizeof...(p)> args{{WasmValue(p)...}};
interpreter()->InitFrame(function(), args.data());
interpreter()->Run();
CHECK_GT(interpreter()->NumInterpretedCalls(), 0);
if (interpreter()->state() == WasmInterpreter::FINISHED) {
WasmValue val = interpreter()->GetReturnValue();
possible_nondeterminism_ |= interpreter()->PossibleNondeterminism();
return val.to<ReturnType>();
} else if (interpreter()->state() == WasmInterpreter::TRAPPED) {
// TODO(titzer): return the correct trap code
int64_t result = 0xDEADBEEFDEADBEEF;
return static_cast<ReturnType>(result);
} else {
// TODO(titzer): falling off end
return ReturnType{0};
}
}
void CheckCallApplyViaJS(double expected, uint32_t function_index,
Handle<Object>* buffer, int count) {
Isolate* isolate = builder_.isolate();
SetUpTrapCallback();
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 =
Execution::TryCall(isolate, jsfunc, global, count, buffer,
Execution::MessageHandling::kReport, nullptr);
if (retval.is_null() || WasmRunnerBase::trap_happened) {
CHECK_EQ(expected, static_cast<double>(0xDEADBEEF));
} else {
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());
}
}
if (builder_.interpret()) {
CHECK_GT(builder_.interpreter()->NumInterpretedCalls(), 0);
}
}
void CheckCallViaJS(double expected, ParamTypes... p) {
Isolate* isolate = builder_.isolate();
// MSVC doesn't allow empty arrays, so include a dummy at the end.
Handle<Object> buffer[] = {isolate->factory()->NewNumber(p)...,
Handle<Object>()};
CheckCallApplyViaJS(expected, function()->func_index, buffer, sizeof...(p));
}
void CheckCallViaJSTraps(ParamTypes... p) {
CheckCallViaJS(static_cast<double>(0xDEADBEEF), p...);
}
void CheckUsedExecutionTier(TestExecutionTier 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());
}
Handle<Code> GetWrapperCode() { return wrapper_.GetWrapperCode(); }
private:
wasm::WasmCodeRefScope code_ref_scope_;
std::vector<Handle<JSFunction>> jsfuncs_;
void SetThreadInWasmFlag() {
*reinterpret_cast<int*>(trap_handler::GetThreadInWasmThreadLocalAddress()) =
true;
}
void ClearThreadInWasmFlag() {
*reinterpret_cast<int*>(trap_handler::GetThreadInWasmThreadLocalAddress()) =
false;
}
};
// A macro to define tests that run in different engine configurations.
#define WASM_EXEC_TEST(name) \
void RunWasm_##name(TestExecutionTier execution_tier); \
TEST(RunWasmTurbofan_##name) { \
RunWasm_##name(TestExecutionTier::kTurbofan); \
} \
TEST(RunWasmLiftoff_##name) { RunWasm_##name(TestExecutionTier::kLiftoff); } \
TEST(RunWasmInterpreter_##name) { \
RunWasm_##name(TestExecutionTier::kInterpreter); \
} \
void RunWasm_##name(TestExecutionTier execution_tier)
#define WASM_COMPILED_EXEC_TEST(name) \
void RunWasm_##name(TestExecutionTier execution_tier); \
TEST(RunWasmTurbofan_##name) { \
RunWasm_##name(TestExecutionTier::kTurbofan); \
} \
TEST(RunWasmLiftoff_##name) { RunWasm_##name(TestExecutionTier::kLiftoff); } \
void RunWasm_##name(TestExecutionTier execution_tier)
} // namespace wasm
} // namespace internal
} // namespace v8
#endif