+ return getMemorySetting(null, null);
+ }
+
+ public static long getMemorySetting(String jvmmemmaxarg,
+ String jvmmempcarg)
+ {
+ return getMemorySetting(jvmmemmaxarg, jvmmempcarg, true, false);
+ }
+
+ /**
+ * Decide on appropriate memory setting for Jalview based on the two arguments
+ * values: jvmmempc - the maximum percentage of total physical memory to
+ * allocate, and jvmmemmax - the maximum absolute amount of physical memory to
+ * allocate. These can be provided as arguments. If not provided as arguments
+ * (or set as null) system properties will be used instead (if set). The
+ * memory setting returned will be the lower of the two values. If either of
+ * the values are not provided then defaults will be used (jvmmempc=90,
+ * jvmmemmax=32GB). If total physical memory can't be ascertained when
+ * jvmmempc was set or neither jvmmempc nor jvmmemmax were set, then jvmmemmax
+ * defaults to a much safer 8GB. In this case explicitly setting jvmmemmax and
+ * not setting jvmmempc can set a higher memory for Jalview. The calculation
+ * also tries to ensure 0.5GB memory for the OS, but also tries to ensure at
+ * least 0.5GB memory for Jalview (which takes priority over the OS) If there
+ * is less then 0.5GB of physical memory then the total physical memory is
+ * used for Jalview.
+ *
+ * @param jvmmemmaxarg
+ * Maximum value of memory to set. This can be a numeric string
+ * optionally followed by "b", "k", "m", "g", "t" (case insensitive)
+ * to indicate bytes, kilobytes, megabytes, gigabytes, terabytes
+ * respectively. If null a default value of 32G will be used. If null
+ * and either physical memory can't be determined then the default is
+ * 8GB.
+ * @param jvmmempcarg
+ * Max percentage of physical memory to use. Defaults to "90".
+ *
+ * @param useProps
+ * boolean to decide whether to look at System properties.
+ *
+ * @return The amount of memory (in bytes) to allocate to Jalview
+ */
+ public static long getMemorySetting(String jvmmemmaxarg,
+ String jvmmempcarg, boolean useProps, boolean quiet)
+ {
+ // actual Xmx value-to-be
+ long maxMemLong = -1;
+ clearAdjustmentMessage();
+
+ // (absolute) jvmmaxmem setting, start with default
+ long memmax = MAX_HEAPSIZE_GB_DEFAULT * GIGABYTE;
+ if (jvmmemmaxarg == null && useProps)
+ {
+ jvmmemmaxarg = System.getProperty(MAX_HEAPSIZE_PROPERTY_NAME);
+ }
+ String jvmmemmax = jvmmemmaxarg;
+ if (jvmmemmax != null && jvmmemmax.length() > 0)
+ {
+ // parse the arg
+ try
+ {
+ memmax = memoryStringToLong(jvmmemmax);
+ if (memmax == 0)
+ {
+ throw (new NumberFormatException("Not allowing 0"));
+ }
+ } catch (NumberFormatException e)
+ {
+ memmax = MAX_HEAPSIZE_GB_DEFAULT * GIGABYTE;
+ setAdjustmentMessage("MemorySetting Property '"
+ + MAX_HEAPSIZE_PROPERTY_NAME + "' (" + jvmmemmaxarg
+ + "') badly formatted or 0, using default ("
+ + MAX_HEAPSIZE_GB_DEFAULT + "g).", quiet);
+ }
+
+ // check at least minimum value (this accounts for negatives too)
+ if (memmax < APPLICATION_MIN_MEMORY)
+ {
+ memmax = APPLICATION_MIN_MEMORY;
+ setAdjustmentMessage("MemorySetting Property '"
+ + MAX_HEAPSIZE_PROPERTY_NAME + "' (" + jvmmemmaxarg
+ + ") too small, using minimum (" + APPLICATION_MIN_MEMORY
+ + ").", quiet);
+ }