author | dnsimon |
Tue, 04 Jul 2017 11:45:09 -0700 | |
changeset 45803 | 8ee2c9c86cfe |
parent 43972 | 1ade39b8381b |
child 45871 | 878e21603932 |
permissions | -rw-r--r-- |
43972 | 1 |
/* |
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
package org.graalvm.compiler.hotspot; |
|
24 |
||
25 |
import java.util.Formatter; |
|
45803
8ee2c9c86cfe
8183401: compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/NativeCallTest.java fails with The VM does not support the minimum JVMCI API version required by Graal
dnsimon
parents:
43972
diff
changeset
|
26 |
import java.util.Objects; |
43972 | 27 |
|
28 |
/** |
|
29 |
* Mechanism for checking that the current Java runtime environment supports the minimum JVMCI API |
|
30 |
* required by Graal. The {@code JVMCI_VERSION_CHECK} environment variable can be used to ignore a |
|
31 |
* failed check ({@code JVMCI_VERSION_CHECK=ignore}) or print a warning ( |
|
32 |
* {@code JVMCI_VERSION_CHECK=warn}) and continue. Otherwise, a failed check results in an |
|
33 |
* {@link InternalError} being raised or, if called from {@link #main(String[])}, the VM exiting |
|
34 |
* with a result code of {@code -1} |
|
35 |
* |
|
36 |
* This class only depends on the JDK so that it can be used without building Graal. |
|
37 |
*/ |
|
38 |
class JVMCIVersionCheck { |
|
39 |
||
40 |
private static final int JVMCI8_MIN_MAJOR_VERSION = 0; |
|
45803
8ee2c9c86cfe
8183401: compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/NativeCallTest.java fails with The VM does not support the minimum JVMCI API version required by Graal
dnsimon
parents:
43972
diff
changeset
|
41 |
private static final int JVMCI8_MIN_MINOR_VERSION = 26; |
43972 | 42 |
|
45803
8ee2c9c86cfe
8183401: compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/NativeCallTest.java fails with The VM does not support the minimum JVMCI API version required by Graal
dnsimon
parents:
43972
diff
changeset
|
43 |
// MAX_VALUE indicates that no current EA version is compatible with Graal. |
8ee2c9c86cfe
8183401: compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/NativeCallTest.java fails with The VM does not support the minimum JVMCI API version required by Graal
dnsimon
parents:
43972
diff
changeset
|
44 |
// Note: Keep README.md in sync with the EA version support checked here. |
8ee2c9c86cfe
8183401: compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/NativeCallTest.java fails with The VM does not support the minimum JVMCI API version required by Graal
dnsimon
parents:
43972
diff
changeset
|
45 |
private static final int JVMCI9_MIN_EA_BUILD = 176; |
43972 | 46 |
|
47 |
private static void failVersionCheck(boolean exit, String reason, Object... args) { |
|
48 |
Formatter errorMessage = new Formatter().format(reason, args); |
|
49 |
String javaHome = System.getProperty("java.home"); |
|
50 |
String vmName = System.getProperty("java.vm.name"); |
|
51 |
errorMessage.format("Set the JVMCI_VERSION_CHECK environment variable to \"ignore\" to suppress "); |
|
52 |
errorMessage.format("this error or to \"warn\" to emit a warning and continue execution.%n"); |
|
53 |
errorMessage.format("Currently used Java home directory is %s.%n", javaHome); |
|
54 |
errorMessage.format("Currently used VM configuration is: %s%n", vmName); |
|
55 |
if (System.getProperty("java.specification.version").compareTo("1.9") < 0) { |
|
56 |
errorMessage.format("Download the latest JVMCI JDK 8 from http://www.oracle.com/technetwork/oracle-labs/program-languages/downloads/index.html"); |
|
57 |
} else { |
|
58 |
errorMessage.format("Download the latest JDK 9 EA from https://jdk9.java.net/download/"); |
|
59 |
} |
|
60 |
String value = System.getenv("JVMCI_VERSION_CHECK"); |
|
61 |
if ("warn".equals(value)) { |
|
62 |
System.err.println(errorMessage.toString()); |
|
63 |
} else if ("ignore".equals(value)) { |
|
64 |
return; |
|
65 |
} else if (exit) { |
|
66 |
System.err.println(errorMessage.toString()); |
|
67 |
System.exit(-1); |
|
68 |
} else { |
|
69 |
throw new InternalError(errorMessage.toString()); |
|
70 |
} |
|
71 |
} |
|
72 |
||
73 |
static void check(boolean exitOnFailure) { |
|
74 |
// Don't use regular expressions to minimize Graal startup time |
|
75 |
String vmVersion = System.getProperty("java.vm.version"); |
|
76 |
if (System.getProperty("java.specification.version").compareTo("1.9") < 0) { |
|
77 |
int start = vmVersion.indexOf("-jvmci-"); |
|
78 |
if (start >= 0) { |
|
79 |
start += "-jvmci-".length(); |
|
80 |
int end = vmVersion.indexOf('.', start); |
|
81 |
if (end > 0) { |
|
45803
8ee2c9c86cfe
8183401: compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/NativeCallTest.java fails with The VM does not support the minimum JVMCI API version required by Graal
dnsimon
parents:
43972
diff
changeset
|
82 |
int major; |
8ee2c9c86cfe
8183401: compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/NativeCallTest.java fails with The VM does not support the minimum JVMCI API version required by Graal
dnsimon
parents:
43972
diff
changeset
|
83 |
try { |
8ee2c9c86cfe
8183401: compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/NativeCallTest.java fails with The VM does not support the minimum JVMCI API version required by Graal
dnsimon
parents:
43972
diff
changeset
|
84 |
major = Integer.parseInt(vmVersion.substring(start, end)); |
8ee2c9c86cfe
8183401: compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/NativeCallTest.java fails with The VM does not support the minimum JVMCI API version required by Graal
dnsimon
parents:
43972
diff
changeset
|
85 |
} catch (NumberFormatException e) { |
8ee2c9c86cfe
8183401: compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/NativeCallTest.java fails with The VM does not support the minimum JVMCI API version required by Graal
dnsimon
parents:
43972
diff
changeset
|
86 |
failVersionCheck(exitOnFailure, "The VM does not support the minimum JVMCI API version required by Graal.%n" + |
8ee2c9c86cfe
8183401: compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/NativeCallTest.java fails with The VM does not support the minimum JVMCI API version required by Graal
dnsimon
parents:
43972
diff
changeset
|
87 |
"Cannot read JVMCI major version from java.vm.version property: %s.%n", vmVersion); |
8ee2c9c86cfe
8183401: compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/NativeCallTest.java fails with The VM does not support the minimum JVMCI API version required by Graal
dnsimon
parents:
43972
diff
changeset
|
88 |
return; |
8ee2c9c86cfe
8183401: compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/NativeCallTest.java fails with The VM does not support the minimum JVMCI API version required by Graal
dnsimon
parents:
43972
diff
changeset
|
89 |
} |
43972 | 90 |
start = end + 1; |
91 |
end = start; |
|
92 |
while (end < vmVersion.length() && Character.isDigit(vmVersion.charAt(end))) { |
|
93 |
end++; |
|
94 |
} |
|
45803
8ee2c9c86cfe
8183401: compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/NativeCallTest.java fails with The VM does not support the minimum JVMCI API version required by Graal
dnsimon
parents:
43972
diff
changeset
|
95 |
int minor; |
8ee2c9c86cfe
8183401: compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/NativeCallTest.java fails with The VM does not support the minimum JVMCI API version required by Graal
dnsimon
parents:
43972
diff
changeset
|
96 |
try { |
8ee2c9c86cfe
8183401: compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/NativeCallTest.java fails with The VM does not support the minimum JVMCI API version required by Graal
dnsimon
parents:
43972
diff
changeset
|
97 |
minor = Integer.parseInt(vmVersion.substring(start, end)); |
8ee2c9c86cfe
8183401: compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/NativeCallTest.java fails with The VM does not support the minimum JVMCI API version required by Graal
dnsimon
parents:
43972
diff
changeset
|
98 |
} catch (NumberFormatException e) { |
8ee2c9c86cfe
8183401: compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/NativeCallTest.java fails with The VM does not support the minimum JVMCI API version required by Graal
dnsimon
parents:
43972
diff
changeset
|
99 |
failVersionCheck(exitOnFailure, "The VM does not support the minimum JVMCI API version required by Graal.%n" + |
8ee2c9c86cfe
8183401: compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/NativeCallTest.java fails with The VM does not support the minimum JVMCI API version required by Graal
dnsimon
parents:
43972
diff
changeset
|
100 |
"Cannot read JVMCI minor version from java.vm.version property: %s.%n", vmVersion); |
8ee2c9c86cfe
8183401: compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/NativeCallTest.java fails with The VM does not support the minimum JVMCI API version required by Graal
dnsimon
parents:
43972
diff
changeset
|
101 |
return; |
8ee2c9c86cfe
8183401: compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/NativeCallTest.java fails with The VM does not support the minimum JVMCI API version required by Graal
dnsimon
parents:
43972
diff
changeset
|
102 |
} |
43972 | 103 |
if (major >= JVMCI8_MIN_MAJOR_VERSION && minor >= JVMCI8_MIN_MINOR_VERSION) { |
104 |
return; |
|
105 |
} |
|
106 |
failVersionCheck(exitOnFailure, "The VM does not support the minimum JVMCI API version required by Graal: %d.%d < %d.%d.%n", |
|
107 |
major, minor, JVMCI8_MIN_MAJOR_VERSION, JVMCI8_MIN_MINOR_VERSION); |
|
108 |
return; |
|
109 |
} |
|
110 |
} |
|
111 |
failVersionCheck(exitOnFailure, "The VM does not support the minimum JVMCI API version required by Graal.%n" + |
|
112 |
"Cannot read JVMCI version from java.vm.version property: %s.%n", vmVersion); |
|
113 |
} else { |
|
114 |
if (vmVersion.contains("SNAPSHOT")) { |
|
45803
8ee2c9c86cfe
8183401: compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/NativeCallTest.java fails with The VM does not support the minimum JVMCI API version required by Graal
dnsimon
parents:
43972
diff
changeset
|
115 |
// The snapshot of http://hg.openjdk.java.net/jdk9/dev tip is expected to work |
43972 | 116 |
return; |
117 |
} |
|
118 |
if (vmVersion.contains("internal")) { |
|
119 |
// Allow local builds |
|
120 |
return; |
|
121 |
} |
|
122 |
// http://openjdk.java.net/jeps/223 |
|
45803
8ee2c9c86cfe
8183401: compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/NativeCallTest.java fails with The VM does not support the minimum JVMCI API version required by Graal
dnsimon
parents:
43972
diff
changeset
|
123 |
if (vmVersion.startsWith("9+")) { |
8ee2c9c86cfe
8183401: compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/NativeCallTest.java fails with The VM does not support the minimum JVMCI API version required by Graal
dnsimon
parents:
43972
diff
changeset
|
124 |
int start = "9+".length(); |
43972 | 125 |
int end = start; |
126 |
end = start; |
|
127 |
while (end < vmVersion.length() && Character.isDigit(vmVersion.charAt(end))) { |
|
128 |
end++; |
|
129 |
} |
|
45803
8ee2c9c86cfe
8183401: compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/NativeCallTest.java fails with The VM does not support the minimum JVMCI API version required by Graal
dnsimon
parents:
43972
diff
changeset
|
130 |
int build; |
8ee2c9c86cfe
8183401: compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/NativeCallTest.java fails with The VM does not support the minimum JVMCI API version required by Graal
dnsimon
parents:
43972
diff
changeset
|
131 |
try { |
8ee2c9c86cfe
8183401: compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/NativeCallTest.java fails with The VM does not support the minimum JVMCI API version required by Graal
dnsimon
parents:
43972
diff
changeset
|
132 |
build = Integer.parseInt(vmVersion.substring(start, end)); |
8ee2c9c86cfe
8183401: compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/NativeCallTest.java fails with The VM does not support the minimum JVMCI API version required by Graal
dnsimon
parents:
43972
diff
changeset
|
133 |
} catch (NumberFormatException e) { |
8ee2c9c86cfe
8183401: compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/NativeCallTest.java fails with The VM does not support the minimum JVMCI API version required by Graal
dnsimon
parents:
43972
diff
changeset
|
134 |
failVersionCheck(exitOnFailure, "The VM does not support the minimum JVMCI API version required by Graal.%n" + |
8ee2c9c86cfe
8183401: compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/NativeCallTest.java fails with The VM does not support the minimum JVMCI API version required by Graal
dnsimon
parents:
43972
diff
changeset
|
135 |
"Cannot read JDK9 EA build number from java.vm.version property: %s.%n", vmVersion); |
8ee2c9c86cfe
8183401: compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/NativeCallTest.java fails with The VM does not support the minimum JVMCI API version required by Graal
dnsimon
parents:
43972
diff
changeset
|
136 |
return; |
8ee2c9c86cfe
8183401: compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/NativeCallTest.java fails with The VM does not support the minimum JVMCI API version required by Graal
dnsimon
parents:
43972
diff
changeset
|
137 |
} |
43972 | 138 |
if (build >= JVMCI9_MIN_EA_BUILD) { |
139 |
return; |
|
140 |
} |
|
45803
8ee2c9c86cfe
8183401: compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/NativeCallTest.java fails with The VM does not support the minimum JVMCI API version required by Graal
dnsimon
parents:
43972
diff
changeset
|
141 |
// Using Object.equals suppresses Eclipse's "Dead code" warning. |
8ee2c9c86cfe
8183401: compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/NativeCallTest.java fails with The VM does not support the minimum JVMCI API version required by Graal
dnsimon
parents:
43972
diff
changeset
|
142 |
// Unfortunately @SuppressWarnings("unused") can only be applied at method level. |
8ee2c9c86cfe
8183401: compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/NativeCallTest.java fails with The VM does not support the minimum JVMCI API version required by Graal
dnsimon
parents:
43972
diff
changeset
|
143 |
if (Objects.equals(JVMCI9_MIN_EA_BUILD, Integer.MAX_VALUE)) { |
8ee2c9c86cfe
8183401: compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/NativeCallTest.java fails with The VM does not support the minimum JVMCI API version required by Graal
dnsimon
parents:
43972
diff
changeset
|
144 |
failVersionCheck(exitOnFailure, "This version of Graal is not compatible with any JDK 9 Early Access build.%n"); |
8ee2c9c86cfe
8183401: compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/NativeCallTest.java fails with The VM does not support the minimum JVMCI API version required by Graal
dnsimon
parents:
43972
diff
changeset
|
145 |
} else { |
8ee2c9c86cfe
8183401: compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/NativeCallTest.java fails with The VM does not support the minimum JVMCI API version required by Graal
dnsimon
parents:
43972
diff
changeset
|
146 |
failVersionCheck(exitOnFailure, "The VM is an insufficiently recent EA JDK9 build for Graal: %d < %d.%n", build, JVMCI9_MIN_EA_BUILD); |
8ee2c9c86cfe
8183401: compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/NativeCallTest.java fails with The VM does not support the minimum JVMCI API version required by Graal
dnsimon
parents:
43972
diff
changeset
|
147 |
} |
43972 | 148 |
return; |
45803
8ee2c9c86cfe
8183401: compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/NativeCallTest.java fails with The VM does not support the minimum JVMCI API version required by Graal
dnsimon
parents:
43972
diff
changeset
|
149 |
} else { |
8ee2c9c86cfe
8183401: compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/NativeCallTest.java fails with The VM does not support the minimum JVMCI API version required by Graal
dnsimon
parents:
43972
diff
changeset
|
150 |
// Graal will be compatible with all JDK versions as of 9 GA |
8ee2c9c86cfe
8183401: compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/NativeCallTest.java fails with The VM does not support the minimum JVMCI API version required by Graal
dnsimon
parents:
43972
diff
changeset
|
151 |
// until a JVMCI API change is made in a 9u or later release. |
43972 | 152 |
} |
153 |
} |
|
154 |
} |
|
155 |
||
156 |
/** |
|
157 |
* Command line interface for performing the check. |
|
158 |
*/ |
|
159 |
public static void main(String[] args) { |
|
160 |
check(true); |
|
161 |
} |
|
162 |
} |