X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=getdown%2Fsrc%2Fgetdown%2Fcore%2Fsrc%2Fmain%2Fjava%2Fjalview%2Fbin%2FMemorySetting.java;fp=getdown%2Fsrc%2Fgetdown%2Fcore%2Fsrc%2Fmain%2Fjava%2Fjalview%2Fbin%2FMemorySetting.java;h=f6924b9b9cdfb6369288aaaee05f48efe8acd918;hb=38120f6e0031a59b21cd4ae9c94c9e83f1ebc6cd;hp=561fea58116afd92be2da9cf09caadf82bf6e8d9;hpb=390934f61c1d821fadb030f5541b1a061d1952dc;p=jalview.git diff --git a/getdown/src/getdown/core/src/main/java/jalview/bin/MemorySetting.java b/getdown/src/getdown/core/src/main/java/jalview/bin/MemorySetting.java index 561fea5..f6924b9 100644 --- a/getdown/src/getdown/core/src/main/java/jalview/bin/MemorySetting.java +++ b/getdown/src/getdown/core/src/main/java/jalview/bin/MemorySetting.java @@ -23,15 +23,14 @@ public class MemorySetting return getMemorySetting(null, null); } - public static long getMemorySetting(String jvmmemmaxString, - String jvmmempcString) + public static long getMemorySetting(String jvmmemmaxorig, + String jvmmempcorig) { // actual Xmx value-to-be long maxMemLong = -1; // get (absolute) jvmmaxmem setting long memmax = maxHeapSizeDefault; - String jvmmemmaxorig = jvmmemmaxString; if (jvmmemmaxorig == null) { jvmmemmaxorig = System.getProperty(maxHeapSizeProperty); @@ -95,13 +94,14 @@ public class MemorySetting } // check at least minimum value (this accounts for negatives too) - if (memmax < MemorySetting.applicationMinMemory) + if (memmax < applicationMinMemory) { - memmax = MemorySetting.applicationMinMemory; + memmax = applicationMinMemory; System.out.println( "MemorySetting Property '" + maxHeapSizeProperty + "' (" + jvmmemmaxorig - + ") too small, using minimum (" + memmax + ")."); + + ") too small, using minimum (" + + applicationMinMemory + ")."); } } @@ -115,7 +115,11 @@ public class MemorySetting // get max percent of physical memory float percent = maxHeapSizePerCentDefault; - String jvmmempc = jvmmempcString; + if (jvmmempcorig == null) + { + jvmmempcorig = System.getProperty(maxHeapSizePerCentProperty); + } + String jvmmempc = jvmmempcorig; if (jvmmempc == null) { jvmmempc = System.getProperty(maxHeapSizePerCentProperty); @@ -148,7 +152,44 @@ public class MemorySetting boolean memoryPercentError = false; try { - pcmem = MemoryPercent.memPercentAmount(percent); + long physicalMem = MemoryPercent.getPhysicalMemory(); + if (physicalMem > applicationMinMemory) + { + // try and set at least applicationMinMemory and thereafter ensure + // leaveFreeMinMemory is left for the OS + + pcmem = (long) ((physicalMem * percent) / 100F); + + // check for memory left for OS + if (physicalMem - pcmem < leaveFreeMinMemory) + { + pcmem = physicalMem - leaveFreeMinMemory; + System.out.println("MemorySetting Property '" + + maxHeapSizePerCentProperty + "' (" + jvmmempcorig + + ") too large. Leaving free space for OS, using (" + + pcmem + ")."); + } + + // check for minimum application memsize + if (pcmem < applicationMinMemory) + { + pcmem = applicationMinMemory; + System.out.println("MemorySetting Property '" + + maxHeapSizePerCentProperty + "' (" + jvmmempcorig + + ") too small, using minimum (" + applicationMinMemory + + ")."); + } + } + else + { + // not enough memory for application, just try and grab what we can! + pcmem = physicalMem; + System.out.println("MemorySetting Property '" + + maxHeapSizePerCentProperty + "' (" + jvmmempcorig + + "): Not enough memory, using max available (" + pcmem + + ")."); + } + } catch (Throwable t) { memoryPercentError = true; @@ -178,4 +219,4 @@ public class MemorySetting return maxMemLong; } -} +} \ No newline at end of file