< prev index next >

test/lib/share/classes/jdk/test/lib/Platform.java

Print this page
rev 1834 : 8066599: Add methods to check VM mode to c.o.j.t.Platform
Reviewed-by:


  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 jdk.test.lib;
  25 
  26 import java.util.regex.Pattern;
  27 
  28 public class Platform {
  29     private static final String osName      = System.getProperty("os.name");
  30     private static final String dataModel   = System.getProperty("sun.arch.data.model");
  31     private static final String vmVersion   = System.getProperty("java.vm.version");
  32     private static final String javaVersion = System.getProperty("java.version");
  33     private static final String osArch      = System.getProperty("os.arch");
  34     private static final String vmName      = System.getProperty("java.vm.name");
  35     private static final String userName    = System.getProperty("user.name");
  36     private static final String compiler    = System.getProperty("sun.management.compiler");

  37 
  38     public static boolean isClient() {
  39         return vmName.endsWith(" Client VM");
  40     }
  41 
  42     public static boolean isServer() {
  43         return vmName.endsWith(" Server VM");
  44     }
  45 
  46     public static boolean isGraal() {
  47         return vmName.endsWith(" Graal VM");
  48     }
  49 
  50     public static boolean isZero() {
  51         return vmName.endsWith(" Zero VM");
  52     }
  53 
  54     public static boolean isMinimal() {
  55         return vmName.endsWith(" Minimal VM");
  56     }
  57 
  58     public static boolean isEmbedded() {
  59         return vmName.contains("Embedded");
  60     }
  61 
  62     public static boolean isTieredSupported() {
  63         return compiler.contains("Tiered Compilers");
  64     }
  65 












  66     public static boolean is32bit() {
  67         return dataModel.equals("32");
  68     }
  69 
  70     public static boolean is64bit() {
  71         return dataModel.equals("64");
  72     }
  73 
  74     public static boolean isAix() {
  75         return isOs("aix");
  76     }
  77 
  78     public static boolean isLinux() {
  79         return isOs("linux");
  80     }
  81 
  82     public static boolean isOSX() {
  83         return isOs("mac");
  84     }
  85 


 118     }
 119 
 120     public static boolean isPPC() {
 121         return isArch("ppc.*");
 122     }
 123 
 124     public static boolean isX86() {
 125         // On Linux it's 'i386', Windows 'x86' without '_64' suffix.
 126         return isArch("(i386)|(x86(?!_64))");
 127     }
 128 
 129     public static boolean isX64() {
 130         // On OSX it's 'x86_64' and on other (Linux, Windows and Solaris) platforms it's 'amd64'
 131         return isArch("(amd64)|(x86_64)");
 132     }
 133 
 134     public static boolean isAArch64() {
 135         return isArch("aarch64");
 136     }
 137 
 138     private static boolean isArch(String archnameRE) {
 139         return Pattern.compile(archnameRE, Pattern.CASE_INSENSITIVE)
 140                 .matcher(osArch)
 141                 .matches();
 142     }
 143 
 144     public static String getOsArch() {
 145         return osArch;
 146     }
 147 
 148     /**
 149      * Return a boolean for whether we expect to be able to attach
 150      * the SA to our own processes on this system.
 151      */
 152     public static boolean shouldSAAttach() throws Exception {
 153 
 154         if (isAix()) {
 155             return false;   // SA not implemented.
 156         } else if (isLinux()) {
 157             return canPtraceAttachLinux();
 158         } else if (isOSX()) {
 159             return canAttachOSX();
 160         } else {
 161             // Other platforms expected to work:
 162             return true;
 163         }


 185         // 3 - no attach: no processes may use ptrace with PTRACE_ATTACH
 186         String ptrace_scope = Utils.fileAsString("/proc/sys/kernel/yama/ptrace_scope");
 187         if (ptrace_scope != null) {
 188             if (ptrace_scope.startsWith("3")) {
 189                 return false;
 190             }
 191             if (!userName.equals("root") && !ptrace_scope.startsWith("0")) {
 192                 // ptrace will be denied:
 193                 return false;
 194             }
 195         }
 196         // Otherwise expect to be permitted:
 197         return true;
 198     }
 199 
 200     /**
 201      * On OSX, expect permission to attach only if we are root.
 202      */
 203     public static boolean canAttachOSX() throws Exception {
 204         return userName.equals("root");






 205     }
 206 }


  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 jdk.test.lib;
  25 
  26 import java.util.regex.Pattern;
  27 
  28 public class Platform {
  29     private static final String osName      = System.getProperty("os.name");
  30     private static final String dataModel   = System.getProperty("sun.arch.data.model");
  31     private static final String vmVersion   = System.getProperty("java.vm.version");
  32     private static final String javaVersion = System.getProperty("java.version");
  33     private static final String osArch      = System.getProperty("os.arch");
  34     private static final String vmName      = System.getProperty("java.vm.name");
  35     private static final String userName    = System.getProperty("user.name");
  36     private static final String compiler    = System.getProperty("sun.management.compiler");
  37     private static final String vmInfo      = System.getProperty("java.vm.info");
  38 
  39     public static boolean isClient() {
  40         return vmName.endsWith(" Client VM");
  41     }
  42 
  43     public static boolean isServer() {
  44         return vmName.endsWith(" Server VM");
  45     }
  46 
  47     public static boolean isGraal() {
  48         return vmName.endsWith(" Graal VM");
  49     }
  50 
  51     public static boolean isZero() {
  52         return vmName.endsWith(" Zero VM");
  53     }
  54 
  55     public static boolean isMinimal() {
  56         return vmName.endsWith(" Minimal VM");
  57     }
  58 
  59     public static boolean isEmbedded() {
  60         return vmName.contains("Embedded");
  61     }
  62 
  63     public static boolean isTieredSupported() {
  64         return compiler.contains("Tiered Compilers");
  65     }
  66 
  67     public static boolean isInt() {
  68         return vmInfo.contains("interpreted");
  69     }
  70 
  71     public static boolean isMixed() {
  72         return vmInfo.contains("mixed");
  73     }
  74 
  75     public static boolean isComp() {
  76         return vmInfo.contains("compiled");
  77     }
  78 
  79     public static boolean is32bit() {
  80         return dataModel.equals("32");
  81     }
  82 
  83     public static boolean is64bit() {
  84         return dataModel.equals("64");
  85     }
  86 
  87     public static boolean isAix() {
  88         return isOs("aix");
  89     }
  90 
  91     public static boolean isLinux() {
  92         return isOs("linux");
  93     }
  94 
  95     public static boolean isOSX() {
  96         return isOs("mac");
  97     }
  98 


 131     }
 132 
 133     public static boolean isPPC() {
 134         return isArch("ppc.*");
 135     }
 136 
 137     public static boolean isX86() {
 138         // On Linux it's 'i386', Windows 'x86' without '_64' suffix.
 139         return isArch("(i386)|(x86(?!_64))");
 140     }
 141 
 142     public static boolean isX64() {
 143         // On OSX it's 'x86_64' and on other (Linux, Windows and Solaris) platforms it's 'amd64'
 144         return isArch("(amd64)|(x86_64)");
 145     }
 146 
 147     public static boolean isAArch64() {
 148         return isArch("aarch64");
 149     }
 150 






 151     public static String getOsArch() {
 152         return osArch;
 153     }
 154 
 155     /**
 156      * Return a boolean for whether we expect to be able to attach
 157      * the SA to our own processes on this system.
 158      */
 159     public static boolean shouldSAAttach() throws Exception {
 160 
 161         if (isAix()) {
 162             return false;   // SA not implemented.
 163         } else if (isLinux()) {
 164             return canPtraceAttachLinux();
 165         } else if (isOSX()) {
 166             return canAttachOSX();
 167         } else {
 168             // Other platforms expected to work:
 169             return true;
 170         }


 192         // 3 - no attach: no processes may use ptrace with PTRACE_ATTACH
 193         String ptrace_scope = Utils.fileAsString("/proc/sys/kernel/yama/ptrace_scope");
 194         if (ptrace_scope != null) {
 195             if (ptrace_scope.startsWith("3")) {
 196                 return false;
 197             }
 198             if (!userName.equals("root") && !ptrace_scope.startsWith("0")) {
 199                 // ptrace will be denied:
 200                 return false;
 201             }
 202         }
 203         // Otherwise expect to be permitted:
 204         return true;
 205     }
 206 
 207     /**
 208      * On OSX, expect permission to attach only if we are root.
 209      */
 210     public static boolean canAttachOSX() throws Exception {
 211         return userName.equals("root");
 212     }
 213 
 214     private static boolean isArch(String archnameRE) {
 215         return Pattern.compile(archnameRE, Pattern.CASE_INSENSITIVE)
 216                       .matcher(osArch)
 217                       .matches();
 218     }
 219 }
< prev index next >