test/jtreg-ext/requires/VMProps.java
changeset 46237 3aeb6cbc0ccc
parent 46225 f99654379e9c
parent 45823 f3cf2ee05985
child 46239 bd5621d3ebc1
equal deleted inserted replaced
46236:1b8fd7adc9cc 46237:3aeb6cbc0ccc
     1 /*
     1 /*
     2  * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
     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.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    74         VMProps.dump(map);
    74         VMProps.dump(map);
    75         return map;
    75         return map;
    76     }
    76     }
    77 
    77 
    78     /**
    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     /**
    79      * @return vm.simpleArch value of "os.simpleArch" property of tested JDK.
    92      * @return vm.simpleArch value of "os.simpleArch" property of tested JDK.
    80      */
    93      */
    81     protected String vmArch() {
    94     protected String vmArch() {
    82         String arch = System.getProperty("os.arch");
    95         String arch = System.getProperty("os.arch");
    83         if (arch.equals("x86_64") || arch.equals("amd64")) {
    96         if (arch.equals("x86_64") || arch.equals("amd64")) {
    97      */
   110      */
    98     protected String vmFlavor() {
   111     protected String vmFlavor() {
    99         // E.g. "Java HotSpot(TM) 64-Bit Server VM"
   112         // E.g. "Java HotSpot(TM) 64-Bit Server VM"
   100         String vmName = System.getProperty("java.vm.name");
   113         String vmName = System.getProperty("java.vm.name");
   101         if (vmName == null) {
   114         if (vmName == null) {
   102             return null;
   115             return nullWithException("Can't get 'java.vm.name' property");
   103         }
   116         }
   104 
   117 
   105         Pattern startP = Pattern.compile(".* (\\S+) VM");
   118         Pattern startP = Pattern.compile(".* (\\S+) VM");
   106         Matcher m = startP.matcher(vmName);
   119         Matcher m = startP.matcher(vmName);
   107         if (m.matches()) {
   120         if (m.matches()) {
   108             return m.group(1).toLowerCase();
   121             return m.group(1).toLowerCase();
   109         }
   122         }
   110         return null;
   123         return nullWithException("Can't get VM flavor from 'java.vm.name'");
   111     }
   124     }
   112 
   125 
   113     /**
   126     /**
   114      * @return VM compilation mode extracted from the "java.vm.info" property.
   127      * @return VM compilation mode extracted from the "java.vm.info" property.
   115      */
   128      */
   116     protected String vmCompMode() {
   129     protected String vmCompMode() {
   117         // E.g. "mixed mode"
   130         // E.g. "mixed mode"
   118         String vmInfo = System.getProperty("java.vm.info");
   131         String vmInfo = System.getProperty("java.vm.info");
   119         if (vmInfo == null) {
   132         if (vmInfo == null) {
   120             return null;
   133             return nullWithException("Can't get 'java.vm.info' property");
   121         }
   134         }
   122         int k = vmInfo.toLowerCase().indexOf(" mode");
   135         if (vmInfo.toLowerCase().indexOf("mixed mode") != -1) {
   123         if (k < 0) {
   136             return "Xmixed";
   124             return null;
   137         } else if (vmInfo.toLowerCase().indexOf("compiled mode") != -1) {
   125         }
   138             return "Xcomp";
   126         vmInfo = vmInfo.substring(0, k);
   139         } else if (vmInfo.toLowerCase().indexOf("interpreted mode") != -1) {
   127         switch (vmInfo) {
   140             return "Xint";
   128             case "mixed" : return "Xmixed";
   141         } else {
   129             case "compiled" : return "Xcomp";
   142             return nullWithException("Can't get compilation mode from 'java.vm.info'");
   130             case "interpreted" : return "Xint";
       
   131             default: return null;
       
   132         }
   143         }
   133     }
   144     }
   134 
   145 
   135     /**
   146     /**
   136      * @return VM bitness, the value of the "sun.arch.data.model" property.
   147      * @return VM bitness, the value of the "sun.arch.data.model" property.
   137      */
   148      */
   138     protected String vmBits() {
   149     protected String vmBits() {
   139         return System.getProperty("sun.arch.data.model");
   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         }
   140     }
   156     }
   141 
   157 
   142     /**
   158     /**
   143      * @return "true" if Flight Recorder is enabled, "false" if is disabled.
   159      * @return "true" if Flight Recorder is enabled, "false" if is disabled.
   144      */
   160      */
   159 
   175 
   160     /**
   176     /**
   161      * @return debug level value extracted from the "jdk.debug" property.
   177      * @return debug level value extracted from the "jdk.debug" property.
   162      */
   178      */
   163     protected String vmDebug() {
   179     protected String vmDebug() {
   164         return "" + System.getProperty("jdk.debug").contains("debug");
   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         }
   165     }
   186     }
   166 
   187 
   167     /**
   188     /**
   168      * @return true if VM supports JVMCI and false otherwise
   189      * @return true if VM supports JVMCI and false otherwise
   169      */
   190      */