Skip to content

[GR-67544] Backport to 25: Support conditional invocation plugin in runtime compilation. #11759

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: release/graal-vm/25.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@
import jdk.graal.compiler.hotspot.meta.UnimplementedGraalIntrinsics;
import jdk.graal.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins;
import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugin;
import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugin.ConditionalInvocationPlugin;
import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugins;
import jdk.graal.compiler.options.OptionValues;
import jdk.graal.compiler.runtime.RuntimeProvider;
import jdk.graal.compiler.test.GraalTest;
import jdk.vm.ci.code.Architecture;
import jdk.vm.ci.hotspot.HotSpotVMConfigStore;
import jdk.vm.ci.hotspot.VMIntrinsicMethod;
import jdk.vm.ci.meta.MetaAccessProvider;
Expand Down Expand Up @@ -144,6 +146,16 @@ public interface Refiner {
public final GraalHotSpotVMConfig config = rt.getVMConfig();
public final UnimplementedGraalIntrinsics unimplementedGraalIntrinsics = new UnimplementedGraalIntrinsics(rt.getTarget().arch);

private static boolean isApplicable(InvocationPlugin plugin, Architecture arch) {
if (plugin == null) {
return false;
}
if (plugin instanceof ConditionalInvocationPlugin conditionalInvocationPlugin) {
return conditionalInvocationPlugin.isApplicable(arch);
}
return true;
}

@Test
@SuppressWarnings("try")
public void test() throws ClassNotFoundException, NoSuchFieldException {
Expand Down Expand Up @@ -171,12 +183,10 @@ public void test() throws ClassNotFoundException, NoSuchFieldException {

InvocationPlugin plugin = invocationPlugins.lookupInvocation(method, Graal.getRequiredCapability(OptionValues.class));
String m = String.format("%s.%s%s", intrinsic.declaringClass, intrinsic.name, intrinsic.descriptor);
if (plugin == null) {
if (method != null) {
IntrinsicMethod intrinsicMethod = providers.getConstantReflection().getMethodHandleAccess().lookupMethodHandleIntrinsic(method);
if (intrinsicMethod != null) {
continue;
}
if (!isApplicable(plugin, providers.getLowerer().getTarget().arch)) {
IntrinsicMethod intrinsicMethod = providers.getConstantReflection().getMethodHandleAccess().lookupMethodHandleIntrinsic(method);
if (intrinsicMethod != null) {
continue;
}
if (!unimplementedGraalIntrinsics.isDocumented(m) && isIntrinsicAvailable(intrinsic) && isIntrinsicSupportedByC2(intrinsic)) {
missing.add(m);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -42,7 +42,7 @@ public class ArrayUtilsIndexOfWithMaskTest extends GraalCompilerTest {

@Override
protected void registerInvocationPlugins(InvocationPlugins invocationPlugins) {
TruffleInvocationPlugins.register(getBackend().getTarget().arch, invocationPlugins, getReplacements());
TruffleInvocationPlugins.register(getBackend().getTarget().arch, invocationPlugins);
super.registerInvocationPlugins(invocationPlugins);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class ArrayUtilsRegionEqualsWithMaskConstantTest extends GraalCompilerTes

@Override
protected void registerInvocationPlugins(InvocationPlugins invocationPlugins) {
TruffleInvocationPlugins.register(getBackend().getTarget().arch, invocationPlugins, getReplacements());
TruffleInvocationPlugins.register(getBackend().getTarget().arch, invocationPlugins);
super.registerInvocationPlugins(invocationPlugins);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class ArrayUtilsRegionEqualsWithMaskTest extends GraalCompilerTest {

@Override
protected void registerInvocationPlugins(InvocationPlugins invocationPlugins) {
TruffleInvocationPlugins.register(getBackend().getTarget().arch, invocationPlugins, getReplacements());
TruffleInvocationPlugins.register(getBackend().getTarget().arch, invocationPlugins);
super.registerInvocationPlugins(invocationPlugins);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class ArrayUtilsTest extends GraalCompilerTest {

@Override
protected void registerInvocationPlugins(InvocationPlugins invocationPlugins) {
TruffleInvocationPlugins.register(getBackend().getTarget().arch, invocationPlugins, getReplacements());
TruffleInvocationPlugins.register(getBackend().getTarget().arch, invocationPlugins);
super.registerInvocationPlugins(invocationPlugins);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class ExactMathTest extends TruffleCompilerImplTest {

@Override
protected void registerInvocationPlugins(InvocationPlugins invocationPlugins) {
TruffleGraphBuilderPlugins.registerExactMathPlugins(invocationPlugins, getTypes(), getReplacements(), getLowerer());
TruffleGraphBuilderPlugins.registerExactMathPlugins(invocationPlugins, getTypes());
super.registerInvocationPlugins(invocationPlugins);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected void addConstantParameterBinding(GraphBuilderConfiguration conf, Objec

@Override
protected void registerInvocationPlugins(InvocationPlugins invocationPlugins) {
TruffleInvocationPlugins.register(getBackend().getTarget().arch, invocationPlugins, getReplacements());
TruffleInvocationPlugins.register(getBackend().getTarget().arch, invocationPlugins);
super.registerInvocationPlugins(invocationPlugins);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -52,8 +52,6 @@

import java.util.EnumSet;

import org.graalvm.collections.EconomicSet;

import jdk.graal.compiler.asm.Assembler;
import jdk.graal.compiler.core.common.Stride;
import jdk.graal.compiler.debug.GraalError;
Expand Down Expand Up @@ -308,35 +306,6 @@ public final boolean supports(CPUFeature feature) {
return getFeatures().contains(feature);
}

public final boolean supports(String feature) {
try {
return getFeatures().contains(AMD64.CPUFeature.valueOf(feature));
} catch (IllegalArgumentException e) {
return false;
}
}

/**
* Mitigates exception throwing by recording unknown CPU feature names.
*/
private final EconomicSet<String> unknownFeatures = EconomicSet.create();

/**
* Determines if the CPU feature denoted by {@code name} is supported. This name based look up
* is for features only available in later JVMCI releases.
*/
public final boolean supportsCPUFeature(String name) {
if (unknownFeatures.contains(name)) {
return false;
}
try {
return supports(CPUFeature.valueOf(name));
} catch (IllegalArgumentException e) {
unknownFeatures.add(name);
return false;
}
}

protected static boolean inRC(RegisterCategory rc, Register r) {
return r.getRegisterCategory().equals(rc);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ public void emitArrayCopyWithConversion(EnumSet<?> runtimeCheckedCPUFeatures, Va
}

@Override
public void emitArrayFill(JavaKind kind, EnumSet<?> runtimeCheckedCPUFeatures, Value array, Value arrayBaseOffset, Value length, Value value) {
public void emitArrayFill(JavaKind kind, Value array, Value arrayBaseOffset, Value length, Value value) {
append(new AArch64ArrayFillOp(kind, emitConvertNullToZero(array), asAllocatable(arrayBaseOffset), asAllocatable(length), asAllocatable(value)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ default boolean supportsBulkZeroingOfEden() {
return true;
}

@Override
default boolean supportsRounding() {
return true;
}

@Override
default boolean writesStronglyOrdered() {
/* AArch64 only requires a weak memory model. */
Expand Down Expand Up @@ -88,14 +83,4 @@ default boolean supportsFoldingExtendIntoAccess(ExtendableMemoryAccess access, M
}
return false;
}

@Override
default boolean supportsFloatToUnsignedConvert() {
return true;
}

@Override
default boolean supportsUnsignedToFloatConvert() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1232,14 +1232,6 @@ public boolean supportsCPUFeature(AMD64.CPUFeature feature) {
return ((AMD64) target().arch).getFeatures().contains(feature);
}

public boolean supportsCPUFeature(String feature) {
try {
return ((AMD64) target().arch).getFeatures().contains(AMD64.CPUFeature.valueOf(feature));
} catch (IllegalArgumentException e) {
return false;
}
}

public boolean usePopCountInstruction() {
return supportsCPUFeature(CPUFeature.POPCNT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@

package jdk.graal.compiler.core.amd64;

import jdk.graal.compiler.asm.amd64.AMD64Assembler;
import jdk.graal.compiler.core.common.memory.MemoryExtendKind;
import jdk.graal.compiler.nodes.memory.ExtendableMemoryAccess;
import jdk.graal.compiler.nodes.spi.LoweringProvider;
import jdk.vm.ci.amd64.AMD64;

public interface AMD64LoweringProviderMixin extends LoweringProvider {

Expand Down Expand Up @@ -66,19 +64,4 @@ default boolean narrowsUseCastValue() {
default boolean supportsFoldingExtendIntoAccess(ExtendableMemoryAccess access, MemoryExtendKind extendKind) {
return false;
}

@Override
default boolean supportsFloatToUnsignedConvert() {
return true;
}

@Override
default boolean supportsUnsignedToFloatConvert() {
/*
* Use AVX-512 conversion instructions if available. Otherwise, don't bother with
* hand-written assembly intrinsics, which won't beat the pure Java implementation.
*/
AMD64 amd64 = (AMD64) getTarget().arch;
return AMD64Assembler.supportsFullAVX512(amd64.getFeatures());
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -46,11 +46,6 @@ default boolean supportsBulkZeroingOfEden() {
return false;
}

@Override
default boolean supportsRounding() {
return false;
}

@Override
default boolean writesStronglyOrdered() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -692,10 +692,6 @@ private long getZGCAddressField(String name) {
public final long jvmtiVThreadMount = getAddress("SharedRuntime::notify_jvmti_vthread_mount");
public final long jvmtiVThreadUnmount = getAddress("SharedRuntime::notify_jvmti_vthread_unmount");

public boolean supportJVMTIVThreadNotification() {
return jvmtiVThreadStart != 0L && jvmtiVThreadEnd != 0L && jvmtiVThreadMount != 0L && jvmtiVThreadUnmount != 0L;
}

// JDK-8322630
public final int icSpeculatedKlassOffset = getFieldOffset("CompiledICData::_speculated_klass", Integer.class, "uintptr_t");

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -24,9 +24,9 @@
*/
package jdk.graal.compiler.hotspot;

import static jdk.vm.ci.common.InitTimer.timer;
import static jdk.graal.compiler.core.common.NativeImageSupport.inBuildtimeCode;
import static jdk.graal.compiler.core.common.NativeImageSupport.inRuntimeCode;
import static jdk.vm.ci.common.InitTimer.timer;

import jdk.graal.compiler.bytecode.BytecodeProvider;
import jdk.graal.compiler.core.ArchitectureSpecific;
Expand Down Expand Up @@ -215,7 +215,7 @@ public final HotSpotBackend createBackend(HotSpotGraalRuntimeProvider graalRunti
replacements.setGraphBuilderPlugins(plugins);
}
try (InitTimer rt = timer("create Suites provider")) {
HotSpotSuitesProvider suites = createSuites(config, graalRuntime, compilerConfiguration, plugins, registers, replacements, options);
HotSpotSuitesProvider suites = createSuites(config, graalRuntime, compilerConfiguration, plugins, registers, options);
providers.setSuites(suites);
}
Replacements replacements2 = replacements.getProviders().getReplacements();
Expand All @@ -241,8 +241,7 @@ protected abstract GraphBuilderConfiguration.Plugins createGraphBuilderPlugins(H
HotSpotSnippetReflectionProvider snippetReflection, HotSpotReplacementsImpl replacements, HotSpotWordTypes wordTypes, OptionValues options, BarrierSet barrierSet);

protected abstract HotSpotSuitesProvider createSuites(GraalHotSpotVMConfig config, HotSpotGraalRuntimeProvider runtime, CompilerConfiguration compilerConfiguration,
GraphBuilderConfiguration.Plugins plugins,
HotSpotRegistersProvider registers, HotSpotReplacementsImpl replacements, OptionValues options);
Plugins plugins, HotSpotRegistersProvider registers, OptionValues options);

protected abstract HotSpotRegistersProvider createRegisters();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,6 @@ public Class<? extends GraphBuilderPlugin> getIntrinsifyingPlugin(ResolvedJavaMe
return super.getIntrinsifyingPlugin(method);
}

@Override
public void registerConditionalPlugin(InvocationPlugin plugin) {
if (!LibGraalSupport.inLibGraalRuntime()) {
if (snippetEncoder != null) {
snippetEncoder.registerConditionalPlugin(plugin);
}
}
}

@Override
public void notifyNotInlined(GraphBuilderContext b, ResolvedJavaMethod method, Invoke invoke) {
if (!LibGraalSupport.inLibGraalRuntime()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -40,7 +40,6 @@
import java.util.function.BiFunction;

import org.graalvm.collections.EconomicMap;
import org.graalvm.collections.EconomicSet;
import org.graalvm.collections.MapCursor;

import jdk.graal.compiler.api.replacements.Fold;
Expand Down Expand Up @@ -89,6 +88,7 @@
import jdk.graal.compiler.nodes.graphbuilderconf.InlineInvokePlugin;
import jdk.graal.compiler.nodes.graphbuilderconf.IntrinsicContext;
import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugin;
import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugin.ConditionalInvocationPlugin;
import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugins;
import jdk.graal.compiler.nodes.graphbuilderconf.NodePlugin;
import jdk.graal.compiler.nodes.java.AccessFieldNode;
Expand Down Expand Up @@ -206,8 +206,6 @@ public String toString() {

private final EconomicMap<String, SnippetParameterInfo> snippetParameterInfos = EconomicMap.create();

private final EconomicSet<InvocationPlugin> conditionalPlugins = EconomicSet.create();

/**
* The invocation plugins which were delayed during graph preparation.
*/
Expand Down Expand Up @@ -266,10 +264,6 @@ public boolean handleLoadField(GraphBuilderContext b, ValueNode object, Resolved
this.originalReplacements = replacements;
}

synchronized void registerConditionalPlugin(InvocationPlugin plugin) {
conditionalPlugins.add(plugin);
}

@SuppressWarnings("try")
private StructuredGraph buildGraph(ResolvedJavaMethod method, ResolvedJavaMethod original, Object receiver, BitSet nonNullParameters,
boolean trackNodeSourcePosition, OptionValues options, ReplacementsImpl snippetReplacements) {
Expand Down Expand Up @@ -1053,7 +1047,7 @@ protected boolean tryInvocationPlugin(CallTargetNode.InvokeKind invokeKind, Valu
}

InvocationPlugin plugin = graphBuilderConfig.getPlugins().getInvocationPlugins().lookupInvocation(targetMethod, options);
if (plugin != null && conditionalPlugins.contains(plugin)) {
if (plugin instanceof ConditionalInvocationPlugin) {
// Because supporting arbitrary plugins in the context of encoded graphs is complex
// we disallow it. This limitation can be worked around through the use of method
// substitutions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,7 @@ protected Plugins createGraphBuilderPlugins(HotSpotGraalRuntimeProvider graalRun
options,
target,
barrierSet);
AArch64GraphBuilderPlugins.register(plugins,
replacements,
/* registerForeignCallMath */true,
options);
AArch64GraphBuilderPlugins.register(plugins, options);
return plugins;
}

Expand All @@ -134,7 +131,7 @@ protected HotSpotHostForeignCallsProvider createForeignCalls(HotSpotJVMCIRuntime

@Override
protected HotSpotSuitesProvider createSuites(GraalHotSpotVMConfig config, HotSpotGraalRuntimeProvider runtime, CompilerConfiguration compilerConfiguration, Plugins plugins,
HotSpotRegistersProvider registers, HotSpotReplacementsImpl replacements, OptionValues options) {
HotSpotRegistersProvider registers, OptionValues options) {
AArch64SuitesCreator suitesCreator = new AArch64HotSpotSuitesCreator(compilerConfiguration, plugins);
BasePhase<CoreProviders> addressLoweringPhase = new AddressLoweringByUsePhase(new AArch64AddressLoweringByUse(new AArch64HotSpotSimdLIRKindTool(), true));
return new AddressLoweringHotSpotSuitesProvider(suitesCreator, config, runtime, addressLoweringPhase);
Expand Down
Loading