| Index: test/cctest/test-macro-assembler-ia32.cc
|
| diff --git a/test/cctest/test-macro-assembler-ia32.cc b/test/cctest/test-macro-assembler-ia32.cc
|
| index 829ada3a61059cc49b57f6294f240f9a78fbc5ff..34269ee159c6ea008dc65eb48490d0e2cb6eed2e 100644
|
| --- a/test/cctest/test-macro-assembler-ia32.cc
|
| +++ b/test/cctest/test-macro-assembler-ia32.cc
|
| @@ -33,6 +33,7 @@
|
| #include "src/base/platform/platform.h"
|
| #include "src/factory.h"
|
| #include "src/macro-assembler.h"
|
| +#include "test/cctest/heap/heap-utils.h"
|
|
|
| using namespace v8::internal;
|
|
|
| @@ -43,11 +44,12 @@ using namespace v8::internal;
|
| #endif
|
|
|
| typedef int STDCALL F0Type();
|
| +typedef intptr_t STDCALL F1Type();
|
| typedef F0Type* F0;
|
| +typedef F1Type* F1;
|
|
|
| #define __ masm->
|
|
|
| -
|
| TEST(LoadAndStoreWithRepresentation) {
|
| // Allocate an executable page of memory.
|
| size_t actual_size;
|
| @@ -158,4 +160,207 @@ TEST(LoadAndStoreWithRepresentation) {
|
| CHECK_EQ(0, result);
|
| }
|
|
|
| +// Helper for the tests below.
|
| +template <typename Fun>
|
| +void AssembleFunction(Isolate* isolate, size_t actual_size, byte* buffer,
|
| + Fun f) {
|
| + MacroAssembler assembler(isolate, buffer, static_cast<int>(actual_size),
|
| + v8::internal::CodeObjectRequired::kYes);
|
| + MacroAssembler* masm = &assembler;
|
| + Label exit;
|
| + __ push(ebx);
|
| + __ push(edx);
|
| + __ sub(esp, Immediate(1 * kPointerSize));
|
| + f(masm);
|
| + __ add(esp, Immediate(1 * kPointerSize));
|
| + __ pop(edx);
|
| + __ pop(ebx);
|
| + __ ret(0);
|
| +
|
| + CodeDesc desc;
|
| + masm->GetCode(&desc);
|
| +}
|
| +
|
| +TEST(AllocateMacrosNoGCRequired) {
|
| + // Allocate an executable page of memory.
|
| + size_t actual_size;
|
| + byte* buffer = static_cast<byte*>(v8::base::OS::Allocate(
|
| + Assembler::kMinimalBufferSize, &actual_size, true));
|
| + CHECK(buffer);
|
| + Isolate* isolate = CcTest::i_isolate();
|
| + HandleScope handles(isolate);
|
| +
|
| + AllocationFlags const kDoubleAligned =
|
| + static_cast<AllocationFlags>(DOUBLE_ALIGNMENT);
|
| + AllocationFlags const kNoAllocationFlags =
|
| + static_cast<AllocationFlags>(NO_ALLOCATION_FLAGS);
|
| +
|
| +#define CHECK_TAGGED(result) CHECK_EQ(result& kHeapObjectTag, 1);
|
| +
|
| +#define CHECK_DOUBLE_ALIGNED(result) \
|
| + do { \
|
| + CHECK_TAGGED((result)); \
|
| + CHECK_EQ((result)&kDoubleAlignmentMaskTagged, 0); \
|
| + /* Check that the filler was written in the correct place */ \
|
| + CHECK_EQ(*reinterpret_cast<v8::internal::Map***>( \
|
| + (result) - (kHeapObjectTag + kPointerSize)), \
|
| + isolate->factory()->one_pointer_filler_map().location()); \
|
| + } while (false)
|
| +
|
| + heap::GcAndSweep(isolate->heap(), AllocationSpace::NEW_SPACE);
|
| + {
|
| + AssembleFunction(isolate, actual_size, buffer, [](MacroAssembler* masm) {
|
| + Label gc_required, success;
|
| + __ Allocate(kPointerSize, eax, ecx, edx, &gc_required,
|
| + kNoAllocationFlags);
|
| + __ jmp(&success);
|
| + __ bind(&gc_required);
|
| + __ Abort(kNoReason);
|
| + __ bind(&success);
|
| + });
|
| + intptr_t test_result = FUNCTION_CAST<F1>(buffer)();
|
| + CHECK_TAGGED(test_result);
|
| + }
|
| +
|
| + {
|
| + AssembleFunction(isolate, actual_size, buffer, [](MacroAssembler* masm) {
|
| + Label gc_required, success;
|
| + __ Allocate(kDoubleSize, eax, ecx, edx, &gc_required, kDoubleAligned);
|
| + __ jmp(&success);
|
| + __ bind(&gc_required);
|
| + __ Abort(kNoReason);
|
| + __ bind(&success);
|
| + });
|
| + heap::MakeSureNewSpaceTopIsNotDoubleAligned(isolate->heap());
|
| + intptr_t test_result = FUNCTION_CAST<F1>(buffer)();
|
| + CHECK_DOUBLE_ALIGNED(test_result);
|
| + }
|
| + {
|
| + AssembleFunction(isolate, actual_size, buffer, [](MacroAssembler* masm) {
|
| + Label gc_required, success;
|
| + __ mov(ebx, Immediate(kPointerSize));
|
| + __ Allocate(kPointerSize, eax, ecx, edx, &gc_required,
|
| + kNoAllocationFlags);
|
| + __ jmp(&success);
|
| + __ bind(&gc_required);
|
| + __ Abort(kNoReason);
|
| + __ bind(&success);
|
| + });
|
| + intptr_t test_result = FUNCTION_CAST<F1>(buffer)();
|
| + CHECK_TAGGED(test_result);
|
| + }
|
| +
|
| + {
|
| + AssembleFunction(isolate, actual_size, buffer, [](MacroAssembler* masm) {
|
| + Label gc_required, success;
|
| + __ mov(ebx, Immediate(kDoubleSize));
|
| + __ Allocate(ebx, eax, ecx, edx, &gc_required, kDoubleAligned);
|
| + __ jmp(&success);
|
| + __ bind(&gc_required);
|
| + __ Abort(kNoReason);
|
| + __ bind(&success);
|
| + });
|
| + heap::MakeSureNewSpaceTopIsNotDoubleAligned(isolate->heap());
|
| + intptr_t test_result = FUNCTION_CAST<F1>(buffer)();
|
| + CHECK_DOUBLE_ALIGNED(test_result);
|
| + }
|
| +
|
| + {
|
| + AssembleFunction(isolate, actual_size, buffer, [](MacroAssembler* masm) {
|
| + Label gc_required, success;
|
| + __ mov(ebx, Immediate(2));
|
| + __ Allocate(0, times_4, ebx, REGISTER_VALUE_IS_SMI, eax, ecx, edx,
|
| + &gc_required, kNoAllocationFlags);
|
| + __ jmp(&success);
|
| + __ bind(&gc_required);
|
| + __ Abort(kNoReason);
|
| + __ bind(&success);
|
| + });
|
| + intptr_t test_result = FUNCTION_CAST<F1>(buffer)();
|
| + CHECK_TAGGED(test_result);
|
| + }
|
| +
|
| + {
|
| + AssembleFunction(isolate, actual_size, buffer, [](MacroAssembler* masm) {
|
| + Label gc_required, success;
|
| + __ mov(ebx, Immediate(kDoubleSize));
|
| + __ Allocate(FixedDoubleArray::kHeaderSize, times_8, ebx,
|
| + REGISTER_VALUE_IS_SMI, eax, ecx, edx, &gc_required,
|
| + kDoubleAligned);
|
| + __ jmp(&success);
|
| + __ bind(&gc_required);
|
| + __ Abort(kNoReason);
|
| + __ bind(&success);
|
| + });
|
| + heap::MakeSureNewSpaceTopIsNotDoubleAligned(isolate->heap());
|
| + intptr_t test_result = FUNCTION_CAST<F1>(buffer)();
|
| + CHECK_DOUBLE_ALIGNED(test_result);
|
| + }
|
| +#undef CHECK_TAGGED
|
| +#undef CHECK_DOUBLE_ALIGNED
|
| +}
|
| +
|
| +TEST(AllocateMacrosGCRequired) {
|
| + // Allocate an executable page of memory.
|
| + size_t actual_size;
|
| + byte* buffer = static_cast<byte*>(v8::base::OS::Allocate(
|
| + Assembler::kMinimalBufferSize, &actual_size, true));
|
| + CHECK(buffer);
|
| + Isolate* isolate = CcTest::i_isolate();
|
| + HandleScope handles(isolate);
|
| +
|
| + AllocationFlags const kDoubleAligned =
|
| + static_cast<AllocationFlags>(DOUBLE_ALIGNMENT);
|
| +
|
| + // Test that the macro jumps to the gc_required label if there's not enough
|
| + // space to allocate with double alignment.
|
| + {
|
| + AssembleFunction(isolate, actual_size, buffer, [](MacroAssembler* masm) {
|
| + Label gc_required, end;
|
| + __ Allocate(kPointerSize, eax, ecx, edx, &gc_required, kDoubleAligned);
|
| + __ xor_(eax, eax);
|
| + __ jmp(&end);
|
| + __ bind(&gc_required);
|
| + __ mov(eax, Immediate(1));
|
| + __ bind(&end);
|
| + });
|
| + heap::AllocateAllButNBytes(isolate->heap()->new_space(), 4);
|
| + intptr_t test_result = FUNCTION_CAST<F1>(buffer)();
|
| + CHECK_EQ(test_result, 1);
|
| + }
|
| +
|
| + {
|
| + AssembleFunction(isolate, actual_size, buffer, [](MacroAssembler* masm) {
|
| + Label gc_required, end;
|
| + __ mov(ebx, Immediate(kPointerSize));
|
| + __ Allocate(ebx, eax, ecx, edx, &gc_required, kDoubleAligned);
|
| + __ xor_(eax, eax);
|
| + __ jmp(&end);
|
| + __ bind(&gc_required);
|
| + __ mov(eax, Immediate(1));
|
| + __ bind(&end);
|
| + });
|
| + heap::AllocateAllButNBytes(isolate->heap()->new_space(), 4);
|
| + intptr_t test_result = FUNCTION_CAST<F1>(buffer)();
|
| + CHECK_EQ(test_result, 1);
|
| + }
|
| +
|
| + {
|
| + AssembleFunction(isolate, actual_size, buffer, [](MacroAssembler* masm) {
|
| + Label gc_required, end;
|
| + __ mov(ebx, Immediate(kPointerSize));
|
| + __ Allocate(0, times_8, ebx, REGISTER_VALUE_IS_SMI, eax, ecx, edx,
|
| + &gc_required, kDoubleAligned);
|
| + __ xor_(eax, eax);
|
| + __ jmp(&end);
|
| + __ bind(&gc_required);
|
| + __ mov(eax, Immediate(1));
|
| + __ bind(&end);
|
| + });
|
| + heap::AllocateAllButNBytes(isolate->heap()->new_space(), 4);
|
| + intptr_t test_result = FUNCTION_CAST<F1>(buffer)();
|
| + CHECK_EQ(test_result, 1);
|
| + }
|
| +}
|
| +
|
| #undef __
|
|
|