jdk/src/share/classes/sun/misc/Version.java.template
author alanb
Mon, 21 Jan 2013 23:21:15 -0500
changeset 15683 3acd10709925
parent 8993 9076d969ffdf
child 16731 c6f7eeb4acc0
permissions -rw-r--r--
8003256: (profiles) Add support for profile identification Reviewed-by: dholmes, mchung, ksrini
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
15683
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
     2
 * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
2
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
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4115
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4115
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4115
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4115
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4115
diff changeset
    23
 * questions.
2
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 =
15683
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
    39
        "@@java_runtime_name@@";
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
    40
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
    41
    private static final String java_profile_name =
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
    42
        "@@java_profile_name@@";
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
    43
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    private static final String java_runtime_version =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        "@@java_runtime_version@@";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    public static void init() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        System.setProperty("java.version", java_version);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        System.setProperty("java.runtime.version", java_runtime_version);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        System.setProperty("java.runtime.name", java_runtime_name);
15683
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
    55
        if (java_profile_name.length() > 0)
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
    56
            System.setProperty("java.runtime.profile", java_profile_name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private static boolean versionsInitialized = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private static int jvm_major_version = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private static int jvm_minor_version = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private static int jvm_micro_version = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private static int jvm_update_version = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private static int jvm_build_number = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private static String jvm_special_version = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private static int jdk_major_version = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    private static int jdk_minor_version = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private static int jdk_micro_version = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private static int jdk_update_version = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    private static int jdk_build_number = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private static String jdk_special_version = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * In case you were wondering this method is called by java -version.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * Sad that it prints to stderr; would be nicer if default printed on
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * stdout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    public static void print() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        print(System.err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * This is the same as print except that it adds an extra line-feed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * at the end, typically used by the -showversion in the launcher
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    public static void println() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        print(System.err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        System.err.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * Give a stream, it will print version info on it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    public static void print(PrintStream ps) {
8993
9076d969ffdf 7025066: Build systems changes to support SE Embedded Integration
dholmes
parents: 5506
diff changeset
    95
        boolean isHeadless = false;
9076d969ffdf 7025066: Build systems changes to support SE Embedded Integration
dholmes
parents: 5506
diff changeset
    96
9076d969ffdf 7025066: Build systems changes to support SE Embedded Integration
dholmes
parents: 5506
diff changeset
    97
        /* Report that we're running headless if the property is true */
15683
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
    98
        String headless = System.getProperty("java.awt.headless");
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
    99
        if ( (headless != null) && (headless.equalsIgnoreCase("true")) ) {
8993
9076d969ffdf 7025066: Build systems changes to support SE Embedded Integration
dholmes
parents: 5506
diff changeset
   100
            isHeadless = true;
15683
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   101
        }
8993
9076d969ffdf 7025066: Build systems changes to support SE Embedded Integration
dholmes
parents: 5506
diff changeset
   102
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        /* First line: platform version. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        ps.println(launcher_name + " version \"" + java_version + "\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        /* Second line: runtime version (ie, libraries). */
8993
9076d969ffdf 7025066: Build systems changes to support SE Embedded Integration
dholmes
parents: 5506
diff changeset
   107
15683
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   108
        ps.print(java_runtime_name + " (build " + java_runtime_version);
8993
9076d969ffdf 7025066: Build systems changes to support SE Embedded Integration
dholmes
parents: 5506
diff changeset
   109
15683
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   110
        if (java_profile_name.length() > 0) {
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   111
            // profile name
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   112
            ps.print(", profile " + java_profile_name);
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   113
        }
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   114
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   115
        if (java_runtime_name.indexOf("Embedded") != -1 && isHeadless) {
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   116
            // embedded builds report headless state
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   117
            ps.print(", headless");
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   118
        }
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   119
        ps.println(')');
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        /* Third line: JVM information. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        String java_vm_name    = System.getProperty("java.vm.name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        String java_vm_version = System.getProperty("java.vm.version");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        String java_vm_info    = System.getProperty("java.vm.info");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        ps.println(java_vm_name + " (build " + java_vm_version + ", " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                   java_vm_info + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * Returns the major version of the running JVM if it's 1.6 or newer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * or any RE VM build. It will return 0 if it's an internal 1.5 or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * 1.4.x build.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    public static synchronized int jvmMajorVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        if (!versionsInitialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            initVersions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        return jvm_major_version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * Returns the minor version of the running JVM if it's 1.6 or newer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * or any RE VM build. It will return 0 if it's an internal 1.5 or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * 1.4.x build.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    public static synchronized int jvmMinorVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        if (!versionsInitialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            initVersions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        return jvm_minor_version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * Returns the micro version of the running JVM if it's 1.6 or newer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * or any RE VM build. It will return 0 if it's an internal 1.5 or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * 1.4.x build.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    public static synchronized int jvmMicroVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        if (!versionsInitialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            initVersions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        return jvm_micro_version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * Returns the update release version of the running JVM if it's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * a RE build. It will return 0 if it's an internal build.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    public static synchronized int jvmUpdateVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        if (!versionsInitialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            initVersions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        return jvm_update_version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    public static synchronized String jvmSpecialVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        if (!versionsInitialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            initVersions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        if (jvm_special_version == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            jvm_special_version = getJvmSpecialVersion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        return jvm_special_version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    public static native String getJvmSpecialVersion();
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 build number of the running JVM if it's a RE build
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * It will return 0 if it's an internal build.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    public static synchronized int jvmBuildNumber() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        if (!versionsInitialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            initVersions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        return jvm_build_number;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * Returns the major version of the running JDK.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    public static synchronized int jdkMajorVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        if (!versionsInitialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            initVersions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        return jdk_major_version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * Returns the minor version of the running JDK.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    public static synchronized int jdkMinorVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        if (!versionsInitialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            initVersions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        return jdk_minor_version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * Returns the micro version of the running JDK.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    public static synchronized int jdkMicroVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        if (!versionsInitialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            initVersions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        return jdk_micro_version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * Returns the update release version of the running JDK if it's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * a RE build. It will return 0 if it's an internal build.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    public static synchronized int jdkUpdateVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        if (!versionsInitialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            initVersions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        return jdk_update_version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    public static synchronized String jdkSpecialVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        if (!versionsInitialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            initVersions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        if (jdk_special_version == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            jdk_special_version = getJdkSpecialVersion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        return jdk_special_version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    public static native String getJdkSpecialVersion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * Returns the build number of the running JDK if it's a RE build
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * It will return 0 if it's an internal build.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    public static synchronized int jdkBuildNumber() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        if (!versionsInitialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            initVersions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        return jdk_build_number;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    // true if JVM exports the version info including the capabilities
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    private static boolean jvmVersionInfoAvailable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    private static synchronized void initVersions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        if (versionsInitialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        jvmVersionInfoAvailable = getJvmVersionInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        if (!jvmVersionInfoAvailable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            // parse java.vm.version for older JVM before the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            // new JVM_GetVersionInfo is added.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            // valid format of the version string is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            // n.n.n[_uu[c]][-<identifer>]-bxx
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            CharSequence cs = System.getProperty("java.vm.version");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            if (cs.length() >= 5 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                Character.isDigit(cs.charAt(0)) && cs.charAt(1) == '.' &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                Character.isDigit(cs.charAt(2)) && cs.charAt(3) == '.' &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                Character.isDigit(cs.charAt(4))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                jvm_major_version = Character.digit(cs.charAt(0), 10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                jvm_minor_version = Character.digit(cs.charAt(2), 10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                jvm_micro_version = Character.digit(cs.charAt(4), 10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                cs = cs.subSequence(5, cs.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                if (cs.charAt(0) == '_' && cs.length() >= 3 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                    Character.isDigit(cs.charAt(1)) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                    Character.isDigit(cs.charAt(2))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                    int nextChar = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                        String uu = cs.subSequence(1, 3).toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                        jvm_update_version = Integer.valueOf(uu).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                        if (cs.length() >= 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                            char c = cs.charAt(3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                            if (c >= 'a' && c <= 'z') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                                jvm_special_version = Character.toString(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                                nextChar++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                    } catch (NumberFormatException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                        // not conforming to the naming convention
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                    cs = cs.subSequence(nextChar, cs.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                if (cs.charAt(0) == '-') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                    // skip the first character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                    // valid format: <identifier>-bxx or bxx
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                    // non-product VM will have -debug|-release appended
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                    cs = cs.subSequence(1, cs.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                    String[] res = cs.toString().split("-");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                    for (String s : res) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                        if (s.charAt(0) == 'b' && s.length() == 3 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                            Character.isDigit(s.charAt(1)) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                            Character.isDigit(s.charAt(2))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                            jvm_build_number =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                                Integer.valueOf(s.substring(1, 3)).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        getJdkVersionInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        versionsInitialized = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    // Gets the JVM version info if available and sets the jvm_*_version fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    // and its capabilities.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    // Return false if not available which implies an old VM (Tiger or before).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    private static native boolean getJvmVersionInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    private static native void getJdkVersionInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
15683
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   345
    // Possible runtime profiles, ordered from small to large
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   346
    private final static String[] PROFILES = { "compact1", "compact2", "compact3" };
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   347
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   348
    /**
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   349
     * Returns the name of the profile that this runtime implements. The empty
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   350
     * string is returned for the full Java Runtime.
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   351
     */
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   352
    public static String profileName() {
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   353
        return java_profile_name;
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   354
    }
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   355
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   356
    /**
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   357
     * Indicates if this runtime implements the full Java Runtime.
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   358
     */
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   359
    public static boolean isFullJre() {
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   360
        return java_profile_name.length() == 0;
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   361
    }
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   362
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   363
    // cached index of this profile's name in PROFILES (1-based)
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   364
    private static int thisRuntimeIndex;
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   365
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   366
    /**
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   367
     * Indicates if this runtime supports the given profile. Profile names are
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   368
     * case sensitive. 
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   369
     *
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   370
     * @return {@code true} if the given profile is supported
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   371
     */
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   372
    public static boolean supportsProfile(String requiredProfile) {
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   373
        int x = thisRuntimeIndex - 1;
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   374
        if (x < 0) {
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   375
            String profile = profileName();
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   376
            if (profile.length() > 0) {
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   377
                x = 0;
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   378
                while (x < PROFILES.length) {
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   379
                    if (PROFILES[x].equals(profile))
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   380
                        break;
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   381
                    x++;
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   382
                }
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   383
                if (x >= PROFILES.length)
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   384
                    throw new InternalError(profile + " not known to sun.misc.Version");
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   385
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   386
                // okay if another thread has already set it
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   387
                thisRuntimeIndex = x + 1;
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   388
            }
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   389
            // else we are a full JRE
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   390
        }
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   391
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   392
        int y = 0;
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   393
        while (y < PROFILES.length) {
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   394
            if (PROFILES[y].equals(requiredProfile))
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   395
                break;
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   396
            y++;
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   397
        }
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   398
        if (y >= PROFILES.length) {
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   399
            // profile not found so caller has requested something that is not defined
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   400
            return false;
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   401
        }
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   402
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   403
        return x < 0 || x >= y;
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   404
    }
3acd10709925 8003256: (profiles) Add support for profile identification
alanb
parents: 8993
diff changeset
   405
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
// Help Emacs a little because this file doesn't end in .java.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
// Local Variables: ***
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
// mode: java ***
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
// End: ***