Skip to content

Commit

Permalink
compiler: strip optional java version part in JVMCIVersionCheck
Browse files Browse the repository at this point in the history
  • Loading branch information
zapster committed Dec 15, 2023
1 parent 468811f commit b0821d5
Showing 1 changed file with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,38 @@ private Version(String jdkVersionString, int jvmciMajor, int jvmciMinor, int jvm
}

private Version(Runtime.Version jdkVersion, int jvmciMajor, int jvmciMinor, int jvmciBuild, boolean legacy) {
this.jdkVersion = jdkVersion;
this.jdkVersion = stripOptional(jdkVersion);
this.jvmciMajor = jvmciMajor;
this.jvmciMinor = jvmciMinor;
this.jvmciBuild = jvmciBuild;
this.legacy = legacy;
}

/**
* Gets rid of the {@link Runtime.Version#optional()} part of a version string. See
* {@link Runtime.Version} for details about the version string format.
*/
private static Runtime.Version stripOptional(Runtime.Version jdkVersion) {
if (!jdkVersion.optional().isPresent()) {
return jdkVersion;
}
String jdkVersionStr = jdkVersion.toString();
final int optionalLength;
if (!jdkVersion.pre().isPresent() && !jdkVersion.build().isPresent()) {
// if we have no $PRE and no $BUILD, then the optional is delimited by "+-"
optionalLength = "+-".length() + jdkVersion.optional().get().length();
} else {
// else it is only delimited by "-"
optionalLength = "-".length() + jdkVersion.optional().get().length();
}
Runtime.Version strippedVersion = Runtime.Version.parse(jdkVersionStr.substring(0, jdkVersionStr.length() - optionalLength));
if (!strippedVersion.equalsIgnoreOptional(jdkVersion)) {
throw new RuntimeException(String.format("%s failed to strip the $OPTIONAL part from the Java Runtime Version string: %s vs %s", JVMCIVersionCheck.class.getSimpleName(), jdkVersion,
strippedVersion));
}
return strippedVersion;
}

boolean isGreaterThan(Version other) {
if (!isLessThan(other)) {
return !equals(other);
Expand Down

0 comments on commit b0821d5

Please sign in to comment.