Skip to content

Commit b3c9d67

Browse files
author
Doug Simon
committed
8309136: [JVMCI] add -XX:+UseGraalJIT flag
Reviewed-by: dholmes, kvn
1 parent 98b53c0 commit b3c9d67

File tree

5 files changed

+66
-23
lines changed

5 files changed

+66
-23
lines changed

src/hotspot/share/compiler/compilerDefinitions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ bool CompilerConfig::check_args_consistency(bool status) {
545545
FLAG_SET_DEFAULT(SegmentedCodeCache, false);
546546
}
547547
#if INCLUDE_JVMCI
548-
if (EnableJVMCI) {
548+
if (EnableJVMCI || UseJVMCICompiler) {
549549
if (!FLAG_IS_DEFAULT(EnableJVMCI) || !FLAG_IS_DEFAULT(UseJVMCICompiler)) {
550550
warning("JVMCI Compiler disabled due to -Xint.");
551551
}

src/hotspot/share/jvmci/jvmci_globals.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ bool JVMCIGlobals::check_jvmci_flags_are_consistent() {
7171
JVMCI_FLAG_CHECKED(UseJVMCICompiler)
7272
JVMCI_FLAG_CHECKED(EnableJVMCI)
7373
JVMCI_FLAG_CHECKED(EnableJVMCIProduct)
74+
JVMCI_FLAG_CHECKED(UseGraalJIT)
7475

7576
CHECK_NOT_SET(BootstrapJVMCI, UseJVMCICompiler)
7677
CHECK_NOT_SET(PrintBootstrap, UseJVMCICompiler)
@@ -164,7 +165,7 @@ bool JVMCIGlobals::check_jvmci_flags_are_consistent() {
164165
}
165166

166167
// Convert JVMCI flags from experimental to product
167-
bool JVMCIGlobals::enable_jvmci_product_mode(JVMFlagOrigin origin) {
168+
bool JVMCIGlobals::enable_jvmci_product_mode(JVMFlagOrigin origin, bool use_graal_jit) {
168169
const char *JVMCIFlags[] = {
169170
"EnableJVMCI",
170171
"EnableJVMCIProduct",
@@ -201,6 +202,12 @@ bool JVMCIGlobals::enable_jvmci_product_mode(JVMFlagOrigin origin) {
201202
if (JVMFlagAccess::set_bool(jvmciEnableFlag, &value, origin) != JVMFlag::SUCCESS) {
202203
return false;
203204
}
205+
if (use_graal_jit) {
206+
JVMFlag *useGraalJITFlag = JVMFlag::find_flag("UseGraalJIT");
207+
if (JVMFlagAccess::set_bool(useGraalJITFlag, &value, origin) != JVMFlag::SUCCESS) {
208+
return false;
209+
}
210+
}
204211

205212
// Effect of EnableJVMCIProduct on changing defaults of EnableJVMCI
206213
// and UseJVMCICompiler is deferred to check_jvmci_flags_are_consistent

src/hotspot/share/jvmci/jvmci_globals.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ class fileStream;
4848
product(bool, EnableJVMCI, false, EXPERIMENTAL, \
4949
"Enable JVMCI") \
5050
\
51+
product(bool, UseGraalJIT, false, EXPERIMENTAL, \
52+
"Select the Graal JVMCI compiler. This is an alias for: " \
53+
" -XX:+EnableJVMCIProduct " \
54+
" -Djvmci.Compiler=graal ") \
55+
\
5156
product(bool, EnableJVMCIProduct, false, EXPERIMENTAL, \
5257
"Allow JVMCI to be used in product mode. This alters a subset of "\
5358
"JVMCI flags to be non-experimental, defaults UseJVMCICompiler " \
@@ -185,7 +190,7 @@ class JVMCIGlobals {
185190
static bool check_jvmci_flags_are_consistent();
186191

187192
// Convert JVMCI experimental flags to product
188-
static bool enable_jvmci_product_mode(JVMFlagOrigin);
193+
static bool enable_jvmci_product_mode(JVMFlagOrigin origin, bool use_graal_jit);
189194

190195
// Returns true iff the GC fully supports JVMCI.
191196
static bool gc_supports_jvmci();

src/hotspot/share/runtime/arguments.cpp

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2827,28 +2827,42 @@ jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args, bool* patch_m
28272827
return JNI_ERR;
28282828
#endif // INCLUDE_MANAGEMENT
28292829
#if INCLUDE_JVMCI
2830-
} else if (match_option(option, "-XX:-EnableJVMCIProduct")) {
2830+
} else if (match_option(option, "-XX:-EnableJVMCIProduct") || match_option(option, "-XX:-UseGraalJIT")) {
28312831
if (EnableJVMCIProduct) {
28322832
jio_fprintf(defaultStream::error_stream(),
2833-
"-XX:-EnableJVMCIProduct cannot come after -XX:+EnableJVMCIProduct\n");
2833+
"-XX:-EnableJVMCIProduct or -XX:-UseGraalJIT cannot come after -XX:+EnableJVMCIProduct or -XX:+UseGraalJIT\n");
28342834
return JNI_EINVAL;
28352835
}
2836-
} else if (match_option(option, "-XX:+EnableJVMCIProduct")) {
2837-
// Just continue, since "-XX:+EnableJVMCIProduct" has been specified before
2836+
} else if (match_option(option, "-XX:+EnableJVMCIProduct") || match_option(option, "-XX:+UseGraalJIT")) {
2837+
bool use_graal_jit = match_option(option, "-XX:+UseGraalJIT");
2838+
if (use_graal_jit) {
2839+
const char* jvmci_compiler = get_property("jvmci.Compiler");
2840+
if (jvmci_compiler != nullptr) {
2841+
if (strncmp(jvmci_compiler, "graal", strlen("graal")) != 0) {
2842+
jio_fprintf(defaultStream::error_stream(),
2843+
"Value of jvmci.Compiler incompatible with +UseGraalJIT: %s", jvmci_compiler);
2844+
return JNI_ERR;
2845+
}
2846+
} else if (!add_property("jvmci.Compiler=graal")) {
2847+
return JNI_ENOMEM;
2848+
}
2849+
}
2850+
2851+
// Just continue, since "-XX:+EnableJVMCIProduct" or "-XX:+UseGraalJIT" has been specified before
28382852
if (EnableJVMCIProduct) {
28392853
continue;
28402854
}
28412855
JVMFlag *jvmciFlag = JVMFlag::find_flag("EnableJVMCIProduct");
28422856
// Allow this flag if it has been unlocked.
28432857
if (jvmciFlag != nullptr && jvmciFlag->is_unlocked()) {
2844-
if (!JVMCIGlobals::enable_jvmci_product_mode(origin)) {
2858+
if (!JVMCIGlobals::enable_jvmci_product_mode(origin, use_graal_jit)) {
28452859
jio_fprintf(defaultStream::error_stream(),
28462860
"Unable to enable JVMCI in product mode");
28472861
return JNI_ERR;
28482862
}
28492863
}
28502864
// The flag was locked so process normally to report that error
2851-
else if (!process_argument("EnableJVMCIProduct", args->ignoreUnrecognized, origin)) {
2865+
else if (!process_argument(use_graal_jit ? "UseGraalJIT" : "EnableJVMCIProduct", args->ignoreUnrecognized, origin)) {
28522866
return JNI_EINVAL;
28532867
}
28542868
#endif // INCLUDE_JVMCI

test/hotspot/jtreg/compiler/jvmci/TestEnableJVMCIProduct.java

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -50,6 +50,14 @@ static class Expectation {
5050
}
5151

5252
public static void main(String[] args) throws Exception {
53+
if (args.length != 0) {
54+
// Called as subprocess. Print system properties named by
55+
// `args` and then exit.
56+
for (String arg : args) {
57+
System.out.printf("%s=%s%n", arg, System.getProperty(arg));
58+
}
59+
return;
60+
}
5361
// Test EnableJVMCIProduct without any other explicit JVMCI option
5462
test("-XX:-PrintWarnings",
5563
new Expectation("EnableJVMCI", "true", "default"),
@@ -67,24 +75,33 @@ public static void main(String[] args) throws Exception {
6775
new Expectation("EnableJVMCI", "false", "command line"),
6876
new Expectation("UseJVMCICompiler", "false", "default"));
6977
test("-XX:+EnableJVMCIProduct",
70-
new Expectation("EnableJVMCIProduct", "true", "command line"),
78+
new Expectation("EnableJVMCIProduct", "true", "(?:command line|jimage)"),
7179
new Expectation("EnableJVMCI", "true", "default"),
7280
new Expectation("UseJVMCICompiler", "true", "default"));
7381
}
7482

7583
static void test(String explicitFlag, Expectation... expectations) throws Exception {
76-
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
77-
"-XX:+UnlockExperimentalVMOptions", "-XX:+EnableJVMCIProduct", "-XX:-UnlockExperimentalVMOptions",
78-
explicitFlag,
79-
"-XX:+PrintFlagsFinal", "-version");
80-
OutputAnalyzer output = new OutputAnalyzer(pb.start());
81-
for (Expectation expectation : expectations) {
82-
output.stdoutShouldMatch(expectation.pattern);
83-
}
84-
if (output.getExitValue() != 0) {
85-
// This should only happen when JVMCI compilation is requested and the VM has no
86-
// JVMCI compiler (e.g. Graal is not included in the build)
87-
output.stdoutShouldMatch("No JVMCI compiler found");
84+
String[] flags = {"-XX:+EnableJVMCIProduct", "-XX:+UseGraalJIT"};
85+
String cwd = System.getProperty("user.dir");
86+
for (String flag : flags) {
87+
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
88+
"-XX:+UnlockExperimentalVMOptions", flag, "-XX:-UnlockExperimentalVMOptions",
89+
explicitFlag,
90+
"-XX:+PrintFlagsFinal",
91+
"--class-path=" + System.getProperty("java.class.path"),
92+
"TestEnableJVMCIProduct", "jvmci.Compiler");
93+
OutputAnalyzer output = new OutputAnalyzer(pb.start());
94+
for (Expectation expectation : expectations) {
95+
output.stdoutShouldMatch(expectation.pattern);
96+
}
97+
if (flag.equals("-XX:+UseGraalJIT")) {
98+
output.shouldContain("jvmci.Compiler=graal");
99+
}
100+
if (output.getExitValue() != 0) {
101+
// This should only happen when JVMCI compilation is requested and the VM has no
102+
// JVMCI compiler (e.g. Graal is not included in the build)
103+
output.stdoutShouldMatch("No JVMCI compiler found");
104+
}
88105
}
89106
}
90107
}

0 commit comments

Comments
 (0)