JAL-3477 A bit of refactoring for the better
authorBen Soares <bsoares@dundee.ac.uk>
Wed, 20 Nov 2019 13:11:07 +0000 (13:11 +0000)
committerBen Soares <bsoares@dundee.ac.uk>
Wed, 20 Nov 2019 13:11:07 +0000 (13:11 +0000)
getdown/lib/getdown-core.jar
getdown/lib/getdown-launcher-local.jar
getdown/lib/getdown-launcher.jar
getdown/src/getdown/core/src/main/java/jalview/bin/MemoryPercent.java
getdown/src/getdown/core/src/main/java/jalview/bin/MemorySetting.java
gradle.properties
j11lib/getdown-core.jar
j8lib/getdown-core.jar
src/jalview/bin/MemoryPercent.java
src/jalview/bin/MemorySetting.java

index 8ca010a..703b4ec 100644 (file)
Binary files a/getdown/lib/getdown-core.jar and b/getdown/lib/getdown-core.jar differ
index ab2a28a..fadb3df 100644 (file)
Binary files a/getdown/lib/getdown-launcher-local.jar and b/getdown/lib/getdown-launcher-local.jar differ
index f7ca0f8..400dedd 100644 (file)
Binary files a/getdown/lib/getdown-launcher.jar and b/getdown/lib/getdown-launcher.jar differ
index 90257d1..3288e66 100644 (file)
@@ -29,39 +29,4 @@ public class MemoryPercent
     return -1;
   }
 
-  public static long memPercentAmount(int percent)
-  {
-    return memPercentAmount((float)percent);
-  }
-  public static long memPercentAmount(float percent)
-  {
-    long memPercentAmount = -1;
-
-    long physicalMem = getPhysicalMemory();
-    if (physicalMem > MemorySetting.applicationMinMemory)
-    {
-      // try and set at least applicationMinMemory and thereafter ensure
-      // leaveFreeMinMemory is left for the OS
-
-      memPercentAmount = (long) ((physicalMem * percent) / 100F);
-
-      // check for memory left for OS
-      if (physicalMem - memPercentAmount < MemorySetting.leaveFreeMinMemory)
-      {
-        memPercentAmount = physicalMem - MemorySetting.leaveFreeMinMemory;
-      }
-
-      // check for minimum application memsize
-      if (memPercentAmount < MemorySetting.applicationMinMemory)
-      {
-        memPercentAmount = MemorySetting.applicationMinMemory;
-      }
-    } else {
-      // not enough memory for application, just try and grab what we can!
-      memPercentAmount = physicalMem;
-    }
-
-    return memPercentAmount;
-  }
-
 }
index 561fea5..f6924b9 100644 (file)
@@ -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
index 6119b45..1be3977 100644 (file)
@@ -65,7 +65,7 @@ getdown_txt_max_concurrent_downloads = 10
 # now got better defaults when not set
 #getdown_txt_jalview.jvmmempc = 90
 # now got better defaults when not set
-#getdown_txt_jalview.jvmmemmax = 2G
+#getdown_txt_jalview.jvmmemmax = 32G
 getdown_txt_multi_jvmarg = -Dgetdownappdir=%APPDIR%
 getdown_txt_strict_comments = true
 getdown_txt_title = Jalview
index 8ca010a..703b4ec 100644 (file)
Binary files a/j11lib/getdown-core.jar and b/j11lib/getdown-core.jar differ
index 8ca010a..703b4ec 100644 (file)
Binary files a/j8lib/getdown-core.jar and b/j8lib/getdown-core.jar differ
index 90257d1..3288e66 100644 (file)
@@ -29,39 +29,4 @@ public class MemoryPercent
     return -1;
   }
 
-  public static long memPercentAmount(int percent)
-  {
-    return memPercentAmount((float)percent);
-  }
-  public static long memPercentAmount(float percent)
-  {
-    long memPercentAmount = -1;
-
-    long physicalMem = getPhysicalMemory();
-    if (physicalMem > MemorySetting.applicationMinMemory)
-    {
-      // try and set at least applicationMinMemory and thereafter ensure
-      // leaveFreeMinMemory is left for the OS
-
-      memPercentAmount = (long) ((physicalMem * percent) / 100F);
-
-      // check for memory left for OS
-      if (physicalMem - memPercentAmount < MemorySetting.leaveFreeMinMemory)
-      {
-        memPercentAmount = physicalMem - MemorySetting.leaveFreeMinMemory;
-      }
-
-      // check for minimum application memsize
-      if (memPercentAmount < MemorySetting.applicationMinMemory)
-      {
-        memPercentAmount = MemorySetting.applicationMinMemory;
-      }
-    } else {
-      // not enough memory for application, just try and grab what we can!
-      memPercentAmount = physicalMem;
-    }
-
-    return memPercentAmount;
-  }
-
 }
index 561fea5..f6924b9 100644 (file)
@@ -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