Skip to content

Commit

Permalink
Finish porting swapper ids from short to int.
Browse files Browse the repository at this point in the history
These parts were somehow missed in #11674 and #11668.
  • Loading branch information
chrisvest committed May 22, 2018
1 parent 46c0cef commit 2482d23
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
Expand Up @@ -55,7 +55,7 @@ abstract class MuninnPageCursor extends PageCursor
private final PageCursorTracer tracer;
protected MuninnPagedFile pagedFile;
protected PageSwapper swapper;
protected short swapperId;
protected int swapperId;
protected long pinnedPageRef;
protected PinEvent pinEvent;
protected long pageId;
Expand Down
Expand Up @@ -70,7 +70,7 @@ final class MuninnPagedFile extends PageList implements PagedFile, Flushable
volatile int[][] translationTable;

final PageSwapper swapper;
final short swapperId;
final int swapperId;
private final CursorPool cursorPool;

// Guarded by the monitor lock on MuninnPageCache (map and unmap)
Expand Down
Expand Up @@ -91,7 +91,7 @@ private void checkId( int id )
/**
* Allocate a new swapper id for the given {@link PageSwapper}.
*/
synchronized short allocate( PageSwapper swapper )
synchronized int allocate( PageSwapper swapper )
{
SwapperMapping[] swapperMappings = this.swapperMappings;

Expand All @@ -100,7 +100,7 @@ synchronized short allocate( PageSwapper swapper )
{
if ( !free.isEmpty() )
{
short id = safeCastIntToShort( free.iterator().next() );
int id = free.iterator().next();
free.remove( id );
swapperMappings[id] = new SwapperMapping( id, swapper );
this.swapperMappings = swapperMappings; // Volatile store synchronizes-with loads in getters.
Expand All @@ -109,7 +109,7 @@ synchronized short allocate( PageSwapper swapper )
}

// No free slot was found above, so we extend the array to make room for a new slot.
short id = safeCastIntToShort( swapperMappings.length );
int id = swapperMappings.length;
if ( id + 1 > MAX_SWAPPER_ID )
{
throw new IllegalStateException( "All swapper ids are allocated: " + MAX_SWAPPER_ID );
Expand Down
Expand Up @@ -1571,7 +1571,7 @@ public void exclusiveLockMustStillBeHeldAfterFault() throws Exception
public void tryEvictMustFailIfPageIsAlreadyExclusivelyLocked() throws Exception
{
pageList.unlockExclusive( pageRef );
short swapperId = swappers.allocate( DUMMY_SWAPPER );
int swapperId = swappers.allocate( DUMMY_SWAPPER );
doFault( swapperId, 42 ); // page is now loaded
// pages are delivered from the fault routine with the exclusive lock already held!
assertFalse( pageList.tryEvict( pageRef, EvictionRunEvent.NULL ) );
Expand All @@ -1581,7 +1581,7 @@ public void tryEvictMustFailIfPageIsAlreadyExclusivelyLocked() throws Exception
public void tryEvictThatFailsOnExclusiveLockMustNotUndoSaidLock() throws Exception
{
pageList.unlockExclusive( pageRef );
short swapperId = swappers.allocate( DUMMY_SWAPPER );
int swapperId = swappers.allocate( DUMMY_SWAPPER );
doFault( swapperId, 42 ); // page is now loaded
// pages are delivered from the fault routine with the exclusive lock already held!
pageList.tryEvict( pageRef, EvictionRunEvent.NULL ); // This attempt will fail
Expand All @@ -1606,7 +1606,7 @@ public void tryEvictMustWhenPageIsNotLoadedMustNotLeavePageLocked() throws Excep
public void tryEvictMustLeavePageExclusivelyLockedOnSuccess() throws Exception
{
pageList.unlockExclusive( pageRef );
short swapperId = swappers.allocate( DUMMY_SWAPPER );
int swapperId = swappers.allocate( DUMMY_SWAPPER );
doFault( swapperId, 42 ); // page now bound & exclusively locked
pageList.unlockExclusive( pageRef ); // no longer exclusively locked; can now be evicted
assertTrue( pageList.tryEvict( pageRef, EvictionRunEvent.NULL ) );
Expand All @@ -1617,7 +1617,7 @@ public void tryEvictMustLeavePageExclusivelyLockedOnSuccess() throws Exception
public void pageMustNotBeLoadedAfterSuccessfulEviction() throws Exception
{
pageList.unlockExclusive( pageRef );
short swapperId = swappers.allocate( DUMMY_SWAPPER );
int swapperId = swappers.allocate( DUMMY_SWAPPER );
doFault( swapperId, 42 ); // page now bound & exclusively locked
pageList.unlockExclusive( pageRef ); // no longer exclusively locked; can now be evicted
assertTrue( pageList.isLoaded( pageRef ) );
Expand Down Expand Up @@ -1645,7 +1645,7 @@ public void pageMustNotBeBoundAfterSuccessfulEviction() throws Exception
public void pageMustNotBeModifiedAfterSuccessfulEviction() throws Exception
{
pageList.unlockExclusive( pageRef );
short swapperId = swappers.allocate( DUMMY_SWAPPER );
int swapperId = swappers.allocate( DUMMY_SWAPPER );
doFault( swapperId, 42 );
pageList.unlockExclusiveAndTakeWriteLock( pageRef );
pageList.unlockWrite( pageRef ); // page is now modified
Expand All @@ -1670,7 +1670,7 @@ public long write( long filePageId, long bufferAddress ) throws IOException
return super.write( filePageId, bufferAddress );
}
};
short swapperId = swappers.allocate( swapper );
int swapperId = swappers.allocate( swapper );
doFault( swapperId, 42 );
pageList.unlockExclusiveAndTakeWriteLock( pageRef );
pageList.unlockWrite( pageRef ); // page is now modified
Expand All @@ -1694,7 +1694,7 @@ public long write( long filePageId, long bufferAddress ) throws IOException
return super.write( filePageId, bufferAddress );
}
};
short swapperId = swappers.allocate( swapper );
int swapperId = swappers.allocate( swapper );
doFault( swapperId, 42 );
pageList.unlockExclusive( pageRef ); // we take no write lock, so page is not modified
assertFalse( pageList.isModified( pageRef ) );
Expand All @@ -1716,7 +1716,7 @@ public void evicted( long filePageId )
assertThat( filePageId, is( 42L ) );
}
};
short swapperId = swappers.allocate( swapper );
int swapperId = swappers.allocate( swapper );
doFault( swapperId, 42 );
pageList.unlockExclusive( pageRef );
assertTrue( pageList.tryEvict( pageRef, EvictionRunEvent.NULL ) );
Expand All @@ -1737,7 +1737,7 @@ public void evicted( long filePageId )
assertThat( filePageId, is( 42L ) );
}
};
short swapperId = swappers.allocate( swapper );
int swapperId = swappers.allocate( swapper );
doFault( swapperId, 42 );
pageList.unlockExclusiveAndTakeWriteLock( pageRef );
pageList.unlockWrite( pageRef ); // page is now modified
Expand All @@ -1759,7 +1759,7 @@ public long write( long filePageId, long bufferAddress ) throws IOException
throw new IOException();
}
};
short swapperId = swappers.allocate( swapper );
int swapperId = swappers.allocate( swapper );
doFault( swapperId, 42 );
pageList.unlockExclusiveAndTakeWriteLock( pageRef );
pageList.unlockWrite( pageRef ); // page is now modified
Expand Down Expand Up @@ -1802,7 +1802,7 @@ public void evicted( long filePageId )
evictionNotified.set( true );
}
};
short swapperId = swappers.allocate( swapper );
int swapperId = swappers.allocate( swapper );
doFault( swapperId, 42 );
pageList.unlockExclusiveAndTakeWriteLock( pageRef );
pageList.unlockWrite( pageRef ); // page is now modified
Expand Down Expand Up @@ -1912,7 +1912,7 @@ public void tryEvictMustReportToEvictionEvent() throws Exception
{
pageList.unlockExclusive( pageRef );
PageSwapper swapper = new DummyPageSwapper( "a", 313 );
short swapperId = swappers.allocate( swapper );
int swapperId = swappers.allocate( swapper );
doFault( swapperId, 42 );
pageList.unlockExclusive( pageRef );
EvictionAndFlushRecorder recorder = new EvictionAndFlushRecorder();
Expand All @@ -1934,7 +1934,7 @@ public void tryEvictThatFlushesMustReportToEvictionAndFlushEvents() throws Excep
pageList.unlockExclusive( pageRef );
int filePageSize = 313;
PageSwapper swapper = new DummyPageSwapper( "a", filePageSize );
short swapperId = swappers.allocate( swapper );
int swapperId = swappers.allocate( swapper );
doFault( swapperId, 42 );
pageList.unlockExclusiveAndTakeWriteLock( pageRef );
pageList.unlockWrite( pageRef ); // page is now modified
Expand Down Expand Up @@ -1965,7 +1965,7 @@ public long write( long filePageId, long bufferAddress ) throws IOException
throw ioException;
}
};
short swapperId = swappers.allocate( swapper );
int swapperId = swappers.allocate( swapper );
doFault( swapperId, 42 );
pageList.unlockExclusiveAndTakeWriteLock( pageRef );
pageList.unlockWrite( pageRef ); // page is now modified
Expand Down Expand Up @@ -1998,7 +1998,7 @@ public void tryEvictThatSucceedsMustNotInterfereWithAdjacentPages() throws Excep
pageList.unlockExclusive( pageRef );
pageList.unlockExclusive( nextPageRef );
PageSwapper swapper = new DummyPageSwapper( "a", 313 );
short swapperId = swappers.allocate( swapper );
int swapperId = swappers.allocate( swapper );
long prevStamp = pageList.tryOptimisticReadLock( prevPageRef );
long nextStamp = pageList.tryOptimisticReadLock( nextPageRef );
doFault( swapperId, 42 );
Expand All @@ -2015,7 +2015,7 @@ public void tryEvictThatFlushesAndSucceedsMustNotInterfereWithAdjacentPages() th
pageList.unlockExclusive( pageRef );
pageList.unlockExclusive( nextPageRef );
PageSwapper swapper = new DummyPageSwapper( "a", 313 );
short swapperId = swappers.allocate( swapper );
int swapperId = swappers.allocate( swapper );
long prevStamp = pageList.tryOptimisticReadLock( prevPageRef );
long nextStamp = pageList.tryOptimisticReadLock( nextPageRef );
doFault( swapperId, 42 );
Expand All @@ -2041,7 +2041,7 @@ public long write( long filePageId, long bufferAddress ) throws IOException
throw new IOException();
}
};
short swapperId = swappers.allocate( swapper );
int swapperId = swappers.allocate( swapper );
long prevStamp = pageList.tryOptimisticReadLock( prevPageRef );
long nextStamp = pageList.tryOptimisticReadLock( nextPageRef );
doFault( swapperId, 42 );
Expand Down
Expand Up @@ -55,8 +55,8 @@ public void mustReturnAllocationWithSwapper() throws Exception
{
DummyPageSwapper a = new DummyPageSwapper( "a", 42 );
DummyPageSwapper b = new DummyPageSwapper( "b", 43 );
short idA = set.allocate( a );
short idB = set.allocate( b );
int idA = set.allocate( a );
int idB = set.allocate( b );
SwapperSet.SwapperMapping allocA = set.getAllocation( idA );
SwapperSet.SwapperMapping allocB = set.getAllocation( idB );
assertThat( allocA.swapper, is( a ) );
Expand All @@ -66,7 +66,7 @@ public void mustReturnAllocationWithSwapper() throws Exception
@Test
public void accessingFreedAllocationMustReturnNull() throws Exception
{
short id = set.allocate( new DummyPageSwapper( "a", 42 ) );
int id = set.allocate( new DummyPageSwapper( "a", 42 ) );
set.free( id );
assertNull( set.getAllocation( id ) );
}
Expand Down Expand Up @@ -166,7 +166,7 @@ public void vacuumMustNotDustOffAnyIdsWhenNoneHaveBeenFreed() throws Exception
public void mustNotUseZeroAsSwapperId() throws Exception
{
PageSwapper swapper = new DummyPageSwapper( "a", 42 );
Matcher<Short> isNotZero = is( not( (short) 0 ) );
Matcher<Integer> isNotZero = is( not( 0 ) );
for ( int i = 0; i < 10_000; i++ )
{
assertThat( set.allocate( swapper ), isNotZero );
Expand Down

0 comments on commit 2482d23

Please sign in to comment.