annotate src/java.base/share/classes/sun/misc/Version.java.template @ 13209:c95bba55626c

8139986: Store debug level in java.vm.debug and conditionally print in "java -version" Reviewed-by: ihse, dcubed, ksrini, dholmes Contributed-by: alejandro.murillo@oracle.com, kumar.x.srinivasan@oracle.com
author amurillo
date Wed, 04 Nov 2015 16:02:53 -0800
parents 9cea16b048db
children
rev   line source
duke@0 1 /*
ihse@13182 2 * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
duke@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 4 *
duke@0 5 * This code is free software; you can redistribute it and/or modify it
duke@0 6 * under the terms of the GNU General Public License version 2 only, as
ohair@2362 7 * published by the Free Software Foundation. Oracle designates this
duke@0 8 * particular file as subject to the "Classpath" exception as provided
ohair@2362 9 * by Oracle in the LICENSE file that accompanied this code.
duke@0 10 *
duke@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@0 15 * accompanied this code).
duke@0 16 *
duke@0 17 * You should have received a copy of the GNU General Public License version
duke@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 20 *
ohair@2362 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@2362 22 * or visit www.oracle.com if you need additional information or have any
ohair@2362 23 * questions.
duke@0 24 */
duke@0 25
duke@0 26 package sun.misc;
duke@0 27 import java.io.PrintStream;
duke@0 28
duke@0 29 public class Version {
duke@0 30
duke@0 31
duke@0 32 private static final String launcher_name =
ihse@13182 33 "@@LAUNCHER_NAME@@";
duke@0 34
duke@0 35 private static final String java_version =
ihse@13182 36 "@@VERSION_SHORT@@";
duke@0 37
duke@0 38 private static final String java_runtime_name =
ihse@13182 39 "@@RUNTIME_NAME@@";
alanb@6573 40
duke@0 41 private static final String java_runtime_version =
ihse@13182 42 "@@VERSION_STRING@@";
duke@0 43
duke@0 44 static {
duke@0 45 init();
duke@0 46 }
duke@0 47
duke@0 48 public static void init() {
duke@0 49 System.setProperty("java.version", java_version);
duke@0 50 System.setProperty("java.runtime.version", java_runtime_version);
duke@0 51 System.setProperty("java.runtime.name", java_runtime_name);
duke@0 52 }
duke@0 53
duke@0 54 private static boolean versionsInitialized = false;
duke@0 55 private static int jvm_major_version = 0;
duke@0 56 private static int jvm_minor_version = 0;
ihse@13182 57 private static int jvm_security_version = 0;
amurillo@13184 58 private static int jvm_patch_version = 0;
duke@0 59 private static int jvm_build_number = 0;
duke@0 60 private static int jdk_major_version = 0;
duke@0 61 private static int jdk_minor_version = 0;
ihse@13182 62 private static int jdk_security_version = 0;
amurillo@13184 63 private static int jdk_patch_version = 0;
duke@0 64 private static int jdk_build_number = 0;
duke@0 65
duke@0 66 /**
duke@0 67 * In case you were wondering this method is called by java -version.
duke@0 68 * Sad that it prints to stderr; would be nicer if default printed on
duke@0 69 * stdout.
duke@0 70 */
duke@0 71 public static void print() {
duke@0 72 print(System.err);
duke@0 73 }
duke@0 74
duke@0 75 /**
duke@0 76 * This is the same as print except that it adds an extra line-feed
duke@0 77 * at the end, typically used by the -showversion in the launcher
duke@0 78 */
duke@0 79 public static void println() {
duke@0 80 print(System.err);
duke@0 81 System.err.println();
duke@0 82 }
duke@0 83
duke@0 84 /**
duke@0 85 * Give a stream, it will print version info on it.
duke@0 86 */
duke@0 87 public static void print(PrintStream ps) {
dholmes@3867 88 boolean isHeadless = false;
dholmes@3867 89
dholmes@3867 90 /* Report that we're running headless if the property is true */
alanb@6573 91 String headless = System.getProperty("java.awt.headless");
alanb@6573 92 if ( (headless != null) && (headless.equalsIgnoreCase("true")) ) {
dholmes@3867 93 isHeadless = true;
alanb@6573 94 }
dholmes@3867 95
duke@0 96 /* First line: platform version. */
duke@0 97 ps.println(launcher_name + " version \"" + java_version + "\"");
duke@0 98
duke@0 99 /* Second line: runtime version (ie, libraries). */
dholmes@3867 100
amurillo@13209 101 String jdk_debug_level = System.getProperty("jdk.debug", "release");
amurillo@13209 102 /* Debug level is not printed for "release" builds */
amurillo@13209 103 if ("release".equals(jdk_debug_level)) {
amurillo@13209 104 jdk_debug_level = "";
amurillo@13209 105 } else {
amurillo@13209 106 jdk_debug_level = jdk_debug_level + " ";
amurillo@13209 107 }
amurillo@13209 108
amurillo@13209 109 ps.print(java_runtime_name + " (" + jdk_debug_level + "build " + java_runtime_version);
dholmes@3867 110
alanb@6573 111 if (java_runtime_name.indexOf("Embedded") != -1 && isHeadless) {
alanb@6573 112 // embedded builds report headless state
alanb@6573 113 ps.print(", headless");
alanb@6573 114 }
alanb@6573 115 ps.println(')');
duke@0 116
duke@0 117 /* Third line: JVM information. */
duke@0 118 String java_vm_name = System.getProperty("java.vm.name");
duke@0 119 String java_vm_version = System.getProperty("java.vm.version");
duke@0 120 String java_vm_info = System.getProperty("java.vm.info");
amurillo@13209 121 ps.println(java_vm_name + " (" + jdk_debug_level + "build " + java_vm_version + ", " +
duke@0 122 java_vm_info + ")");
duke@0 123 }
duke@0 124
duke@0 125
duke@0 126 /**
amurillo@13201 127 * Returns the major version of the running JVM.
amurillo@13201 128 * @return the major version of the running JVM
duke@0 129 * @since 1.6
duke@0 130 */
duke@0 131 public static synchronized int jvmMajorVersion() {
duke@0 132 if (!versionsInitialized) {
duke@0 133 initVersions();
duke@0 134 }
duke@0 135 return jvm_major_version;
duke@0 136 }
duke@0 137
duke@0 138 /**
amurillo@13201 139 * Returns the minor version of the running JVM.
amurillo@13201 140 * @return the minor version of the running JVM
duke@0 141 * @since 1.6
duke@0 142 */
duke@0 143 public static synchronized int jvmMinorVersion() {
duke@0 144 if (!versionsInitialized) {
duke@0 145 initVersions();
duke@0 146 }
duke@0 147 return jvm_minor_version;
duke@0 148 }
duke@0 149
duke@0 150
duke@0 151 /**
amurillo@13201 152 * Returns the security version of the running JVM.
amurillo@13201 153 * @return the security version of the running JVM
amurillo@13201 154 * @since 9
duke@0 155 */
ihse@13182 156 public static synchronized int jvmSecurityVersion() {
duke@0 157 if (!versionsInitialized) {
duke@0 158 initVersions();
duke@0 159 }
ihse@13182 160 return jvm_security_version;
duke@0 161 }
duke@0 162
duke@0 163 /**
amurillo@13201 164 * Returns the patch release version of the running JVM.
amurillo@13201 165 * @return the patch release version of the running JVM
amurillo@13201 166 * @since 9
duke@0 167 */
amurillo@13184 168 public static synchronized int jvmPatchVersion() {
duke@0 169 if (!versionsInitialized) {
duke@0 170 initVersions();
duke@0 171 }
amurillo@13184 172 return jvm_patch_version;
duke@0 173 }
duke@0 174
duke@0 175 /**
amurillo@13201 176 * Returns the build number of the running JVM.
amurillo@13201 177 * @return the build number of the running JVM
duke@0 178 * @since 1.6
duke@0 179 */
duke@0 180 public static synchronized int jvmBuildNumber() {
duke@0 181 if (!versionsInitialized) {
duke@0 182 initVersions();
duke@0 183 }
duke@0 184 return jvm_build_number;
duke@0 185 }
duke@0 186
duke@0 187 /**
duke@0 188 * Returns the major version of the running JDK.
amurillo@13201 189 * @return the major version of the running JDK
duke@0 190 * @since 1.6
duke@0 191 */
duke@0 192 public static synchronized int jdkMajorVersion() {
duke@0 193 if (!versionsInitialized) {
duke@0 194 initVersions();
duke@0 195 }
duke@0 196 return jdk_major_version;
duke@0 197 }
duke@0 198
duke@0 199 /**
duke@0 200 * Returns the minor version of the running JDK.
amurillo@13201 201 * @return the minor version of the running JDK
duke@0 202 * @since 1.6
duke@0 203 */
duke@0 204 public static synchronized int jdkMinorVersion() {
duke@0 205 if (!versionsInitialized) {
duke@0 206 initVersions();
duke@0 207 }
duke@0 208 return jdk_minor_version;
duke@0 209 }
duke@0 210
duke@0 211 /**
ihse@13182 212 * Returns the security version of the running JDK.
amurillo@13201 213 * @return the security version of the running JDK
amurillo@13201 214 * @since 9
duke@0 215 */
ihse@13182 216 public static synchronized int jdkSecurityVersion() {
duke@0 217 if (!versionsInitialized) {
duke@0 218 initVersions();
duke@0 219 }
ihse@13182 220 return jdk_security_version;
duke@0 221 }
duke@0 222
duke@0 223 /**
amurillo@13201 224 * Returns the patch release version of the running JDK.
amurillo@13201 225 * @return the patch release version of the running JDK
amurillo@13184 226 * @since 9
duke@0 227 */
amurillo@13184 228 public static synchronized int jdkPatchVersion() {
duke@0 229 if (!versionsInitialized) {
duke@0 230 initVersions();
duke@0 231 }
amurillo@13184 232 return jdk_patch_version;
duke@0 233 }
duke@0 234
duke@0 235 /**
amurillo@13201 236 * Returns the build number of the running JDK.
amurillo@13201 237 * @return the build number of the running JDK
duke@0 238 * @since 1.6
duke@0 239 */
duke@0 240 public static synchronized int jdkBuildNumber() {
duke@0 241 if (!versionsInitialized) {
duke@0 242 initVersions();
duke@0 243 }
duke@0 244 return jdk_build_number;
duke@0 245 }
duke@0 246
duke@0 247 private static synchronized void initVersions() {
duke@0 248 if (versionsInitialized) {
duke@0 249 return;
duke@0 250 }
amurillo@13184 251 if (!getJvmVersionInfo()) {
amurillo@13184 252 throw new InternalError("Unable to obtain JVM version info");
duke@0 253 }
duke@0 254 getJdkVersionInfo();
duke@0 255 versionsInitialized = true;
duke@0 256 }
duke@0 257
duke@0 258 // Gets the JVM version info if available and sets the jvm_*_version fields
duke@0 259 // and its capabilities.
duke@0 260 private static native boolean getJvmVersionInfo();
duke@0 261 private static native void getJdkVersionInfo();
duke@0 262 }
duke@0 263
duke@0 264 // Help Emacs a little because this file doesn't end in .java.
duke@0 265 //
duke@0 266 // Local Variables: ***
duke@0 267 // mode: java ***
duke@0 268 // End: ***