Skip to content

Reduce long time memory usage #207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ public BufferingChunkedInput( ReadableByteChannel ch )
public BufferingChunkedInput( ReadableByteChannel channel, int bufferCapacity )
{
assert bufferCapacity >= 1;
this.buffer = ByteBuffer.allocateDirect( bufferCapacity ).order( ByteOrder.BIG_ENDIAN );
this.buffer = ByteBuffer.allocate( bufferCapacity ).order( ByteOrder.BIG_ENDIAN );
this.buffer.limit( 0 );
this.scratchBuffer = ByteBuffer.allocateDirect( 8 ).order( ByteOrder.BIG_ENDIAN );
this.scratchBuffer = ByteBuffer.allocate( 8 ).order( ByteOrder.BIG_ENDIAN );
this.channel = channel;
this.state = State.AWAITING_CHUNK;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class ChunkedInput implements PackInput
private final ByteBuffer buffer;

/* a special buffer for chunk header */
private final ByteBuffer chunkHeaderBuffer = ByteBuffer.allocateDirect( 2 );
private final ByteBuffer chunkHeaderBuffer = ByteBuffer.allocate( 2 );

/* the size of bytes that have not been read in current incoming chunk */
private int unreadChunkSize = 0;
Expand All @@ -52,7 +52,7 @@ public ChunkedInput( ReadableByteChannel ch )
public ChunkedInput( int bufferCapacity, ReadableByteChannel channel )
{
assert bufferCapacity >= 1;
buffer = ByteBuffer.allocateDirect( bufferCapacity ).order( ByteOrder.BIG_ENDIAN );
buffer = ByteBuffer.allocate( bufferCapacity ).order( ByteOrder.BIG_ENDIAN );
buffer.limit( 0 );
this.channel = channel;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public ChunkedOutput( WritableByteChannel ch )

public ChunkedOutput( int bufferSize, WritableByteChannel ch )
{
buffer = ByteBuffer.allocateDirect( max( 16, bufferSize ) );
buffer = ByteBuffer.allocate( max( 16, bufferSize ) );
chunkOpen = false;
channel = ch;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ private SocketProtocol negotiateProtocol() throws IOException
{
logger.debug( "~~ [HANDSHAKE] [0x6060B017, 1, 0, 0, 0]." );
//Propose protocol versions
ByteBuffer buf = ByteBuffer.allocateDirect( 5 * 4 ).order( BIG_ENDIAN );
ByteBuffer buf = ByteBuffer.allocate( 5 * 4 ).order( BIG_ENDIAN );
buf.putInt( MAGIC_PREAMBLE );
for ( int version : SUPPORTED_VERSIONS )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class TLSSocketChannel implements ByteChannel
private ByteBuffer plainIn;
private ByteBuffer plainOut;

private static final ByteBuffer DUMMY_BUFFER = ByteBuffer.allocateDirect( 0 );
private static final ByteBuffer DUMMY_BUFFER = ByteBuffer.allocate( 0 );

public TLSSocketChannel( String host, int port, ByteChannel channel, Logger logger,
TrustStrategy trustStrategy )
Expand All @@ -75,10 +75,10 @@ public TLSSocketChannel( String host, int port, ByteChannel channel, Logger logg
public TLSSocketChannel( ByteChannel channel, Logger logger, SSLEngine sslEngine ) throws GeneralSecurityException, IOException
{
this(channel, logger, sslEngine,
ByteBuffer.allocateDirect( sslEngine.getSession().getApplicationBufferSize() ),
ByteBuffer.allocateDirect( sslEngine.getSession().getPacketBufferSize() ),
ByteBuffer.allocateDirect( sslEngine.getSession().getApplicationBufferSize() ),
ByteBuffer.allocateDirect( sslEngine.getSession().getPacketBufferSize() ) );
ByteBuffer.allocate( sslEngine.getSession().getApplicationBufferSize() ),
ByteBuffer.allocate( sslEngine.getSession().getPacketBufferSize() ),
ByteBuffer.allocate( sslEngine.getSession().getApplicationBufferSize() ),
ByteBuffer.allocate( sslEngine.getSession().getPacketBufferSize() ) );
}

TLSSocketChannel( ByteChannel channel, Logger logger, SSLEngine sslEngine,
Expand Down Expand Up @@ -216,7 +216,7 @@ private HandshakeStatus unwrap( ByteBuffer buffer ) throws IOException
"buffer size allowed is %s. The content in the buffer is: %s\n",
curAppSize, newAppSize, appSize * 2, BytePrinter.hex( plainIn ) ) );
}
ByteBuffer newPlainIn = ByteBuffer.allocateDirect( newAppSize );
ByteBuffer newPlainIn = ByteBuffer.allocate( newAppSize );
newPlainIn.put( plainIn );
plainIn = newPlainIn;
logger.debug( "Enlarged application input buffer from %s to %s. " +
Expand All @@ -229,7 +229,7 @@ private HandshakeStatus unwrap( ByteBuffer buffer ) throws IOException
// Resize buffer if needed.
if ( netSize > curNetSize )
{
ByteBuffer newCipherIn = ByteBuffer.allocateDirect( netSize );
ByteBuffer newCipherIn = ByteBuffer.allocate( netSize );
newCipherIn.put( cipherIn );
cipherIn = newCipherIn;
logger.debug( "Enlarged network input buffer from %s to %s. " +
Expand Down Expand Up @@ -297,7 +297,7 @@ private HandshakeStatus wrap( ByteBuffer buffer ) throws IOException
"new network buffer.", curNetSize, netSize, buffer.capacity() ) );
}

cipherOut = ByteBuffer.allocateDirect( netSize );
cipherOut = ByteBuffer.allocate( netSize );
logger.debug( "Enlarged network output buffer from %s to %s. " +
"This operation should be a rare operation.", curNetSize, netSize );
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public BufferedChannelInput(ReadableByteChannel ch )

public BufferedChannelInput( int bufferCapacity, ReadableByteChannel ch )
{
this.buffer = ByteBuffer.allocateDirect( bufferCapacity ).order( ByteOrder.BIG_ENDIAN );
this.buffer = ByteBuffer.allocate( bufferCapacity ).order( ByteOrder.BIG_ENDIAN );
reset( ch );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class BufferedChannelOutput implements PackOutput

public BufferedChannelOutput( int bufferSize )
{
this.buffer = ByteBuffer.allocateDirect( bufferSize ).order( ByteOrder.BIG_ENDIAN );
this.buffer = ByteBuffer.allocate( bufferSize ).order( ByteOrder.BIG_ENDIAN );
}

public BufferedChannelOutput( WritableByteChannel channel )
Expand Down