16-byte align frames on the VMFrameStack

- Fixed: Don't assume operator new will return a pointer with 16-byte
  alignment when allocating a block for the VMFrameStack. Because it seems
  it's actually guaranteed to be 8-byte aligned. Don't know where I got
  the idea it would always be 16-byte aligned.
This commit is contained in:
Randy Heit 2015-01-10 23:00:45 -06:00
parent 649875b17e
commit 9b81e0e597
2 changed files with 8 additions and 2 deletions

View File

@ -682,6 +682,7 @@ struct VMFrame
VMValue *GetParam() const VMValue *GetParam() const
{ {
assert(((size_t)this & 15) == 0 && "VM frame is unaligned");
return (VMValue *)(((size_t)(this + 1) + 15) & ~15); return (VMValue *)(((size_t)(this + 1) + 15) & ~15);
} }
@ -789,6 +790,11 @@ private:
VMFrame *LastFrame; VMFrame *LastFrame;
VM_UBYTE *FreeSpace; VM_UBYTE *FreeSpace;
int BlockSize; int BlockSize;
void InitFreeSpace()
{
FreeSpace = (VM_UBYTE *)(((size_t)(this + 1) + 15) & ~15);
}
}; };
BlockHeader *Blocks; BlockHeader *Blocks;
BlockHeader *UnusedBlocks; BlockHeader *UnusedBlocks;

View File

@ -286,7 +286,7 @@ VMFrame *VMFrameStack::Alloc(int size)
block = (BlockHeader *)new VM_UBYTE[blocksize]; block = (BlockHeader *)new VM_UBYTE[blocksize];
block->BlockSize = blocksize; block->BlockSize = blocksize;
} }
block->FreeSpace = (VM_UBYTE *)block + ((sizeof(BlockHeader) + 15) & ~15); block->InitFreeSpace();
block->LastFrame = NULL; block->LastFrame = NULL;
block->NextBlock = Blocks; block->NextBlock = Blocks;
Blocks = block; Blocks = block;
@ -340,7 +340,7 @@ VMFrame *VMFrameStack::PopFrame()
{ {
assert(Blocks->NextBlock == NULL); assert(Blocks->NextBlock == NULL);
Blocks->LastFrame = NULL; Blocks->LastFrame = NULL;
Blocks->FreeSpace = (VM_UBYTE *)Blocks + ((sizeof(BlockHeader) + 15) & ~15); Blocks->InitFreeSpace();
} }
return NULL; return NULL;
} }