1
1
/*
2
- * Copyright (c) 2015, 2023 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2015, 2025 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* The Universal Permissive License (UPL), Version 1.0
@@ -136,25 +136,30 @@ protected static TruffleRuntime createRuntime() {
136
136
if (truffleVersion .compareTo (NEXT_VERSION_UPDATE ) >= 0 ) {
137
137
throw new AssertionError ("MIN_COMPILER_VERSION, MIN_JDK_VERSION and MAX_JDK_VERSION must be updated!" );
138
138
}
139
+ Version truffleMajorMinorVersion = stripUpdateVersion (truffleVersion );
139
140
Version compilerVersion = getCompilerVersion (compilationSupport );
141
+ Version compilerMajorMinorVersion = stripUpdateVersion (compilerVersion );
140
142
int jdkFeatureVersion = Runtime .version ().feature ();
141
143
if (jdkFeatureVersion < MIN_JDK_VERSION || jdkFeatureVersion >= MAX_JDK_VERSION ) {
142
- throw throwVersionError ("""
144
+ return new DefaultTruffleRuntime ( formatVersionWarningMessage ("""
143
145
Your Java runtime '%s' with compiler version '%s' is incompatible with polyglot version '%s'.
144
146
The Java runtime version must be greater or equal to JDK '%d' and smaller than JDK '%d'.
145
147
Update your Java runtime to resolve this.
146
- """ , Runtime .version (), compilerVersion , truffleVersion , MIN_JDK_VERSION , MAX_JDK_VERSION );
147
- } else if (compilerVersion .compareTo (truffleVersion ) > 0 ) {
148
- // no forward compatibility
149
- throw throwVersionError ("""
148
+ """ , Runtime .version (), compilerVersion , truffleVersion , MIN_JDK_VERSION , MAX_JDK_VERSION ));
149
+ } else if (compilerMajorMinorVersion .compareTo (truffleMajorMinorVersion ) > 0 ) {
150
+ /*
151
+ * Forward compatibility is supported only for minor updates, not for major
152
+ * releases.
153
+ */
154
+ return new DefaultTruffleRuntime (formatVersionWarningMessage ("""
150
155
Your Java runtime '%s' with compiler version '%s' is incompatible with polyglot version '%s'.
151
156
Update the org.graalvm.polyglot versions to at least '%s' to resolve this.
152
- """ , Runtime .version (), compilerVersion , truffleVersion , compilerVersion );
157
+ """ , Runtime .version (), compilerVersion , truffleVersion , compilerVersion )) ;
153
158
} else if (compilerVersion .compareTo (MIN_COMPILER_VERSION ) < 0 ) {
154
- throw throwVersionError ("""
159
+ return new DefaultTruffleRuntime ( formatVersionWarningMessage ("""
155
160
Your Java runtime '%s' with compiler version '%s' is incompatible with polyglot version '%s'.
156
161
Update the Java runtime to the latest update release of JDK '%d'.
157
- """ , Runtime .version (), compilerVersion , truffleVersion , jdkFeatureVersion );
162
+ """ , Runtime .version (), compilerVersion , truffleVersion , jdkFeatureVersion )) ;
158
163
}
159
164
}
160
165
} else {
@@ -171,12 +176,14 @@ protected static TruffleRuntime createRuntime() {
171
176
compilationSupport = (TruffleCompilationSupport ) hotspotCompilationSupport .getConstructor ().newInstance ();
172
177
if (!Boolean .getBoolean ("polyglotimpl.DisableVersionChecks" )) {
173
178
Version truffleVersion = getTruffleVersion ();
179
+ Version truffleMajorMinorVersion = stripUpdateVersion (truffleVersion );
174
180
Version compilerVersion = getCompilerVersion (compilationSupport );
175
- if (!compilerVersion .equals (truffleVersion )) {
176
- throw throwVersionError ("""
181
+ Version compilerMajorMinorVersion = stripUpdateVersion (compilerVersion );
182
+ if (!compilerMajorMinorVersion .equals (truffleMajorMinorVersion )) {
183
+ return new DefaultTruffleRuntime (formatVersionWarningMessage ("""
177
184
The Graal compiler version '%s' is incompatible with polyglot version '%s'.
178
185
Update the compiler version to '%s' to resolve this.
179
- """ , compilerVersion , truffleVersion , truffleVersion );
186
+ """ , compilerVersion , truffleVersion , truffleVersion )) ;
180
187
}
181
188
}
182
189
} catch (ReflectiveOperationException e ) {
@@ -188,18 +195,27 @@ protected static TruffleRuntime createRuntime() {
188
195
return rt ;
189
196
}
190
197
191
- private static RuntimeException throwVersionError (String errorFormat , Object ... args ) {
192
- StringBuilder errorMessage = new StringBuilder ("Polyglot version compatibility check failed.\n " );
198
+ private static Version stripUpdateVersion (Version version ) {
199
+ int major = version .getComponent (0 );
200
+ int minor = version .getComponent (1 );
201
+ if (major == 0 && minor == 0 ) {
202
+ /*
203
+ * Version represents a pure snapshot version without any numeric component.
204
+ */
205
+ return version ;
206
+ } else {
207
+ return Version .create (major , minor );
208
+ }
209
+ }
210
+
211
+ private static String formatVersionWarningMessage (String errorFormat , Object ... args ) {
212
+ StringBuilder errorMessage = new StringBuilder ("Version check failed.\n " );
193
213
errorMessage .append (String .format (errorFormat , args ));
194
214
errorMessage .append ("""
195
- Alternatively, it is possible to switch to the fallback runtime with -Dtruffle.UseFallbackRuntime=true.
196
- The fallback runtime is compatible to any Java 17 capable JDK.
197
- Execution with the fallback runtime does not support runtime compilation and therefore will negatively impact the guest application performance.
198
- For more information see: https://www.graalvm.org/latest/reference-manual/embed-languages/#runtime-optimization-support.
199
215
To disable this version check the '-Dpolyglotimpl.DisableVersionChecks=true' system property can be used.
200
216
It is not recommended to disable version checks.
201
217
""" );
202
- throw new IllegalStateException ( errorMessage .toString () );
218
+ return errorMessage .toString ();
203
219
}
204
220
205
221
/**
0 commit comments