< prev index next >

test/jtreg-ext/requires/VMProps.java

Print this page
rev 2714 : 8183534: [TEST] Make detection of compilation mode more robust
Reviewed-by: clanger, stuefe
   1 /*
   2  * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  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  */


  59     public Map<String, String> call() {
  60         Map<String, String> map = new HashMap<>();
  61         map.put("vm.flavor", vmFlavor());
  62         map.put("vm.compMode", vmCompMode());
  63         map.put("vm.bits", vmBits());
  64         map.put("vm.flightRecorder", vmFlightRecorder());
  65         map.put("vm.simpleArch", vmArch());
  66         map.put("vm.debug", vmDebug());
  67         map.put("vm.jvmci", vmJvmci());
  68         map.put("vm.emulatedClient", vmEmulatedClient());
  69         map.put("vm.cpu.features", cpuFeatures());
  70         map.put("vm.rtm.cpu", vmRTMCPU());
  71         map.put("vm.rtm.os", vmRTMOS());
  72         vmGC(map); // vm.gc.X = true/false
  73 
  74         VMProps.dump(map);
  75         return map;
  76     }
  77 
  78     /**













  79      * @return vm.simpleArch value of "os.simpleArch" property of tested JDK.
  80      */
  81     protected String vmArch() {
  82         String arch = System.getProperty("os.arch");
  83         if (arch.equals("x86_64") || arch.equals("amd64")) {
  84             return "x64";
  85         }
  86         else if (arch.contains("86")) {
  87             return "x86";
  88         } else {
  89             return arch;
  90         }
  91     }
  92 
  93 
  94 
  95     /**
  96      * @return VM type value extracted from the "java.vm.name" property.
  97      */
  98     protected String vmFlavor() {
  99         // E.g. "Java HotSpot(TM) 64-Bit Server VM"
 100         String vmName = System.getProperty("java.vm.name");
 101         if (vmName == null) {
 102             return null;
 103         }
 104 
 105         Pattern startP = Pattern.compile(".* (\\S+) VM");
 106         Matcher m = startP.matcher(vmName);
 107         if (m.matches()) {
 108             return m.group(1).toLowerCase();
 109         }
 110         return null;
 111     }
 112 
 113     /**
 114      * @return VM compilation mode extracted from the "java.vm.info" property.
 115      */
 116     protected String vmCompMode() {
 117         // E.g. "mixed mode"
 118         String vmInfo = System.getProperty("java.vm.info");
 119         if (vmInfo == null) {
 120             return null;
 121         }
 122         int k = vmInfo.toLowerCase().indexOf(" mode");
 123         if (k < 0) {
 124             return null;
 125         }
 126         vmInfo = vmInfo.substring(0, k);
 127         switch (vmInfo) {
 128             case "mixed" : return "Xmixed";
 129             case "compiled" : return "Xcomp";
 130             case "interpreted" : return "Xint";
 131             default: return null;


 132         }
 133     }
 134 
 135     /**
 136      * @return VM bitness, the value of the "sun.arch.data.model" property.
 137      */
 138     protected String vmBits() {
 139         return System.getProperty("sun.arch.data.model");





 140     }
 141 
 142     /**
 143      * @return "true" if Flight Recorder is enabled, "false" if is disabled.
 144      */
 145     protected String vmFlightRecorder() {
 146         Boolean isUnlockedCommercialFatures = WB.getBooleanVMFlag("UnlockCommercialFeatures");
 147         Boolean isFlightRecorder = WB.getBooleanVMFlag("FlightRecorder");
 148         String startFROptions = WB.getStringVMFlag("StartFlightRecording");
 149         if (isUnlockedCommercialFatures != null && isUnlockedCommercialFatures) {
 150             if (isFlightRecorder != null && isFlightRecorder) {
 151                 return "true";
 152             }
 153             if (startFROptions != null && !startFROptions.isEmpty()) {
 154                 return "true";
 155             }
 156         }
 157         return "false";
 158     }
 159 
 160     /**
 161      * @return debug level value extracted from the "jdk.debug" property.
 162      */
 163     protected String vmDebug() {
 164         return "" + System.getProperty("jdk.debug").contains("debug");





 165     }
 166 
 167     /**
 168      * @return true if VM supports JVMCI and false otherwise
 169      */
 170     protected String vmJvmci() {
 171         // builds with jvmci have this flag
 172         return "" + (WB.getBooleanVMFlag("EnableJVMCI") != null);
 173     }
 174 
 175     /**
 176      * @return true if VM runs in emulated-client mode and false otherwise.
 177      */
 178     protected String vmEmulatedClient() {
 179         String vmInfo = System.getProperty("java.vm.info");
 180         if (vmInfo == null) {
 181             return "false";
 182         }
 183         return "" + vmInfo.contains(" emulated-client");
 184     }


   1 /*
   2  * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  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  */


  59     public Map<String, String> call() {
  60         Map<String, String> map = new HashMap<>();
  61         map.put("vm.flavor", vmFlavor());
  62         map.put("vm.compMode", vmCompMode());
  63         map.put("vm.bits", vmBits());
  64         map.put("vm.flightRecorder", vmFlightRecorder());
  65         map.put("vm.simpleArch", vmArch());
  66         map.put("vm.debug", vmDebug());
  67         map.put("vm.jvmci", vmJvmci());
  68         map.put("vm.emulatedClient", vmEmulatedClient());
  69         map.put("vm.cpu.features", cpuFeatures());
  70         map.put("vm.rtm.cpu", vmRTMCPU());
  71         map.put("vm.rtm.os", vmRTMOS());
  72         vmGC(map); // vm.gc.X = true/false
  73 
  74         VMProps.dump(map);
  75         return map;
  76     }
  77 
  78     /**
  79      * Prints a stack trace before returning null.
  80      * Used by the various helper functions which parse information from
  81      * VM properties in the case where they don't find an expected property
  82      * or a propoerty doesn't conform to an expected format.
  83      *
  84      * @return null
  85      */
  86     private String nullWithException(String message) {
  87         new Exception(message).printStackTrace();
  88         return null;
  89     }
  90 
  91     /**
  92      * @return vm.simpleArch value of "os.simpleArch" property of tested JDK.
  93      */
  94     protected String vmArch() {
  95         String arch = System.getProperty("os.arch");
  96         if (arch.equals("x86_64") || arch.equals("amd64")) {
  97             return "x64";
  98         }
  99         else if (arch.contains("86")) {
 100             return "x86";
 101         } else {
 102             return arch;
 103         }
 104     }
 105 
 106 
 107 
 108     /**
 109      * @return VM type value extracted from the "java.vm.name" property.
 110      */
 111     protected String vmFlavor() {
 112         // E.g. "Java HotSpot(TM) 64-Bit Server VM"
 113         String vmName = System.getProperty("java.vm.name");
 114         if (vmName == null) {
 115             return nullWithException("Can't get 'java.vm.name' property");
 116         }
 117 
 118         Pattern startP = Pattern.compile(".* (\\S+) VM");
 119         Matcher m = startP.matcher(vmName);
 120         if (m.matches()) {
 121             return m.group(1).toLowerCase();
 122         }
 123         return nullWithException("Can't get VM flavor from 'java.vm.name'");
 124     }
 125 
 126     /**
 127      * @return VM compilation mode extracted from the "java.vm.info" property.
 128      */
 129     protected String vmCompMode() {
 130         // E.g. "mixed mode"
 131         String vmInfo = System.getProperty("java.vm.info");
 132         if (vmInfo == null) {
 133             return nullWithException("Can't get 'java.vm.info' property");




 134         }
 135         if (vmInfo.toLowerCase().indexOf("mixed mode") != -1) {
 136             return "Xmixed";
 137         } else if (vmInfo.toLowerCase().indexOf("compiled mode") != -1) {
 138             return "Xcomp";
 139         } else if (vmInfo.toLowerCase().indexOf("interpreted mode") != -1) {
 140             return "Xint";
 141         } else {
 142             return nullWithException("Can't get compilation mode from 'java.vm.info'");
 143         }
 144     }
 145 
 146     /**
 147      * @return VM bitness, the value of the "sun.arch.data.model" property.
 148      */
 149     protected String vmBits() {
 150         String dataModel = System.getProperty("sun.arch.data.model");
 151         if (dataModel != null) {
 152             return dataModel;
 153         } else {
 154             return nullWithException("Can't get 'sun.arch.data.model' property");
 155         }
 156     }
 157 
 158     /**
 159      * @return "true" if Flight Recorder is enabled, "false" if is disabled.
 160      */
 161     protected String vmFlightRecorder() {
 162         Boolean isUnlockedCommercialFatures = WB.getBooleanVMFlag("UnlockCommercialFeatures");
 163         Boolean isFlightRecorder = WB.getBooleanVMFlag("FlightRecorder");
 164         String startFROptions = WB.getStringVMFlag("StartFlightRecording");
 165         if (isUnlockedCommercialFatures != null && isUnlockedCommercialFatures) {
 166             if (isFlightRecorder != null && isFlightRecorder) {
 167                 return "true";
 168             }
 169             if (startFROptions != null && !startFROptions.isEmpty()) {
 170                 return "true";
 171             }
 172         }
 173         return "false";
 174     }
 175 
 176     /**
 177      * @return debug level value extracted from the "jdk.debug" property.
 178      */
 179     protected String vmDebug() {
 180         String debug = System.getProperty("jdk.debug");
 181         if (debug != null) {
 182             return "" + debug.contains("debug");
 183         } else {
 184             return nullWithException("Can't get 'jdk.debug' property");
 185         }
 186     }
 187 
 188     /**
 189      * @return true if VM supports JVMCI and false otherwise
 190      */
 191     protected String vmJvmci() {
 192         // builds with jvmci have this flag
 193         return "" + (WB.getBooleanVMFlag("EnableJVMCI") != null);
 194     }
 195 
 196     /**
 197      * @return true if VM runs in emulated-client mode and false otherwise.
 198      */
 199     protected String vmEmulatedClient() {
 200         String vmInfo = System.getProperty("java.vm.info");
 201         if (vmInfo == null) {
 202             return "false";
 203         }
 204         return "" + vmInfo.contains(" emulated-client");
 205     }


< prev index next >