8274670: Improve version string handling in SA

Reviewed-by: cjplummer, sspitsyn
This commit is contained in:
Yasumasa Suenaga 2021-10-06 00:36:50 +00:00
parent df7b0c7077
commit 986ee5d0bf
2 changed files with 14 additions and 14 deletions

View File

@ -359,26 +359,26 @@ public class VM {
if (System.getProperty("sun.jvm.hotspot.runtime.VM.disableVersionCheck") == null) { if (System.getProperty("sun.jvm.hotspot.runtime.VM.disableVersionCheck") == null) {
// read sa build version. // read sa build version.
String versionProp = "sun.jvm.hotspot.runtime.VM.saBuildVersion"; String versionProp = "sun.jvm.hotspot.runtime.VM.saBuildVersion";
String saVersion = saProps.getProperty(versionProp); String versionPropVal = saProps.getProperty(versionProp);
if (saVersion == null) if (versionPropVal == null) {
throw new RuntimeException("Missing property " + versionProp); throw new RuntimeException("Missing property " + versionProp);
}
// Strip nonproduct VM version substring (note: saVersion doesn't have it). var saVersion = Runtime.Version.parse(versionPropVal);
String vmVersion = vmRelease.replaceAll("(-fastdebug)|(-debug)|(-jvmg)|(-optimized)|(-profiled)",""); var vmVersion = Runtime.Version.parse(vmRelease);
if (saVersion.equals(vmVersion)) { if (saVersion.equals(vmVersion)) {
// Exact match // Exact match
return; return;
} }
if (saVersion.indexOf('-') == saVersion.lastIndexOf('-') && if (!saVersion.equalsIgnoreOptional(vmVersion)) {
vmVersion.indexOf('-') == vmVersion.lastIndexOf('-')) {
// Throw exception if different release versions: // Throw exception if different release versions:
// <major>.<minor>-b<n> // <version>+<build>
throw new VMVersionMismatchException(saVersion, vmRelease); throw new VMVersionMismatchException(saVersion, vmVersion);
} else { } else {
// Otherwise print warning to allow mismatch not release versions // Otherwise print warning to allow mismatch not release versions
// during development. // during development.
System.err.println("WARNING: Hotspot VM version " + vmRelease + System.err.println("WARNING: Hotspot VM version " + vmVersion +
" does not match with SA version " + saVersion + " does not match with SA version " + saVersion +
"." + " You may see unexpected results. "); "." + " You may see unexpected results. ");
} }

View File

@ -27,7 +27,7 @@ package sun.jvm.hotspot.runtime;
/** An instance of this exception is thrown when debuggee VM version /** An instance of this exception is thrown when debuggee VM version
is not supported current version of SA. */ is not supported current version of SA. */
public class VMVersionMismatchException extends RuntimeException { public class VMVersionMismatchException extends RuntimeException {
public VMVersionMismatchException(String supported, String target) { public VMVersionMismatchException(Runtime.Version supported, Runtime.Version target) {
super(); super();
supportedVersions = supported; supportedVersions = supported;
targetVersion = target; targetVersion = target;
@ -38,14 +38,14 @@ public class VMVersionMismatchException extends RuntimeException {
". Target VM is " + targetVersion; ". Target VM is " + targetVersion;
} }
public String getSupportedVersions() { public Runtime.Version getSupportedVersions() {
return supportedVersions; return supportedVersions;
} }
public String getTargetVersion() { public Runtime.Version getTargetVersion() {
return targetVersion; return targetVersion;
} }
private String supportedVersions; private final Runtime.Version supportedVersions;
private String targetVersion; private final Runtime.Version targetVersion;
} }