Skip to content

Commit a6157ee

Browse files
committed
[GR-55686] GuestGraal: Add EE support.
PullRequest: graal/18368
2 parents 3d2b94b + c1eecdd commit a6157ee

File tree

49 files changed

+473
-448
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+473
-448
lines changed

compiler/mx.compiler/mx_compiler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ def compiler_gate_benchmark_runner(tasks, extraVMarguments=None, prefix='', task
605605
# ensure we can run with --enable-preview
606606
with Task(prefix + 'DaCapo_enable-preview:fop', tasks, tags=GraalTags.test, report=task_report_component) as t:
607607
if t:
608-
_gate_dacapo('fop', 8, ['--enable-preview', '-Djdk.graal.CompilationFailureAction=ExitVM'])
608+
_gate_dacapo('fop', 8, benchVmArgs + ['--enable-preview', '-Djdk.graal.CompilationFailureAction=ExitVM'])
609609

610610
# run Scala DaCapo benchmarks #
611611
###############################

compiler/mx.compiler/suite.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,14 @@
190190
],
191191
},
192192
"uses" : [
193+
"jdk.graal.compiler.hotspot.meta.DefaultHotSpotLoweringProvider.Extensions",
193194
"jdk.graal.compiler.hotspot.meta.HotSpotInvocationPluginProvider",
194195
"jdk.graal.compiler.lir.LIRInstructionVerifier",
195196
"jdk.graal.compiler.core.common.CompilerProfiler",
196197
"jdk.graal.compiler.truffle.substitutions.GraphBuilderInvocationPluginProvider",
197198
"jdk.graal.compiler.truffle.phases.inlining.InliningPolicyProvider",
199+
"jdk.graal.compiler.truffle.host.TruffleHostEnvironment.Lookup",
200+
"jdk.graal.compiler.truffle.substitutions.GraphDecoderInvocationPluginProvider"
198201
],
199202
"annotationProcessors" : [
200203
"GRAAL_PROCESSOR"
@@ -557,7 +560,6 @@
557560
"jdk.graal.compiler.debug.DebugHandlersFactory",
558561
"jdk.graal.compiler.debug.TTYStreamProvider",
559562
"jdk.graal.compiler.debug.PathUtilitiesProvider",
560-
"jdk.graal.compiler.hotspot.HotSpotCodeCacheListener",
561563
"jdk.graal.compiler.hotspot.HotSpotBackendFactory",
562564
"jdk.graal.compiler.hotspot.meta.HotSpotInvocationPluginProvider",
563565
"jdk.graal.compiler.nodes.graphbuilderconf.GeneratedPluginFactory",

compiler/src/jdk.graal.compiler.processor/src/jdk/graal/compiler/replacements/processor/PluginGenerator.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,20 @@ private static void disambiguateNames(List<GeneratedPlugin> plugins) {
110110
disambiguateWith(plugins, plugin -> plugin.getPluginName() + "__" + nextId[0]++);
111111
}
112112

113+
/**
114+
* Map from an architecture's name as it appears in a package name to its name returned by
115+
* {@code jdk.vm.ci.code.Architecture.getName()}.
116+
*/
117+
private static final Map<String, String> SUPPORTED_JVMCI_ARCHITECTURES = Map.of(
118+
"amd64", "AMD64",
119+
"aarch64", "aarch64",
120+
"riscv64", "riscv64");
121+
113122
private static void createPluginFactory(AbstractProcessor processor, Element topLevelClass, List<GeneratedPlugin> plugins) {
114123
PackageElement pkg = (PackageElement) topLevelClass.getEnclosingElement();
115124

116125
String genClassName = "PluginFactory_" + topLevelClass.getSimpleName();
126+
String arch = SUPPORTED_JVMCI_ARCHITECTURES.get(pkg.getSimpleName().toString());
117127

118128
String qualifiedGenClassName = pkg.getQualifiedName() + "." + genClassName;
119129
try {
@@ -131,7 +141,15 @@ private static void createPluginFactory(AbstractProcessor processor, Element top
131141
plugin.generate(processor, out);
132142
out.printf("\n");
133143
}
134-
out.printf("public class %s implements GeneratedPluginFactory {\n", genClassName);
144+
if (arch != null) {
145+
out.printf("public class %s implements GeneratedPluginFactory, jdk.graal.compiler.core.ArchitectureSpecific {\n", genClassName);
146+
out.printf(" @Override\n");
147+
out.printf(" public String getArchitecture() {\n");
148+
out.printf(" return \"%s\";\n", arch);
149+
out.printf(" }\n");
150+
} else {
151+
out.printf("public class %s implements GeneratedPluginFactory {\n", genClassName);
152+
}
135153
createPluginFactoryMethod(out, plugins);
136154
out.printf("}\n");
137155
}

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/core/test/VerifyFoldableMethods.java

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@
2525
package jdk.graal.compiler.core.test;
2626

2727
import java.util.Map;
28+
import java.util.Set;
2829
import java.util.concurrent.ConcurrentHashMap;
2930
import java.util.stream.Collectors;
3031

3132
import jdk.graal.compiler.api.replacements.Fold;
33+
import jdk.graal.compiler.nodes.PluginReplacementNode;
3234
import jdk.graal.compiler.nodes.StructuredGraph;
3335
import jdk.graal.compiler.nodes.graphbuilderconf.GeneratedInvocationPlugin;
3436
import jdk.graal.compiler.nodes.java.MethodCallTargetNode;
@@ -39,7 +41,9 @@
3941
import jdk.vm.ci.meta.ResolvedJavaType;
4042

4143
/**
42-
* Verifies that all {@link Fold} annotated methods have at least one caller.
44+
* Verifies that all {@link Fold} annotated methods have at least one caller from non-generated
45+
* code. Ideally, the class should verify that foldable methods are only called from snippets but
46+
* that requires a more global analysis (i.e., to know whether a caller is used within a snippet).
4347
*/
4448
public class VerifyFoldableMethods extends VerifyPhase<CoreProviders> {
4549

@@ -48,32 +52,59 @@ public boolean checkContract() {
4852
return false;
4953
}
5054

51-
private final Map<ResolvedJavaMethod, Boolean> foldables = new ConcurrentHashMap<>();
52-
ResolvedJavaType generatedInvocationPluginType;
55+
/**
56+
* Map from a foldable method to one of its callers. The absence of a caller is represented a
57+
* foldable method mapping to itself.
58+
*/
59+
private final Map<ResolvedJavaMethod, ResolvedJavaMethod> foldableCallers = new ConcurrentHashMap<>();
60+
61+
/*
62+
* Super types or interfaces for generated classes. Calls from methods in these classes are
63+
* ignored.
64+
*/
65+
Set<ResolvedJavaType> generatedClassSupertypes;
66+
67+
/**
68+
* Determines if {@code method} is in a generated class.
69+
*/
70+
private boolean isGenerated(ResolvedJavaMethod method, CoreProviders context) {
71+
if (generatedClassSupertypes == null) {
72+
generatedClassSupertypes = Set.of(
73+
context.getMetaAccess().lookupJavaType(GeneratedInvocationPlugin.class),
74+
context.getMetaAccess().lookupJavaType(PluginReplacementNode.ReplacementFunction.class));
75+
}
76+
ResolvedJavaType declaringClass = method.getDeclaringClass();
77+
for (ResolvedJavaType t : generatedClassSupertypes) {
78+
if (t.isAssignableFrom(declaringClass)) {
79+
return true;
80+
}
81+
}
82+
return false;
83+
}
5384

5485
@Override
5586
protected void verify(StructuredGraph graph, CoreProviders context) {
5687
ResolvedJavaMethod method = graph.method();
5788
if (method.getAnnotation(Fold.class) != null) {
58-
foldables.putIfAbsent(method, false);
89+
foldableCallers.putIfAbsent(method, method);
5990
} else {
60-
if (generatedInvocationPluginType == null) {
61-
generatedInvocationPluginType = context.getMetaAccess().lookupJavaType(GeneratedInvocationPlugin.class);
62-
}
63-
if (!generatedInvocationPluginType.isAssignableFrom(method.getDeclaringClass())) {
91+
if (!isGenerated(method, context)) {
6492
for (MethodCallTargetNode t : graph.getNodes(MethodCallTargetNode.TYPE)) {
6593
ResolvedJavaMethod callee = t.targetMethod();
6694
if (callee.getAnnotation(Fold.class) != null) {
67-
foldables.put(callee, true);
95+
foldableCallers.put(callee, method);
6896
}
6997
}
7098
}
7199
}
72100
}
73101

74102
public void finish() {
75-
String uncalled = foldables.entrySet().stream().filter(e -> e.getValue() == false).map(e -> e.getKey().format("%H.%n(%p)")).collect(Collectors.joining(System.lineSeparator() + " "));
76-
if (uncalled.length() != 0) {
103+
String uncalled = foldableCallers.entrySet().stream()//
104+
.filter(e -> e.getValue() == e.getKey())//
105+
.map(e -> e.getKey().format("%H.%n(%p)"))//
106+
.collect(Collectors.joining(System.lineSeparator() + " "));
107+
if (!uncalled.isEmpty()) {
77108
throw new VerificationError(String.format("Methods annotated with @" + Fold.class.getSimpleName() + " appear to have no usages:%n %s", uncalled));
78109
}
79110
}

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/code/DisassemblerProvider.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@
2424
*/
2525
package jdk.graal.compiler.code;
2626

27+
import jdk.graal.compiler.serviceprovider.LibGraalService;
2728
import jdk.vm.ci.code.CodeCacheProvider;
2829
import jdk.vm.ci.code.InstalledCode;
2930
import jdk.graal.compiler.options.OptionValues;
3031

3132
/**
3233
* Interface providing capability for disassembling machine code.
3334
*/
35+
@LibGraalService
3436
public interface DisassemblerProvider {
3537

3638
/**

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/core/ArchitectureSpecific.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
public interface ArchitectureSpecific {
3131
/**
3232
* Gets the {@linkplain Architecture#getName() name} of the architecture this Graal component is
33-
* associated with.
33+
* associated with. Note that the JVMCI architecture names are somewhat inconsistent wrt case
34+
* (i.e., "AMD64", "aarch64" and "riscv64").
3435
*/
3536
String getArchitecture();
3637
}

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/core/common/CompilerProfiler.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@
2424
*/
2525
package jdk.graal.compiler.core.common;
2626

27+
import jdk.graal.compiler.serviceprovider.LibGraalService;
2728
import jdk.vm.ci.meta.ResolvedJavaMethod;
2829

2930
/**
3031
* A profiling service that consumes compilation related events. The Java Flight Recorder (JFR) is
3132
* an example of such a service that can be exposed via this interface.
3233
*/
34+
@LibGraalService
3335
public interface CompilerProfiler {
3436

3537
/**

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/core/match/MatchRuleRegistry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public static synchronized EconomicMap<Class<? extends Node>, List<MatchStatemen
102102
}
103103
}
104104

105-
if (result.size() == 0) {
105+
if (result.isEmpty()) {
106106
return null;
107107
}
108108
return result;

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/core/match/MatchStatementSet.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
import jdk.graal.compiler.core.ArchitectureSpecific;
3030
import jdk.graal.compiler.core.gen.NodeLIRBuilder;
3131
import jdk.graal.compiler.core.gen.NodeMatchRules;
32+
import jdk.graal.compiler.serviceprovider.LibGraalService;
3233

34+
@LibGraalService
3335
public interface MatchStatementSet extends ArchitectureSpecific {
3436
/**
3537
* @return the {@link NodeLIRBuilder} subclass which defined this set of {@link MatchStatement}

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/debug/DebugHandlersFactory.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@
2929

3030
import jdk.graal.compiler.options.OptionValues;
3131
import jdk.graal.compiler.serviceprovider.GraalServices;
32+
import jdk.graal.compiler.serviceprovider.LibGraalService;
3233

3334
/**
3435
* Factory for creating {@link DebugHandler}s.
3536
*/
37+
@LibGraalService
3638
public interface DebugHandlersFactory {
3739

3840
/**

0 commit comments

Comments
 (0)