PageRenderTime 56ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/java-1.7.0-openjdk/openjdk/hotspot/agent/src/share/classes/sun/jvm/hotspot/utilities/PlatformInfo.java

#
Java | 75 lines | 38 code | 5 blank | 32 comment | 25 complexity | e64271984e771c01be5a413cc7fd04b3 MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause-No-Nuclear-License-2014, LGPL-3.0, LGPL-2.0
  1. /*
  2. * Copyright (c) 2000, 2012, 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 sun.jvm.hotspot.utilities;
  25. /** Provides canonicalized OS and CPU information for the rest of the
  26. system. */
  27. public class PlatformInfo {
  28. /* Returns "solaris" if on Solaris; "win32" if Windows; "linux" if
  29. Linux. Used to determine location of dbx and import module, or
  30. possible debugger agent on win32. */
  31. public static String getOS() throws UnsupportedPlatformException {
  32. String os = System.getProperty("os.name");
  33. if (os.equals("SunOS")) {
  34. return "solaris";
  35. } else if (os.equals("Linux")) {
  36. return "linux";
  37. } else if (os.equals("FreeBSD")) {
  38. return "bsd";
  39. } else if (os.equals("NetBSD")) {
  40. return "bsd";
  41. } else if (os.equals("OpenBSD")) {
  42. return "bsd";
  43. } else if (os.equals("Darwin") || os.contains("OS X")) {
  44. return "bsd";
  45. } else if (os.startsWith("Windows")) {
  46. return "win32";
  47. } else {
  48. throw new UnsupportedPlatformException("Operating system " + os + " not yet supported");
  49. }
  50. }
  51. /* Returns "sparc" for SPARC based platforms and "x86" for x86 based
  52. platforms. Otherwise returns the value of os.arch. If the value
  53. is not recognized as supported, an exception is thrown instead. */
  54. public static String getCPU() throws UnsupportedPlatformException {
  55. String cpu = System.getProperty("os.arch");
  56. if (cpu.equals("i386") || cpu.equals("x86")) {
  57. return "x86";
  58. } else if (cpu.equals("sparc") || cpu.equals("sparcv9")) {
  59. return "sparc";
  60. } else if (cpu.equals("ia64") || cpu.equals("amd64") || cpu.equals("x86_64")) {
  61. return cpu;
  62. } else {
  63. throw new UnsupportedPlatformException("CPU type " + cpu + " not yet supported");
  64. }
  65. }
  66. // this main is invoked from Makefile to make platform specific agent Makefile(s).
  67. public static void main(String[] args) {
  68. System.out.println(getOS());
  69. }
  70. }