Commit 1a1f4e1e authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[test] Refactor AllocateAssemblerBuffer

Refactor the AllocateAssemblerBuffer helper for the new Assembler API.
This is the only non-mechanical part, all other callsites that create
Assembler instances can be trivially changed to the new API. This will
be done in a separate CL.

R=mstarzinger@chromium.org

Bug: v8:8689, v8:8562
Change-Id: I6c150748eeea778d9b70f41fd66fbb1221035a1b
Reviewed-on: https://chromium-review.googlesource.com/c/1415490
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58881}
parent 119c083e
...@@ -171,18 +171,19 @@ static void InitializeVM() { ...@@ -171,18 +171,19 @@ static void InitializeVM() {
#else // ifdef USE_SIMULATOR. #else // ifdef USE_SIMULATOR.
// Run the test on real hardware or models. // Run the test on real hardware or models.
#define SETUP_SIZE(buf_size) \ #define SETUP_SIZE(buf_size) \
Isolate* isolate = CcTest::i_isolate(); \ Isolate* isolate = CcTest::i_isolate(); \
HandleScope scope(isolate); \ HandleScope scope(isolate); \
CHECK_NOT_NULL(isolate); \ CHECK_NOT_NULL(isolate); \
size_t allocated; \ auto owned_buf = AllocateAssemblerBuffer(buf_size); \
byte* buf = AllocateAssemblerBuffer(&allocated, buf_size); \ MacroAssembler masm(isolate, v8::internal::CodeObjectRequired::kYes, \
MacroAssembler masm(isolate, buf, static_cast<int>(allocated), \ owned_buf->CreateView()); \
v8::internal::CodeObjectRequired::kYes); \ uint8_t* buf = owned_buf->start(); \
USE(buf); \
RegisterDump core; RegisterDump core;
#define RESET() \ #define RESET() \
MakeAssemblerBufferWritable(buf, allocated); \ owned_buf->MakeWritable(); \
__ Reset(); \ __ Reset(); \
/* Reset the machine state (like simulator.ResetState()). */ \ /* Reset the machine state (like simulator.ResetState()). */ \
__ Msr(NZCV, xzr); \ __ Msr(NZCV, xzr); \
...@@ -195,12 +196,11 @@ static void InitializeVM() { ...@@ -195,12 +196,11 @@ static void InitializeVM() {
RESET(); \ RESET(); \
START_AFTER_RESET(); START_AFTER_RESET();
#define RUN() \ #define RUN() \
MakeAssemblerBufferExecutable(buf, allocated); \ owned_buf->MakeExecutable(); \
{ \ { \
void (*test_function)(void); \ auto* test_function = bit_cast<void (*)()>(buf); \
memcpy(&test_function, &buf, sizeof(buf)); \ test_function(); \
test_function(); \
} }
#define END() \ #define END() \
...@@ -209,7 +209,7 @@ static void InitializeVM() { ...@@ -209,7 +209,7 @@ static void InitializeVM() {
__ Ret(); \ __ Ret(); \
__ GetCode(masm.isolate(), nullptr); __ GetCode(masm.isolate(), nullptr);
#define TEARDOWN() FreeAssemblerBuffer(buf, allocated); #define TEARDOWN()
#endif // ifdef USE_SIMULATOR. #endif // ifdef USE_SIMULATOR.
......
This diff is collapsed.
...@@ -21,9 +21,8 @@ static constexpr int kNumInstr = 100; ...@@ -21,9 +21,8 @@ static constexpr int kNumInstr = 100;
static constexpr int kNumIterations = 5; static constexpr int kNumIterations = 5;
static constexpr int kBufferSize = 8 * KB; static constexpr int kBufferSize = 8 * KB;
static void FloodWithInc(Isolate* isolate, byte* buffer, size_t allocated) { static void FloodWithInc(Isolate* isolate, TestingAssemblerBuffer* buffer) {
MacroAssembler masm(isolate, buffer, static_cast<int>(allocated), MacroAssembler masm(isolate, CodeObjectRequired::kYes, buffer->CreateView());
CodeObjectRequired::kYes);
#if V8_TARGET_ARCH_IA32 #if V8_TARGET_ARCH_IA32
__ mov(eax, Operand(esp, kPointerSize)); __ mov(eax, Operand(esp, kPointerSize));
for (int i = 0; i < kNumInstr; ++i) { for (int i = 0; i < kNumInstr; ++i) {
...@@ -69,9 +68,8 @@ static void FloodWithInc(Isolate* isolate, byte* buffer, size_t allocated) { ...@@ -69,9 +68,8 @@ static void FloodWithInc(Isolate* isolate, byte* buffer, size_t allocated) {
masm.GetCode(isolate, &desc); masm.GetCode(isolate, &desc);
} }
static void FloodWithNop(Isolate* isolate, byte* buffer, size_t allocated) { static void FloodWithNop(Isolate* isolate, TestingAssemblerBuffer* buffer) {
MacroAssembler masm(isolate, buffer, static_cast<int>(allocated), MacroAssembler masm(isolate, CodeObjectRequired::kYes, buffer->CreateView());
CodeObjectRequired::kYes);
#if V8_TARGET_ARCH_IA32 #if V8_TARGET_ARCH_IA32
__ mov(eax, Operand(esp, kPointerSize)); __ mov(eax, Operand(esp, kPointerSize));
#elif V8_TARGET_ARCH_X64 #elif V8_TARGET_ARCH_X64
...@@ -96,30 +94,27 @@ static void FloodWithNop(Isolate* isolate, byte* buffer, size_t allocated) { ...@@ -96,30 +94,27 @@ static void FloodWithNop(Isolate* isolate, byte* buffer, size_t allocated) {
TEST(TestFlushICacheOfWritable) { TEST(TestFlushICacheOfWritable) {
Isolate* isolate = CcTest::i_isolate(); Isolate* isolate = CcTest::i_isolate();
HandleScope handles(isolate); HandleScope handles(isolate);
size_t allocated;
for (int i = 0; i < kNumIterations; ++i) { for (int i = 0; i < kNumIterations; ++i) {
byte* buffer = AllocateAssemblerBuffer(&allocated, kBufferSize); auto buffer = AllocateAssemblerBuffer(kBufferSize);
// Allow calling the function from C++. // Allow calling the function from C++.
auto f = GeneratedCode<F0>::FromBuffer(isolate, buffer); auto f = GeneratedCode<F0>::FromBuffer(isolate, buffer->start());
CHECK(SetPermissions(GetPlatformPageAllocator(), buffer, allocated, CHECK(SetPermissions(GetPlatformPageAllocator(), buffer->start(),
v8::PageAllocator::kReadWrite)); buffer->size(), v8::PageAllocator::kReadWrite));
FloodWithInc(isolate, buffer, allocated); FloodWithInc(isolate, buffer.get());
Assembler::FlushICache(buffer, allocated); Assembler::FlushICache(buffer->start(), buffer->size());
CHECK(SetPermissions(GetPlatformPageAllocator(), buffer, allocated, CHECK(SetPermissions(GetPlatformPageAllocator(), buffer->start(),
v8::PageAllocator::kReadExecute)); buffer->size(), v8::PageAllocator::kReadExecute));
CHECK_EQ(23 + kNumInstr, f.Call(23)); // Call into generated code. CHECK_EQ(23 + kNumInstr, f.Call(23)); // Call into generated code.
CHECK(SetPermissions(GetPlatformPageAllocator(), buffer, allocated, CHECK(SetPermissions(GetPlatformPageAllocator(), buffer->start(),
v8::PageAllocator::kReadWrite)); buffer->size(), v8::PageAllocator::kReadWrite));
FloodWithNop(isolate, buffer, allocated); FloodWithNop(isolate, buffer.get());
Assembler::FlushICache(buffer, allocated); Assembler::FlushICache(buffer->start(), buffer->size());
CHECK(SetPermissions(GetPlatformPageAllocator(), buffer, allocated, CHECK(SetPermissions(GetPlatformPageAllocator(), buffer->start(),
v8::PageAllocator::kReadExecute)); buffer->size(), v8::PageAllocator::kReadExecute));
CHECK_EQ(23, f.Call(23)); // Call into generated code. CHECK_EQ(23, f.Call(23)); // Call into generated code.
CHECK(FreePages(GetPlatformPageAllocator(), buffer, allocated));
} }
} }
...@@ -144,30 +139,27 @@ TEST(TestFlushICacheOfWritable) { ...@@ -144,30 +139,27 @@ TEST(TestFlushICacheOfWritable) {
CONDITIONAL_TEST(TestFlushICacheOfExecutable) { CONDITIONAL_TEST(TestFlushICacheOfExecutable) {
Isolate* isolate = CcTest::i_isolate(); Isolate* isolate = CcTest::i_isolate();
HandleScope handles(isolate); HandleScope handles(isolate);
size_t allocated;
for (int i = 0; i < kNumIterations; ++i) { for (int i = 0; i < kNumIterations; ++i) {
byte* buffer = AllocateAssemblerBuffer(&allocated, kBufferSize); auto buffer = AllocateAssemblerBuffer(kBufferSize);
// Allow calling the function from C++. // Allow calling the function from C++.
auto f = GeneratedCode<F0>::FromBuffer(isolate, buffer); auto f = GeneratedCode<F0>::FromBuffer(isolate, buffer->start());
CHECK(SetPermissions(GetPlatformPageAllocator(), buffer, allocated, CHECK(SetPermissions(GetPlatformPageAllocator(), buffer->start(),
v8::PageAllocator::kReadWrite)); buffer->size(), v8::PageAllocator::kReadWrite));
FloodWithInc(isolate, buffer, allocated); FloodWithInc(isolate, buffer.get());
CHECK(SetPermissions(GetPlatformPageAllocator(), buffer, allocated, CHECK(SetPermissions(GetPlatformPageAllocator(), buffer->start(),
v8::PageAllocator::kReadExecute)); buffer->size(), v8::PageAllocator::kReadExecute));
Assembler::FlushICache(buffer, allocated); Assembler::FlushICache(buffer->start(), buffer->size());
CHECK_EQ(23 + kNumInstr, f.Call(23)); // Call into generated code. CHECK_EQ(23 + kNumInstr, f.Call(23)); // Call into generated code.
CHECK(SetPermissions(GetPlatformPageAllocator(), buffer, allocated, CHECK(SetPermissions(GetPlatformPageAllocator(), buffer->start(),
v8::PageAllocator::kReadWrite)); buffer->size(), v8::PageAllocator::kReadWrite));
FloodWithNop(isolate, buffer, allocated); FloodWithNop(isolate, buffer.get());
CHECK(SetPermissions(GetPlatformPageAllocator(), buffer, allocated, CHECK(SetPermissions(GetPlatformPageAllocator(), buffer->start(),
v8::PageAllocator::kReadExecute)); buffer->size(), v8::PageAllocator::kReadExecute));
Assembler::FlushICache(buffer, allocated); Assembler::FlushICache(buffer->start(), buffer->size());
CHECK_EQ(23, f.Call(23)); // Call into generated code. CHECK_EQ(23, f.Call(23)); // Call into generated code.
CHECK(FreePages(GetPlatformPageAllocator(), buffer, allocated));
} }
} }
...@@ -178,24 +170,21 @@ CONDITIONAL_TEST(TestFlushICacheOfExecutable) { ...@@ -178,24 +170,21 @@ CONDITIONAL_TEST(TestFlushICacheOfExecutable) {
TEST(TestFlushICacheOfWritableAndExecutable) { TEST(TestFlushICacheOfWritableAndExecutable) {
Isolate* isolate = CcTest::i_isolate(); Isolate* isolate = CcTest::i_isolate();
HandleScope handles(isolate); HandleScope handles(isolate);
size_t allocated;
for (int i = 0; i < kNumIterations; ++i) { for (int i = 0; i < kNumIterations; ++i) {
byte* buffer = AllocateAssemblerBuffer(&allocated, kBufferSize); auto buffer = AllocateAssemblerBuffer(kBufferSize);
// Allow calling the function from C++. // Allow calling the function from C++.
auto f = GeneratedCode<F0>::FromBuffer(isolate, buffer); auto f = GeneratedCode<F0>::FromBuffer(isolate, buffer->start());
CHECK(SetPermissions(GetPlatformPageAllocator(), buffer, allocated, CHECK(SetPermissions(GetPlatformPageAllocator(), buffer->start(),
v8::PageAllocator::kReadWriteExecute)); buffer->size(), v8::PageAllocator::kReadWriteExecute));
FloodWithInc(isolate, buffer, allocated); FloodWithInc(isolate, buffer.get());
Assembler::FlushICache(buffer, allocated); Assembler::FlushICache(buffer->start(), buffer->size());
CHECK_EQ(23 + kNumInstr, f.Call(23)); // Call into generated code. CHECK_EQ(23 + kNumInstr, f.Call(23)); // Call into generated code.
FloodWithNop(isolate, buffer, allocated); FloodWithNop(isolate, buffer.get());
Assembler::FlushICache(buffer, allocated); Assembler::FlushICache(buffer->start(), buffer->size());
CHECK_EQ(23, f.Call(23)); // Call into generated code. CHECK_EQ(23, f.Call(23)); // Call into generated code.
CHECK(FreePages(GetPlatformPageAllocator(), buffer, allocated));
} }
} }
......
...@@ -50,10 +50,9 @@ TEST(LoadAndStoreWithRepresentation) { ...@@ -50,10 +50,9 @@ TEST(LoadAndStoreWithRepresentation) {
Isolate* isolate = CcTest::i_isolate(); Isolate* isolate = CcTest::i_isolate();
HandleScope handles(isolate); HandleScope handles(isolate);
size_t allocated; auto buffer = AllocateAssemblerBuffer();
byte* buffer = AllocateAssemblerBuffer(&allocated); MacroAssembler assembler(isolate, v8::internal::CodeObjectRequired::kYes,
MacroAssembler assembler(isolate, buffer, static_cast<int>(allocated), buffer->CreateView());
v8::internal::CodeObjectRequired::kYes);
MacroAssembler* masm = &assembler; // Create a pointer for the __ macro. MacroAssembler* masm = &assembler; // Create a pointer for the __ macro.
__ sub(sp, sp, Operand(1 * kPointerSize)); __ sub(sp, sp, Operand(1 * kPointerSize));
...@@ -140,10 +139,9 @@ TEST(ExtractLane) { ...@@ -140,10 +139,9 @@ TEST(ExtractLane) {
Isolate* isolate = CcTest::i_isolate(); Isolate* isolate = CcTest::i_isolate();
HandleScope handles(isolate); HandleScope handles(isolate);
size_t allocated; auto buffer = AllocateAssemblerBuffer();
byte* buffer = AllocateAssemblerBuffer(&allocated); MacroAssembler assembler(isolate, v8::internal::CodeObjectRequired::kYes,
MacroAssembler assembler(isolate, buffer, static_cast<int>(allocated), buffer->CreateView());
v8::internal::CodeObjectRequired::kYes);
MacroAssembler* masm = &assembler; // Create a pointer for the __ macro. MacroAssembler* masm = &assembler; // Create a pointer for the __ macro.
typedef struct { typedef struct {
...@@ -280,10 +278,9 @@ TEST(ReplaceLane) { ...@@ -280,10 +278,9 @@ TEST(ReplaceLane) {
Isolate* isolate = CcTest::i_isolate(); Isolate* isolate = CcTest::i_isolate();
HandleScope handles(isolate); HandleScope handles(isolate);
size_t allocated; auto buffer = AllocateAssemblerBuffer();
byte* buffer = AllocateAssemblerBuffer(&allocated); MacroAssembler assembler(isolate, v8::internal::CodeObjectRequired::kYes,
MacroAssembler assembler(isolate, buffer, static_cast<int>(allocated), buffer->CreateView());
v8::internal::CodeObjectRequired::kYes);
MacroAssembler* masm = &assembler; // Create a pointer for the __ macro. MacroAssembler* masm = &assembler; // Create a pointer for the __ macro.
typedef struct { typedef struct {
......
...@@ -101,10 +101,9 @@ static void TestMoveSmi(MacroAssembler* masm, Label* exit, int id, Smi value) { ...@@ -101,10 +101,9 @@ static void TestMoveSmi(MacroAssembler* masm, Label* exit, int id, Smi value) {
TEST(SmiMove) { TEST(SmiMove) {
Isolate* isolate = CcTest::i_isolate(); Isolate* isolate = CcTest::i_isolate();
HandleScope handles(isolate); HandleScope handles(isolate);
size_t allocated; auto buffer = AllocateAssemblerBuffer();
byte* buffer = AllocateAssemblerBuffer(&allocated); MacroAssembler assembler(isolate, v8::internal::CodeObjectRequired::kYes,
MacroAssembler assembler(isolate, buffer, static_cast<int>(allocated), buffer->CreateView());
v8::internal::CodeObjectRequired::kYes);
MacroAssembler* masm = &assembler; // Create a pointer for the __ macro. MacroAssembler* masm = &assembler; // Create a pointer for the __ macro.
EntryCode(masm); EntryCode(masm);
Label exit; Label exit;
...@@ -129,9 +128,9 @@ TEST(SmiMove) { ...@@ -129,9 +128,9 @@ TEST(SmiMove) {
CodeDesc desc; CodeDesc desc;
masm->GetCode(isolate, &desc); masm->GetCode(isolate, &desc);
MakeAssemblerBufferExecutable(buffer, allocated); buffer->MakeExecutable();
// Call the function from C++. // Call the function from C++.
auto f = GeneratedCode<F0>::FromBuffer(CcTest::i_isolate(), buffer); auto f = GeneratedCode<F0>::FromBuffer(CcTest::i_isolate(), buffer->start());
int result = f.Call(); int result = f.Call();
CHECK_EQ(0, result); CHECK_EQ(0, result);
} }
...@@ -186,11 +185,9 @@ void TestSmiCompare(MacroAssembler* masm, Label* exit, int id, int x, int y) { ...@@ -186,11 +185,9 @@ void TestSmiCompare(MacroAssembler* masm, Label* exit, int id, int x, int y) {
TEST(SmiCompare) { TEST(SmiCompare) {
Isolate* isolate = CcTest::i_isolate(); Isolate* isolate = CcTest::i_isolate();
HandleScope handles(isolate); HandleScope handles(isolate);
size_t allocated; auto buffer = AllocateAssemblerBuffer(2 * Assembler::kMinimalBufferSize);
byte* buffer = MacroAssembler assembler(isolate, v8::internal::CodeObjectRequired::kYes,
AllocateAssemblerBuffer(&allocated, 2 * Assembler::kMinimalBufferSize); buffer->CreateView());
MacroAssembler assembler(isolate, buffer, static_cast<int>(allocated),
v8::internal::CodeObjectRequired::kYes);
MacroAssembler* masm = &assembler; MacroAssembler* masm = &assembler;
EntryCode(masm); EntryCode(masm);
...@@ -223,9 +220,9 @@ TEST(SmiCompare) { ...@@ -223,9 +220,9 @@ TEST(SmiCompare) {
CodeDesc desc; CodeDesc desc;
masm->GetCode(isolate, &desc); masm->GetCode(isolate, &desc);
MakeAssemblerBufferExecutable(buffer, allocated); buffer->MakeExecutable();
// Call the function from C++. // Call the function from C++.
auto f = GeneratedCode<F0>::FromBuffer(CcTest::i_isolate(), buffer); auto f = GeneratedCode<F0>::FromBuffer(CcTest::i_isolate(), buffer->start());
int result = f.Call(); int result = f.Call();
CHECK_EQ(0, result); CHECK_EQ(0, result);
} }
...@@ -233,10 +230,9 @@ TEST(SmiCompare) { ...@@ -233,10 +230,9 @@ TEST(SmiCompare) {
TEST(SmiTag) { TEST(SmiTag) {
Isolate* isolate = CcTest::i_isolate(); Isolate* isolate = CcTest::i_isolate();
HandleScope handles(isolate); HandleScope handles(isolate);
size_t allocated; auto buffer = AllocateAssemblerBuffer();
byte* buffer = AllocateAssemblerBuffer(&allocated); MacroAssembler assembler(isolate, v8::internal::CodeObjectRequired::kYes,
MacroAssembler assembler(isolate, buffer, static_cast<int>(allocated), buffer->CreateView());
v8::internal::CodeObjectRequired::kYes);
MacroAssembler* masm = &assembler; MacroAssembler* masm = &assembler;
EntryCode(masm); EntryCode(masm);
...@@ -322,9 +318,9 @@ TEST(SmiTag) { ...@@ -322,9 +318,9 @@ TEST(SmiTag) {
CodeDesc desc; CodeDesc desc;
masm->GetCode(isolate, &desc); masm->GetCode(isolate, &desc);
MakeAssemblerBufferExecutable(buffer, allocated); buffer->MakeExecutable();
// Call the function from C++. // Call the function from C++.
auto f = GeneratedCode<F0>::FromBuffer(CcTest::i_isolate(), buffer); auto f = GeneratedCode<F0>::FromBuffer(CcTest::i_isolate(), buffer->start());
int result = f.Call(); int result = f.Call();
CHECK_EQ(0, result); CHECK_EQ(0, result);
} }
...@@ -332,10 +328,9 @@ TEST(SmiTag) { ...@@ -332,10 +328,9 @@ TEST(SmiTag) {
TEST(SmiCheck) { TEST(SmiCheck) {
Isolate* isolate = CcTest::i_isolate(); Isolate* isolate = CcTest::i_isolate();
HandleScope handles(isolate); HandleScope handles(isolate);
size_t allocated; auto buffer = AllocateAssemblerBuffer();
byte* buffer = AllocateAssemblerBuffer(&allocated); MacroAssembler assembler(isolate, v8::internal::CodeObjectRequired::kYes,
MacroAssembler assembler(isolate, buffer, static_cast<int>(allocated), buffer->CreateView());
v8::internal::CodeObjectRequired::kYes);
MacroAssembler* masm = &assembler; MacroAssembler* masm = &assembler;
EntryCode(masm); EntryCode(masm);
...@@ -398,9 +393,9 @@ TEST(SmiCheck) { ...@@ -398,9 +393,9 @@ TEST(SmiCheck) {
CodeDesc desc; CodeDesc desc;
masm->GetCode(isolate, &desc); masm->GetCode(isolate, &desc);
MakeAssemblerBufferExecutable(buffer, allocated); buffer->MakeExecutable();
// Call the function from C++. // Call the function from C++.
auto f = GeneratedCode<F0>::FromBuffer(CcTest::i_isolate(), buffer); auto f = GeneratedCode<F0>::FromBuffer(CcTest::i_isolate(), buffer->start());
int result = f.Call(); int result = f.Call();
CHECK_EQ(0, result); CHECK_EQ(0, result);
} }
...@@ -431,10 +426,9 @@ void TestSmiIndex(MacroAssembler* masm, Label* exit, int id, int x) { ...@@ -431,10 +426,9 @@ void TestSmiIndex(MacroAssembler* masm, Label* exit, int id, int x) {
TEST(SmiIndex) { TEST(SmiIndex) {
Isolate* isolate = CcTest::i_isolate(); Isolate* isolate = CcTest::i_isolate();
HandleScope handles(isolate); HandleScope handles(isolate);
size_t allocated; auto buffer = AllocateAssemblerBuffer();
byte* buffer = AllocateAssemblerBuffer(&allocated); MacroAssembler assembler(isolate, v8::internal::CodeObjectRequired::kYes,
MacroAssembler assembler(isolate, buffer, static_cast<int>(allocated), buffer->CreateView());
v8::internal::CodeObjectRequired::kYes);
MacroAssembler* masm = &assembler; MacroAssembler* masm = &assembler;
EntryCode(masm); EntryCode(masm);
...@@ -453,9 +447,9 @@ TEST(SmiIndex) { ...@@ -453,9 +447,9 @@ TEST(SmiIndex) {
CodeDesc desc; CodeDesc desc;
masm->GetCode(isolate, &desc); masm->GetCode(isolate, &desc);
MakeAssemblerBufferExecutable(buffer, allocated); buffer->MakeExecutable();
// Call the function from C++. // Call the function from C++.
auto f = GeneratedCode<F0>::FromBuffer(CcTest::i_isolate(), buffer); auto f = GeneratedCode<F0>::FromBuffer(CcTest::i_isolate(), buffer->start());
int result = f.Call(); int result = f.Call();
CHECK_EQ(0, result); CHECK_EQ(0, result);
} }
...@@ -466,10 +460,9 @@ TEST(OperandOffset) { ...@@ -466,10 +460,9 @@ TEST(OperandOffset) {
Isolate* isolate = CcTest::i_isolate(); Isolate* isolate = CcTest::i_isolate();
HandleScope handles(isolate); HandleScope handles(isolate);
size_t allocated; auto buffer = AllocateAssemblerBuffer();
byte* buffer = AllocateAssemblerBuffer(&allocated); MacroAssembler assembler(isolate, v8::internal::CodeObjectRequired::kYes,
MacroAssembler assembler(isolate, buffer, static_cast<int>(allocated), buffer->CreateView());
v8::internal::CodeObjectRequired::kYes);
MacroAssembler* masm = &assembler; MacroAssembler* masm = &assembler;
Label exit; Label exit;
...@@ -807,9 +800,9 @@ TEST(OperandOffset) { ...@@ -807,9 +800,9 @@ TEST(OperandOffset) {
CodeDesc desc; CodeDesc desc;
masm->GetCode(isolate, &desc); masm->GetCode(isolate, &desc);
MakeAssemblerBufferExecutable(buffer, allocated); buffer->MakeExecutable();
// Call the function from C++. // Call the function from C++.
auto f = GeneratedCode<F0>::FromBuffer(CcTest::i_isolate(), buffer); auto f = GeneratedCode<F0>::FromBuffer(CcTest::i_isolate(), buffer->start());
int result = f.Call(); int result = f.Call();
CHECK_EQ(0, result); CHECK_EQ(0, result);
} }
...@@ -818,10 +811,9 @@ TEST(OperandOffset) { ...@@ -818,10 +811,9 @@ TEST(OperandOffset) {
TEST(LoadAndStoreWithRepresentation) { TEST(LoadAndStoreWithRepresentation) {
Isolate* isolate = CcTest::i_isolate(); Isolate* isolate = CcTest::i_isolate();
HandleScope handles(isolate); HandleScope handles(isolate);
size_t allocated; auto buffer = AllocateAssemblerBuffer();
byte* buffer = AllocateAssemblerBuffer(&allocated); MacroAssembler assembler(isolate, v8::internal::CodeObjectRequired::kYes,
MacroAssembler assembler(isolate, buffer, static_cast<int>(allocated), buffer->CreateView());
v8::internal::CodeObjectRequired::kYes);
MacroAssembler* masm = &assembler; // Create a pointer for the __ macro. MacroAssembler* masm = &assembler; // Create a pointer for the __ macro.
EntryCode(masm); EntryCode(masm);
...@@ -969,9 +961,9 @@ TEST(LoadAndStoreWithRepresentation) { ...@@ -969,9 +961,9 @@ TEST(LoadAndStoreWithRepresentation) {
CodeDesc desc; CodeDesc desc;
masm->GetCode(isolate, &desc); masm->GetCode(isolate, &desc);
MakeAssemblerBufferExecutable(buffer, allocated); buffer->MakeExecutable();
// Call the function from C++. // Call the function from C++.
auto f = GeneratedCode<F0>::FromBuffer(CcTest::i_isolate(), buffer); auto f = GeneratedCode<F0>::FromBuffer(CcTest::i_isolate(), buffer->start());
int result = f.Call(); int result = f.Call();
CHECK_EQ(0, result); CHECK_EQ(0, result);
} }
...@@ -1101,10 +1093,9 @@ void TestFloat64x2Neg(MacroAssembler* masm, Label* exit, double x, double y) { ...@@ -1101,10 +1093,9 @@ void TestFloat64x2Neg(MacroAssembler* masm, Label* exit, double x, double y) {
TEST(SIMDMacros) { TEST(SIMDMacros) {
Isolate* isolate = CcTest::i_isolate(); Isolate* isolate = CcTest::i_isolate();
HandleScope handles(isolate); HandleScope handles(isolate);
size_t allocated; auto buffer = AllocateAssemblerBuffer();
byte* buffer = AllocateAssemblerBuffer(&allocated); MacroAssembler assembler(isolate, v8::internal::CodeObjectRequired::kYes,
MacroAssembler assembler(isolate, buffer, static_cast<int>(allocated), buffer->CreateView());
v8::internal::CodeObjectRequired::kYes);
MacroAssembler* masm = &assembler; MacroAssembler* masm = &assembler;
EntryCode(masm); EntryCode(masm);
...@@ -1123,9 +1114,9 @@ TEST(SIMDMacros) { ...@@ -1123,9 +1114,9 @@ TEST(SIMDMacros) {
CodeDesc desc; CodeDesc desc;
masm->GetCode(isolate, &desc); masm->GetCode(isolate, &desc);
MakeAssemblerBufferExecutable(buffer, allocated); buffer->MakeExecutable();
// Call the function from C++. // Call the function from C++.
auto f = GeneratedCode<F0>::FromBuffer(CcTest::i_isolate(), buffer); auto f = GeneratedCode<F0>::FromBuffer(CcTest::i_isolate(), buffer->start());
int result = f.Call(); int result = f.Call();
CHECK_EQ(0, result); CHECK_EQ(0, result);
} }
......
...@@ -45,9 +45,10 @@ constexpr uint32_t kBufferSlotStartOffset = ...@@ -45,9 +45,10 @@ constexpr uint32_t kBufferSlotStartOffset =
constexpr uint32_t kAvailableBufferSlots = 0; constexpr uint32_t kAvailableBufferSlots = 0;
#endif #endif
Address GenerateJumpTableThunk(Address jump_target, byte* thunk_slot_buffer, Address GenerateJumpTableThunk(
std::bitset<kAvailableBufferSlots>* used_slots) { Address jump_target, byte* thunk_slot_buffer,
size_t allocated; std::bitset<kAvailableBufferSlots>* used_slots,
std::vector<std::unique_ptr<TestingAssemblerBuffer>>* thunk_buffers) {
#if V8_TARGET_ARCH_ARM64 #if V8_TARGET_ARCH_ARM64
// To guarantee that the branch range lies within the near-call range, // To guarantee that the branch range lies within the near-call range,
// generate the thunk in the same (kMaxWasmCodeMemory-sized) buffer as the // generate the thunk in the same (kMaxWasmCodeMemory-sized) buffer as the
...@@ -71,15 +72,17 @@ Address GenerateJumpTableThunk(Address jump_target, byte* thunk_slot_buffer, ...@@ -71,15 +72,17 @@ Address GenerateJumpTableThunk(Address jump_target, byte* thunk_slot_buffer,
DCHECK(TurboAssembler::IsNearCallOffset( DCHECK(TurboAssembler::IsNearCallOffset(
(reinterpret_cast<byte*>(jump_target) - buffer) / kInstrSize)); (reinterpret_cast<byte*>(jump_target) - buffer) / kInstrSize));
allocated = AssemblerBase::kMinimalBufferSize;
#else #else
USE(thunk_slot_buffer); USE(thunk_slot_buffer);
USE(used_slots); USE(used_slots);
byte* buffer = AllocateAssemblerBuffer( thunk_buffers->emplace_back(AllocateAssemblerBuffer(
&allocated, AssemblerBase::kMinimalBufferSize, GetRandomMmapAddr()); AssemblerBase::kMinimalBufferSize, GetRandomMmapAddr()));
byte* buffer = thunk_buffers->back()->start();
#endif #endif
MacroAssembler masm(nullptr, AssemblerOptions{}, buffer,
static_cast<int>(allocated), CodeObjectRequired::kNo); MacroAssembler masm(
nullptr, AssemblerOptions{}, CodeObjectRequired::kNo,
ExternalAssemblerBuffer(buffer, AssemblerBase::kMinimalBufferSize));
Label exit; Label exit;
Register scratch = kReturnRegister0; Register scratch = kReturnRegister0;
...@@ -114,7 +117,6 @@ Address GenerateJumpTableThunk(Address jump_target, byte* thunk_slot_buffer, ...@@ -114,7 +117,6 @@ Address GenerateJumpTableThunk(Address jump_target, byte* thunk_slot_buffer,
CodeDesc desc; CodeDesc desc;
masm.GetCode(nullptr, &desc); masm.GetCode(nullptr, &desc);
MakeAssemblerBufferExecutable(buffer, allocated);
return reinterpret_cast<Address>(buffer); return reinterpret_cast<Address>(buffer);
} }
...@@ -180,7 +182,6 @@ class JumpTablePatcher : public v8::base::Thread { ...@@ -180,7 +182,6 @@ class JumpTablePatcher : public v8::base::Thread {
TEST(JumpTablePatchingStress) { TEST(JumpTablePatchingStress) {
constexpr int kNumberOfRunnerThreads = 5; constexpr int kNumberOfRunnerThreads = 5;
size_t allocated;
#if V8_TARGET_ARCH_ARM64 #if V8_TARGET_ARCH_ARM64
// We need the branches (from GenerateJumpTableThunk) to be within near-call // We need the branches (from GenerateJumpTableThunk) to be within near-call
// range of the jump table slots. The address hint to AllocateAssemblerBuffer // range of the jump table slots. The address hint to AllocateAssemblerBuffer
...@@ -191,30 +192,34 @@ TEST(JumpTablePatchingStress) { ...@@ -191,30 +192,34 @@ TEST(JumpTablePatchingStress) {
// TODO(wasm): Currently {kMaxWasmCodeMemory} limits code sufficiently, so // TODO(wasm): Currently {kMaxWasmCodeMemory} limits code sufficiently, so
// that the jump table only supports {near_call} distances. // that the jump table only supports {near_call} distances.
STATIC_ASSERT(kMaxWasmCodeMemory >= kJumpTableSize); STATIC_ASSERT(kMaxWasmCodeMemory >= kJumpTableSize);
byte* buffer = AllocateAssemblerBuffer(&allocated, kMaxWasmCodeMemory); auto buffer = AllocateAssemblerBuffer(kMaxWasmCodeMemory);
byte* thunk_slot_buffer = buffer + kBufferSlotStartOffset; byte* thunk_slot_buffer = buffer->start() + kBufferSlotStartOffset;
#else #else
byte* buffer = AllocateAssemblerBuffer(&allocated, kJumpTableSize); auto buffer = AllocateAssemblerBuffer(kJumpTableSize);
byte* thunk_slot_buffer = nullptr; byte* thunk_slot_buffer = nullptr;
#endif #endif
std::bitset<kAvailableBufferSlots> used_thunk_slots; std::bitset<kAvailableBufferSlots> used_thunk_slots;
MakeAssemblerBufferWritableAndExecutable(buffer, allocated); buffer->MakeWritableAndExecutable();
// Iterate through jump-table slots to hammer at different alignments within // Iterate through jump-table slots to hammer at different alignments within
// the jump-table, thereby increasing stress for variable-length ISAs. // the jump-table, thereby increasing stress for variable-length ISAs.
Address slot_start = reinterpret_cast<Address>(buffer); Address slot_start = reinterpret_cast<Address>(buffer->start());
for (int slot = 0; slot < kJumpTableSlotCount; ++slot) { for (int slot = 0; slot < kJumpTableSlotCount; ++slot) {
TRACE("Hammering on jump table slot #%d ...\n", slot); TRACE("Hammering on jump table slot #%d ...\n", slot);
uint32_t slot_offset = JumpTableAssembler::SlotIndexToOffset(slot); uint32_t slot_offset = JumpTableAssembler::SlotIndexToOffset(slot);
Address thunk1 = GenerateJumpTableThunk( std::vector<std::unique_ptr<TestingAssemblerBuffer>> thunk_buffers;
slot_start + slot_offset, thunk_slot_buffer, &used_thunk_slots); Address thunk1 =
Address thunk2 = GenerateJumpTableThunk( GenerateJumpTableThunk(slot_start + slot_offset, thunk_slot_buffer,
slot_start + slot_offset, thunk_slot_buffer, &used_thunk_slots); &used_thunk_slots, &thunk_buffers);
Address thunk2 =
GenerateJumpTableThunk(slot_start + slot_offset, thunk_slot_buffer,
&used_thunk_slots, &thunk_buffers);
TRACE(" generated thunk1: " V8PRIxPTR_FMT "\n", thunk1); TRACE(" generated thunk1: " V8PRIxPTR_FMT "\n", thunk1);
TRACE(" generated thunk2: " V8PRIxPTR_FMT "\n", thunk2); TRACE(" generated thunk2: " V8PRIxPTR_FMT "\n", thunk2);
JumpTableAssembler::PatchJumpTableSlot(slot_start, slot, thunk1, JumpTableAssembler::PatchJumpTableSlot(slot_start, slot, thunk1,
WasmCode::kFlushICache); WasmCode::kFlushICache);
for (auto& buf : thunk_buffers) buf->MakeExecutable();
// Start multiple runner threads and a patcher thread that hammer on the // Start multiple runner threads and a patcher thread that hammer on the
// same jump-table slot concurrently. // same jump-table slot concurrently.
std::list<JumpTableRunner> runners; std::list<JumpTableRunner> runners;
......
...@@ -10,50 +10,70 @@ ...@@ -10,50 +10,70 @@
namespace v8 { namespace v8 {
namespace internal { namespace internal {
static inline uint8_t* AllocateAssemblerBuffer( class TestingAssemblerBuffer : public AssemblerBuffer {
size_t* allocated, public:
size_t requested = v8::internal::AssemblerBase::kMinimalBufferSize, TestingAssemblerBuffer(size_t requested, void* address) {
void* address = nullptr) { size_t page_size = v8::internal::AllocatePageSize();
size_t page_size = v8::internal::AllocatePageSize(); size_t alloc_size = RoundUp(requested, page_size);
size_t alloc_size = RoundUp(requested, page_size); CHECK_GE(kMaxInt, alloc_size);
void* result = AllocatePages(GetPlatformPageAllocator(), address, alloc_size, size_ = static_cast<int>(alloc_size);
page_size, v8::PageAllocator::kReadWrite); buffer_ = static_cast<byte*>(AllocatePages(GetPlatformPageAllocator(),
CHECK(result); address, alloc_size, page_size,
*allocated = alloc_size; v8::PageAllocator::kReadWrite));
return static_cast<uint8_t*>(result); CHECK_NOT_NULL(buffer_);
} }
static inline void FreeAssemblerBuffer(uint8_t* buffer, size_t size) { ~TestingAssemblerBuffer() {
CHECK(FreePages(GetPlatformPageAllocator(), buffer, size)); CHECK(FreePages(GetPlatformPageAllocator(), buffer_, size_));
} }
static inline void MakeAssemblerBufferExecutable(uint8_t* buffer, byte* start() const override { return buffer_; }
size_t allocated) {
// Flush the instruction cache as part of making the buffer executable.
// Note: we do this before setting permissions to ReadExecute because on
// some older ARM kernels there is a bug which causes an access error on
// cache flush instructions to trigger access error on non-writable memory.
// See https://bugs.chromium.org/p/v8/issues/detail?id=8157
Assembler::FlushICache(buffer, allocated);
bool result = SetPermissions(GetPlatformPageAllocator(), buffer, allocated,
v8::PageAllocator::kReadExecute);
CHECK(result);
}
static inline void MakeAssemblerBufferWritable(uint8_t* buffer, int size() const override { return size_; }
size_t allocated) {
bool result = SetPermissions(GetPlatformPageAllocator(), buffer, allocated, std::unique_ptr<AssemblerBuffer> Grow(int new_size) override {
v8::PageAllocator::kReadWrite); FATAL("Cannot grow TestingAssemblerBuffer");
CHECK(result); }
}
std::unique_ptr<AssemblerBuffer> CreateView() const {
return ExternalAssemblerBuffer(buffer_, size_);
}
// TODO(wasm): Only needed for the "test-jump-table-assembler.cc" tests. void MakeExecutable() {
static inline void MakeAssemblerBufferWritableAndExecutable(uint8_t* buffer, // Flush the instruction cache as part of making the buffer executable.
size_t allocated) { // Note: we do this before setting permissions to ReadExecute because on
bool result = SetPermissions(GetPlatformPageAllocator(), buffer, allocated, // some older ARM kernels there is a bug which causes an access error on
v8::PageAllocator::kReadWriteExecute); // cache flush instructions to trigger access error on non-writable memory.
CHECK(result); // See https://bugs.chromium.org/p/v8/issues/detail?id=8157
Assembler::FlushICache(buffer_, size_);
bool result = SetPermissions(GetPlatformPageAllocator(), buffer_, size_,
v8::PageAllocator::kReadExecute);
CHECK(result);
}
void MakeWritable() {
bool result = SetPermissions(GetPlatformPageAllocator(), buffer_, size_,
v8::PageAllocator::kReadWrite);
CHECK(result);
}
// TODO(wasm): Only needed for the "test-jump-table-assembler.cc" tests.
void MakeWritableAndExecutable() {
bool result = SetPermissions(GetPlatformPageAllocator(), buffer_, size_,
v8::PageAllocator::kReadWriteExecute);
CHECK(result);
}
private:
byte* buffer_;
int size_;
};
static inline std::unique_ptr<TestingAssemblerBuffer> AllocateAssemblerBuffer(
size_t requested = v8::internal::AssemblerBase::kMinimalBufferSize,
void* address = nullptr) {
return base::make_unique<TestingAssemblerBuffer>(requested, address);
} }
} // namespace internal } // namespace internal
......
...@@ -30,28 +30,26 @@ namespace internal { ...@@ -30,28 +30,26 @@ namespace internal {
class TurboAssemblerTest : public TestWithIsolate {}; class TurboAssemblerTest : public TestWithIsolate {};
TEST_F(TurboAssemblerTest, TestHardAbort) { TEST_F(TurboAssemblerTest, TestHardAbort) {
size_t allocated; auto buffer = AllocateAssemblerBuffer();
byte* buffer = AllocateAssemblerBuffer(&allocated); TurboAssembler tasm(nullptr, AssemblerOptions{}, CodeObjectRequired::kNo,
TurboAssembler tasm(nullptr, AssemblerOptions{}, buffer, buffer->CreateView());
static_cast<int>(allocated), CodeObjectRequired::kNo);
__ set_abort_hard(true); __ set_abort_hard(true);
__ Abort(AbortReason::kNoReason); __ Abort(AbortReason::kNoReason);
CodeDesc desc; CodeDesc desc;
tasm.GetCode(nullptr, &desc); tasm.GetCode(nullptr, &desc);
MakeAssemblerBufferExecutable(buffer, allocated); buffer->MakeExecutable();
// We need an isolate here to execute in the simulator. // We need an isolate here to execute in the simulator.
auto f = GeneratedCode<void>::FromBuffer(isolate(), buffer); auto f = GeneratedCode<void>::FromBuffer(isolate(), buffer->start());
ASSERT_DEATH_IF_SUPPORTED({ f.Call(); }, ERROR_MESSAGE("abort: no reason")); ASSERT_DEATH_IF_SUPPORTED({ f.Call(); }, ERROR_MESSAGE("abort: no reason"));
} }
TEST_F(TurboAssemblerTest, TestCheck) { TEST_F(TurboAssemblerTest, TestCheck) {
size_t allocated; auto buffer = AllocateAssemblerBuffer();
byte* buffer = AllocateAssemblerBuffer(&allocated); TurboAssembler tasm(nullptr, AssemblerOptions{}, CodeObjectRequired::kNo,
TurboAssembler tasm(nullptr, AssemblerOptions{}, buffer, buffer->CreateView());
static_cast<int>(allocated), CodeObjectRequired::kNo);
__ set_abort_hard(true); __ set_abort_hard(true);
// Fail if the first parameter is 17. // Fail if the first parameter is 17.
...@@ -62,9 +60,9 @@ TEST_F(TurboAssemblerTest, TestCheck) { ...@@ -62,9 +60,9 @@ TEST_F(TurboAssemblerTest, TestCheck) {
CodeDesc desc; CodeDesc desc;
tasm.GetCode(nullptr, &desc); tasm.GetCode(nullptr, &desc);
MakeAssemblerBufferExecutable(buffer, allocated); buffer->MakeExecutable();
// We need an isolate here to execute in the simulator. // We need an isolate here to execute in the simulator.
auto f = GeneratedCode<void, int>::FromBuffer(isolate(), buffer); auto f = GeneratedCode<void, int>::FromBuffer(isolate(), buffer->start());
f.Call(0); f.Call(0);
f.Call(18); f.Call(18);
......
...@@ -30,28 +30,26 @@ namespace internal { ...@@ -30,28 +30,26 @@ namespace internal {
class TurboAssemblerTest : public TestWithIsolate {}; class TurboAssemblerTest : public TestWithIsolate {};
TEST_F(TurboAssemblerTest, TestHardAbort) { TEST_F(TurboAssemblerTest, TestHardAbort) {
size_t allocated; auto buffer = AllocateAssemblerBuffer();
byte* buffer = AllocateAssemblerBuffer(&allocated); TurboAssembler tasm(nullptr, AssemblerOptions{}, CodeObjectRequired::kNo,
TurboAssembler tasm(nullptr, AssemblerOptions{}, buffer, buffer->CreateView());
static_cast<int>(allocated), CodeObjectRequired::kNo);
__ set_abort_hard(true); __ set_abort_hard(true);
__ Abort(AbortReason::kNoReason); __ Abort(AbortReason::kNoReason);
CodeDesc desc; CodeDesc desc;
tasm.GetCode(nullptr, &desc); tasm.GetCode(nullptr, &desc);
MakeAssemblerBufferExecutable(buffer, allocated); buffer->MakeExecutable();
// We need an isolate here to execute in the simulator. // We need an isolate here to execute in the simulator.
auto f = GeneratedCode<void>::FromBuffer(isolate(), buffer); auto f = GeneratedCode<void>::FromBuffer(isolate(), buffer->start());
ASSERT_DEATH_IF_SUPPORTED({ f.Call(); }, ERROR_MESSAGE("abort: no reason")); ASSERT_DEATH_IF_SUPPORTED({ f.Call(); }, ERROR_MESSAGE("abort: no reason"));
} }
TEST_F(TurboAssemblerTest, TestCheck) { TEST_F(TurboAssemblerTest, TestCheck) {
size_t allocated; auto buffer = AllocateAssemblerBuffer();
byte* buffer = AllocateAssemblerBuffer(&allocated); TurboAssembler tasm(nullptr, AssemblerOptions{}, CodeObjectRequired::kNo,
TurboAssembler tasm(nullptr, AssemblerOptions{}, buffer, buffer->CreateView());
static_cast<int>(allocated), CodeObjectRequired::kNo);
__ set_abort_hard(true); __ set_abort_hard(true);
// Fail if the first parameter is 17. // Fail if the first parameter is 17.
...@@ -62,9 +60,9 @@ TEST_F(TurboAssemblerTest, TestCheck) { ...@@ -62,9 +60,9 @@ TEST_F(TurboAssemblerTest, TestCheck) {
CodeDesc desc; CodeDesc desc;
tasm.GetCode(nullptr, &desc); tasm.GetCode(nullptr, &desc);
MakeAssemblerBufferExecutable(buffer, allocated); buffer->MakeExecutable();
// We need an isolate here to execute in the simulator. // We need an isolate here to execute in the simulator.
auto f = GeneratedCode<void, int>::FromBuffer(isolate(), buffer); auto f = GeneratedCode<void, int>::FromBuffer(isolate(), buffer->start());
f.Call(0); f.Call(0);
f.Call(18); f.Call(18);
......
...@@ -17,27 +17,25 @@ namespace internal { ...@@ -17,27 +17,25 @@ namespace internal {
// V8 library, create a context, or use any V8 objects. // V8 library, create a context, or use any V8 objects.
TEST(TurboAssemblerTest, TestHardAbort) { TEST(TurboAssemblerTest, TestHardAbort) {
size_t allocated; auto buffer = AllocateAssemblerBuffer();
byte* buffer = AllocateAssemblerBuffer(&allocated); TurboAssembler tasm(nullptr, AssemblerOptions{}, CodeObjectRequired::kNo,
TurboAssembler tasm(nullptr, AssemblerOptions{}, buffer, buffer->CreateView());
static_cast<int>(allocated), CodeObjectRequired::kNo);
__ set_abort_hard(true); __ set_abort_hard(true);
__ Abort(AbortReason::kNoReason); __ Abort(AbortReason::kNoReason);
CodeDesc desc; CodeDesc desc;
tasm.GetCode(nullptr, &desc); tasm.GetCode(nullptr, &desc);
MakeAssemblerBufferExecutable(buffer, allocated); buffer->MakeExecutable();
auto f = GeneratedCode<void>::FromBuffer(nullptr, buffer); auto f = GeneratedCode<void>::FromBuffer(nullptr, buffer->start());
ASSERT_DEATH_IF_SUPPORTED({ f.Call(); }, "abort: no reason"); ASSERT_DEATH_IF_SUPPORTED({ f.Call(); }, "abort: no reason");
} }
TEST(TurboAssemblerTest, TestCheck) { TEST(TurboAssemblerTest, TestCheck) {
size_t allocated; auto buffer = AllocateAssemblerBuffer();
byte* buffer = AllocateAssemblerBuffer(&allocated); TurboAssembler tasm(nullptr, AssemblerOptions{}, CodeObjectRequired::kNo,
TurboAssembler tasm(nullptr, AssemblerOptions{}, buffer, buffer->CreateView());
static_cast<int>(allocated), CodeObjectRequired::kNo);
__ set_abort_hard(true); __ set_abort_hard(true);
// Fail if the first parameter is 17. // Fail if the first parameter is 17.
...@@ -48,8 +46,8 @@ TEST(TurboAssemblerTest, TestCheck) { ...@@ -48,8 +46,8 @@ TEST(TurboAssemblerTest, TestCheck) {
CodeDesc desc; CodeDesc desc;
tasm.GetCode(nullptr, &desc); tasm.GetCode(nullptr, &desc);
MakeAssemblerBufferExecutable(buffer, allocated); buffer->MakeExecutable();
auto f = GeneratedCode<void, int>::FromBuffer(nullptr, buffer); auto f = GeneratedCode<void, int>::FromBuffer(nullptr, buffer->start());
f.Call(0); f.Call(0);
f.Call(18); f.Call(18);
......
...@@ -21,28 +21,26 @@ namespace internal { ...@@ -21,28 +21,26 @@ namespace internal {
class TurboAssemblerTest : public TestWithIsolate {}; class TurboAssemblerTest : public TestWithIsolate {};
TEST_F(TurboAssemblerTest, TestHardAbort) { TEST_F(TurboAssemblerTest, TestHardAbort) {
size_t allocated; auto buffer = AllocateAssemblerBuffer();
byte* buffer = AllocateAssemblerBuffer(&allocated); TurboAssembler tasm(nullptr, AssemblerOptions{}, CodeObjectRequired::kNo,
TurboAssembler tasm(nullptr, AssemblerOptions{}, buffer, buffer->CreateView());
static_cast<int>(allocated), CodeObjectRequired::kNo);
__ set_abort_hard(true); __ set_abort_hard(true);
__ Abort(AbortReason::kNoReason); __ Abort(AbortReason::kNoReason);
CodeDesc desc; CodeDesc desc;
tasm.GetCode(nullptr, &desc); tasm.GetCode(nullptr, &desc);
MakeAssemblerBufferExecutable(buffer, allocated); buffer->MakeExecutable();
// We need an isolate here to execute in the simulator. // We need an isolate here to execute in the simulator.
auto f = GeneratedCode<void>::FromBuffer(isolate(), buffer); auto f = GeneratedCode<void>::FromBuffer(isolate(), buffer->start());
ASSERT_DEATH_IF_SUPPORTED({ f.Call(); }, "abort: no reason"); ASSERT_DEATH_IF_SUPPORTED({ f.Call(); }, "abort: no reason");
} }
TEST_F(TurboAssemblerTest, TestCheck) { TEST_F(TurboAssemblerTest, TestCheck) {
size_t allocated; auto buffer = AllocateAssemblerBuffer();
byte* buffer = AllocateAssemblerBuffer(&allocated); TurboAssembler tasm(nullptr, AssemblerOptions{}, CodeObjectRequired::kNo,
TurboAssembler tasm(nullptr, AssemblerOptions{}, buffer, buffer->CreateView());
static_cast<int>(allocated), CodeObjectRequired::kNo);
__ set_abort_hard(true); __ set_abort_hard(true);
// Fail if the first parameter (in {a0}) is 17. // Fail if the first parameter (in {a0}) is 17.
...@@ -51,9 +49,9 @@ TEST_F(TurboAssemblerTest, TestCheck) { ...@@ -51,9 +49,9 @@ TEST_F(TurboAssemblerTest, TestCheck) {
CodeDesc desc; CodeDesc desc;
tasm.GetCode(nullptr, &desc); tasm.GetCode(nullptr, &desc);
MakeAssemblerBufferExecutable(buffer, allocated); buffer->MakeExecutable();
// We need an isolate here to execute in the simulator. // We need an isolate here to execute in the simulator.
auto f = GeneratedCode<void, int>::FromBuffer(isolate(), buffer); auto f = GeneratedCode<void, int>::FromBuffer(isolate(), buffer->start());
f.Call(0); f.Call(0);
f.Call(18); f.Call(18);
......
...@@ -21,28 +21,26 @@ namespace internal { ...@@ -21,28 +21,26 @@ namespace internal {
class TurboAssemblerTest : public TestWithIsolate {}; class TurboAssemblerTest : public TestWithIsolate {};
TEST_F(TurboAssemblerTest, TestHardAbort) { TEST_F(TurboAssemblerTest, TestHardAbort) {
size_t allocated; auto buffer = AllocateAssemblerBuffer();
byte* buffer = AllocateAssemblerBuffer(&allocated); TurboAssembler tasm(nullptr, AssemblerOptions{}, CodeObjectRequired::kNo,
TurboAssembler tasm(nullptr, AssemblerOptions{}, buffer, buffer->CreateView());
static_cast<int>(allocated), CodeObjectRequired::kNo);
__ set_abort_hard(true); __ set_abort_hard(true);
__ Abort(AbortReason::kNoReason); __ Abort(AbortReason::kNoReason);
CodeDesc desc; CodeDesc desc;
tasm.GetCode(nullptr, &desc); tasm.GetCode(nullptr, &desc);
MakeAssemblerBufferExecutable(buffer, allocated); buffer->MakeExecutable();
// We need an isolate here to execute in the simulator. // We need an isolate here to execute in the simulator.
auto f = GeneratedCode<void>::FromBuffer(isolate(), buffer); auto f = GeneratedCode<void>::FromBuffer(isolate(), buffer->start());
ASSERT_DEATH_IF_SUPPORTED({ f.Call(); }, "abort: no reason"); ASSERT_DEATH_IF_SUPPORTED({ f.Call(); }, "abort: no reason");
} }
TEST_F(TurboAssemblerTest, TestCheck) { TEST_F(TurboAssemblerTest, TestCheck) {
size_t allocated; auto buffer = AllocateAssemblerBuffer();
byte* buffer = AllocateAssemblerBuffer(&allocated); TurboAssembler tasm(nullptr, AssemblerOptions{}, CodeObjectRequired::kNo,
TurboAssembler tasm(nullptr, AssemblerOptions{}, buffer, buffer->CreateView());
static_cast<int>(allocated), CodeObjectRequired::kNo);
__ set_abort_hard(true); __ set_abort_hard(true);
// Fail if the first parameter (in {a0}) is 17. // Fail if the first parameter (in {a0}) is 17.
...@@ -51,9 +49,9 @@ TEST_F(TurboAssemblerTest, TestCheck) { ...@@ -51,9 +49,9 @@ TEST_F(TurboAssemblerTest, TestCheck) {
CodeDesc desc; CodeDesc desc;
tasm.GetCode(nullptr, &desc); tasm.GetCode(nullptr, &desc);
MakeAssemblerBufferExecutable(buffer, allocated); buffer->MakeExecutable();
// We need an isolate here to execute in the simulator. // We need an isolate here to execute in the simulator.
auto f = GeneratedCode<void, int>::FromBuffer(isolate(), buffer); auto f = GeneratedCode<void, int>::FromBuffer(isolate(), buffer->start());
f.Call(0); f.Call(0);
f.Call(18); f.Call(18);
......
...@@ -21,10 +21,9 @@ namespace internal { ...@@ -21,10 +21,9 @@ namespace internal {
class TurboAssemblerTest : public TestWithIsolate {}; class TurboAssemblerTest : public TestWithIsolate {};
TEST_F(TurboAssemblerTest, TestHardAbort) { TEST_F(TurboAssemblerTest, TestHardAbort) {
size_t allocated; auto buffer = AllocateAssemblerBuffer();
byte* buffer = AllocateAssemblerBuffer(&allocated); TurboAssembler tasm(nullptr, AssemblerOptions{}, CodeObjectRequired::kNo,
TurboAssembler tasm(nullptr, AssemblerOptions{}, buffer, buffer->CreateView());
static_cast<int>(allocated), CodeObjectRequired::kNo);
// Called from C // Called from C
__ function_descriptor(); __ function_descriptor();
...@@ -34,7 +33,7 @@ TEST_F(TurboAssemblerTest, TestHardAbort) { ...@@ -34,7 +33,7 @@ TEST_F(TurboAssemblerTest, TestHardAbort) {
CodeDesc desc; CodeDesc desc;
tasm.GetCode(nullptr, &desc); tasm.GetCode(nullptr, &desc);
MakeAssemblerBufferExecutable(buffer, allocated); buffer->MakeExecutable();
// We need an isolate here to execute in the simulator. // We need an isolate here to execute in the simulator.
auto f = GeneratedCode<void>::FromBuffer(isolate(), buffer); auto f = GeneratedCode<void>::FromBuffer(isolate(), buffer);
...@@ -42,10 +41,9 @@ TEST_F(TurboAssemblerTest, TestHardAbort) { ...@@ -42,10 +41,9 @@ TEST_F(TurboAssemblerTest, TestHardAbort) {
} }
TEST_F(TurboAssemblerTest, TestCheck) { TEST_F(TurboAssemblerTest, TestCheck) {
size_t allocated; auto buffer = AllocateAssemblerBuffer();
byte* buffer = AllocateAssemblerBuffer(&allocated); TurboAssembler tasm(nullptr, AssemblerOptions{}, CodeObjectRequired::kNo,
TurboAssembler tasm(nullptr, AssemblerOptions{}, buffer, buffer->CreateView());
static_cast<int>(allocated), CodeObjectRequired::kNo);
// Called from C // Called from C
__ function_descriptor(); __ function_descriptor();
...@@ -59,7 +57,7 @@ TEST_F(TurboAssemblerTest, TestCheck) { ...@@ -59,7 +57,7 @@ TEST_F(TurboAssemblerTest, TestCheck) {
CodeDesc desc; CodeDesc desc;
tasm.GetCode(nullptr, &desc); tasm.GetCode(nullptr, &desc);
MakeAssemblerBufferExecutable(buffer, allocated); buffer->MakeExecutable();
// We need an isolate here to execute in the simulator. // We need an isolate here to execute in the simulator.
auto f = GeneratedCode<void, int>::FromBuffer(isolate(), buffer); auto f = GeneratedCode<void, int>::FromBuffer(isolate(), buffer);
......
...@@ -21,17 +21,16 @@ namespace internal { ...@@ -21,17 +21,16 @@ namespace internal {
class TurboAssemblerTest : public TestWithIsolate {}; class TurboAssemblerTest : public TestWithIsolate {};
TEST_F(TurboAssemblerTest, TestHardAbort) { TEST_F(TurboAssemblerTest, TestHardAbort) {
size_t allocated; auto buffer = AllocateAssemblerBuffer();
byte* buffer = AllocateAssemblerBuffer(&allocated); TurboAssembler tasm(nullptr, AssemblerOptions{}, CodeObjectRequired::kNo,
TurboAssembler tasm(nullptr, AssemblerOptions{}, buffer, buffer->CreateView());
static_cast<int>(allocated), CodeObjectRequired::kNo);
__ set_abort_hard(true); __ set_abort_hard(true);
__ Abort(AbortReason::kNoReason); __ Abort(AbortReason::kNoReason);
CodeDesc desc; CodeDesc desc;
tasm.GetCode(nullptr, &desc); tasm.GetCode(nullptr, &desc);
MakeAssemblerBufferExecutable(buffer, allocated); buffer->MakeExecutable();
// We need an isolate here to execute in the simulator. // We need an isolate here to execute in the simulator.
auto f = GeneratedCode<void>::FromBuffer(isolate(), buffer); auto f = GeneratedCode<void>::FromBuffer(isolate(), buffer);
...@@ -39,10 +38,9 @@ TEST_F(TurboAssemblerTest, TestHardAbort) { ...@@ -39,10 +38,9 @@ TEST_F(TurboAssemblerTest, TestHardAbort) {
} }
TEST_F(TurboAssemblerTest, TestCheck) { TEST_F(TurboAssemblerTest, TestCheck) {
size_t allocated; auto buffer = AllocateAssemblerBuffer();
byte* buffer = AllocateAssemblerBuffer(&allocated); TurboAssembler tasm(nullptr, AssemblerOptions{}, CodeObjectRequired::kNo,
TurboAssembler tasm(nullptr, AssemblerOptions{}, buffer, buffer->CreateView());
static_cast<int>(allocated), CodeObjectRequired::kNo);
__ set_abort_hard(true); __ set_abort_hard(true);
// Fail if the first parameter is 17. // Fail if the first parameter is 17.
...@@ -53,7 +51,7 @@ TEST_F(TurboAssemblerTest, TestCheck) { ...@@ -53,7 +51,7 @@ TEST_F(TurboAssemblerTest, TestCheck) {
CodeDesc desc; CodeDesc desc;
tasm.GetCode(nullptr, &desc); tasm.GetCode(nullptr, &desc);
MakeAssemblerBufferExecutable(buffer, allocated); buffer->MakeExecutable();
// We need an isolate here to execute in the simulator. // We need an isolate here to execute in the simulator.
auto f = GeneratedCode<void, int>::FromBuffer(isolate(), buffer); auto f = GeneratedCode<void, int>::FromBuffer(isolate(), buffer);
......
...@@ -17,27 +17,25 @@ namespace internal { ...@@ -17,27 +17,25 @@ namespace internal {
// V8 library, create a context, or use any V8 objects. // V8 library, create a context, or use any V8 objects.
TEST(TurboAssemblerTest, TestHardAbort) { TEST(TurboAssemblerTest, TestHardAbort) {
size_t allocated; auto buffer = AllocateAssemblerBuffer();
byte* buffer = AllocateAssemblerBuffer(&allocated); TurboAssembler tasm(nullptr, AssemblerOptions{}, CodeObjectRequired::kNo,
TurboAssembler tasm(nullptr, AssemblerOptions{}, buffer, buffer->CreateView());
static_cast<int>(allocated), CodeObjectRequired::kNo);
__ set_abort_hard(true); __ set_abort_hard(true);
__ Abort(AbortReason::kNoReason); __ Abort(AbortReason::kNoReason);
CodeDesc desc; CodeDesc desc;
tasm.GetCode(nullptr, &desc); tasm.GetCode(nullptr, &desc);
MakeAssemblerBufferExecutable(buffer, allocated); buffer->MakeExecutable();
auto f = GeneratedCode<void>::FromBuffer(nullptr, buffer); auto f = GeneratedCode<void>::FromBuffer(nullptr, buffer->start());
ASSERT_DEATH_IF_SUPPORTED({ f.Call(); }, "abort: no reason"); ASSERT_DEATH_IF_SUPPORTED({ f.Call(); }, "abort: no reason");
} }
TEST(TurboAssemblerTest, TestCheck) { TEST(TurboAssemblerTest, TestCheck) {
size_t allocated; auto buffer = AllocateAssemblerBuffer();
byte* buffer = AllocateAssemblerBuffer(&allocated); TurboAssembler tasm(nullptr, AssemblerOptions{}, CodeObjectRequired::kNo,
TurboAssembler tasm(nullptr, AssemblerOptions{}, buffer, buffer->CreateView());
static_cast<int>(allocated), CodeObjectRequired::kNo);
__ set_abort_hard(true); __ set_abort_hard(true);
// Fail if the first parameter is 17. // Fail if the first parameter is 17.
...@@ -48,8 +46,8 @@ TEST(TurboAssemblerTest, TestCheck) { ...@@ -48,8 +46,8 @@ TEST(TurboAssemblerTest, TestCheck) {
CodeDesc desc; CodeDesc desc;
tasm.GetCode(nullptr, &desc); tasm.GetCode(nullptr, &desc);
MakeAssemblerBufferExecutable(buffer, allocated); buffer->MakeExecutable();
auto f = GeneratedCode<void, int>::FromBuffer(nullptr, buffer); auto f = GeneratedCode<void, int>::FromBuffer(nullptr, buffer->start());
f.Call(0); f.Call(0);
f.Call(18); f.Call(18);
......
...@@ -94,10 +94,8 @@ class TrapHandlerTest : public TestWithIsolate, ...@@ -94,10 +94,8 @@ class TrapHandlerTest : public TestWithIsolate,
// The allocated memory buffer ends with a guard page. // The allocated memory buffer ends with a guard page.
crash_address_ = memory_buffer_.end() - 32; crash_address_ = memory_buffer_.end() - 32;
// Allocate a buffer for the generated code. // Allocate a buffer for the generated code.
size_t buffer_size; buffer_ = AllocateAssemblerBuffer(AssemblerBase::kMinimalBufferSize,
byte* buffer = AllocateAssemblerBuffer( GetRandomMmapAddr());
&buffer_size, AssemblerBase::kMinimalBufferSize, GetRandomMmapAddr());
buffer_ = Vector<byte>(buffer, buffer_size);
InitRecoveryCode(); InitRecoveryCode();
...@@ -122,8 +120,8 @@ class TrapHandlerTest : public TestWithIsolate, ...@@ -122,8 +120,8 @@ class TrapHandlerTest : public TestWithIsolate,
void TearDown() override { void TearDown() override {
// We should always have left wasm code. // We should always have left wasm code.
CHECK(!GetThreadInWasmFlag()); CHECK(!GetThreadInWasmFlag());
FreeAssemblerBuffer(buffer_.start(), buffer_.size()); buffer_.reset();
FreeAssemblerBuffer(recovery_buffer_.start(), recovery_buffer_.size()); recovery_buffer_.reset();
// Free the allocated backing store. // Free the allocated backing store.
i_isolate()->wasm_engine()->memory_tracker()->FreeBackingStoreForTesting( i_isolate()->wasm_engine()->memory_tracker()->FreeBackingStoreForTesting(
...@@ -148,20 +146,17 @@ class TrapHandlerTest : public TestWithIsolate, ...@@ -148,20 +146,17 @@ class TrapHandlerTest : public TestWithIsolate,
void InitRecoveryCode() { void InitRecoveryCode() {
// Create a code snippet where we can jump to to recover from a signal or // Create a code snippet where we can jump to to recover from a signal or
// exception. The code snippet only consists of a return statement. // exception. The code snippet only consists of a return statement.
size_t buffer_size; recovery_buffer_ = AllocateAssemblerBuffer(
byte* buffer = AllocateAssemblerBuffer( AssemblerBase::kMinimalBufferSize, GetRandomMmapAddr());
&buffer_size, AssemblerBase::kMinimalBufferSize, GetRandomMmapAddr());
recovery_buffer_ = Vector<byte>(buffer, buffer_size);
MacroAssembler masm(nullptr, AssemblerOptions{}, recovery_buffer_.start(), MacroAssembler masm(nullptr, AssemblerOptions{}, CodeObjectRequired::kNo,
recovery_buffer_.length(), CodeObjectRequired::kNo); recovery_buffer_->CreateView());
int recovery_offset = __ pc_offset(); int recovery_offset = __ pc_offset();
__ Pop(scratch); __ Pop(scratch);
__ Ret(); __ Ret();
CodeDesc desc; CodeDesc desc;
masm.GetCode(nullptr, &desc); masm.GetCode(nullptr, &desc);
MakeAssemblerBufferExecutable(recovery_buffer_.start(), recovery_buffer_->MakeExecutable();
recovery_buffer_.size());
g_recovery_address = g_recovery_address =
reinterpret_cast<Address>(desc.buffer + recovery_offset); reinterpret_cast<Address>(desc.buffer + recovery_offset);
} }
...@@ -233,21 +228,22 @@ class TrapHandlerTest : public TestWithIsolate, ...@@ -233,21 +228,22 @@ class TrapHandlerTest : public TestWithIsolate,
} }
// Execute the code in buffer. // Execute the code in buffer.
void ExecuteBuffer(Vector<byte> buffer) { void ExecuteBuffer() {
MakeAssemblerBufferExecutable(buffer.start(), buffer.size()); buffer_->MakeExecutable();
GeneratedCode<void>::FromAddress(i_isolate(), GeneratedCode<void>::FromAddress(
reinterpret_cast<Address>(buffer.start())) i_isolate(), reinterpret_cast<Address>(buffer_->start()))
.Call(); .Call();
CHECK(!g_test_handler_executed); CHECK(!g_test_handler_executed);
} }
// Execute the code in buffer. We expect a crash which we recover from in the // Execute the code in buffer. We expect a crash which we recover from in the
// test handler. // test handler.
void ExecuteExpectCrash(Vector<byte> buffer, bool check_wasm_flag = true) { void ExecuteExpectCrash(TestingAssemblerBuffer* buffer,
bool check_wasm_flag = true) {
CHECK(!g_test_handler_executed); CHECK(!g_test_handler_executed);
MakeAssemblerBufferExecutable(buffer.start(), buffer.size()); buffer->MakeExecutable();
GeneratedCode<void>::FromAddress(i_isolate(), GeneratedCode<void>::FromAddress(i_isolate(),
reinterpret_cast<Address>(buffer.start())) reinterpret_cast<Address>(buffer->start()))
.Call(); .Call();
CHECK(g_test_handler_executed); CHECK(g_test_handler_executed);
g_test_handler_executed = false; g_test_handler_executed = false;
...@@ -266,16 +262,16 @@ class TrapHandlerTest : public TestWithIsolate, ...@@ -266,16 +262,16 @@ class TrapHandlerTest : public TestWithIsolate,
void* accessible_memory_start_; void* accessible_memory_start_;
// Buffer for generated code. // Buffer for generated code.
Vector<byte> buffer_; std::unique_ptr<TestingAssemblerBuffer> buffer_;
// Buffer for the code for the landing pad of the test handler. // Buffer for the code for the landing pad of the test handler.
Vector<byte> recovery_buffer_; std::unique_ptr<TestingAssemblerBuffer> recovery_buffer_;
}; };
TEST_P(TrapHandlerTest, TestTrapHandlerRecovery) { TEST_P(TrapHandlerTest, TestTrapHandlerRecovery) {
// Test that the wasm trap handler can recover a memory access violation in // Test that the wasm trap handler can recover a memory access violation in
// wasm code (we fake the wasm code and the access violation). // wasm code (we fake the wasm code and the access violation).
MacroAssembler masm(nullptr, AssemblerOptions{}, buffer_.start(), MacroAssembler masm(nullptr, AssemblerOptions{}, CodeObjectRequired::kNo,
buffer_.length(), CodeObjectRequired::kNo); buffer_->CreateView());
__ Push(scratch); __ Push(scratch);
GenerateSetThreadInWasmFlagCode(&masm); GenerateSetThreadInWasmFlagCode(&masm);
__ Move(scratch, crash_address_, RelocInfo::NONE); __ Move(scratch, crash_address_, RelocInfo::NONE);
...@@ -294,14 +290,14 @@ TEST_P(TrapHandlerTest, TestTrapHandlerRecovery) { ...@@ -294,14 +290,14 @@ TEST_P(TrapHandlerTest, TestTrapHandlerRecovery) {
trap_handler::RegisterHandlerData(reinterpret_cast<Address>(desc.buffer), trap_handler::RegisterHandlerData(reinterpret_cast<Address>(desc.buffer),
desc.instr_size, 1, &protected_instruction); desc.instr_size, 1, &protected_instruction);
ExecuteBuffer(buffer_); ExecuteBuffer();
} }
TEST_P(TrapHandlerTest, TestReleaseHandlerData) { TEST_P(TrapHandlerTest, TestReleaseHandlerData) {
// Test that after we release handler data in the trap handler, it cannot // Test that after we release handler data in the trap handler, it cannot
// recover from the specific memory access violation anymore. // recover from the specific memory access violation anymore.
MacroAssembler masm(nullptr, AssemblerOptions{}, buffer_.start(), MacroAssembler masm(nullptr, AssemblerOptions{}, CodeObjectRequired::kNo,
buffer_.length(), CodeObjectRequired::kNo); buffer_->CreateView());
__ Push(scratch); __ Push(scratch);
GenerateSetThreadInWasmFlagCode(&masm); GenerateSetThreadInWasmFlagCode(&masm);
__ Move(scratch, crash_address_, RelocInfo::NONE); __ Move(scratch, crash_address_, RelocInfo::NONE);
...@@ -322,20 +318,20 @@ TEST_P(TrapHandlerTest, TestReleaseHandlerData) { ...@@ -322,20 +318,20 @@ TEST_P(TrapHandlerTest, TestReleaseHandlerData) {
SetupTrapHandler(GetParam()); SetupTrapHandler(GetParam());
ExecuteBuffer(buffer_); ExecuteBuffer();
// Deregister from the trap handler. The trap handler should not do the // Deregister from the trap handler. The trap handler should not do the
// recovery now. // recovery now.
trap_handler::ReleaseHandlerData(handler_id); trap_handler::ReleaseHandlerData(handler_id);
ExecuteExpectCrash(buffer_); ExecuteExpectCrash(buffer_.get());
} }
TEST_P(TrapHandlerTest, TestNoThreadInWasmFlag) { TEST_P(TrapHandlerTest, TestNoThreadInWasmFlag) {
// That that if the thread_in_wasm flag is not set, the trap handler does not // That that if the thread_in_wasm flag is not set, the trap handler does not
// get active. // get active.
MacroAssembler masm(nullptr, AssemblerOptions{}, buffer_.start(), MacroAssembler masm(nullptr, AssemblerOptions{}, CodeObjectRequired::kNo,
buffer_.length(), CodeObjectRequired::kNo); buffer_->CreateView());
__ Push(scratch); __ Push(scratch);
__ Move(scratch, crash_address_, RelocInfo::NONE); __ Move(scratch, crash_address_, RelocInfo::NONE);
int crash_offset = __ pc_offset(); int crash_offset = __ pc_offset();
...@@ -353,14 +349,14 @@ TEST_P(TrapHandlerTest, TestNoThreadInWasmFlag) { ...@@ -353,14 +349,14 @@ TEST_P(TrapHandlerTest, TestNoThreadInWasmFlag) {
SetupTrapHandler(GetParam()); SetupTrapHandler(GetParam());
ExecuteExpectCrash(buffer_); ExecuteExpectCrash(buffer_.get());
} }
TEST_P(TrapHandlerTest, TestCrashInWasmNoProtectedInstruction) { TEST_P(TrapHandlerTest, TestCrashInWasmNoProtectedInstruction) {
// Test that if the crash in wasm happened at an instruction which is not // Test that if the crash in wasm happened at an instruction which is not
// protected, then the trap handler does not handle it. // protected, then the trap handler does not handle it.
MacroAssembler masm(nullptr, AssemblerOptions{}, buffer_.start(), MacroAssembler masm(nullptr, AssemblerOptions{}, CodeObjectRequired::kNo,
buffer_.length(), CodeObjectRequired::kNo); buffer_->CreateView());
__ Push(scratch); __ Push(scratch);
GenerateSetThreadInWasmFlagCode(&masm); GenerateSetThreadInWasmFlagCode(&masm);
int no_crash_offset = __ pc_offset(); int no_crash_offset = __ pc_offset();
...@@ -381,14 +377,14 @@ TEST_P(TrapHandlerTest, TestCrashInWasmNoProtectedInstruction) { ...@@ -381,14 +377,14 @@ TEST_P(TrapHandlerTest, TestCrashInWasmNoProtectedInstruction) {
SetupTrapHandler(GetParam()); SetupTrapHandler(GetParam());
ExecuteExpectCrash(buffer_); ExecuteExpectCrash(buffer_.get());
} }
TEST_P(TrapHandlerTest, TestCrashInWasmWrongCrashType) { TEST_P(TrapHandlerTest, TestCrashInWasmWrongCrashType) {
// Test that if the crash reason is not a memory access violation, then the // Test that if the crash reason is not a memory access violation, then the
// wasm trap handler does not handle it. // wasm trap handler does not handle it.
MacroAssembler masm(nullptr, AssemblerOptions{}, buffer_.start(), MacroAssembler masm(nullptr, AssemblerOptions{}, CodeObjectRequired::kNo,
buffer_.length(), CodeObjectRequired::kNo); buffer_->CreateView());
__ Push(scratch); __ Push(scratch);
GenerateSetThreadInWasmFlagCode(&masm); GenerateSetThreadInWasmFlagCode(&masm);
__ xorq(scratch, scratch); __ xorq(scratch, scratch);
...@@ -417,7 +413,7 @@ TEST_P(TrapHandlerTest, TestCrashInWasmWrongCrashType) { ...@@ -417,7 +413,7 @@ TEST_P(TrapHandlerTest, TestCrashInWasmWrongCrashType) {
#else #else
bool check_wasm_flag = true; bool check_wasm_flag = true;
#endif #endif
ExecuteExpectCrash(buffer_, check_wasm_flag); ExecuteExpectCrash(buffer_.get(), check_wasm_flag);
if (!check_wasm_flag) { if (!check_wasm_flag) {
// Reset the thread-in-wasm flag because it was probably not reset in the // Reset the thread-in-wasm flag because it was probably not reset in the
// trap handler. // trap handler.
...@@ -427,14 +423,14 @@ TEST_P(TrapHandlerTest, TestCrashInWasmWrongCrashType) { ...@@ -427,14 +423,14 @@ TEST_P(TrapHandlerTest, TestCrashInWasmWrongCrashType) {
class CodeRunner : public v8::base::Thread { class CodeRunner : public v8::base::Thread {
public: public:
CodeRunner(TrapHandlerTest* test, Vector<byte> buffer) CodeRunner(TrapHandlerTest* test, TestingAssemblerBuffer* buffer)
: Thread(Options("CodeRunner")), test_(test), buffer_(buffer) {} : Thread(Options("CodeRunner")), test_(test), buffer_(buffer) {}
void Run() override { test_->ExecuteExpectCrash(buffer_); } void Run() override { test_->ExecuteExpectCrash(buffer_); }
private: private:
TrapHandlerTest* test_; TrapHandlerTest* test_;
Vector<byte> buffer_; TestingAssemblerBuffer* buffer_;
}; };
TEST_P(TrapHandlerTest, TestCrashInOtherThread) { TEST_P(TrapHandlerTest, TestCrashInOtherThread) {
...@@ -442,8 +438,8 @@ TEST_P(TrapHandlerTest, TestCrashInOtherThread) { ...@@ -442,8 +438,8 @@ TEST_P(TrapHandlerTest, TestCrashInOtherThread) {
// The current thread enters wasm land (sets the thread_in_wasm flag) // The current thread enters wasm land (sets the thread_in_wasm flag)
// A second thread crashes at a protected instruction without having the flag // A second thread crashes at a protected instruction without having the flag
// set. // set.
MacroAssembler masm(nullptr, AssemblerOptions{}, buffer_.start(), MacroAssembler masm(nullptr, AssemblerOptions{}, CodeObjectRequired::kNo,
buffer_.length(), CodeObjectRequired::kNo); buffer_->CreateView());
__ Push(scratch); __ Push(scratch);
__ Move(scratch, crash_address_, RelocInfo::NONE); __ Move(scratch, crash_address_, RelocInfo::NONE);
int crash_offset = __ pc_offset(); int crash_offset = __ pc_offset();
...@@ -461,7 +457,7 @@ TEST_P(TrapHandlerTest, TestCrashInOtherThread) { ...@@ -461,7 +457,7 @@ TEST_P(TrapHandlerTest, TestCrashInOtherThread) {
SetupTrapHandler(GetParam()); SetupTrapHandler(GetParam());
CodeRunner runner(this, buffer_); CodeRunner runner(this, buffer_.get());
CHECK(!GetThreadInWasmFlag()); CHECK(!GetThreadInWasmFlag());
// Set the thread-in-wasm flag manually in this thread. // Set the thread-in-wasm flag manually in this thread.
*trap_handler::GetThreadInWasmThreadLocalAddress() = 1; *trap_handler::GetThreadInWasmThreadLocalAddress() = 1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment