forked from I2P_Developers/i2p.i2p
ByteCache: Move all 16/32 byte users to SimpleByteCache;
increase SimpleByteCache default size.
This commit is contained in:
@ -21,8 +21,8 @@ import net.i2p.I2PAppContext;
|
||||
import net.i2p.data.ByteArray;
|
||||
import net.i2p.data.DataHelper;
|
||||
import net.i2p.data.SessionKey;
|
||||
import net.i2p.util.ByteCache;
|
||||
import net.i2p.util.Log;
|
||||
import net.i2p.util.SimpleByteCache;
|
||||
|
||||
/**
|
||||
* Wrapper for AES cypher operation using Cryptix's Rijndael implementation. Implements
|
||||
@ -38,8 +38,6 @@ public class CryptixAESEngine extends AESEngine {
|
||||
// keys are now cached in the SessionKey objects
|
||||
//private CryptixAESKeyCache _cache;
|
||||
|
||||
private static final ByteCache _prevCache = ByteCache.getInstance(16, 16);
|
||||
|
||||
/**** see comments for main() below
|
||||
private static final boolean USE_SYSTEM_AES;
|
||||
static {
|
||||
@ -166,10 +164,8 @@ public class CryptixAESEngine extends AESEngine {
|
||||
int numblock = length / 16;
|
||||
if (length % 16 != 0) numblock++;
|
||||
|
||||
ByteArray prevA = _prevCache.acquire();
|
||||
byte prev[] = prevA.getData();
|
||||
ByteArray curA = _prevCache.acquire();
|
||||
byte cur[] = curA.getData();
|
||||
byte prev[] = SimpleByteCache.acquire(16);
|
||||
byte cur[] = SimpleByteCache.acquire(16);
|
||||
System.arraycopy(iv, ivOffset, prev, 0, 16);
|
||||
|
||||
for (int x = 0; x < numblock; x++) {
|
||||
@ -190,8 +186,8 @@ public class CryptixAESEngine extends AESEngine {
|
||||
}
|
||||
*/
|
||||
|
||||
_prevCache.release(prevA);
|
||||
_prevCache.release(curA);
|
||||
SimpleByteCache.release(prev);
|
||||
SimpleByteCache.release(cur);
|
||||
}
|
||||
|
||||
/** encrypt exactly 16 bytes using the session key
|
||||
|
@ -98,6 +98,11 @@ public class SDSCache<V extends SimpleDataStructure> {
|
||||
}
|
||||
|
||||
/**
|
||||
* WARNING - If the SDS is found in the cache, the passed-in
|
||||
* byte array will be returned to the SimpleByteCache for reuse.
|
||||
* Do NOT save a reference to the passed-in data, or use or modify it,
|
||||
* after this call.
|
||||
*
|
||||
* @param data non-null, the byte array for the SimpleDataStructure
|
||||
* @return the cached value if available, otherwise
|
||||
* makes a new object and returns it
|
||||
|
@ -13,22 +13,14 @@ import net.i2p.data.ByteArray;
|
||||
* Cache the objects frequently used to reduce memory churn. The ByteArray
|
||||
* should be held onto as long as the data referenced in it is needed.
|
||||
*
|
||||
* For small arrays where the management of valid bytes in ByteArray
|
||||
* and prezeroing isn't required, use SimpleByteArray instead.
|
||||
*
|
||||
* Heap size control - survey of usage (April 2010) :
|
||||
*
|
||||
* <pre>
|
||||
Size Max MaxMem From
|
||||
|
||||
16 16 256 CryptixAESEngine
|
||||
16 32 512 BloomFilterIVValidator
|
||||
16 64 1K UDP PacketBuilder
|
||||
16 128 2K tunnel HopProcessor
|
||||
16 128 2K tunnel TrivialPreprocessor
|
||||
16 128 2K tunnel InboundEndpointProcessor
|
||||
16 128 2K tunnel OutboundGatewayProcessor
|
||||
|
||||
32 64 2K UDP PacketBuilder
|
||||
32 128 4K tunnel TrivialPreprocessor
|
||||
|
||||
1K 32 32K tunnel TrivialPreprocessor
|
||||
1K 512 512K tunnel FragmentHandler
|
||||
1K 512 512K I2NP TunnelDataMessage
|
||||
|
@ -18,7 +18,7 @@ public final class SimpleByteCache {
|
||||
|
||||
private static final Map<Integer, SimpleByteCache> _caches = new ConcurrentHashMap(8);
|
||||
|
||||
private static final int DEFAULT_SIZE = 16;
|
||||
private static final int DEFAULT_SIZE = 64;
|
||||
|
||||
/** up to this, use ABQ to minimize object churn and for performance; above this, use LBQ for two locks */
|
||||
private static final int MAX_FOR_ABQ = 64;
|
||||
|
Reference in New Issue
Block a user