8150162: Move sun.misc.Version to a truly internal package
Reviewed-by: alanb, iris, mchung, rriggs
--- a/jdk/make/gensrc/GensrcMisc.gmk Thu Mar 03 10:06:25 2016 +0100
+++ b/jdk/make/gensrc/GensrcMisc.gmk Thu Mar 03 12:07:13 2016 +0000
@@ -25,11 +25,11 @@
##########################################################################################
# Install the launcher name, release version string, full version
-# string and the runtime name into the Version.java file.
+# string and the runtime name into the VersionProps.java file.
$(eval $(call SetupTextFileProcessing, BUILD_VERSION_JAVA, \
- SOURCE_FILES := $(JDK_TOPDIR)/src/java.base/share/classes/sun/misc/Version.java.template, \
- OUTPUT_FILE := $(SUPPORT_OUTPUTDIR)/gensrc/java.base/sun/misc/Version.java, \
+ SOURCE_FILES := $(JDK_TOPDIR)/src/java.base/share/classes/java/lang/VersionProps.java.template, \
+ OUTPUT_FILE := $(SUPPORT_OUTPUTDIR)/gensrc/java.base/java/lang/VersionProps.java, \
REPLACEMENTS := \
@@LAUNCHER_NAME@@ => $(LAUNCHER_NAME) ; \
@@RUNTIME_NAME@@ => $(RUNTIME_NAME) ; \
--- a/jdk/make/mapfiles/libjava/mapfile-vers Thu Mar 03 10:06:25 2016 +0100
+++ b/jdk/make/mapfiles/libjava/mapfile-vers Thu Mar 03 12:07:13 2016 +0000
@@ -268,8 +268,6 @@
Java_sun_reflect_Reflection_getCallerClass__;
Java_sun_reflect_Reflection_getCallerClass__I;
Java_sun_reflect_Reflection_getClassAccessFlags;
- Java_sun_misc_Version_getJdkVersionInfo;
- Java_sun_misc_Version_getJvmVersionInfo;
Java_jdk_internal_misc_VM_latestUserDefinedLoader;
Java_jdk_internal_misc_VM_getuid;
Java_jdk_internal_misc_VM_geteuid;
--- a/jdk/src/java.base/share/classes/java/lang/System.java Thu Mar 03 10:06:25 2016 +0100
+++ b/jdk/src/java.base/share/classes/java/lang/System.java Thu Mar 03 12:07:13 2016 +0000
@@ -1830,7 +1830,7 @@
lineSeparator = props.getProperty("line.separator");
- sun.misc.Version.init();
+ VersionProps.init();
FileInputStream fdIn = new FileInputStream(FileDescriptor.in);
FileOutputStream fdOut = new FileOutputStream(FileDescriptor.out);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/java/lang/VersionProps.java.template Thu Mar 03 12:07:13 2016 +0000
@@ -0,0 +1,114 @@
+/*
+ * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package java.lang;
+
+import java.io.PrintStream;
+
+class VersionProps {
+
+
+ private static final String launcher_name =
+ "@@LAUNCHER_NAME@@";
+
+ private static final String java_version =
+ "@@VERSION_SHORT@@";
+
+ private static final String java_runtime_name =
+ "@@RUNTIME_NAME@@";
+
+ private static final String java_runtime_version =
+ "@@VERSION_STRING@@";
+
+ static {
+ init();
+ }
+
+ public static void init() {
+ System.setProperty("java.version", java_version);
+ System.setProperty("java.runtime.version", java_runtime_version);
+ System.setProperty("java.runtime.name", java_runtime_name);
+ }
+
+ /**
+ * In case you were wondering this method is called by java -version.
+ * Sad that it prints to stderr; would be nicer if default printed on
+ * stdout.
+ */
+ public static void print() {
+ print(System.err);
+ }
+
+ /**
+ * This is the same as print except that it adds an extra line-feed
+ * at the end, typically used by the -showversion in the launcher
+ */
+ public static void println() {
+ print(System.err);
+ System.err.println();
+ }
+
+ /**
+ * Give a stream, it will print version info on it.
+ */
+ public static void print(PrintStream ps) {
+ boolean isHeadless = false;
+
+ /* Report that we're running headless if the property is true */
+ String headless = System.getProperty("java.awt.headless");
+ if ( (headless != null) && (headless.equalsIgnoreCase("true")) ) {
+ isHeadless = true;
+ }
+
+ /* First line: platform version. */
+ ps.println(launcher_name + " version \"" + java_version + "\"");
+
+ /* Second line: runtime version (ie, libraries). */
+
+ String jdk_debug_level = System.getProperty("jdk.debug", "release");
+ /* Debug level is not printed for "release" builds */
+ if ("release".equals(jdk_debug_level)) {
+ jdk_debug_level = "";
+ } else {
+ jdk_debug_level = jdk_debug_level + " ";
+ }
+
+ ps.print(java_runtime_name + " (" + jdk_debug_level + "build " + java_runtime_version);
+
+ if (java_runtime_name.indexOf("Embedded") != -1 && isHeadless) {
+ // embedded builds report headless state
+ ps.print(", headless");
+ }
+ ps.println(')');
+
+ /* Third line: JVM information. */
+ String java_vm_name = System.getProperty("java.vm.name");
+ String java_vm_version = System.getProperty("java.vm.version");
+ String java_vm_info = System.getProperty("java.vm.info");
+ ps.println(java_vm_name + " (" + jdk_debug_level + "build " + java_vm_version + ", " +
+ java_vm_info + ")");
+ }
+
+}
\ No newline at end of file
--- a/jdk/src/java.base/share/classes/sun/misc/Version.java.template Thu Mar 03 10:06:25 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,268 +0,0 @@
-/*
- * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package sun.misc;
-import java.io.PrintStream;
-
-public class Version {
-
-
- private static final String launcher_name =
- "@@LAUNCHER_NAME@@";
-
- private static final String java_version =
- "@@VERSION_SHORT@@";
-
- private static final String java_runtime_name =
- "@@RUNTIME_NAME@@";
-
- private static final String java_runtime_version =
- "@@VERSION_STRING@@";
-
- static {
- init();
- }
-
- public static void init() {
- System.setProperty("java.version", java_version);
- System.setProperty("java.runtime.version", java_runtime_version);
- System.setProperty("java.runtime.name", java_runtime_name);
- }
-
- private static boolean versionsInitialized = false;
- private static int jvm_major_version = 0;
- private static int jvm_minor_version = 0;
- private static int jvm_security_version = 0;
- private static int jvm_patch_version = 0;
- private static int jvm_build_number = 0;
- private static int jdk_major_version = 0;
- private static int jdk_minor_version = 0;
- private static int jdk_security_version = 0;
- private static int jdk_patch_version = 0;
- private static int jdk_build_number = 0;
-
- /**
- * In case you were wondering this method is called by java -version.
- * Sad that it prints to stderr; would be nicer if default printed on
- * stdout.
- */
- public static void print() {
- print(System.err);
- }
-
- /**
- * This is the same as print except that it adds an extra line-feed
- * at the end, typically used by the -showversion in the launcher
- */
- public static void println() {
- print(System.err);
- System.err.println();
- }
-
- /**
- * Give a stream, it will print version info on it.
- */
- public static void print(PrintStream ps) {
- boolean isHeadless = false;
-
- /* Report that we're running headless if the property is true */
- String headless = System.getProperty("java.awt.headless");
- if ( (headless != null) && (headless.equalsIgnoreCase("true")) ) {
- isHeadless = true;
- }
-
- /* First line: platform version. */
- ps.println(launcher_name + " version \"" + java_version + "\"");
-
- /* Second line: runtime version (ie, libraries). */
-
- String jdk_debug_level = System.getProperty("jdk.debug", "release");
- /* Debug level is not printed for "release" builds */
- if ("release".equals(jdk_debug_level)) {
- jdk_debug_level = "";
- } else {
- jdk_debug_level = jdk_debug_level + " ";
- }
-
- ps.print(java_runtime_name + " (" + jdk_debug_level + "build " + java_runtime_version);
-
- if (java_runtime_name.indexOf("Embedded") != -1 && isHeadless) {
- // embedded builds report headless state
- ps.print(", headless");
- }
- ps.println(')');
-
- /* Third line: JVM information. */
- String java_vm_name = System.getProperty("java.vm.name");
- String java_vm_version = System.getProperty("java.vm.version");
- String java_vm_info = System.getProperty("java.vm.info");
- ps.println(java_vm_name + " (" + jdk_debug_level + "build " + java_vm_version + ", " +
- java_vm_info + ")");
- }
-
-
- /**
- * Returns the major version of the running JVM.
- * @return the major version of the running JVM
- * @since 1.6
- */
- public static synchronized int jvmMajorVersion() {
- if (!versionsInitialized) {
- initVersions();
- }
- return jvm_major_version;
- }
-
- /**
- * Returns the minor version of the running JVM.
- * @return the minor version of the running JVM
- * @since 1.6
- */
- public static synchronized int jvmMinorVersion() {
- if (!versionsInitialized) {
- initVersions();
- }
- return jvm_minor_version;
- }
-
-
- /**
- * Returns the security version of the running JVM.
- * @return the security version of the running JVM
- * @since 9
- */
- public static synchronized int jvmSecurityVersion() {
- if (!versionsInitialized) {
- initVersions();
- }
- return jvm_security_version;
- }
-
- /**
- * Returns the patch release version of the running JVM.
- * @return the patch release version of the running JVM
- * @since 9
- */
- public static synchronized int jvmPatchVersion() {
- if (!versionsInitialized) {
- initVersions();
- }
- return jvm_patch_version;
- }
-
- /**
- * Returns the build number of the running JVM.
- * @return the build number of the running JVM
- * @since 1.6
- */
- public static synchronized int jvmBuildNumber() {
- if (!versionsInitialized) {
- initVersions();
- }
- return jvm_build_number;
- }
-
- /**
- * Returns the major version of the running JDK.
- * @return the major version of the running JDK
- * @since 1.6
- */
- public static synchronized int jdkMajorVersion() {
- if (!versionsInitialized) {
- initVersions();
- }
- return jdk_major_version;
- }
-
- /**
- * Returns the minor version of the running JDK.
- * @return the minor version of the running JDK
- * @since 1.6
- */
- public static synchronized int jdkMinorVersion() {
- if (!versionsInitialized) {
- initVersions();
- }
- return jdk_minor_version;
- }
-
- /**
- * Returns the security version of the running JDK.
- * @return the security version of the running JDK
- * @since 9
- */
- public static synchronized int jdkSecurityVersion() {
- if (!versionsInitialized) {
- initVersions();
- }
- return jdk_security_version;
- }
-
- /**
- * Returns the patch release version of the running JDK.
- * @return the patch release version of the running JDK
- * @since 9
- */
- public static synchronized int jdkPatchVersion() {
- if (!versionsInitialized) {
- initVersions();
- }
- return jdk_patch_version;
- }
-
- /**
- * Returns the build number of the running JDK.
- * @return the build number of the running JDK
- * @since 1.6
- */
- public static synchronized int jdkBuildNumber() {
- if (!versionsInitialized) {
- initVersions();
- }
- return jdk_build_number;
- }
-
- private static synchronized void initVersions() {
- if (versionsInitialized) {
- return;
- }
- if (!getJvmVersionInfo()) {
- throw new InternalError("Unable to obtain JVM version info");
- }
- getJdkVersionInfo();
- versionsInitialized = true;
- }
-
- // Gets the JVM version info if available and sets the jvm_*_version fields
- // and its capabilities.
- private static native boolean getJvmVersionInfo();
- private static native void getJdkVersionInfo();
-}
-
-// Help Emacs a little because this file doesn't end in .java.
-//
-// Local Variables: ***
-// mode: java ***
-// End: ***
--- a/jdk/src/java.base/share/native/libjava/Version.c Thu Mar 03 10:06:25 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,90 +0,0 @@
-/*
- * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-#include "jni.h"
-#include "jni_util.h"
-#include "jvm.h"
-#include "jdk_util.h"
-
-#include "sun_misc_Version.h"
-
-static void setStaticIntField(JNIEnv* env, jclass cls, const char* name, jint value)
-{
- jfieldID fid;
- fid = (*env)->GetStaticFieldID(env, cls, name, "I");
- if (fid != 0) {
- (*env)->SetStaticIntField(env, cls, fid, value);
- }
-}
-
-typedef void (JNICALL *GetJvmVersionInfo_fp)(JNIEnv*, jvm_version_info*, size_t);
-
-JNIEXPORT jboolean JNICALL
-Java_sun_misc_Version_getJvmVersionInfo(JNIEnv *env, jclass cls)
-{
- jvm_version_info info;
- GetJvmVersionInfo_fp func_p;
-
- if (!JDK_InitJvmHandle()) {
- JNU_ThrowInternalError(env, "Handle for JVM not found for symbol lookup");
- return JNI_FALSE;
- }
- func_p = (GetJvmVersionInfo_fp) JDK_FindJvmEntry("JVM_GetVersionInfo");
- if (func_p == NULL) {
- return JNI_FALSE;
- }
-
- (*func_p)(env, &info, sizeof(info));
- setStaticIntField(env, cls, "jvm_major_version", JVM_VERSION_MAJOR(info.jvm_version));
- JNU_CHECK_EXCEPTION_RETURN(env, JNI_FALSE);
- setStaticIntField(env, cls, "jvm_minor_version", JVM_VERSION_MINOR(info.jvm_version));
- JNU_CHECK_EXCEPTION_RETURN(env, JNI_FALSE);
- setStaticIntField(env, cls, "jvm_security_version", JVM_VERSION_SECURITY(info.jvm_version));
- JNU_CHECK_EXCEPTION_RETURN(env, JNI_FALSE);
- setStaticIntField(env, cls, "jvm_build_number", JVM_VERSION_BUILD(info.jvm_version));
- JNU_CHECK_EXCEPTION_RETURN(env, JNI_FALSE);
- setStaticIntField(env, cls, "jvm_patch_version", info.patch_version);
- JNU_CHECK_EXCEPTION_RETURN(env, JNI_FALSE);
-
- return JNI_TRUE;
-}
-
-JNIEXPORT void JNICALL
-Java_sun_misc_Version_getJdkVersionInfo(JNIEnv *env, jclass cls)
-{
- jdk_version_info info;
-
- JDK_GetVersionInfo0(&info, sizeof(info));
- setStaticIntField(env, cls, "jdk_major_version", JDK_VERSION_MAJOR(info.jdk_version));
- JNU_CHECK_EXCEPTION(env);
- setStaticIntField(env, cls, "jdk_minor_version", JDK_VERSION_MINOR(info.jdk_version));
- JNU_CHECK_EXCEPTION(env);
- setStaticIntField(env, cls, "jdk_security_version", JDK_VERSION_SECURITY(info.jdk_version));
- JNU_CHECK_EXCEPTION(env);
- setStaticIntField(env, cls, "jdk_build_number", JDK_VERSION_BUILD(info.jdk_version));
- JNU_CHECK_EXCEPTION(env);
- setStaticIntField(env, cls, "jdk_patch_version", info.patch_version);
- JNU_CHECK_EXCEPTION(env);
-}
--- a/jdk/src/java.base/share/native/libjli/java.c Thu Mar 03 10:06:25 2016 +0100
+++ b/jdk/src/java.base/share/native/libjli/java.c Thu Mar 03 12:07:13 2016 +0000
@@ -1470,7 +1470,7 @@
jclass ver;
jmethodID print;
- NULL_CHECK(ver = FindBootStrapClass(env, "sun/misc/Version"));
+ NULL_CHECK(ver = FindBootStrapClass(env, "java/lang/VersionProps"));
NULL_CHECK(print = (*env)->GetStaticMethodID(env,
ver,
(extraLF == JNI_TRUE) ? "println" : "print",
--- a/jdk/test/sun/misc/Version/Version.java Thu Mar 03 10:06:25 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,139 +0,0 @@
-/*
- * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/* @test
- * @bug 6994413 8134365
- * @summary Check the JDK and JVM version returned by sun.misc.Version
- * matches the versions defined in the system properties.
- * Should use the API described in JDK-8136651 when available
- * @modules java.base/sun.misc
- * @compile -XDignore.symbol.file Version.java
- * @run main Version
- */
-
-import static sun.misc.Version.*;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-public class Version {
-
- public static void main(String[] args) throws Exception {
- VersionInfo jdk = newVersionInfo(System.getProperty("java.runtime.version"));
- VersionInfo v1 = new VersionInfo(jdkMajorVersion(),
- jdkMinorVersion(),
- jdkSecurityVersion(),
- jdkPatchVersion(),
- jdkBuildNumber());
- System.out.println("JDK version = " + jdk + " " + v1);
- if (!jdk.equals(v1)) {
- throw new RuntimeException("Unmatched version: " + jdk + " vs " + v1);
- }
- VersionInfo jvm = newVersionInfo(System.getProperty("java.vm.version"));
- VersionInfo v2 = new VersionInfo(jvmMajorVersion(),
- jvmMinorVersion(),
- jvmSecurityVersion(),
- jvmPatchVersion(),
- jvmBuildNumber());
- System.out.println("JVM version = " + jvm + " " + v2);
- if (!jvm.equals(v2)) {
- throw new RuntimeException("Unmatched version: " + jvm + " vs " + v2);
- }
- }
-
- static class VersionInfo {
- final int major;
- final int minor;
- final int security;
- final int patch;
- final int build;
- VersionInfo(int major, int minor, int security,
- int patch, int build) {
- this.major = major;
- this.minor = minor;
- this.security = security;
- this.patch = patch;
- this.build = build;
- }
-
- VersionInfo(int[] fields) {
- this.major = fields[0];
- this.minor = fields[1];
- this.security = fields[2];
- this.patch = fields[3];
- this.build = fields[4];
- }
-
- public boolean equals(VersionInfo v) {
- return (this.major == v.major && this.minor == v.minor &&
- this.security == v.security && this.patch == v.patch &&
- this.build == v.build);
- }
-
- public String toString() {
- StringBuilder sb = new StringBuilder();
- // Do not include trailing zeros
- if (patch > 0) {
- sb.insert(0, "." + patch);
- }
- if (security > 0 || sb.length() > 0) {
- sb.insert(0, "." + security);
- }
- if (minor > 0 || sb.length() > 0) {
- sb.insert(0, "." + minor);
- }
- sb.insert(0, major);
-
- if (build >= 0)
- sb.append("+" + build);
-
- return sb.toString();
- }
- }
-
- private static VersionInfo newVersionInfo(String version) throws Exception {
- // Version string fromat as defined by JEP-223
- String jep223Pattern =
- "^([0-9]+)(\\.([0-9]+))?(\\.([0-9]+))?(\\.([0-9]+))?" + // $VNUM
- "(-([a-zA-Z]+))?(\\.([a-zA-Z]+))?" + // $PRE
- "(\\+([0-9]+))?" + // Build Number
- "(([-a-zA-Z0-9.]+))?$"; // $OPT
-
- // Pattern group index for: Major, Minor, Security, Patch, Build
- int[] groups = {1, 3, 5, 7, 13};
- // Default values for Major, Minor, Security, Patch, Build
- int[] versionFields = {0, 0, 0, 0, 0};
-
- Pattern pattern = Pattern.compile(jep223Pattern);
- Matcher matcher = pattern.matcher(version);
- if (matcher.matches()) {
- for (int i = 0; i < versionFields.length; i++) {
- String field = matcher.group(groups[i]);
- versionFields[i] = (field != null) ? Integer.parseInt(field) : 0;
- }
- }
-
- VersionInfo vi = new VersionInfo(versionFields);
- System.out.printf("newVersionInfo: input=%s output=%s\n", version, vi);
- return vi;
- }
-}