Skip to content

Commit

Permalink
Avoid recursion in MuninnPageCursor.close()
Browse files Browse the repository at this point in the history
It apparently makes the JIT cautious about inlining such methods.
  • Loading branch information
chrisvest committed Apr 21, 2016
1 parent 7fbb446 commit 3866f7c
Showing 1 changed file with 20 additions and 8 deletions.
Expand Up @@ -53,7 +53,7 @@ abstract class MuninnPageCursor implements PageCursor
protected int pf_flags; protected int pf_flags;
protected long currentPageId; protected long currentPageId;
protected long nextPageId; protected long nextPageId;
protected PageCursor linkedCursor; protected MuninnPageCursor linkedCursor;
private long pointer; private long pointer;
private int pageSize; private int pageSize;
private int filePageSize; private int filePageSize;
Expand Down Expand Up @@ -109,12 +109,24 @@ public final boolean next( long pageId ) throws IOException
@Override @Override
public final void close() public final void close()
{ {
unpinCurrentPage(); MuninnPageCursor cursor = this;
releaseCursor(); do
closeLinkedCursorIfAny(); {
// We null out the pagedFile field to allow it and its (potentially big) translation table to be garbage cursor.unpinCurrentPage();
// collected when the file is unmapped, since the cursors can stick around in thread local caches, etc. cursor.releaseCursor();
pagedFile = null; // We null out the pagedFile field to allow it and its (potentially big) translation table to be garbage
// collected when the file is unmapped, since the cursors can stick around in thread local caches, etc.
cursor.pagedFile = null;

}
while ( (cursor = cursor.getAndClearLinkedCursor()) != null );
}

private MuninnPageCursor getAndClearLinkedCursor()
{
MuninnPageCursor cursor = linkedCursor;
linkedCursor = null;
return cursor;
} }


private void closeLinkedCursorIfAny() private void closeLinkedCursorIfAny()
Expand All @@ -130,7 +142,7 @@ private void closeLinkedCursorIfAny()
public PageCursor openLinkedCursor( long pageId ) public PageCursor openLinkedCursor( long pageId )
{ {
closeLinkedCursorIfAny(); closeLinkedCursorIfAny();
linkedCursor = pagedFile.io( pageId, pf_flags ); linkedCursor = (MuninnPageCursor) pagedFile.io( pageId, pf_flags );
return linkedCursor; return linkedCursor;
} }


Expand Down

0 comments on commit 3866f7c

Please sign in to comment.