0N/A/*
3867N/A * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage sun.misc;
0N/Aimport java.io.PrintStream;
0N/A
0N/Apublic class Version {
0N/A
0N/A
0N/A private static final String launcher_name =
0N/A "@@launcher_name@@";
0N/A
0N/A private static final String java_version =
0N/A "@@java_version@@";
0N/A
0N/A private static final String java_runtime_name =
3867N/A "@@java_runtime_name@@";
3867N/A
0N/A private static final String java_runtime_version =
0N/A "@@java_runtime_version@@";
0N/A
0N/A static {
0N/A init();
0N/A }
0N/A
0N/A public static void init() {
0N/A System.setProperty("java.version", java_version);
0N/A System.setProperty("java.runtime.version", java_runtime_version);
0N/A System.setProperty("java.runtime.name", java_runtime_name);
0N/A }
0N/A
0N/A private static boolean versionsInitialized = false;
0N/A private static int jvm_major_version = 0;
0N/A private static int jvm_minor_version = 0;
0N/A private static int jvm_micro_version = 0;
0N/A private static int jvm_update_version = 0;
0N/A private static int jvm_build_number = 0;
0N/A private static String jvm_special_version = null;
0N/A private static int jdk_major_version = 0;
0N/A private static int jdk_minor_version = 0;
0N/A private static int jdk_micro_version = 0;
0N/A private static int jdk_update_version = 0;
0N/A private static int jdk_build_number = 0;
0N/A private static String jdk_special_version = null;
0N/A
0N/A /**
0N/A * In case you were wondering this method is called by java -version.
0N/A * Sad that it prints to stderr; would be nicer if default printed on
0N/A * stdout.
0N/A */
0N/A public static void print() {
0N/A print(System.err);
0N/A }
0N/A
0N/A /**
0N/A * This is the same as print except that it adds an extra line-feed
0N/A * at the end, typically used by the -showversion in the launcher
0N/A */
0N/A public static void println() {
0N/A print(System.err);
0N/A System.err.println();
0N/A }
0N/A
0N/A /**
0N/A * Give a stream, it will print version info on it.
0N/A */
0N/A public static void print(PrintStream ps) {
3867N/A boolean isHeadless = false;
3867N/A
3867N/A /* Report that we're running headless if the property is true */
3867N/A String headless = System.getProperty("java.awt.headless");
3867N/A if ( (headless != null) && (headless.equalsIgnoreCase("true")) ) {
3867N/A isHeadless = true;
3867N/A }
3867N/A
0N/A /* First line: platform version. */
0N/A ps.println(launcher_name + " version \"" + java_version + "\"");
0N/A
0N/A /* Second line: runtime version (ie, libraries). */
3867N/A
3867N/A ps.print(java_runtime_name + " (build " + java_runtime_version);
3867N/A
3867N/A if (java_runtime_name.indexOf("Embedded") != -1 && isHeadless) {
3867N/A // embedded builds report headless state
3867N/A ps.print(", headless");
3867N/A }
3867N/A ps.println(')');
0N/A
0N/A /* Third line: JVM information. */
0N/A String java_vm_name = System.getProperty("java.vm.name");
0N/A String java_vm_version = System.getProperty("java.vm.version");
0N/A String java_vm_info = System.getProperty("java.vm.info");
0N/A ps.println(java_vm_name + " (build " + java_vm_version + ", " +
0N/A java_vm_info + ")");
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the major version of the running JVM if it's 1.6 or newer
0N/A * or any RE VM build. It will return 0 if it's an internal 1.5 or
0N/A * 1.4.x build.
0N/A *
0N/A * @since 1.6
0N/A */
0N/A public static synchronized int jvmMajorVersion() {
0N/A if (!versionsInitialized) {
0N/A initVersions();
0N/A }
0N/A return jvm_major_version;
0N/A }
0N/A
0N/A /**
0N/A * Returns the minor version of the running JVM if it's 1.6 or newer
0N/A * or any RE VM build. It will return 0 if it's an internal 1.5 or
0N/A * 1.4.x build.
0N/A * @since 1.6
0N/A */
0N/A public static synchronized int jvmMinorVersion() {
0N/A if (!versionsInitialized) {
0N/A initVersions();
0N/A }
0N/A return jvm_minor_version;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the micro version of the running JVM if it's 1.6 or newer
0N/A * or any RE VM build. It will return 0 if it's an internal 1.5 or
0N/A * 1.4.x build.
0N/A * @since 1.6
0N/A */
0N/A public static synchronized int jvmMicroVersion() {
0N/A if (!versionsInitialized) {
0N/A initVersions();
0N/A }
0N/A return jvm_micro_version;
0N/A }
0N/A
0N/A /**
0N/A * Returns the update release version of the running JVM if it's
0N/A * a RE build. It will return 0 if it's an internal build.
0N/A * @since 1.6
0N/A */
0N/A public static synchronized int jvmUpdateVersion() {
0N/A if (!versionsInitialized) {
0N/A initVersions();
0N/A }
0N/A return jvm_update_version;
0N/A }
0N/A
0N/A public static synchronized String jvmSpecialVersion() {
0N/A if (!versionsInitialized) {
0N/A initVersions();
0N/A }
0N/A if (jvm_special_version == null) {
0N/A jvm_special_version = getJvmSpecialVersion();
0N/A }
0N/A return jvm_special_version;
0N/A }
0N/A public static native String getJvmSpecialVersion();
0N/A
0N/A /**
0N/A * Returns the build number of the running JVM if it's a RE build
0N/A * It will return 0 if it's an internal build.
0N/A * @since 1.6
0N/A */
0N/A public static synchronized int jvmBuildNumber() {
0N/A if (!versionsInitialized) {
0N/A initVersions();
0N/A }
0N/A return jvm_build_number;
0N/A }
0N/A
0N/A /**
0N/A * Returns the major version of the running JDK.
0N/A *
0N/A * @since 1.6
0N/A */
0N/A public static synchronized int jdkMajorVersion() {
0N/A if (!versionsInitialized) {
0N/A initVersions();
0N/A }
0N/A return jdk_major_version;
0N/A }
0N/A
0N/A /**
0N/A * Returns the minor version of the running JDK.
0N/A * @since 1.6
0N/A */
0N/A public static synchronized int jdkMinorVersion() {
0N/A if (!versionsInitialized) {
0N/A initVersions();
0N/A }
0N/A return jdk_minor_version;
0N/A }
0N/A
0N/A /**
0N/A * Returns the micro version of the running JDK.
0N/A * @since 1.6
0N/A */
0N/A public static synchronized int jdkMicroVersion() {
0N/A if (!versionsInitialized) {
0N/A initVersions();
0N/A }
0N/A return jdk_micro_version;
0N/A }
0N/A
0N/A /**
0N/A * Returns the update release version of the running JDK if it's
0N/A * a RE build. It will return 0 if it's an internal build.
0N/A * @since 1.6
0N/A */
0N/A public static synchronized int jdkUpdateVersion() {
0N/A if (!versionsInitialized) {
0N/A initVersions();
0N/A }
0N/A return jdk_update_version;
0N/A }
0N/A
0N/A public static synchronized String jdkSpecialVersion() {
0N/A if (!versionsInitialized) {
0N/A initVersions();
0N/A }
0N/A if (jdk_special_version == null) {
0N/A jdk_special_version = getJdkSpecialVersion();
0N/A }
0N/A return jdk_special_version;
0N/A }
0N/A public static native String getJdkSpecialVersion();
0N/A
0N/A /**
0N/A * Returns the build number of the running JDK if it's a RE build
0N/A * It will return 0 if it's an internal build.
0N/A * @since 1.6
0N/A */
0N/A public static synchronized int jdkBuildNumber() {
0N/A if (!versionsInitialized) {
0N/A initVersions();
0N/A }
0N/A return jdk_build_number;
0N/A }
0N/A
0N/A // true if JVM exports the version info including the capabilities
0N/A private static boolean jvmVersionInfoAvailable;
0N/A private static synchronized void initVersions() {
0N/A if (versionsInitialized) {
0N/A return;
0N/A }
0N/A jvmVersionInfoAvailable = getJvmVersionInfo();
0N/A if (!jvmVersionInfoAvailable) {
0N/A // parse java.vm.version for older JVM before the
0N/A // new JVM_GetVersionInfo is added.
0N/A // valid format of the version string is:
0N/A // n.n.n[_uu[c]][-<identifer>]-bxx
0N/A CharSequence cs = System.getProperty("java.vm.version");
0N/A if (cs.length() >= 5 &&
0N/A Character.isDigit(cs.charAt(0)) && cs.charAt(1) == '.' &&
0N/A Character.isDigit(cs.charAt(2)) && cs.charAt(3) == '.' &&
0N/A Character.isDigit(cs.charAt(4))) {
0N/A jvm_major_version = Character.digit(cs.charAt(0), 10);
0N/A jvm_minor_version = Character.digit(cs.charAt(2), 10);
0N/A jvm_micro_version = Character.digit(cs.charAt(4), 10);
0N/A cs = cs.subSequence(5, cs.length());
0N/A if (cs.charAt(0) == '_' && cs.length() >= 3 &&
0N/A Character.isDigit(cs.charAt(1)) &&
0N/A Character.isDigit(cs.charAt(2))) {
0N/A int nextChar = 3;
0N/A try {
0N/A String uu = cs.subSequence(1, 3).toString();
0N/A jvm_update_version = Integer.valueOf(uu).intValue();
0N/A if (cs.length() >= 4) {
0N/A char c = cs.charAt(3);
0N/A if (c >= 'a' && c <= 'z') {
0N/A jvm_special_version = Character.toString(c);
0N/A nextChar++;
0N/A }
0N/A }
0N/A } catch (NumberFormatException e) {
0N/A // not conforming to the naming convention
0N/A return;
0N/A }
0N/A cs = cs.subSequence(nextChar, cs.length());
0N/A }
0N/A if (cs.charAt(0) == '-') {
0N/A // skip the first character
0N/A // valid format: <identifier>-bxx or bxx
0N/A // non-product VM will have -debug|-release appended
0N/A cs = cs.subSequence(1, cs.length());
0N/A String[] res = cs.toString().split("-");
0N/A for (String s : res) {
0N/A if (s.charAt(0) == 'b' && s.length() == 3 &&
0N/A Character.isDigit(s.charAt(1)) &&
0N/A Character.isDigit(s.charAt(2))) {
0N/A jvm_build_number =
0N/A Integer.valueOf(s.substring(1, 3)).intValue();
0N/A break;
0N/A }
0N/A }
0N/A }
0N/A }
0N/A }
0N/A getJdkVersionInfo();
0N/A versionsInitialized = true;
0N/A }
0N/A
0N/A // Gets the JVM version info if available and sets the jvm_*_version fields
0N/A // and its capabilities.
0N/A //
0N/A // Return false if not available which implies an old VM (Tiger or before).
0N/A private static native boolean getJvmVersionInfo();
0N/A private static native void getJdkVersionInfo();
0N/A
0N/A}
0N/A
0N/A// Help Emacs a little because this file doesn't end in .java.
0N/A//
0N/A// Local Variables: ***
0N/A// mode: java ***
0N/A// End: ***