1 /* 2 * Copyright (c) 2013, 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 */ 23 24 package jdk.testlibrary; 25 26 public class Platform { 27 private static final String osName = System.getProperty("os.name"); 28 private static final String dataModel = System.getProperty("sun.arch.data.model"); 29 private static final String vmVersion = System.getProperty("java.vm.version"); 30 private static final String osArch = System.getProperty("os.arch"); 31 32 public static boolean is32bit() { 33 return dataModel.equals("32"); 34 } 35 36 public static boolean is64bit() { 37 return dataModel.equals("64"); 38 } 39 40 public static boolean isSolaris() { 41 return isOs("sunos"); 42 } 43 44 public static boolean isWindows() { 45 return isOs("win"); 46 } 47 48 public static boolean isOSX() { 49 return isOs("mac"); 50 } 51 52 public static boolean isLinux() { 53 return isOs("linux"); 54 } 55 56 private static boolean isOs(String osname) { 57 return osName.toLowerCase().startsWith(osname.toLowerCase()); 58 } 59 60 public static String getOsName() { 61 return osName; 62 } 63 64 public static boolean isDebugBuild() { 65 return vmVersion.toLowerCase().contains("debug"); 66 } 67 68 public static String getVMVersion() { 69 return vmVersion; 70 } 71 72 // Returns true for sparc and sparcv9. 73 public static boolean isSparc() { 74 return isArch("sparc"); 75 } 76 77 public static boolean isARM() { 78 return isArch("arm"); 79 } 80 81 public static boolean isPPC() { 82 return isArch("ppc"); 83 } 84 85 public static boolean isX86() { 86 // On Linux it's 'i386', Windows 'x86' 87 return (isArch("i386") || isArch("x86")); 88 } 89 90 public static boolean isX64() { 91 // On OSX it's 'x86_64' and on other (Linux, Windows and Solaris) platforms it's 'amd64' 92 return (isArch("amd64") || isArch("x86_64")); 93 } 94 95 private static boolean isArch(String archname) { 96 return osArch.toLowerCase().startsWith(archname.toLowerCase()); 97 } 98 99 public static String getOsArch() { 100 return osArch; 101 } 102 103 }