+ // (absolute) jvmmaxmem setting, start with default
+ long memmax = MAX_HEAPSIZE_GB_DEFAULT * GIGABYTE;
+ if (jvmmemmaxarg == null)
+ {
+ jvmmemmaxarg = System.getProperty(MAX_HEAPSIZE_PROPERTY_NAME);
+ }
+ String jvmmemmax = jvmmemmaxarg;
+ if (jvmmemmax != null && jvmmemmax.length() > 0)
+ {
+ long multiplier = 1;
+ switch (jvmmemmax.toLowerCase().substring(jvmmemmax.length() - 1))
+ {
+ case "t":
+ multiplier = 1099511627776L; // 2^40
+ jvmmemmax = jvmmemmax.substring(0, jvmmemmax.length() - 1);
+ break;
+ case "g":
+ multiplier = 1073741824; // 2^30
+ jvmmemmax = jvmmemmax.substring(0, jvmmemmax.length() - 1);
+ break;
+ case "m":
+ multiplier = 1048576; // 2^20
+ jvmmemmax = jvmmemmax.substring(0, jvmmemmax.length() - 1);
+ break;
+ case "k":
+ multiplier = 1024; // 2^10
+ jvmmemmax = jvmmemmax.substring(0, jvmmemmax.length() - 1);
+ break;
+ case "b":
+ multiplier = 1; // 2^0
+ jvmmemmax = jvmmemmax.substring(0, jvmmemmax.length() - 1);
+ break;
+ default:
+ break;
+ }
+
+ // parse the arg
+ try
+ {
+ memmax = Long.parseLong(jvmmemmax);
+ } catch (NumberFormatException e)
+ {
+ memmax = MAX_HEAPSIZE_GB_DEFAULT * GIGABYTE;
+ System.out.println("MemorySetting Property '"
+ + MAX_HEAPSIZE_PROPERTY_NAME
+ + "' ("
+ + jvmmemmaxarg + "') badly formatted, using default ("
+ + MAX_HEAPSIZE_GB_DEFAULT + "g).");
+ }
+
+ // apply multiplier if not too big (i.e. bigger than a long)
+ if (Long.MAX_VALUE / memmax < multiplier)
+ {
+ memmax = MAX_HEAPSIZE_GB_DEFAULT * GIGABYTE;
+ System.out.println(
+ "MemorySetting Property '" + MAX_HEAPSIZE_PROPERTY_NAME + "' ("
+ + jvmmemmaxarg
+ + ") too big, using default ("
+ + MAX_HEAPSIZE_GB_DEFAULT + "g).");
+ }
+ else
+ {
+ memmax = multiplier * memmax;
+ }
+
+ // check at least minimum value (this accounts for negatives too)
+ if (memmax < APPLICATION_MIN_MEMORY)
+ {
+ memmax = APPLICATION_MIN_MEMORY;
+ System.out.println(
+ "MemorySetting Property '" + MAX_HEAPSIZE_PROPERTY_NAME + "' ("
+ + jvmmemmaxarg
+ + ") too small, using minimum ("
+ + APPLICATION_MIN_MEMORY + ").");
+ }
+
+ }
+ else
+ {
+ // no need to warn if no setting
+ // System.out.println("MemorySetting Property '" + maxHeapSizeProperty
+ // + "' not
+ // set.");
+ }
+
+ // get max percent of physical memory, starting with default
+ float percent = MAX_HEAPSIZE_PERCENT_DEFAULT;
+ if (jvmmempcarg == null)
+ {
+ jvmmempcarg = System.getProperty(MAX_HEAPSIZE_PERCENT_PROPERTY_NAME);
+ }
+ String jvmmempc = jvmmempcarg;
+ long mempc = -1;