Skip to content

Commit 1543c02

Browse files
committed
compiler: use well-named factory methods for creating JVMCIVersionCheck.Version objects
1 parent 61c489a commit 1543c02

File tree

4 files changed

+36
-24
lines changed

4 files changed

+36
-24
lines changed

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/hotspot/test/JVMCIVersionCheckMaxValueTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void testNewVersion() {
5454

5555
private static void testVersion(String javaVmVersion) {
5656
try {
57-
JVMCIVersionCheck.Version minVersion = new JVMCIVersionCheck.Version(20, 0, 1);
57+
JVMCIVersionCheck.Version minVersion = JVMCIVersionCheck.createLegacyVersion(20, 0, 1);
5858
// Use a javaSpecVersion that will likely not fail in the near future
5959
String javaSpecVersion = "99";
6060
var props = JVMCIVersionCheckTest.createTestProperties(javaSpecVersion, javaVmVersion, null);

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/hotspot/test/JVMCIVersionCheckTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ public static Collection<Object[]> data() {
110110
private static Version getVersion(String jdkVersion, int major, int minor, int build) {
111111
if (jdkVersion != null) {
112112
// new version scheme
113-
return new Version(jdkVersion, build);
113+
return JVMCIVersionCheck.createLabsJDKVersion(jdkVersion, build);
114114
} else {
115115
// legacy version scheme
116-
return new Version(major, minor, build);
116+
return JVMCIVersionCheck.createLegacyVersion(major, minor, build);
117117
}
118118
}
119119

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/hotspot/test/JVMCIVersionCheckVendorTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
public class JVMCIVersionCheckVendorTest extends GraalCompilerTest {
4242

4343
private static final Map<String, Map<String, JVMCIVersionCheck.Version>> VERSION_MAP = Map.of("99", Map.of(
44-
DEFAULT_VENDOR_ENTRY, new JVMCIVersionCheck.Version("99+99", 1),
45-
"Vendor Specific", new JVMCIVersionCheck.Version("99.0.1", 1)));
44+
DEFAULT_VENDOR_ENTRY, JVMCIVersionCheck.createLabsJDKVersion("99+99", 1),
45+
"Vendor Specific", JVMCIVersionCheck.createLabsJDKVersion("99.0.1", 1)));
4646

4747
private static void expect(String javaVmVendor, String expected) {
4848
var props = JVMCIVersionCheckTest.createTestProperties("99", null, javaVmVendor);

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/JVMCIVersionCheck.java

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,31 @@ public final class JVMCIVersionCheck {
6363
*/
6464
private static final int JAVA_MIN_RELEASE = 21;
6565

66+
/**
67+
* Convenience factory for the current version scheme that only uses the JDK version and the
68+
* JVMCI build number.
69+
*/
70+
public static Version createLabsJDKVersion(String jdkVersionString, int jvmciBuild) {
71+
return new Version(jdkVersionString, jvmciBuild);
72+
}
73+
74+
/**
75+
* Convenience factory for the current version scheme that only uses the JDK version
76+
* <em>without</em> a JVMCI build number. This is used when running on a plain OpenJDK, not a
77+
* custom LabsJDK build.
78+
*/
79+
public static Version createOpenJDKVersion(String jdkVersionString) {
80+
return new Version(jdkVersionString);
81+
}
82+
83+
/**
84+
* Legacy factory for versions without JDK version. This force sets {@link Version#jdkVersion}
85+
* to {@code 21}. While this is not entirely correct, it works for our purposes.
86+
*/
87+
public static Version createLegacyVersion(int jvmciMajor, int jvmciMinor, int jvmciBuild) {
88+
return new Version(jvmciMajor, jvmciMinor, jvmciBuild);
89+
}
90+
6691
public static class Version {
6792
private final Runtime.Version jdkVersion;
6893
private final int jvmciMajor;
@@ -79,12 +104,12 @@ static Version parse(String vmVersion) {
79104
assert m.group(4) == null : "if jvmciMajor is null jvmciMinor must also be null";
80105
String jdkVersion = m.group(1);
81106
int jvmciBuild = Integer.parseInt(m.group(5));
82-
return new Version(jdkVersion, jvmciBuild);
107+
return createLabsJDKVersion(jdkVersion, jvmciBuild);
83108
} else {
84109
int jvmciMajor = Integer.parseInt(m.group(3));
85110
int jvmciMinor = Integer.parseInt(m.group(4));
86111
int jvmciBuild = Integer.parseInt(m.group(5));
87-
return new Version(jvmciMajor, jvmciMinor, jvmciBuild);
112+
return createLegacyVersion(jvmciMajor, jvmciMinor, jvmciBuild);
88113
}
89114

90115
} catch (NumberFormatException e) {
@@ -93,7 +118,7 @@ static Version parse(String vmVersion) {
93118
} else {
94119
try {
95120
// assume OpenJDK version
96-
return new Version(stripVersion(vmVersion));
121+
return createOpenJDKVersion(stripVersion(vmVersion));
97122
} catch (IllegalArgumentException e) {
98123
// ignore
99124
}
@@ -114,28 +139,15 @@ private static String stripVersion(String versionString) {
114139
return sb.toString();
115140
}
116141

117-
/**
118-
* Convenience constructor for the current version scheme that only uses the JDK version and
119-
* the JVMCI build number.
120-
*/
121-
public Version(String jdkVersionString, int jvmciBuild) {
142+
private Version(String jdkVersionString, int jvmciBuild) {
122143
this(jdkVersionString, NA, NA, jvmciBuild, false, false);
123144
}
124145

125-
/**
126-
* Convenience constructor for the current version scheme that only uses the JDK version
127-
* <em>without</em> a JVMCI build number. This is used when running on a plain OpenJDK, not
128-
* a custom LabsJDK build.
129-
*/
130-
public Version(String jdkVersionString) {
146+
private Version(String jdkVersionString) {
131147
this(jdkVersionString, NA, NA, NA, false, true);
132148
}
133149

134-
/**
135-
* Legacy construction for versions without JDK version. This force sets {@link #jdkVersion}
136-
* to {@code 21}. While this is not entirely correct, it works for our purposes.
137-
*/
138-
public Version(int jvmciMajor, int jvmciMinor, int jvmciBuild) {
150+
private Version(int jvmciMajor, int jvmciMinor, int jvmciBuild) {
139151
this("21", jvmciMajor, jvmciMinor, jvmciBuild, true, false);
140152
}
141153

0 commit comments

Comments
 (0)