jdk/src/share/classes/sun/misc/Version.java.template
author ohair
Wed, 28 Oct 2009 12:54:37 -0700
changeset 4115 e09be02771b6
parent 2 jdk/src/share/classes/sun/misc/Version-template.java@90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
6888701: Change all template java source files to a .java-template file suffix Reviewed-by: jjg, alanb, mr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1999-2007 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.misc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.io.PrintStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
public class Version {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
    private static final String launcher_name =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
        "@@launcher_name@@";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
    private static final String java_version =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
        "@@java_version@@";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    private static final String java_runtime_name =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
        "@@java_runtime_name@@";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    private static final String java_runtime_version =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
        "@@java_runtime_version@@";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    public static void init() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        System.setProperty("java.version", java_version);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        System.setProperty("java.runtime.version", java_runtime_version);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        System.setProperty("java.runtime.name", java_runtime_name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private static boolean versionsInitialized = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private static int jvm_major_version = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private static int jvm_minor_version = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private static int jvm_micro_version = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private static int jvm_update_version = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private static int jvm_build_number = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private static String jvm_special_version = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private static int jdk_major_version = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private static int jdk_minor_version = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private static int jdk_micro_version = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private static int jdk_update_version = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private static int jdk_build_number = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private static String jdk_special_version = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * In case you were wondering this method is called by java -version.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * Sad that it prints to stderr; would be nicer if default printed on
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * stdout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    public static void print() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        print(System.err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * This is the same as print except that it adds an extra line-feed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * at the end, typically used by the -showversion in the launcher
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    public static void println() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        print(System.err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        System.err.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * Give a stream, it will print version info on it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    public static void print(PrintStream ps) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        /* First line: platform version. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        ps.println(launcher_name + " version \"" + java_version + "\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        /* Second line: runtime version (ie, libraries). */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        ps.println(java_runtime_name + " (build " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                           java_runtime_version + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        /* Third line: JVM information. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        String java_vm_name    = System.getProperty("java.vm.name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        String java_vm_version = System.getProperty("java.vm.version");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        String java_vm_info    = System.getProperty("java.vm.info");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        ps.println(java_vm_name + " (build " + java_vm_version + ", " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                   java_vm_info + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * Returns the major version of the running JVM if it's 1.6 or newer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * or any RE VM build. It will return 0 if it's an internal 1.5 or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * 1.4.x build.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    public static synchronized int jvmMajorVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        if (!versionsInitialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            initVersions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        return jvm_major_version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * Returns the minor version of the running JVM if it's 1.6 or newer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * or any RE VM build. It will return 0 if it's an internal 1.5 or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * 1.4.x build.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public static synchronized int jvmMinorVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        if (!versionsInitialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            initVersions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        return jvm_minor_version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * Returns the micro version of the running JVM if it's 1.6 or newer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * or any RE VM build. It will return 0 if it's an internal 1.5 or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * 1.4.x build.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    public static synchronized int jvmMicroVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        if (!versionsInitialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            initVersions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        return jvm_micro_version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * Returns the update release version of the running JVM if it's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * a RE build. It will return 0 if it's an internal build.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    public static synchronized int jvmUpdateVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        if (!versionsInitialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            initVersions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        return jvm_update_version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    public static synchronized String jvmSpecialVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        if (!versionsInitialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            initVersions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        if (jvm_special_version == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            jvm_special_version = getJvmSpecialVersion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        return jvm_special_version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    public static native String getJvmSpecialVersion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * Returns the build number of the running JVM if it's a RE build
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * It will return 0 if it's an internal build.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    public static synchronized int jvmBuildNumber() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        if (!versionsInitialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            initVersions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        return jvm_build_number;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * Returns the major version of the running JDK.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    public static synchronized int jdkMajorVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        if (!versionsInitialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            initVersions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        return jdk_major_version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * Returns the minor version of the running JDK.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    public static synchronized int jdkMinorVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        if (!versionsInitialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            initVersions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        return jdk_minor_version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * Returns the micro version of the running JDK.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    public static synchronized int jdkMicroVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        if (!versionsInitialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            initVersions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        return jdk_micro_version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * Returns the update release version of the running JDK if it's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * a RE build. It will return 0 if it's an internal build.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    public static synchronized int jdkUpdateVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        if (!versionsInitialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            initVersions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        return jdk_update_version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    public static synchronized String jdkSpecialVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        if (!versionsInitialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            initVersions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        if (jdk_special_version == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            jdk_special_version = getJdkSpecialVersion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        return jdk_special_version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    public static native String getJdkSpecialVersion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * Returns the build number of the running JDK if it's a RE build
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * It will return 0 if it's an internal build.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    public static synchronized int jdkBuildNumber() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        if (!versionsInitialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            initVersions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        return jdk_build_number;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    // true if JVM exports the version info including the capabilities
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    private static boolean jvmVersionInfoAvailable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    private static synchronized void initVersions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        if (versionsInitialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        jvmVersionInfoAvailable = getJvmVersionInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        if (!jvmVersionInfoAvailable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            // parse java.vm.version for older JVM before the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            // new JVM_GetVersionInfo is added.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            // valid format of the version string is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            // n.n.n[_uu[c]][-<identifer>]-bxx
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            CharSequence cs = System.getProperty("java.vm.version");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            if (cs.length() >= 5 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                Character.isDigit(cs.charAt(0)) && cs.charAt(1) == '.' &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                Character.isDigit(cs.charAt(2)) && cs.charAt(3) == '.' &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                Character.isDigit(cs.charAt(4))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                jvm_major_version = Character.digit(cs.charAt(0), 10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                jvm_minor_version = Character.digit(cs.charAt(2), 10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                jvm_micro_version = Character.digit(cs.charAt(4), 10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                cs = cs.subSequence(5, cs.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                if (cs.charAt(0) == '_' && cs.length() >= 3 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                    Character.isDigit(cs.charAt(1)) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                    Character.isDigit(cs.charAt(2))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                    int nextChar = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                        String uu = cs.subSequence(1, 3).toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                        jvm_update_version = Integer.valueOf(uu).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                        if (cs.length() >= 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                            char c = cs.charAt(3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                            if (c >= 'a' && c <= 'z') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                                jvm_special_version = Character.toString(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                                nextChar++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                    } catch (NumberFormatException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                        // not conforming to the naming convention
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                    cs = cs.subSequence(nextChar, cs.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                if (cs.charAt(0) == '-') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                    // skip the first character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                    // valid format: <identifier>-bxx or bxx
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                    // non-product VM will have -debug|-release appended
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                    cs = cs.subSequence(1, cs.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                    String[] res = cs.toString().split("-");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                    for (String s : res) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                        if (s.charAt(0) == 'b' && s.length() == 3 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                            Character.isDigit(s.charAt(1)) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                            Character.isDigit(s.charAt(2))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                            jvm_build_number =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                                Integer.valueOf(s.substring(1, 3)).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        getJdkVersionInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        versionsInitialized = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    // Gets the JVM version info if available and sets the jvm_*_version fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    // and its capabilities.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    // Return false if not available which implies an old VM (Tiger or before).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    private static native boolean getJvmVersionInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    private static native void getJdkVersionInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
// Help Emacs a little because this file doesn't end in .java.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
// Local Variables: ***
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
// mode: java ***
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
// End: ***