1 /* 2 * Copyright (c) 2000, 2015, 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 25 package sun.jvm.hotspot.utilities; 26 27 /** Provides canonicalized OS and CPU information for the rest of the 28 system. */ 29 30 public class PlatformInfo { 31 /* Returns "solaris" if on Solaris; "win32" if Windows; "linux" if 32 Linux. Used to determine location of dbx and import module, or 33 possible debugger agent on win32. */ getOS()34 public static String getOS() throws UnsupportedPlatformException { 35 String os = System.getProperty("os.name"); 36 if (os.equals("SunOS")) { 37 return "solaris"; 38 } else if (os.equals("Linux")) { 39 return "linux"; 40 } else if (os.equals("DragonFly") || os.equals("DragonFlyBSD") ) { 41 return "bsd"; 42 } else if (os.equals("FreeBSD")) { 43 return "bsd"; 44 } else if (os.equals("NetBSD")) { 45 return "bsd"; 46 } else if (os.equals("OpenBSD")) { 47 return "bsd"; 48 } else if (os.contains("Darwin") || os.contains("OS X")) { 49 return "darwin"; 50 } else if (os.startsWith("Windows")) { 51 return "win32"; 52 } else { 53 throw new UnsupportedPlatformException("Operating system " + os + " not yet supported"); 54 } 55 } 56 knownCPU(String cpu)57 public static boolean knownCPU(String cpu) { 58 final String[] KNOWN = 59 new String[] {"i386", "x86", "x86_64", "amd64", "sparc", "sparcv9", "ppc64", "ppc64le", "aarch64"}; 60 61 for(String s : KNOWN) { 62 if(s.equals(cpu)) 63 return true; 64 } 65 66 return false; 67 } 68 69 /* Returns "sparc" for SPARC based platforms "x86" for x86 based 70 platforms and x86_64 for 64bit x86 based platform. Otherwise 71 returns the value of os.arch. If the value is not recognized as supported, 72 an exception is thrown instead. */ 73 getCPU()74 public static String getCPU() throws UnsupportedPlatformException { 75 String cpu = System.getProperty("os.arch"); 76 77 // Check that CPU is supported 78 if (!knownCPU(cpu)) { 79 throw new UnsupportedPlatformException("CPU type " + cpu + " not yet supported"); 80 } 81 82 // Tweeks 83 if (cpu.equals("i386")) 84 return "x86"; 85 86 if (cpu.equals("sparcv9")) 87 return "sparc"; 88 89 if (cpu.equals("x86_64")) 90 return "amd64"; 91 92 if (cpu.equals("ppc64le")) 93 return "ppc64"; 94 95 return cpu; 96 97 } 98 99 // this main is invoked from Makefile to make platform specific agent Makefile(s). main(String[] args)100 public static void main(String[] args) { 101 System.out.println(getOS()); 102 } 103 } 104