test/runtime/CommandLine/OptionsValidation/common/optionsvalidation/JVMOptionsUtils.java
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File webrev Sdiff test/runtime/CommandLine/OptionsValidation/common/optionsvalidation

test/runtime/CommandLine/OptionsValidation/common/optionsvalidation/JVMOptionsUtils.java

Print this page




  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 package optionsvalidation;
  25 
  26 import java.io.BufferedReader;
  27 import java.io.IOException;
  28 import java.io.InputStreamReader;
  29 import java.io.Reader;

  30 import java.util.ArrayList;
  31 import java.util.Arrays;
  32 import java.util.List;
  33 import java.util.LinkedHashMap;
  34 import java.util.Map;
  35 import java.util.StringTokenizer;
  36 import java.util.function.Predicate;
  37 import jdk.test.lib.OutputAnalyzer;
  38 import jdk.test.lib.Platform;
  39 import jdk.test.lib.ProcessTools;
  40 
  41 public class JVMOptionsUtils {
  42 
  43     /* Java option which print options with ranges */
  44     private static final String PRINT_FLAGS_RANGES = "-XX:+PrintFlagsRanges";
  45 
  46     /* StringBuilder to accumulate failed message */
  47     private static final StringBuilder finalFailedMessage = new StringBuilder();
  48 
  49     /* Used to start the JVM with the same type as current */
  50     static String VMType;
  51 


  52     static {
  53         if (Platform.isServer()) {
  54             VMType = "-server";
  55         } else if (Platform.isClient()) {
  56             VMType = "-client";
  57         } else if (Platform.isMinimal()) {
  58             VMType = "-minimal";
  59         } else if (Platform.isGraal()) {
  60             VMType = "-graal";
  61         } else {
  62             VMType = null;
  63         }
  64     }
  65 














































































  66     /**
  67      * Add dependency for option depending on it's name. E.g. enable G1 GC for
  68      * G1 options or add prepend options to not hit constraints.
  69      *
  70      * @param option option
  71      */
  72     private static void addNameDependency(JVMOption option) {
  73         String name = option.getName();
  74 
  75         if (name.startsWith("G1")) {
  76             option.addPrepend("-XX:+UseG1GC");
  77         }
  78 
  79         if (name.startsWith("CMS")) {
  80             option.addPrepend("-XX:+UseConcMarkSweepGC");
  81         }
  82 




  83         switch (name) {
  84             case "MinHeapFreeRatio":
  85                 option.addPrepend("-XX:MaxHeapFreeRatio=100");
  86                 break;
  87             case "MaxHeapFreeRatio":
  88                 option.addPrepend("-XX:MinHeapFreeRatio=0");
  89                 break;
  90             case "MinMetaspaceFreeRatio":
  91                 option.addPrepend("-XX:MaxMetaspaceFreeRatio=100");
  92                 break;
  93             case "MaxMetaspaceFreeRatio":
  94                 option.addPrepend("-XX:MinMetaspaceFreeRatio=0");
  95                 break;
  96             case "CMSOldPLABMin":
  97                 option.addPrepend("-XX:CMSOldPLABMax=" + option.getMax());
  98                 break;
  99             case "CMSOldPLABMax":
 100                 option.addPrepend("-XX:CMSOldPLABMin=" + option.getMin());
 101                 break;
 102             case "CMSPrecleanNumerator":
 103                 option.addPrepend("-XX:CMSPrecleanDenominator=" + option.getMax());
 104                 break;
 105             case "CMSPrecleanDenominator":
 106                 option.addPrepend("-XX:CMSPrecleanNumerator=" + ((new Integer(option.getMin())) - 1));
 107                 break;
 108             case "InitialTenuringThreshold":
 109                 option.addPrepend("-XX:MaxTenuringThreshold=" + option.getMax());
 110                 break;
 111             default:
 112                 /* Do nothing */
 113                 break;
 114         }
 115 
 116     }
 117 
 118     /**
 119      * Parse JVM Options. Get input from "inputReader". Parse using
 120      * "-XX:+PrintFlagsRanges" output format.
 121      *
 122      * @param inputReader input data for parsing
 123      * @param withRanges true if needed options with defined ranges inside JVM
 124      * @param acceptOrigin predicate for option origins. Origins can be
 125      * "product", "diagnostic" etc. Accept option only if acceptOrigin evaluates
 126      * to true.
 127      * @return map from option name to the JVMOption object
 128      * @throws IOException if an error occurred while reading the data
 129      */
 130     private static Map<String, JVMOption> getJVMOptions(Reader inputReader,
 131             boolean withRanges, Predicate<String> acceptOrigin) throws IOException {
 132         BufferedReader reader = new BufferedReader(inputReader);
 133         String type;
 134         String line;
 135         String token;




  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 package optionsvalidation;
  25 
  26 import java.io.BufferedReader;
  27 import java.io.IOException;
  28 import java.io.InputStreamReader;
  29 import java.io.Reader;
  30 import java.math.BigDecimal;
  31 import java.util.ArrayList;
  32 import java.util.Arrays;
  33 import java.util.List;
  34 import java.util.LinkedHashMap;
  35 import java.util.Map;
  36 import java.util.StringTokenizer;
  37 import java.util.function.Predicate;
  38 import jdk.test.lib.OutputAnalyzer;
  39 import jdk.test.lib.Platform;
  40 import jdk.test.lib.ProcessTools;
  41 
  42 public class JVMOptionsUtils {
  43 
  44     /* Java option which print options with ranges */
  45     private static final String PRINT_FLAGS_RANGES = "-XX:+PrintFlagsRanges";
  46 
  47     /* StringBuilder to accumulate failed message */
  48     private static final StringBuilder finalFailedMessage = new StringBuilder();
  49 
  50     /* Used to start the JVM with the same type as current */
  51     static String VMType;
  52 
  53     private static Map<String, JVMOption> optionsAsMap;
  54 
  55     static {
  56         if (Platform.isServer()) {
  57             VMType = "-server";
  58         } else if (Platform.isClient()) {
  59             VMType = "-client";
  60         } else if (Platform.isMinimal()) {
  61             VMType = "-minimal";
  62         } else if (Platform.isGraal()) {
  63             VMType = "-graal";
  64         } else {
  65             VMType = null;
  66         }
  67     }
  68 
  69     public static boolean fitsRange(String optionName, BigDecimal number) throws Exception {
  70         JVMOption option;
  71         String minRangeString = null;
  72         String maxRangeString = null;
  73         boolean fits = true;
  74 
  75         if (optionsAsMap == null) {
  76             optionsAsMap = getOptionsWithRangeAsMap();
  77         }
  78 
  79         option = optionsAsMap.get(optionName);
  80         if (option != null) {
  81             minRangeString = option.getMin();
  82             if (minRangeString != null) {
  83                 fits = (number.compareTo(new BigDecimal(minRangeString)) >= 0);
  84             }
  85             maxRangeString = option.getMax();
  86             if (maxRangeString != null) {
  87                 fits &= (number.compareTo(new BigDecimal(maxRangeString)) <= 0);
  88             }
  89         }
  90 
  91         return fits;
  92     }
  93 
  94     public static boolean fitsRange(String optionName, String number) throws Exception {
  95         String lowerCase = number.toLowerCase();
  96         String multiplier = "1";
  97         if (lowerCase.endsWith("k")) {
  98             multiplier = "1024";
  99             lowerCase = lowerCase.substring(0, lowerCase.length()-1);
 100         } else if (lowerCase.endsWith("m")) {
 101             multiplier = "1048576"; //1024*1024
 102             lowerCase = lowerCase.substring(0, lowerCase.length()-1);
 103         } else if (lowerCase.endsWith("g")) {
 104             multiplier = "1073741824"; //1024*1024*1024
 105             lowerCase = lowerCase.substring(0, lowerCase.length()-1);
 106         } else if (lowerCase.endsWith("t")) {
 107             multiplier = "1099511627776"; //1024*1024*1024*1024
 108             lowerCase = lowerCase.substring(0, lowerCase.length()-1);
 109         }
 110         BigDecimal valueBig = new BigDecimal(lowerCase);
 111         BigDecimal multiplierBig = new BigDecimal(multiplier);
 112         return fitsRange(optionName, valueBig.multiply(multiplierBig));
 113     }
 114 
 115     public static String getMinOptionRange(String optionName) throws Exception {
 116         JVMOption option;
 117         String minRange = null;
 118 
 119         if (optionsAsMap == null) {
 120             optionsAsMap = getOptionsWithRangeAsMap();
 121         }
 122 
 123         option = optionsAsMap.get(optionName);
 124         if (option != null) {
 125             minRange = option.getMin();
 126         }
 127 
 128         return minRange;
 129     }
 130 
 131     public static String getMaxOptionRange(String optionName) throws Exception {
 132         JVMOption option;
 133         String maxRange = null;
 134 
 135         if (optionsAsMap == null) {
 136             optionsAsMap = getOptionsWithRangeAsMap();
 137         }
 138 
 139         option = optionsAsMap.get(optionName);
 140         if (option != null) {
 141             maxRange = option.getMax();
 142         }
 143 
 144         return maxRange;
 145     }
 146 
 147     /**
 148      * Add dependency for option depending on it's name. E.g. enable G1 GC for
 149      * G1 options or add prepend options to not hit constraints.
 150      *
 151      * @param option option
 152      */
 153     private static void addNameDependency(JVMOption option) {
 154         String name = option.getName();
 155 
 156         if (name.startsWith("G1")) {
 157             option.addPrepend("-XX:+UseG1GC");
 158         }
 159 
 160         if (name.startsWith("CMS")) {
 161             option.addPrepend("-XX:+UseConcMarkSweepGC");
 162         }
 163 
 164         if (name.startsWith("Shared")) {
 165             option.addPrepend("-Xshare:dump");
 166         }
 167 
 168         switch (name) {
 169             case "MinHeapFreeRatio":
 170                 option.addPrepend("-XX:MaxHeapFreeRatio=100");
 171                 break;
 172             case "MaxHeapFreeRatio":
 173                 option.addPrepend("-XX:MinHeapFreeRatio=0");
 174                 break;
 175             case "MinMetaspaceFreeRatio":
 176                 option.addPrepend("-XX:MaxMetaspaceFreeRatio=100");
 177                 break;
 178             case "MaxMetaspaceFreeRatio":
 179                 option.addPrepend("-XX:MinMetaspaceFreeRatio=0");
 180                 break;
 181             case "CMSOldPLABMin":
 182                 option.addPrepend("-XX:CMSOldPLABMax=" + option.getMax());
 183                 break;
 184             case "CMSOldPLABMax":
 185                 option.addPrepend("-XX:CMSOldPLABMin=" + option.getMin());
 186                 break;
 187             case "CMSPrecleanNumerator":
 188                 option.addPrepend("-XX:CMSPrecleanDenominator=" + option.getMax());
 189                 break;
 190             case "CMSPrecleanDenominator":
 191                 option.addPrepend("-XX:CMSPrecleanNumerator=" + ((new Integer(option.getMin())) - 1));
 192                 break;
 193             case "InitialTenuringThreshold":
 194                 option.addPrepend("-XX:MaxTenuringThreshold=" + option.getMax());
 195                 break;
 196             default:
 197                 /* Do nothing */
 198                 break;
 199         }

 200     }
 201 
 202     /**
 203      * Parse JVM Options. Get input from "inputReader". Parse using
 204      * "-XX:+PrintFlagsRanges" output format.
 205      *
 206      * @param inputReader input data for parsing
 207      * @param withRanges true if needed options with defined ranges inside JVM
 208      * @param acceptOrigin predicate for option origins. Origins can be
 209      * "product", "diagnostic" etc. Accept option only if acceptOrigin evaluates
 210      * to true.
 211      * @return map from option name to the JVMOption object
 212      * @throws IOException if an error occurred while reading the data
 213      */
 214     private static Map<String, JVMOption> getJVMOptions(Reader inputReader,
 215             boolean withRanges, Predicate<String> acceptOrigin) throws IOException {
 216         BufferedReader reader = new BufferedReader(inputReader);
 217         String type;
 218         String line;
 219         String token;


test/runtime/CommandLine/OptionsValidation/common/optionsvalidation/JVMOptionsUtils.java
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File