Skip to content

Commit

Permalink
Split MemoryAccess.access into 3 methods
Browse files Browse the repository at this point in the history
  • Loading branch information
fickludd committed Jun 25, 2017
1 parent 7ef2ceb commit d36be06
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 28 deletions.
Expand Up @@ -24,7 +24,7 @@
abstract class MemoryAccess abstract class MemoryAccess
{ {
long virtualAddress; long virtualAddress;
PageManager pageman; PageManager pageMan;
long pageId; long pageId;
long base; long base;
int offset; int offset;
Expand All @@ -34,64 +34,79 @@ abstract class MemoryAccess


final void closeAccess() final void closeAccess()
{ {
if ( pageman != null ) if ( pageMan != null )
{ {
try try
{ {
pageman.releasePage( pageId, base, offset, lockToken ); pageMan.releasePage( pageId, base, offset, lockToken );
} }
finally finally
{ {
pageman = null; pageMan = null;
} }
} }
} }


public final boolean hasPageReference() public final boolean hasPageReference()
{ {
return pageman != null; return pageMan != null;
} }


final void access( long virtualAddress, PageManager pageman, long pageId, long base, int offset ) final void initializeMemoryAccess( long virtualAddress, PageManager pageMan, long pageId, long base, int offset )
{ {
// TODO: this method is too large to inline... if ( this.pageMan != null )
if ( this.pageman != null )
{ {
if ( this.pageman != pageman || this.pageId != pageId ) if ( this.pageMan != pageMan || this.pageId != pageId )
{ {
closeAccess(); closeAccess();
} }
else else
{ {
lockRelease(); // TODO: this is wrong - the move method assumes that the lock has NOT been released! lockRelease();
} }
} }
this.virtualAddress = virtualAddress; this.virtualAddress = virtualAddress;
this.pageman = pageman; this.pageMan = pageMan;
this.pageId = pageId; this.pageId = pageId;
this.base = base; this.base = base;
this.offset = offset; this.offset = offset;
} }


final void moveToOtherPage( long virtualAddress, long pageId, long base, int offset )
{
assert this.pageMan != null : "Memory access must be initialized before moving";
this.virtualAddress = virtualAddress;
this.pageId = pageId;
this.base = base;
this.offset = offset;
}

final void moveWithinPage( long virtualAddress, int offset )
{
assert this.pageMan != null : "Memory access must be initialized before moving";
this.virtualAddress = virtualAddress;
this.offset = offset;
}

final void lockShared() final void lockShared()
{ {
lockToken = pageman.sharedLock( pageId, base, offset ); lockToken = pageMan.sharedLock( pageId, base, offset );
} }


final void lockExclusive() final void lockExclusive()
{ {
lockToken = pageman.exclusiveLock( pageId, base, offset ); lockToken = pageMan.exclusiveLock( pageId, base, offset );
} }


final void lockRelease() final void lockRelease()
{ {
pageman.releaseLock( pageId, base, offset, lockToken ); pageMan.releaseLock( pageId, base, offset, lockToken );
lockToken = 0; lockToken = 0;
} }


final long address( int offset, int size ) final long address( int offset, int size )
{ {
if ( pageman == null ) if ( pageMan == null )
{ {
throw new IllegalStateException( "Cursor has not been initialized." ); throw new IllegalStateException( "Cursor has not been initialized." );
} }
Expand Down
Expand Up @@ -24,7 +24,7 @@ public abstract class MemoryManager
protected static void setup( ReadCursor cursor, long virtualAddress, PageManager page, long pageId, long base, protected static void setup( ReadCursor cursor, long virtualAddress, PageManager page, long pageId, long base,
int offset ) int offset )
{ {
cursor.access( virtualAddress, page, pageId, base, offset ); cursor.initializeMemoryAccess( virtualAddress, page, pageId, base, offset );
} }


protected static void read( protected static void read(
Expand All @@ -37,17 +37,17 @@ protected static void read(
int bound ) int bound )
{ {
page.assertValidOffset( pageId, base, offset, bound ); page.assertValidOffset( pageId, base, offset, bound );
cursor.access( virtualAddress, page, pageId, base, offset ); cursor.moveToOtherPage( virtualAddress, pageId, base, offset );
cursor.lockShared(); cursor.lockShared();
} }


protected static void move( ReadCursor cursor, long virtualAddress, int offset, int bound ) protected static void move( ReadCursor cursor, long virtualAddress, int offset, int bound )
{ {
PageManager page = cursor.pageman; PageManager page = cursor.pageMan;
long pageId = cursor.pageId; long pageId = cursor.pageId;
long base = cursor.base; long base = cursor.base;
page.assertValidOffset( pageId, base, offset, bound ); page.assertValidOffset( pageId, base, offset, bound );
cursor.access( virtualAddress, page, pageId, base, offset ); cursor.moveWithinPage( virtualAddress, offset );
cursor.lockToken = page.moveLock( pageId, base, cursor.offset, cursor.lockToken, offset ); cursor.lockToken = page.moveLock( pageId, base, cursor.offset, cursor.lockToken, offset );
} }


Expand All @@ -61,7 +61,7 @@ protected static void write(
int bound ) int bound )
{ {
page.assertValidOffset( pageId, base, offset, bound ); page.assertValidOffset( pageId, base, offset, bound );
writer.access( virtualAddress, page, pageId, base, offset ); writer.initializeMemoryAccess( virtualAddress, page, pageId, base, offset );
writer.lockExclusive(); writer.lockExclusive();
} }
} }
Expand Up @@ -23,7 +23,7 @@ public abstract class ReadCursor extends MemoryAccess implements AutoCloseable
{ {
public final boolean shouldRetry() public final boolean shouldRetry()
{ {
long token = pageman.refreshLockToken( pageId, base, offset, lockToken ); long token = pageMan.refreshLockToken( pageId, base, offset, lockToken );
if ( token != lockToken ) if ( token != lockToken )
{ {
lockToken = token; lockToken = token;
Expand All @@ -35,11 +35,6 @@ public final boolean shouldRetry()
} }
} }


protected final void prepareReadCursor( long virtualAddress, PageManager page, long pageId, long base )
{
access( virtualAddress, page, pageId, base, 0 );
}

protected final long virtualAddress() protected final long virtualAddress()
{ {
return virtualAddress; return virtualAddress;
Expand All @@ -51,11 +46,11 @@ protected final long virtualAddress()
*/ */
protected final boolean gotoVirtualAddress( long virtualAddress ) protected final boolean gotoVirtualAddress( long virtualAddress )
{ {
if ( pageman == null ) if ( pageMan == null )
{ {
throw new IllegalStateException( "Cursor has not been initialized." ); throw new IllegalStateException( "Cursor has not been initialized." );
} }
return pageman.gotoVirtualAddress( virtualAddress, this, pageId, base, offset, lockToken ); return pageMan.gotoVirtualAddress( virtualAddress, this, pageId, base, offset, lockToken );
} }


protected boolean scanNextByVirtualAddress( long maxAddress ) protected boolean scanNextByVirtualAddress( long maxAddress )
Expand Down

0 comments on commit d36be06

Please sign in to comment.