8087202: Add support for PATCH field and remove unused fields of new version string

Reviewed-by: dholmes, alanb
This commit is contained in:
Alejandro Murillo 2015-06-19 10:58:00 -07:00
parent 715981d1d4
commit c23fcc8a3e
6 changed files with 70 additions and 229 deletions

View File

@ -269,9 +269,7 @@ SUNWprivate_1.1 {
Java_sun_reflect_Reflection_getCallerClass__I; Java_sun_reflect_Reflection_getCallerClass__I;
Java_sun_reflect_Reflection_getClassAccessFlags; Java_sun_reflect_Reflection_getClassAccessFlags;
Java_sun_misc_Version_getJdkVersionInfo; Java_sun_misc_Version_getJdkVersionInfo;
Java_sun_misc_Version_getJdkSpecialVersion;
Java_sun_misc_Version_getJvmVersionInfo; Java_sun_misc_Version_getJvmVersionInfo;
Java_sun_misc_Version_getJvmSpecialVersion;
Java_sun_misc_VM_latestUserDefinedLoader; Java_sun_misc_VM_latestUserDefinedLoader;
Java_sun_misc_VM_getuid; Java_sun_misc_VM_getuid;
Java_sun_misc_VM_geteuid; Java_sun_misc_VM_geteuid;

View File

@ -55,15 +55,13 @@ public class Version {
private static int jvm_major_version = 0; private static int jvm_major_version = 0;
private static int jvm_minor_version = 0; private static int jvm_minor_version = 0;
private static int jvm_security_version = 0; private static int jvm_security_version = 0;
private static int jvm_update_version = 0; private static int jvm_patch_version = 0;
private static int jvm_build_number = 0; private static int jvm_build_number = 0;
private static String jvm_special_version = null;
private static int jdk_major_version = 0; private static int jdk_major_version = 0;
private static int jdk_minor_version = 0; private static int jdk_minor_version = 0;
private static int jdk_security_version = 0; private static int jdk_security_version = 0;
private static int jdk_update_version = 0; private static int jdk_patch_version = 0;
private static int jdk_build_number = 0; private static int jdk_build_number = 0;
private static String jdk_special_version = null;
/** /**
* In case you were wondering this method is called by java -version. * In case you were wondering this method is called by java -version.
@ -146,9 +144,7 @@ public class Version {
/** /**
* Returns the security version of the running JVM if it's 1.6 or newer * Returns the security version of the running JVM
* or any RE VM build. It will return 0 if it's an internal 1.5 or
* 1.4.x build.
* @since 1.6 * @since 1.6
*/ */
public static synchronized int jvmSecurityVersion() { public static synchronized int jvmSecurityVersion() {
@ -159,31 +155,18 @@ public class Version {
} }
/** /**
* Returns the update release version of the running JVM if it's * Returns the patch release version of the running JVM
* a RE build. It will return 0 if it's an internal build. * @since JDK9
* @since 1.6
*/ */
public static synchronized int jvmUpdateVersion() { public static synchronized int jvmPatchVersion() {
if (!versionsInitialized) { if (!versionsInitialized) {
initVersions(); initVersions();
} }
return jvm_update_version; return jvm_patch_version;
} }
public static synchronized String jvmSpecialVersion() {
if (!versionsInitialized) {
initVersions();
}
if (jvm_special_version == null) {
jvm_special_version = getJvmSpecialVersion();
}
return jvm_special_version;
}
public static native String getJvmSpecialVersion();
/** /**
* Returns the build number of the running JVM if it's a RE build * Returns the build number of the running JVM
* It will return 0 if it's an internal build.
* @since 1.6 * @since 1.6
*/ */
public static synchronized int jvmBuildNumber() { public static synchronized int jvmBuildNumber() {
@ -228,31 +211,18 @@ public class Version {
} }
/** /**
* Returns the update release version of the running JDK if it's * Returns the patch release version of the running JDK
* a RE build. It will return 0 if it's an internal build. * @since 9
* @since 1.6
*/ */
public static synchronized int jdkUpdateVersion() { public static synchronized int jdkPatchVersion() {
if (!versionsInitialized) { if (!versionsInitialized) {
initVersions(); initVersions();
} }
return jdk_update_version; return jdk_patch_version;
} }
public static synchronized String jdkSpecialVersion() {
if (!versionsInitialized) {
initVersions();
}
if (jdk_special_version == null) {
jdk_special_version = getJdkSpecialVersion();
}
return jdk_special_version;
}
public static native String getJdkSpecialVersion();
/** /**
* Returns the build number of the running JDK if it's a RE build * Returns the build number of the running JDK
* It will return 0 if it's an internal build.
* @since 1.6 * @since 1.6
*/ */
public static synchronized int jdkBuildNumber() { public static synchronized int jdkBuildNumber() {
@ -262,64 +232,12 @@ public class Version {
return jdk_build_number; return jdk_build_number;
} }
// true if JVM exports the version info including the capabilities
private static boolean jvmVersionInfoAvailable;
private static synchronized void initVersions() { private static synchronized void initVersions() {
if (versionsInitialized) { if (versionsInitialized) {
return; return;
} }
jvmVersionInfoAvailable = getJvmVersionInfo(); if (!getJvmVersionInfo()) {
if (!jvmVersionInfoAvailable) { throw new InternalError("Unable to obtain JVM version info");
// parse java.vm.version for older JVM before the
// new JVM_GetVersionInfo is added.
// valid format of the version string is:
// n.n.n[_uu[c]][-<identifer>]-bxx
CharSequence cs = System.getProperty("java.vm.version");
if (cs.length() >= 5 &&
Character.isDigit(cs.charAt(0)) && cs.charAt(1) == '.' &&
Character.isDigit(cs.charAt(2)) && cs.charAt(3) == '.' &&
Character.isDigit(cs.charAt(4))) {
jvm_major_version = Character.digit(cs.charAt(0), 10);
jvm_minor_version = Character.digit(cs.charAt(2), 10);
jvm_security_version = Character.digit(cs.charAt(4), 10);
cs = cs.subSequence(5, cs.length());
if (cs.charAt(0) == '_' && cs.length() >= 3 &&
Character.isDigit(cs.charAt(1)) &&
Character.isDigit(cs.charAt(2))) {
int nextChar = 3;
try {
String uu = cs.subSequence(1, 3).toString();
jvm_update_version = Integer.valueOf(uu).intValue();
if (cs.length() >= 4) {
char c = cs.charAt(3);
if (c >= 'a' && c <= 'z') {
jvm_special_version = Character.toString(c);
nextChar++;
}
}
} catch (NumberFormatException e) {
// not conforming to the naming convention
return;
}
cs = cs.subSequence(nextChar, cs.length());
}
if (cs.charAt(0) == '-') {
// skip the first character
// valid format: <identifier>-bxx or bxx
// non-product VM will have -debug|-release appended
cs = cs.subSequence(1, cs.length());
String[] res = cs.toString().split("-");
for (String s : res) {
if (s.charAt(0) == 'b' && s.length() == 3 &&
Character.isDigit(s.charAt(1)) &&
Character.isDigit(s.charAt(2))) {
jvm_build_number =
Integer.valueOf(s.substring(1, 3)).intValue();
break;
}
}
}
}
} }
getJdkVersionInfo(); getJdkVersionInfo();
versionsInitialized = true; versionsInitialized = true;
@ -327,8 +245,6 @@ public class Version {
// Gets the JVM version info if available and sets the jvm_*_version fields // Gets the JVM version info if available and sets the jvm_*_version fields
// and its capabilities. // and its capabilities.
//
// Return false if not available which implies an old VM (Tiger or before).
private static native boolean getJvmVersionInfo(); private static native boolean getJvmVersionInfo();
private static native void getJdkVersionInfo(); private static native void getJdkVersionInfo();
} }

View File

@ -1127,9 +1127,9 @@ JVM_GetEnclosingMethodInfo(JNIEnv* env, jclass ofClass);
* ========================================================================== * ==========================================================================
*/ */
typedef struct { typedef struct {
unsigned int jvm_version; /* Follows JDK version string as specified by JEP-223 */ unsigned int jvm_version; /* Encoded $VNUM as specified by JEP-223 */
unsigned int update_version : 8; /* Update release version (uu) */ unsigned int patch_version : 8; /* JEP-223 patch version */
unsigned int special_update_version : 8; /* Special update release version (c)*/ unsigned int reserved3 : 8;
unsigned int reserved1 : 16; unsigned int reserved1 : 16;
unsigned int reserved2; unsigned int reserved2;
@ -1149,19 +1149,15 @@ typedef struct {
#define JVM_VERSION_MAJOR(version) ((version & 0xFF000000) >> 24) #define JVM_VERSION_MAJOR(version) ((version & 0xFF000000) >> 24)
#define JVM_VERSION_MINOR(version) ((version & 0x00FF0000) >> 16) #define JVM_VERSION_MINOR(version) ((version & 0x00FF0000) >> 16)
#define JVM_VERSION_SECURITY(version) ((version & 0x0000FF00) >> 8) #define JVM_VERSION_SECURITY(version) ((version & 0x0000FF00) >> 8)
/* Build number is available only for RE builds.
* It will be zero for internal builds.
*/
#define JVM_VERSION_BUILD(version) ((version & 0x000000FF)) #define JVM_VERSION_BUILD(version) ((version & 0x000000FF))
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
JVM_GetVersionInfo(JNIEnv* env, jvm_version_info* info, size_t info_size); JVM_GetVersionInfo(JNIEnv* env, jvm_version_info* info, size_t info_size);
typedef struct { typedef struct {
unsigned int jdk_version; /* JDK version string as specified by JEP-223 */ unsigned int jdk_version; /* Encoded $VNUM as specified by JEP-223 */
unsigned int update_version : 8; /* Update release version (uu) */ unsigned int patch_version : 8; /* JEP-223 patch version */
unsigned int special_update_version : 8; /* Special update release version (c)*/ unsigned int reserved3 : 8;
unsigned int reserved1 : 16; unsigned int reserved1 : 16;
unsigned int reserved2; unsigned int reserved2;
@ -1183,10 +1179,6 @@ typedef struct {
#define JDK_VERSION_MAJOR(version) ((version & 0xFF000000) >> 24) #define JDK_VERSION_MAJOR(version) ((version & 0xFF000000) >> 24)
#define JDK_VERSION_MINOR(version) ((version & 0x00FF0000) >> 16) #define JDK_VERSION_MINOR(version) ((version & 0x00FF0000) >> 16)
#define JDK_VERSION_SECURITY(version) ((version & 0x0000FF00) >> 8) #define JDK_VERSION_SECURITY(version) ((version & 0x0000FF00) >> 8)
/* Build number is available only for RE build (i.e. JDK_BUILD_NUMBER is set to NN)
* It will be zero for internal builds.
*/
#define JDK_VERSION_BUILD(version) ((version & 0x000000FF)) #define JDK_VERSION_BUILD(version) ((version & 0x000000FF))
/* /*

View File

@ -30,8 +30,6 @@
#include "sun_misc_Version.h" #include "sun_misc_Version.h"
char jvm_special_version = '\0';
char jdk_special_version = '\0';
static void setStaticIntField(JNIEnv* env, jclass cls, const char* name, jint value) static void setStaticIntField(JNIEnv* env, jclass cls, const char* name, jint value)
{ {
jfieldID fid; jfieldID fid;
@ -67,23 +65,12 @@ Java_sun_misc_Version_getJvmVersionInfo(JNIEnv *env, jclass cls)
JNU_CHECK_EXCEPTION_RETURN(env, JNI_FALSE); JNU_CHECK_EXCEPTION_RETURN(env, JNI_FALSE);
setStaticIntField(env, cls, "jvm_build_number", JVM_VERSION_BUILD(info.jvm_version)); setStaticIntField(env, cls, "jvm_build_number", JVM_VERSION_BUILD(info.jvm_version));
JNU_CHECK_EXCEPTION_RETURN(env, JNI_FALSE); JNU_CHECK_EXCEPTION_RETURN(env, JNI_FALSE);
setStaticIntField(env, cls, "jvm_update_version", info.update_version); setStaticIntField(env, cls, "jvm_patch_version", info.patch_version);
JNU_CHECK_EXCEPTION_RETURN(env, JNI_FALSE); JNU_CHECK_EXCEPTION_RETURN(env, JNI_FALSE);
jvm_special_version = info.special_update_version;
return JNI_TRUE; return JNI_TRUE;
} }
JNIEXPORT jstring JNICALL
Java_sun_misc_Version_getJvmSpecialVersion(JNIEnv *env, jclass cls) {
char s[2];
jstring special;
s[0] = jvm_special_version;
s[1] = '\0';
special = (*env)->NewStringUTF(env, s);
return special;
}
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_sun_misc_Version_getJdkVersionInfo(JNIEnv *env, jclass cls) Java_sun_misc_Version_getJdkVersionInfo(JNIEnv *env, jclass cls)
{ {
@ -98,17 +85,6 @@ Java_sun_misc_Version_getJdkVersionInfo(JNIEnv *env, jclass cls)
JNU_CHECK_EXCEPTION(env); JNU_CHECK_EXCEPTION(env);
setStaticIntField(env, cls, "jdk_build_number", JDK_VERSION_BUILD(info.jdk_version)); setStaticIntField(env, cls, "jdk_build_number", JDK_VERSION_BUILD(info.jdk_version));
JNU_CHECK_EXCEPTION(env); JNU_CHECK_EXCEPTION(env);
setStaticIntField(env, cls, "jdk_update_version", info.update_version); setStaticIntField(env, cls, "jdk_patch_version", info.patch_version);
JNU_CHECK_EXCEPTION(env); JNU_CHECK_EXCEPTION(env);
jdk_special_version = info.special_update_version;
}
JNIEXPORT jstring JNICALL
Java_sun_misc_Version_getJdkSpecialVersion(JNIEnv *env, jclass cls) {
char s[2];
jstring special;
s[0] = jdk_special_version;
s[1] = '\0';
special = (*env)->NewStringUTF(env, s);
return special;
} }

View File

@ -37,6 +37,7 @@ JDK_GetVersionInfo0(jdk_version_info* info, size_t info_size) {
const unsigned int version_major = VERSION_MAJOR; const unsigned int version_major = VERSION_MAJOR;
const unsigned int version_minor = VERSION_MINOR; const unsigned int version_minor = VERSION_MINOR;
const unsigned int version_security = VERSION_SECURITY; const unsigned int version_security = VERSION_SECURITY;
const unsigned int version_patch = VERSION_PATCH;
const unsigned int version_build = VERSION_BUILD; const unsigned int version_build = VERSION_BUILD;
memset(info, 0, info_size); memset(info, 0, info_size);
@ -44,9 +45,7 @@ JDK_GetVersionInfo0(jdk_version_info* info, size_t info_size) {
((version_minor & 0xFF) << 16) | ((version_minor & 0xFF) << 16) |
((version_security & 0xFF) << 8) | ((version_security & 0xFF) << 8) |
(version_build & 0xFF); (version_build & 0xFF);
// FIXME: update_version and special_update_version does not make sense anymore. info->patch_version = version_patch;
info->update_version = 0;
info->special_update_version = 0;
info->thread_park_blocker = 1; info->thread_park_blocker = 1;
// Advertise presence of sun.misc.PostVMInitHook: // Advertise presence of sun.misc.PostVMInitHook:
// future optimization: detect if this is enabled. // future optimization: detect if this is enabled.

View File

@ -31,6 +31,9 @@
*/ */
import static sun.misc.Version.*; import static sun.misc.Version.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Version { public class Version {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
@ -38,8 +41,7 @@ public class Version {
VersionInfo v1 = new VersionInfo(jdkMajorVersion(), VersionInfo v1 = new VersionInfo(jdkMajorVersion(),
jdkMinorVersion(), jdkMinorVersion(),
jdkSecurityVersion(), jdkSecurityVersion(),
jdkUpdateVersion(), jdkPatchVersion(),
jdkSpecialVersion(),
jdkBuildNumber()); jdkBuildNumber());
System.out.println("JDK version = " + jdk + " " + v1); System.out.println("JDK version = " + jdk + " " + v1);
if (!jdk.equals(v1)) { if (!jdk.equals(v1)) {
@ -49,8 +51,7 @@ public class Version {
VersionInfo v2 = new VersionInfo(jvmMajorVersion(), VersionInfo v2 = new VersionInfo(jvmMajorVersion(),
jvmMinorVersion(), jvmMinorVersion(),
jvmSecurityVersion(), jvmSecurityVersion(),
jvmUpdateVersion(), jvmPatchVersion(),
jvmSpecialVersion(),
jvmBuildNumber()); jvmBuildNumber());
System.out.println("JVM version = " + jvm + " " + v2); System.out.println("JVM version = " + jvm + " " + v2);
if (!jvm.equals(v2)) { if (!jvm.equals(v2)) {
@ -61,108 +62,67 @@ public class Version {
static class VersionInfo { static class VersionInfo {
final int major; final int major;
final int minor; final int minor;
final int micro; final int security;
final int update; final int patch;
final String special;
final int build; final int build;
VersionInfo(int major, int minor, int micro, VersionInfo(int major, int minor, int security,
int update, String special, int build) { int patch, int build) {
this.major = major; this.major = major;
this.minor = minor; this.minor = minor;
this.micro = micro; this.security = security;
this.update = update; this.patch = patch;
this.special = special;
this.build = build; 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) { public boolean equals(VersionInfo v) {
return (this.major == v.major && this.minor == v.minor && return (this.major == v.major && this.minor == v.minor &&
this.micro == v.micro && this.update == v.update && this.security == v.security && this.patch == v.patch &&
this.special.equals(v.special) && this.build == v.build); this.build == v.build);
} }
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append(major + "." + minor + "." + micro); sb.append(major + "." + minor + "." + security);
if (update > 0) { if (patch > 0) {
sb.append("_" + update); sb.append("." + patch);
} }
if (!special.isEmpty()) { sb.append("+" + build);
sb.append(special);
}
sb.append("-b" + build);
return sb.toString(); return sb.toString();
} }
} }
private static VersionInfo newVersionInfo(String version) throws Exception { private static VersionInfo newVersionInfo(String version) throws Exception {
// valid format of the version string is: // Version string fromat as defined by JEP-223
// n.n.n[_uu[c]][-<identifer>]-bxx String jep223Pattern =
int major = 0; "^([0-9]+)(\\.([0-9]+))?(\\.([0-9]+))?(\\.([0-9]+))?" + // $VNUM
int minor = 0; "(-([a-zA-Z]+))?(\\.([a-zA-Z]+))?" + // $PRE
int micro = 0; "(\\+([0-9]+))?" + // Build Number
int update = 0; "(([-a-zA-Z0-9.]+))?$"; // $OPT
String special = "";
int build = 0; // Pattern group index for: Major, Minor, Security, Patch, Build
CharSequence cs = version; int[] groups = {1, 3, 5, 7, 13};
if (cs.length() >= 5) { // Default values for Major, Minor, Security, Patch, Build
if (Character.isDigit(cs.charAt(0)) && cs.charAt(1) == '.' && int[] versionFields = {0, 0, 0, 0, 0};
Character.isDigit(cs.charAt(2)) && cs.charAt(3) == '.' &&
Character.isDigit(cs.charAt(4))) { Pattern pattern = Pattern.compile(jep223Pattern);
major = Character.digit(cs.charAt(0), 10); Matcher matcher = pattern.matcher(version);
minor = Character.digit(cs.charAt(2), 10); if (matcher.matches()) {
micro = Character.digit(cs.charAt(4), 10); for (int i = 0; i < versionFields.length; i++) {
cs = cs.subSequence(5, cs.length()); String field = matcher.group(groups[i]);
} else if (Character.isDigit(cs.charAt(0)) && versionFields[i] = (field != null) ? Integer.parseInt(field) : 0;
Character.isDigit(cs.charAt(1)) && cs.charAt(2) == '.' &&
Character.isDigit(cs.charAt(3))) {
// HSX has nn.n[n] (major.minor) version
major = Integer.valueOf(version.substring(0, 2)).intValue();
if (Character.isDigit(cs.charAt(4))) {
minor = Integer.valueOf(version.substring(3, 5)).intValue();
cs = cs.subSequence(5, cs.length());
}
else {
minor = Character.digit(cs.charAt(3), 10);
cs = cs.subSequence(4, cs.length());
}
}
if (cs.charAt(0) == '_' && cs.length() >= 3 &&
Character.isDigit(cs.charAt(1)) &&
Character.isDigit(cs.charAt(2))) {
int nextChar = 3;
String uu = cs.subSequence(1, 3).toString();
update = Integer.valueOf(uu).intValue();
if (cs.length() >= 4) {
char c = cs.charAt(3);
if (c >= 'a' && c <= 'z') {
special = Character.toString(c);
nextChar++;
}
}
cs = cs.subSequence(nextChar, cs.length());
}
if (cs.charAt(0) == '-') {
// skip the first character
// valid format: <identifier>-bxx or bxx
// non-product VM will have -debug|-release appended
cs = cs.subSequence(1, cs.length());
String[] res = cs.toString().split("-");
for (int i = res.length - 1; i >= 0; i--) {
String s = res[i];
if (s.charAt(0) == 'b') {
try {
build = Integer.parseInt(s.substring(1, s.length()));
break;
} catch (NumberFormatException nfe) {
// ignore
}
}
}
} }
} }
VersionInfo vi = new VersionInfo(major, minor, micro, update, special, build);
VersionInfo vi = new VersionInfo(versionFields);
System.out.printf("newVersionInfo: input=%s output=%s\n", version, vi); System.out.printf("newVersionInfo: input=%s output=%s\n", version, vi);
return vi; return vi;
} }