< prev index next >

test/jtreg-ext/requires/VMProps.java

Print this page




   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  */
  23 package requires;
  24 


  25 import java.io.IOException;

  26 import java.nio.file.Files;
  27 import java.nio.file.Path;
  28 import java.nio.file.Paths;
  29 import java.nio.file.StandardOpenOption;
  30 import java.util.ArrayList;
  31 import java.util.HashMap;
  32 import java.util.List;
  33 import java.util.Map;

  34 import java.util.concurrent.Callable;
  35 import java.util.concurrent.TimeUnit;
  36 import java.util.regex.Matcher;
  37 import java.util.regex.Pattern;
  38 
  39 import sun.hotspot.cpuinfo.CPUInfo;
  40 import sun.hotspot.gc.GC;
  41 import sun.hotspot.WhiteBox;
  42 import jdk.test.lib.Platform;
  43 
  44 /**
  45  * The Class to be invoked by jtreg prior Test Suite execution to
  46  * collect information about VM.
  47  * Do not use any API's that may not be available in all target VMs.
  48  * Properties set by this Class will be available in the @requires expressions.
  49  */
  50 public class VMProps implements Callable<Map<String, String>> {
  51 
  52     private static final WhiteBox WB = WhiteBox.getWhiteBox();
  53 


  62         Map<String, String> map = new HashMap<>();
  63         map.put("vm.flavor", vmFlavor());
  64         map.put("vm.compMode", vmCompMode());
  65         map.put("vm.bits", vmBits());
  66         map.put("vm.flightRecorder", vmFlightRecorder());
  67         map.put("vm.simpleArch", vmArch());
  68         map.put("vm.debug", vmDebug());
  69         map.put("vm.jvmci", vmJvmci());
  70         map.put("vm.emulatedClient", vmEmulatedClient());
  71         map.put("vm.cpu.features", cpuFeatures());
  72         map.put("vm.rtm.cpu", vmRTMCPU());
  73         map.put("vm.rtm.os", vmRTMOS());
  74         map.put("vm.aot", vmAOT());
  75         // vm.cds is true if the VM is compiled with cds support.
  76         map.put("vm.cds", vmCDS());
  77         map.put("vm.cds.custom.loaders", vmCDSForCustomLoaders());
  78         map.put("vm.cds.archived.java.heap", vmCDSForArchivedJavaHeap());
  79         // vm.graal.enabled is true if Graal is used as JIT
  80         map.put("vm.graal.enabled", isGraalEnabled());
  81         map.put("docker.support", dockerSupport());

  82         vmGC(map); // vm.gc.X = true/false
  83         vmOptFinalFlags(map);
  84 
  85         VMProps.dump(map);
  86         return map;
  87     }
  88 
  89     /**
  90      * Prints a stack trace before returning null.
  91      * Used by the various helper functions which parse information from
  92      * VM properties in the case where they don't find an expected property
  93      * or a propoerty doesn't conform to an expected format.
  94      *
  95      * @return null
  96      */
  97     private String nullWithException(String message) {
  98         new Exception(message).printStackTrace();
  99         return null;
 100     }
 101 


 403 
 404         if (isSupported) {
 405            try {
 406               isSupported = checkDockerSupport();
 407            } catch (Exception e) {
 408               isSupported = false;
 409            }
 410          }
 411 
 412         return (isSupported) ? "true" : "false";
 413     }
 414 
 415     private boolean checkDockerSupport() throws IOException, InterruptedException {
 416         ProcessBuilder pb = new ProcessBuilder("docker", "ps");
 417         Process p = pb.start();
 418         p.waitFor(10, TimeUnit.SECONDS);
 419 
 420         return (p.exitValue() == 0);
 421     }
 422 












 423 
 424 
 425     /**
 426      * Dumps the map to the file if the file name is given as the property.
 427      * This functionality could be helpful to know context in the real
 428      * execution.
 429      *
 430      * @param map
 431      */
 432     protected static void dump(Map<String, String> map) {
 433         String dumpFileName = System.getProperty("vmprops.dump");
 434         if (dumpFileName == null) {
 435             return;
 436         }
 437         List<String> lines = new ArrayList<>();
 438         map.forEach((k, v) -> lines.add(k + ":" + v));
 439         try {
 440             Files.write(Paths.get(dumpFileName), lines, StandardOpenOption.APPEND);
 441         } catch (IOException e) {
 442             throw new RuntimeException("Failed to dump properties into '"


   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  */
  23 package requires;
  24 
  25 import java.io.BufferedInputStream;
  26 import java.io.FileInputStream;
  27 import java.io.IOException;
  28 import java.io.InputStream;
  29 import java.nio.file.Files;
  30 import java.nio.file.Path;
  31 import java.nio.file.Paths;
  32 import java.nio.file.StandardOpenOption;
  33 import java.util.ArrayList;
  34 import java.util.HashMap;
  35 import java.util.List;
  36 import java.util.Map;
  37 import java.util.Properties;
  38 import java.util.concurrent.Callable;
  39 import java.util.concurrent.TimeUnit;
  40 import java.util.regex.Matcher;
  41 import java.util.regex.Pattern;
  42 
  43 import sun.hotspot.cpuinfo.CPUInfo;
  44 import sun.hotspot.gc.GC;
  45 import sun.hotspot.WhiteBox;
  46 import jdk.test.lib.Platform;
  47 
  48 /**
  49  * The Class to be invoked by jtreg prior Test Suite execution to
  50  * collect information about VM.
  51  * Do not use any API's that may not be available in all target VMs.
  52  * Properties set by this Class will be available in the @requires expressions.
  53  */
  54 public class VMProps implements Callable<Map<String, String>> {
  55 
  56     private static final WhiteBox WB = WhiteBox.getWhiteBox();
  57 


  66         Map<String, String> map = new HashMap<>();
  67         map.put("vm.flavor", vmFlavor());
  68         map.put("vm.compMode", vmCompMode());
  69         map.put("vm.bits", vmBits());
  70         map.put("vm.flightRecorder", vmFlightRecorder());
  71         map.put("vm.simpleArch", vmArch());
  72         map.put("vm.debug", vmDebug());
  73         map.put("vm.jvmci", vmJvmci());
  74         map.put("vm.emulatedClient", vmEmulatedClient());
  75         map.put("vm.cpu.features", cpuFeatures());
  76         map.put("vm.rtm.cpu", vmRTMCPU());
  77         map.put("vm.rtm.os", vmRTMOS());
  78         map.put("vm.aot", vmAOT());
  79         // vm.cds is true if the VM is compiled with cds support.
  80         map.put("vm.cds", vmCDS());
  81         map.put("vm.cds.custom.loaders", vmCDSForCustomLoaders());
  82         map.put("vm.cds.archived.java.heap", vmCDSForArchivedJavaHeap());
  83         // vm.graal.enabled is true if Graal is used as JIT
  84         map.put("vm.graal.enabled", isGraalEnabled());
  85         map.put("docker.support", dockerSupport());
  86         map.put("release.implementor", implementor());
  87         vmGC(map); // vm.gc.X = true/false
  88         vmOptFinalFlags(map);
  89 
  90         VMProps.dump(map);
  91         return map;
  92     }
  93 
  94     /**
  95      * Prints a stack trace before returning null.
  96      * Used by the various helper functions which parse information from
  97      * VM properties in the case where they don't find an expected property
  98      * or a propoerty doesn't conform to an expected format.
  99      *
 100      * @return null
 101      */
 102     private String nullWithException(String message) {
 103         new Exception(message).printStackTrace();
 104         return null;
 105     }
 106 


 408 
 409         if (isSupported) {
 410            try {
 411               isSupported = checkDockerSupport();
 412            } catch (Exception e) {
 413               isSupported = false;
 414            }
 415          }
 416 
 417         return (isSupported) ? "true" : "false";
 418     }
 419 
 420     private boolean checkDockerSupport() throws IOException, InterruptedException {
 421         ProcessBuilder pb = new ProcessBuilder("docker", "ps");
 422         Process p = pb.start();
 423         p.waitFor(10, TimeUnit.SECONDS);
 424 
 425         return (p.exitValue() == 0);
 426     }
 427 
 428 
 429     private String implementor() {
 430         try (InputStream in = new BufferedInputStream(new FileInputStream(
 431                 System.getProperty("java.home") + "/release"))) {
 432             Properties properties = new Properties();
 433             properties.load(in);
 434             return properties.getProperty("IMPLEMENTOR").replace("\"", "");
 435         } catch (IOException e) {
 436             e.printStackTrace();
 437         }
 438         return null;
 439     }
 440 
 441 
 442     /**
 443      * Dumps the map to the file if the file name is given as the property.
 444      * This functionality could be helpful to know context in the real
 445      * execution.
 446      *
 447      * @param map
 448      */
 449     protected static void dump(Map<String, String> map) {
 450         String dumpFileName = System.getProperty("vmprops.dump");
 451         if (dumpFileName == null) {
 452             return;
 453         }
 454         List<String> lines = new ArrayList<>();
 455         map.forEach((k, v) -> lines.add(k + ":" + v));
 456         try {
 457             Files.write(Paths.get(dumpFileName), lines, StandardOpenOption.APPEND);
 458         } catch (IOException e) {
 459             throw new RuntimeException("Failed to dump properties into '"
< prev index next >