more generics

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@4301 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 18 years ago
parent 88b2779787
commit f7c5ccedc7

@ -58,7 +58,6 @@ import de.anomic.server.serverFileUtils;
import de.anomic.server.serverMemory; import de.anomic.server.serverMemory;
import de.anomic.server.serverObjects; import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch; import de.anomic.server.serverSwitch;
//import de.anomic.kelondro.kelondroObjectSpace;
public class PerformanceMemory_p { public class PerformanceMemory_p {
@ -95,7 +94,7 @@ public class PerformanceMemory_p {
long memoryTotalAfterInitBGC = Long.parseLong(env.getConfig("memoryTotalAfterInitBGC", "0")); long memoryTotalAfterInitBGC = Long.parseLong(env.getConfig("memoryTotalAfterInitBGC", "0"));
long memoryTotalAfterInitAGC = Long.parseLong(env.getConfig("memoryTotalAfterInitAGC", "0")); long memoryTotalAfterInitAGC = Long.parseLong(env.getConfig("memoryTotalAfterInitAGC", "0"));
long memoryTotalAfterStartup = Long.parseLong(env.getConfig("memoryTotalAfterStartup", "0")); long memoryTotalAfterStartup = Long.parseLong(env.getConfig("memoryTotalAfterStartup", "0"));
long memoryMax = serverMemory.max; long memoryMax = Runtime.getRuntime().maxMemory();
prop.putNum("memoryMax", memoryMax / MB); prop.putNum("memoryMax", memoryMax / MB);
prop.putNum("memoryAvailAfterStartup", (memoryMax - memoryTotalAfterStartup + memoryFreeAfterStartup) / MB); prop.putNum("memoryAvailAfterStartup", (memoryMax - memoryTotalAfterStartup + memoryFreeAfterStartup) / MB);

@ -54,8 +54,8 @@ import de.anomic.http.httpdByteCountInputStream;
import de.anomic.http.httpdByteCountOutputStream; import de.anomic.http.httpdByteCountOutputStream;
import de.anomic.plasma.plasmaSwitchboard; import de.anomic.plasma.plasmaSwitchboard;
import de.anomic.server.serverCore; import de.anomic.server.serverCore;
import de.anomic.server.serverDomains;
import de.anomic.server.serverDate; import de.anomic.server.serverDate;
import de.anomic.server.serverDomains;
import de.anomic.server.serverMemory; import de.anomic.server.serverMemory;
import de.anomic.server.serverObjects; import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch; import de.anomic.server.serverSwitch;
@ -292,7 +292,7 @@ public class Status {
// memory usage and system attributes // memory usage and system attributes
prop.put("freeMemory", serverMemory.bytesToString(rt.freeMemory())); prop.put("freeMemory", serverMemory.bytesToString(rt.freeMemory()));
prop.put("totalMemory", serverMemory.bytesToString(rt.totalMemory())); prop.put("totalMemory", serverMemory.bytesToString(rt.totalMemory()));
prop.put("maxMemory", serverMemory.bytesToString(serverMemory.max)); prop.put("maxMemory", serverMemory.bytesToString(rt.maxMemory()));
prop.put("processors", rt.availableProcessors()); prop.put("processors", rt.availableProcessors());
// proxy traffic // proxy traffic

@ -40,13 +40,12 @@
package xml; package xml;
import de.anomic.http.httpHeader; import de.anomic.http.httpHeader;
import de.anomic.http.httpdByteCountInputStream;
import de.anomic.http.httpdByteCountOutputStream;
import de.anomic.plasma.plasmaSwitchboard; import de.anomic.plasma.plasmaSwitchboard;
import de.anomic.server.serverObjects; import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch; import de.anomic.server.serverSwitch;
import de.anomic.server.serverMemory;
import de.anomic.yacy.yacyCore; import de.anomic.yacy.yacyCore;
import de.anomic.http.httpdByteCountInputStream;
import de.anomic.http.httpdByteCountOutputStream;
public class status_p { public class status_p {
@ -75,7 +74,7 @@ public class status_p {
final Runtime rt = Runtime.getRuntime(); final Runtime rt = Runtime.getRuntime();
prop.putNum("freeMemory", rt.freeMemory()); prop.putNum("freeMemory", rt.freeMemory());
prop.putNum("totalMemory", rt.totalMemory()); prop.putNum("totalMemory", rt.totalMemory());
prop.putNum("maxMemory", serverMemory.max); prop.putNum("maxMemory", rt.maxMemory());
prop.putNum("processors", rt.availableProcessors()); prop.putNum("processors", rt.availableProcessors());
// proxy traffic // proxy traffic

@ -30,8 +30,6 @@ import de.anomic.tools.yFormatter;
public class serverMemory { public class serverMemory {
public static boolean vm14 = System.getProperty("java.vm.version").startsWith("1.4");
public static final long max = (vm14) ? computedMaxMemory() : Runtime.getRuntime().maxMemory() ; // patch for maxMemory bug in Java 1.4.2
private static final Runtime runtime = Runtime.getRuntime(); private static final Runtime runtime = Runtime.getRuntime();
private static final serverLog log = new serverLog("MEMORY"); private static final serverLog log = new serverLog("MEMORY");
@ -54,9 +52,9 @@ public class serverMemory {
/** @return the amount of freed bytes by a forced GC this method performes */ /** @return the amount of freed bytes by a forced GC this method performes */
private static long runGC(final boolean count) { private static long runGC(final boolean count) {
final long memnow = available(); final long memnow = runtime.maxMemory() - runtime.totalMemory() + runtime.freeMemory();
gc(1000, "serverMemory.runGC(...)"); gc(1000, "serverMemory.runGC(...)");
final long freed = available() - memnow; final long freed = runtime.maxMemory() - runtime.totalMemory() + runtime.freeMemory() - memnow;
if (count) { if (count) {
gcs[gcs_pos] = freed; gcs[gcs_pos] = freed;
gcs_pos = (gcs_pos + 1) % gcs.length; gcs_pos = (gcs_pos + 1) % gcs.length;
@ -96,19 +94,10 @@ public class serverMemory {
* @param gciffail if not enough memory is available, this parameter specifies whether to perform * @param gciffail if not enough memory is available, this parameter specifies whether to perform
* a Full GC to free enough RAM * a Full GC to free enough RAM
* @return whether enough RAM is available * @return whether enough RAM is available
* @deprecated use {@link serverMemory#request(long, boolean)} instead to enable the collection of
* heuristics about explicit usage of Full GCs.
*/ */
public static boolean available(long memory, boolean gciffail) {
if (available() >= memory) return true;
if (!gciffail) return false;
gc(4000, "serverMemory.available(...)");
return (available() >= memory);
}
public static long available() { public static long available() {
// memory that is available including increasing total memory up to maximum // memory that is available including increasing total memory up to maximum
return max - runtime.totalMemory() + runtime.freeMemory(); return runtime.maxMemory() - runtime.totalMemory() + runtime.freeMemory();
} }
/** /**
@ -131,7 +120,7 @@ public class serverMemory {
* @return whether enough memory could be freed (or is free) or not * @return whether enough memory could be freed (or is free) or not
*/ */
public static boolean request(final long size, final boolean force) { public static boolean request(final long size, final boolean force) {
long avail = available(); long avail = runtime.maxMemory() - runtime.totalMemory() + runtime.freeMemory();
if (avail >= size) return true; if (avail >= size) return true;
if (log.isFine()) { if (log.isFine()) {
String t = new Throwable("Stack trace").getStackTrace()[1].toString(); String t = new Throwable("Stack trace").getStackTrace()[1].toString();
@ -141,10 +130,10 @@ public class serverMemory {
if (force || avg == 0 || avg + avail >= size) { if (force || avg == 0 || avg + avail >= size) {
// this is only called if we expect that an allocation of <size> bytes would cause the jvm to call the GC anyway // this is only called if we expect that an allocation of <size> bytes would cause the jvm to call the GC anyway
final long freed = runGC(!force); final long freed = runGC(!force);
avail = available(); avail = runtime.maxMemory() - runtime.totalMemory() + runtime.freeMemory();
log.logInfo("performed " + ((force) ? "explicit" : "necessary") + " GC, freed " + (freed >> 10) log.logInfo("performed " + ((force) ? "explicit" : "necessary") + " GC, freed " + (freed >> 10)
+ " KB (requested/available/average: " + (size >> 10) + " / " + " KB (requested/available/average: "
+ (avail >> 10) + " / " + (avg >> 10) + " KB)"); + (size >> 10) + " / " + (avail >> 10) + " / " + (avg >> 10) + " KB)");
return avail >= size; return avail >= size;
} else { } else {
log.logInfo("former GCs indicate to not be able to free enough memory (requested/available/average: " log.logInfo("former GCs indicate to not be able to free enough memory (requested/available/average: "
@ -182,30 +171,11 @@ public class serverMemory {
} }
} }
private static int computedMaxMemory() {
// there is a bug in java 1.4.2 for maxMemory()
// see for bug description:
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4686462
// to get the correct maxMemory, we force a OutOfMemoryError here to measure the 'real' maxMemory()
int mb = 1024 * 1024;
byte[][] x = new byte[2048][];
for (int i = 0; i < x.length; i++) {
try {
x[i] = new byte[mb];
} catch (OutOfMemoryError e) {
x = null; // free memory
//System.out.println("* computed maxMemory = " + i + " mb");
return (int) Math.max(i * mb, Runtime.getRuntime().totalMemory());
}
}
return 2048 * mb;
}
public static void main(String[] args) { public static void main(String[] args) {
// try this with a jvm 1.4.2 and with a jvm 1.5 and compare results // try this with a jvm 1.4.2 and with a jvm 1.5 and compare results
int mb = 1024 * 1024; int mb = 1024 * 1024;
System.out.println("vm: " + System.getProperty("java.vm.version")); System.out.println("vm: " + System.getProperty("java.vm.version"));
System.out.println("computed max = " + (computedMaxMemory() / mb) + " mb"); System.out.println("computed max = " + (Runtime.getRuntime().maxMemory() / mb) + " mb");
int alloc = 10000; int alloc = 10000;
Runtime rt = Runtime.getRuntime(); Runtime rt = Runtime.getRuntime();
byte[][] x = new byte[100000][]; byte[][] x = new byte[100000][];

@ -81,7 +81,6 @@ import de.anomic.plasma.plasmaWordIndex;
import de.anomic.server.serverCore; import de.anomic.server.serverCore;
import de.anomic.server.serverDate; import de.anomic.server.serverDate;
import de.anomic.server.serverFileUtils; import de.anomic.server.serverFileUtils;
import de.anomic.server.serverMemory;
import de.anomic.server.serverSemaphore; import de.anomic.server.serverSemaphore;
import de.anomic.server.serverSystem; import de.anomic.server.serverSystem;
import de.anomic.server.logging.serverLog; import de.anomic.server.logging.serverLog;
@ -604,7 +603,7 @@ public final class yacy {
plasmaCrawlLURL minimizedUrlDB = new plasmaCrawlLURL(indexRoot2, 10000); plasmaCrawlLURL minimizedUrlDB = new plasmaCrawlLURL(indexRoot2, 10000);
Runtime rt = Runtime.getRuntime(); Runtime rt = Runtime.getRuntime();
int cacheMem = (int)(serverMemory.max-rt.totalMemory()); int cacheMem = (int)(rt.maxMemory() - rt.totalMemory());
if (cacheMem < 2048000) throw new OutOfMemoryError("Not enough memory available to start clean up."); if (cacheMem < 2048000) throw new OutOfMemoryError("Not enough memory available to start clean up.");
plasmaWordIndex wordIndex = new plasmaWordIndex(indexPrimaryRoot, indexSecondaryRoot, 10000, log); plasmaWordIndex wordIndex = new plasmaWordIndex(indexPrimaryRoot, indexSecondaryRoot, 10000, log);
@ -901,7 +900,6 @@ public final class yacy {
System.gc(); System.gc();
long startupMemFree = Runtime.getRuntime().freeMemory(); // the amount of free memory in the Java Virtual Machine long startupMemFree = Runtime.getRuntime().freeMemory(); // the amount of free memory in the Java Virtual Machine
long startupMemTotal = Runtime.getRuntime().totalMemory(); // the total amount of memory in the Java virtual machine; may vary over time long startupMemTotal = Runtime.getRuntime().totalMemory(); // the total amount of memory in the Java virtual machine; may vary over time
serverMemory.available(); // force initialization of class serverMemory
// go into headless awt mode // go into headless awt mode
System.setProperty("java.awt.headless", "true"); System.setProperty("java.awt.headless", "true");

Loading…
Cancel
Save