Skip to content

Commit

Permalink
Fix bugs in MemoryManager around alignment handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvest committed Apr 30, 2018
1 parent a60da9f commit c715dec
Showing 1 changed file with 12 additions and 7 deletions.
Expand Up @@ -167,35 +167,40 @@ private static class Grab
public final Grab next;
private final long address;
private final long limit;
private final long alignMask;
private final long alignment;
private long nextAlignedPointer;

Grab( Grab next, long size, long alignment )
{
this.next = next;
this.address = allocateNativeMemory( size );
this.limit = address + size;
this.alignMask = alignment - 1;
this.alignment = alignment;

nextAlignedPointer = nextAligned( this.address );
}

Grab( Grab next, long address, long limit, long alignMask, long nextAlignedPointer )
Grab( Grab next, long address, long limit, long alignment, long nextAlignedPointer )
{
this.next = next;
this.address = address;
this.limit = limit;
this.alignMask = alignMask;
this.alignment = alignment;
this.nextAlignedPointer = nextAlignedPointer;
}

private long nextAligned( long pointer )
{
if ( (pointer & ~alignMask) == pointer )
if ( alignment == 1 )
{
return pointer;
}
return (pointer + alignMask) & ~alignMask;
long off = pointer % alignment;
if ( off == 0 )
{
return pointer;
}
return pointer + (alignment - off);
}

long allocate( long bytes )
Expand All @@ -217,7 +222,7 @@ boolean canAllocate( long bytes )

Grab setNext( Grab grab )
{
return new Grab( grab, address, limit, alignMask, nextAlignedPointer );
return new Grab( grab, address, limit, alignment, nextAlignedPointer );
}

@Override
Expand Down

0 comments on commit c715dec

Please sign in to comment.