diff options
Diffstat (limited to 'deps/v8/test/unittests')
45 files changed, 1380 insertions, 310 deletions
diff --git a/deps/v8/test/unittests/BUILD.gn b/deps/v8/test/unittests/BUILD.gn index a6cf82f163..606fe9c343 100644 --- a/deps/v8/test/unittests/BUILD.gn +++ b/deps/v8/test/unittests/BUILD.gn @@ -41,6 +41,7 @@ v8_source_set("unittests_sources") { testonly = true sources = [ + "../../test/common/assembler-tester.h", "../../test/common/wasm/wasm-macro-gen.h", "../../testing/gmock-support.h", "../../testing/gtest-support.h", @@ -191,6 +192,7 @@ v8_source_set("unittests_sources") { "test-helpers.h", "test-utils.cc", "test-utils.h", + "torque/earley-parser-unittest.cc", "unicode-unittest.cc", "utils-unittest.cc", "value-serializer-unittest.cc", @@ -222,21 +224,45 @@ v8_source_set("unittests_sources") { } if (v8_current_cpu == "arm") { - sources += [ "compiler/arm/instruction-selector-arm-unittest.cc" ] + sources += [ + "assembler/turbo-assembler-arm-unittest.cc", + "compiler/arm/instruction-selector-arm-unittest.cc", + ] } else if (v8_current_cpu == "arm64") { - sources += [ "compiler/arm64/instruction-selector-arm64-unittest.cc" ] + sources += [ + "assembler/turbo-assembler-arm64-unittest.cc", + "compiler/arm64/instruction-selector-arm64-unittest.cc", + ] } else if (v8_current_cpu == "x86") { - sources += [ "compiler/ia32/instruction-selector-ia32-unittest.cc" ] + sources += [ + "assembler/turbo-assembler-ia32-unittest.cc", + "compiler/ia32/instruction-selector-ia32-unittest.cc", + ] } else if (v8_current_cpu == "mips" || v8_current_cpu == "mipsel") { - sources += [ "compiler/mips/instruction-selector-mips-unittest.cc" ] + sources += [ + "assembler/turbo-assembler-mips-unittest.cc", + "compiler/mips/instruction-selector-mips-unittest.cc", + ] } else if (v8_current_cpu == "mips64" || v8_current_cpu == "mips64el") { - sources += [ "compiler/mips64/instruction-selector-mips64-unittest.cc" ] + sources += [ + "assembler/turbo-assembler-mips64-unittest.cc", + "compiler/mips64/instruction-selector-mips64-unittest.cc", + ] } else if (v8_current_cpu == "x64") { - sources += [ "compiler/x64/instruction-selector-x64-unittest.cc" ] + sources += [ + "assembler/turbo-assembler-x64-unittest.cc", + "compiler/x64/instruction-selector-x64-unittest.cc", + ] } else if (v8_current_cpu == "ppc" || v8_current_cpu == "ppc64") { - sources += [ "compiler/ppc/instruction-selector-ppc-unittest.cc" ] + sources += [ + "assembler/turbo-assembler-ppc-unittest.cc", + "compiler/ppc/instruction-selector-ppc-unittest.cc", + ] } else if (v8_current_cpu == "s390" || v8_current_cpu == "s390x") { - sources += [ "compiler/s390/instruction-selector-s390-unittest.cc" ] + sources += [ + "assembler/turbo-assembler-s390-unittest.cc", + "compiler/s390/instruction-selector-s390-unittest.cc", + ] } configs = [ diff --git a/deps/v8/test/unittests/api/remote-object-unittest.cc b/deps/v8/test/unittests/api/remote-object-unittest.cc index 40754d50f4..5fa0646425 100644 --- a/deps/v8/test/unittests/api/remote-object-unittest.cc +++ b/deps/v8/test/unittests/api/remote-object-unittest.cc @@ -5,7 +5,7 @@ #include "testing/gtest/include/gtest/gtest.h" #include "include/v8.h" -#include "src/api.h" +#include "src/api-inl.h" #include "src/handles.h" #include "src/objects-inl.h" #include "test/unittests/test-utils.h" diff --git a/deps/v8/test/unittests/asmjs/asm-types-unittest.cc b/deps/v8/test/unittests/asmjs/asm-types-unittest.cc index 7430ce6b35..f17528977c 100644 --- a/deps/v8/test/unittests/asmjs/asm-types-unittest.cc +++ b/deps/v8/test/unittests/asmjs/asm-types-unittest.cc @@ -63,12 +63,12 @@ class AsmTypeTest : public TestWithZone { class FunctionTypeBuilder { public: - FunctionTypeBuilder(FunctionTypeBuilder&& b) + FunctionTypeBuilder(FunctionTypeBuilder&& b) V8_NOEXCEPT : function_type_(b.function_type_) { b.function_type_ = nullptr; } - FunctionTypeBuilder& operator=(FunctionTypeBuilder&& b) { + FunctionTypeBuilder& operator=(FunctionTypeBuilder&& b) V8_NOEXCEPT { if (this != &b) { function_type_ = b.function_type_; b.function_type_ = nullptr; diff --git a/deps/v8/test/unittests/assembler/turbo-assembler-arm-unittest.cc b/deps/v8/test/unittests/assembler/turbo-assembler-arm-unittest.cc new file mode 100644 index 0000000000..056bd1c2c6 --- /dev/null +++ b/deps/v8/test/unittests/assembler/turbo-assembler-arm-unittest.cc @@ -0,0 +1,78 @@ +// Copyright 2018 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. + +#include "src/arm/assembler-arm-inl.h" +#include "src/macro-assembler.h" +#include "src/simulator.h" +#include "test/common/assembler-tester.h" +#include "test/unittests/test-utils.h" +#include "testing/gtest-support.h" + +namespace v8 { +namespace internal { + +#define __ tasm. + +// If we are running on android and the output is not redirected (i.e. ends up +// in the android log) then we cannot find the error message in the output. This +// macro just returns the empty string in that case. +#if defined(ANDROID) && !defined(V8_ANDROID_LOG_STDOUT) +#define ERROR_MESSAGE(msg) "" +#else +#define ERROR_MESSAGE(msg) msg +#endif + +// Test the x64 assembler by compiling some simple functions into +// a buffer and executing them. These tests do not initialize the +// V8 library, create a context, or use any V8 objects. + +class TurboAssemblerTest : public TestWithIsolate {}; + +TEST_F(TurboAssemblerTest, TestHardAbort) { + size_t allocated; + byte* buffer = AllocateAssemblerBuffer(&allocated); + TurboAssembler tasm(nullptr, AssemblerOptions{}, buffer, + static_cast<int>(allocated), CodeObjectRequired::kNo); + __ set_abort_hard(true); + + __ Abort(AbortReason::kNoReason); + + CodeDesc desc; + tasm.GetCode(nullptr, &desc); + MakeAssemblerBufferExecutable(buffer, allocated); + // We need an isolate here to execute in the simulator. + auto f = GeneratedCode<void>::FromBuffer(isolate(), buffer); + + ASSERT_DEATH_IF_SUPPORTED({ f.Call(); }, ERROR_MESSAGE("abort: no reason")); +} + +TEST_F(TurboAssemblerTest, TestCheck) { + size_t allocated; + byte* buffer = AllocateAssemblerBuffer(&allocated); + TurboAssembler tasm(nullptr, AssemblerOptions{}, buffer, + static_cast<int>(allocated), CodeObjectRequired::kNo); + __ set_abort_hard(true); + + // Fail if the first parameter is 17. + __ Move32BitImmediate(r1, Operand(17)); + __ cmp(r0, r1); // 1st parameter is in {r0}. + __ Check(Condition::ne, AbortReason::kNoReason); + __ Ret(); + + CodeDesc desc; + tasm.GetCode(nullptr, &desc); + MakeAssemblerBufferExecutable(buffer, allocated); + // We need an isolate here to execute in the simulator. + auto f = GeneratedCode<void, int>::FromBuffer(isolate(), buffer); + + f.Call(0); + f.Call(18); + ASSERT_DEATH_IF_SUPPORTED({ f.Call(17); }, ERROR_MESSAGE("abort: no reason")); +} + +#undef __ +#undef ERROR_MESSAGE + +} // namespace internal +} // namespace v8 diff --git a/deps/v8/test/unittests/assembler/turbo-assembler-arm64-unittest.cc b/deps/v8/test/unittests/assembler/turbo-assembler-arm64-unittest.cc new file mode 100644 index 0000000000..e354fb91d9 --- /dev/null +++ b/deps/v8/test/unittests/assembler/turbo-assembler-arm64-unittest.cc @@ -0,0 +1,78 @@ +// Copyright 2018 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. + +#include "src/arm64/macro-assembler-arm64-inl.h" +#include "src/macro-assembler.h" +#include "src/simulator.h" +#include "test/common/assembler-tester.h" +#include "test/unittests/test-utils.h" +#include "testing/gtest-support.h" + +namespace v8 { +namespace internal { + +#define __ tasm. + +// If we are running on android and the output is not redirected (i.e. ends up +// in the android log) then we cannot find the error message in the output. This +// macro just returns the empty string in that case. +#if defined(ANDROID) && !defined(V8_ANDROID_LOG_STDOUT) +#define ERROR_MESSAGE(msg) "" +#else +#define ERROR_MESSAGE(msg) msg +#endif + +// Test the x64 assembler by compiling some simple functions into +// a buffer and executing them. These tests do not initialize the +// V8 library, create a context, or use any V8 objects. + +class TurboAssemblerTest : public TestWithIsolate {}; + +TEST_F(TurboAssemblerTest, TestHardAbort) { + size_t allocated; + byte* buffer = AllocateAssemblerBuffer(&allocated); + TurboAssembler tasm(nullptr, AssemblerOptions{}, buffer, + static_cast<int>(allocated), CodeObjectRequired::kNo); + __ set_abort_hard(true); + + __ Abort(AbortReason::kNoReason); + + CodeDesc desc; + tasm.GetCode(nullptr, &desc); + MakeAssemblerBufferExecutable(buffer, allocated); + // We need an isolate here to execute in the simulator. + auto f = GeneratedCode<void>::FromBuffer(isolate(), buffer); + + ASSERT_DEATH_IF_SUPPORTED({ f.Call(); }, ERROR_MESSAGE("abort: no reason")); +} + +TEST_F(TurboAssemblerTest, TestCheck) { + size_t allocated; + byte* buffer = AllocateAssemblerBuffer(&allocated); + TurboAssembler tasm(nullptr, AssemblerOptions{}, buffer, + static_cast<int>(allocated), CodeObjectRequired::kNo); + __ set_abort_hard(true); + + // Fail if the first parameter is 17. + __ Mov(w1, Immediate(17)); + __ Cmp(w0, w1); // 1st parameter is in {w0}. + __ Check(Condition::ne, AbortReason::kNoReason); + __ Ret(); + + CodeDesc desc; + tasm.GetCode(nullptr, &desc); + MakeAssemblerBufferExecutable(buffer, allocated); + // We need an isolate here to execute in the simulator. + auto f = GeneratedCode<void, int>::FromBuffer(isolate(), buffer); + + f.Call(0); + f.Call(18); + ASSERT_DEATH_IF_SUPPORTED({ f.Call(17); }, ERROR_MESSAGE("abort: no reason")); +} + +#undef __ +#undef ERROR_MESSAGE + +} // namespace internal +} // namespace v8 diff --git a/deps/v8/test/unittests/assembler/turbo-assembler-ia32-unittest.cc b/deps/v8/test/unittests/assembler/turbo-assembler-ia32-unittest.cc new file mode 100644 index 0000000000..ba3634314f --- /dev/null +++ b/deps/v8/test/unittests/assembler/turbo-assembler-ia32-unittest.cc @@ -0,0 +1,62 @@ +// Copyright 2018 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. + +#include "src/macro-assembler.h" +#include "src/simulator.h" +#include "test/common/assembler-tester.h" +#include "testing/gtest-support.h" + +namespace v8 { +namespace internal { + +#define __ tasm. + +// Test the x64 assembler by compiling some simple functions into +// a buffer and executing them. These tests do not initialize the +// V8 library, create a context, or use any V8 objects. + +TEST(TurboAssemblerTest, TestHardAbort) { + size_t allocated; + byte* buffer = AllocateAssemblerBuffer(&allocated); + TurboAssembler tasm(nullptr, AssemblerOptions{}, buffer, + static_cast<int>(allocated), CodeObjectRequired::kNo); + __ set_abort_hard(true); + + __ Abort(AbortReason::kNoReason); + + CodeDesc desc; + tasm.GetCode(nullptr, &desc); + MakeAssemblerBufferExecutable(buffer, allocated); + auto f = GeneratedCode<void>::FromBuffer(nullptr, buffer); + + ASSERT_DEATH_IF_SUPPORTED({ f.Call(); }, "abort: no reason"); +} + +TEST(TurboAssemblerTest, TestCheck) { + size_t allocated; + byte* buffer = AllocateAssemblerBuffer(&allocated); + TurboAssembler tasm(nullptr, AssemblerOptions{}, buffer, + static_cast<int>(allocated), CodeObjectRequired::kNo); + __ set_abort_hard(true); + + // Fail if the first parameter is 17. + __ mov(eax, 17); + __ cmp(eax, Operand(esp, 4)); // compare with 1st parameter. + __ Check(Condition::not_equal, AbortReason::kNoReason); + __ ret(0); + + CodeDesc desc; + tasm.GetCode(nullptr, &desc); + MakeAssemblerBufferExecutable(buffer, allocated); + auto f = GeneratedCode<void, int>::FromBuffer(nullptr, buffer); + + f.Call(0); + f.Call(18); + ASSERT_DEATH_IF_SUPPORTED({ f.Call(17); }, "abort: no reason"); +} + +#undef __ + +} // namespace internal +} // namespace v8 diff --git a/deps/v8/test/unittests/assembler/turbo-assembler-mips-unittest.cc b/deps/v8/test/unittests/assembler/turbo-assembler-mips-unittest.cc new file mode 100644 index 0000000000..abba0ff30b --- /dev/null +++ b/deps/v8/test/unittests/assembler/turbo-assembler-mips-unittest.cc @@ -0,0 +1,66 @@ +// Copyright 2018 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. + +#include "src/macro-assembler.h" +#include "src/mips/assembler-mips-inl.h" +#include "src/simulator.h" +#include "test/common/assembler-tester.h" +#include "test/unittests/test-utils.h" +#include "testing/gtest-support.h" + +namespace v8 { +namespace internal { + +#define __ tasm. + +// Test the x64 assembler by compiling some simple functions into +// a buffer and executing them. These tests do not initialize the +// V8 library, create a context, or use any V8 objects. + +class TurboAssemblerTest : public TestWithIsolate {}; + +TEST_F(TurboAssemblerTest, TestHardAbort) { + size_t allocated; + byte* buffer = AllocateAssemblerBuffer(&allocated); + TurboAssembler tasm(nullptr, AssemblerOptions{}, buffer, + static_cast<int>(allocated), CodeObjectRequired::kNo); + __ set_abort_hard(true); + + __ Abort(AbortReason::kNoReason); + + CodeDesc desc; + tasm.GetCode(nullptr, &desc); + MakeAssemblerBufferExecutable(buffer, allocated); + // We need an isolate here to execute in the simulator. + auto f = GeneratedCode<void>::FromBuffer(isolate(), buffer); + + ASSERT_DEATH_IF_SUPPORTED({ f.Call(); }, "abort: no reason"); +} + +TEST_F(TurboAssemblerTest, TestCheck) { + size_t allocated; + byte* buffer = AllocateAssemblerBuffer(&allocated); + TurboAssembler tasm(nullptr, AssemblerOptions{}, buffer, + static_cast<int>(allocated), CodeObjectRequired::kNo); + __ set_abort_hard(true); + + // Fail if the first parameter (in {a0}) is 17. + __ Check(Condition::ne, AbortReason::kNoReason, a0, Operand(17)); + __ Ret(); + + CodeDesc desc; + tasm.GetCode(nullptr, &desc); + MakeAssemblerBufferExecutable(buffer, allocated); + // We need an isolate here to execute in the simulator. + auto f = GeneratedCode<void, int>::FromBuffer(isolate(), buffer); + + f.Call(0); + f.Call(18); + ASSERT_DEATH_IF_SUPPORTED({ f.Call(17); }, "abort: no reason"); +} + +#undef __ + +} // namespace internal +} // namespace v8 diff --git a/deps/v8/test/unittests/assembler/turbo-assembler-mips64-unittest.cc b/deps/v8/test/unittests/assembler/turbo-assembler-mips64-unittest.cc new file mode 100644 index 0000000000..8d8bc0756c --- /dev/null +++ b/deps/v8/test/unittests/assembler/turbo-assembler-mips64-unittest.cc @@ -0,0 +1,66 @@ +// Copyright 2018 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. + +#include "src/macro-assembler.h" +#include "src/mips64/assembler-mips64-inl.h" +#include "src/simulator.h" +#include "test/common/assembler-tester.h" +#include "test/unittests/test-utils.h" +#include "testing/gtest-support.h" + +namespace v8 { +namespace internal { + +#define __ tasm. + +// Test the x64 assembler by compiling some simple functions into +// a buffer and executing them. These tests do not initialize the +// V8 library, create a context, or use any V8 objects. + +class TurboAssemblerTest : public TestWithIsolate {}; + +TEST_F(TurboAssemblerTest, TestHardAbort) { + size_t allocated; + byte* buffer = AllocateAssemblerBuffer(&allocated); + TurboAssembler tasm(nullptr, AssemblerOptions{}, buffer, + static_cast<int>(allocated), CodeObjectRequired::kNo); + __ set_abort_hard(true); + + __ Abort(AbortReason::kNoReason); + + CodeDesc desc; + tasm.GetCode(nullptr, &desc); + MakeAssemblerBufferExecutable(buffer, allocated); + // We need an isolate here to execute in the simulator. + auto f = GeneratedCode<void>::FromBuffer(isolate(), buffer); + + ASSERT_DEATH_IF_SUPPORTED({ f.Call(); }, "abort: no reason"); +} + +TEST_F(TurboAssemblerTest, TestCheck) { + size_t allocated; + byte* buffer = AllocateAssemblerBuffer(&allocated); + TurboAssembler tasm(nullptr, AssemblerOptions{}, buffer, + static_cast<int>(allocated), CodeObjectRequired::kNo); + __ set_abort_hard(true); + + // Fail if the first parameter (in {a0}) is 17. + __ Check(Condition::ne, AbortReason::kNoReason, a0, Operand(17)); + __ Ret(); + + CodeDesc desc; + tasm.GetCode(nullptr, &desc); + MakeAssemblerBufferExecutable(buffer, allocated); + // We need an isolate here to execute in the simulator. + auto f = GeneratedCode<void, int>::FromBuffer(isolate(), buffer); + + f.Call(0); + f.Call(18); + ASSERT_DEATH_IF_SUPPORTED({ f.Call(17); }, "abort: no reason"); +} + +#undef __ + +} // namespace internal +} // namespace v8 diff --git a/deps/v8/test/unittests/assembler/turbo-assembler-ppc-unittest.cc b/deps/v8/test/unittests/assembler/turbo-assembler-ppc-unittest.cc new file mode 100644 index 0000000000..8054eb1da5 --- /dev/null +++ b/deps/v8/test/unittests/assembler/turbo-assembler-ppc-unittest.cc @@ -0,0 +1,68 @@ +// Copyright 2018 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. + +#include "src/macro-assembler.h" +#include "src/ppc/assembler-ppc-inl.h" +#include "src/simulator.h" +#include "test/common/assembler-tester.h" +#include "test/unittests/test-utils.h" +#include "testing/gtest-support.h" + +namespace v8 { +namespace internal { + +#define __ tasm. + +// Test the ppc assembler by compiling some simple functions into +// a buffer and executing them. These tests do not initialize the +// V8 library, create a context, or use any V8 objects. + +class TurboAssemblerTest : public TestWithIsolate {}; + +TEST_F(TurboAssemblerTest, TestHardAbort) { + size_t allocated; + byte* buffer = AllocateAssemblerBuffer(&allocated); + TurboAssembler tasm(nullptr, AssemblerOptions{}, buffer, + static_cast<int>(allocated), CodeObjectRequired::kNo); + __ set_abort_hard(true); + + __ Abort(AbortReason::kNoReason); + + CodeDesc desc; + tasm.GetCode(nullptr, &desc); + MakeAssemblerBufferExecutable(buffer, allocated); + // We need an isolate here to execute in the simulator. + auto f = GeneratedCode<void>::FromBuffer(isolate(), buffer); + + ASSERT_DEATH_IF_SUPPORTED({ f.Call(); }, "abort: no reason"); +} + +TEST_F(TurboAssemblerTest, TestCheck) { + size_t allocated; + byte* buffer = AllocateAssemblerBuffer(&allocated); + TurboAssembler tasm(nullptr, AssemblerOptions{}, buffer, + static_cast<int>(allocated), CodeObjectRequired::kNo); + __ set_abort_hard(true); + + // Fail if the first parameter is 17. + __ mov(r4, Operand(17)); + __ cmp(r3, r4); // 1st parameter is in {r3}. + __ Check(Condition::ne, AbortReason::kNoReason); + __ Ret(); + + CodeDesc desc; + tasm.GetCode(nullptr, &desc); + MakeAssemblerBufferExecutable(buffer, allocated); + // We need an isolate here to execute in the simulator. + auto f = GeneratedCode<void, int>::FromBuffer(isolate(), buffer); + + f.Call(0); + f.Call(18); + ASSERT_DEATH_IF_SUPPORTED({ f.Call(17); }, "abort: no reason"); +} + +#undef __ + +} // namespace internal +} // namespace v8 diff --git a/deps/v8/test/unittests/assembler/turbo-assembler-s390-unittest.cc b/deps/v8/test/unittests/assembler/turbo-assembler-s390-unittest.cc new file mode 100644 index 0000000000..7d45ec907f --- /dev/null +++ b/deps/v8/test/unittests/assembler/turbo-assembler-s390-unittest.cc @@ -0,0 +1,68 @@ +// Copyright 2018 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. + +#include "src/macro-assembler.h" +#include "src/s390/assembler-s390-inl.h" +#include "src/simulator.h" +#include "test/common/assembler-tester.h" +#include "test/unittests/test-utils.h" +#include "testing/gtest-support.h" + +namespace v8 { +namespace internal { + +#define __ tasm. + +// Test the s390 assembler by compiling some simple functions into +// a buffer and executing them. These tests do not initialize the +// V8 library, create a context, or use any V8 objects. + +class TurboAssemblerTest : public TestWithIsolate {}; + +TEST_F(TurboAssemblerTest, TestHardAbort) { + size_t allocated; + byte* buffer = AllocateAssemblerBuffer(&allocated); + TurboAssembler tasm(nullptr, AssemblerOptions{}, buffer, + static_cast<int>(allocated), CodeObjectRequired::kNo); + __ set_abort_hard(true); + + __ Abort(AbortReason::kNoReason); + + CodeDesc desc; + tasm.GetCode(nullptr, &desc); + MakeAssemblerBufferExecutable(buffer, allocated); + // We need an isolate here to execute in the simulator. + auto f = GeneratedCode<void>::FromBuffer(isolate(), buffer); + + ASSERT_DEATH_IF_SUPPORTED({ f.Call(); }, "abort: no reason"); +} + +TEST_F(TurboAssemblerTest, TestCheck) { + size_t allocated; + byte* buffer = AllocateAssemblerBuffer(&allocated); + TurboAssembler tasm(nullptr, AssemblerOptions{}, buffer, + static_cast<int>(allocated), CodeObjectRequired::kNo); + __ set_abort_hard(true); + + // Fail if the first parameter is 17. + __ lgfi(r3, Operand(17)); + __ CmpP(r2, r3); // 1st parameter is in {r2}. + __ Check(Condition::ne, AbortReason::kNoReason); + __ Ret(); + + CodeDesc desc; + tasm.GetCode(nullptr, &desc); + MakeAssemblerBufferExecutable(buffer, allocated); + // We need an isolate here to execute in the simulator. + auto f = GeneratedCode<void, int>::FromBuffer(isolate(), buffer); + + f.Call(0); + f.Call(18); + ASSERT_DEATH_IF_SUPPORTED({ f.Call(17); }, "abort: no reason"); +} + +#undef __ + +} // namespace internal +} // namespace v8 diff --git a/deps/v8/test/unittests/assembler/turbo-assembler-x64-unittest.cc b/deps/v8/test/unittests/assembler/turbo-assembler-x64-unittest.cc new file mode 100644 index 0000000000..060060c762 --- /dev/null +++ b/deps/v8/test/unittests/assembler/turbo-assembler-x64-unittest.cc @@ -0,0 +1,62 @@ +// Copyright 2018 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. + +#include "src/macro-assembler.h" +#include "src/simulator.h" +#include "test/common/assembler-tester.h" +#include "testing/gtest-support.h" + +namespace v8 { +namespace internal { + +#define __ tasm. + +// Test the x64 assembler by compiling some simple functions into +// a buffer and executing them. These tests do not initialize the +// V8 library, create a context, or use any V8 objects. + +TEST(TurboAssemblerTest, TestHardAbort) { + size_t allocated; + byte* buffer = AllocateAssemblerBuffer(&allocated); + TurboAssembler tasm(nullptr, AssemblerOptions{}, buffer, + static_cast<int>(allocated), CodeObjectRequired::kNo); + __ set_abort_hard(true); + + __ Abort(AbortReason::kNoReason); + + CodeDesc desc; + tasm.GetCode(nullptr, &desc); + MakeAssemblerBufferExecutable(buffer, allocated); + auto f = GeneratedCode<void>::FromBuffer(nullptr, buffer); + + ASSERT_DEATH_IF_SUPPORTED({ f.Call(); }, "abort: no reason"); +} + +TEST(TurboAssemblerTest, TestCheck) { + size_t allocated; + byte* buffer = AllocateAssemblerBuffer(&allocated); + TurboAssembler tasm(nullptr, AssemblerOptions{}, buffer, + static_cast<int>(allocated), CodeObjectRequired::kNo); + __ set_abort_hard(true); + + // Fail if the first parameter is 17. + __ movl(rax, Immediate(17)); + __ cmpl(rax, arg_reg_1); + __ Check(Condition::not_equal, AbortReason::kNoReason); + __ ret(0); + + CodeDesc desc; + tasm.GetCode(nullptr, &desc); + MakeAssemblerBufferExecutable(buffer, allocated); + auto f = GeneratedCode<void, int>::FromBuffer(nullptr, buffer); + + f.Call(0); + f.Call(18); + ASSERT_DEATH_IF_SUPPORTED({ f.Call(17); }, "abort: no reason"); +} + +#undef __ + +} // namespace internal +} // namespace v8 diff --git a/deps/v8/test/unittests/base/functional-unittest.cc b/deps/v8/test/unittests/base/functional-unittest.cc index 10f9f32c7d..b9295d49a0 100644 --- a/deps/v8/test/unittests/base/functional-unittest.cc +++ b/deps/v8/test/unittests/base/functional-unittest.cc @@ -74,7 +74,9 @@ TYPED_TEST(FunctionalTest, EqualToImpliesSameHashCode) { this->rng()->NextBytes(values, sizeof(values)); TRACED_FOREACH(TypeParam, v1, values) { TRACED_FOREACH(TypeParam, v2, values) { - if (e(v1, v2)) EXPECT_EQ(h(v1), h(v2)); + if (e(v1, v2)) { + EXPECT_EQ(h(v1), h(v2)); + } } } } @@ -143,7 +145,9 @@ TYPED_TEST(FunctionalTest, BitEqualToImpliesSameBitHash) { this->rng()->NextBytes(&values, sizeof(values)); TRACED_FOREACH(TypeParam, v1, values) { TRACED_FOREACH(TypeParam, v2, values) { - if (e(v1, v2)) EXPECT_EQ(h(v1), h(v2)); + if (e(v1, v2)) { + EXPECT_EQ(h(v1), h(v2)); + } } } } diff --git a/deps/v8/test/unittests/compiler-dispatcher/compiler-dispatcher-unittest.cc b/deps/v8/test/unittests/compiler-dispatcher/compiler-dispatcher-unittest.cc index c523906027..45121aedb3 100644 --- a/deps/v8/test/unittests/compiler-dispatcher/compiler-dispatcher-unittest.cc +++ b/deps/v8/test/unittests/compiler-dispatcher/compiler-dispatcher-unittest.cc @@ -7,7 +7,7 @@ #include <sstream> #include "include/v8-platform.h" -#include "src/api.h" +#include "src/api-inl.h" #include "src/ast/ast-value-factory.h" #include "src/base/platform/semaphore.h" #include "src/base/template-utils.h" diff --git a/deps/v8/test/unittests/compiler-dispatcher/optimizing-compile-dispatcher-unittest.cc b/deps/v8/test/unittests/compiler-dispatcher/optimizing-compile-dispatcher-unittest.cc index 95052c9b75..b796e457d4 100644 --- a/deps/v8/test/unittests/compiler-dispatcher/optimizing-compile-dispatcher-unittest.cc +++ b/deps/v8/test/unittests/compiler-dispatcher/optimizing-compile-dispatcher-unittest.cc @@ -4,6 +4,7 @@ #include "src/compiler-dispatcher/optimizing-compile-dispatcher.h" +#include "src/api-inl.h" #include "src/base/atomic-utils.h" #include "src/base/platform/semaphore.h" #include "src/compiler.h" diff --git a/deps/v8/test/unittests/compiler-dispatcher/unoptimized-compile-job-unittest.cc b/deps/v8/test/unittests/compiler-dispatcher/unoptimized-compile-job-unittest.cc index f7fb335ac6..5a0e89326b 100644 --- a/deps/v8/test/unittests/compiler-dispatcher/unoptimized-compile-job-unittest.cc +++ b/deps/v8/test/unittests/compiler-dispatcher/unoptimized-compile-job-unittest.cc @@ -5,7 +5,7 @@ #include <memory> #include "include/v8.h" -#include "src/api.h" +#include "src/api-inl.h" #include "src/ast/ast.h" #include "src/ast/scopes.h" #include "src/base/platform/semaphore.h" diff --git a/deps/v8/test/unittests/compiler/arm/instruction-selector-arm-unittest.cc b/deps/v8/test/unittests/compiler/arm/instruction-selector-arm-unittest.cc index 70e04043c4..011cc67c81 100644 --- a/deps/v8/test/unittests/compiler/arm/instruction-selector-arm-unittest.cc +++ b/deps/v8/test/unittests/compiler/arm/instruction-selector-arm-unittest.cc @@ -1183,12 +1183,12 @@ TEST_P(InstructionSelectorShiftTest, Word32EqualToZeroWithImmediate) { } } - -TEST_P(InstructionSelectorShiftTest, Word32NotWithParameters) { +TEST_P(InstructionSelectorShiftTest, Word32BitwiseNotWithParameters) { const Shift shift = GetParam(); StreamBuilder m(this, MachineType::Int32(), MachineType::Int32(), MachineType::Int32()); - m.Return(m.Word32Not((m.*shift.constructor)(m.Parameter(0), m.Parameter(1)))); + m.Return(m.Word32BitwiseNot( + (m.*shift.constructor)(m.Parameter(0), m.Parameter(1)))); Stream s = m.Build(); ASSERT_EQ(1U, s.size()); EXPECT_EQ(kArmMvn, s[0]->arch_opcode()); @@ -1197,12 +1197,11 @@ TEST_P(InstructionSelectorShiftTest, Word32NotWithParameters) { EXPECT_EQ(1U, s[0]->OutputCount()); } - -TEST_P(InstructionSelectorShiftTest, Word32NotWithImmediate) { +TEST_P(InstructionSelectorShiftTest, Word32BitwiseNotWithImmediate) { const Shift shift = GetParam(); TRACED_FORRANGE(int32_t, imm, shift.i_low, shift.i_high) { StreamBuilder m(this, MachineType::Int32(), MachineType::Int32()); - m.Return(m.Word32Not( + m.Return(m.Word32BitwiseNot( (m.*shift.constructor)(m.Parameter(0), m.Int32Constant(imm)))); Stream s = m.Build(); ASSERT_EQ(1U, s.size()); @@ -1214,13 +1213,14 @@ TEST_P(InstructionSelectorShiftTest, Word32NotWithImmediate) { } } - -TEST_P(InstructionSelectorShiftTest, Word32AndWithWord32NotWithParameters) { +TEST_P(InstructionSelectorShiftTest, + Word32AndWithWord32BitwiseNotWithParameters) { const Shift shift = GetParam(); StreamBuilder m(this, MachineType::Int32(), MachineType::Int32(), MachineType::Int32(), MachineType::Int32()); - m.Return(m.Word32And(m.Parameter(0), m.Word32Not((m.*shift.constructor)( - m.Parameter(1), m.Parameter(2))))); + m.Return( + m.Word32And(m.Parameter(0), m.Word32BitwiseNot((m.*shift.constructor)( + m.Parameter(1), m.Parameter(2))))); Stream s = m.Build(); ASSERT_EQ(1U, s.size()); EXPECT_EQ(kArmBic, s[0]->arch_opcode()); @@ -1229,14 +1229,14 @@ TEST_P(InstructionSelectorShiftTest, Word32AndWithWord32NotWithParameters) { EXPECT_EQ(1U, s[0]->OutputCount()); } - -TEST_P(InstructionSelectorShiftTest, Word32AndWithWord32NotWithImmediate) { +TEST_P(InstructionSelectorShiftTest, + Word32AndWithWord32BitwiseNotWithImmediate) { const Shift shift = GetParam(); TRACED_FORRANGE(int32_t, imm, shift.i_low, shift.i_high) { StreamBuilder m(this, MachineType::Int32(), MachineType::Int32(), MachineType::Int32()); m.Return(m.Word32And(m.Parameter(0), - m.Word32Not((m.*shift.constructor)( + m.Word32BitwiseNot((m.*shift.constructor)( m.Parameter(1), m.Int32Constant(imm))))); Stream s = m.Build(); ASSERT_EQ(1U, s.size()); @@ -2971,12 +2971,11 @@ TEST_F(InstructionSelectorTest, Word32ShrWithWord32AndWithImmediateForARMv7) { } } - -TEST_F(InstructionSelectorTest, Word32AndWithWord32Not) { +TEST_F(InstructionSelectorTest, Word32AndWithWord32BitwiseNot) { { StreamBuilder m(this, MachineType::Int32(), MachineType::Int32(), MachineType::Int32()); - m.Return(m.Word32And(m.Parameter(0), m.Word32Not(m.Parameter(1)))); + m.Return(m.Word32And(m.Parameter(0), m.Word32BitwiseNot(m.Parameter(1)))); Stream s = m.Build(); ASSERT_EQ(1U, s.size()); EXPECT_EQ(kArmBic, s[0]->arch_opcode()); @@ -2987,7 +2986,7 @@ TEST_F(InstructionSelectorTest, Word32AndWithWord32Not) { { StreamBuilder m(this, MachineType::Int32(), MachineType::Int32(), MachineType::Int32()); - m.Return(m.Word32And(m.Word32Not(m.Parameter(0)), m.Parameter(1))); + m.Return(m.Word32And(m.Word32BitwiseNot(m.Parameter(0)), m.Parameter(1))); Stream s = m.Build(); ASSERT_EQ(1U, s.size()); EXPECT_EQ(kArmBic, s[0]->arch_opcode()); @@ -3076,10 +3075,9 @@ TEST_F(InstructionSelectorTest, Word32EqualWithZero) { } } - -TEST_F(InstructionSelectorTest, Word32NotWithParameter) { +TEST_F(InstructionSelectorTest, Word32BitwiseNotWithParameter) { StreamBuilder m(this, MachineType::Int32(), MachineType::Int32()); - m.Return(m.Word32Not(m.Parameter(0))); + m.Return(m.Word32BitwiseNot(m.Parameter(0))); Stream s = m.Build(); ASSERT_EQ(1U, s.size()); EXPECT_EQ(kArmMvn, s[0]->arch_opcode()); diff --git a/deps/v8/test/unittests/compiler/arm64/instruction-selector-arm64-unittest.cc b/deps/v8/test/unittests/compiler/arm64/instruction-selector-arm64-unittest.cc index be876c7cb3..aa54abe320 100644 --- a/deps/v8/test/unittests/compiler/arm64/instruction-selector-arm64-unittest.cc +++ b/deps/v8/test/unittests/compiler/arm64/instruction-selector-arm64-unittest.cc @@ -1327,6 +1327,70 @@ TEST_F(InstructionSelectorTest, Word64AndBranchWithOneBitMaskOnLeft) { } } +TEST_F(InstructionSelectorTest, TestAndBranch64EqualWhenCanCoverFalse) { + TRACED_FORRANGE(int, bit, 0, 63) { + uint64_t mask = uint64_t{1} << bit; + StreamBuilder m(this, MachineType::Int64(), MachineType::Int64()); + RawMachineLabel a, b, c; + Node* n = m.Word64And(m.Parameter(0), m.Int64Constant(mask)); + m.Branch(m.Word64Equal(n, m.Int64Constant(0)), &a, &b); + m.Bind(&a); + m.Branch(m.Word64Equal(n, m.Int64Constant(3)), &b, &c); + m.Bind(&c); + m.Return(m.Int64Constant(1)); + m.Bind(&b); + m.Return(m.Int64Constant(0)); + + Stream s = m.Build(); + ASSERT_EQ(3U, s.size()); + EXPECT_EQ(kArm64And, s[0]->arch_opcode()); + EXPECT_EQ(kEqual, s[0]->flags_condition()); + EXPECT_EQ(kArm64TestAndBranch, s[1]->arch_opcode()); + EXPECT_EQ(kEqual, s[1]->flags_condition()); + EXPECT_EQ(kArm64Cmp, s[2]->arch_opcode()); + EXPECT_EQ(kEqual, s[2]->flags_condition()); + EXPECT_EQ(2U, s[0]->InputCount()); + } +} + +TEST_F(InstructionSelectorTest, TestAndBranch64AndWhenCanCoverFalse) { + TRACED_FORRANGE(int, bit, 0, 63) { + uint64_t mask = uint64_t{1} << bit; + StreamBuilder m(this, MachineType::Int64(), MachineType::Int64()); + RawMachineLabel a, b, c; + m.Branch(m.Word64And(m.Parameter(0), m.Int64Constant(mask)), &a, &b); + m.Bind(&a); + m.Return(m.Int64Constant(1)); + m.Bind(&b); + m.Return(m.Int64Constant(0)); + + Stream s = m.Build(); + ASSERT_EQ(1U, s.size()); + EXPECT_EQ(kArm64TestAndBranch, s[0]->arch_opcode()); + EXPECT_EQ(InstructionOperand::IMMEDIATE, s[0]->InputAt(1)->kind()); + EXPECT_EQ(4U, s[0]->InputCount()); + } +} + +TEST_F(InstructionSelectorTest, TestAndBranch32AndWhenCanCoverFalse) { + TRACED_FORRANGE(int, bit, 0, 31) { + uint32_t mask = uint32_t{1} << bit; + StreamBuilder m(this, MachineType::Int64(), MachineType::Int64()); + RawMachineLabel a, b, c; + m.Branch(m.Word32And(m.Parameter(0), m.Int32Constant(mask)), &a, &b); + m.Bind(&a); + m.Return(m.Int32Constant(1)); + m.Bind(&b); + m.Return(m.Int32Constant(0)); + + Stream s = m.Build(); + ASSERT_EQ(1U, s.size()); + EXPECT_EQ(kArm64TestAndBranch32, s[0]->arch_opcode()); + EXPECT_EQ(InstructionOperand::IMMEDIATE, s[0]->InputAt(1)->kind()); + EXPECT_EQ(4U, s[0]->InputCount()); + } +} + TEST_F(InstructionSelectorTest, Word32EqualZeroAndBranchWithOneBitMask) { TRACED_FORRANGE(int, bit, 0, 31) { uint32_t mask = 1 << bit; @@ -3746,8 +3810,8 @@ TEST_P(InstructionSelectorLogicalWithNotRHSTest, Parameter) { { StreamBuilder m(this, type, type, type); if (type == MachineType::Int32()) { - m.Return( - (m.*inst.constructor)(m.Parameter(0), m.Word32Not(m.Parameter(1)))); + m.Return((m.*inst.constructor)(m.Parameter(0), + m.Word32BitwiseNot(m.Parameter(1)))); } else { ASSERT_EQ(MachineType::Int64(), type); m.Return( @@ -3762,8 +3826,8 @@ TEST_P(InstructionSelectorLogicalWithNotRHSTest, Parameter) { { StreamBuilder m(this, type, type, type); if (type == MachineType::Int32()) { - m.Return( - (m.*inst.constructor)(m.Word32Not(m.Parameter(0)), m.Parameter(1))); + m.Return((m.*inst.constructor)(m.Word32BitwiseNot(m.Parameter(0)), + m.Parameter(1))); } else { ASSERT_EQ(MachineType::Int64(), type); m.Return( @@ -3782,10 +3846,9 @@ INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, InstructionSelectorLogicalWithNotRHSTest, ::testing::ValuesIn(kLogicalWithNotRHSs)); - -TEST_F(InstructionSelectorTest, Word32NotWithParameter) { +TEST_F(InstructionSelectorTest, Word32BitwiseNotWithParameter) { StreamBuilder m(this, MachineType::Int32(), MachineType::Int32()); - m.Return(m.Word32Not(m.Parameter(0))); + m.Return(m.Word32BitwiseNot(m.Parameter(0))); Stream s = m.Build(); ASSERT_EQ(1U, s.size()); EXPECT_EQ(kArm64Not32, s[0]->arch_opcode()); diff --git a/deps/v8/test/unittests/compiler/common-operator-reducer-unittest.cc b/deps/v8/test/unittests/compiler/common-operator-reducer-unittest.cc index 086fa2ec7d..cb5b5fd806 100644 --- a/deps/v8/test/unittests/compiler/common-operator-reducer-unittest.cc +++ b/deps/v8/test/unittests/compiler/common-operator-reducer-unittest.cc @@ -29,7 +29,7 @@ class CommonOperatorReducerTest : public GraphTest { Reduction Reduce( AdvancedReducer::Editor* editor, Node* node, MachineOperatorBuilder::Flags flags = MachineOperatorBuilder::kNoFlags) { - JSHeapBroker broker(isolate()); + JSHeapBroker broker(isolate(), zone()); MachineOperatorBuilder machine(zone(), MachineType::PointerRepresentation(), flags); CommonOperatorReducer reducer(editor, graph(), &broker, common(), &machine, diff --git a/deps/v8/test/unittests/compiler/constant-folding-reducer-unittest.cc b/deps/v8/test/unittests/compiler/constant-folding-reducer-unittest.cc index 6780bf8500..464ee3a971 100644 --- a/deps/v8/test/unittests/compiler/constant-folding-reducer-unittest.cc +++ b/deps/v8/test/unittests/compiler/constant-folding-reducer-unittest.cc @@ -63,7 +63,7 @@ class ConstantFoldingReducerTest : public TypedGraphTest { public: ConstantFoldingReducerTest() : TypedGraphTest(3), - js_heap_broker_(isolate()), + js_heap_broker_(isolate(), zone()), simplified_(zone()), deps_(isolate(), zone()) {} ~ConstantFoldingReducerTest() override {} @@ -81,7 +81,7 @@ class ConstantFoldingReducerTest : public TypedGraphTest { } SimplifiedOperatorBuilder* simplified() { return &simplified_; } - const JSHeapBroker* js_heap_broker() const { return &js_heap_broker_; } + JSHeapBroker* js_heap_broker() { return &js_heap_broker_; } private: JSHeapBroker js_heap_broker_; diff --git a/deps/v8/test/unittests/compiler/graph-unittest.cc b/deps/v8/test/unittests/compiler/graph-unittest.cc index a731a8f1cb..af2c382f5b 100644 --- a/deps/v8/test/unittests/compiler/graph-unittest.cc +++ b/deps/v8/test/unittests/compiler/graph-unittest.cc @@ -16,9 +16,10 @@ namespace compiler { GraphTest::GraphTest(int num_parameters) : TestWithNativeContext(), TestWithIsolateAndZone(), + canonical_(isolate()), common_(zone()), graph_(zone()), - js_heap_broker_(isolate()), + js_heap_broker_(isolate(), zone()), source_positions_(&graph_), node_origins_(&graph_) { graph()->SetStart(graph()->NewNode(common()->Start(num_parameters))); diff --git a/deps/v8/test/unittests/compiler/graph-unittest.h b/deps/v8/test/unittests/compiler/graph-unittest.h index 1a9c83bb8a..d9b9934770 100644 --- a/deps/v8/test/unittests/compiler/graph-unittest.h +++ b/deps/v8/test/unittests/compiler/graph-unittest.h @@ -10,6 +10,7 @@ #include "src/compiler/graph.h" #include "src/compiler/node-origin-table.h" #include "src/compiler/typer.h" +#include "src/handles.h" #include "test/unittests/test-utils.h" #include "testing/gmock/include/gmock/gmock.h" @@ -17,8 +18,6 @@ namespace v8 { namespace internal { // Forward declarations. -template <class T> -class Handle; class HeapObject; namespace compiler { @@ -62,9 +61,10 @@ class GraphTest : public virtual TestWithNativeContext, Graph* graph() { return &graph_; } SourcePositionTable* source_positions() { return &source_positions_; } NodeOriginTable* node_origins() { return &node_origins_; } - const JSHeapBroker* js_heap_broker() { return &js_heap_broker_; } + JSHeapBroker* js_heap_broker() { return &js_heap_broker_; } private: + CanonicalHandleScope canonical_; CommonOperatorBuilder common_; Graph graph_; JSHeapBroker js_heap_broker_; diff --git a/deps/v8/test/unittests/compiler/int64-lowering-unittest.cc b/deps/v8/test/unittests/compiler/int64-lowering-unittest.cc index 5897187ae4..4df81d5d59 100644 --- a/deps/v8/test/unittests/compiler/int64-lowering-unittest.cc +++ b/deps/v8/test/unittests/compiler/int64-lowering-unittest.cc @@ -882,7 +882,7 @@ TEST_F(Int64LoweringTest, I64PhiWord32) { } TEST_F(Int64LoweringTest, I64ReverseBytes) { - LowerGraph(graph()->NewNode(machine()->Word64ReverseBytes().placeholder(), + LowerGraph(graph()->NewNode(machine()->Word64ReverseBytes(), Int64Constant(value(0))), MachineRepresentation::kWord64); EXPECT_THAT( diff --git a/deps/v8/test/unittests/compiler/js-call-reducer-unittest.cc b/deps/v8/test/unittests/compiler/js-call-reducer-unittest.cc index 1f5e666eb2..53e3b48762 100644 --- a/deps/v8/test/unittests/compiler/js-call-reducer-unittest.cc +++ b/deps/v8/test/unittests/compiler/js-call-reducer-unittest.cc @@ -24,7 +24,7 @@ class JSCallReducerTest : public TypedGraphTest { : TypedGraphTest(3), javascript_(zone()), deps_(isolate(), zone()), - js_heap_broker(isolate()) {} + js_heap_broker(isolate(), zone()) {} ~JSCallReducerTest() override {} protected: diff --git a/deps/v8/test/unittests/compiler/load-elimination-unittest.cc b/deps/v8/test/unittests/compiler/load-elimination-unittest.cc index 8cf5bd3236..5c49468991 100644 --- a/deps/v8/test/unittests/compiler/load-elimination-unittest.cc +++ b/deps/v8/test/unittests/compiler/load-elimination-unittest.cc @@ -410,9 +410,10 @@ TEST_F(LoadEliminationTest, LoadFieldWithTypeMismatch) { Node* load = graph()->NewNode(simplified()->LoadField(access), object, effect, control); + EXPECT_CALL(editor, ReplaceWithValue(load, IsTypeGuard(value, _), _, _)); Reduction r = load_elimination.Reduce(load); ASSERT_TRUE(r.Changed()); - EXPECT_EQ(load, r.replacement()); + EXPECT_THAT(r.replacement(), IsTypeGuard(value, _)); } TEST_F(LoadEliminationTest, LoadElementWithTypeMismatch) { diff --git a/deps/v8/test/unittests/compiler/mips/OWNERS b/deps/v8/test/unittests/compiler/mips/OWNERS index 4ce9d7f91d..8bbcab4c2d 100644 --- a/deps/v8/test/unittests/compiler/mips/OWNERS +++ b/deps/v8/test/unittests/compiler/mips/OWNERS @@ -1,3 +1,2 @@ -ivica.bogosavljevic@mips.com -Miran.Karic@mips.com -sreten.kovacevic@mips.com
\ No newline at end of file +ibogosavljevic@wavecomp.com +skovacevic@wavecomp.com
\ No newline at end of file diff --git a/deps/v8/test/unittests/compiler/mips/instruction-selector-mips-unittest.cc b/deps/v8/test/unittests/compiler/mips/instruction-selector-mips-unittest.cc index 34faec9690..15f5de7b2f 100644 --- a/deps/v8/test/unittests/compiler/mips/instruction-selector-mips-unittest.cc +++ b/deps/v8/test/unittests/compiler/mips/instruction-selector-mips-unittest.cc @@ -411,33 +411,35 @@ TEST_F(InstructionSelectorTest, Word32ShlWithWord32And) { } TEST_F(InstructionSelectorTest, Word32SarWithWord32Shl) { - { - StreamBuilder m(this, MachineType::Int32(), MachineType::Int32()); - Node* const p0 = m.Parameter(0); - Node* const r = - m.Word32Sar(m.Word32Shl(p0, m.Int32Constant(24)), m.Int32Constant(24)); - m.Return(r); - Stream s = m.Build(); - ASSERT_EQ(1U, s.size()); - EXPECT_EQ(kMipsSeb, s[0]->arch_opcode()); - ASSERT_EQ(1U, s[0]->InputCount()); - EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0))); - ASSERT_EQ(1U, s[0]->OutputCount()); - EXPECT_EQ(s.ToVreg(r), s.ToVreg(s[0]->Output())); - } - { - StreamBuilder m(this, MachineType::Int32(), MachineType::Int32()); - Node* const p0 = m.Parameter(0); - Node* const r = - m.Word32Sar(m.Word32Shl(p0, m.Int32Constant(16)), m.Int32Constant(16)); - m.Return(r); - Stream s = m.Build(); - ASSERT_EQ(1U, s.size()); - EXPECT_EQ(kMipsSeh, s[0]->arch_opcode()); - ASSERT_EQ(1U, s[0]->InputCount()); - EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0))); - ASSERT_EQ(1U, s[0]->OutputCount()); - EXPECT_EQ(s.ToVreg(r), s.ToVreg(s[0]->Output())); + if (IsMipsArchVariant(kMips32r2) || IsMipsArchVariant(kMips32r6)) { + { + StreamBuilder m(this, MachineType::Int32(), MachineType::Int32()); + Node* const p0 = m.Parameter(0); + Node* const r = m.Word32Sar(m.Word32Shl(p0, m.Int32Constant(24)), + m.Int32Constant(24)); + m.Return(r); + Stream s = m.Build(); + ASSERT_EQ(1U, s.size()); + EXPECT_EQ(kMipsSeb, s[0]->arch_opcode()); + ASSERT_EQ(1U, s[0]->InputCount()); + EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0))); + ASSERT_EQ(1U, s[0]->OutputCount()); + EXPECT_EQ(s.ToVreg(r), s.ToVreg(s[0]->Output())); + } + { + StreamBuilder m(this, MachineType::Int32(), MachineType::Int32()); + Node* const p0 = m.Parameter(0); + Node* const r = m.Word32Sar(m.Word32Shl(p0, m.Int32Constant(16)), + m.Int32Constant(16)); + m.Return(r); + Stream s = m.Build(); + ASSERT_EQ(1U, s.size()); + EXPECT_EQ(kMipsSeh, s[0]->arch_opcode()); + ASSERT_EQ(1U, s[0]->InputCount()); + EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0))); + ASSERT_EQ(1U, s[0]->OutputCount()); + EXPECT_EQ(s.ToVreg(r), s.ToVreg(s[0]->Output())); + } } } diff --git a/deps/v8/test/unittests/compiler/mips64/OWNERS b/deps/v8/test/unittests/compiler/mips64/OWNERS index 4ce9d7f91d..8bbcab4c2d 100644 --- a/deps/v8/test/unittests/compiler/mips64/OWNERS +++ b/deps/v8/test/unittests/compiler/mips64/OWNERS @@ -1,3 +1,2 @@ -ivica.bogosavljevic@mips.com -Miran.Karic@mips.com -sreten.kovacevic@mips.com
\ No newline at end of file +ibogosavljevic@wavecomp.com +skovacevic@wavecomp.com
\ No newline at end of file diff --git a/deps/v8/test/unittests/compiler/simplified-operator-reducer-unittest.cc b/deps/v8/test/unittests/compiler/simplified-operator-reducer-unittest.cc index f0e463265e..7913d6398c 100644 --- a/deps/v8/test/unittests/compiler/simplified-operator-reducer-unittest.cc +++ b/deps/v8/test/unittests/compiler/simplified-operator-reducer-unittest.cc @@ -29,7 +29,7 @@ class SimplifiedOperatorReducerTest : public GraphTest { protected: Reduction Reduce(Node* node) { - JSHeapBroker js_heap_broker(isolate()); + JSHeapBroker js_heap_broker(isolate(), zone()); MachineOperatorBuilder machine(zone()); JSOperatorBuilder javascript(zone()); JSGraph jsgraph(isolate(), graph(), common(), &javascript, simplified(), diff --git a/deps/v8/test/unittests/compiler/typer-unittest.cc b/deps/v8/test/unittests/compiler/typer-unittest.cc index d1283a8ad1..53459c314a 100644 --- a/deps/v8/test/unittests/compiler/typer-unittest.cc +++ b/deps/v8/test/unittests/compiler/typer-unittest.cc @@ -22,7 +22,7 @@ class TyperTest : public TypedGraphTest { public: TyperTest() : TypedGraphTest(3), - js_heap_broker_(isolate()), + js_heap_broker_(isolate(), zone()), operation_typer_(isolate(), &js_heap_broker_, zone()), types_(zone(), isolate(), random_number_generator()), javascript_(zone()), diff --git a/deps/v8/test/unittests/counters-unittest.cc b/deps/v8/test/unittests/counters-unittest.cc index d4772934d6..d137d68ee9 100644 --- a/deps/v8/test/unittests/counters-unittest.cc +++ b/deps/v8/test/unittests/counters-unittest.cc @@ -4,6 +4,7 @@ #include <vector> +#include "src/api-inl.h" #include "src/base/atomic-utils.h" #include "src/base/platform/time.h" #include "src/counters-inl.h" @@ -570,7 +571,7 @@ TEST_F(RuntimeCallStatsTest, BasicJavaScript) { { NativeTimeScope native_timer_scope; - RunJS("function f() { return 1; }"); + RunJS("function f() { return 1; };"); } EXPECT_EQ(1, counter->count()); int64_t time = counter->time().InMicroseconds(); @@ -578,7 +579,7 @@ TEST_F(RuntimeCallStatsTest, BasicJavaScript) { { NativeTimeScope native_timer_scope; - RunJS("f()"); + RunJS("f();"); } EXPECT_EQ(2, counter->count()); EXPECT_LE(time, counter->time().InMicroseconds()); @@ -587,38 +588,43 @@ TEST_F(RuntimeCallStatsTest, BasicJavaScript) { TEST_F(RuntimeCallStatsTest, FunctionLengthGetter) { RuntimeCallCounter* getter_counter = stats()->GetCounter(RuntimeCallCounterId::kFunctionLengthGetter); - RuntimeCallCounter* js_counter = - stats()->GetCounter(RuntimeCallCounterId::kJS_Execution); EXPECT_EQ(0, getter_counter->count()); - EXPECT_EQ(0, js_counter->count()); + EXPECT_EQ(0, js_counter()->count()); EXPECT_EQ(0, getter_counter->time().InMicroseconds()); - EXPECT_EQ(0, js_counter->time().InMicroseconds()); + EXPECT_EQ(0, js_counter()->time().InMicroseconds()); { NativeTimeScope native_timer_scope; - RunJS("function f(array) { return array.length; }"); + RunJS("function f(array) { return array.length; };"); } EXPECT_EQ(0, getter_counter->count()); - EXPECT_EQ(1, js_counter->count()); + EXPECT_EQ(1, js_counter()->count()); EXPECT_EQ(0, getter_counter->time().InMicroseconds()); - int64_t js_time = js_counter->time().InMicroseconds(); + int64_t js_time = js_counter()->time().InMicroseconds(); EXPECT_LT(0, js_time); { NativeTimeScope native_timer_scope; - RunJS("f.length"); + RunJS("f.length;"); } EXPECT_EQ(1, getter_counter->count()); - EXPECT_EQ(2, js_counter->count()); + EXPECT_EQ(2, js_counter()->count()); EXPECT_LE(0, getter_counter->time().InMicroseconds()); - EXPECT_LE(js_time, js_counter->time().InMicroseconds()); + EXPECT_LE(js_time, js_counter()->time().InMicroseconds()); { NativeTimeScope native_timer_scope; - RunJS("for (let i = 0; i < 50; i++) { f.length }"); + RunJS("for (let i = 0; i < 50; i++) { f.length };"); } EXPECT_EQ(51, getter_counter->count()); - EXPECT_EQ(3, js_counter->count()); + EXPECT_EQ(3, js_counter()->count()); + + { + NativeTimeScope native_timer_scope; + RunJS("for (let i = 0; i < 1000; i++) { f.length; };"); + } + EXPECT_EQ(1051, getter_counter->count()); + EXPECT_EQ(4, js_counter()->count()); } namespace { @@ -631,7 +637,10 @@ static void CustomCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { } } // namespace -TEST_F(RuntimeCallStatsTest, CustomCallback) { +TEST_F(RuntimeCallStatsTest, CallbackFunction) { + RuntimeCallCounter* callback_counter = + stats()->GetCounter(RuntimeCallCounterId::kFunctionCallback); + current_test = this; // Set up a function template with a custom callback. v8::Isolate* isolate = v8_isolate(); @@ -645,9 +654,9 @@ TEST_F(RuntimeCallStatsTest, CustomCallback) { object_template->NewInstance(v8_context()).ToLocalChecked(); SetGlobalProperty("custom_object", object); - // TODO(cbruni): Check api accessor timer (one above the custom callback). EXPECT_EQ(0, js_counter()->count()); EXPECT_EQ(0, counter()->count()); + EXPECT_EQ(0, callback_counter->count()); EXPECT_EQ(0, counter2()->count()); { RuntimeCallTimerScope scope(stats(), counter_id()); @@ -655,29 +664,105 @@ TEST_F(RuntimeCallStatsTest, CustomCallback) { RunJS("custom_object.callback();"); } EXPECT_EQ(1, js_counter()->count()); + EXPECT_EQ(1, counter()->count()); + EXPECT_EQ(1, callback_counter->count()); + EXPECT_EQ(1, counter2()->count()); // Given that no native timers are used, only the two scopes explitly // mentioned above will track the time. EXPECT_EQ(0, js_counter()->time().InMicroseconds()); - EXPECT_EQ(1, counter()->count()); + EXPECT_EQ(0, callback_counter->time().InMicroseconds()); EXPECT_EQ(100, counter()->time().InMicroseconds()); - EXPECT_EQ(1, counter2()->count()); EXPECT_EQ(kCustomCallbackTime, counter2()->time().InMicroseconds()); - RunJS("for (let i = 0; i < 9; i++) { custom_object.callback() };"); + RunJS("for (let i = 0; i < 9; i++) { custom_object.callback(); };"); EXPECT_EQ(2, js_counter()->count()); - EXPECT_EQ(0, js_counter()->time().InMicroseconds()); EXPECT_EQ(1, counter()->count()); - EXPECT_EQ(100, counter()->time().InMicroseconds()); + EXPECT_EQ(10, callback_counter->count()); EXPECT_EQ(10, counter2()->count()); + EXPECT_EQ(0, js_counter()->time().InMicroseconds()); + EXPECT_EQ(0, callback_counter->time().InMicroseconds()); + EXPECT_EQ(100, counter()->time().InMicroseconds()); EXPECT_EQ(kCustomCallbackTime * 10, counter2()->time().InMicroseconds()); - RunJS("for (let i = 0; i < 4000; i++) { custom_object.callback() };"); + RunJS("for (let i = 0; i < 4000; i++) { custom_object.callback(); };"); EXPECT_EQ(3, js_counter()->count()); + EXPECT_EQ(1, counter()->count()); + EXPECT_EQ(4010, callback_counter->count()); + EXPECT_EQ(4010, counter2()->count()); EXPECT_EQ(0, js_counter()->time().InMicroseconds()); + EXPECT_EQ(0, callback_counter->time().InMicroseconds()); + EXPECT_EQ(100, counter()->time().InMicroseconds()); + EXPECT_EQ(kCustomCallbackTime * 4010, counter2()->time().InMicroseconds()); +} + +TEST_F(RuntimeCallStatsTest, ApiGetter) { + RuntimeCallCounter* callback_counter = + stats()->GetCounter(RuntimeCallCounterId::kFunctionCallback); + current_test = this; + // Set up a function template with an api accessor. + v8::Isolate* isolate = v8_isolate(); + v8::HandleScope scope(isolate); + + v8::Local<v8::ObjectTemplate> object_template = + v8::ObjectTemplate::New(isolate); + object_template->SetAccessorProperty( + NewString("apiGetter"), + v8::FunctionTemplate::New(isolate, CustomCallback)); + v8::Local<v8::Object> object = + object_template->NewInstance(v8_context()).ToLocalChecked(); + SetGlobalProperty("custom_object", object); + + // TODO(cbruni): Check api accessor timer (one above the custom callback). + EXPECT_EQ(0, js_counter()->count()); + EXPECT_EQ(0, counter()->count()); + EXPECT_EQ(0, callback_counter->count()); + EXPECT_EQ(0, counter2()->count()); + + { + RuntimeCallTimerScope scope(stats(), counter_id()); + Sleep(100); + RunJS("custom_object.apiGetter;"); + } + PrintStats(); + + EXPECT_EQ(1, js_counter()->count()); + EXPECT_EQ(1, counter()->count()); + EXPECT_EQ(1, callback_counter->count()); + EXPECT_EQ(1, counter2()->count()); + // Given that no native timers are used, only the two scopes explitly + // mentioned above will track the time. + EXPECT_EQ(0, js_counter()->time().InMicroseconds()); + EXPECT_EQ(100, counter()->time().InMicroseconds()); + EXPECT_EQ(0, callback_counter->time().InMicroseconds()); + EXPECT_EQ(kCustomCallbackTime, counter2()->time().InMicroseconds()); + + RunJS("for (let i = 0; i < 9; i++) { custom_object.apiGetter };"); + PrintStats(); + + EXPECT_EQ(2, js_counter()->count()); EXPECT_EQ(1, counter()->count()); + EXPECT_EQ(10, callback_counter->count()); + EXPECT_EQ(10, counter2()->count()); + + EXPECT_EQ(0, js_counter()->time().InMicroseconds()); EXPECT_EQ(100, counter()->time().InMicroseconds()); + EXPECT_EQ(0, callback_counter->time().InMicroseconds()); + EXPECT_EQ(kCustomCallbackTime * 10, counter2()->time().InMicroseconds()); + + RunJS("for (let i = 0; i < 4000; i++) { custom_object.apiGetter };"); + PrintStats(); + + EXPECT_EQ(3, js_counter()->count()); + EXPECT_EQ(1, counter()->count()); + EXPECT_EQ(4010, callback_counter->count()); EXPECT_EQ(4010, counter2()->count()); + + EXPECT_EQ(0, js_counter()->time().InMicroseconds()); + EXPECT_EQ(100, counter()->time().InMicroseconds()); + EXPECT_EQ(0, callback_counter->time().InMicroseconds()); EXPECT_EQ(kCustomCallbackTime * 4010, counter2()->time().InMicroseconds()); + + PrintStats(); } } // namespace internal diff --git a/deps/v8/test/unittests/heap/embedder-tracing-unittest.cc b/deps/v8/test/unittests/heap/embedder-tracing-unittest.cc index e07fa1b327..ac2cb3e2ee 100644 --- a/deps/v8/test/unittests/heap/embedder-tracing-unittest.cc +++ b/deps/v8/test/unittests/heap/embedder-tracing-unittest.cc @@ -3,6 +3,7 @@ // found in the LICENSE file. #include "src/heap/embedder-tracing.h" +#include "src/heap/heap.h" #include "test/unittests/test-utils.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -33,12 +34,11 @@ class MockEmbedderHeapTracer : public EmbedderHeapTracer { MOCK_METHOD0(TracePrologue, void()); MOCK_METHOD0(TraceEpilogue, void()); MOCK_METHOD0(AbortTracing, void()); - MOCK_METHOD0(EnterFinalPause, void()); + MOCK_METHOD1(EnterFinalPause, void(EmbedderHeapTracer::EmbedderStackState)); MOCK_METHOD0(IsTracingDone, bool()); MOCK_METHOD1(RegisterV8References, void(const std::vector<std::pair<void*, void*> >&)); - MOCK_METHOD2(AdvanceTracing, - bool(double deadline_in_ms, AdvanceTracingActions actions)); + MOCK_METHOD1(AdvanceTracing, bool(double deadline_in_ms)); }; TEST(LocalEmbedderHeapTracer, InUse) { @@ -55,10 +55,8 @@ TEST(LocalEmbedderHeapTracer, NoRemoteTracer) { EXPECT_FALSE(local_tracer.InUse()); local_tracer.TracePrologue(); local_tracer.EnterFinalPause(); - bool more_work = local_tracer.Trace( - 0, EmbedderHeapTracer::AdvanceTracingActions( - EmbedderHeapTracer::ForceCompletionAction::FORCE_COMPLETION)); - EXPECT_FALSE(more_work); + bool done = local_tracer.Trace(std::numeric_limits<double>::infinity()); + EXPECT_TRUE(done); local_tracer.TraceEpilogue(); } @@ -100,7 +98,38 @@ TEST(LocalEmbedderHeapTracer, EnterFinalPauseForwards) { StrictMock<MockEmbedderHeapTracer> remote_tracer; LocalEmbedderHeapTracer local_tracer(nullptr); local_tracer.SetRemoteTracer(&remote_tracer); - EXPECT_CALL(remote_tracer, EnterFinalPause()); + EXPECT_CALL(remote_tracer, EnterFinalPause(_)); + local_tracer.EnterFinalPause(); +} + +TEST(LocalEmbedderHeapTracer, EnterFinalPauseDefaultStackStateUnkown) { + StrictMock<MockEmbedderHeapTracer> remote_tracer; + LocalEmbedderHeapTracer local_tracer(nullptr); + local_tracer.SetRemoteTracer(&remote_tracer); + // The default stack state is expected to be unkown. + EXPECT_CALL(remote_tracer, EnterFinalPause(EmbedderHeapTracer::kUnknown)); + local_tracer.EnterFinalPause(); +} + +TEST(LocalEmbedderHeapTracer, EnterFinalPauseStackStateIsForwarded) { + StrictMock<MockEmbedderHeapTracer> remote_tracer; + LocalEmbedderHeapTracer local_tracer(nullptr); + local_tracer.SetRemoteTracer(&remote_tracer); + local_tracer.SetEmbedderStackStateForNextFinalization( + EmbedderHeapTracer::kEmpty); + EXPECT_CALL(remote_tracer, EnterFinalPause(EmbedderHeapTracer::kEmpty)); + local_tracer.EnterFinalPause(); +} + +TEST(LocalEmbedderHeapTracer, EnterFinalPauseStackStateResets) { + StrictMock<MockEmbedderHeapTracer> remote_tracer; + LocalEmbedderHeapTracer local_tracer(nullptr); + local_tracer.SetRemoteTracer(&remote_tracer); + local_tracer.SetEmbedderStackStateForNextFinalization( + EmbedderHeapTracer::kEmpty); + EXPECT_CALL(remote_tracer, EnterFinalPause(EmbedderHeapTracer::kEmpty)); + local_tracer.EnterFinalPause(); + EXPECT_CALL(remote_tracer, EnterFinalPause(EmbedderHeapTracer::kUnknown)); local_tracer.EnterFinalPause(); } @@ -140,10 +169,8 @@ TEST(LocalEmbedderHeapTracer, TraceFinishes) { EXPECT_EQ(1u, local_tracer.NumberOfCachedWrappersToTrace()); EXPECT_CALL(remote_tracer, RegisterV8References(_)); local_tracer.RegisterWrappersWithRemoteTracer(); - EXPECT_CALL(remote_tracer, AdvanceTracing(0, _)).WillOnce(Return(false)); - EXPECT_FALSE(local_tracer.Trace( - 0, EmbedderHeapTracer::AdvanceTracingActions( - EmbedderHeapTracer::ForceCompletionAction::FORCE_COMPLETION))); + EXPECT_CALL(remote_tracer, AdvanceTracing(_)).WillOnce(Return(true)); + EXPECT_TRUE(local_tracer.Trace(std::numeric_limits<double>::infinity())); EXPECT_EQ(0u, local_tracer.NumberOfCachedWrappersToTrace()); } @@ -155,10 +182,8 @@ TEST(LocalEmbedderHeapTracer, TraceDoesNotFinish) { EXPECT_EQ(1u, local_tracer.NumberOfCachedWrappersToTrace()); EXPECT_CALL(remote_tracer, RegisterV8References(_)); local_tracer.RegisterWrappersWithRemoteTracer(); - EXPECT_CALL(remote_tracer, AdvanceTracing(0, _)).WillOnce(Return(true)); - EXPECT_TRUE(local_tracer.Trace( - 0, EmbedderHeapTracer::AdvanceTracingActions( - EmbedderHeapTracer::ForceCompletionAction::FORCE_COMPLETION))); + EXPECT_CALL(remote_tracer, AdvanceTracing(_)).WillOnce(Return(false)); + EXPECT_FALSE(local_tracer.Trace(1.0)); EXPECT_EQ(0u, local_tracer.NumberOfCachedWrappersToTrace()); } diff --git a/deps/v8/test/unittests/heap/heap-controller-unittest.cc b/deps/v8/test/unittests/heap/heap-controller-unittest.cc index dc75820f64..b2446afa84 100644 --- a/deps/v8/test/unittests/heap/heap-controller-unittest.cc +++ b/deps/v8/test/unittests/heap/heap-controller-unittest.cc @@ -32,80 +32,82 @@ void CheckEqualRounded(double expected, double actual) { EXPECT_DOUBLE_EQ(expected, actual); } -TEST(HeapController, HeapGrowingFactor) { - CheckEqualRounded(HeapController::kMaxHeapGrowingFactor, - HeapController::HeapGrowingFactor(34, 1, 4.0)); - CheckEqualRounded(3.553, HeapController::HeapGrowingFactor(45, 1, 4.0)); - CheckEqualRounded(2.830, HeapController::HeapGrowingFactor(50, 1, 4.0)); - CheckEqualRounded(1.478, HeapController::HeapGrowingFactor(100, 1, 4.0)); - CheckEqualRounded(1.193, HeapController::HeapGrowingFactor(200, 1, 4.0)); - CheckEqualRounded(1.121, HeapController::HeapGrowingFactor(300, 1, 4.0)); - CheckEqualRounded(HeapController::HeapGrowingFactor(300, 1, 4.0), - HeapController::HeapGrowingFactor(600, 2, 4.0)); - CheckEqualRounded(HeapController::kMinHeapGrowingFactor, - HeapController::HeapGrowingFactor(400, 1, 4.0)); +TEST_F(HeapControllerTest, HeapGrowingFactor) { + HeapController heap_controller(i_isolate()->heap()); + double min_factor = heap_controller.kMinGrowingFactor; + double max_factor = heap_controller.kMaxGrowingFactor; + + CheckEqualRounded(max_factor, heap_controller.GrowingFactor(34, 1, 4.0)); + CheckEqualRounded(3.553, heap_controller.GrowingFactor(45, 1, 4.0)); + CheckEqualRounded(2.830, heap_controller.GrowingFactor(50, 1, 4.0)); + CheckEqualRounded(1.478, heap_controller.GrowingFactor(100, 1, 4.0)); + CheckEqualRounded(1.193, heap_controller.GrowingFactor(200, 1, 4.0)); + CheckEqualRounded(1.121, heap_controller.GrowingFactor(300, 1, 4.0)); + CheckEqualRounded(heap_controller.GrowingFactor(300, 1, 4.0), + heap_controller.GrowingFactor(600, 2, 4.0)); + CheckEqualRounded(min_factor, heap_controller.GrowingFactor(400, 1, 4.0)); } -TEST(HeapController, MaxHeapGrowingFactor) { - CheckEqualRounded(1.3, HeapController::MaxHeapGrowingFactor( - HeapController::kMinOldGenerationSize * MB)); - CheckEqualRounded(1.600, HeapController::MaxHeapGrowingFactor( - HeapController::kMaxOldGenerationSize / 2 * MB)); - CheckEqualRounded(1.999, HeapController::MaxHeapGrowingFactor( - (HeapController::kMaxOldGenerationSize - - Heap::kPointerMultiplier) * - MB)); +TEST_F(HeapControllerTest, MaxHeapGrowingFactor) { + HeapController heap_controller(i_isolate()->heap()); CheckEqualRounded( - 4.0, - HeapController::MaxHeapGrowingFactor( - static_cast<size_t>(HeapController::kMaxOldGenerationSize) * MB)); + 1.3, heap_controller.MaxGrowingFactor(heap_controller.kMinSize * MB)); + CheckEqualRounded(1.600, heap_controller.MaxGrowingFactor( + heap_controller.kMaxSize / 2 * MB)); + CheckEqualRounded( + 1.999, heap_controller.MaxGrowingFactor( + (heap_controller.kMaxSize - Heap::kPointerMultiplier) * MB)); + CheckEqualRounded(4.0, + heap_controller.MaxGrowingFactor( + static_cast<size_t>(heap_controller.kMaxSize) * MB)); } TEST_F(HeapControllerTest, OldGenerationAllocationLimit) { Heap* heap = i_isolate()->heap(); + HeapController heap_controller(heap); size_t old_gen_size = 128 * MB; size_t max_old_generation_size = 512 * MB; double gc_speed = 100; double mutator_speed = 1; size_t new_space_capacity = 16 * MB; - double max_factor = - HeapController::MaxHeapGrowingFactor(max_old_generation_size); + double max_factor = heap_controller.MaxGrowingFactor(max_old_generation_size); double factor = - HeapController::HeapGrowingFactor(gc_speed, mutator_speed, max_factor); + heap_controller.GrowingFactor(gc_speed, mutator_speed, max_factor); EXPECT_EQ(static_cast<size_t>(old_gen_size * factor + new_space_capacity), - heap->heap_controller()->CalculateOldGenerationAllocationLimit( + heap->heap_controller()->CalculateAllocationLimit( old_gen_size, max_old_generation_size, gc_speed, mutator_speed, new_space_capacity, Heap::HeapGrowingMode::kDefault)); - factor = Min(factor, HeapController::kConservativeHeapGrowingFactor); + factor = Min(factor, heap_controller.kConservativeGrowingFactor); EXPECT_EQ(static_cast<size_t>(old_gen_size * factor + new_space_capacity), - heap->heap_controller()->CalculateOldGenerationAllocationLimit( + heap->heap_controller()->CalculateAllocationLimit( old_gen_size, max_old_generation_size, gc_speed, mutator_speed, new_space_capacity, Heap::HeapGrowingMode::kSlow)); - factor = Min(factor, HeapController::kConservativeHeapGrowingFactor); + factor = Min(factor, heap_controller.kConservativeGrowingFactor); EXPECT_EQ(static_cast<size_t>(old_gen_size * factor + new_space_capacity), - heap->heap_controller()->CalculateOldGenerationAllocationLimit( + heap->heap_controller()->CalculateAllocationLimit( old_gen_size, max_old_generation_size, gc_speed, mutator_speed, new_space_capacity, Heap::HeapGrowingMode::kConservative)); - factor = HeapController::kMinHeapGrowingFactor; + factor = heap_controller.kMinGrowingFactor; EXPECT_EQ(static_cast<size_t>(old_gen_size * factor + new_space_capacity), - heap->heap_controller()->CalculateOldGenerationAllocationLimit( + heap->heap_controller()->CalculateAllocationLimit( old_gen_size, max_old_generation_size, gc_speed, mutator_speed, new_space_capacity, Heap::HeapGrowingMode::kMinimal)); } -TEST(HeapController, MaxOldGenerationSize) { +TEST_F(HeapControllerTest, MaxOldGenerationSize) { + HeapController heap_controller(i_isolate()->heap()); uint64_t configurations[][2] = { - {0, HeapController::kMinOldGenerationSize}, - {512, HeapController::kMinOldGenerationSize}, + {0, heap_controller.kMinSize}, + {512, heap_controller.kMinSize}, {1 * GB, 256 * Heap::kPointerMultiplier}, {2 * static_cast<uint64_t>(GB), 512 * Heap::kPointerMultiplier}, - {4 * static_cast<uint64_t>(GB), HeapController::kMaxOldGenerationSize}, - {8 * static_cast<uint64_t>(GB), HeapController::kMaxOldGenerationSize}}; + {4 * static_cast<uint64_t>(GB), heap_controller.kMaxSize}, + {8 * static_cast<uint64_t>(GB), heap_controller.kMaxSize}}; for (auto configuration : configurations) { ASSERT_EQ(configuration[1], diff --git a/deps/v8/test/unittests/heap/spaces-unittest.cc b/deps/v8/test/unittests/heap/spaces-unittest.cc index 13c0297489..d81b7e1413 100644 --- a/deps/v8/test/unittests/heap/spaces-unittest.cc +++ b/deps/v8/test/unittests/heap/spaces-unittest.cc @@ -3,6 +3,7 @@ // found in the LICENSE file. #include "src/heap/heap-inl.h" +#include "src/heap/heap-write-barrier-inl.h" #include "src/heap/spaces-inl.h" #include "src/isolate.h" #include "test/unittests/test-utils.h" @@ -51,6 +52,69 @@ TEST_F(SpacesTest, CompactionSpaceMerge) { delete compaction_space; } +TEST_F(SpacesTest, WriteBarrierFromHeapObject) { + constexpr Address address1 = Page::kPageSize; + HeapObject* object1 = reinterpret_cast<HeapObject*>(address1); + MemoryChunk* chunk1 = MemoryChunk::FromHeapObject(object1); + heap_internals::MemoryChunk* slim_chunk1 = + heap_internals::MemoryChunk::FromHeapObject(object1); + EXPECT_EQ(static_cast<void*>(chunk1), static_cast<void*>(slim_chunk1)); + constexpr Address address2 = 2 * Page::kPageSize - 1; + HeapObject* object2 = reinterpret_cast<HeapObject*>(address2); + MemoryChunk* chunk2 = MemoryChunk::FromHeapObject(object2); + heap_internals::MemoryChunk* slim_chunk2 = + heap_internals::MemoryChunk::FromHeapObject(object2); + EXPECT_EQ(static_cast<void*>(chunk2), static_cast<void*>(slim_chunk2)); +} + +TEST_F(SpacesTest, WriteBarrierIsMarking) { + char memory[256]; + memset(&memory, 0, sizeof(memory)); + MemoryChunk* chunk = reinterpret_cast<MemoryChunk*>(&memory); + heap_internals::MemoryChunk* slim_chunk = + reinterpret_cast<heap_internals::MemoryChunk*>(&memory); + EXPECT_FALSE(chunk->IsFlagSet(MemoryChunk::INCREMENTAL_MARKING)); + EXPECT_FALSE(slim_chunk->IsMarking()); + chunk->SetFlag(MemoryChunk::INCREMENTAL_MARKING); + EXPECT_TRUE(chunk->IsFlagSet(MemoryChunk::INCREMENTAL_MARKING)); + EXPECT_TRUE(slim_chunk->IsMarking()); + chunk->ClearFlag(MemoryChunk::INCREMENTAL_MARKING); + EXPECT_FALSE(chunk->IsFlagSet(MemoryChunk::INCREMENTAL_MARKING)); + EXPECT_FALSE(slim_chunk->IsMarking()); +} + +TEST_F(SpacesTest, WriteBarrierInNewSpaceToSpace) { + char memory[256]; + memset(&memory, 0, sizeof(memory)); + MemoryChunk* chunk = reinterpret_cast<MemoryChunk*>(&memory); + heap_internals::MemoryChunk* slim_chunk = + reinterpret_cast<heap_internals::MemoryChunk*>(&memory); + EXPECT_FALSE(chunk->InNewSpace()); + EXPECT_FALSE(slim_chunk->InNewSpace()); + chunk->SetFlag(MemoryChunk::IN_TO_SPACE); + EXPECT_TRUE(chunk->InNewSpace()); + EXPECT_TRUE(slim_chunk->InNewSpace()); + chunk->ClearFlag(MemoryChunk::IN_TO_SPACE); + EXPECT_FALSE(chunk->InNewSpace()); + EXPECT_FALSE(slim_chunk->InNewSpace()); +} + +TEST_F(SpacesTest, WriteBarrierInNewSpaceFromSpace) { + char memory[256]; + memset(&memory, 0, sizeof(memory)); + MemoryChunk* chunk = reinterpret_cast<MemoryChunk*>(&memory); + heap_internals::MemoryChunk* slim_chunk = + reinterpret_cast<heap_internals::MemoryChunk*>(&memory); + EXPECT_FALSE(chunk->InNewSpace()); + EXPECT_FALSE(slim_chunk->InNewSpace()); + chunk->SetFlag(MemoryChunk::IN_FROM_SPACE); + EXPECT_TRUE(chunk->InNewSpace()); + EXPECT_TRUE(slim_chunk->InNewSpace()); + chunk->ClearFlag(MemoryChunk::IN_FROM_SPACE); + EXPECT_FALSE(chunk->InNewSpace()); + EXPECT_FALSE(slim_chunk->InNewSpace()); +} + TEST_F(SpacesTest, CodeRangeAddressReuse) { CodeRangeAddressHint hint; // Create code ranges. diff --git a/deps/v8/test/unittests/interpreter/bytecode-array-builder-unittest.cc b/deps/v8/test/unittests/interpreter/bytecode-array-builder-unittest.cc index 1ae636eceb..5030d3897d 100644 --- a/deps/v8/test/unittests/interpreter/bytecode-array-builder-unittest.cc +++ b/deps/v8/test/unittests/interpreter/bytecode-array-builder-unittest.cc @@ -376,7 +376,8 @@ TEST_F(BytecodeArrayBuilderTest, AllBytecodesGenerated) { .CreateArrayLiteral(0, 0, 0) .CreateEmptyArrayLiteral(0) .CreateObjectLiteral(0, 0, 0, reg) - .CreateEmptyObjectLiteral(); + .CreateEmptyObjectLiteral() + .CloneObject(reg, 0, 0); // Emit load and store operations for module variables. builder.LoadModuleVariable(-1, 42) diff --git a/deps/v8/test/unittests/object-unittest.cc b/deps/v8/test/unittests/object-unittest.cc index 0b603298ad..ad8d631961 100644 --- a/deps/v8/test/unittests/object-unittest.cc +++ b/deps/v8/test/unittests/object-unittest.cc @@ -6,6 +6,7 @@ #include <iostream> #include <limits> +#include "src/api-inl.h" #include "src/compiler.h" #include "src/objects-inl.h" #include "src/objects.h" diff --git a/deps/v8/test/unittests/parser/preparser-unittest.cc b/deps/v8/test/unittests/parser/preparser-unittest.cc index a9f77b4b7a..f20fbb2cee 100644 --- a/deps/v8/test/unittests/parser/preparser-unittest.cc +++ b/deps/v8/test/unittests/parser/preparser-unittest.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "src/api.h" +#include "src/api-inl.h" #include "src/objects-inl.h" #include "test/unittests/test-helpers.h" #include "test/unittests/test-utils.h" diff --git a/deps/v8/test/unittests/test-helpers.cc b/deps/v8/test/unittests/test-helpers.cc index ee601da900..c771906dc2 100644 --- a/deps/v8/test/unittests/test-helpers.cc +++ b/deps/v8/test/unittests/test-helpers.cc @@ -42,7 +42,8 @@ Handle<SharedFunctionInfo> CreateSharedFunctionInfo( // Ensure that the function can be compiled lazily. shared->set_uncompiled_data( *isolate->factory()->NewUncompiledDataWithoutPreParsedScope( - 0, source->length(), function_literal_id)); + ReadOnlyRoots(isolate).empty_string_handle(), 0, source->length(), + function_literal_id)); // Make sure we have an outer scope info, even though it's empty shared->set_raw_outer_scope_info_or_feedback_metadata( ScopeInfo::Empty(isolate)); diff --git a/deps/v8/test/unittests/test-utils.cc b/deps/v8/test/unittests/test-utils.cc index d19c337239..2b099e0ea5 100644 --- a/deps/v8/test/unittests/test-utils.cc +++ b/deps/v8/test/unittests/test-utils.cc @@ -6,7 +6,7 @@ #include "include/libplatform/libplatform.h" #include "include/v8.h" -#include "src/api.h" +#include "src/api-inl.h" #include "src/base/platform/time.h" #include "src/flags.h" #include "src/isolate.h" @@ -67,17 +67,19 @@ Local<Value> TestWithIsolate::RunJS(const char* source) { TestWithContext::TestWithContext() : context_(Context::New(isolate())), context_scope_(context_) {} - TestWithContext::~TestWithContext() {} +v8::Local<v8::String> TestWithContext::NewString(const char* string) { + return v8::String::NewFromUtf8(v8_isolate(), string, + v8::NewStringType::kNormal) + .ToLocalChecked(); +} + void TestWithContext::SetGlobalProperty(const char* name, v8::Local<v8::Value> value) { - v8::Local<v8::String> property_name = - v8::String::NewFromUtf8(v8_isolate(), name, v8::NewStringType::kNormal) - .ToLocalChecked(); CHECK(v8_context() ->Global() - ->Set(v8_context(), property_name, value) + ->Set(v8_context(), NewString(name), value) .FromJust()); } @@ -89,6 +91,10 @@ TestWithIsolateAndZone::~TestWithIsolateAndZone() {} Factory* TestWithIsolate::factory() const { return isolate()->factory(); } +Handle<Object> TestWithIsolate::RunJSInternal(const char* source) { + return Utils::OpenHandle(*::v8::TestWithIsolate::RunJS(source)); +} + base::RandomNumberGenerator* TestWithIsolate::random_number_generator() const { return isolate()->random_number_generator(); } diff --git a/deps/v8/test/unittests/test-utils.h b/deps/v8/test/unittests/test-utils.h index 17a5eb7c21..c361810219 100644 --- a/deps/v8/test/unittests/test-utils.h +++ b/deps/v8/test/unittests/test-utils.h @@ -8,7 +8,6 @@ #include <vector> #include "include/v8.h" -#include "src/api.h" #include "src/base/macros.h" #include "src/base/utils/random-number-generator.h" #include "src/handles.h" @@ -61,6 +60,7 @@ class TestWithContext : public virtual v8::TestWithIsolate { const Local<Context>& context() const { return v8_context(); } const Local<Context>& v8_context() const { return context_; } + v8::Local<v8::String> NewString(const char* string); void SetGlobalProperty(const char* name, v8::Local<v8::Value> value); private: @@ -85,10 +85,9 @@ class TestWithIsolate : public virtual ::v8::TestWithIsolate { Isolate* isolate() const { return i_isolate(); } template <typename T = Object> Handle<T> RunJS(const char* source) { - Handle<Object> result = - Utils::OpenHandle(*::v8::TestWithIsolate::RunJS(source)); - return Handle<T>::cast(result); + return Handle<T>::cast(RunJSInternal(source)); } + Handle<Object> RunJSInternal(const char* source); base::RandomNumberGenerator* random_number_generator() const; private: diff --git a/deps/v8/test/unittests/torque/earley-parser-unittest.cc b/deps/v8/test/unittests/torque/earley-parser-unittest.cc new file mode 100644 index 0000000000..9718a404c9 --- /dev/null +++ b/deps/v8/test/unittests/torque/earley-parser-unittest.cc @@ -0,0 +1,84 @@ +// Copyright 2018 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. + +#include "src/torque/earley-parser.h" +#include "test/unittests/test-utils.h" + +namespace v8 { +namespace internal { +namespace torque { + +namespace { + +template <int op(int, int)> +base::Optional<ParseResult> MakeBinop(ParseResultIterator* child_results) { + // Ideally, we would want to use int as a result type here instead of + // std::string. This is possible, but requires adding int to the list of + // supported ParseResult types in torque-parser.cc. To avoid changing that + // code, we use std::string here, which is already used in the Torque parser. + auto a = child_results->NextAs<std::string>(); + auto b = child_results->NextAs<std::string>(); + return ParseResult{std::to_string(op(std::stoi(a), std::stoi(b)))}; +} + +int plus(int a, int b) { return a + b; } +int minus(int a, int b) { return a - b; } +int mul(int a, int b) { return a * b; } + +} // namespace + +struct SimpleArithmeticGrammar : Grammar { + static bool MatchWhitespace(InputPosition* pos) { + while (MatchChar(std::isspace, pos)) { + } + return true; + } + + static bool MatchInteger(InputPosition* pos) { + InputPosition current = *pos; + MatchString("-", ¤t); + if (MatchChar(std::isdigit, ¤t)) { + while (MatchChar(std::isdigit, ¤t)) { + } + *pos = current; + return true; + } + return false; + } + + SimpleArithmeticGrammar() : Grammar(&sum_expression) { + SetWhitespace(MatchWhitespace); + } + + Symbol integer = {Rule({Pattern(MatchInteger)}, YieldMatchedInput)}; + + Symbol atomic_expression = {Rule({&integer}), + Rule({Token("("), &sum_expression, Token(")")})}; + + Symbol mul_expression = { + Rule({&atomic_expression}), + Rule({&mul_expression, Token("*"), &atomic_expression}, MakeBinop<mul>)}; + + Symbol sum_expression = { + Rule({&mul_expression}), + Rule({&sum_expression, Token("+"), &mul_expression}, MakeBinop<plus>), + Rule({&sum_expression, Token("-"), &mul_expression}, MakeBinop<minus>)}; +}; + +TEST(EarleyParser, SimpleArithmetic) { + SimpleArithmeticGrammar grammar; + SourceFileMap::Scope source_file_map; + CurrentSourceFile::Scope current_source_file{ + SourceFileMap::AddSource("dummy_filename")}; + std::string result1 = + grammar.Parse("-5 - 5 + (3 + 5) * 2")->Cast<std::string>(); + ASSERT_EQ("6", result1); + std::string result2 = grammar.Parse("((-1 + (1) * 2 + 3 - 4 * 5 + -6 * 7))") + ->Cast<std::string>(); + ASSERT_EQ("-58", result2); +} + +} // namespace torque +} // namespace internal +} // namespace v8 diff --git a/deps/v8/test/unittests/value-serializer-unittest.cc b/deps/v8/test/unittests/value-serializer-unittest.cc index 92603b588a..77f609052a 100644 --- a/deps/v8/test/unittests/value-serializer-unittest.cc +++ b/deps/v8/test/unittests/value-serializer-unittest.cc @@ -8,7 +8,7 @@ #include <string> #include "include/v8.h" -#include "src/api.h" +#include "src/api-inl.h" #include "src/base/build_config.h" #include "src/objects-inl.h" #include "src/wasm/wasm-objects.h" @@ -1689,12 +1689,12 @@ TEST_F(ValueSerializerTest, RoundTripTypedArray) { // Check that the right type comes out the other side for every kind of typed // array. Local<Value> value; -#define TYPED_ARRAY_ROUND_TRIP_TEST(Type, type, TYPE, ctype, size) \ - value = RoundTripTest("new " #Type "Array(2)"); \ - ASSERT_TRUE(value->Is##Type##Array()); \ - EXPECT_EQ(2u * size, TypedArray::Cast(*value)->ByteLength()); \ - EXPECT_EQ(2u, TypedArray::Cast(*value)->Length()); \ - ExpectScriptTrue("Object.getPrototypeOf(result) === " #Type \ +#define TYPED_ARRAY_ROUND_TRIP_TEST(Type, type, TYPE, ctype) \ + value = RoundTripTest("new " #Type "Array(2)"); \ + ASSERT_TRUE(value->Is##Type##Array()); \ + EXPECT_EQ(2u * sizeof(ctype), TypedArray::Cast(*value)->ByteLength()); \ + EXPECT_EQ(2u, TypedArray::Cast(*value)->Length()); \ + ExpectScriptTrue("Object.getPrototypeOf(result) === " #Type \ "Array.prototype"); TYPED_ARRAYS(TYPED_ARRAY_ROUND_TRIP_TEST) @@ -2514,7 +2514,8 @@ TEST_F(ValueSerializerTestWithWasm, DefaultSerializationDelegate) { Local<Message> message = InvalidEncodeTest(MakeWasm()); size_t msg_len = static_cast<size_t>(message->Get()->Length()); std::unique_ptr<char[]> buff(new char[msg_len + 1]); - message->Get()->WriteOneByte(reinterpret_cast<uint8_t*>(buff.get())); + message->Get()->WriteOneByte(isolate(), + reinterpret_cast<uint8_t*>(buff.get())); // the message ends with the custom error string size_t custom_msg_len = strlen(kUnsupportedSerialization); ASSERT_GE(msg_len, custom_msg_len); diff --git a/deps/v8/test/unittests/wasm/function-body-decoder-unittest.cc b/deps/v8/test/unittests/wasm/function-body-decoder-unittest.cc index 3b25056160..771c61e237 100644 --- a/deps/v8/test/unittests/wasm/function-body-decoder-unittest.cc +++ b/deps/v8/test/unittests/wasm/function-body-decoder-unittest.cc @@ -92,6 +92,9 @@ static const WasmOpcode kInt32BinopOpcodes[] = { class FunctionBodyDecoderTest : public TestWithZone { public: typedef std::pair<uint32_t, ValueType> LocalsDecl; + // All features are disabled by default and must be activated with + // a WASM_FEATURE_SCOPE in individual tests. + WasmFeatures enabled_features_; FunctionBodyDecoderTest() : module(nullptr), local_decls(zone()) {} @@ -133,8 +136,11 @@ class FunctionBodyDecoderTest : public TestWithZone { PrepareBytecode(&start, &end, append_end); // Verify the code. + FunctionBody body(sig, 0, start, end); + WasmFeatures unused_detected_features; DecodeResult result = - VerifyWasmCode(zone()->allocator(), module, sig, start, end); + VerifyWasmCode(zone()->allocator(), enabled_features_, module, + &unused_detected_features, body); uint32_t pc = result.error_offset(); std::ostringstream str; @@ -198,6 +204,17 @@ class FunctionBodyDecoderTest : public TestWithZone { namespace { +class EnableBoolScope { + public: + bool prev_; + bool* ptr_; + explicit EnableBoolScope(bool* ptr) : prev_(*ptr), ptr_(ptr) { *ptr = true; } + ~EnableBoolScope() { *ptr_ = prev_; } +}; + +#define WASM_FEATURE_SCOPE(feat) \ + EnableBoolScope feat##_scope(&this->enabled_features_.feat); + constexpr size_t kMaxByteSizedLeb128 = 127; // A helper for tests that require a module environment for functions, @@ -263,7 +280,7 @@ TEST_F(FunctionBodyDecoderTest, Int32Const1) { } TEST_F(FunctionBodyDecoderTest, RefNull) { - FlagScope<bool> flag_scope(&FLAG_experimental_wasm_anyref, true); + WASM_FEATURE_SCOPE(anyref); byte code[] = {kExprRefNull}; EXPECT_VERIFIES_C(r_v, code); } @@ -1236,8 +1253,8 @@ TEST_F(FunctionBodyDecoderTest, MacrosInt64) { } TEST_F(FunctionBodyDecoderTest, AllSimpleExpressions) { - EXPERIMENTAL_FLAG_SCOPE(se); - EXPERIMENTAL_FLAG_SCOPE(anyref); + WASM_FEATURE_SCOPE(se); + WASM_FEATURE_SCOPE(anyref); // Test all simple expressions which are described by a signature. #define DECODE_TEST(name, opcode, sig) \ { \ @@ -1476,7 +1493,7 @@ TEST_F(FunctionBodyDecoderTest, CallsWithMismatchedSigs3) { } TEST_F(FunctionBodyDecoderTest, MultiReturn) { - EXPERIMENTAL_FLAG_SCOPE(mv); + WASM_FEATURE_SCOPE(mv); ValueType storage[] = {kWasmI32, kWasmI32}; FunctionSig sig_ii_v(2, 0, storage); FunctionSig sig_v_ii(0, 2, storage); @@ -1492,7 +1509,7 @@ TEST_F(FunctionBodyDecoderTest, MultiReturn) { } TEST_F(FunctionBodyDecoderTest, MultiReturnType) { - EXPERIMENTAL_FLAG_SCOPE(mv); + WASM_FEATURE_SCOPE(mv); for (size_t a = 0; a < arraysize(kValueTypes); a++) { for (size_t b = 0; b < arraysize(kValueTypes); b++) { for (size_t c = 0; c < arraysize(kValueTypes); c++) { @@ -1612,7 +1629,7 @@ TEST_F(FunctionBodyDecoderTest, IncompleteStore) { } TEST_F(FunctionBodyDecoderTest, IncompleteS8x16Shuffle) { - EXPERIMENTAL_FLAG_SCOPE(simd); + WASM_FEATURE_SCOPE(simd); FunctionSig* sig = sigs.i_i(); TestModuleBuilder builder; builder.InitializeMemory(); @@ -2383,7 +2400,7 @@ TEST_F(FunctionBodyDecoderTest, Select_TypeCheck) { } TEST_F(FunctionBodyDecoderTest, Throw) { - EXPERIMENTAL_FLAG_SCOPE(eh); + WASM_FEATURE_SCOPE(eh); TestModuleBuilder builder; module = builder.module(); @@ -2403,7 +2420,7 @@ TEST_F(FunctionBodyDecoderTest, Throw) { TEST_F(FunctionBodyDecoderTest, ThrowUnreachable) { // TODO(titzer): unreachable code after throw should validate. - EXPERIMENTAL_FLAG_SCOPE(eh); + WASM_FEATURE_SCOPE(eh); TestModuleBuilder builder; module = builder.module(); @@ -2420,7 +2437,7 @@ TEST_F(FunctionBodyDecoderTest, ThrowUnreachable) { #define WASM_CATCH(index) kExprCatch, static_cast<byte>(index) TEST_F(FunctionBodyDecoderTest, TryCatch) { - EXPERIMENTAL_FLAG_SCOPE(eh); + WASM_FEATURE_SCOPE(eh); TestModuleBuilder builder; module = builder.module(); @@ -2445,7 +2462,7 @@ TEST_F(FunctionBodyDecoderTest, TryCatch) { #undef WASM_CATCH TEST_F(FunctionBodyDecoderTest, MultiValBlock1) { - EXPERIMENTAL_FLAG_SCOPE(mv); + WASM_FEATURE_SCOPE(mv); TestModuleBuilder builder; module = builder.module(); byte f0 = builder.AddSignature(sigs.ii_v()); @@ -2461,7 +2478,7 @@ TEST_F(FunctionBodyDecoderTest, MultiValBlock1) { } TEST_F(FunctionBodyDecoderTest, MultiValBlock2) { - EXPERIMENTAL_FLAG_SCOPE(mv); + WASM_FEATURE_SCOPE(mv); TestModuleBuilder builder; module = builder.module(); byte f0 = builder.AddSignature(sigs.ii_v()); @@ -2479,7 +2496,7 @@ TEST_F(FunctionBodyDecoderTest, MultiValBlock2) { } TEST_F(FunctionBodyDecoderTest, MultiValBlockBr) { - EXPERIMENTAL_FLAG_SCOPE(mv); + WASM_FEATURE_SCOPE(mv); TestModuleBuilder builder; module = builder.module(); byte f0 = builder.AddSignature(sigs.ii_v()); @@ -2491,7 +2508,7 @@ TEST_F(FunctionBodyDecoderTest, MultiValBlockBr) { } TEST_F(FunctionBodyDecoderTest, MultiValLoop1) { - EXPERIMENTAL_FLAG_SCOPE(mv); + WASM_FEATURE_SCOPE(mv); TestModuleBuilder builder; module = builder.module(); byte f0 = builder.AddSignature(sigs.ii_v()); @@ -2507,7 +2524,7 @@ TEST_F(FunctionBodyDecoderTest, MultiValLoop1) { } TEST_F(FunctionBodyDecoderTest, MultiValIf) { - EXPERIMENTAL_FLAG_SCOPE(mv); + WASM_FEATURE_SCOPE(mv); TestModuleBuilder builder; module = builder.module(); byte f0 = builder.AddSignature(sigs.ii_v()); @@ -2570,7 +2587,7 @@ TEST_F(FunctionBodyDecoderTest, MultiValIf) { } TEST_F(FunctionBodyDecoderTest, BlockParam) { - EXPERIMENTAL_FLAG_SCOPE(mv); + WASM_FEATURE_SCOPE(mv); TestModuleBuilder builder; module = builder.module(); byte f1 = builder.AddSignature(sigs.i_i()); @@ -2596,7 +2613,7 @@ TEST_F(FunctionBodyDecoderTest, BlockParam) { } TEST_F(FunctionBodyDecoderTest, LoopParam) { - EXPERIMENTAL_FLAG_SCOPE(mv); + WASM_FEATURE_SCOPE(mv); TestModuleBuilder builder; module = builder.module(); byte f1 = builder.AddSignature(sigs.i_i()); @@ -2622,7 +2639,7 @@ TEST_F(FunctionBodyDecoderTest, LoopParam) { } TEST_F(FunctionBodyDecoderTest, LoopParamBr) { - EXPERIMENTAL_FLAG_SCOPE(mv); + WASM_FEATURE_SCOPE(mv); TestModuleBuilder builder; module = builder.module(); byte f1 = builder.AddSignature(sigs.i_i()); @@ -2644,7 +2661,7 @@ TEST_F(FunctionBodyDecoderTest, LoopParamBr) { } TEST_F(FunctionBodyDecoderTest, IfParam) { - EXPERIMENTAL_FLAG_SCOPE(mv); + WASM_FEATURE_SCOPE(mv); TestModuleBuilder builder; module = builder.module(); byte f1 = builder.AddSignature(sigs.i_i()); @@ -2678,8 +2695,11 @@ TEST_F(FunctionBodyDecoderTest, Regression709741) { PrepareBytecode(&start, &end, kAppendEnd); for (const byte* i = start; i < end; i++) { + FunctionBody body(sigs.v_v(), 0, start, i); + WasmFeatures unused_detected_features; DecodeResult result = - VerifyWasmCode(zone()->allocator(), nullptr, sigs.v_v(), start, i); + VerifyWasmCode(zone()->allocator(), kAllWasmFeatures, nullptr, + &unused_detected_features, body); if (result.ok()) { std::ostringstream str; str << "Expected verification to fail"; @@ -2999,6 +3019,7 @@ typedef ZoneVector<ValueType> TypesOfLocals; class LocalDeclDecoderTest : public TestWithZone { public: v8::internal::AccountingAllocator allocator; + WasmFeatures enabled_features_; size_t ExpectRun(TypesOfLocals map, size_t pos, ValueType expected, size_t count) { @@ -3007,6 +3028,11 @@ class LocalDeclDecoderTest : public TestWithZone { } return pos; } + + bool DecodeLocalDecls(BodyLocalDecls* decls, const byte* start, + const byte* end) { + return i::wasm::DecodeLocalDecls(enabled_features_, decls, start, end); + } }; TEST_F(LocalDeclDecoderTest, EmptyLocals) { @@ -3024,7 +3050,7 @@ TEST_F(LocalDeclDecoderTest, NoLocals) { } TEST_F(LocalDeclDecoderTest, OneLocal) { - EXPERIMENTAL_FLAG_SCOPE(anyref); + WASM_FEATURE_SCOPE(anyref); for (size_t i = 0; i < arraysize(kValueTypes); i++) { ValueType type = kValueTypes[i]; const byte data[] = {1, 1, @@ -3040,7 +3066,7 @@ TEST_F(LocalDeclDecoderTest, OneLocal) { } TEST_F(LocalDeclDecoderTest, FiveLocals) { - EXPERIMENTAL_FLAG_SCOPE(anyref); + WASM_FEATURE_SCOPE(anyref); for (size_t i = 0; i < arraysize(kValueTypes); i++) { ValueType type = kValueTypes[i]; const byte data[] = {1, 5, @@ -3180,6 +3206,7 @@ TEST_F(BytecodeIteratorTest, WithLocalDecls) { EXPECT_FALSE(iter.has_next()); } +#undef WASM_FEATURE_SCOPE #undef B1 #undef B2 #undef B3 diff --git a/deps/v8/test/unittests/wasm/module-decoder-unittest.cc b/deps/v8/test/unittests/wasm/module-decoder-unittest.cc index 26b4f74a7a..3507f897f9 100644 --- a/deps/v8/test/unittests/wasm/module-decoder-unittest.cc +++ b/deps/v8/test/unittests/wasm/module-decoder-unittest.cc @@ -7,6 +7,7 @@ #include "src/handles.h" #include "src/objects-inl.h" #include "src/wasm/module-decoder.h" +#include "src/wasm/wasm-features.h" #include "src/wasm/wasm-limits.h" #include "src/wasm/wasm-opcodes.h" #include "test/common/wasm/flag-utils.h" @@ -146,6 +147,8 @@ struct ValueTypePair { class WasmModuleVerifyTest : public TestWithIsolateAndZone { public: + WasmFeatures enabled_features_; + ModuleResult DecodeModule(const byte* module_start, const byte* module_end) { // Add the wasm magic and version number automatically. size_t size = static_cast<size_t>(module_end - module_start); @@ -154,18 +157,39 @@ class WasmModuleVerifyTest : public TestWithIsolateAndZone { auto temp = new byte[total]; memcpy(temp, header, sizeof(header)); memcpy(temp + sizeof(header), module_start, size); - ModuleResult result = - SyncDecodeWasmModule(isolate(), temp, temp + total, false, kWasmOrigin); + ModuleResult result = DecodeWasmModule( + enabled_features_, temp, temp + total, false, kWasmOrigin, + isolate()->counters(), isolate()->allocator()); delete[] temp; return result; } ModuleResult DecodeModuleNoHeader(const byte* module_start, const byte* module_end) { - return SyncDecodeWasmModule(isolate(), module_start, module_end, false, - kWasmOrigin); + return DecodeWasmModule(enabled_features_, module_start, module_end, false, + kWasmOrigin, isolate()->counters(), + isolate()->allocator()); + } +}; + +namespace { +class EnableBoolScope { + public: + bool prev_; + bool* ptr_; + explicit EnableBoolScope(bool* ptr, bool val = true) + : prev_(*ptr), ptr_(ptr) { + *ptr = val; } + ~EnableBoolScope() { *ptr_ = prev_; } }; +#define WASM_FEATURE_SCOPE(feat) \ + EnableBoolScope feat##_scope(&this->enabled_features_.feat) + +#define WASM_FEATURE_SCOPE_VAL(feat, val) \ + EnableBoolScope feat##_scope(&this->enabled_features_.feat, val) +} // namespace + TEST_F(WasmModuleVerifyTest, WrongMagic) { for (uint32_t x = 1; x; x <<= 1) { const byte data[] = {U32_LE(kWasmMagic ^ x), U32_LE(kWasmVersion)}; @@ -217,7 +241,7 @@ TEST_F(WasmModuleVerifyTest, OneGlobal) { } TEST_F(WasmModuleVerifyTest, AnyRefGlobal) { - EXPERIMENTAL_FLAG_SCOPE(anyref); + WASM_FEATURE_SCOPE(anyref); static const byte data[] = { SECTION(Global, 5), // -- 1, @@ -243,7 +267,7 @@ TEST_F(WasmModuleVerifyTest, AnyRefGlobal) { } TEST_F(WasmModuleVerifyTest, AnyRefGlobalWithGlobalInit) { - EXPERIMENTAL_FLAG_SCOPE(anyref); + WASM_FEATURE_SCOPE(anyref); static const byte data[] = { SECTION(Import, 8), // section header 1, // number of imports @@ -313,6 +337,7 @@ TEST_F(WasmModuleVerifyTest, ZeroGlobals) { } TEST_F(WasmModuleVerifyTest, ExportMutableGlobal) { + WASM_FEATURE_SCOPE(mut_global); { static const byte data[] = { SECTION(Global, 6), // -- @@ -444,7 +469,7 @@ TEST_F(WasmModuleVerifyTest, ZeroExceptions) { }; FAIL_IF_NO_EXPERIMENTAL_EH(data); - EXPERIMENTAL_FLAG_SCOPE(eh); + WASM_FEATURE_SCOPE(eh); ModuleResult result = DecodeModule(data, data + sizeof(data)); EXPECT_OK(result); EXPECT_EQ(0u, result.val->exceptions.size()); @@ -458,7 +483,7 @@ TEST_F(WasmModuleVerifyTest, OneI32Exception) { }; FAIL_IF_NO_EXPERIMENTAL_EH(data); - EXPERIMENTAL_FLAG_SCOPE(eh); + WASM_FEATURE_SCOPE(eh); ModuleResult result = DecodeModule(data, data + sizeof(data)); EXPECT_OK(result); EXPECT_EQ(1u, result.val->exceptions.size()); @@ -476,7 +501,7 @@ TEST_F(WasmModuleVerifyTest, TwoExceptions) { 1, kLocalI32}; FAIL_IF_NO_EXPERIMENTAL_EH(data); - EXPERIMENTAL_FLAG_SCOPE(eh); + WASM_FEATURE_SCOPE(eh); ModuleResult result = DecodeModule(data, data + sizeof(data)); EXPECT_OK(result); EXPECT_EQ(2u, result.val->exceptions.size()); @@ -495,7 +520,7 @@ TEST_F(WasmModuleVerifyTest, Exception_invalid_type) { FAIL_IF_NO_EXPERIMENTAL_EH(data); // Should fail decoding exception section. - EXPERIMENTAL_FLAG_SCOPE(eh); + WASM_FEATURE_SCOPE(eh); ModuleResult result = DecodeModule(data, data + sizeof(data)); EXPECT_FALSE(result.ok()); } @@ -939,7 +964,7 @@ TEST_F(WasmModuleVerifyTest, MultipleIndirectFunctions) { TEST_F(WasmModuleVerifyTest, ElementSectionMultipleTables) { // Test that if we have multiple tables, in the element section we can target // and initialize all tables. - FlagScope<bool> flag_scope(&FLAG_experimental_wasm_anyref, true); + WASM_FEATURE_SCOPE(anyref); static const byte data[] = { // sig#0 --------------------------------------------------------------- SIGNATURES_SECTION_VOID_VOID, @@ -969,7 +994,7 @@ TEST_F(WasmModuleVerifyTest, ElementSectionMultipleTables) { TEST_F(WasmModuleVerifyTest, ElementSectionMixedTables) { // Test that if we have multiple tables, both imported and module-defined, in // the element section we can target and initialize all tables. - FlagScope<bool> flag_scope(&FLAG_experimental_wasm_anyref, true); + WASM_FEATURE_SCOPE(anyref); static const byte data[] = { // sig#0 --------------------------------------------------------------- SIGNATURES_SECTION_VOID_VOID, @@ -1026,7 +1051,7 @@ TEST_F(WasmModuleVerifyTest, ElementSectionMixedTables) { TEST_F(WasmModuleVerifyTest, ElementSectionMultipleTablesArbitraryOrder) { // Test that the order in which tables are targeted in the element secion // can be arbitrary. - FlagScope<bool> flag_scope(&FLAG_experimental_wasm_anyref, true); + WASM_FEATURE_SCOPE(anyref); static const byte data[] = { // sig#0 --------------------------------------------------------------- SIGNATURES_SECTION_VOID_VOID, @@ -1060,7 +1085,7 @@ TEST_F(WasmModuleVerifyTest, ElementSectionMultipleTablesArbitraryOrder) { TEST_F(WasmModuleVerifyTest, ElementSectionMixedTablesArbitraryOrder) { // Test that the order in which tables are targeted in the element secion can // be arbitrary. In this test, tables can be both imported and module-defined. - FlagScope<bool> flag_scope(&FLAG_experimental_wasm_anyref, true); + WASM_FEATURE_SCOPE(anyref); static const byte data[] = { // sig#0 --------------------------------------------------------------- SIGNATURES_SECTION_VOID_VOID, @@ -1117,7 +1142,7 @@ TEST_F(WasmModuleVerifyTest, ElementSectionMixedTablesArbitraryOrder) { TEST_F(WasmModuleVerifyTest, ElementSectionDontInitAnyRefTable) { // Test that tables of type 'AnyRef' cannot be initialized by the element // section. - FlagScope<bool> flag_scope(&FLAG_experimental_wasm_anyref, true); + WASM_FEATURE_SCOPE(anyref); static const byte data[] = { // sig#0 --------------------------------------------------------------- SIGNATURES_SECTION_VOID_VOID, @@ -1147,7 +1172,7 @@ TEST_F(WasmModuleVerifyTest, ElementSectionDontInitAnyRefTable) { TEST_F(WasmModuleVerifyTest, ElementSectionDontInitAnyRefImportedTable) { // Test that imported tables of type AnyRef cannot be initialized in the // elements section. - FlagScope<bool> flag_scope(&FLAG_experimental_wasm_anyref, true); + WASM_FEATURE_SCOPE(anyref); static const byte data[] = { // sig#0 --------------------------------------------------------------- SIGNATURES_SECTION_VOID_VOID, @@ -1231,7 +1256,7 @@ TEST_F(WasmModuleVerifyTest, MultipleTablesWithoutFlag) { } TEST_F(WasmModuleVerifyTest, MultipleTablesWithFlag) { - FlagScope<bool> flag_scope(&FLAG_experimental_wasm_anyref, true); + WASM_FEATURE_SCOPE(anyref); static const byte data[] = { SECTION(Table, 7), // table section ENTRY_COUNT(2), // 2 tables @@ -1257,22 +1282,18 @@ TEST_F(WasmModuleVerifyTest, MultipleTablesWithFlag) { class WasmSignatureDecodeTest : public TestWithZone { public: - WasmSignatureDecodeTest() - // In the following tests we turn on support for AnyRef by default. There - // is a test (Fail_anyref_without_flag) which explicitly turns off support - // for AnyRef. - : flag_scope(&FLAG_experimental_wasm_anyref, true) {} - - private: - FlagScope<bool> flag_scope; + WasmFeatures enabled_features_; + + FunctionSig* DecodeSig(const byte* start, const byte* end) { + return DecodeWasmSignatureForTesting(enabled_features_, zone(), start, end); + } }; TEST_F(WasmSignatureDecodeTest, Ok_v_v) { static const byte data[] = {SIG_ENTRY_v_v}; v8::internal::AccountingAllocator allocator; Zone zone(&allocator, ZONE_NAME); - FunctionSig* sig = - DecodeWasmSignatureForTesting(&zone, data, data + sizeof(data)); + FunctionSig* sig = DecodeSig(data, data + sizeof(data)); EXPECT_TRUE(sig != nullptr); EXPECT_EQ(0u, sig->parameter_count()); @@ -1280,11 +1301,11 @@ TEST_F(WasmSignatureDecodeTest, Ok_v_v) { } TEST_F(WasmSignatureDecodeTest, Ok_t_v) { + WASM_FEATURE_SCOPE(anyref); for (size_t i = 0; i < arraysize(kValueTypes); i++) { ValueTypePair ret_type = kValueTypes[i]; const byte data[] = {SIG_ENTRY_x(ret_type.code)}; - FunctionSig* sig = - DecodeWasmSignatureForTesting(zone(), data, data + sizeof(data)); + FunctionSig* sig = DecodeSig(data, data + sizeof(data)); EXPECT_TRUE(sig != nullptr); EXPECT_EQ(0u, sig->parameter_count()); @@ -1294,11 +1315,11 @@ TEST_F(WasmSignatureDecodeTest, Ok_t_v) { } TEST_F(WasmSignatureDecodeTest, Ok_v_t) { + WASM_FEATURE_SCOPE(anyref); for (size_t i = 0; i < arraysize(kValueTypes); i++) { ValueTypePair param_type = kValueTypes[i]; const byte data[] = {SIG_ENTRY_v_x(param_type.code)}; - FunctionSig* sig = - DecodeWasmSignatureForTesting(zone(), data, data + sizeof(data)); + FunctionSig* sig = DecodeSig(data, data + sizeof(data)); EXPECT_TRUE(sig != nullptr); EXPECT_EQ(1u, sig->parameter_count()); @@ -1308,13 +1329,13 @@ TEST_F(WasmSignatureDecodeTest, Ok_v_t) { } TEST_F(WasmSignatureDecodeTest, Ok_t_t) { + WASM_FEATURE_SCOPE(anyref); for (size_t i = 0; i < arraysize(kValueTypes); i++) { ValueTypePair ret_type = kValueTypes[i]; for (size_t j = 0; j < arraysize(kValueTypes); j++) { ValueTypePair param_type = kValueTypes[j]; const byte data[] = {SIG_ENTRY_x_x(ret_type.code, param_type.code)}; - FunctionSig* sig = - DecodeWasmSignatureForTesting(zone(), data, data + sizeof(data)); + FunctionSig* sig = DecodeSig(data, data + sizeof(data)); EXPECT_TRUE(sig != nullptr); EXPECT_EQ(1u, sig->parameter_count()); @@ -1326,14 +1347,15 @@ TEST_F(WasmSignatureDecodeTest, Ok_t_t) { } TEST_F(WasmSignatureDecodeTest, Ok_i_tt) { + WASM_FEATURE_SCOPE(anyref); + WASM_FEATURE_SCOPE(mv); for (size_t i = 0; i < arraysize(kValueTypes); i++) { ValueTypePair p0_type = kValueTypes[i]; for (size_t j = 0; j < arraysize(kValueTypes); j++) { ValueTypePair p1_type = kValueTypes[j]; const byte data[] = { SIG_ENTRY_x_xx(kLocalI32, p0_type.code, p1_type.code)}; - FunctionSig* sig = - DecodeWasmSignatureForTesting(zone(), data, data + sizeof(data)); + FunctionSig* sig = DecodeSig(data, data + sizeof(data)); EXPECT_TRUE(sig != nullptr); EXPECT_EQ(2u, sig->parameter_count()); @@ -1344,25 +1366,45 @@ TEST_F(WasmSignatureDecodeTest, Ok_i_tt) { } } +TEST_F(WasmSignatureDecodeTest, Ok_tt_tt) { + WASM_FEATURE_SCOPE(anyref); + WASM_FEATURE_SCOPE(mv); + for (size_t i = 0; i < arraysize(kValueTypes); i++) { + ValueTypePair p0_type = kValueTypes[i]; + for (size_t j = 0; j < arraysize(kValueTypes); j++) { + ValueTypePair p1_type = kValueTypes[j]; + const byte data[] = {SIG_ENTRY_xx_xx(p0_type.code, p1_type.code, + p0_type.code, p1_type.code)}; + FunctionSig* sig = DecodeSig(data, data + sizeof(data)); + + EXPECT_TRUE(sig != nullptr); + EXPECT_EQ(2u, sig->parameter_count()); + EXPECT_EQ(2u, sig->return_count()); + EXPECT_EQ(p0_type.type, sig->GetParam(0)); + EXPECT_EQ(p1_type.type, sig->GetParam(1)); + EXPECT_EQ(p0_type.type, sig->GetReturn(0)); + EXPECT_EQ(p1_type.type, sig->GetReturn(1)); + } + } +} + TEST_F(WasmSignatureDecodeTest, TooManyParams) { static const byte data[] = {kWasmFunctionTypeCode, WASM_I32V_3(kV8MaxWasmFunctionParams + 1), kLocalI32, 0}; - FunctionSig* sig = - DecodeWasmSignatureForTesting(zone(), data, data + sizeof(data)); + FunctionSig* sig = DecodeSig(data, data + sizeof(data)); EXPECT_FALSE(sig != nullptr); } TEST_F(WasmSignatureDecodeTest, TooManyReturns) { for (int i = 0; i < 2; i++) { - FlagScope<bool> flag_scope(&FLAG_experimental_wasm_mv, i != 0); + bool enable_mv = i != 0; + WASM_FEATURE_SCOPE_VAL(mv, enable_mv); const int max_return_count = static_cast<int>( - FLAG_experimental_wasm_mv ? kV8MaxWasmFunctionMultiReturns - : kV8MaxWasmFunctionReturns); + enable_mv ? kV8MaxWasmFunctionMultiReturns : kV8MaxWasmFunctionReturns); byte data[] = {kWasmFunctionTypeCode, 0, WASM_I32V_3(max_return_count + 1), kLocalI32}; - FunctionSig* sig = - DecodeWasmSignatureForTesting(zone(), data, data + sizeof(data)); + FunctionSig* sig = DecodeSig(data, data + sizeof(data)); EXPECT_EQ(nullptr, sig); } } @@ -1375,7 +1417,7 @@ TEST_F(WasmSignatureDecodeTest, Fail_off_end) { for (int i = 0; i < p + 1; i++) { // Should fall off the end for all signatures. - FunctionSig* sig = DecodeWasmSignatureForTesting(zone(), data, data + i); + FunctionSig* sig = DecodeSig(data, data + i); EXPECT_EQ(nullptr, sig); } } @@ -1383,14 +1425,13 @@ TEST_F(WasmSignatureDecodeTest, Fail_off_end) { TEST_F(WasmSignatureDecodeTest, Fail_anyref_without_flag) { // Disable AnyRef support and check that decoding fails. - FlagScope<bool> flag_scope(&FLAG_experimental_wasm_anyref, false); + WASM_FEATURE_SCOPE_VAL(anyref, false); byte ref_types[] = {kLocalAnyFunc, kLocalAnyRef}; for (byte invalid_type : ref_types) { for (size_t i = 0; i < SIZEOF_SIG_ENTRY_x_xx; i++) { byte data[] = {SIG_ENTRY_x_xx(kLocalI32, kLocalI32, kLocalI32)}; data[i] = invalid_type; - FunctionSig* sig = - DecodeWasmSignatureForTesting(zone(), data, data + sizeof(data)); + FunctionSig* sig = DecodeSig(data, data + sizeof(data)); EXPECT_EQ(nullptr, sig); } } @@ -1401,41 +1442,43 @@ TEST_F(WasmSignatureDecodeTest, Fail_invalid_type) { for (size_t i = 0; i < SIZEOF_SIG_ENTRY_x_xx; i++) { byte data[] = {SIG_ENTRY_x_xx(kLocalI32, kLocalI32, kLocalI32)}; data[i] = kInvalidType; - FunctionSig* sig = - DecodeWasmSignatureForTesting(zone(), data, data + sizeof(data)); + FunctionSig* sig = DecodeSig(data, data + sizeof(data)); EXPECT_EQ(nullptr, sig); } } TEST_F(WasmSignatureDecodeTest, Fail_invalid_ret_type1) { static const byte data[] = {SIG_ENTRY_x_x(kLocalVoid, kLocalI32)}; - FunctionSig* sig = - DecodeWasmSignatureForTesting(zone(), data, data + sizeof(data)); + FunctionSig* sig = DecodeSig(data, data + sizeof(data)); EXPECT_EQ(nullptr, sig); } TEST_F(WasmSignatureDecodeTest, Fail_invalid_param_type1) { static const byte data[] = {SIG_ENTRY_x_x(kLocalI32, kLocalVoid)}; - FunctionSig* sig = - DecodeWasmSignatureForTesting(zone(), data, data + sizeof(data)); + FunctionSig* sig = DecodeSig(data, data + sizeof(data)); EXPECT_EQ(nullptr, sig); } TEST_F(WasmSignatureDecodeTest, Fail_invalid_param_type2) { static const byte data[] = {SIG_ENTRY_x_xx(kLocalI32, kLocalI32, kLocalVoid)}; - FunctionSig* sig = - DecodeWasmSignatureForTesting(zone(), data, data + sizeof(data)); + FunctionSig* sig = DecodeSig(data, data + sizeof(data)); EXPECT_EQ(nullptr, sig); } class WasmFunctionVerifyTest : public TestWithIsolateAndZone { public: - WasmFunctionVerifyTest() {} - virtual ~WasmFunctionVerifyTest() {} - + WasmFeatures enabled_features_; WasmModule module; Vector<const byte> bytes; - DISALLOW_COPY_AND_ASSIGN(WasmFunctionVerifyTest); + + FunctionResult DecodeWasmFunction(const ModuleWireBytes& wire_bytes, + const WasmModule* module, + const byte* function_start, + const byte* function_end) { + return DecodeWasmFunctionForTesting(enabled_features_, zone(), wire_bytes, + module, function_start, function_end, + isolate()->counters()); + } }; TEST_F(WasmFunctionVerifyTest, Ok_v_v_empty) { @@ -1453,8 +1496,8 @@ TEST_F(WasmFunctionVerifyTest, Ok_v_v_empty) { kExprEnd // body }; - FunctionResult result = SyncDecodeWasmFunction( - isolate(), zone(), bytes, &module, data, data + sizeof(data)); + FunctionResult result = + DecodeWasmFunction(bytes, &module, data, data + sizeof(data)); EXPECT_OK(result); if (result.val && result.ok()) { @@ -1583,6 +1626,7 @@ TEST_F(WasmModuleVerifyTest, ImportTable_nosigs1) { } TEST_F(WasmModuleVerifyTest, ImportTable_mutable_global) { + WASM_FEATURE_SCOPE(mut_global); { static const byte data[] = { SECTION(Import, 8), // section header @@ -1614,6 +1658,7 @@ TEST_F(WasmModuleVerifyTest, ImportTable_mutable_global) { } TEST_F(WasmModuleVerifyTest, ImportTable_mutability_malformed) { + WASM_FEATURE_SCOPE(mut_global); static const byte data[] = { SECTION(Import, 8), 1, // -- @@ -2021,61 +2066,68 @@ TEST_F(WasmModuleVerifyTest, Regression684855) { EXPECT_VERIFIES(data); } -#define EXPECT_INIT_EXPR(Type, type, value, ...) \ - { \ - static const byte data[] = {__VA_ARGS__, kExprEnd}; \ - WasmInitExpr expr = \ - DecodeWasmInitExprForTesting(data, data + sizeof(data)); \ - EXPECT_EQ(WasmInitExpr::k##Type##Const, expr.kind); \ - EXPECT_EQ(value, expr.val.type##_const); \ +class WasmInitExprDecodeTest : public TestWithZone { + public: + WasmInitExprDecodeTest() {} + + WasmFeatures enabled_features_; + + WasmInitExpr DecodeInitExpr(const byte* start, const byte* end) { + return DecodeWasmInitExprForTesting(enabled_features_, start, end); + } +}; + +#define EXPECT_INIT_EXPR(Type, type, value, ...) \ + { \ + static const byte data[] = {__VA_ARGS__, kExprEnd}; \ + WasmInitExpr expr = DecodeInitExpr(data, data + sizeof(data)); \ + EXPECT_EQ(WasmInitExpr::k##Type##Const, expr.kind); \ + EXPECT_EQ(value, expr.val.type##_const); \ } -TEST_F(WasmModuleVerifyTest, InitExpr_i32) { +#define EXPECT_INIT_EXPR_FAIL(...) \ + { \ + static const byte data[] = {__VA_ARGS__, kExprEnd}; \ + WasmInitExpr expr = DecodeInitExpr(data, data + sizeof(data)); \ + EXPECT_EQ(WasmInitExpr::kNone, expr.kind); \ + } + +TEST_F(WasmInitExprDecodeTest, InitExpr_i32) { EXPECT_INIT_EXPR(I32, i32, 33, WASM_I32V_1(33)); EXPECT_INIT_EXPR(I32, i32, -21, WASM_I32V_1(-21)); EXPECT_INIT_EXPR(I32, i32, 437, WASM_I32V_2(437)); EXPECT_INIT_EXPR(I32, i32, 77777, WASM_I32V_3(77777)); } -TEST_F(WasmModuleVerifyTest, InitExpr_f32) { +TEST_F(WasmInitExprDecodeTest, InitExpr_f32) { EXPECT_INIT_EXPR(F32, f32, static_cast<float>(13.1), WASM_F32(13.1)); EXPECT_INIT_EXPR(F32, f32, static_cast<float>(-21.1), WASM_F32(-21.1)); EXPECT_INIT_EXPR(F32, f32, static_cast<float>(437.2), WASM_F32(437.2)); EXPECT_INIT_EXPR(F32, f32, static_cast<float>(77777.3), WASM_F32(77777.3)); } -TEST_F(WasmModuleVerifyTest, InitExpr_i64) { +TEST_F(WasmInitExprDecodeTest, InitExpr_i64) { EXPECT_INIT_EXPR(I64, i64, 33, WASM_I64V_1(33)); EXPECT_INIT_EXPR(I64, i64, -21, WASM_I64V_2(-21)); EXPECT_INIT_EXPR(I64, i64, 437, WASM_I64V_5(437)); EXPECT_INIT_EXPR(I64, i64, 77777, WASM_I64V_7(77777)); } -TEST_F(WasmModuleVerifyTest, InitExpr_f64) { +TEST_F(WasmInitExprDecodeTest, InitExpr_f64) { EXPECT_INIT_EXPR(F64, f64, 83.22, WASM_F64(83.22)); EXPECT_INIT_EXPR(F64, f64, -771.3, WASM_F64(-771.3)); EXPECT_INIT_EXPR(F64, f64, 43703.0, WASM_F64(43703.0)); EXPECT_INIT_EXPR(F64, f64, 77999.1, WASM_F64(77999.1)); } -TEST_F(WasmModuleVerifyTest, InitExpr_AnyRef) { - EXPERIMENTAL_FLAG_SCOPE(anyref); +TEST_F(WasmInitExprDecodeTest, InitExpr_AnyRef) { + WASM_FEATURE_SCOPE(anyref); static const byte data[] = {kExprRefNull, kExprEnd}; - WasmInitExpr expr = DecodeWasmInitExprForTesting(data, data + sizeof(data)); + WasmInitExpr expr = DecodeInitExpr(data, data + sizeof(data)); EXPECT_EQ(WasmInitExpr::kAnyRefConst, expr.kind); } -#undef EXPECT_INIT_EXPR - -#define EXPECT_INIT_EXPR_FAIL(...) \ - { \ - static const byte data[] = {__VA_ARGS__, kExprEnd}; \ - WasmInitExpr expr = \ - DecodeWasmInitExprForTesting(data, data + sizeof(data)); \ - EXPECT_EQ(WasmInitExpr::kNone, expr.kind); \ - } - -TEST_F(WasmModuleVerifyTest, InitExpr_illegal) { +TEST_F(WasmInitExprDecodeTest, InitExpr_illegal) { EXPECT_INIT_EXPR_FAIL(WASM_I32V_1(0), WASM_I32V_1(0)); EXPECT_INIT_EXPR_FAIL(WASM_GET_LOCAL(0)); EXPECT_INIT_EXPR_FAIL(WASM_SET_LOCAL(0, WASM_I32V_1(0))); @@ -2083,8 +2135,6 @@ TEST_F(WasmModuleVerifyTest, InitExpr_illegal) { EXPECT_INIT_EXPR_FAIL(WASM_IF_ELSE(WASM_ZERO, WASM_ZERO, WASM_ZERO)); } -#undef EXPECT_INIT_EXPR_FAIL - TEST_F(WasmModuleVerifyTest, Multiple_Named_Sections) { static const byte data[] = { SECTION(Unknown, 4), 1, 'X', 17, 18, // -- @@ -2173,6 +2223,10 @@ TEST_F(WasmModuleCustomSectionTest, TwoKnownTwoUnknownSections) { CheckSections(data, data + sizeof(data), expected, arraysize(expected)); } +#undef WASM_FEATURE_SCOPE +#undef WASM_FEATURE_SCOPE_VAL +#undef EXPECT_INIT_EXPR +#undef EXPECT_INIT_EXPR_FAIL #undef WASM_INIT_EXPR_I32V_1 #undef WASM_INIT_EXPR_I32V_2 #undef WASM_INIT_EXPR_I32V_3 diff --git a/deps/v8/test/unittests/wasm/wasm-code-manager-unittest.cc b/deps/v8/test/unittests/wasm/wasm-code-manager-unittest.cc index c05a13c431..cc66f14d9c 100644 --- a/deps/v8/test/unittests/wasm/wasm-code-manager-unittest.cc +++ b/deps/v8/test/unittests/wasm/wasm-code-manager-unittest.cc @@ -8,6 +8,7 @@ #include "src/wasm/function-compiler.h" #include "src/wasm/jump-table-assembler.h" #include "src/wasm/wasm-code-manager.h" +#include "src/wasm/wasm-memory.h" namespace v8 { namespace internal { @@ -157,7 +158,7 @@ class WasmCodeManagerTest : public TestWithContext, public: static constexpr uint32_t kNumFunctions = 10; static constexpr uint32_t kJumpTableSize = RoundUp<kCodeAlignment>( - kNumFunctions * JumpTableAssembler::kJumpTableSlotSize); + JumpTableAssembler::SizeForNumberOfSlots(kNumFunctions)); using NativeModulePtr = std::unique_ptr<NativeModule>; @@ -166,10 +167,10 @@ class WasmCodeManagerTest : public TestWithContext, std::shared_ptr<WasmModule> module(new WasmModule); module->num_declared_functions = kNumFunctions; bool can_request_more = style == Growable; - wasm::ModuleEnv env(module.get(), UseTrapHandler::kNoTrapHandler, - RuntimeExceptionSupport::kNoRuntimeExceptionSupport); - return manager->NewNativeModule(i_isolate(), size, can_request_more, - std::move(module), env); + ModuleEnv env(module.get(), UseTrapHandler::kNoTrapHandler, + RuntimeExceptionSupport::kNoRuntimeExceptionSupport); + return manager->NewNativeModule(i_isolate(), kAllWasmFeatures, size, + can_request_more, std::move(module), env); } WasmCode* AddCode(NativeModule* native_module, uint32_t index, size_t size) { @@ -183,6 +184,11 @@ class WasmCodeManagerTest : public TestWithContext, } size_t page() const { return AllocatePageSize(); } + + WasmMemoryTracker* memory_tracker() { return &memory_tracker_; } + + private: + WasmMemoryTracker memory_tracker_; }; INSTANTIATE_TEST_CASE_P(Parameterized, WasmCodeManagerTest, @@ -190,7 +196,7 @@ INSTANTIATE_TEST_CASE_P(Parameterized, WasmCodeManagerTest, PrintWasmCodeManageTestParam); TEST_P(WasmCodeManagerTest, EmptyCase) { - WasmCodeManager manager(0 * page()); + WasmCodeManager manager(memory_tracker(), 0 * page()); CHECK_EQ(0, manager.remaining_uncommitted_code_space()); ASSERT_DEATH_IF_SUPPORTED(AllocModule(&manager, 1 * page(), GetParam()), @@ -198,7 +204,7 @@ TEST_P(WasmCodeManagerTest, EmptyCase) { } TEST_P(WasmCodeManagerTest, AllocateAndGoOverLimit) { - WasmCodeManager manager(1 * page()); + WasmCodeManager manager(memory_tracker(), 1 * page()); CHECK_EQ(1 * page(), manager.remaining_uncommitted_code_space()); NativeModulePtr native_module = AllocModule(&manager, 1 * page(), GetParam()); CHECK(native_module); @@ -223,7 +229,7 @@ TEST_P(WasmCodeManagerTest, AllocateAndGoOverLimit) { } TEST_P(WasmCodeManagerTest, TotalLimitIrrespectiveOfModuleCount) { - WasmCodeManager manager(3 * page()); + WasmCodeManager manager(memory_tracker(), 3 * page()); NativeModulePtr nm1 = AllocModule(&manager, 2 * page(), GetParam()); NativeModulePtr nm2 = AllocModule(&manager, 2 * page(), GetParam()); CHECK(nm1); @@ -235,8 +241,8 @@ TEST_P(WasmCodeManagerTest, TotalLimitIrrespectiveOfModuleCount) { } TEST_P(WasmCodeManagerTest, DifferentHeapsApplyLimitsIndependently) { - WasmCodeManager manager1(1 * page()); - WasmCodeManager manager2(2 * page()); + WasmCodeManager manager1(memory_tracker(), 1 * page()); + WasmCodeManager manager2(memory_tracker(), 2 * page()); NativeModulePtr nm1 = AllocModule(&manager1, 1 * page(), GetParam()); NativeModulePtr nm2 = AllocModule(&manager2, 1 * page(), GetParam()); CHECK(nm1); @@ -249,7 +255,7 @@ TEST_P(WasmCodeManagerTest, DifferentHeapsApplyLimitsIndependently) { } TEST_P(WasmCodeManagerTest, GrowingVsFixedModule) { - WasmCodeManager manager(3 * page()); + WasmCodeManager manager(memory_tracker(), 3 * page()); NativeModulePtr nm = AllocModule(&manager, 1 * page(), GetParam()); size_t module_size = GetParam() == Fixed ? kMaxWasmCodeMemory : 1 * page(); size_t remaining_space_in_module = module_size - kJumpTableSize; @@ -268,7 +274,7 @@ TEST_P(WasmCodeManagerTest, GrowingVsFixedModule) { } TEST_P(WasmCodeManagerTest, CommitIncrements) { - WasmCodeManager manager(10 * page()); + WasmCodeManager manager(memory_tracker(), 10 * page()); NativeModulePtr nm = AllocModule(&manager, 3 * page(), GetParam()); WasmCode* code = AddCode(nm.get(), 0, kCodeAlignment); CHECK_NOT_NULL(code); @@ -282,7 +288,7 @@ TEST_P(WasmCodeManagerTest, CommitIncrements) { } TEST_P(WasmCodeManagerTest, Lookup) { - WasmCodeManager manager(2 * page()); + WasmCodeManager manager(memory_tracker(), 2 * page()); NativeModulePtr nm1 = AllocModule(&manager, 1 * page(), GetParam()); NativeModulePtr nm2 = AllocModule(&manager, 1 * page(), GetParam()); @@ -321,8 +327,8 @@ TEST_P(WasmCodeManagerTest, Lookup) { } TEST_P(WasmCodeManagerTest, MultiManagerLookup) { - WasmCodeManager manager1(2 * page()); - WasmCodeManager manager2(2 * page()); + WasmCodeManager manager1(memory_tracker(), 2 * page()); + WasmCodeManager manager2(memory_tracker(), 2 * page()); NativeModulePtr nm1 = AllocModule(&manager1, 1 * page(), GetParam()); NativeModulePtr nm2 = AllocModule(&manager2, 1 * page(), GetParam()); @@ -344,7 +350,7 @@ TEST_P(WasmCodeManagerTest, MultiManagerLookup) { } TEST_P(WasmCodeManagerTest, LookupWorksAfterRewrite) { - WasmCodeManager manager(2 * page()); + WasmCodeManager manager(memory_tracker(), 2 * page()); NativeModulePtr nm1 = AllocModule(&manager, 1 * page(), GetParam()); diff --git a/deps/v8/test/unittests/zone/zone-chunk-list-unittest.cc b/deps/v8/test/unittests/zone/zone-chunk-list-unittest.cc index 0883dd9538..d982c1e0ec 100644 --- a/deps/v8/test/unittests/zone/zone-chunk-list-unittest.cc +++ b/deps/v8/test/unittests/zone/zone-chunk-list-unittest.cc @@ -280,5 +280,77 @@ TEST(ZoneChunkList, PushBackPopBackSize) { CHECK_EQ(size_t(0), zone_chunk_list.size()); } +TEST(ZoneChunkList, AdvanceZeroTest) { + AccountingAllocator allocator; + Zone zone(&allocator, ZONE_NAME); + + ZoneChunkList<uintptr_t> zone_chunk_list(&zone); + + for (size_t i = 0; i < kItemCount; ++i) { + zone_chunk_list.push_back(static_cast<uintptr_t>(i)); + } + + auto iterator_advance = zone_chunk_list.begin(); + + iterator_advance.Advance(0); + + CHECK_EQ(iterator_advance, zone_chunk_list.begin()); +} + +TEST(ZoneChunkList, AdvancePartwayTest) { + AccountingAllocator allocator; + Zone zone(&allocator, ZONE_NAME); + + ZoneChunkList<uintptr_t> zone_chunk_list(&zone); + + for (size_t i = 0; i < kItemCount; ++i) { + zone_chunk_list.push_back(static_cast<uintptr_t>(i)); + } + + auto iterator_advance = zone_chunk_list.begin(); + auto iterator_one_by_one = zone_chunk_list.begin(); + + iterator_advance.Advance(kItemCount / 2); + for (size_t i = 0; i < kItemCount / 2; ++i) { + ++iterator_one_by_one; + } + + CHECK_EQ(iterator_advance, iterator_one_by_one); +} + +TEST(ZoneChunkList, AdvanceEndTest) { + AccountingAllocator allocator; + Zone zone(&allocator, ZONE_NAME); + + ZoneChunkList<uintptr_t> zone_chunk_list(&zone); + + for (size_t i = 0; i < kItemCount; ++i) { + zone_chunk_list.push_back(static_cast<uintptr_t>(i)); + } + + auto iterator_advance = zone_chunk_list.begin(); + + iterator_advance.Advance(kItemCount); + + CHECK_EQ(iterator_advance, zone_chunk_list.end()); +} + +TEST(ZoneChunkList, FindOverChunkBoundary) { + AccountingAllocator allocator; + Zone zone(&allocator, ZONE_NAME); + + ZoneChunkList<int> zone_chunk_list(&zone); + + // Make sure we get two chunks. + int chunk_size = static_cast<int>(ZoneChunkList<int>::StartMode::kSmall); + for (int i = 0; i < chunk_size + 1; ++i) { + zone_chunk_list.push_back(i); + } + + for (int i = 0; i < chunk_size + 1; ++i) { + CHECK_EQ(i, *zone_chunk_list.Find(i)); + } +} + } // namespace internal } // namespace v8 |