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);
}
// 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 + ").");
}
}
// 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);
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;
return maxMemLong;
}
-}
+}
\ No newline at end of file