forked from I2P_Developers/i2p.i2p
consolidate maxMemory() calls
This commit is contained in:
@ -15,6 +15,7 @@ import java.util.concurrent.LinkedBlockingQueue;
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.util.I2PThread;
|
||||
import net.i2p.util.NativeBigInteger;
|
||||
import net.i2p.util.SystemVersion;
|
||||
|
||||
/**
|
||||
* Precalculate the Y and K for ElGamal encryption operations.
|
||||
@ -55,9 +56,7 @@ class YKGenerator {
|
||||
ctx = context;
|
||||
|
||||
// add to the defaults for every 128MB of RAM, up to 1GB
|
||||
long maxMemory = Runtime.getRuntime().maxMemory();
|
||||
if (maxMemory == Long.MAX_VALUE)
|
||||
maxMemory = 127*1024*1024l;
|
||||
long maxMemory = SystemVersion.getMaxMemory();
|
||||
int factor = (int) Math.max(1l, Math.min(8l, 1 + (maxMemory / (128*1024*1024l))));
|
||||
int defaultMin = DEFAULT_YK_PRECALC_MIN * factor;
|
||||
int defaultMax = DEFAULT_YK_PRECALC_MAX * factor;
|
||||
|
@ -33,6 +33,7 @@ import net.i2p.crypto.SHA256Generator;
|
||||
import net.i2p.util.Clock;
|
||||
import net.i2p.util.Log;
|
||||
import net.i2p.util.OrderedProperties;
|
||||
import net.i2p.util.SystemVersion;
|
||||
|
||||
/**
|
||||
* Defines the data that a router either publishes to the global routing table or
|
||||
@ -68,8 +69,7 @@ public class RouterInfo extends DatabaseEntry {
|
||||
/** should we cache the byte and string versions _byteified ? **/
|
||||
private boolean _shouldCache;
|
||||
/** maybe we should check if we are floodfill? */
|
||||
private static final boolean CACHE_ALL = Runtime.getRuntime().maxMemory() > 128*1024*1024l &&
|
||||
Runtime.getRuntime().maxMemory() < Long.MAX_VALUE;
|
||||
private static final boolean CACHE_ALL = SystemVersion.getMaxMemory() > 128*1024*1024l;
|
||||
|
||||
public static final String PROP_NETWORK_ID = "netId";
|
||||
public static final String PROP_CAPABILITIES = "caps";
|
||||
|
@ -11,6 +11,7 @@ import java.util.Map;
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.util.LHMCache;
|
||||
import net.i2p.util.SimpleByteCache;
|
||||
import net.i2p.util.SystemVersion;
|
||||
|
||||
/**
|
||||
* A least recently used cache with a max size, for SimpleDataStructures.
|
||||
@ -49,9 +50,7 @@ public class SDSCache<V extends SimpleDataStructure> {
|
||||
private static final double MAX_FACTOR = 5.0;
|
||||
private static final double FACTOR;
|
||||
static {
|
||||
long maxMemory = Runtime.getRuntime().maxMemory();
|
||||
if (maxMemory == Long.MAX_VALUE)
|
||||
maxMemory = 96*1024*1024l;
|
||||
long maxMemory = SystemVersion.getMaxMemory();
|
||||
FACTOR = Math.max(MIN_FACTOR, Math.min(MAX_FACTOR, maxMemory / (128*1024*1024d)));
|
||||
}
|
||||
|
||||
|
@ -228,9 +228,7 @@ public abstract class Addresses {
|
||||
int size;
|
||||
I2PAppContext ctx = I2PAppContext.getCurrentContext();
|
||||
if (ctx != null && ctx.isRouterContext()) {
|
||||
long maxMemory = Runtime.getRuntime().maxMemory();
|
||||
if (maxMemory == Long.MAX_VALUE)
|
||||
maxMemory = 96*1024*1024l;
|
||||
long maxMemory = SystemVersion.getMaxMemory();
|
||||
long min = 128;
|
||||
long max = 4096;
|
||||
// 512 nominal for 128 MB
|
||||
|
@ -62,9 +62,7 @@ public final class ByteCache {
|
||||
*/
|
||||
private static final int MAX_CACHE;
|
||||
static {
|
||||
long maxMemory = Runtime.getRuntime().maxMemory();
|
||||
if (maxMemory == Long.MAX_VALUE)
|
||||
maxMemory = 96*1024*1024l;
|
||||
long maxMemory = SystemVersion.getMaxMemory();
|
||||
MAX_CACHE = (int) Math.min(4*1024*1024l, Math.max(128*1024l, maxMemory / 128));
|
||||
}
|
||||
|
||||
|
@ -58,9 +58,7 @@ public class SimpleScheduler {
|
||||
private SimpleScheduler(I2PAppContext context, String name) {
|
||||
_log = context.logManager().getLog(SimpleScheduler.class);
|
||||
_name = name;
|
||||
long maxMemory = Runtime.getRuntime().maxMemory();
|
||||
if (maxMemory == Long.MAX_VALUE)
|
||||
maxMemory = 96*1024*1024l;
|
||||
long maxMemory = SystemVersion.getMaxMemory();
|
||||
_threads = (int) Math.max(MIN_THREADS, Math.min(MAX_THREADS, 1 + (maxMemory / (32*1024*1024))));
|
||||
_executor = new ScheduledThreadPoolExecutor(_threads, new CustomThreadFactory());
|
||||
_executor.prestartAllCoreThreads();
|
||||
|
@ -61,9 +61,7 @@ public class SimpleTimer {
|
||||
runner.setName(name);
|
||||
runner.setDaemon(true);
|
||||
runner.start();
|
||||
long maxMemory = Runtime.getRuntime().maxMemory();
|
||||
if (maxMemory == Long.MAX_VALUE)
|
||||
maxMemory = 128*1024*1024l;
|
||||
long maxMemory = SystemVersion.getMaxMemory();
|
||||
int threads = (int) Math.max(MIN_THREADS, Math.min(MAX_THREADS, 1 + (maxMemory / (32*1024*1024))));
|
||||
for (int i = 1; i <= threads ; i++) {
|
||||
I2PThread executor = new I2PThread(new Executor(context, _log, _readyEvents, runn));
|
||||
|
@ -64,9 +64,7 @@ public class SimpleTimer2 {
|
||||
*/
|
||||
protected SimpleTimer2(I2PAppContext context, String name, boolean prestartAllThreads) {
|
||||
_name = name;
|
||||
long maxMemory = Runtime.getRuntime().maxMemory();
|
||||
if (maxMemory == Long.MAX_VALUE)
|
||||
maxMemory = 96*1024*1024l;
|
||||
long maxMemory = SystemVersion.getMaxMemory();
|
||||
_threads = (int) Math.max(MIN_THREADS, Math.min(MAX_THREADS, 1 + (maxMemory / (32*1024*1024))));
|
||||
_executor = new CustomScheduledThreadPoolExecutor(_threads, new CustomThreadFactory());
|
||||
if (prestartAllThreads)
|
||||
|
@ -126,4 +126,16 @@ public abstract class SystemVersion {
|
||||
public static boolean hasWrapper() {
|
||||
return _hasWrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Runtime.getRuntime().maxMemory() but check for
|
||||
* bogus values
|
||||
* @since 0.9.8
|
||||
*/
|
||||
public static long getMaxMemory() {
|
||||
long maxMemory = Runtime.getRuntime().maxMemory();
|
||||
if (maxMemory >= Long.MAX_VALUE / 2)
|
||||
maxMemory = 96*1024*1024l;
|
||||
return maxMemory;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user