Skip to content

Commit

Permalink
First draft of off-heap PageList implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvest committed May 26, 2017
1 parent 7ccf60f commit 81d661f
Show file tree
Hide file tree
Showing 14 changed files with 2,036 additions and 65 deletions.
Expand Up @@ -85,13 +85,13 @@ public InputStream openAsInputStream( File fileName ) throws IOException
@Override @Override
public Reader openAsReader( File fileName, Charset charset ) throws IOException public Reader openAsReader( File fileName, Charset charset ) throws IOException
{ {
return new InputStreamReader( new FileInputStream( fileName ), charset ); return new InputStreamReader( openAsInputStream( fileName ), charset );
} }


@Override @Override
public Writer openAsWriter( File fileName, Charset charset, boolean append ) throws IOException public Writer openAsWriter( File fileName, Charset charset, boolean append ) throws IOException
{ {
return new OutputStreamWriter( new FileOutputStream( fileName, append ), charset ); return new OutputStreamWriter( openAsOutputStream( fileName, append ), charset );
} }


@Override @Override
Expand Down
Expand Up @@ -33,7 +33,7 @@


import static java.lang.String.format; import static java.lang.String.format;


final class MuninnPage extends SequenceLock implements Page final class MuninnPage extends OnHeapSequenceLock implements Page
{ {
private static final long usageStampOffset = UnsafeUtil.getFieldOffset( MuninnPage.class, "usageStamp" ); private static final long usageStampOffset = UnsafeUtil.getFieldOffset( MuninnPage.class, "usageStamp" );


Expand Down
Expand Up @@ -224,6 +224,9 @@ public MuninnPageCache( PageSwapperFactory swapperFactory, int maxPages, int cac
long expectedMaxMemory = ((long) maxPages) * cachePageSize; // cast to long prevents overflow long expectedMaxMemory = ((long) maxPages) * cachePageSize; // cast to long prevents overflow
MemoryManager memoryManager = new MemoryManager( expectedMaxMemory, alignment ); MemoryManager memoryManager = new MemoryManager( expectedMaxMemory, alignment );
this.victimPage = VictimPageReference.getVictimPage( cachePageSize ); this.victimPage = VictimPageReference.getVictimPage( cachePageSize );

// PageList pages = new PageList( maxPages, cachePageSize, memoryManager, victimPage );

Object pageList = null; Object pageList = null;
int pageIndex = maxPages; int pageIndex = maxPages;
while ( pageIndex-- > 0 ) while ( pageIndex-- > 0 )
Expand Down

Large diffs are not rendered by default.

@@ -0,0 +1,51 @@
/*
* Copyright (c) 2002-2016 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.io.pagecache.impl.muninn;

import org.neo4j.unsafe.impl.internal.dragons.UnsafeUtil;

/**
* This is a {@link SequenceLock} lock implementation that keeps its state on-heap in a field.
*/
public class OnHeapSequenceLock extends SequenceLock
{
private static final long STATE = UnsafeUtil.getFieldOffset( OnHeapSequenceLock.class, "state" );

@SuppressWarnings( "unused" ) // accessed via unsafe
private volatile long state;

@Override
protected long getState()
{
return state;
}

@Override
protected boolean compareAndSetState( long expect, long update )
{
return UnsafeUtil.compareAndSwapLong( this, STATE, expect, update );
}

@Override
protected void unconditionallySetState( long update )
{
state = update;
}
}

0 comments on commit 81d661f

Please sign in to comment.