maxMemory() fixes for silly GNU returning Long.MAX_VALUE

This commit is contained in:
zzz
2011-03-20 18:14:30 +00:00
parent fa8f2290af
commit bfb4560dc2
17 changed files with 45 additions and 4 deletions

View File

@ -82,7 +82,9 @@ public class DHSessionKeyBuilder {
// add to the defaults for every 128MB of RAM, up to 512MB
long maxMemory = Runtime.getRuntime().maxMemory();
int factor = Math.min(4, (int) (1 + (maxMemory / (128*1024*1024l))));
if (maxMemory == Long.MAX_VALUE)
maxMemory = 127*1024*1024l;
int factor = (int) Math.max(1l, Math.min(4l, 1 + (maxMemory / (128*1024*1024l))));
int defaultMin = DEFAULT_DH_PRECALC_MIN * factor;
int defaultMax = DEFAULT_DH_PRECALC_MAX * factor;
MIN_NUM_BUILDERS = ctx.getProperty(PROP_DH_PRECALC_MIN, defaultMin);

View File

@ -60,7 +60,9 @@ class YKGenerator {
// add to the defaults for every 128MB of RAM, up to 1GB
long maxMemory = Runtime.getRuntime().maxMemory();
int factor = Math.min(8, (int) (1 + (maxMemory / (128*1024*1024l))));
if (maxMemory == Long.MAX_VALUE)
maxMemory = 127*1024*1024l;
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;
MIN_NUM_BUILDERS = ctx.getProperty(PROP_YK_PRECALC_MIN, defaultMin);

View File

@ -1195,6 +1195,10 @@ public class DataHelper {
case 2: return str + "M";
case 3: return str + "G";
case 4: return str + "T";
case 5: return str + "P";
case 6: return str + "E";
case 7: return str + "Z";
case 8: return str + "Y";
default: return bytes + "";
}
}
@ -1221,12 +1225,17 @@ public class DataHelper {
case 2: return str + " M";
case 3: return str + " G";
case 4: return str + " T";
case 5: return str + " P";
case 6: return str + " E";
case 7: return str + " Z";
case 8: return str + " Y";
default: return bytes + " ";
}
}
/**
* Strip out any HTML (simply removing any less than / greater than symbols)
* @param orig may be null, returns empty string if null
*/
public static String stripHTML(String orig) {
if (orig == null) return "";

View File

@ -52,7 +52,8 @@ 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;
private static final boolean CACHE_ALL = Runtime.getRuntime().maxMemory() > 128*1024*1024l &&
Runtime.getRuntime().maxMemory() < Long.MAX_VALUE;
public static final String PROP_NETWORK_ID = "netId";
public static final String PROP_CAPABILITIES = "caps";

View File

@ -50,6 +50,8 @@ public class SDSCache<V extends SimpleDataStructure> {
private static final double FACTOR;
static {
long maxMemory = Runtime.getRuntime().maxMemory();
if (maxMemory == Long.MAX_VALUE)
maxMemory = 96*1024*1024l;
FACTOR = Math.max(MIN_FACTOR, Math.min(MAX_FACTOR, maxMemory / (128*1024*1024d)));
}

View File

@ -69,6 +69,8 @@ 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;
MAX_CACHE = (int) Math.min(4*1024*1024l, Math.max(128*1024l, maxMemory / 128));
}

View File

@ -43,6 +43,8 @@ public class SimpleScheduler {
_log = _context.logManager().getLog(SimpleScheduler.class);
_name = name;
long maxMemory = Runtime.getRuntime().maxMemory();
if (maxMemory == Long.MAX_VALUE)
maxMemory = 96*1024*1024l;
_threads = (int) Math.max(MIN_THREADS, Math.min(MAX_THREADS, 1 + (maxMemory / (32*1024*1024))));
_executor = new ScheduledThreadPoolExecutor(_threads, new CustomThreadFactory());
_executor.prestartAllCoreThreads();

View File

@ -44,6 +44,8 @@ public class SimpleTimer {
runner.setDaemon(true);
runner.start();
long maxMemory = Runtime.getRuntime().maxMemory();
if (maxMemory == Long.MAX_VALUE)
maxMemory = 128*1024*1024l;
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));

View File

@ -43,6 +43,8 @@ public class SimpleTimer2 {
_name = name;
_count = 0;
long maxMemory = Runtime.getRuntime().maxMemory();
if (maxMemory == Long.MAX_VALUE)
maxMemory = 96*1024*1024l;
_threads = (int) Math.max(MIN_THREADS, Math.min(MAX_THREADS, 1 + (maxMemory / (32*1024*1024))));
_executor = new CustomScheduledThreadPoolExecutor(_threads, new CustomThreadFactory());
_executor.prestartAllCoreThreads();