diff --git a/compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/hotspot/test/CheckGraalIntrinsics.java b/compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/hotspot/test/CheckGraalIntrinsics.java index 89d5f1670f4c..03206e9b325c 100644 --- a/compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/hotspot/test/CheckGraalIntrinsics.java +++ b/compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/hotspot/test/CheckGraalIntrinsics.java @@ -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; @@ -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 { @@ -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); diff --git a/compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/truffle/test/ArrayUtilsIndexOfWithMaskTest.java b/compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/truffle/test/ArrayUtilsIndexOfWithMaskTest.java index 4de762f5eafd..a62c58256bb3 100644 --- a/compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/truffle/test/ArrayUtilsIndexOfWithMaskTest.java +++ b/compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/truffle/test/ArrayUtilsIndexOfWithMaskTest.java @@ -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 @@ -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); } diff --git a/compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/truffle/test/ArrayUtilsRegionEqualsWithMaskConstantTest.java b/compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/truffle/test/ArrayUtilsRegionEqualsWithMaskConstantTest.java index 9ef0f14c8673..a85b14361474 100644 --- a/compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/truffle/test/ArrayUtilsRegionEqualsWithMaskConstantTest.java +++ b/compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/truffle/test/ArrayUtilsRegionEqualsWithMaskConstantTest.java @@ -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); } diff --git a/compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/truffle/test/ArrayUtilsRegionEqualsWithMaskTest.java b/compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/truffle/test/ArrayUtilsRegionEqualsWithMaskTest.java index 9639258e9e5d..7d1da8e539bf 100644 --- a/compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/truffle/test/ArrayUtilsRegionEqualsWithMaskTest.java +++ b/compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/truffle/test/ArrayUtilsRegionEqualsWithMaskTest.java @@ -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); } diff --git a/compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/truffle/test/ArrayUtilsTest.java b/compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/truffle/test/ArrayUtilsTest.java index 2c085efdb79e..66f74eb3f354 100644 --- a/compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/truffle/test/ArrayUtilsTest.java +++ b/compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/truffle/test/ArrayUtilsTest.java @@ -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); } diff --git a/compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/truffle/test/ExactMathTest.java b/compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/truffle/test/ExactMathTest.java index bb805305f941..b83341b3b24b 100644 --- a/compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/truffle/test/ExactMathTest.java +++ b/compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/truffle/test/ExactMathTest.java @@ -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); } diff --git a/compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/truffle/test/strings/TStringTest.java b/compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/truffle/test/strings/TStringTest.java index 0e272fd258ce..0daa01416811 100644 --- a/compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/truffle/test/strings/TStringTest.java +++ b/compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/truffle/test/strings/TStringTest.java @@ -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); } diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/asm/amd64/AMD64BaseAssembler.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/asm/amd64/AMD64BaseAssembler.java index 01b891bf5096..d6343fba1b56 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/asm/amd64/AMD64BaseAssembler.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/asm/amd64/AMD64BaseAssembler.java @@ -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 @@ -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; @@ -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 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); } diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/core/aarch64/AArch64LIRGenerator.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/core/aarch64/AArch64LIRGenerator.java index 29cb1f10b657..d906bbb0066d 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/core/aarch64/AArch64LIRGenerator.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/core/aarch64/AArch64LIRGenerator.java @@ -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))); } diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/core/aarch64/AArch64LoweringProviderMixin.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/core/aarch64/AArch64LoweringProviderMixin.java index b12e66923de3..edc4f61cdc83 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/core/aarch64/AArch64LoweringProviderMixin.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/core/aarch64/AArch64LoweringProviderMixin.java @@ -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. */ @@ -88,14 +83,4 @@ default boolean supportsFoldingExtendIntoAccess(ExtendableMemoryAccess access, M } return false; } - - @Override - default boolean supportsFloatToUnsignedConvert() { - return true; - } - - @Override - default boolean supportsUnsignedToFloatConvert() { - return true; - } } diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/core/amd64/AMD64LIRGenerator.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/core/amd64/AMD64LIRGenerator.java index 2f293783daf2..083e1ed060ba 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/core/amd64/AMD64LIRGenerator.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/core/amd64/AMD64LIRGenerator.java @@ -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); } diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/core/amd64/AMD64LoweringProviderMixin.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/core/amd64/AMD64LoweringProviderMixin.java index 78168f417cb4..bab195e7618f 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/core/amd64/AMD64LoweringProviderMixin.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/core/amd64/AMD64LoweringProviderMixin.java @@ -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 { @@ -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()); - } } diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/core/riscv64/RISCV64LoweringProviderMixin.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/core/riscv64/RISCV64LoweringProviderMixin.java index 5a8a80c577f5..038addc608dc 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/core/riscv64/RISCV64LoweringProviderMixin.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/core/riscv64/RISCV64LoweringProviderMixin.java @@ -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 @@ -46,11 +46,6 @@ default boolean supportsBulkZeroingOfEden() { return false; } - @Override - default boolean supportsRounding() { - return false; - } - @Override default boolean writesStronglyOrdered() { return false; diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/GraalHotSpotVMConfig.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/GraalHotSpotVMConfig.java index 24f529a66095..eb0814bfe520 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/GraalHotSpotVMConfig.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/GraalHotSpotVMConfig.java @@ -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"); diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/HotSpotBackendFactory.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/HotSpotBackendFactory.java index 3f13486e7dc7..ed81222a9f71 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/HotSpotBackendFactory.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/HotSpotBackendFactory.java @@ -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 @@ -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; @@ -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(); @@ -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(); diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/HotSpotReplacementsImpl.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/HotSpotReplacementsImpl.java index 7b2eb9983f28..81a73c8343f7 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/HotSpotReplacementsImpl.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/HotSpotReplacementsImpl.java @@ -110,15 +110,6 @@ public Class 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()) { diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/SymbolicSnippetEncoder.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/SymbolicSnippetEncoder.java index 34a6269c3cb7..647009a3557d 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/SymbolicSnippetEncoder.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/SymbolicSnippetEncoder.java @@ -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 @@ -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; @@ -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; @@ -206,8 +206,6 @@ public String toString() { private final EconomicMap snippetParameterInfos = EconomicMap.create(); - private final EconomicSet conditionalPlugins = EconomicSet.create(); - /** * The invocation plugins which were delayed during graph preparation. */ @@ -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) { @@ -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. diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/aarch64/AArch64HotSpotBackendFactory.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/aarch64/AArch64HotSpotBackendFactory.java index 48451bd9582c..cf7caa0de775 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/aarch64/AArch64HotSpotBackendFactory.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/aarch64/AArch64HotSpotBackendFactory.java @@ -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; } @@ -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 addressLoweringPhase = new AddressLoweringByUsePhase(new AArch64AddressLoweringByUse(new AArch64HotSpotSimdLIRKindTool(), true)); return new AddressLoweringHotSpotSuitesProvider(suitesCreator, config, runtime, addressLoweringPhase); diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/amd64/AMD64HotSpotBackendFactory.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/amd64/AMD64HotSpotBackendFactory.java index 1c0576e86373..690899bf8938 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/amd64/AMD64HotSpotBackendFactory.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/amd64/AMD64HotSpotBackendFactory.java @@ -92,7 +92,7 @@ protected Plugins createGraphBuilderPlugins(HotSpotGraalRuntimeProvider graalRun options, target, barrierSet); - AMD64GraphBuilderPlugins.register(plugins, replacements, (AMD64) target.arch, options); + AMD64GraphBuilderPlugins.register(plugins, options); return plugins; } @@ -112,12 +112,9 @@ protected HotSpotHostForeignCallsProvider createForeignCalls(HotSpotJVMCIRuntime return new AMD64HotSpotForeignCallsProvider(runtime, graalRuntime, metaAccess, codeCache, wordTypes, nativeABICallerSaveRegisters); } - /** - * @param replacements - */ @Override protected HotSpotSuitesProvider createSuites(GraalHotSpotVMConfig config, HotSpotGraalRuntimeProvider runtime, CompilerConfiguration compilerConfiguration, Plugins plugins, - HotSpotRegistersProvider registers, HotSpotReplacementsImpl replacements, OptionValues options) { + HotSpotRegistersProvider registers, OptionValues options) { return new AddressLoweringHotSpotSuitesProvider(new AMD64HotSpotSuitesCreator(compilerConfiguration, plugins), config, runtime, new AddressLoweringByNodePhase(new AMD64HotSpotAddressLowering(config, registers.getHeapBaseRegister()))); } diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/amd64/AMD64HotSpotLoweringProvider.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/amd64/AMD64HotSpotLoweringProvider.java index 7843b961508d..14af142dd551 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/amd64/AMD64HotSpotLoweringProvider.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/amd64/AMD64HotSpotLoweringProvider.java @@ -46,7 +46,6 @@ import jdk.graal.compiler.replacements.nodes.UnaryMathIntrinsicNode; import jdk.graal.compiler.replacements.nodes.UnaryMathIntrinsicNode.UnaryOperation; import jdk.graal.compiler.vector.architecture.VectorArchitecture; -import jdk.vm.ci.amd64.AMD64; import jdk.vm.ci.code.TargetDescription; import jdk.vm.ci.hotspot.HotSpotConstantReflectionProvider; import jdk.vm.ci.meta.MetaAccessProvider; @@ -111,10 +110,4 @@ private void lowerUnaryMath(UnaryMathIntrinsicNode math, LoweringTool tool) { } lowerUnaryMathToForeignCall(math, tool); } - - @Override - public boolean supportsRounding() { - return ((AMD64) getTarget().arch).getFeatures().contains(AMD64.CPUFeature.SSE4_1); - } - } diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/meta/HotSpotGraphBuilderPlugins.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/meta/HotSpotGraphBuilderPlugins.java index a94134a14af2..7074a7d5a788 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/meta/HotSpotGraphBuilderPlugins.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/meta/HotSpotGraphBuilderPlugins.java @@ -162,6 +162,8 @@ import jdk.graal.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins; import jdk.graal.compiler.nodes.graphbuilderconf.GraphBuilderContext; import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugin; +import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugin.ConditionalInvocationPlugin; +import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugin.InlineOnlyConditionalInvocationPlugin; import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugin.InlineOnlyInvocationPlugin; import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver; import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugins; @@ -176,7 +178,6 @@ import jdk.graal.compiler.nodes.memory.WriteNode; import jdk.graal.compiler.nodes.memory.address.AddressNode; import jdk.graal.compiler.nodes.memory.address.OffsetAddressNode; -import jdk.graal.compiler.nodes.spi.Replacements; import jdk.graal.compiler.nodes.util.GraphUtil; import jdk.graal.compiler.options.Option; import jdk.graal.compiler.options.OptionKey; @@ -199,11 +200,9 @@ import jdk.graal.compiler.replacements.arraycopy.ArrayCopyForeignCalls; import jdk.graal.compiler.replacements.arraycopy.ArrayCopySnippets; import jdk.graal.compiler.replacements.nodes.AESNode.CryptMode; -import jdk.graal.compiler.replacements.nodes.CipherBlockChainingAESNode; -import jdk.graal.compiler.replacements.nodes.CounterModeAESNode; +import jdk.graal.compiler.replacements.nodes.BinaryMathIntrinsicNode; import jdk.graal.compiler.replacements.nodes.MacroNode.MacroParams; -import jdk.graal.compiler.replacements.nodes.VectorizedHashCodeNode; -import jdk.graal.compiler.replacements.nodes.VectorizedMismatchNode; +import jdk.graal.compiler.replacements.nodes.UnaryMathIntrinsicNode; import jdk.graal.compiler.serviceprovider.GraalServices; import jdk.graal.compiler.serviceprovider.SpeculationReasonGroup; import jdk.graal.compiler.vector.replacements.vectorapi.VectorAPIIntrinsics; @@ -271,45 +270,48 @@ public static Plugins create(HotSpotGraalRuntimeProvider graalRuntime, if (config.instanceKlassInitThreadOffset != -1) { plugins.setClassInitializationPlugin(new HotSpotJITClassInitializationPlugin()); } - compilerConfiguration.registerGraphBuilderPlugins(target.arch, plugins, options, replacements); + compilerConfiguration.registerGraphBuilderPlugins(target.arch, plugins, options); invocationPlugins.defer(new Runnable() { @Override public void run() { - registerObjectPlugins(invocationPlugins, config, replacements); - registerClassPlugins(plugins, config, replacements); + StandardGraphBuilderPlugins.registerInvocationPlugins(snippetReflection, invocationPlugins, true, false, true); + + registerObjectPlugins(invocationPlugins, config); + registerClassPlugins(plugins, config); registerSystemPlugins(invocationPlugins); - registerThreadPlugins(invocationPlugins, config, replacements); - registerVirtualThreadPlugins(invocationPlugins, config, replacements); - registerContinuationPlugins(invocationPlugins, config, replacements); + registerThreadPlugins(invocationPlugins, config, barrierSet); + registerVirtualThreadPlugins(invocationPlugins, config); + registerMathPlugins(invocationPlugins, target.arch); + registerContinuationPlugins(invocationPlugins, config); registerCallSitePlugins(invocationPlugins); - registerReflectionPlugins(invocationPlugins, replacements, config); - registerAESPlugins(invocationPlugins, config, replacements, target.arch); - registerAdler32Plugins(invocationPlugins, config, replacements); - registerCRC32Plugins(invocationPlugins, config, replacements); - registerCRC32CPlugins(invocationPlugins, config, replacements); - registerBigIntegerPlugins(invocationPlugins, config, replacements); - registerSHAPlugins(invocationPlugins, config, replacements); - registerMLPlugins(invocationPlugins, config, replacements); - registerBase64Plugins(invocationPlugins, config, metaAccess, replacements); - registerUnsafePlugins(invocationPlugins, replacements, config); - StandardGraphBuilderPlugins.registerInvocationPlugins(snippetReflection, invocationPlugins, replacements, true, false, true, graalRuntime.getHostProviders().getLowerer()); - registerArrayPlugins(invocationPlugins, replacements, config); - registerStringPlugins(invocationPlugins, replacements, wordTypes, foreignCalls, config); - registerArraysSupportPlugins(invocationPlugins, replacements, target.arch); - registerReferencePlugins(invocationPlugins, replacements); + registerReflectionPlugins(invocationPlugins, config); + registerAESPlugins(invocationPlugins, config); + registerAdler32Plugins(invocationPlugins, config); + registerCRC32Plugins(invocationPlugins, config); + registerCRC32CPlugins(invocationPlugins, config); + registerBigIntegerPlugins(invocationPlugins, config); + registerSHAPlugins(invocationPlugins, config); + registerMLPlugins(invocationPlugins, config); + registerBase64Plugins(invocationPlugins, config, metaAccess); + registerUnsafePlugins(invocationPlugins, config); + registerArrayPlugins(invocationPlugins, config); + registerStringPlugins(invocationPlugins, wordTypes, foreignCalls, config); + registerArraysSupportPlugins(invocationPlugins, target.arch); + registerReferencePlugins(invocationPlugins); registerTrufflePlugins(invocationPlugins, wordTypes, config); - registerInstrumentationImplPlugins(invocationPlugins, config, replacements); - for (HotSpotInvocationPluginProvider p : GraalServices.load(HotSpotInvocationPluginProvider.class)) { - p.registerInvocationPlugins(target.arch, plugins.getInvocationPlugins(), replacements); - } - registerPoly1305Plugins(invocationPlugins, config, replacements); - registerChaCha20Plugins(invocationPlugins, config, replacements); - registerP256Plugins(invocationPlugins, config, replacements); - registerDualPivotQuicksortPlugins(invocationPlugins, config, replacements, target.arch); + registerInstrumentationImplPlugins(invocationPlugins, config); + registerPoly1305Plugins(invocationPlugins, config); + registerChaCha20Plugins(invocationPlugins, config); + registerP256Plugins(invocationPlugins, config); + registerDualPivotQuicksortPlugins(invocationPlugins, config, target.arch); + if (VectorAPIIntrinsics.intrinsificationSupported(options)) { - VectorAPIIntrinsics.registerPlugins(plugins.getInvocationPlugins(), replacements); + VectorAPIIntrinsics.registerPlugins(plugins.getInvocationPlugins()); + } + for (HotSpotInvocationPluginProvider p : GraalServices.load(HotSpotInvocationPluginProvider.class)) { + p.registerInvocationPlugins(target.arch, plugins.getInvocationPlugins()); } } @@ -327,10 +329,6 @@ public void run() { } private static void registerTrufflePlugins(InvocationPlugins plugins, WordTypes wordTypes, GraalHotSpotVMConfig config) { - if (config.jvmciReservedReference0Offset == -1) { - // cannot install intrinsics without - return; - } plugins.registerIntrinsificationPredicate(t -> t.getName().equals("Lcom/oracle/truffle/runtime/hotspot/HotSpotFastThreadLocal;")); Registration tl = new Registration(plugins, "com.oracle.truffle.runtime.hotspot.HotSpotFastThreadLocal"); tl.register(new InvocationPlugin("get", Receiver.class) { @@ -355,8 +353,8 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec }); } - private static void registerObjectPlugins(InvocationPlugins plugins, GraalHotSpotVMConfig config, Replacements replacements) { - Registration r = new Registration(plugins, Object.class, replacements); + private static void registerObjectPlugins(InvocationPlugins plugins, GraalHotSpotVMConfig config) { + Registration r = new Registration(plugins, Object.class); r.register(new InlineOnlyInvocationPlugin("clone", Receiver.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) { @@ -373,30 +371,36 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec return true; } }); - if (config.inlineNotify()) { - r.register(new InlineOnlyInvocationPlugin("notify", Receiver.class) { - @Override - public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) { - ValueNode object = receiver.get(true); - b.add(new FastNotifyNode(object, false, b.bci())); - return true; - } - }); - } - if (config.inlineNotifyAll()) { - r.register(new InlineOnlyInvocationPlugin("notifyAll", Receiver.class) { - @Override - public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) { - ValueNode object = receiver.get(true); - b.add(new FastNotifyNode(object, true, b.bci())); - return true; - } - }); - } + r.register(new InlineOnlyConditionalInvocationPlugin("notify", Receiver.class) { + @Override + public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) { + ValueNode object = receiver.get(true); + b.add(new FastNotifyNode(object, false, b.bci())); + return true; + } + + @Override + public boolean isApplicable(Architecture arch) { + return config.inlineNotify(); + } + }); + r.register(new InlineOnlyConditionalInvocationPlugin("notifyAll", Receiver.class) { + @Override + public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) { + ValueNode object = receiver.get(true); + b.add(new FastNotifyNode(object, true, b.bci())); + return true; + } + + @Override + public boolean isApplicable(Architecture arch) { + return config.inlineNotifyAll(); + } + }); } - private static void registerClassPlugins(Plugins plugins, GraalHotSpotVMConfig config, Replacements replacements) { - Registration r = new Registration(plugins.getInvocationPlugins(), Class.class, replacements); + private static void registerClassPlugins(Plugins plugins, GraalHotSpotVMConfig config) { + Registration r = new Registration(plugins.getInvocationPlugins(), Class.class); r.register(new InvocationPlugin("getSuperclass", Receiver.class) { @Override @@ -432,7 +436,7 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec } }); - r.registerConditional(config.jvmAccIsHiddenClass != 0, new InvocationPlugin("isHidden", Receiver.class) { + r.register(new InvocationPlugin("isHidden", Receiver.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) { try (HotSpotInvocationPluginHelper helper = new HotSpotInvocationPluginHelper(b, targetMethod, config)) { @@ -449,6 +453,37 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec }); } + private static void registerMathPlugins(InvocationPlugins plugins, Architecture architecture) { + Registration r = new Registration(plugins, Math.class); + // On AArch64, the following Math plugins call into ShareRuntime utilities. While on AMD64, + // the relevant Math plugins call into ported stubs. + if (architecture instanceof AArch64) { + registerUnaryMath(r, "sin", UnaryMathIntrinsicNode.UnaryOperation.SIN); + registerUnaryMath(r, "cos", UnaryMathIntrinsicNode.UnaryOperation.COS); + registerUnaryMath(r, "tan", UnaryMathIntrinsicNode.UnaryOperation.TAN); + registerUnaryMath(r, "exp", UnaryMathIntrinsicNode.UnaryOperation.EXP); + registerUnaryMath(r, "log", UnaryMathIntrinsicNode.UnaryOperation.LOG); + registerUnaryMath(r, "log10", UnaryMathIntrinsicNode.UnaryOperation.LOG10); + r.register(new InlineOnlyInvocationPlugin("pow", double.class, double.class) { + @Override + public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode x, ValueNode y) { + b.push(JavaKind.Double, b.append(BinaryMathIntrinsicNode.create(x, y, BinaryMathIntrinsicNode.BinaryOperation.POW))); + return true; + } + }); + } + } + + private static void registerUnaryMath(Registration r, String name, UnaryMathIntrinsicNode.UnaryOperation operation) { + r.register(new InlineOnlyInvocationPlugin(name, double.class) { + @Override + public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) { + b.push(JavaKind.Double, b.append(UnaryMathIntrinsicNode.create(value, operation))); + return true; + } + }); + } + private static void registerCallSitePlugins(InvocationPlugins plugins) { InvocationPlugin plugin = new InlineOnlyInvocationPlugin("getTarget", Receiver.class) { @Override @@ -468,8 +503,8 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec plugins.register(VolatileCallSite.class, plugin); } - private static void registerReflectionPlugins(InvocationPlugins plugins, Replacements replacements, GraalHotSpotVMConfig config) { - Registration r = new Registration(plugins, "jdk.internal.reflect.Reflection", replacements); + private static void registerReflectionPlugins(InvocationPlugins plugins, GraalHotSpotVMConfig config) { + Registration r = new Registration(plugins, "jdk.internal.reflect.Reflection"); r.register(new InlineOnlyInvocationPlugin("getCallerClass") { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) { @@ -495,8 +530,8 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec private static final SpeculationReasonGroup JVMTI_NOTIFY_ALLOCATE_INSTANCE = new SpeculationReasonGroup("JvmtiNotifyAllocateInstance"); - private static void registerUnsafePlugins(InvocationPlugins plugins, Replacements replacements, GraalHotSpotVMConfig config) { - Registration r = new Registration(plugins, "jdk.internal.misc.Unsafe", replacements); + private static void registerUnsafePlugins(InvocationPlugins plugins, GraalHotSpotVMConfig config) { + Registration r = new Registration(plugins, "jdk.internal.misc.Unsafe"); r.register(new InvocationPlugin("copyMemory0", Receiver.class, Object.class, long.class, Object.class, long.class, long.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode srcBase, ValueNode srcOffset, ValueNode destBase, @@ -505,12 +540,18 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec return true; } }); - r.registerConditional(config.unsafeSetMemory != 0L, new InvocationPlugin("setMemory0", Receiver.class, Object.class, long.class, long.class, byte.class) { + + r.register(new ConditionalInvocationPlugin("setMemory0", Receiver.class, Object.class, long.class, long.class, byte.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode obj, ValueNode offset, ValueNode bytes, ValueNode value) { b.add(new UnsafeSetMemoryNode(receiver.get(true), obj, offset, bytes, value)); return true; } + + @Override + public boolean isApplicable(Architecture arch) { + return config.unsafeSetMemory != 0L; + } }); r.register(new InvocationPlugin("allocateInstance", Receiver.class, Class.class) { @Override @@ -564,8 +605,8 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec ArrayCopySnippets.registerSystemArraycopyPlugin(r); } - private static void registerArrayPlugins(InvocationPlugins plugins, Replacements replacements, GraalHotSpotVMConfig config) { - Registration r = new Registration(plugins, Array.class, replacements); + private static void registerArrayPlugins(InvocationPlugins plugins, GraalHotSpotVMConfig config) { + Registration r = new Registration(plugins, Array.class); r.setAllowOverwrite(true); r.register(new InvocationPlugin("newArray", Class.class, int.class) { @Override @@ -587,8 +628,8 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec r.register(StandardGraphBuilderPlugins.newArrayPlugin("newInstance")); } - private static void registerStringPlugins(InvocationPlugins plugins, Replacements replacements, WordTypes wordTypes, ArrayCopyForeignCalls foreignCalls, GraalHotSpotVMConfig vmConfig) { - final Registration utf16r = new Registration(plugins, "java.lang.StringUTF16", replacements); + private static void registerStringPlugins(InvocationPlugins plugins, WordTypes wordTypes, ArrayCopyForeignCalls foreignCalls, GraalHotSpotVMConfig vmConfig) { + final Registration utf16r = new Registration(plugins, "java.lang.StringUTF16"); utf16r.register(new InvocationPlugin("toBytes", char[].class, int.class, int.class) { private static final int MAX_LENGTH = Integer.MAX_VALUE >> 1; @@ -667,9 +708,8 @@ private static AddressNode getScopedValueCacheAddress(GraphBuilderContext b, Hot return b.add(OffsetAddressNode.create(scopedValueCacheHandle)); } - private static void registerThreadPlugins(InvocationPlugins plugins, GraalHotSpotVMConfig config, Replacements replacements) { - BarrierSet barrierSet = replacements.getProviders().getPlatformConfigurationProvider().getBarrierSet(); - Registration r = new Registration(plugins, Thread.class, replacements); + private static void registerThreadPlugins(InvocationPlugins plugins, GraalHotSpotVMConfig config, BarrierSet barrierSet) { + Registration r = new Registration(plugins, Thread.class); r.register(new InvocationPlugin("currentThread") { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) { @@ -731,8 +771,7 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec return true; } }); - - r.registerConditional(config.javaThreadScopedValueCacheOffset != -1, new InvocationPlugin("scopedValueCache") { + r.register(new InvocationPlugin("scopedValueCache") { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) { try (HotSpotInvocationPluginHelper helper = new HotSpotInvocationPluginHelper(b, targetMethod, config)) { @@ -745,8 +784,7 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec return true; } }); - - r.registerConditional(config.javaThreadScopedValueCacheOffset != -1, new InvocationPlugin("setScopedValueCache", Object[].class) { + r.register(new InvocationPlugin("setScopedValueCache", Object[].class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode cache) { try (HotSpotInvocationPluginHelper helper = new HotSpotInvocationPluginHelper(b, targetMethod, config)) { @@ -853,64 +891,60 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec } } - private static void registerContinuationPlugins(InvocationPlugins plugins, GraalHotSpotVMConfig config, Replacements replacements) { - Registration r = new Registration(plugins, "jdk.internal.vm.Continuation", replacements); + private static void registerContinuationPlugins(InvocationPlugins plugins, GraalHotSpotVMConfig config) { + Registration r = new Registration(plugins, "jdk.internal.vm.Continuation"); r.register(new ContinuationPinningPlugin(config, true)); r.register(new ContinuationPinningPlugin(config, false)); } - private static void registerVirtualThreadPlugins(InvocationPlugins plugins, GraalHotSpotVMConfig config, Replacements replacements) { - Registration r = new Registration(plugins, "java.lang.VirtualThread", replacements); - if (config.supportJVMTIVThreadNotification()) { - r.register(new InvocationPlugin("notifyJvmtiStart", Receiver.class) { - @Override - public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) { - if (config.doJVMTIVirtualThreadTransitions) { - ValueNode nonNullReceiver = receiver.get(true); - inlineNativeNotifyJvmtiFunctions(config, b, targetMethod, SHAREDRUNTIME_NOTIFY_JVMTI_VTHREAD_START, nonNullReceiver, ConstantNode.forBoolean(false, b.getGraph())); - } - return true; + private static void registerVirtualThreadPlugins(InvocationPlugins plugins, GraalHotSpotVMConfig config) { + Registration r = new Registration(plugins, "java.lang.VirtualThread"); + r.register(new InvocationPlugin("notifyJvmtiStart", Receiver.class) { + @Override + public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) { + if (config.doJVMTIVirtualThreadTransitions) { + ValueNode nonNullReceiver = receiver.get(true); + inlineNativeNotifyJvmtiFunctions(config, b, targetMethod, SHAREDRUNTIME_NOTIFY_JVMTI_VTHREAD_START, nonNullReceiver, ConstantNode.forBoolean(false, b.getGraph())); } - }); - r.register(new InvocationPlugin("notifyJvmtiEnd", Receiver.class) { - @Override - public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) { - if (config.doJVMTIVirtualThreadTransitions) { - ValueNode nonNullReceiver = receiver.get(true); - inlineNativeNotifyJvmtiFunctions(config, b, targetMethod, SHAREDRUNTIME_NOTIFY_JVMTI_VTHREAD_END, nonNullReceiver, ConstantNode.forBoolean(true, b.getGraph())); - } - return true; + return true; + } + }); + r.register(new InvocationPlugin("notifyJvmtiEnd", Receiver.class) { + @Override + public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) { + if (config.doJVMTIVirtualThreadTransitions) { + ValueNode nonNullReceiver = receiver.get(true); + inlineNativeNotifyJvmtiFunctions(config, b, targetMethod, SHAREDRUNTIME_NOTIFY_JVMTI_VTHREAD_END, nonNullReceiver, ConstantNode.forBoolean(true, b.getGraph())); } - }); - r.register(new InvocationPlugin("notifyJvmtiMount", Receiver.class, boolean.class) { - @Override - public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode hide) { - if (config.doJVMTIVirtualThreadTransitions) { - ValueNode nonNullReceiver = receiver.get(true); - inlineNativeNotifyJvmtiFunctions(config, b, targetMethod, SHAREDRUNTIME_NOTIFY_JVMTI_VTHREAD_MOUNT, nonNullReceiver, hide); - } - return true; + return true; + } + }); + r.register(new InvocationPlugin("notifyJvmtiMount", Receiver.class, boolean.class) { + @Override + public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode hide) { + if (config.doJVMTIVirtualThreadTransitions) { + ValueNode nonNullReceiver = receiver.get(true); + inlineNativeNotifyJvmtiFunctions(config, b, targetMethod, SHAREDRUNTIME_NOTIFY_JVMTI_VTHREAD_MOUNT, nonNullReceiver, hide); } - }); - r.register(new InvocationPlugin("notifyJvmtiUnmount", Receiver.class, boolean.class) { - @Override - public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode hide) { - if (config.doJVMTIVirtualThreadTransitions) { - ValueNode nonNullReceiver = receiver.get(true); - inlineNativeNotifyJvmtiFunctions(config, b, targetMethod, SHAREDRUNTIME_NOTIFY_JVMTI_VTHREAD_UNMOUNT, nonNullReceiver, hide); - } - return true; + return true; + } + }); + r.register(new InvocationPlugin("notifyJvmtiUnmount", Receiver.class, boolean.class) { + @Override + public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode hide) { + if (config.doJVMTIVirtualThreadTransitions) { + ValueNode nonNullReceiver = receiver.get(true); + inlineNativeNotifyJvmtiFunctions(config, b, targetMethod, SHAREDRUNTIME_NOTIFY_JVMTI_VTHREAD_UNMOUNT, nonNullReceiver, hide); } - }); - } + return true; + } + }); r.register(new InvocationPlugin("notifyJvmtiDisableSuspend", boolean.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode enter) { if (config.doJVMTIVirtualThreadTransitions) { try (HotSpotInvocationPluginHelper helper = new HotSpotInvocationPluginHelper(b, targetMethod, config)) { - // unconditionally update the is_disable_suspend bit in current - // JavaThread - GraalError.guarantee(config.javaThreadIsDisableSuspendOffset != -1, "JavaThread::_is_disable_suspend is not exported"); + // unconditionally update the is_disable_suspend bit in current JavaThread CurrentJavaThreadNode javaThread = b.add(new CurrentJavaThreadNode(helper.getWordKind())); OffsetAddressNode address = b.add(new OffsetAddressNode(javaThread, helper.asWord(config.javaThreadIsDisableSuspendOffset))); b.add(new JavaWriteNode(JavaKind.Boolean, address, HotSpotReplacementsUtil.HOTSPOT_JAVA_THREAD_IS_DISABLE_SUSPEND, enter, BarrierType.NONE, false)); @@ -942,7 +976,7 @@ protected ResolvedJavaType getTypeAESCrypt(MetaAccessProvider metaAccess, Resolv } } - public static class ElectronicCodeBookCryptPlugin extends AESCryptDelegatePlugin { + public abstract static class ElectronicCodeBookCryptPlugin extends AESCryptDelegatePlugin { ElectronicCodeBookCryptPlugin(CryptMode mode) { super(mode, mode.isEncrypt() ? "implECBEncrypt" : "implECBDecrypt", @@ -972,7 +1006,7 @@ protected ResolvedJavaType getTypeAESCrypt(MetaAccessProvider metaAccess, Resolv } } - public static class GaloisCounterModeCryptPlugin extends AESCryptDelegatePlugin { + public abstract static class GaloisCounterModeCryptPlugin extends AESCryptDelegatePlugin { GaloisCounterModeCryptPlugin() { super(CryptMode.ENCRYPT, "implGCMCrypt0", @@ -1027,20 +1061,36 @@ protected ResolvedJavaType getTypeAESCrypt(MetaAccessProvider metaAccess, Resolv } } - private static void registerAESPlugins(InvocationPlugins plugins, GraalHotSpotVMConfig config, Replacements replacements, Architecture arch) { - Registration r = new Registration(plugins, "com.sun.crypto.provider.CipherBlockChaining", replacements); - r.registerConditional(CipherBlockChainingAESNode.isSupported(arch), new HotSpotCipherBlockChainingCryptPlugin(CryptMode.ENCRYPT)); - r.registerConditional(CipherBlockChainingAESNode.isSupported(arch), new HotSpotCipherBlockChainingCryptPlugin(CryptMode.DECRYPT)); + private static void registerAESPlugins(InvocationPlugins plugins, GraalHotSpotVMConfig config) { + Registration r = new Registration(plugins, "com.sun.crypto.provider.CipherBlockChaining"); + r.register(new HotSpotCipherBlockChainingCryptPlugin(CryptMode.ENCRYPT)); + r.register(new HotSpotCipherBlockChainingCryptPlugin(CryptMode.DECRYPT)); - r = new Registration(plugins, "com.sun.crypto.provider.ElectronicCodeBook", replacements); - r.registerConditional(config.electronicCodeBookEncrypt != 0L, new ElectronicCodeBookCryptPlugin(CryptMode.ENCRYPT)); - r.registerConditional(config.electronicCodeBookDecrypt != 0L, new ElectronicCodeBookCryptPlugin(CryptMode.DECRYPT)); + r = new Registration(plugins, "com.sun.crypto.provider.ElectronicCodeBook"); + r.register(new ElectronicCodeBookCryptPlugin(CryptMode.ENCRYPT) { + @Override + public boolean isApplicable(Architecture arch) { + return config.electronicCodeBookEncrypt != 0L; + } + }); + r.register(new ElectronicCodeBookCryptPlugin(CryptMode.DECRYPT) { + @Override + public boolean isApplicable(Architecture arch) { + return config.electronicCodeBookDecrypt != 0L; + } + }); - r = new Registration(plugins, "com.sun.crypto.provider.GaloisCounterMode", replacements); - r.registerConditional(config.galoisCounterModeCrypt != 0L, new GaloisCounterModeCryptPlugin()); + r = new Registration(plugins, "com.sun.crypto.provider.GaloisCounterMode"); + r.register(new GaloisCounterModeCryptPlugin() { + @Override + public boolean isApplicable(Architecture arch) { + return config.galoisCounterModeCrypt != 0L; + } + }); - r = new Registration(plugins, "com.sun.crypto.provider.CounterMode", replacements); - r.registerConditional(CounterModeAESNode.isSupported(arch), new CounterModeCryptPlugin() { + r = new Registration(plugins, "com.sun.crypto.provider.CounterMode"); + + r.register(new CounterModeCryptPlugin() { @Override protected boolean canApply(GraphBuilderContext b) { return b instanceof BytecodeParser || b instanceof IntrinsicGraphBuilder; @@ -1058,9 +1108,9 @@ protected ResolvedJavaType getTypeAESCrypt(MetaAccessProvider metaAccess, Resolv }); } - private static void registerAdler32Plugins(InvocationPlugins plugins, GraalHotSpotVMConfig config, Replacements replacements) { - Registration r = new Registration(plugins, "java.util.zip.Adler32", replacements); - r.registerConditional(config.updateBytesAdler32 != 0L, new InlineOnlyInvocationPlugin("updateBytes", int.class, byte[].class, int.class, int.class) { + private static void registerAdler32Plugins(InvocationPlugins plugins, GraalHotSpotVMConfig config) { + Registration r = new Registration(plugins, "java.util.zip.Adler32"); + r.register(new ConditionalInvocationPlugin("updateBytes", int.class, byte[].class, int.class, int.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode adler, ValueNode src, ValueNode off, ValueNode len) { try (InvocationPluginHelper helper = new InvocationPluginHelper(b, targetMethod)) { @@ -1070,8 +1120,13 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec } return true; } + + @Override + public boolean isApplicable(Architecture arch) { + return config.updateBytesAdler32 != 0L; + } }); - r.registerConditional(config.updateBytesAdler32 != 0L, new InlineOnlyInvocationPlugin("updateByteBuffer", int.class, long.class, int.class, int.class) { + r.register(new ConditionalInvocationPlugin("updateByteBuffer", int.class, long.class, int.class, int.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode adler, ValueNode addr, ValueNode off, ValueNode len) { ValueNode buff = b.add(new ComputeObjectAddressNode(addr, off)); @@ -1079,12 +1134,17 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec b.addPush(JavaKind.Int, call); return true; } + + @Override + public boolean isApplicable(Architecture arch) { + return config.updateBytesAdler32 != 0L; + } }); } - private static void registerBigIntegerPlugins(InvocationPlugins plugins, GraalHotSpotVMConfig config, Replacements replacements) { - Registration r = new Registration(plugins, BigInteger.class, replacements); - r.registerConditional(config.montgomeryMultiply != 0L, new InvocationPlugin("implMontgomeryMultiply", int[].class, int[].class, int[].class, int.class, long.class, int[].class) { + private static void registerBigIntegerPlugins(InvocationPlugins plugins, GraalHotSpotVMConfig config) { + Registration r = new Registration(plugins, BigInteger.class); + r.register(new ConditionalInvocationPlugin("implMontgomeryMultiply", int[].class, int[].class, int[].class, int.class, long.class, int[].class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode a, ValueNode bObject, ValueNode n, ValueNode len, ValueNode inv, @@ -1098,8 +1158,13 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec } return true; } + + @Override + public boolean isApplicable(Architecture arch) { + return config.montgomeryMultiply != 0L; + } }); - r.registerConditional(config.montgomerySquare != 0L, new InvocationPlugin("implMontgomerySquare", int[].class, int[].class, int.class, long.class, int[].class) { + r.register(new ConditionalInvocationPlugin("implMontgomerySquare", int[].class, int[].class, int.class, long.class, int[].class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode a, ValueNode n, ValueNode len, ValueNode inv, ValueNode product) { try (InvocationPluginHelper helper = new InvocationPluginHelper(b, targetMethod)) { @@ -1111,8 +1176,13 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec } return true; } + + @Override + public boolean isApplicable(Architecture arch) { + return config.montgomerySquare != 0L; + } }); - r.registerConditional(config.bigIntegerLeftShiftWorker != 0L, new InvocationPlugin("shiftLeftImplWorker", int[].class, int[].class, int.class, int.class, int.class) { + r.register(new ConditionalInvocationPlugin("shiftLeftImplWorker", int[].class, int[].class, int.class, int.class, int.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode newArr, ValueNode oldArr, ValueNode newIdx, ValueNode shiftCount, ValueNode numIter) { @@ -1122,8 +1192,13 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec } return true; } + + @Override + public boolean isApplicable(Architecture arch) { + return config.bigIntegerLeftShiftWorker != 0L; + } }); - r.registerConditional(config.bigIntegerRightShiftWorker != 0L, new InvocationPlugin("shiftRightImplWorker", int[].class, int[].class, int.class, int.class, int.class) { + r.register(new ConditionalInvocationPlugin("shiftRightImplWorker", int[].class, int[].class, int.class, int.class, int.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode newArr, ValueNode oldArr, ValueNode newIdx, ValueNode shiftCount, ValueNode numIter) { @@ -1133,10 +1208,15 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec } return true; } + + @Override + public boolean isApplicable(Architecture arch) { + return config.bigIntegerRightShiftWorker != 0L; + } }); } - private static void registerSHAPlugins(InvocationPlugins plugins, GraalHotSpotVMConfig config, Replacements replacements) { + private static void registerSHAPlugins(InvocationPlugins plugins, GraalHotSpotVMConfig config) { boolean useMD5 = config.md5ImplCompressMultiBlock != 0L; boolean useSha1 = config.sha1ImplCompressMultiBlock != 0L; boolean useSha256 = config.sha256ImplCompressMultiBlock != 0L; @@ -1144,30 +1224,32 @@ private static void registerSHAPlugins(InvocationPlugins plugins, GraalHotSpotVM boolean useSha3 = config.sha3ImplCompressMultiBlock != 0L; boolean implCompressMultiBlock0Enabled = useMD5 || useSha1 || useSha256 || useSha512 || useSha3; - Registration r = new Registration(plugins, "sun.security.provider.DigestBase", replacements); - r.registerConditional(implCompressMultiBlock0Enabled, new SnippetSubstitutionInvocationPlugin<>(DigestBaseSnippets.Templates.class, - "implCompressMultiBlock0", Receiver.class, byte[].class, int.class, int.class) { - @Override - protected Object[] getConstantArguments(ResolvedJavaMethod targetMethod) { - ResolvedJavaType declaringClass = targetMethod.getDeclaringClass(); - return new Object[]{ - declaringClass, - HotSpotReplacementsUtil.getType(declaringClass, "Lsun/security/provider/MD5;"), - HotSpotReplacementsUtil.getType(declaringClass, "Lsun/security/provider/SHA;"), - HotSpotReplacementsUtil.getType(declaringClass, "Lsun/security/provider/SHA2;"), - HotSpotReplacementsUtil.getType(declaringClass, "Lsun/security/provider/SHA5;"), - HotSpotReplacementsUtil.getType(declaringClass, "Lsun/security/provider/SHA3;") - }; - } + Registration r = new Registration(plugins, "sun.security.provider.DigestBase"); + if (implCompressMultiBlock0Enabled) { + r.register(new SnippetSubstitutionInvocationPlugin<>(DigestBaseSnippets.Templates.class, + "implCompressMultiBlock0", Receiver.class, byte[].class, int.class, int.class) { + @Override + protected Object[] getConstantArguments(ResolvedJavaMethod targetMethod) { + ResolvedJavaType declaringClass = targetMethod.getDeclaringClass(); + return new Object[]{ + declaringClass, + HotSpotReplacementsUtil.getType(declaringClass, "Lsun/security/provider/MD5;"), + HotSpotReplacementsUtil.getType(declaringClass, "Lsun/security/provider/SHA;"), + HotSpotReplacementsUtil.getType(declaringClass, "Lsun/security/provider/SHA2;"), + HotSpotReplacementsUtil.getType(declaringClass, "Lsun/security/provider/SHA5;"), + HotSpotReplacementsUtil.getType(declaringClass, "Lsun/security/provider/SHA3;") + }; + } - @Override - public SnippetTemplate.SnippetInfo getSnippet(DigestBaseSnippets.Templates templates) { - return templates.implCompressMultiBlock0; - } - }); + @Override + public SnippetTemplate.SnippetInfo getSnippet(DigestBaseSnippets.Templates templates) { + return templates.implCompressMultiBlock0; + } + }); + } - r = new Registration(plugins, "sun.security.provider.SHA3Parallel", replacements); - r.registerConditional(config.stubDoubleKeccak != 0L, new InvocationPlugin("doubleKeccak", long[].class, long[].class) { + r = new Registration(plugins, "sun.security.provider.SHA3Parallel"); + r.register(new ConditionalInvocationPlugin("doubleKeccak", long[].class, long[].class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode lanes0, ValueNode lanes1) { try (InvocationPluginHelper helper = new InvocationPluginHelper(b, targetMethod)) { @@ -1182,12 +1264,17 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec return true; } } + + @Override + public boolean isApplicable(Architecture arch) { + return config.stubDoubleKeccak != 0L; + } }); } - private static void registerMLPlugins(InvocationPlugins plugins, GraalHotSpotVMConfig config, Replacements replacements) { - Registration r = new Registration(plugins, "sun.security.provider.ML_DSA", replacements); - r.registerConditional(config.stubDilithiumAlmostNtt != 0L, new InvocationPlugin("implDilithiumAlmostNtt", int[].class, int[].class) { + private static void registerMLPlugins(InvocationPlugins plugins, GraalHotSpotVMConfig config) { + Registration r = new Registration(plugins, "sun.security.provider.ML_DSA"); + r.register(new ConditionalInvocationPlugin("implDilithiumAlmostNtt", int[].class, int[].class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode coeffs, ValueNode zetas) { try (InvocationPluginHelper helper = new InvocationPluginHelper(b, targetMethod)) { @@ -1202,8 +1289,13 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec return true; } } + + @Override + public boolean isApplicable(Architecture arch) { + return config.stubDilithiumAlmostNtt != 0L; + } }); - r.registerConditional(config.stubDilithiumAlmostInverseNtt != 0L, new InvocationPlugin("implDilithiumAlmostInverseNtt", int[].class, int[].class) { + r.register(new ConditionalInvocationPlugin("implDilithiumAlmostInverseNtt", int[].class, int[].class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode coeffs, ValueNode zetas) { try (InvocationPluginHelper helper = new InvocationPluginHelper(b, targetMethod)) { @@ -1218,8 +1310,13 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec return true; } } + + @Override + public boolean isApplicable(Architecture arch) { + return config.stubDilithiumAlmostInverseNtt != 0L; + } }); - r.registerConditional(config.stubDilithiumNttMult != 0L, new InvocationPlugin("implDilithiumNttMult", int[].class, int[].class, int[].class) { + r.register(new ConditionalInvocationPlugin("implDilithiumNttMult", int[].class, int[].class, int[].class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode product, ValueNode coeffs1, ValueNode coeffs2) { try (InvocationPluginHelper helper = new InvocationPluginHelper(b, targetMethod)) { @@ -1236,8 +1333,13 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec return true; } } + + @Override + public boolean isApplicable(Architecture arch) { + return config.stubDilithiumNttMult != 0L; + } }); - r.registerConditional(config.stubDilithiumMontMulByConstant != 0L, new InvocationPlugin("implDilithiumMontMulByConstant", int[].class, int.class) { + r.register(new ConditionalInvocationPlugin("implDilithiumMontMulByConstant", int[].class, int.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode coeffs, ValueNode constant) { try (InvocationPluginHelper helper = new InvocationPluginHelper(b, targetMethod)) { @@ -1250,8 +1352,13 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec return true; } } + + @Override + public boolean isApplicable(Architecture arch) { + return config.stubDilithiumMontMulByConstant != 0L; + } }); - r.registerConditional(config.stubDilithiumDecomposePoly != 0L, new InvocationPlugin("implDilithiumDecomposePoly", int[].class, int[].class, int[].class, int.class, int.class) { + r.register(new ConditionalInvocationPlugin("implDilithiumDecomposePoly", int[].class, int[].class, int[].class, int.class, int.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode input, ValueNode lowPart, ValueNode highPart, ValueNode twoGamma2, ValueNode multiplier) { @@ -1269,10 +1376,15 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec return true; } } + + @Override + public boolean isApplicable(Architecture arch) { + return config.stubDilithiumDecomposePoly != 0L; + } }); - r = new Registration(plugins, "com.sun.crypto.provider.ML_KEM", replacements); - r.registerConditional(config.stubKyberNtt != 0L, new InvocationPlugin("implKyberNtt", short[].class, short[].class) { + r = new Registration(plugins, "com.sun.crypto.provider.ML_KEM"); + r.register(new ConditionalInvocationPlugin("implKyberNtt", short[].class, short[].class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode poly, ValueNode zetas) { try (InvocationPluginHelper helper = new InvocationPluginHelper(b, targetMethod)) { @@ -1287,8 +1399,13 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec return true; } } + + @Override + public boolean isApplicable(Architecture arch) { + return config.stubKyberNtt != 0L; + } }); - r.registerConditional(config.stubKyberInverseNtt != 0L, new InvocationPlugin("implKyberInverseNtt", short[].class, short[].class) { + r.register(new ConditionalInvocationPlugin("implKyberInverseNtt", short[].class, short[].class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode poly, ValueNode zetas) { try (InvocationPluginHelper helper = new InvocationPluginHelper(b, targetMethod)) { @@ -1303,8 +1420,13 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec return true; } } + + @Override + public boolean isApplicable(Architecture arch) { + return config.stubKyberInverseNtt != 0L; + } }); - r.registerConditional(config.stubKyberNttMult != 0L, new InvocationPlugin("implKyberNttMult", short[].class, short[].class, short[].class, short[].class) { + r.register(new ConditionalInvocationPlugin("implKyberNttMult", short[].class, short[].class, short[].class, short[].class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode result, ValueNode ntta, ValueNode nttb, ValueNode zetas) { try (InvocationPluginHelper helper = new InvocationPluginHelper(b, targetMethod)) { @@ -1323,8 +1445,13 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec return true; } } + + @Override + public boolean isApplicable(Architecture arch) { + return config.stubKyberNttMult != 0L; + } }); - r.registerConditional(config.stubKyberAddPoly2 != 0L, new InvocationPlugin("implKyberAddPoly", short[].class, short[].class, short[].class) { + r.register(new ConditionalInvocationPlugin("implKyberAddPoly", short[].class, short[].class, short[].class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode result, ValueNode aIn, ValueNode bIn) { try (InvocationPluginHelper helper = new InvocationPluginHelper(b, targetMethod)) { @@ -1341,8 +1468,13 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec return true; } } + + @Override + public boolean isApplicable(Architecture arch) { + return config.stubKyberAddPoly2 != 0L; + } }); - r.registerConditional(config.stubKyberAddPoly3 != 0L, new InvocationPlugin("implKyberAddPoly", short[].class, short[].class, short[].class, short[].class) { + r.register(new ConditionalInvocationPlugin("implKyberAddPoly", short[].class, short[].class, short[].class, short[].class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode result, ValueNode aIn, ValueNode bIn, ValueNode cIn) { try (InvocationPluginHelper helper = new InvocationPluginHelper(b, targetMethod)) { @@ -1361,8 +1493,13 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec return true; } } + + @Override + public boolean isApplicable(Architecture arch) { + return config.stubKyberAddPoly3 != 0L; + } }); - r.registerConditional(config.stubKyber12To16 != 0L, new InvocationPlugin("implKyber12To16", byte[].class, int.class, short[].class, int.class) { + r.register(new ConditionalInvocationPlugin("implKyber12To16", byte[].class, int.class, short[].class, int.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode condensed, ValueNode index, ValueNode parsed, ValueNode parsedLength) { try (InvocationPluginHelper helper = new InvocationPluginHelper(b, targetMethod)) { @@ -1377,8 +1514,13 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec return true; } } + + @Override + public boolean isApplicable(Architecture arch) { + return config.stubKyber12To16 != 0L; + } }); - r.registerConditional(config.stubKyberBarrettReduce != 0L, new InvocationPlugin("implKyberBarrettReduce", short[].class) { + r.register(new ConditionalInvocationPlugin("implKyberBarrettReduce", short[].class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode coeffs) { try (InvocationPluginHelper helper = new InvocationPluginHelper(b, targetMethod)) { @@ -1390,12 +1532,17 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec return true; } } + + @Override + public boolean isApplicable(Architecture arch) { + return config.stubKyberBarrettReduce != 0L; + } }); } - private static void registerBase64Plugins(InvocationPlugins plugins, GraalHotSpotVMConfig config, MetaAccessProvider metaAccess, Replacements replacements) { - Registration r = new Registration(plugins, "java.util.Base64$Encoder", replacements); - r.registerConditional(config.base64EncodeBlock != 0L, new InvocationPlugin("encodeBlock", Receiver.class, byte[].class, int.class, int.class, byte[].class, int.class, boolean.class) { + private static void registerBase64Plugins(InvocationPlugins plugins, GraalHotSpotVMConfig config, MetaAccessProvider metaAccess) { + Registration r = new Registration(plugins, "java.util.Base64$Encoder"); + r.register(new ConditionalInvocationPlugin("encodeBlock", Receiver.class, byte[].class, int.class, int.class, byte[].class, int.class, boolean.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode src, ValueNode sp, ValueNode sl, ValueNode dst, ValueNode dp, ValueNode isURL) { @@ -1409,31 +1556,40 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec b.add(new ForeignCallNode(BASE64_ENCODE_BLOCK, srcAddress, sp, sl, dstAddress, dp, isURL)); return true; } + + @Override + public boolean isApplicable(Architecture arch) { + return config.base64EncodeBlock != 0L; + } }); - r = new Registration(plugins, "java.util.Base64$Decoder", replacements); - if (config.base64DecodeBlock != 0L) { - r.register(new InvocationPlugin("decodeBlock", Receiver.class, byte[].class, int.class, int.class, byte[].class, int.class, boolean.class, boolean.class) { - @Override - public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode src, - ValueNode sp, ValueNode sl, ValueNode dst, ValueNode dp, ValueNode isURL, ValueNode isMime) { - if (receiver != null) { - // Side effect of call below is to add a receiver null check if required - receiver.get(true); - } - int byteArrayBaseOffset = metaAccess.getArrayBaseOffset(JavaKind.Byte); - ComputeObjectAddressNode srcAddress = b.add(new ComputeObjectAddressNode(src, ConstantNode.forInt(byteArrayBaseOffset))); - ComputeObjectAddressNode dstAddress = b.add(new ComputeObjectAddressNode(dst, ConstantNode.forInt(byteArrayBaseOffset))); - ForeignCallNode call = new ForeignCallNode(BASE64_DECODE_BLOCK, srcAddress, sp, sl, dstAddress, dp, isURL, isMime); - b.addPush(JavaKind.Int, call); - return true; + r = new Registration(plugins, "java.util.Base64$Decoder"); + r.register(new ConditionalInvocationPlugin("decodeBlock", Receiver.class, byte[].class, int.class, int.class, byte[].class, int.class, boolean.class, boolean.class) { + @Override + public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode src, + ValueNode sp, ValueNode sl, ValueNode dst, ValueNode dp, ValueNode isURL, ValueNode isMime) { + if (receiver != null) { + // Side effect of call below is to add a receiver null check if required + receiver.get(true); } - }); - } + int byteArrayBaseOffset = metaAccess.getArrayBaseOffset(JavaKind.Byte); + ComputeObjectAddressNode srcAddress = b.add(new ComputeObjectAddressNode(src, ConstantNode.forInt(byteArrayBaseOffset))); + ComputeObjectAddressNode dstAddress = b.add(new ComputeObjectAddressNode(dst, ConstantNode.forInt(byteArrayBaseOffset))); + ForeignCallNode call = new ForeignCallNode(BASE64_DECODE_BLOCK, srcAddress, sp, sl, dstAddress, dp, isURL, isMime); + b.addPush(JavaKind.Int, call); + return true; + } + + @Override + public boolean isApplicable(Architecture arch) { + return config.base64DecodeBlock != 0L; + } + }); } - private static void registerCRC32Plugins(InvocationPlugins plugins, GraalHotSpotVMConfig config, Replacements replacements) { - Registration r = new Registration(plugins, CRC32.class, replacements); - r.registerConditional(config.updateBytesCRC32Stub != 0L && config.crcTableAddress != 0L, new InvocationPlugin("update", int.class, int.class) { + private static void registerCRC32Plugins(InvocationPlugins plugins, GraalHotSpotVMConfig config) { + Registration r = new Registration(plugins, CRC32.class); + + r.register(new ConditionalInvocationPlugin("update", int.class, int.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode crc, ValueNode arg) { final ValueNode crcTableRawAddress = ConstantNode.forLong(config.crcTableAddress); @@ -1446,8 +1602,13 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec b.addPush(JavaKind.Int, new XorNode(result, ConstantNode.forInt(-1))); return true; } + + @Override + public boolean isApplicable(Architecture arch) { + return config.updateBytesCRC32Stub != 0L && config.crcTableAddress != 0L; + } }); - r.registerConditional(config.updateBytesCRC32Stub != 0L, new InvocationPlugin("updateBytes0", int.class, byte[].class, int.class, int.class) { + r.register(new ConditionalInvocationPlugin("updateBytes0", int.class, byte[].class, int.class, int.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode crc, ValueNode buf, ValueNode off, ValueNode len) { int byteArrayBaseOffset = b.getMetaAccess().getArrayBaseOffset(JavaKind.Byte); @@ -1455,20 +1616,30 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec b.addPush(JavaKind.Int, new ForeignCallNode(UPDATE_BYTES_CRC32, crc, bufAddr, len)); return true; } + + @Override + public boolean isApplicable(Architecture arch) { + return config.updateBytesCRC32Stub != 0L; + } }); - r.registerConditional(config.updateBytesCRC32Stub != 0L, new InvocationPlugin("updateByteBuffer0", int.class, long.class, int.class, int.class) { + r.register(new ConditionalInvocationPlugin("updateByteBuffer0", int.class, long.class, int.class, int.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode crc, ValueNode addr, ValueNode off, ValueNode len) { ValueNode bufAddr = b.add(new AddNode(addr, new SignExtendNode(off, 32, 64))); b.addPush(JavaKind.Int, new ForeignCallNode(UPDATE_BYTES_CRC32, crc, bufAddr, len)); return true; } + + @Override + public boolean isApplicable(Architecture arch) { + return config.updateBytesCRC32Stub != 0L; + } }); } - private static void registerCRC32CPlugins(InvocationPlugins plugins, GraalHotSpotVMConfig config, Replacements replacements) { - Registration r = new Registration(plugins, "java.util.zip.CRC32C", replacements); - r.registerConditional(config.updateBytesCRC32C != 0L, new InvocationPlugin("updateBytes", int.class, byte[].class, int.class, int.class) { + private static void registerCRC32CPlugins(InvocationPlugins plugins, GraalHotSpotVMConfig config) { + Registration r = new Registration(plugins, "java.util.zip.CRC32C"); + r.register(new ConditionalInvocationPlugin("updateBytes", int.class, byte[].class, int.class, int.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode crc, ValueNode buf, ValueNode off, ValueNode end) { int byteArrayBaseOffset = b.getMetaAccess().getArrayBaseOffset(JavaKind.Byte); @@ -1476,22 +1647,33 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec b.addPush(JavaKind.Int, new ForeignCallNode(UPDATE_BYTES_CRC32C, crc, bufAddr, new SubNode(end, off))); return true; } + + @Override + public boolean isApplicable(Architecture arch) { + return config.updateBytesCRC32C != 0L; + } }); - r.registerConditional(config.updateBytesCRC32C != 0L, new InvocationPlugin("updateDirectByteBuffer", int.class, long.class, int.class, int.class) { + r.register(new ConditionalInvocationPlugin("updateDirectByteBuffer", int.class, long.class, int.class, int.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode crc, ValueNode addr, ValueNode off, ValueNode end) { ValueNode bufAddr = b.add(new AddNode(addr, new SignExtendNode(off, 32, 64))); b.addPush(JavaKind.Int, new ForeignCallNode(UPDATE_BYTES_CRC32C, crc, bufAddr, new SubNode(end, off))); return true; } + + @Override + public boolean isApplicable(Architecture arch) { + return config.updateBytesCRC32C != 0L; + } }); } - private static void registerPoly1305Plugins(InvocationPlugins plugins, GraalHotSpotVMConfig config, Replacements replacements) { - Registration r = new Registration(plugins, "com.sun.crypto.provider.Poly1305", replacements); - r.registerConditional(config.poly1305ProcessBlocks != 0L, new InvocationPlugin("processMultipleBlocks", Receiver.class, byte[].class, int.class, int.class, long[].class, long[].class) { + private static void registerPoly1305Plugins(InvocationPlugins plugins, GraalHotSpotVMConfig config) { + Registration r = new Registration(plugins, "com.sun.crypto.provider.Poly1305"); + r.register(new ConditionalInvocationPlugin("processMultipleBlocks", Receiver.class, byte[].class, int.class, int.class, long[].class, long[].class) { @Override - public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode input, ValueNode offset, ValueNode length, ValueNode aLimbs, ValueNode rLimbs) { + public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode input, ValueNode offset, ValueNode length, ValueNode aLimbs, + ValueNode rLimbs) { try (InvocationPluginHelper helper = new InvocationPluginHelper(b, targetMethod)) { receiver.get(true); ValueNode inputNotNull = b.nullCheckedValue(input); @@ -1506,12 +1688,17 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec } return true; } + + @Override + public boolean isApplicable(Architecture arch) { + return config.poly1305ProcessBlocks != 0L; + } }); } - private static void registerChaCha20Plugins(InvocationPlugins plugins, GraalHotSpotVMConfig config, Replacements replacements) { - Registration r = new Registration(plugins, "com.sun.crypto.provider.ChaCha20Cipher", replacements); - r.registerConditional(config.chacha20Block != 0L, new InvocationPlugin("implChaCha20Block", int[].class, byte[].class) { + private static void registerChaCha20Plugins(InvocationPlugins plugins, GraalHotSpotVMConfig config) { + Registration r = new Registration(plugins, "com.sun.crypto.provider.ChaCha20Cipher"); + r.register(new ConditionalInvocationPlugin("implChaCha20Block", int[].class, byte[].class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode initState, ValueNode result) { try (InvocationPluginHelper helper = new InvocationPluginHelper(b, targetMethod)) { @@ -1526,12 +1713,17 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec } return true; } + + @Override + public boolean isApplicable(Architecture arch) { + return config.chacha20Block != 0L; + } }); } - private static void registerP256Plugins(InvocationPlugins plugins, GraalHotSpotVMConfig config, Replacements replacements) { - Registration r = new Registration(plugins, "sun.security.util.math.intpoly.MontgomeryIntegerPolynomialP256", replacements); - r.registerConditional(config.intpolyMontgomeryMultP256 != 0L, new InvocationPlugin("mult", Receiver.class, long[].class, long[].class, long[].class) { + private static void registerP256Plugins(InvocationPlugins plugins, GraalHotSpotVMConfig config) { + Registration r = new Registration(plugins, "sun.security.util.math.intpoly.MontgomeryIntegerPolynomialP256"); + r.register(new ConditionalInvocationPlugin("mult", Receiver.class, long[].class, long[].class, long[].class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode aIn, ValueNode bIn, ValueNode rOut) { try (InvocationPluginHelper helper = new InvocationPluginHelper(b, targetMethod)) { @@ -1548,10 +1740,15 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec } return true; } + + @Override + public boolean isApplicable(Architecture arch) { + return config.intpolyMontgomeryMultP256 != 0L; + } }); - r = new Registration(plugins, "sun.security.util.math.intpoly.IntegerPolynomial", replacements); - r.registerConditional(config.intpolyAssign != 0L, new InvocationPlugin("conditionalAssign", int.class, long[].class, long[].class) { + r = new Registration(plugins, "sun.security.util.math.intpoly.IntegerPolynomial"); + r.register(new ConditionalInvocationPlugin("conditionalAssign", int.class, long[].class, long[].class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode set, ValueNode aIn, ValueNode bIn) { try (InvocationPluginHelper helper = new InvocationPluginHelper(b, targetMethod)) { @@ -1567,21 +1764,17 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec } return true; } - }); - } - private static void registerArraysSupportPlugins(InvocationPlugins plugins, Replacements replacements, Architecture arch) { - Registration r = new Registration(plugins, "jdk.internal.util.ArraysSupport", replacements); - r.registerConditional(VectorizedMismatchNode.isSupported(arch), new InvocationPlugin("vectorizedMismatch", Object.class, long.class, Object.class, long.class, int.class, int.class) { @Override - public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, - ValueNode aObject, ValueNode aOffset, ValueNode bObject, ValueNode bOffset, ValueNode length, ValueNode log2ArrayIndexScale) { - ValueNode aAddr = b.add(new ComputeObjectAddressNode(aObject, aOffset)); - ValueNode bAddr = b.add(new ComputeObjectAddressNode(bObject, bOffset)); - b.addPush(JavaKind.Int, new VectorizedMismatchNode(aAddr, bAddr, length, log2ArrayIndexScale)); - return true; + public boolean isApplicable(Architecture arch) { + return config.intpolyAssign != 0L; } + }); + } + private static void registerArraysSupportPlugins(InvocationPlugins plugins, Architecture arch) { + Registration r = new Registration(plugins, "jdk.internal.util.ArraysSupport"); + r.register(new StandardGraphBuilderPlugins.VectorizedMismatchInvocationPlugin() { @Override public boolean isGraalOnly() { // On AArch64 HotSpot, this intrinsic is not implemented and @@ -1589,7 +1782,7 @@ public boolean isGraalOnly() { return arch instanceof AArch64; } }); - r.registerConditional(VectorizedHashCodeNode.isSupported(arch), new StandardGraphBuilderPlugins.VectorizedHashCodeInvocationPlugin("vectorizedHashCode") { + r.register(new StandardGraphBuilderPlugins.VectorizedHashCodeInvocationPlugin() { @Override public boolean isGraalOnly() { // On AArch64 HotSpot, this intrinsic is not implemented and @@ -1599,8 +1792,8 @@ public boolean isGraalOnly() { }); } - private static void registerReferencePlugins(InvocationPlugins plugins, Replacements replacements) { - Registration r = new Registration(plugins, Reference.class, replacements); + private static void registerReferencePlugins(InvocationPlugins plugins) { + Registration r = new Registration(plugins, Reference.class); r.register(new ReachabilityFencePlugin() { @Override protected boolean useExplicitReachabilityFence(GraphBuilderContext b) { @@ -1634,7 +1827,7 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec } } }); - r = new Registration(plugins, PhantomReference.class, replacements); + r = new Registration(plugins, PhantomReference.class); r.register(new InlineOnlyInvocationPlugin("refersTo0", Receiver.class, Object.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode o) { @@ -1664,8 +1857,8 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec }); } - private static void registerInstrumentationImplPlugins(InvocationPlugins plugins, GraalHotSpotVMConfig config, Replacements replacements) { - Registration r = new Registration(plugins, "sun.instrument.InstrumentationImpl", replacements); + private static void registerInstrumentationImplPlugins(InvocationPlugins plugins, GraalHotSpotVMConfig config) { + Registration r = new Registration(plugins, "sun.instrument.InstrumentationImpl"); r.register(new InlineOnlyInvocationPlugin("getObjectSize0", Receiver.class, long.class, Object.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode nativeAgent, ValueNode objectToSize) { @@ -1728,9 +1921,9 @@ private static boolean isSimdSortSupported(Architecture arch, GraalHotSpotVMConf return true; } - private static void registerDualPivotQuicksortPlugins(InvocationPlugins plugins, GraalHotSpotVMConfig config, Replacements replacements, Architecture arch) { - Registration r = new Registration(plugins, "java.util.DualPivotQuicksort", replacements); - r.registerConditional(config.stubArraySort != 0L, new InlineOnlyInvocationPlugin("sort", Class.class, Object.class, long.class, int.class, int.class, + private static void registerDualPivotQuicksortPlugins(InvocationPlugins plugins, GraalHotSpotVMConfig config, Architecture architecture) { + Registration r = new Registration(plugins, "java.util.DualPivotQuicksort"); + r.register(new ConditionalInvocationPlugin("sort", Class.class, Object.class, long.class, int.class, int.class, new InvocationPlugins.OptionalLazySymbol("java.util.DualPivotQuicksort$SortOperation")) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode elemType, ValueNode array, @@ -1742,9 +1935,10 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec case Double -> T_DOUBLE; case Int -> T_INT; case Long -> T_LONG; - default -> throw GraalError.shouldNotReachHere("Unexpected element type " + type.toJavaName()); + default -> + throw GraalError.shouldNotReachHere("Unexpected element type " + type.toJavaName()); }; - if (isSimdSortSupported(arch, config, jvmType)) { + if (isSimdSortSupported(architecture, config, jvmType)) { ValueNode arrayNonNull = b.nullCheckedValue(array); ValueNode arrayStart = b.add(new ComputeObjectAddressNode(arrayNonNull, offset)); b.add(new ForeignCallNode(ARRAY_SORT, arrayStart, ConstantNode.forInt(jvmType), low, high)); @@ -1753,8 +1947,13 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec } return false; } + + @Override + public boolean isApplicable(Architecture arch) { + return config.stubArraySort != 0L; + } }); - r.registerConditional(config.stubArrayPartition != 0L, new InlineOnlyInvocationPlugin("partition", Class.class, Object.class, long.class, int.class, int.class, int.class, int.class, + r.register(new ConditionalInvocationPlugin("partition", Class.class, Object.class, long.class, int.class, int.class, int.class, int.class, new InvocationPlugins.OptionalLazySymbol("java.util.DualPivotQuicksort$PartitionOperation")) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode elemType, ValueNode array, @@ -1767,9 +1966,10 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec case Double -> T_DOUBLE; case Int -> T_INT; case Long -> T_LONG; - default -> throw GraalError.shouldNotReachHere("Unexpected element type " + type.toJavaName()); + default -> + throw GraalError.shouldNotReachHere("Unexpected element type " + type.toJavaName()); }; - if (isSimdSortSupported(arch, config, jvmType)) { + if (isSimdSortSupported(architecture, config, jvmType)) { ValueNode arrayNonNull = b.nullCheckedValue(array); ValueNode arrayStart = b.add(new ComputeObjectAddressNode(arrayNonNull, offset)); ValueNode pivotIndices = b.append(new NewArrayNode(b.getMetaAccess().lookupJavaType(Integer.TYPE), ConstantNode.forInt(2), false)); @@ -1784,6 +1984,11 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec return false; } } + + @Override + public boolean isApplicable(Architecture arch) { + return config.stubArrayPartition != 0L; + } }); } } diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/meta/HotSpotHostForeignCallsProvider.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/meta/HotSpotHostForeignCallsProvider.java index f8cc456c57dc..e0119bd19363 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/meta/HotSpotHostForeignCallsProvider.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/meta/HotSpotHostForeignCallsProvider.java @@ -490,12 +490,10 @@ public void initialize(HotSpotProviders providers, OptionValues options) { linkForeignCall(options, providers, NEW_MULTI_ARRAY_OR_NULL, c.newMultiArrayOrNullAddress, PREPEND_THREAD); linkForeignCall(options, providers, DYNAMIC_NEW_INSTANCE_OR_NULL, c.dynamicNewInstanceOrNullAddress, PREPEND_THREAD); - if (c.supportJVMTIVThreadNotification()) { - linkForeignCall(options, providers, SHAREDRUNTIME_NOTIFY_JVMTI_VTHREAD_START, c.jvmtiVThreadStart, DONT_PREPEND_THREAD); - linkForeignCall(options, providers, SHAREDRUNTIME_NOTIFY_JVMTI_VTHREAD_END, c.jvmtiVThreadEnd, DONT_PREPEND_THREAD); - linkForeignCall(options, providers, SHAREDRUNTIME_NOTIFY_JVMTI_VTHREAD_MOUNT, c.jvmtiVThreadMount, DONT_PREPEND_THREAD); - linkForeignCall(options, providers, SHAREDRUNTIME_NOTIFY_JVMTI_VTHREAD_UNMOUNT, c.jvmtiVThreadUnmount, DONT_PREPEND_THREAD); - } + linkForeignCall(options, providers, SHAREDRUNTIME_NOTIFY_JVMTI_VTHREAD_START, c.jvmtiVThreadStart, DONT_PREPEND_THREAD); + linkForeignCall(options, providers, SHAREDRUNTIME_NOTIFY_JVMTI_VTHREAD_END, c.jvmtiVThreadEnd, DONT_PREPEND_THREAD); + linkForeignCall(options, providers, SHAREDRUNTIME_NOTIFY_JVMTI_VTHREAD_MOUNT, c.jvmtiVThreadMount, DONT_PREPEND_THREAD); + linkForeignCall(options, providers, SHAREDRUNTIME_NOTIFY_JVMTI_VTHREAD_UNMOUNT, c.jvmtiVThreadUnmount, DONT_PREPEND_THREAD); link(new ExceptionHandlerStub(options, providers, foreignCalls.get(EXCEPTION_HANDLER.getSignature()))); link(new UnwindExceptionToCallerStub(options, providers, diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/meta/HotSpotInvocationPluginProvider.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/meta/HotSpotInvocationPluginProvider.java index 229ba91b7835..11061005358d 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/meta/HotSpotInvocationPluginProvider.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/meta/HotSpotInvocationPluginProvider.java @@ -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 @@ -25,7 +25,6 @@ package jdk.graal.compiler.hotspot.meta; import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugins; -import jdk.graal.compiler.nodes.spi.Replacements; import jdk.graal.compiler.serviceprovider.LibGraalService; import jdk.graal.compiler.serviceprovider.ServiceProvider; @@ -37,5 +36,5 @@ */ @LibGraalService public interface HotSpotInvocationPluginProvider { - void registerInvocationPlugins(Architecture architecture, InvocationPlugins plugins, Replacements replacements); + void registerInvocationPlugins(Architecture architecture, InvocationPlugins plugins); } diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/riscv64/RISCV64HotSpotBackendFactory.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/riscv64/RISCV64HotSpotBackendFactory.java index 38a4771d6097..4287b698acf3 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/riscv64/RISCV64HotSpotBackendFactory.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/riscv64/RISCV64HotSpotBackendFactory.java @@ -135,7 +135,7 @@ protected void run(StructuredGraph graph, CoreProviders context) { @Override protected HotSpotSuitesProvider createSuites(GraalHotSpotVMConfig config, HotSpotGraalRuntimeProvider runtime, CompilerConfiguration compilerConfiguration, Plugins plugins, - HotSpotRegistersProvider registers, HotSpotReplacementsImpl replacements, OptionValues options) { + HotSpotRegistersProvider registers, OptionValues options) { DefaultSuitesCreator suitesCreator = new RISCV64HotSpotSuitesCreator(compilerConfiguration, plugins); BasePhase addressLoweringPhase = new EmptyAddressLoweringPhase(); return new AddressLoweringHotSpotSuitesProvider(suitesCreator, config, runtime, addressLoweringPhase); diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/lir/gen/LIRGeneratorTool.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/lir/gen/LIRGeneratorTool.java index ccaf4735817a..98a12e90f19e 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/lir/gen/LIRGeneratorTool.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/lir/gen/LIRGeneratorTool.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 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 @@ -234,7 +234,7 @@ default Variable emitVectorizedHashCode(EnumSet runtimeCheckedCPUFeatures, Va } @SuppressWarnings("unused") - default void emitArrayFill(JavaKind commonElementKind, EnumSet runtimeCheckedCPUFeatures, Value array, Value arrayBaseOffset, Value length, Value value) { + default void emitArrayFill(JavaKind commonElementKind, Value array, Value arrayBaseOffset, Value length, Value value) { throw GraalError.unimplemented("Arrays.fill substitution is not implemented on this architecture"); // ExcludeFromJacocoGeneratedReport } diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/ShortCircuitOrNode.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/ShortCircuitOrNode.java index f8330b43aaa7..5f05684b9cc8 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/ShortCircuitOrNode.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/ShortCircuitOrNode.java @@ -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 @@ -309,11 +309,6 @@ public Integer smallestCompareWidth() { return tool.smallestCompareWidth(); } - @Override - public boolean supportsRounding() { - return tool.supportsRounding(); - } - @Override public OptionValues getOptions() { return tool.getOptions(); diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/SimplifyingGraphDecoder.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/SimplifyingGraphDecoder.java index efa52f853ca0..332df96fc89b 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/SimplifyingGraphDecoder.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/SimplifyingGraphDecoder.java @@ -111,11 +111,6 @@ public Integer smallestCompareWidth() { return null; } - @Override - public boolean supportsRounding() { - return getLowerer().supportsRounding(); - } - @Override public boolean divisionOverflowIsJVMSCompliant() { return getLowerer().divisionOverflowIsJVMSCompliant(); diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/calc/CompressBitsNode.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/calc/CompressBitsNode.java index d3261bc41604..8e18db9a5b4d 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/calc/CompressBitsNode.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/calc/CompressBitsNode.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 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 @@ -41,6 +41,8 @@ import jdk.graal.compiler.nodes.spi.CanonicalizerTool; import jdk.graal.compiler.nodes.spi.NodeLIRBuilderTool; +import jdk.vm.ci.amd64.AMD64; +import jdk.vm.ci.code.Architecture; import jdk.vm.ci.meta.JavaConstant; import jdk.vm.ci.meta.JavaKind; @@ -129,4 +131,12 @@ public ValueNode canonical(CanonicalizerTool tool, ValueNode value, ValueNode ma public void generate(NodeLIRBuilderTool builder, ArithmeticLIRGeneratorTool gen) { builder.setResult(this, gen.emitIntegerCompress(builder.operand(getX()), builder.operand(getY()))); } + + @SuppressWarnings("unlikely-arg-type") + public static boolean isSupported(Architecture arch) { + if (arch instanceof AMD64 amd64) { + return amd64.getFeatures().contains(AMD64.CPUFeature.BMI2); + } + return false; + } } diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/calc/ConditionalNode.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/calc/ConditionalNode.java index dade9e228315..433ddfd8c392 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/calc/ConditionalNode.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/calc/ConditionalNode.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 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 @@ -231,13 +231,10 @@ public static ValueNode canonicalizeConditional(LogicNode condition, ValueNode t * Convert `x < 0.0 ? Math.ceil(x) : Math.floor(x)` to RoundNode(x, TRUNCATE). */ if (canonicalizer != null && - canonicalizer.supportsRounding() && - condition instanceof FloatLessThanNode && - trueValue instanceof RoundNode && - falseValue instanceof RoundNode) { - FloatLessThanNode lessThan = (FloatLessThanNode) condition; - RoundNode trueRound = (RoundNode) trueValue; - RoundNode falseRound = (RoundNode) falseValue; + RoundNode.isSupported(canonicalizer.getLowerer().getTarget().arch) && + condition instanceof FloatLessThanNode lessThan && + trueValue instanceof RoundNode trueRound && + falseValue instanceof RoundNode falseRound) { if (trueRound.getValue() == falseRound.getValue()) { ValueNode roundInput = trueRound.getValue(); diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/calc/CopySignNode.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/calc/CopySignNode.java index 6ee47c3ef0e0..c329b053e207 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/calc/CopySignNode.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/calc/CopySignNode.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2024, 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 @@ -41,6 +41,9 @@ import jdk.graal.compiler.nodes.spi.CanonicalizerTool; import jdk.graal.compiler.nodes.spi.NodeLIRBuilderTool; +import jdk.vm.ci.aarch64.AArch64; +import jdk.vm.ci.amd64.AMD64; +import jdk.vm.ci.code.Architecture; import jdk.vm.ci.meta.JavaKind; @NodeInfo(cycles = CYCLES_2, size = SIZE_1) @@ -180,4 +183,13 @@ public Node canonical(CanonicalizerTool tool, ValueNode forX, ValueNode forY) { public void generate(NodeLIRBuilderTool nodeValueMap, ArithmeticLIRGeneratorTool gen) { nodeValueMap.setResult(this, gen.emitMathCopySign(nodeValueMap.operand(getX()), nodeValueMap.operand(getY()))); } + + @SuppressWarnings("unlikely-arg-type") + public static boolean isSupported(Architecture arch) { + return switch (arch) { + case AMD64 amd64 -> amd64.getFeatures().contains(AMD64.CPUFeature.AVX512VL); + case AArch64 aarch64 -> true; + default -> false; + }; + } } diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/calc/ExpandBitsNode.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/calc/ExpandBitsNode.java index 0b44278e3ecd..871168129dc1 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/calc/ExpandBitsNode.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/calc/ExpandBitsNode.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 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 @@ -41,6 +41,8 @@ import jdk.graal.compiler.nodes.spi.CanonicalizerTool; import jdk.graal.compiler.nodes.spi.NodeLIRBuilderTool; +import jdk.vm.ci.amd64.AMD64; +import jdk.vm.ci.code.Architecture; import jdk.vm.ci.meta.JavaConstant; import jdk.vm.ci.meta.JavaKind; @@ -142,4 +144,12 @@ public ValueNode canonical(CanonicalizerTool tool, ValueNode value, ValueNode ma public void generate(NodeLIRBuilderTool builder, ArithmeticLIRGeneratorTool gen) { builder.setResult(this, gen.emitIntegerExpand(builder.operand(getX()), builder.operand(getY()))); } + + @SuppressWarnings("unlikely-arg-type") + public static boolean isSupported(Architecture arch) { + if (arch instanceof AMD64 amd64) { + return amd64.getFeatures().contains(AMD64.CPUFeature.BMI2); + } + return false; + } } diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/calc/FloatConvertNode.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/calc/FloatConvertNode.java index 96c52e549ac5..60ff96ffce3d 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/calc/FloatConvertNode.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/calc/FloatConvertNode.java @@ -26,6 +26,7 @@ import static jdk.graal.compiler.nodeinfo.NodeCycles.CYCLES_8; +import jdk.graal.compiler.asm.amd64.AMD64BaseAssembler; import jdk.graal.compiler.core.common.calc.FloatConvert; import jdk.graal.compiler.core.common.type.ArithmeticOpTable; import jdk.graal.compiler.core.common.type.ArithmeticOpTable.FloatConvertOp; @@ -43,6 +44,9 @@ import jdk.graal.compiler.nodes.spi.CanonicalizerTool; import jdk.graal.compiler.nodes.spi.Lowerable; import jdk.graal.compiler.nodes.spi.NodeLIRBuilderTool; +import jdk.vm.ci.aarch64.AArch64; +import jdk.vm.ci.amd64.AMD64; +import jdk.vm.ci.code.Architecture; import jdk.vm.ci.meta.Constant; import jdk.vm.ci.meta.ConstantReflectionProvider; @@ -128,17 +132,11 @@ public boolean canOverflow() { } private static boolean isLosslessIntegerToFloatingPoint(IntegerStamp inputStamp, FloatStamp resultStamp, boolean unsigned) { - int mantissaBits; - switch (resultStamp.getBits()) { - case 32: - mantissaBits = 24; - break; - case 64: - mantissaBits = 53; - break; - default: - throw GraalError.shouldNotReachHereUnexpectedValue(resultStamp.getBits()); // ExcludeFromJacocoGeneratedReport - } + int mantissaBits = switch (resultStamp.getBits()) { + case 32 -> 24; + case 64 -> 53; + default -> throw GraalError.shouldNotReachHereUnexpectedValue(resultStamp.getBits()); // ExcludeFromJacocoGeneratedReport + }; long max = 1L << mantissaBits; long min = -(1L << mantissaBits); if (unsigned) { @@ -155,8 +153,7 @@ public ValueNode canonical(CanonicalizerTool tool, ValueNode forValue) { return ret; } - if (forValue instanceof FloatConvertNode) { - FloatConvertNode other = (FloatConvertNode) forValue; + if (forValue instanceof FloatConvertNode other) { if (other.isLossless() && other.op == this.op.reverse()) { return other.getValue(); } @@ -173,4 +170,28 @@ public void generate(NodeLIRBuilderTool nodeValueMap, ArithmeticLIRGeneratorTool public boolean mayNullCheckSkipConversion() { return false; } + + /** + * Indicates whether this target platform supports lowering floating point conversions to + * unsigned integer. + */ + public static boolean supportsFloatToUnsignedConvert(Architecture arch) { + return switch (arch) { + case AMD64 amd64 -> true; + case AArch64 aarch64 -> true; + default -> false; + }; + } + + /** + * Indicates whether this target platform supports lowering conversions from unsigned integers + * to floating point. + */ + public static boolean supportsUnsignedToFloatConvert(Architecture arch) { + return switch (arch) { + case AMD64 amd64 -> AMD64BaseAssembler.supportsFullAVX512(amd64.getFeatures()); + case AArch64 aarch64 -> true; + default -> false; + }; + } } diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/calc/FloatTypeTestNode.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/calc/FloatTypeTestNode.java index 41e18a38a81e..8fb6716dbd1c 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/calc/FloatTypeTestNode.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/calc/FloatTypeTestNode.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 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 @@ -39,8 +39,12 @@ import jdk.graal.compiler.nodes.spi.CanonicalizerTool; import jdk.graal.compiler.nodes.spi.NodeLIRBuilderTool; +import jdk.vm.ci.amd64.AMD64; +import jdk.vm.ci.code.Architecture; import jdk.vm.ci.meta.JavaKind; +import java.util.Objects; + @NodeInfo(cycles = CYCLES_2, size = SIZE_1) public final class FloatTypeTestNode extends UnaryNode implements ArithmeticLIRLowerable { public static final NodeClass TYPE = NodeClass.create(FloatTypeTestNode.class); @@ -64,22 +68,18 @@ public Node canonical(CanonicalizerTool tool, ValueNode forValue) { switch (forValue.getStackKind()) { case Float: if (forValue.isJavaConstant()) { - switch (op) { - case IS_FINITE: - return ConstantNode.forBoolean(Float.isFinite(forValue.asJavaConstant().asFloat())); - case IS_INFINITE: - return ConstantNode.forBoolean(Float.isInfinite(forValue.asJavaConstant().asFloat())); - } + return switch (op) { + case IS_FINITE -> ConstantNode.forBoolean(Float.isFinite(forValue.asJavaConstant().asFloat())); + case IS_INFINITE -> ConstantNode.forBoolean(Float.isInfinite(forValue.asJavaConstant().asFloat())); + }; } break; case Double: if (forValue.isJavaConstant()) { - switch (op) { - case IS_FINITE: - return ConstantNode.forBoolean(Double.isFinite(forValue.asJavaConstant().asDouble())); - case IS_INFINITE: - return ConstantNode.forBoolean(Double.isInfinite(forValue.asJavaConstant().asDouble())); - } + return switch (op) { + case IS_FINITE -> ConstantNode.forBoolean(Double.isFinite(forValue.asJavaConstant().asDouble())); + case IS_INFINITE -> ConstantNode.forBoolean(Double.isInfinite(forValue.asJavaConstant().asDouble())); + }; } break; default: @@ -90,12 +90,18 @@ public Node canonical(CanonicalizerTool tool, ValueNode forValue) { @Override public void generate(NodeLIRBuilderTool nodeValueMap, ArithmeticLIRGeneratorTool gen) { - switch (op) { - case IS_INFINITE: - nodeValueMap.setResult(this, gen.emitFloatIsInfinite(nodeValueMap.operand(getValue()))); - break; - default: - throw GraalError.shouldNotReachHere("unimplemented float type test op " + op); + if (Objects.requireNonNull(op) == FloatTypeTestOp.IS_INFINITE) { + nodeValueMap.setResult(this, gen.emitFloatIsInfinite(nodeValueMap.operand(getValue()))); + } else { + throw GraalError.shouldNotReachHere("unimplemented float type test op " + op); + } + } + + @SuppressWarnings("unlikely-arg-type") + public static boolean isSupported(Architecture arch) { + if (arch instanceof AMD64 amd64) { + return amd64.getFeatures().contains(AMD64.CPUFeature.AVX512DQ); } + return false; } } diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/calc/FusedMultiplyAddNode.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/calc/FusedMultiplyAddNode.java index 4788b7432277..9c150de50d49 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/calc/FusedMultiplyAddNode.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/calc/FusedMultiplyAddNode.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 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 @@ -41,6 +41,9 @@ import jdk.graal.compiler.nodes.spi.CanonicalizerTool; import jdk.graal.compiler.nodes.spi.NodeLIRBuilderTool; import jdk.graal.compiler.serviceprovider.GraalServices; +import jdk.vm.ci.aarch64.AArch64; +import jdk.vm.ci.amd64.AMD64; +import jdk.vm.ci.code.Architecture; import jdk.vm.ci.meta.JavaConstant; import jdk.vm.ci.meta.JavaKind; @@ -95,4 +98,13 @@ public ValueNode canonical(CanonicalizerTool tool, ValueNode forX, ValueNode for public void generate(NodeLIRBuilderTool builder, ArithmeticLIRGeneratorTool gen) { builder.setResult(this, gen.emitFusedMultiplyAdd(builder.operand(getX()), builder.operand(getY()), builder.operand(getZ()))); } + + @SuppressWarnings("unlikely-arg-type") + public static boolean isSupported(Architecture arch) { + return switch (arch) { + case AMD64 amd64 -> amd64.getFeatures().contains(AMD64.CPUFeature.FMA); + case AArch64 aarch64 -> true; + default -> false; + }; + } } diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/calc/MaxNode.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/calc/MaxNode.java index b2c29ee41186..b69c64829f5c 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/calc/MaxNode.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/calc/MaxNode.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2020, Arm Limited. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -37,6 +37,9 @@ import jdk.graal.compiler.nodes.NodeView; import jdk.graal.compiler.nodes.ValueNode; import jdk.graal.compiler.nodes.spi.LoweringProvider; +import jdk.vm.ci.aarch64.AArch64; +import jdk.vm.ci.amd64.AMD64; +import jdk.vm.ci.code.Architecture; @NodeInfo(shortName = "Max") public class MaxNode extends MinMaxNode { @@ -78,4 +81,13 @@ public boolean isNarrowable(int resultBits) { } return super.isNarrowable(resultBits, Signedness.SIGNED); } + + @SuppressWarnings("unlikely-arg-type") + public static boolean isSupported(Architecture arch) { + return switch (arch) { + case AMD64 amd64 -> amd64.getFeatures().contains(AMD64.CPUFeature.AVX); + case AArch64 aarch64 -> true; + default -> false; + }; + } } diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/calc/MinNode.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/calc/MinNode.java index f3dd271ed0ad..85ccb4388c62 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/calc/MinNode.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/calc/MinNode.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2020, Arm Limited. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -37,6 +37,9 @@ import jdk.graal.compiler.nodes.NodeView; import jdk.graal.compiler.nodes.ValueNode; import jdk.graal.compiler.nodes.spi.LoweringProvider; +import jdk.vm.ci.aarch64.AArch64; +import jdk.vm.ci.amd64.AMD64; +import jdk.vm.ci.code.Architecture; @NodeInfo(shortName = "Min") public class MinNode extends MinMaxNode { @@ -78,4 +81,13 @@ public boolean isNarrowable(int resultBits) { } return super.isNarrowable(resultBits, Signedness.SIGNED); } + + @SuppressWarnings("unlikely-arg-type") + public static boolean isSupported(Architecture arch) { + return switch (arch) { + case AMD64 amd64 -> amd64.getFeatures().contains(AMD64.CPUFeature.AVX); + case AArch64 aarch64 -> true; + default -> false; + }; + } } diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/calc/RoundNode.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/calc/RoundNode.java index a4568226b5b2..64c467e567bf 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/calc/RoundNode.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/calc/RoundNode.java @@ -30,7 +30,6 @@ import jdk.graal.compiler.core.common.calc.FloatConvert; import jdk.graal.compiler.core.common.type.FloatStamp; import jdk.graal.compiler.core.common.type.Stamp; -import jdk.graal.compiler.debug.GraalError; import jdk.graal.compiler.graph.NodeClass; import jdk.graal.compiler.lir.gen.ArithmeticLIRGeneratorTool; import jdk.graal.compiler.lir.gen.ArithmeticLIRGeneratorTool.RoundingMode; @@ -40,16 +39,15 @@ import jdk.graal.compiler.nodes.ValueNode; import jdk.graal.compiler.nodes.spi.ArithmeticLIRLowerable; import jdk.graal.compiler.nodes.spi.CanonicalizerTool; -import jdk.graal.compiler.nodes.spi.LoweringProvider; import jdk.graal.compiler.nodes.spi.NodeLIRBuilderTool; +import jdk.vm.ci.aarch64.AArch64; +import jdk.vm.ci.amd64.AMD64; +import jdk.vm.ci.code.Architecture; import jdk.vm.ci.meta.JavaConstant; import jdk.vm.ci.meta.JavaKind; /** * Round floating-point value. - *

- * Can only be used if {@link CanonicalizerTool#supportsRounding()} or - * {@link LoweringProvider#supportsRounding()} returns {@code true}. */ @NodeInfo(cycles = CYCLES_1) public final class RoundNode extends UnaryNode implements ArithmeticLIRLowerable { @@ -76,18 +74,12 @@ public RoundingMode mode() { } private static double round(RoundingMode mode, double input) { - switch (mode) { - case DOWN: - return Math.floor(input); - case NEAREST: - return Math.rint(input); - case UP: - return Math.ceil(input); - case TRUNCATE: - return input < 0.0 ? Math.ceil(input) : Math.floor(input); - default: - throw GraalError.unimplemented("unimplemented RoundingMode " + mode); // ExcludeFromJacocoGeneratedReport - } + return switch (mode) { + case DOWN -> Math.floor(input); + case NEAREST -> Math.rint(input); + case UP -> Math.ceil(input); + case TRUNCATE -> input < 0.0 ? Math.ceil(input) : Math.floor(input); + }; } private static FloatStamp roundStamp(FloatStamp stamp, RoundingMode mode) { @@ -143,4 +135,12 @@ public void generate(NodeLIRBuilderTool builder, ArithmeticLIRGeneratorTool gen) builder.setResult(this, gen.emitRound(builder.operand(getValue()), mode)); } + @SuppressWarnings("unlikely-arg-type") + public static boolean isSupported(Architecture arch) { + return switch (arch) { + case AMD64 amd64 -> amd64.getFeatures().contains(AMD64.CPUFeature.SSE4_1); + case AArch64 aarch64 -> true; + default -> false; + }; + } } diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/graphbuilderconf/InvocationPlugin.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/graphbuilderconf/InvocationPlugin.java index b386a054ec0c..4185ab9862f9 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/graphbuilderconf/InvocationPlugin.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/graphbuilderconf/InvocationPlugin.java @@ -37,6 +37,7 @@ import jdk.graal.compiler.nodes.Invoke; import jdk.graal.compiler.nodes.ValueNode; import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugins.ClassPlugins; +import jdk.vm.ci.code.Architecture; import jdk.vm.ci.meta.MetaUtil; import jdk.vm.ci.meta.ResolvedJavaMethod; @@ -530,4 +531,62 @@ public final boolean inlineOnly() { return true; } } + + /** + * ConditionalInvocationPlugin enables additional checks (e.g., CPU feature detection) before + * the plugin is applied. In a native image with runtime compilation, this plugin can help + * identify plugins that cannot be applied during image building but may still be relevant when + * running the image on more advanced architectures. + * + * Because supporting arbitrary plugins in the context of encoded graphs is complex, we disallow + * ConditionalInvocationPlugin in snippets. See + * {@code SymbolicSnippetEncoder$HotSpotSnippetBytecodeParser#tryInvocationPlugin} + */ + public abstract static class ConditionalInvocationPlugin extends InvocationPlugin implements Cloneable { + + public ConditionalInvocationPlugin(String name, Type... argumentTypes) { + super(name, argumentTypes); + } + + @Override + public final boolean execute(GraphBuilderContext b, ResolvedJavaMethod targetMethod, InvocationPlugin.Receiver receiver, ValueNode[] argsIncludingReceiver) { + if (!isApplicable(b.getLowerer().getTarget().arch)) { + return false; + } + return super.execute(b, targetMethod, receiver, argsIncludingReceiver); + } + + public boolean isRuntimeChecked(Architecture arch) { + return !isApplicable(arch); + } + + @Override + @SuppressWarnings("unchecked") + public ConditionalInvocationPlugin clone() { + try { + ConditionalInvocationPlugin newInstance = (ConditionalInvocationPlugin) super.clone(); + newInstance.next = null; + return newInstance; + } catch (CloneNotSupportedException e) { + throw GraalError.shouldNotReachHere(e); + } + } + + /** + * Determines if this plugin is applicable on the given {@code arch}. + */ + public abstract boolean isApplicable(Architecture arch); + } + + public abstract static class InlineOnlyConditionalInvocationPlugin extends ConditionalInvocationPlugin { + + public InlineOnlyConditionalInvocationPlugin(String name, Type... argumentTypes) { + super(name, argumentTypes); + } + + @Override + public boolean inlineOnly() { + return true; + } + } } diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/graphbuilderconf/InvocationPlugins.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/graphbuilderconf/InvocationPlugins.java index 0c666da8da77..ef265d4c2d00 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/graphbuilderconf/InvocationPlugins.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/graphbuilderconf/InvocationPlugins.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 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 @@ -42,7 +42,6 @@ import java.util.TreeSet; import java.util.function.Predicate; -import jdk.vm.ci.meta.JavaType; import org.graalvm.collections.EconomicMap; import org.graalvm.collections.Equivalence; import org.graalvm.collections.MapCursor; @@ -58,7 +57,7 @@ import jdk.graal.compiler.graph.Node; import jdk.graal.compiler.graph.iterators.NodeIterable; import jdk.graal.compiler.nodes.ValueNode; -import jdk.graal.compiler.nodes.spi.Replacements; +import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugin.ConditionalInvocationPlugin; import jdk.graal.compiler.nodes.type.StampTool; import jdk.graal.compiler.options.Option; import jdk.graal.compiler.options.OptionKey; @@ -66,6 +65,8 @@ import jdk.graal.compiler.options.OptionValues; import jdk.graal.compiler.serviceprovider.GlobalAtomicLong; import jdk.graal.compiler.serviceprovider.IsolateUtil; +import jdk.vm.ci.code.Architecture; +import jdk.vm.ci.meta.JavaType; import jdk.vm.ci.meta.MetaUtil; import jdk.vm.ci.meta.ResolvedJavaMethod; import jdk.vm.ci.meta.ResolvedJavaType; @@ -199,7 +200,6 @@ public static class Registration { private final InvocationPlugins plugins; private final Type declaringType; - private final Replacements replacements; private boolean allowOverwrite; /** @@ -213,22 +213,6 @@ public static class Registration { public Registration(InvocationPlugins plugins, Type declaringType) { this.plugins = plugins; this.declaringType = declaringType; - this.replacements = null; - } - - /** - * Creates an object for registering {@link InvocationPlugin}s for methods declared by a - * given class. - * - * @param plugins where to register the plugins - * @param declaringType the class declaring the methods for which plugins will be registered - * via this object - * @param replacements the current Replacements provider - */ - public Registration(InvocationPlugins plugins, Type declaringType, Replacements replacements) { - this.plugins = plugins; - this.declaringType = declaringType; - this.replacements = replacements; } /** @@ -242,22 +226,6 @@ public Registration(InvocationPlugins plugins, Type declaringType, Replacements public Registration(InvocationPlugins plugins, String declaringClassName) { this.plugins = plugins; this.declaringType = new OptionalLazySymbol(declaringClassName); - this.replacements = null; - } - - /** - * Creates an object for registering {@link InvocationPlugin}s for methods declared by a - * given class. - * - * @param plugins where to register the plugins - * @param declaringClassName the name of the class class declaring the methods for which - * plugins will be registered via this object - * @param replacements the current Replacements provider - */ - public Registration(InvocationPlugins plugins, String declaringClassName, Replacements replacements) { - this.plugins = plugins; - this.declaringType = new OptionalLazySymbol(declaringClassName); - this.replacements = replacements; } /** @@ -274,20 +242,6 @@ public Registration setAllowOverwrite(boolean allowOverwrite) { public void register(InvocationPlugin plugin) { plugins.register(declaringType, plugin, allowOverwrite); } - - /** - * Registers a plugin for a method that is conditionally enabled. {@link Replacements} keeps - * records of such plugins and avoids encoding method substitution graphs using these - * plugins. - * - * @param isEnabled controls whether the plugin is actually registered. - */ - public void registerConditional(boolean isEnabled, InvocationPlugin plugin) { - replacements.registerConditionalPlugin(plugin); - if (isEnabled) { - plugins.register(declaringType, plugin, allowOverwrite); - } - } } /** @@ -811,6 +765,29 @@ protected void register(Type declaringClass, InvocationPlugin plugin, boolean al assert inRuntimeCode() || Checks.checkResolvable(declaringClass, plugin); } + public void collectRuntimeCheckedPlugins(InvocationPlugins plugins, Architecture arch) { + if (parent != null) { + parent.collectRuntimeCheckedPlugins(plugins, arch); + } + + for (String className : registrations.getKeys()) { + ClassPlugins classPlugins = registrations.get(className); + ClassPlugins copyClassPlugins = null; + + for (InvocationPlugin invocationPlugin : classPlugins.invocationPlugins.getValues()) { + if (invocationPlugin instanceof ConditionalInvocationPlugin conditionalInvocationPlugin) { + if (conditionalInvocationPlugin.isRuntimeChecked(arch)) { + if (copyClassPlugins == null) { + copyClassPlugins = new ClassPlugins(); + plugins.registrations.put(className, copyClassPlugins); + } + copyClassPlugins.register(conditionalInvocationPlugin.clone(), false); + } + } + } + } + } + /** * Registers an invocation plugin for a given method. There must be no plugin currently * registered for {@code method}. diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/spi/CanonicalizerTool.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/spi/CanonicalizerTool.java index 7f8060918422..ce9cf5d1c7fd 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/spi/CanonicalizerTool.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/spi/CanonicalizerTool.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 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 @@ -65,11 +65,6 @@ default boolean finalCanonicalization() { */ Integer smallestCompareWidth(); - /** - * Indicates whether this target platform supports lowering {@code RoundNode}. - */ - boolean supportsRounding(); - OptionValues getOptions(); /** diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/spi/DelegatingReplacements.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/spi/DelegatingReplacements.java index 8ea62aa73eb9..25036fb0c2e7 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/spi/DelegatingReplacements.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/spi/DelegatingReplacements.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2022, 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 @@ -36,7 +36,6 @@ import jdk.graal.compiler.nodes.StructuredGraph.AllowAssumptions; import jdk.graal.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration; import jdk.graal.compiler.nodes.graphbuilderconf.GraphBuilderPlugin; -import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugin; import jdk.graal.compiler.options.OptionValues; import jdk.vm.ci.meta.JavaKind; import jdk.vm.ci.meta.ResolvedJavaMethod; @@ -102,11 +101,6 @@ public void registerSnippet(ResolvedJavaMethod method, ResolvedJavaMethod origin delegate.registerSnippet(method, original, receiver, trackNodeSourcePosition, options); } - @Override - public void registerConditionalPlugin(InvocationPlugin plugin) { - delegate.registerConditionalPlugin(plugin); - } - @Override public StructuredGraph getInlineSubstitution(ResolvedJavaMethod method, int invokeBci, boolean isInOOMETry, Invoke.InlineControl inlineControl, boolean trackNodeSourcePosition, NodeSourcePosition replaceePosition, AllowAssumptions allowAssumptions, OptionValues options) { diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/spi/LoweringProvider.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/spi/LoweringProvider.java index d69219163f0d..362f09ba6e15 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/spi/LoweringProvider.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/spi/LoweringProvider.java @@ -28,7 +28,6 @@ import jdk.graal.compiler.graph.Node; import jdk.graal.compiler.lir.CastValue; import jdk.graal.compiler.nodes.ValueNode; -import jdk.graal.compiler.nodes.calc.RoundNode; import jdk.graal.compiler.nodes.gc.BarrierSet; import jdk.graal.compiler.nodes.memory.ExtendableMemoryAccess; import jdk.graal.compiler.nodes.memory.address.AddressNode; @@ -80,11 +79,6 @@ default boolean supportsBulkClearArray(JavaKind elementKind) { */ boolean supportsOptimizedFilling(OptionValues options); - /** - * Indicates whether this target platform supports lowering {@link RoundNode}. - */ - boolean supportsRounding(); - /** * Indicates whether this target platform supports the usage of implicit (trapping) null checks. */ @@ -123,20 +117,4 @@ default boolean supportsBulkClearArray(JavaKind elementKind) { * {@link ExtendableMemoryAccess}. */ boolean supportsFoldingExtendIntoAccess(ExtendableMemoryAccess access, MemoryExtendKind extendKind); - - /** - * Indicates whether this target platform supports lowering floating point conversions to - * unsigned integer. - */ - default boolean supportsFloatToUnsignedConvert() { - return false; - } - - /** - * Indicates whether this target platform supports lowering conversions from unsigned integers - * to floating point. - */ - default boolean supportsUnsignedToFloatConvert() { - return false; - } } diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/spi/Replacements.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/spi/Replacements.java index f5330aabc983..87b23b2410fa 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/spi/Replacements.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/spi/Replacements.java @@ -94,13 +94,6 @@ StructuredGraph getSnippet(ResolvedJavaMethod method, ResolvedJavaMethod recursi */ void registerSnippet(ResolvedJavaMethod method, ResolvedJavaMethod original, Object receiver, boolean trackNodeSourcePosition, OptionValues options); - /** - * Marks a plugin as conditionally applied. In the context of libgraal conditional plugins can't - * be used during graph encoding for snippets and in method substitutions, and this is used to - * detect violations of this restriction. - */ - void registerConditionalPlugin(InvocationPlugin plugin); - /** * Gets a graph that is a substitution for a given method. * diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/util/GraphUtil.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/util/GraphUtil.java index 781bc8b2efdb..cb2a1651e1af 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/util/GraphUtil.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/util/GraphUtil.java @@ -1179,15 +1179,6 @@ public Integer smallestCompareWidth() { } } - @Override - public boolean supportsRounding() { - if (getLowerer() != null) { - return getLowerer().supportsRounding(); - } else { - return false; - } - } - @Override public boolean divisionOverflowIsJVMSCompliant() { if (getLowerer() != null) { diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/phases/common/CanonicalizerPhase.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/phases/common/CanonicalizerPhase.java index 40572802513e..785325035c5a 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/phases/common/CanonicalizerPhase.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/phases/common/CanonicalizerPhase.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 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 @@ -839,11 +839,6 @@ public Integer smallestCompareWidth() { return context.getLowerer().smallestCompareWidth(); } - @Override - public boolean supportsRounding() { - return context.getLowerer().supportsRounding(); - } - @Override public OptionValues getOptions() { return options; diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/phases/common/FixReadsPhase.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/phases/common/FixReadsPhase.java index f790aa6ccdfb..f15ae84e1a74 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/phases/common/FixReadsPhase.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/phases/common/FixReadsPhase.java @@ -214,11 +214,6 @@ public Integer smallestCompareWidth() { return null; } - @Override - public boolean supportsRounding() { - return false; - } - @Override public OptionValues getOptions() { return graph.getOptions(); diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/phases/tiers/CompilerConfiguration.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/phases/tiers/CompilerConfiguration.java index 7f68c64c5f31..7976d90cbec8 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/phases/tiers/CompilerConfiguration.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/phases/tiers/CompilerConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2022, 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 @@ -30,10 +30,8 @@ import jdk.graal.compiler.lir.phases.PostAllocationOptimizationPhase.PostAllocationOptimizationContext; import jdk.graal.compiler.lir.phases.PreAllocationOptimizationPhase.PreAllocationOptimizationContext; import jdk.graal.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins; -import jdk.graal.compiler.nodes.spi.Replacements; import jdk.graal.compiler.options.OptionValues; import jdk.graal.compiler.phases.PhaseSuite; - import jdk.vm.ci.code.Architecture; public interface CompilerConfiguration { @@ -53,6 +51,6 @@ public interface CompilerConfiguration { LIRPhaseSuite createFinalCodeAnalysisStage(OptionValues options); @SuppressWarnings("unused") - default void registerGraphBuilderPlugins(Architecture arch, Plugins plugins, OptionValues options, Replacements replacements) { + default void registerGraphBuilderPlugins(Architecture arch, Plugins plugins, OptionValues options) { } } diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/ReplacementsImpl.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/ReplacementsImpl.java index 8a50aac59c22..bd3d0ada4f6d 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/ReplacementsImpl.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/ReplacementsImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 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 @@ -77,7 +77,6 @@ import jdk.graal.compiler.nodes.graphbuilderconf.InlineInvokePlugin; import jdk.graal.compiler.nodes.graphbuilderconf.IntrinsicContext; import jdk.graal.compiler.nodes.graphbuilderconf.IntrinsicContext.CompilationContext; -import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugin; import jdk.graal.compiler.nodes.java.MethodCallTargetNode; import jdk.graal.compiler.nodes.spi.Replacements; import jdk.graal.compiler.nodes.spi.SnippetParameterInfo; @@ -320,10 +319,6 @@ public void registerSnippet(ResolvedJavaMethod method, ResolvedJavaMethod origin // No initialization needed as snippet graphs are created on demand in getSnippet } - @Override - public void registerConditionalPlugin(InvocationPlugin plugin) { - } - @Override public boolean hasSubstitution(ResolvedJavaMethod method, OptionValues options) { return false; diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/StandardGraphBuilderPlugins.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/StandardGraphBuilderPlugins.java index 0b4442de6800..78f2f246e507 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/StandardGraphBuilderPlugins.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/StandardGraphBuilderPlugins.java @@ -151,6 +151,8 @@ import jdk.graal.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins; import jdk.graal.compiler.nodes.graphbuilderconf.GraphBuilderContext; import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugin; +import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugin.ConditionalInvocationPlugin; +import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugin.InlineOnlyConditionalInvocationPlugin; import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugin.InlineOnlyInvocationPlugin; import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugin.OptionalInvocationPlugin; import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver; @@ -179,8 +181,6 @@ import jdk.graal.compiler.nodes.java.UnsafeCompareAndExchangeNode; import jdk.graal.compiler.nodes.java.UnsafeCompareAndSwapNode; import jdk.graal.compiler.nodes.memory.address.IndexAddressNode; -import jdk.graal.compiler.nodes.spi.LoweringProvider; -import jdk.graal.compiler.nodes.spi.Replacements; import jdk.graal.compiler.nodes.spi.TrackedUnsafeAccess; import jdk.graal.compiler.nodes.type.StampTool; import jdk.graal.compiler.nodes.util.ConstantFoldUtil; @@ -190,7 +190,6 @@ import jdk.graal.compiler.replacements.nodes.AESNode; import jdk.graal.compiler.replacements.nodes.AESNode.CryptMode; import jdk.graal.compiler.replacements.nodes.ArrayEqualsNode; -import jdk.graal.compiler.replacements.nodes.ArrayFillNode; import jdk.graal.compiler.replacements.nodes.BigIntegerMulAddNode; import jdk.graal.compiler.replacements.nodes.BigIntegerMultiplyToLenNode; import jdk.graal.compiler.replacements.nodes.BigIntegerSquareToLenNode; @@ -208,11 +207,13 @@ import jdk.graal.compiler.replacements.nodes.MessageDigestNode.MD5Node; import jdk.graal.compiler.replacements.nodes.MessageDigestNode.SHA1Node; import jdk.graal.compiler.replacements.nodes.MessageDigestNode.SHA256Node; +import jdk.graal.compiler.replacements.nodes.MessageDigestNode.SHA3Node; import jdk.graal.compiler.replacements.nodes.MessageDigestNode.SHA512Node; import jdk.graal.compiler.replacements.nodes.ProfileBooleanNode; import jdk.graal.compiler.replacements.nodes.ReverseBitsNode; import jdk.graal.compiler.replacements.nodes.ReverseBytesNode; import jdk.graal.compiler.replacements.nodes.VectorizedHashCodeNode; +import jdk.graal.compiler.replacements.nodes.VectorizedMismatchNode; import jdk.graal.compiler.replacements.nodes.VirtualizableInvokeMacroNode; import jdk.graal.compiler.replacements.nodes.arithmetic.IntegerAddExactNode; import jdk.graal.compiler.replacements.nodes.arithmetic.IntegerAddExactOverflowNode; @@ -248,17 +249,15 @@ public class StandardGraphBuilderPlugins { public static void registerInvocationPlugins(SnippetReflectionProvider snippetReflection, InvocationPlugins plugins, - Replacements replacements, boolean useExactMathPlugins, boolean explicitUnsafeNullChecks, - boolean supportsStubBasedPlugins, - LoweringProvider lowerer) { + boolean supportsStubBasedPlugins) { registerObjectPlugins(plugins); registerClassPlugins(plugins); - registerMathPlugins(plugins, useExactMathPlugins, replacements, lowerer); + registerMathPlugins(plugins, useExactMathPlugins); registerStrictMathPlugins(plugins); registerUnsignedMathPlugins(plugins); - registerStringPlugins(plugins, replacements, snippetReflection, supportsStubBasedPlugins); + registerStringPlugins(plugins, snippetReflection, supportsStubBasedPlugins); registerCharacterPlugins(plugins); registerCharacterDataLatin1Plugins(plugins); registerShortPlugins(plugins); @@ -266,25 +265,25 @@ public static void registerInvocationPlugins(SnippetReflectionProvider snippetRe registerIntegerLongPlugins(plugins, JavaKind.Long); registerFloatPlugins(plugins); registerDoublePlugins(plugins); - registerArrayPlugins(plugins, replacements); - registerUnsafePlugins(plugins, replacements, explicitUnsafeNullChecks); + registerArrayPlugins(plugins); + registerUnsafePlugins(plugins, explicitUnsafeNullChecks); registerEdgesPlugins(plugins); registerGraalDirectivesPlugins(plugins, snippetReflection); registerBoxingPlugins(plugins); - registerJMHBlackholePlugins(plugins, replacements); - registerJFRThrowablePlugins(plugins, replacements); - registerMethodHandleImplPlugins(plugins, replacements); - registerPreconditionsPlugins(plugins, replacements); - registerJcovCollectPlugins(plugins, replacements); - registerThreadPlugins(plugins, replacements); + registerJMHBlackholePlugins(plugins); + registerJFRThrowablePlugins(plugins); + registerMethodHandleImplPlugins(plugins); + registerPreconditionsPlugins(plugins); + registerJcovCollectPlugins(plugins); + registerThreadPlugins(plugins); if (supportsStubBasedPlugins) { - registerArraysPlugins(plugins, replacements, lowerer.getTarget().arch); - registerAESPlugins(plugins, replacements, lowerer.getTarget().arch); - registerGHASHPlugin(plugins, replacements, lowerer.getTarget().arch); - registerBigIntegerPlugins(plugins, replacements); - registerMessageDigestPlugins(plugins, replacements, lowerer.getTarget().arch); - registerStringCodingPlugins(plugins, replacements); + registerArraysPlugins(plugins); + registerAESPlugins(plugins); + registerGHASHPlugin(plugins); + registerBigIntegerPlugins(plugins); + registerMessageDigestPlugins(plugins); + registerStringCodingPlugins(plugins); } } @@ -353,8 +352,8 @@ private boolean tryConstantFold(GraphBuilderContext b, ResolvedJavaField field, }); } - private static void registerStringPlugins(InvocationPlugins plugins, Replacements replacements, SnippetReflectionProvider snippetReflection, boolean supportsStubBasedPlugins) { - final Registration r = new Registration(plugins, String.class, replacements); + private static void registerStringPlugins(InvocationPlugins plugins, SnippetReflectionProvider snippetReflection, boolean supportsStubBasedPlugins) { + final Registration r = new Registration(plugins, String.class); r.register(new InvocationPlugin("hashCode", Receiver.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) { @@ -382,7 +381,7 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec if (supportsStubBasedPlugins) { r.register(new StringEqualsInvocationPlugin()); } - final Registration utf16r = new Registration(plugins, "java.lang.StringUTF16", replacements); + final Registration utf16r = new Registration(plugins, "java.lang.StringUTF16"); utf16r.setAllowOverwrite(true); utf16r.register(new InvocationPlugin("getChar", byte[].class, int.class) { @@ -415,31 +414,6 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec }); } - public static class ArrayFillInvocationPlugin extends InvocationPlugin { - private final JavaKind kind; - - public ArrayFillInvocationPlugin(JavaKind kind, Type... argumentTypes) { - super("fill", argumentTypes); - this.kind = kind; - } - - @SuppressWarnings("try") - @Override - public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode array, ValueNode value) { - ConstantNode arrayBaseOffset = ConstantNode.forLong(b.getMetaAccess().getArrayBaseOffset(this.kind), b.getGraph()); - ValueNode nonNullArray = b.nullCheckedValue(array, DeoptimizationAction.None); - ValueNode arrayLength = b.add(new ArrayLengthNode(nonNullArray)); - ValueNode castedValue = value; - if (this.kind == JavaKind.Float) { - castedValue = ReinterpretNode.create(JavaKind.Int, value, NodeView.DEFAULT); - } else if (this.kind == JavaKind.Double) { - castedValue = ReinterpretNode.create(JavaKind.Long, value, NodeView.DEFAULT); - } - b.add(new ArrayFillNode(nonNullArray, arrayBaseOffset, arrayLength, castedValue, this.kind)); - return true; - } - } - public static class ArrayEqualsInvocationPlugin extends InvocationPlugin { private final JavaKind kind; @@ -529,23 +503,14 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec } } - private static void registerArraysPlugins(InvocationPlugins plugins, Replacements replacements, Architecture arch) { - Registration r = new Registration(plugins, Arrays.class, replacements); + private static void registerArraysPlugins(InvocationPlugins plugins) { + Registration r = new Registration(plugins, Arrays.class); r.register(new ArrayEqualsInvocationPlugin(JavaKind.Boolean, boolean[].class, boolean[].class)); r.register(new ArrayEqualsInvocationPlugin(JavaKind.Byte, byte[].class, byte[].class)); r.register(new ArrayEqualsInvocationPlugin(JavaKind.Short, short[].class, short[].class)); r.register(new ArrayEqualsInvocationPlugin(JavaKind.Char, char[].class, char[].class)); r.register(new ArrayEqualsInvocationPlugin(JavaKind.Int, int[].class, int[].class)); r.register(new ArrayEqualsInvocationPlugin(JavaKind.Long, long[].class, long[].class)); - - r.registerConditional(ArrayFillNode.isSupported(arch), new ArrayFillInvocationPlugin(JavaKind.Boolean, boolean[].class, boolean.class)); - r.registerConditional(ArrayFillNode.isSupported(arch), new ArrayFillInvocationPlugin(JavaKind.Byte, byte[].class, byte.class)); - r.registerConditional(ArrayFillNode.isSupported(arch), new ArrayFillInvocationPlugin(JavaKind.Char, char[].class, char.class)); - r.registerConditional(ArrayFillNode.isSupported(arch), new ArrayFillInvocationPlugin(JavaKind.Short, short[].class, short.class)); - r.registerConditional(ArrayFillNode.isSupported(arch), new ArrayFillInvocationPlugin(JavaKind.Int, int[].class, int.class)); - r.registerConditional(ArrayFillNode.isSupported(arch), new ArrayFillInvocationPlugin(JavaKind.Float, float[].class, float.class)); - r.registerConditional(ArrayFillNode.isSupported(arch), new ArrayFillInvocationPlugin(JavaKind.Long, long[].class, long.class)); - r.registerConditional(ArrayFillNode.isSupported(arch), new ArrayFillInvocationPlugin(JavaKind.Double, double[].class, double.class)); } public static InvocationPlugin newArrayPlugin(final String methodName) { @@ -564,8 +529,8 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec }; } - private static void registerArrayPlugins(InvocationPlugins plugins, Replacements replacements) { - Registration r = new Registration(plugins, Array.class, replacements); + private static void registerArrayPlugins(InvocationPlugins plugins) { + Registration r = new Registration(plugins, Array.class); r.register(new InvocationPlugin("getLength", Object.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver unused, ValueNode object) { @@ -682,10 +647,9 @@ private static String memoryOrderModeToMethodSuffix(MemoryOrderMode memoryOrder) throw new IllegalArgumentException(memoryOrder.name()); } - private static void registerUnsafePlugins(InvocationPlugins plugins, Replacements replacements, boolean explicitUnsafeNullChecks) { + private static void registerUnsafePlugins(InvocationPlugins plugins, boolean explicitUnsafeNullChecks) { JavaKind[] supportedJavaKinds = {JavaKind.Int, JavaKind.Long, JavaKind.Object}; - - Registration jdkInternalMiscUnsafe = new Registration(plugins, "jdk.internal.misc.Unsafe", replacements); + Registration jdkInternalMiscUnsafe = new Registration(plugins, "jdk.internal.misc.Unsafe"); registerUnsafePlugins0(jdkInternalMiscUnsafe, explicitUnsafeNullChecks); registerUnsafeUnalignedPlugins(jdkInternalMiscUnsafe, explicitUnsafeNullChecks); @@ -1075,8 +1039,8 @@ private static void createIntegerExactBinaryOperation(GraphBuilderContext b, Jav } } - private static void registerMathPlugins(InvocationPlugins plugins, boolean useExactMathPlugins, Replacements replacements, LoweringProvider lowerer) { - Registration r = new Registration(plugins, Math.class, replacements); + private static void registerMathPlugins(InvocationPlugins plugins, boolean useExactMathPlugins) { + Registration r = new Registration(plugins, Math.class); if (useExactMathPlugins) { for (JavaKind kind : new JavaKind[]{JavaKind.Int, JavaKind.Long}) { Class type = kind.toJavaClass(); @@ -1160,11 +1124,9 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec } }); r.register(new MathSqrtPlugin()); - - boolean supportsRound = lowerer.supportsRounding(); - registerRound(supportsRound, r, "rint", RoundingMode.NEAREST); - registerRound(supportsRound, r, "ceil", RoundingMode.UP); - registerRound(supportsRound, r, "floor", RoundingMode.DOWN); + registerRound(r, "rint", RoundingMode.NEAREST); + registerRound(r, "ceil", RoundingMode.UP); + registerRound(r, "floor", RoundingMode.DOWN); r.register(new InvocationPlugin("signum", float.class) { @Override @@ -1203,13 +1165,18 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec }); } - private static void registerRound(boolean supportsRound, Registration r, String name, RoundingMode mode) { - r.registerConditional(supportsRound, new InvocationPlugin(name, double.class) { + private static void registerRound(Registration r, String name, RoundingMode mode) { + r.register(new ConditionalInvocationPlugin(name, double.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode arg) { b.push(JavaKind.Double, b.append(RoundNode.create(arg, mode))); return true; } + + @Override + public boolean isApplicable(Architecture arch) { + return RoundNode.isSupported(arch); + } }); } @@ -2148,12 +2115,12 @@ public static void registerEnsureAllocatedHereIntrinsic(GraphBuilderContext b, V object.safeDelete(); } - private static void registerJMHBlackholePlugins(InvocationPlugins plugins, Replacements replacements) { + private static void registerJMHBlackholePlugins(InvocationPlugins plugins) { // The purpose of this plugin is to help Blackhole.consume function mostly correctly even if // it's been inlined. String[] names = {"org.openjdk.jmh.infra.Blackhole", "org.openjdk.jmh.logic.BlackHole"}; for (String name : names) { - Registration r = new Registration(plugins, name, replacements); + Registration r = new Registration(plugins, name); for (JavaKind kind : JavaKind.values()) { if ((kind.isPrimitive() && kind != JavaKind.Void) || kind == JavaKind.Object) { Class javaClass = getJavaClass(kind); @@ -2190,8 +2157,8 @@ public boolean isDecorator() { } } - private static void registerJFRThrowablePlugins(InvocationPlugins plugins, Replacements replacements) { - Registration r = new Registration(plugins, "oracle.jrockit.jfr.jdkevents.ThrowableTracer", replacements); + private static void registerJFRThrowablePlugins(InvocationPlugins plugins) { + Registration r = new Registration(plugins, "oracle.jrockit.jfr.jdkevents.ThrowableTracer"); r.register(new InlineOnlyInvocationPlugin("traceThrowable", Throwable.class, String.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode throwable, ValueNode message) { @@ -2201,8 +2168,8 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec }); } - private static void registerMethodHandleImplPlugins(InvocationPlugins plugins, Replacements replacements) { - Registration r = new Registration(plugins, "java.lang.invoke.MethodHandleImpl", replacements); + private static void registerMethodHandleImplPlugins(InvocationPlugins plugins) { + Registration r = new Registration(plugins, "java.lang.invoke.MethodHandleImpl"); // In later JDKs this no longer exists and the usage is replace by Class.cast which is // already an intrinsic r.register(new InlineOnlyInvocationPlugin("profileBoolean", boolean.class, int[].class) { @@ -2290,8 +2257,8 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec } } - private static void registerPreconditionsPlugins(InvocationPlugins plugins, Replacements replacements) { - final Registration preconditions = new Registration(plugins, "jdk.internal.util.Preconditions", replacements); + private static void registerPreconditionsPlugins(InvocationPlugins plugins) { + final Registration preconditions = new Registration(plugins, "jdk.internal.util.Preconditions"); preconditions.register(new CheckIndexPlugin(int.class)); preconditions.register(new CheckIndexPlugin(long.class)); } @@ -2300,8 +2267,8 @@ private static void registerPreconditionsPlugins(InvocationPlugins plugins, Repl * Registers a plugin to ignore {@code com.sun.tdk.jcov.runtime.Collect.hit} within an * intrinsic. */ - private static void registerJcovCollectPlugins(InvocationPlugins plugins, Replacements replacements) { - Registration r = new Registration(plugins, "com.sun.tdk.jcov.runtime.Collect", replacements); + private static void registerJcovCollectPlugins(InvocationPlugins plugins) { + Registration r = new Registration(plugins, "com.sun.tdk.jcov.runtime.Collect"); r.register(new InvocationPlugin("hit", int.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object) { @@ -2313,7 +2280,7 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec }); } - public abstract static class AESCryptPluginBase extends InvocationPlugin { + public abstract static class AESCryptPluginBase extends ConditionalInvocationPlugin { protected final CryptMode mode; @@ -2334,7 +2301,7 @@ public static ValueNode readFieldArrayStart(GraphBuilderContext b, } } - public static class AESCryptPlugin extends AESCryptPluginBase { + public static final class AESCryptPlugin extends AESCryptPluginBase { /** * The AES block size is a constant 128 bits as defined by the * standard. @@ -2373,6 +2340,11 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec } return true; } + + @Override + public boolean isApplicable(Architecture arch) { + return AESNode.isSupported(arch); + } } public abstract static class AESCryptDelegatePlugin extends AESCryptPluginBase { @@ -2438,6 +2410,11 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec return true; } } + + @Override + public final boolean isApplicable(Architecture arch) { + return CounterModeAESNode.isSupported(arch); + } } public abstract static class CipherBlockChainingCryptPlugin extends AESCryptDelegatePlugin { @@ -2473,40 +2450,43 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec return true; } } - } - - public static class GHASHPlugin extends InvocationPlugin { - - public GHASHPlugin() { - super("processBlocks", byte[].class, int.class, int.class, long[].class, long[].class); - } @Override - public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, - ValueNode data, ValueNode inOffset, ValueNode blocks, ValueNode state, ValueNode hashSubkey) { - try (InvocationPluginHelper helper = new InvocationPluginHelper(b, targetMethod)) { - ValueNode dataAddress = helper.arrayElementPointer(data, JavaKind.Byte, inOffset); - ValueNode stateAddress = helper.arrayStart(state, JavaKind.Long); - ValueNode hashSubkeyAddress = helper.arrayStart(hashSubkey, JavaKind.Long); - b.add(new GHASHProcessBlocksNode(stateAddress, hashSubkeyAddress, dataAddress, blocks)); - return true; - } + public final boolean isApplicable(Architecture arch) { + return CipherBlockChainingAESNode.isSupported(arch); } } - private static void registerAESPlugins(InvocationPlugins plugins, Replacements replacements, Architecture arch) { - Registration r = new Registration(plugins, "com.sun.crypto.provider.AESCrypt", replacements); - r.registerConditional(AESNode.isSupported(arch), new AESCryptPlugin(ENCRYPT)); - r.registerConditional(AESNode.isSupported(arch), new AESCryptPlugin(DECRYPT)); + private static void registerAESPlugins(InvocationPlugins plugins) { + Registration r = new Registration(plugins, "com.sun.crypto.provider.AESCrypt"); + r.register(new AESCryptPlugin(ENCRYPT)); + r.register(new AESCryptPlugin(DECRYPT)); } - private static void registerGHASHPlugin(InvocationPlugins plugins, Replacements replacements, Architecture arch) { - Registration r = new Registration(plugins, "com.sun.crypto.provider.GHASH", replacements); - r.registerConditional(GHASHProcessBlocksNode.isSupported(arch), new GHASHPlugin()); + private static void registerGHASHPlugin(InvocationPlugins plugins) { + Registration r = new Registration(plugins, "com.sun.crypto.provider.GHASH"); + r.register(new ConditionalInvocationPlugin("processBlocks", byte[].class, int.class, int.class, long[].class, long[].class) { + @Override + public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, + ValueNode data, ValueNode inOffset, ValueNode blocks, ValueNode state, ValueNode hashSubkey) { + try (InvocationPluginHelper helper = new InvocationPluginHelper(b, targetMethod)) { + ValueNode dataAddress = helper.arrayElementPointer(data, JavaKind.Byte, inOffset); + ValueNode stateAddress = helper.arrayStart(state, JavaKind.Long); + ValueNode hashSubkeyAddress = helper.arrayStart(hashSubkey, JavaKind.Long); + b.add(new GHASHProcessBlocksNode(stateAddress, hashSubkeyAddress, dataAddress, blocks)); + return true; + } + } + + @Override + public boolean isApplicable(Architecture arch) { + return GHASHProcessBlocksNode.isSupported(arch); + } + }); } - private static void registerBigIntegerPlugins(InvocationPlugins plugins, Replacements replacements) { - Registration r = new Registration(plugins, BigInteger.class, replacements); + private static void registerBigIntegerPlugins(InvocationPlugins plugins) { + Registration r = new Registration(plugins, BigInteger.class); r.register(new InvocationPlugin("implMultiplyToLen", int[].class, int.class, int[].class, int.class, int[].class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode x, ValueNode xlen, ValueNode y, ValueNode ylen, ValueNode z) { @@ -2551,17 +2531,8 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec }); } - private static boolean hasEnsureMaterializedForStackWalk() { - try { - Thread.class.getDeclaredMethod("ensureMaterializedForStackWalk", Object.class); - } catch (Exception e) { - return false; - } - return true; - } - - private static void registerThreadPlugins(InvocationPlugins plugins, Replacements replacements) { - Registration r = new Registration(plugins, Thread.class, replacements); + private static void registerThreadPlugins(InvocationPlugins plugins) { + Registration r = new Registration(plugins, Thread.class); r.register(new InvocationPlugin("onSpinWait") { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) { @@ -2569,28 +2540,19 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec return true; } }); - if (hasEnsureMaterializedForStackWalk()) { - r.register(new InvocationPlugin("ensureMaterializedForStackWalk", Object.class) { - @Override - public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object) { - b.add(new BlackholeNode(object, "ensureMaterializedForStackWalk")); - return true; - } - }); - } + r.register(new InvocationPlugin("ensureMaterializedForStackWalk", Object.class) { + @Override + public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object) { + b.add(new BlackholeNode(object, "ensureMaterializedForStackWalk")); + return true; + } + }); } - public static class MessageDigestPlugin extends InvocationPlugin { - - public interface MessageDigestSupplier { - MessageDigestNode create(ValueNode buf, ValueNode state); - } - - private final MessageDigestSupplier supplier; + public abstract static class MessageDigestPlugin extends ConditionalInvocationPlugin { - public MessageDigestPlugin(MessageDigestSupplier supplier) { + public MessageDigestPlugin() { super("implCompress0", Receiver.class, byte[].class, int.class); - this.supplier = supplier; } @Override @@ -2603,36 +2565,78 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec ValueNode bufStart = helper.arrayElementPointer(buf, JavaKind.Byte, ofs); ValueNode state = helper.loadField(nonNullReceiver, stateField); ValueNode stateStart = helper.arrayStart(state, getStateElementType()); - b.add(supplier.create(bufStart, stateStart)); + b.add(createMessageDigest(bufStart, stateStart)); return true; } } + public abstract MessageDigestNode createMessageDigest(ValueNode buf, ValueNode state); + protected JavaKind getStateElementType() { return JavaKind.Int; } } - private static void registerMessageDigestPlugins(InvocationPlugins plugins, Replacements replacements, Architecture arch) { - Registration rSha1 = new Registration(plugins, "sun.security.provider.SHA", replacements); - rSha1.registerConditional(SHA1Node.isSupported(arch), new MessageDigestPlugin(SHA1Node::new)); + private static void registerMessageDigestPlugins(InvocationPlugins plugins) { + Registration rSha1 = new Registration(plugins, "sun.security.provider.SHA"); + rSha1.register(new MessageDigestPlugin() { + @Override + public MessageDigestNode createMessageDigest(ValueNode buf, ValueNode state) { + return new SHA1Node(buf, state); + } + + @Override + public boolean isApplicable(Architecture arch) { + return SHA1Node.isSupported(arch); + } + }); + + Registration rSha2 = new Registration(plugins, "sun.security.provider.SHA2"); + rSha2.register(new MessageDigestPlugin() { + @Override + public MessageDigestNode createMessageDigest(ValueNode buf, ValueNode state) { + return new SHA256Node(buf, state); + } - Registration rSha2 = new Registration(plugins, "sun.security.provider.SHA2", replacements); - rSha2.registerConditional(SHA256Node.isSupported(arch), new MessageDigestPlugin(SHA256Node::new)); + @Override + public boolean isApplicable(Architecture arch) { + return SHA256Node.isSupported(arch); + } + }); + + Registration rSha5 = new Registration(plugins, "sun.security.provider.SHA5"); + rSha5.register(new MessageDigestPlugin() { + @Override + public MessageDigestNode createMessageDigest(ValueNode buf, ValueNode state) { + return new SHA512Node(buf, state); + } + + @Override + public boolean isApplicable(Architecture arch) { + return SHA512Node.isSupported(arch); + } - Registration rSha5 = new Registration(plugins, "sun.security.provider.SHA5", replacements); - rSha5.registerConditional(SHA512Node.isSupported(arch), new MessageDigestPlugin(SHA512Node::new) { @Override protected JavaKind getStateElementType() { return JavaKind.Long; } }); - Registration rMD5 = new Registration(plugins, "sun.security.provider.MD5", replacements); - rMD5.register(new MessageDigestPlugin(MD5Node::new)); + Registration rMD5 = new Registration(plugins, "sun.security.provider.MD5"); + rMD5.register(new MessageDigestPlugin() { + @Override + public MessageDigestNode createMessageDigest(ValueNode buf, ValueNode state) { + return new MD5Node(buf, state); + } + + @Override + public boolean isApplicable(Architecture arch) { + return true; + } + }); - Registration rSha3 = new Registration(plugins, "sun.security.provider.SHA3", replacements); - rSha3.registerConditional(MessageDigestNode.SHA3Node.isSupported(arch), new InvocationPlugin("implCompress0", InvocationPlugin.Receiver.class, byte[].class, int.class) { + Registration rSha3 = new Registration(plugins, "sun.security.provider.SHA3"); + rSha3.register(new ConditionalInvocationPlugin("implCompress0", InvocationPlugin.Receiver.class, byte[].class, int.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode buf, ValueNode ofs) { try (InvocationPluginHelper helper = new InvocationPluginHelper(b, targetMethod)) { @@ -2647,15 +2651,20 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec JavaKind stateElementKind = stateField.getType().getComponentType().getJavaKind(); ValueNode stateStart = helper.arrayStart(state, stateElementKind); ValueNode blockSize = helper.loadField(nonNullReceiver, blockSizeField); - b.add(new MessageDigestNode.SHA3Node(bufStart, stateStart, blockSize)); + b.add(new SHA3Node(bufStart, stateStart, blockSize)); return true; } } + + @Override + public boolean isApplicable(Architecture arch) { + return SHA3Node.isSupported(arch); + } }); } - private static void registerStringCodingPlugins(InvocationPlugins plugins, Replacements replacements) { - Registration r = new Registration(plugins, "java.lang.StringCoding", replacements); + private static void registerStringCodingPlugins(InvocationPlugins plugins) { + Registration r = new Registration(plugins, "java.lang.StringCoding"); r.register(new InvocationPlugin("implEncodeISOArray", byte[].class, int.class, byte[].class, int.class, int.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode sa, ValueNode sp, @@ -2699,7 +2708,7 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec } }); - r = new Registration(plugins, "sun.nio.cs.ISO_8859_1$Encoder", replacements); + r = new Registration(plugins, "sun.nio.cs.ISO_8859_1$Encoder"); r.register(new InvocationPlugin("implEncodeISOArray", char[].class, int.class, byte[].class, int.class, int.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode sa, ValueNode sp, @@ -2714,7 +2723,28 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec }); } - public static class VectorizedHashCodeInvocationPlugin extends InlineOnlyInvocationPlugin { + public static class VectorizedMismatchInvocationPlugin extends InlineOnlyConditionalInvocationPlugin { + + public VectorizedMismatchInvocationPlugin() { + super("vectorizedMismatch", Object.class, long.class, Object.class, long.class, int.class, int.class); + } + + @Override + public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, + ValueNode aObject, ValueNode aOffset, ValueNode bObject, ValueNode bOffset, ValueNode length, ValueNode log2ArrayIndexScale) { + ValueNode aAddr = b.add(new ComputeObjectAddressNode(aObject, aOffset)); + ValueNode bAddr = b.add(new ComputeObjectAddressNode(bObject, bOffset)); + b.addPush(JavaKind.Int, new VectorizedMismatchNode(aAddr, bAddr, length, log2ArrayIndexScale)); + return true; + } + + @Override + public final boolean isApplicable(Architecture arch) { + return VectorizedMismatchNode.isSupported(arch); + } + } + + public static class VectorizedHashCodeInvocationPlugin extends InlineOnlyConditionalInvocationPlugin { // Sync with ArraysSupport.java public static final int T_BOOLEAN = 4; @@ -2726,8 +2756,8 @@ public static class VectorizedHashCodeInvocationPlugin extends InlineOnlyInvocat public static final int T_INT = 10; public static final int T_LONG = 11; - public VectorizedHashCodeInvocationPlugin(String name) { - super(name, Object.class, int.class, int.class, int.class, int.class); + public VectorizedHashCodeInvocationPlugin() { + super("vectorizedHashCode", Object.class, int.class, int.class, int.class, int.class); } @Override @@ -2757,5 +2787,10 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec } return false; } + + @Override + public final boolean isApplicable(Architecture arch) { + return VectorizedHashCodeNode.isSupported(arch); + } } } diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/TargetGraphBuilderPlugins.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/TargetGraphBuilderPlugins.java index a0eafc3f8f50..5f9de13f55c1 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/TargetGraphBuilderPlugins.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/TargetGraphBuilderPlugins.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 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 @@ -25,11 +25,8 @@ package jdk.graal.compiler.replacements; import jdk.graal.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins; -import jdk.graal.compiler.nodes.spi.Replacements; import jdk.graal.compiler.options.OptionValues; -import jdk.vm.ci.code.Architecture; - public interface TargetGraphBuilderPlugins { - void register(Plugins plugins, Replacements replacements, Architecture arch, boolean registerForeignCallMath, OptionValues options); + void registerPlugins(Plugins plugins, OptionValues options); } diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/aarch64/AArch64GraphBuilderPlugins.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/aarch64/AArch64GraphBuilderPlugins.java index a4664899dfe2..3027ba5d9495 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/aarch64/AArch64GraphBuilderPlugins.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/aarch64/AArch64GraphBuilderPlugins.java @@ -25,6 +25,7 @@ package jdk.graal.compiler.replacements.aarch64; import java.lang.reflect.Type; +import java.util.Arrays; import jdk.graal.compiler.core.common.GraalOptions; import jdk.graal.compiler.core.common.Stride; @@ -41,18 +42,17 @@ import jdk.graal.compiler.nodes.calc.MaxNode; import jdk.graal.compiler.nodes.calc.MinNode; import jdk.graal.compiler.nodes.calc.NarrowNode; +import jdk.graal.compiler.nodes.calc.ReinterpretNode; import jdk.graal.compiler.nodes.calc.RoundFloatToIntegerNode; import jdk.graal.compiler.nodes.calc.ZeroExtendNode; import jdk.graal.compiler.nodes.extended.JavaReadNode; import jdk.graal.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins; import jdk.graal.compiler.nodes.graphbuilderconf.GraphBuilderContext; import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugin; -import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugin.InlineOnlyInvocationPlugin; import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugins; import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration; import jdk.graal.compiler.nodes.java.ArrayLengthNode; import jdk.graal.compiler.nodes.memory.address.IndexAddressNode; -import jdk.graal.compiler.nodes.spi.Replacements; import jdk.graal.compiler.options.OptionValues; import jdk.graal.compiler.replacements.InvocationPluginHelper; import jdk.graal.compiler.replacements.SnippetSubstitutionInvocationPlugin; @@ -63,39 +63,40 @@ import jdk.graal.compiler.replacements.StringUTF16Snippets; import jdk.graal.compiler.replacements.TargetGraphBuilderPlugins; import jdk.graal.compiler.replacements.nodes.ArrayCompareToNode; +import jdk.graal.compiler.replacements.nodes.ArrayFillNode; import jdk.graal.compiler.replacements.nodes.ArrayIndexOfNode; -import jdk.graal.compiler.replacements.nodes.BinaryMathIntrinsicNode; import jdk.graal.compiler.replacements.nodes.FloatToHalfFloatNode; import jdk.graal.compiler.replacements.nodes.HalfFloatToFloatNode; -import jdk.graal.compiler.replacements.nodes.UnaryMathIntrinsicNode; -import jdk.vm.ci.code.Architecture; +import jdk.vm.ci.meta.DeoptimizationAction; import jdk.vm.ci.meta.JavaKind; import jdk.vm.ci.meta.ResolvedJavaMethod; public class AArch64GraphBuilderPlugins implements TargetGraphBuilderPlugins { @Override - public void register(Plugins plugins, Replacements replacements, Architecture arch, boolean registerForeignCallMath, OptionValues options) { - register(plugins, replacements, registerForeignCallMath, options); + public void registerPlugins(Plugins plugins, OptionValues options) { + register(plugins, options); } - public static void register(Plugins plugins, Replacements replacements, boolean registerForeignCallMath, OptionValues options) { + public static void register(Plugins plugins, OptionValues options) { InvocationPlugins invocationPlugins = plugins.getInvocationPlugins(); invocationPlugins.defer(new Runnable() { @Override public void run() { - registerFloatPlugins(invocationPlugins, replacements); - registerMathPlugins(invocationPlugins, registerForeignCallMath); + registerFloatPlugins(invocationPlugins); + registerMathPlugins(invocationPlugins); registerStrictMathPlugins(invocationPlugins); + registerArraysPlugins(invocationPlugins); + if (GraalOptions.EmitStringSubstitutions.getValue(options)) { - registerStringLatin1Plugins(invocationPlugins, replacements); - registerStringUTF16Plugins(invocationPlugins, replacements); + registerStringLatin1Plugins(invocationPlugins); + registerStringUTF16Plugins(invocationPlugins); } } }); } - private static void registerFloatPlugins(InvocationPlugins plugins, Replacements replacements) { - Registration r = new Registration(plugins, Float.class, replacements); + private static void registerFloatPlugins(InvocationPlugins plugins) { + Registration r = new Registration(plugins, Float.class); r.register(new InvocationPlugin("float16ToFloat", short.class) { @Override @@ -113,23 +114,8 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec }); } - private static void registerMathPlugins(InvocationPlugins plugins, boolean registerForeignCallMath) { + private static void registerMathPlugins(InvocationPlugins plugins) { Registration r = new Registration(plugins, Math.class); - if (registerForeignCallMath) { - registerUnaryMath(r, "sin", UnaryMathIntrinsicNode.UnaryOperation.SIN); - registerUnaryMath(r, "cos", UnaryMathIntrinsicNode.UnaryOperation.COS); - registerUnaryMath(r, "tan", UnaryMathIntrinsicNode.UnaryOperation.TAN); - registerUnaryMath(r, "exp", UnaryMathIntrinsicNode.UnaryOperation.EXP); - registerUnaryMath(r, "log", UnaryMathIntrinsicNode.UnaryOperation.LOG); - registerUnaryMath(r, "log10", UnaryMathIntrinsicNode.UnaryOperation.LOG10); - r.register(new InlineOnlyInvocationPlugin("pow", double.class, double.class) { - @Override - public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode x, ValueNode y) { - b.push(JavaKind.Double, b.append(BinaryMathIntrinsicNode.create(x, y, BinaryMathIntrinsicNode.BinaryOperation.POW))); - return true; - } - }); - } registerFMA(r); registerMinMax(r); @@ -217,16 +203,6 @@ private static void registerStrictMathPlugins(InvocationPlugins plugins) { registerMinMax(r); } - private static void registerUnaryMath(Registration r, String name, UnaryMathIntrinsicNode.UnaryOperation operation) { - r.register(new InlineOnlyInvocationPlugin(name, double.class) { - @Override - public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) { - b.push(JavaKind.Double, b.append(UnaryMathIntrinsicNode.create(value, operation))); - return true; - } - }); - } - private static final class ArrayCompareToPlugin extends InvocationPlugin { private final Stride strideA; private final Stride strideB; @@ -268,8 +244,8 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec } } - private static void registerStringLatin1Plugins(InvocationPlugins plugins, Replacements replacements) { - Registration r = new Registration(plugins, "java.lang.StringLatin1", replacements); + private static void registerStringLatin1Plugins(InvocationPlugins plugins) { + Registration r = new Registration(plugins, "java.lang.StringLatin1"); r.setAllowOverwrite(true); r.register(new ArrayCompareToPlugin(Stride.S1, Stride.S1, "compareTo", byte[].class, byte[].class)); r.register(new ArrayCompareToPlugin(Stride.S1, Stride.S2, "compareToUTF16", byte[].class, byte[].class)); @@ -350,8 +326,8 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec }); } - private static void registerStringUTF16Plugins(InvocationPlugins plugins, Replacements replacements) { - Registration r = new Registration(plugins, "java.lang.StringUTF16", replacements); + private static void registerStringUTF16Plugins(InvocationPlugins plugins) { + Registration r = new Registration(plugins, "java.lang.StringUTF16"); r.setAllowOverwrite(true); r.register(new ArrayCompareToPlugin(Stride.S2, Stride.S2, "compareTo", byte[].class, byte[].class)); r.register(new ArrayCompareToPlugin(Stride.S2, Stride.S1, true, "compareToLatin1", byte[].class, byte[].class)); @@ -430,7 +406,7 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec return true; } }); - Registration r2 = new Registration(plugins, StringUTF16Snippets.class, replacements); + Registration r2 = new Registration(plugins, StringUTF16Snippets.class); r2.register(new InvocationPlugin("getChar", byte[].class, int.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode arg1, ValueNode arg2) { @@ -441,4 +417,41 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec } }); } + + public static class ArrayFillInvocationPlugin extends InvocationPlugin { + private final JavaKind kind; + + public ArrayFillInvocationPlugin(JavaKind kind, Type... argumentTypes) { + super("fill", argumentTypes); + this.kind = kind; + } + + @SuppressWarnings("try") + @Override + public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode array, ValueNode value) { + ConstantNode arrayBaseOffset = ConstantNode.forLong(b.getMetaAccess().getArrayBaseOffset(this.kind), b.getGraph()); + ValueNode nonNullArray = b.nullCheckedValue(array, DeoptimizationAction.None); + ValueNode arrayLength = b.add(new ArrayLengthNode(nonNullArray)); + ValueNode castedValue = value; + if (this.kind == JavaKind.Float) { + castedValue = ReinterpretNode.create(JavaKind.Int, value, NodeView.DEFAULT); + } else if (this.kind == JavaKind.Double) { + castedValue = ReinterpretNode.create(JavaKind.Long, value, NodeView.DEFAULT); + } + b.add(new ArrayFillNode(nonNullArray, arrayBaseOffset, arrayLength, castedValue, this.kind)); + return true; + } + } + + private static void registerArraysPlugins(InvocationPlugins plugins) { + Registration r = new Registration(plugins, Arrays.class); + r.register(new ArrayFillInvocationPlugin(JavaKind.Boolean, boolean[].class, boolean.class)); + r.register(new ArrayFillInvocationPlugin(JavaKind.Byte, byte[].class, byte.class)); + r.register(new ArrayFillInvocationPlugin(JavaKind.Char, char[].class, char.class)); + r.register(new ArrayFillInvocationPlugin(JavaKind.Short, short[].class, short.class)); + r.register(new ArrayFillInvocationPlugin(JavaKind.Int, int[].class, int.class)); + r.register(new ArrayFillInvocationPlugin(JavaKind.Float, float[].class, float.class)); + r.register(new ArrayFillInvocationPlugin(JavaKind.Long, long[].class, long.class)); + r.register(new ArrayFillInvocationPlugin(JavaKind.Double, double[].class, double.class)); + } } diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/amd64/AMD64GraphBuilderPlugins.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/amd64/AMD64GraphBuilderPlugins.java index 31603eb87b32..f0f66c87ac94 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/amd64/AMD64GraphBuilderPlugins.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/amd64/AMD64GraphBuilderPlugins.java @@ -61,11 +61,11 @@ import jdk.graal.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins; import jdk.graal.compiler.nodes.graphbuilderconf.GraphBuilderContext; 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.InvocationPlugins.Registration; import jdk.graal.compiler.nodes.java.ArrayLengthNode; import jdk.graal.compiler.nodes.memory.address.IndexAddressNode; -import jdk.graal.compiler.nodes.spi.Replacements; import jdk.graal.compiler.options.OptionValues; import jdk.graal.compiler.replacements.InvocationPluginHelper; import jdk.graal.compiler.replacements.SnippetSubstitutionInvocationPlugin; @@ -83,105 +83,117 @@ import jdk.graal.compiler.replacements.nodes.HalfFloatToFloatNode; import jdk.graal.compiler.replacements.nodes.UnaryMathIntrinsicNode; import jdk.graal.compiler.replacements.nodes.UnaryMathIntrinsicNode.UnaryOperation; -import jdk.vm.ci.amd64.AMD64; -import jdk.vm.ci.amd64.AMD64.CPUFeature; import jdk.vm.ci.code.Architecture; import jdk.vm.ci.meta.JavaKind; import jdk.vm.ci.meta.ResolvedJavaMethod; public class AMD64GraphBuilderPlugins implements TargetGraphBuilderPlugins { @Override - public void register(Plugins plugins, Replacements replacements, Architecture architecture, boolean registerForeignCallMath, OptionValues options) { - register(plugins, replacements, (AMD64) architecture, options); + public void registerPlugins(Plugins plugins, OptionValues options) { + register(plugins, options); } - public static void register(Plugins plugins, Replacements replacements, AMD64 arch, OptionValues options) { + public static void register(Plugins plugins, OptionValues options) { InvocationPlugins invocationPlugins = plugins.getInvocationPlugins(); invocationPlugins.defer(new Runnable() { @Override public void run() { - registerIntegerLongPlugins(invocationPlugins, JavaKind.Int, arch, replacements); - registerIntegerLongPlugins(invocationPlugins, JavaKind.Long, arch, replacements); - registerFloatDoublePlugins(invocationPlugins, JavaKind.Float, arch, replacements); - registerFloatDoublePlugins(invocationPlugins, JavaKind.Double, arch, replacements); - registerFloatPlugins(invocationPlugins, arch, replacements); + registerIntegerLongPlugins(invocationPlugins, JavaKind.Int); + registerIntegerLongPlugins(invocationPlugins, JavaKind.Long); + registerFloatDoublePlugins(invocationPlugins, JavaKind.Float); + registerFloatDoublePlugins(invocationPlugins, JavaKind.Double); + registerFloatPlugins(invocationPlugins); if (GraalOptions.EmitStringSubstitutions.getValue(options)) { - registerStringLatin1Plugins(invocationPlugins, replacements); - registerStringUTF16Plugins(invocationPlugins, replacements); + registerStringLatin1Plugins(invocationPlugins); + registerStringUTF16Plugins(invocationPlugins); } - registerMathPlugins(invocationPlugins, arch, replacements); - registerStrictMathPlugins(invocationPlugins, arch, replacements); - registerArraysEqualsPlugins(invocationPlugins, replacements); + registerMathPlugins(invocationPlugins); + registerStrictMathPlugins(invocationPlugins); + registerArraysEqualsPlugins(invocationPlugins); } }); } - private static void registerIntegerLongPlugins(InvocationPlugins plugins, JavaKind kind, AMD64 arch, Replacements replacements) { + private static void registerIntegerLongPlugins(InvocationPlugins plugins, JavaKind kind) { Class declaringClass = kind.toBoxedJavaClass(); Class type = kind.toJavaClass(); - Registration r = new Registration(plugins, declaringClass, replacements); - r.registerConditional(arch.getFeatures().contains(CPUFeature.BMI2), new InvocationPlugin("compress", type, type) { + Registration r = new Registration(plugins, declaringClass); + r.register(new ConditionalInvocationPlugin("compress", type, type) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value, ValueNode mask) { b.push(kind, b.append(new CompressBitsNode(value, mask))); return true; } + + @Override + public boolean isApplicable(Architecture arch) { + return CompressBitsNode.isSupported(arch); + } }); - r.registerConditional(arch.getFeatures().contains(CPUFeature.BMI2), new InvocationPlugin("expand", type, type) { + r.register(new ConditionalInvocationPlugin("expand", type, type) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value, ValueNode mask) { b.push(kind, b.append(new ExpandBitsNode(value, mask))); return true; } - }); - } - private static boolean supportsFeature(AMD64 arch, String feature) { - try { - return arch.getFeatures().contains(CPUFeature.valueOf(feature)); - } catch (IllegalArgumentException e) { - return false; - } + @Override + public boolean isApplicable(Architecture arch) { + return ExpandBitsNode.isSupported(arch); + } + }); } - private static void registerFloatPlugins(InvocationPlugins plugins, AMD64 arch, Replacements replacements) { - Registration r = new Registration(plugins, Float.class, replacements); - - boolean supportsF16C = supportsFeature(arch, "F16C"); - - r.registerConditional(supportsF16C, new InvocationPlugin("float16ToFloat", short.class) { + private static void registerFloatPlugins(InvocationPlugins plugins) { + Registration r = new Registration(plugins, Float.class); + r.register(new ConditionalInvocationPlugin("float16ToFloat", short.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) { b.push(JavaKind.Float, b.append(new HalfFloatToFloatNode(value))); return true; } + + @Override + public boolean isApplicable(Architecture arch) { + return HalfFloatToFloatNode.isSupported(arch); + } }); - r.registerConditional(supportsF16C, new InvocationPlugin("floatToFloat16", float.class) { + r.register(new ConditionalInvocationPlugin("floatToFloat16", float.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) { b.push(JavaKind.Short, b.append(new FloatToHalfFloatNode(value))); return true; } + + @Override + public boolean isApplicable(Architecture arch) { + return FloatToHalfFloatNode.isSupported(arch); + } }); } - private static void registerFloatDoublePlugins(InvocationPlugins plugins, JavaKind kind, AMD64 arch, Replacements replacements) { + private static void registerFloatDoublePlugins(InvocationPlugins plugins, JavaKind kind) { Class declaringClass = kind.toBoxedJavaClass(); Class type = kind.toJavaClass(); - Registration r = new Registration(plugins, declaringClass, replacements); + Registration r = new Registration(plugins, declaringClass); - r.registerConditional(arch.getFeatures().contains(CPUFeature.AVX512DQ), new InvocationPlugin("isInfinite", type) { + r.register(new ConditionalInvocationPlugin("isInfinite", type) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) { b.push(JavaKind.Boolean, b.append(new FloatTypeTestNode(value, IS_INFINITE))); return true; } + + @Override + public boolean isApplicable(Architecture arch) { + return FloatTypeTestNode.isSupported(arch); + } }); } - private static void registerMathPlugins(InvocationPlugins plugins, AMD64 arch, Replacements replacements) { - Registration r = new Registration(plugins, Math.class, replacements); + private static void registerMathPlugins(InvocationPlugins plugins) { + Registration r = new Registration(plugins, Math.class); registerUnaryMath(r, "log", LOG); registerUnaryMath(r, "log10", LOG10); registerUnaryMath(r, "exp", EXP); @@ -192,22 +204,32 @@ private static void registerMathPlugins(InvocationPlugins plugins, AMD64 arch, R registerUnaryMath(r, "tanh", TANH); registerUnaryMath(r, "cbrt", CBRT); - registerFMA(r, arch); - registerMinMax(r, arch); + registerFMA(r); + registerMinMax(r); - r.registerConditional(arch.getFeatures().contains(CPUFeature.AVX512VL), new InvocationPlugin("copySign", float.class, float.class) { + r.register(new ConditionalInvocationPlugin("copySign", float.class, float.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode magnitude, ValueNode sign) { b.addPush(JavaKind.Float, new CopySignNode(magnitude, sign)); return true; } + + @Override + public boolean isApplicable(Architecture arch) { + return CopySignNode.isSupported(arch); + } }); - r.registerConditional(arch.getFeatures().contains(CPUFeature.AVX512VL), new InvocationPlugin("copySign", double.class, double.class) { + r.register(new ConditionalInvocationPlugin("copySign", double.class, double.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode magnitude, ValueNode sign) { b.addPush(JavaKind.Double, new CopySignNode(magnitude, sign)); return true; } + + @Override + public boolean isApplicable(Architecture arch) { + return CopySignNode.isSupported(arch); + } }); r.register(new InvocationPlugin("round", float.class) { @Override @@ -225,8 +247,8 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec }); } - private static void registerFMA(Registration r, AMD64 arch) { - r.registerConditional(arch.getFeatures().contains(CPUFeature.FMA), new InvocationPlugin("fma", double.class, double.class, double.class) { + private static void registerFMA(Registration r) { + r.register(new ConditionalInvocationPlugin("fma", double.class, double.class, double.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, @@ -237,8 +259,13 @@ public boolean apply(GraphBuilderContext b, b.push(JavaKind.Double, b.append(new FusedMultiplyAddNode(na, nb, nc))); return true; } + + @Override + public boolean isApplicable(Architecture arch) { + return FusedMultiplyAddNode.isSupported(arch); + } }); - r.registerConditional(arch.getFeatures().contains(CPUFeature.FMA), new InvocationPlugin("fma", float.class, float.class, float.class) { + r.register(new ConditionalInvocationPlugin("fma", float.class, float.class, float.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, @@ -249,6 +276,11 @@ public boolean apply(GraphBuilderContext b, b.push(JavaKind.Float, b.append(new FusedMultiplyAddNode(na, nb, nc))); return true; } + + @Override + public boolean isApplicable(Architecture arch) { + return FusedMultiplyAddNode.isSupported(arch); + } }); } @@ -272,29 +304,39 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec }); } - private static void registerMinMax(Registration r, AMD64 arch) { + private static void registerMinMax(Registration r) { JavaKind[] supportedMinMaxKinds = {JavaKind.Float, JavaKind.Double}; for (JavaKind kind : supportedMinMaxKinds) { - r.registerConditional(arch.getFeatures().contains(CPUFeature.AVX), new InvocationPlugin("max", kind.toJavaClass(), kind.toJavaClass()) { + r.register(new ConditionalInvocationPlugin("max", kind.toJavaClass(), kind.toJavaClass()) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode x, ValueNode y) { b.push(kind, b.append(MaxNode.create(x, y, NodeView.DEFAULT))); return true; } + + @Override + public boolean isApplicable(Architecture arch) { + return MaxNode.isSupported(arch); + } }); - r.registerConditional(arch.getFeatures().contains(CPUFeature.AVX), new InvocationPlugin("min", kind.toJavaClass(), kind.toJavaClass()) { + r.register(new ConditionalInvocationPlugin("min", kind.toJavaClass(), kind.toJavaClass()) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode x, ValueNode y) { b.push(kind, b.append(MinNode.create(x, y, NodeView.DEFAULT))); return true; } + + @Override + public boolean isApplicable(Architecture arch) { + return MinNode.isSupported(arch); + } }); } } - private static void registerStrictMathPlugins(InvocationPlugins plugins, AMD64 arch, Replacements replacements) { - Registration r = new Registration(plugins, StrictMath.class, replacements); - registerMinMax(r, arch); + private static void registerStrictMathPlugins(InvocationPlugins plugins) { + Registration r = new Registration(plugins, StrictMath.class); + registerMinMax(r); } private static final class ArrayCompareToPlugin extends InvocationPlugin { @@ -338,8 +380,8 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec } } - private static void registerStringLatin1Plugins(InvocationPlugins plugins, Replacements replacements) { - Registration r = new Registration(plugins, "java.lang.StringLatin1", replacements); + private static void registerStringLatin1Plugins(InvocationPlugins plugins) { + Registration r = new Registration(plugins, "java.lang.StringLatin1"); r.setAllowOverwrite(true); r.register(new ArrayCompareToPlugin(Stride.S1, Stride.S1, "compareTo", byte[].class, byte[].class)); r.register(new ArrayCompareToPlugin(Stride.S1, Stride.S2, "compareToUTF16", byte[].class, byte[].class)); @@ -420,9 +462,9 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec }); } - private static void registerStringUTF16Plugins(InvocationPlugins plugins, Replacements replacements) { + private static void registerStringUTF16Plugins(InvocationPlugins plugins) { - Registration r = new Registration(plugins, "java.lang.StringUTF16", replacements); + Registration r = new Registration(plugins, "java.lang.StringUTF16"); r.setAllowOverwrite(true); r.register(new ArrayCompareToPlugin(Stride.S2, Stride.S2, "compareTo", byte[].class, byte[].class)); r.register(new ArrayCompareToPlugin(Stride.S2, Stride.S1, true, "compareToLatin1", byte[].class, byte[].class)); @@ -510,7 +552,7 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec return true; } }); - Registration r2 = new Registration(plugins, StringUTF16Snippets.class, replacements); + Registration r2 = new Registration(plugins, StringUTF16Snippets.class); r2.register(new InvocationPlugin("getChar", byte[].class, int.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode arg1, ValueNode arg2) { @@ -522,8 +564,8 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec }); } - private static void registerArraysEqualsPlugins(InvocationPlugins plugins, Replacements replacements) { - Registration r = new Registration(plugins, Arrays.class, replacements); + private static void registerArraysEqualsPlugins(InvocationPlugins plugins) { + Registration r = new Registration(plugins, Arrays.class); r.register(new StandardGraphBuilderPlugins.ArrayEqualsInvocationPlugin(JavaKind.Float, float[].class, float[].class)); r.register(new StandardGraphBuilderPlugins.ArrayEqualsInvocationPlugin(JavaKind.Double, double[].class, double[].class)); } diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/nodes/AESNode.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/nodes/AESNode.java index 1a40393487cb..7ab2372b22b8 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/nodes/AESNode.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/nodes/AESNode.java @@ -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 @@ -138,12 +138,11 @@ public static EnumSet minFeaturesAARCH64() { @SuppressWarnings("unlikely-arg-type") public static boolean isSupported(Architecture arch) { - if (arch instanceof AMD64) { - return ((AMD64) arch).getFeatures().containsAll(minFeaturesAMD64()); - } else if (arch instanceof AArch64) { - return ((AArch64) arch).getFeatures().containsAll(minFeaturesAARCH64()); - } - return false; + return switch (arch) { + case AMD64 amd64 -> amd64.getFeatures().containsAll(minFeaturesAMD64()); + case AArch64 aarch64 -> aarch64.getFeatures().containsAll(minFeaturesAARCH64()); + default -> false; + }; } @NodeIntrinsic @@ -166,11 +165,6 @@ public ForeignCallDescriptor getForeignCallDescriptor() { return cryptMode.isEncrypt() ? STUB_ENCRYPT : STUB_DECRYPT; } - @Override - public boolean canBeEmitted(Architecture arch) { - return isSupported(arch); - } - @Override public void emitIntrinsic(NodeLIRBuilderTool gen) { if (cryptMode.isEncrypt()) { diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/nodes/ArrayFillNode.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/nodes/ArrayFillNode.java index 93cfb2b76f46..6b11e431343f 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/nodes/ArrayFillNode.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/nodes/ArrayFillNode.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2024, 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 @@ -190,7 +190,7 @@ public ValueNode[] getForeignCallArguments() { @Override public void emitIntrinsic(NodeLIRBuilderTool gen) { - gen.getLIRGeneratorTool().emitArrayFill(elementKind, getRuntimeCheckedCPUFeatures(), gen.operand(arrayBase), gen.operand(offsetToFirstElement), gen.operand(arrayLength), + gen.getLIRGeneratorTool().emitArrayFill(elementKind, gen.operand(arrayBase), gen.operand(offsetToFirstElement), gen.operand(arrayLength), gen.operand(valueToFillWith)); } @@ -203,11 +203,6 @@ public static boolean isSupported(Architecture arch) { return (arch instanceof AArch64); } - @Override - public boolean canBeEmitted(Architecture arch) { - return isSupported(arch); - } - private static ForeignCallDescriptor createForeignCallDescriptor(JavaKind kind, Class cls) { LocationIdentity[] locs = new LocationIdentity[]{NamedLocationIdentity.getArrayLocation(kind)}; Class[] argTypes = new Class[]{Pointer.class, long.class, int.class, cls}; diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/nodes/CipherBlockChainingAESNode.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/nodes/CipherBlockChainingAESNode.java index 31d68b1d7f75..a4ddc09ec651 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/nodes/CipherBlockChainingAESNode.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/nodes/CipherBlockChainingAESNode.java @@ -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 @@ -137,12 +137,11 @@ public static EnumSet minFeaturesAARCH64() { @SuppressWarnings("unlikely-arg-type") public static boolean isSupported(Architecture arch) { - if (arch instanceof AMD64) { - return ((AMD64) arch).getFeatures().containsAll(minFeaturesAMD64()); - } else if (arch instanceof AArch64) { - return ((AArch64) arch).getFeatures().containsAll(minFeaturesAARCH64()); - } - return false; + return switch (arch) { + case AMD64 amd64 -> amd64.getFeatures().containsAll(minFeaturesAMD64()); + case AArch64 aarch64 -> aarch64.getFeatures().containsAll(minFeaturesAARCH64()); + default -> false; + }; } @NodeIntrinsic @@ -169,11 +168,6 @@ public ForeignCallDescriptor getForeignCallDescriptor() { return cryptMode.isEncrypt() ? STUB_ENCRYPT : STUB_DECRYPT; } - @Override - public boolean canBeEmitted(Architecture arch) { - return isSupported(arch); - } - @Override public void emitIntrinsic(NodeLIRBuilderTool gen) { if (cryptMode.isEncrypt()) { diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/nodes/CounterModeAESNode.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/nodes/CounterModeAESNode.java index 235314e239df..b15037a7aa7e 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/nodes/CounterModeAESNode.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/nodes/CounterModeAESNode.java @@ -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 @@ -130,12 +130,11 @@ public static EnumSet minFeaturesAARCH64() { @SuppressWarnings("unlikely-arg-type") public static boolean isSupported(Architecture arch) { - if (arch instanceof AMD64) { - return ((AMD64) arch).getFeatures().containsAll(minFeaturesAMD64()); - } else if (arch instanceof AArch64) { - return ((AArch64) arch).getFeatures().containsAll(minFeaturesAARCH64()); - } - return false; + return switch (arch) { + case AMD64 amd64 -> amd64.getFeatures().containsAll(minFeaturesAMD64()); + case AArch64 aarch64 -> aarch64.getFeatures().containsAll(minFeaturesAARCH64()); + default -> false; + }; } @NodeIntrinsic @@ -173,11 +172,6 @@ public ForeignCallDescriptor getForeignCallDescriptor() { return STUB; } - @Override - public boolean canBeEmitted(Architecture arch) { - return isSupported(arch); - } - @Override public void emitIntrinsic(NodeLIRBuilderTool gen) { GraalError.guarantee(inputs.size() == 7, "inputs do not match"); diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/nodes/FloatToHalfFloatNode.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/nodes/FloatToHalfFloatNode.java index bb177f485a19..27b48ed2753e 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/nodes/FloatToHalfFloatNode.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/nodes/FloatToHalfFloatNode.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 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 @@ -37,6 +37,9 @@ import jdk.graal.compiler.nodes.spi.LIRLowerable; import jdk.graal.compiler.nodes.spi.NodeLIRBuilderTool; +import jdk.vm.ci.aarch64.AArch64; +import jdk.vm.ci.amd64.AMD64; +import jdk.vm.ci.code.Architecture; import jdk.vm.ci.meta.JavaConstant; import jdk.vm.ci.meta.JavaKind; import jdk.vm.ci.meta.Value; @@ -67,4 +70,13 @@ public void generate(NodeLIRBuilderTool gen) { Value result = gen.getLIRGeneratorTool().getArithmetic().emitFloatToHalfFloat(gen.operand(getValue())); gen.setResult(this, result); } + + @SuppressWarnings("unlikely-arg-type") + public static boolean isSupported(Architecture arch) { + return switch (arch) { + case AMD64 amd64 -> amd64.getFeatures().contains(AMD64.CPUFeature.F16C); + case AArch64 aarch64 -> true; + default -> false; + }; + } } diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/nodes/GHASHProcessBlocksNode.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/nodes/GHASHProcessBlocksNode.java index 90f7fef352d3..8616910ad122 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/nodes/GHASHProcessBlocksNode.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/nodes/GHASHProcessBlocksNode.java @@ -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 @@ -104,12 +104,11 @@ public static EnumSet minFeaturesAARCH64() { @SuppressWarnings("unlikely-arg-type") public static boolean isSupported(Architecture arch) { - if (arch instanceof AMD64) { - return ((AMD64) arch).getFeatures().containsAll(minFeaturesAMD64()); - } else if (arch instanceof AArch64) { - return ((AArch64) arch).getFeatures().containsAll(minFeaturesAARCH64()); - } - return false; + return switch (arch) { + case AMD64 amd64 -> amd64.getFeatures().containsAll(minFeaturesAMD64()); + case AArch64 aarch64 -> aarch64.getFeatures().containsAll(minFeaturesAARCH64()); + default -> false; + }; } @NodeIntrinsic @@ -131,11 +130,6 @@ public ForeignCallDescriptor getForeignCallDescriptor() { return STUB; } - @Override - public boolean canBeEmitted(Architecture arch) { - return isSupported(arch); - } - @Override public void emitIntrinsic(NodeLIRBuilderTool gen) { gen.getLIRGeneratorTool().emitGHASHProcessBlocks(gen.operand(state), gen.operand(hashSubkey), gen.operand(data), gen.operand(blocks)); diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/nodes/HalfFloatToFloatNode.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/nodes/HalfFloatToFloatNode.java index 2dd80b38ca55..1888e2bfe955 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/nodes/HalfFloatToFloatNode.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/nodes/HalfFloatToFloatNode.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 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 @@ -37,6 +37,9 @@ import jdk.graal.compiler.nodes.spi.LIRLowerable; import jdk.graal.compiler.nodes.spi.NodeLIRBuilderTool; +import jdk.vm.ci.aarch64.AArch64; +import jdk.vm.ci.amd64.AMD64; +import jdk.vm.ci.code.Architecture; import jdk.vm.ci.meta.JavaKind; import jdk.vm.ci.meta.Value; @@ -66,4 +69,13 @@ public void generate(NodeLIRBuilderTool gen) { Value result = gen.getLIRGeneratorTool().getArithmetic().emitHalfFloatToFloat(gen.operand(getValue())); gen.setResult(this, result); } + + @SuppressWarnings("unlikely-arg-type") + public static boolean isSupported(Architecture arch) { + return switch (arch) { + case AMD64 amd64 -> amd64.getFeatures().contains(AMD64.CPUFeature.F16C); + case AArch64 aarch64 -> true; + default -> false; + }; + } } diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/nodes/IntrinsicMethodNodeInterface.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/nodes/IntrinsicMethodNodeInterface.java index 6366ed5623c6..a452ce2a2602 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/nodes/IntrinsicMethodNodeInterface.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/nodes/IntrinsicMethodNodeInterface.java @@ -34,7 +34,6 @@ import jdk.graal.compiler.nodes.spi.LIRLowerable; import jdk.graal.compiler.nodes.spi.NodeLIRBuilderTool; -import jdk.vm.ci.code.Architecture; import jdk.vm.ci.meta.Value; /** @@ -71,14 +70,6 @@ default void generate(NodeLIRBuilderTool gen) { emitIntrinsic(gen); } - /** - * Returns true if the current architecture supports this stub. - */ - @SuppressWarnings("unused") - default boolean canBeEmitted(Architecture arch) { - return true; - } - /** * Emit the method body. */ diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/nodes/MessageDigestNode.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/nodes/MessageDigestNode.java index 21cdd8888935..ce07d3778945 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/nodes/MessageDigestNode.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/nodes/MessageDigestNode.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 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 @@ -107,17 +107,11 @@ public static EnumSet minFeaturesAARCH64() { @SuppressWarnings("unlikely-arg-type") public static boolean isSupported(Architecture arch) { - if (arch instanceof AMD64) { - return ((AMD64) arch).getFeatures().containsAll(minFeaturesAMD64()); - } else if (arch instanceof AArch64) { - return ((AArch64) arch).getFeatures().containsAll(minFeaturesAARCH64()); - } - return false; - } - - @Override - public boolean canBeEmitted(Architecture arch) { - return isSupported(arch); + return switch (arch) { + case AMD64 amd64 -> amd64.getFeatures().containsAll(minFeaturesAMD64()); + case AArch64 aarch64 -> aarch64.getFeatures().containsAll(minFeaturesAARCH64()); + default -> false; + }; } @Override @@ -165,17 +159,11 @@ public static EnumSet minFeaturesAARCH64() { @SuppressWarnings("unlikely-arg-type") public static boolean isSupported(Architecture arch) { - if (arch instanceof AMD64) { - return ((AMD64) arch).getFeatures().containsAll(minFeaturesAMD64()); - } else if (arch instanceof AArch64) { - return ((AArch64) arch).getFeatures().containsAll(minFeaturesAARCH64()); - } - return false; - } - - @Override - public boolean canBeEmitted(Architecture arch) { - return isSupported(arch); + return switch (arch) { + case AMD64 amd64 -> amd64.getFeatures().containsAll(minFeaturesAMD64()); + case AArch64 aarch64 -> aarch64.getFeatures().containsAll(minFeaturesAARCH64()); + default -> false; + }; } @Override @@ -230,17 +218,11 @@ public static EnumSet minFeaturesAARCH64() { @SuppressWarnings("unlikely-arg-type") public static boolean isSupported(Architecture arch) { - if (arch instanceof AMD64) { - return ((AMD64) arch).getFeatures().containsAll(minFeaturesAMD64()); - } else if (arch instanceof AArch64) { - return ((AArch64) arch).getFeatures().containsAll(minFeaturesAARCH64()); - } - return false; - } - - @Override - public boolean canBeEmitted(Architecture arch) { - return isSupported(arch); + return switch (arch) { + case AMD64 amd64 -> amd64.getFeatures().containsAll(minFeaturesAMD64()); + case AArch64 aarch64 -> aarch64.getFeatures().containsAll(minFeaturesAARCH64()); + default -> false; + }; } @Override @@ -293,17 +275,11 @@ public static EnumSet minFeaturesAARCH64() { @SuppressWarnings("unlikely-arg-type") public static boolean isSupported(Architecture arch) { - if (arch instanceof AMD64) { - return ((AMD64) arch).getFeatures().containsAll(minFeaturesAMD64()); - } else if (arch instanceof AArch64) { - return ((AArch64) arch).getFeatures().containsAll(minFeaturesAARCH64()); - } - return false; - } - - @Override - public boolean canBeEmitted(Architecture arch) { - return isSupported(arch); + return switch (arch) { + case AMD64 amd64 -> amd64.getFeatures().containsAll(minFeaturesAMD64()); + case AArch64 aarch64 -> aarch64.getFeatures().containsAll(minFeaturesAARCH64()); + default -> false; + }; } @Override diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/nodes/VectorizedHashCodeNode.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/nodes/VectorizedHashCodeNode.java index 2f4361f95028..9a97da3350fb 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/nodes/VectorizedHashCodeNode.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/nodes/VectorizedHashCodeNode.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 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 @@ -115,17 +115,11 @@ public static EnumSet minFeaturesAMD64() { @SuppressWarnings("unlikely-arg-type") public static boolean isSupported(Architecture arch) { - if (arch instanceof AMD64) { - return ((AMD64) arch).getFeatures().containsAll(minFeaturesAMD64()); - } else if (arch instanceof AArch64) { - return true; - } - return false; - } - - @Override - public boolean canBeEmitted(Architecture arch) { - return isSupported(arch); + return switch (arch) { + case AMD64 amd64 -> amd64.getFeatures().containsAll(minFeaturesAMD64()); + case AArch64 aarch64 -> true; + default -> false; + }; } @Override diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/nodes/VectorizedMismatchNode.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/nodes/VectorizedMismatchNode.java index 456219c914e6..cbd97a896c3b 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/nodes/VectorizedMismatchNode.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/nodes/VectorizedMismatchNode.java @@ -116,11 +116,10 @@ public void emitIntrinsic(NodeLIRBuilderTool gen) { } public static boolean isSupported(Architecture arch) { - if (arch instanceof AMD64) { - return true; - } else if (arch instanceof AArch64) { - return true; - } - return false; + return switch (arch) { + case AMD64 amd64 -> true; + case AArch64 aarch64 -> true; + default -> false; + }; } } diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/truffle/hotspot/TruffleCommunityCompilerConfiguration.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/truffle/hotspot/TruffleCommunityCompilerConfiguration.java index c9dda52d465d..46451249c252 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/truffle/hotspot/TruffleCommunityCompilerConfiguration.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/truffle/hotspot/TruffleCommunityCompilerConfiguration.java @@ -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 @@ -31,7 +31,6 @@ import jdk.graal.compiler.core.phases.CommunityCompilerConfiguration; import jdk.graal.compiler.core.phases.HighTier; import jdk.graal.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins; -import jdk.graal.compiler.nodes.spi.Replacements; import jdk.graal.compiler.options.OptionValues; import jdk.graal.compiler.truffle.host.HostInliningPhase; import jdk.graal.compiler.truffle.substitutions.TruffleInvocationPlugins; @@ -64,17 +63,17 @@ public static void installCommunityHighTier(OptionValues options, HighTier defau } @Override - public void registerGraphBuilderPlugins(Architecture arch, Plugins plugins, OptionValues options, Replacements replacements) { - super.registerGraphBuilderPlugins(arch, plugins, options, replacements); - registerCommunityGraphBuilderPlugins(arch, plugins, options, replacements); + public void registerGraphBuilderPlugins(Architecture arch, Plugins plugins, OptionValues options) { + super.registerGraphBuilderPlugins(arch, plugins, options); + registerCommunityGraphBuilderPlugins(arch, plugins, options); } - public static void registerCommunityGraphBuilderPlugins(Architecture arch, Plugins plugins, OptionValues options, Replacements replacements) { + public static void registerCommunityGraphBuilderPlugins(Architecture arch, Plugins plugins, OptionValues options) { HostInliningPhase.installInlineInvokePlugin(plugins, options); plugins.getInvocationPlugins().defer(new Runnable() { @Override public void run() { - TruffleInvocationPlugins.register(arch, plugins.getInvocationPlugins(), replacements); + TruffleInvocationPlugins.register(arch, plugins.getInvocationPlugins()); } }); } diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/truffle/substitutions/TruffleGraphBuilderPlugins.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/truffle/substitutions/TruffleGraphBuilderPlugins.java index d79617595703..8b8771469608 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/truffle/substitutions/TruffleGraphBuilderPlugins.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/truffle/substitutions/TruffleGraphBuilderPlugins.java @@ -80,6 +80,7 @@ import jdk.graal.compiler.nodes.extended.UnsafeAccessNode; import jdk.graal.compiler.nodes.graphbuilderconf.GraphBuilderContext; import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugin; +import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugin.ConditionalInvocationPlugin; import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugin.OptionalInvocationPlugin; import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver; import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugin.RequiredInlineOnlyInvocationPlugin; @@ -90,8 +91,6 @@ import jdk.graal.compiler.nodes.java.InstanceOfDynamicNode; import jdk.graal.compiler.nodes.java.LoadFieldNode; import jdk.graal.compiler.nodes.java.MethodCallTargetNode; -import jdk.graal.compiler.nodes.spi.LoweringProvider; -import jdk.graal.compiler.nodes.spi.Replacements; import jdk.graal.compiler.nodes.type.StampTool; import jdk.graal.compiler.nodes.util.GraphUtil; import jdk.graal.compiler.nodes.virtual.EnsureVirtualizedNode; @@ -127,6 +126,7 @@ import jdk.graal.compiler.truffle.nodes.frame.VirtualFrameSetNode; import jdk.graal.compiler.truffle.nodes.frame.VirtualFrameSwapNode; import jdk.graal.compiler.truffle.phases.TruffleSafepointInsertionPhase; +import jdk.vm.ci.code.Architecture; import jdk.vm.ci.code.BailoutException; import jdk.vm.ci.meta.ConstantReflectionProvider; import jdk.vm.ci.meta.DeoptimizationAction; @@ -161,7 +161,7 @@ public static void registerInvocationPlugins(InvocationPlugins plugins, KnownTru MetaAccessProvider metaAccess = providers.getMetaAccess(); registerObjectsPlugins(plugins, types); registerOptimizedAssumptionPlugins(plugins, types); - registerExactMathPlugins(plugins, types, providers.getReplacements(), providers.getLowerer()); + registerExactMathPlugins(plugins, types); registerHostCompilerDirectivesPlugins(plugins, types); registerCompilerDirectivesPlugins(plugins, types, canDelayIntrinsification); registerCompilerAssertsPlugins(plugins, types, canDelayIntrinsification); @@ -267,8 +267,8 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec }); } - public static void registerExactMathPlugins(InvocationPlugins plugins, KnownTruffleTypes types, Replacements replacements, LoweringProvider lowerer) { - Registration r = new Registration(plugins, new ResolvedJavaSymbol(types.ExactMath), replacements); + public static void registerExactMathPlugins(InvocationPlugins plugins, KnownTruffleTypes types) { + Registration r = new Registration(plugins, new ResolvedJavaSymbol(types.ExactMath)); for (JavaKind kind : new JavaKind[]{JavaKind.Int, JavaKind.Long}) { Class type = kind.toJavaClass(); r.register(new InvocationPlugin("multiplyHigh", type, type) { @@ -287,14 +287,17 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec }); } for (JavaKind kind : new JavaKind[]{JavaKind.Float, JavaKind.Double}) { - r.registerConditional(lowerer.supportsRounding(), new InvocationPlugin("truncate", kind.toJavaClass()) { - + r.register(new ConditionalInvocationPlugin("truncate", kind.toJavaClass()) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode x) { b.addPush(kind, RoundNode.create(x, RoundingMode.TRUNCATE)); return true; } + @Override + public boolean isApplicable(Architecture arch) { + return RoundNode.isSupported(arch); + } }); } } diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/truffle/substitutions/TruffleInvocationPlugins.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/truffle/substitutions/TruffleInvocationPlugins.java index 59a6d68a71ae..f47b19482400 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/truffle/substitutions/TruffleInvocationPlugins.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/truffle/substitutions/TruffleInvocationPlugins.java @@ -58,15 +58,15 @@ import jdk.graal.compiler.nodes.calc.LeftShiftNode; import jdk.graal.compiler.nodes.graphbuilderconf.GraphBuilderContext; import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugin; +import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugin.ConditionalInvocationPlugin; +import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugin.InlineOnlyConditionalInvocationPlugin; import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugin.InlineOnlyInvocationPlugin; import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugin.OptionalInlineOnlyInvocationPlugin; -import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugin.OptionalInvocationPlugin; import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver; import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugins; import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugins.OptionalLazySymbol; import jdk.graal.compiler.nodes.java.LoadFieldNode; import jdk.graal.compiler.nodes.spi.CanonicalizerTool; -import jdk.graal.compiler.nodes.spi.Replacements; import jdk.graal.compiler.replacements.InvocationPluginHelper; import jdk.graal.compiler.replacements.nodes.ArrayCopyWithConversionsNode; import jdk.graal.compiler.replacements.nodes.ArrayIndexOfMacroNode; @@ -94,19 +94,19 @@ */ public class TruffleInvocationPlugins { - public static void register(Architecture architecture, InvocationPlugins plugins, Replacements replacements) { + public static void register(Architecture architecture, InvocationPlugins plugins) { if (architecture instanceof AMD64 || architecture instanceof AArch64) { - registerTStringPlugins(plugins, replacements, architecture); - registerArrayUtilsPlugins(plugins, replacements); - registerExactMathPlugins(plugins, replacements); + registerTStringPlugins(plugins, architecture); + registerArrayUtilsPlugins(plugins); + registerExactMathPlugins(plugins); } - registerFramePlugins(plugins, replacements); - registerBytecodePlugins(plugins, replacements); + registerFramePlugins(plugins); + registerBytecodePlugins(plugins); } - private static void registerFramePlugins(InvocationPlugins plugins, Replacements replacements) { + private static void registerFramePlugins(InvocationPlugins plugins) { plugins.registerIntrinsificationPredicate(t -> t.getName().equals("Lcom/oracle/truffle/api/impl/FrameWithoutBoxing;")); - InvocationPlugins.Registration r = new InvocationPlugins.Registration(plugins, "com.oracle.truffle.api.impl.FrameWithoutBoxing", replacements); + InvocationPlugins.Registration r = new InvocationPlugins.Registration(plugins, "com.oracle.truffle.api.impl.FrameWithoutBoxing"); r.register(new OptionalInlineOnlyInvocationPlugin("unsafeCast", Object.class, Class.class, boolean.class, boolean.class, boolean.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object, ValueNode clazz, ValueNode condition, ValueNode nonNull, @@ -176,9 +176,9 @@ private static ValueNode castTrustedFinalFrameField(GraphBuilderContext b, Value return result; } - private static void registerBytecodePlugins(InvocationPlugins plugins, Replacements replacements) { + private static void registerBytecodePlugins(InvocationPlugins plugins) { plugins.registerIntrinsificationPredicate(t -> t.getName().equals("Lcom/oracle/truffle/api/bytecode/BytecodeDSLUncheckedAccess;")); - InvocationPlugins.Registration r = new InvocationPlugins.Registration(plugins, "com.oracle.truffle.api.bytecode.BytecodeDSLUncheckedAccess", replacements); + InvocationPlugins.Registration r = new InvocationPlugins.Registration(plugins, "com.oracle.truffle.api.bytecode.BytecodeDSLUncheckedAccess"); r.register(new OptionalInlineOnlyInvocationPlugin("uncheckedCast", Receiver.class, Object.class, Class.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, @@ -203,9 +203,9 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec }); } - private static void registerArrayUtilsPlugins(InvocationPlugins plugins, Replacements replacements) { + private static void registerArrayUtilsPlugins(InvocationPlugins plugins) { plugins.registerIntrinsificationPredicate(t -> t.getName().equals("Lcom/oracle/truffle/api/ArrayUtils;")); - InvocationPlugins.Registration r = new InvocationPlugins.Registration(plugins, "com.oracle.truffle.api.ArrayUtils", replacements); + InvocationPlugins.Registration r = new InvocationPlugins.Registration(plugins, "com.oracle.truffle.api.ArrayUtils"); for (Stride stride : new Stride[]{Stride.S1, Stride.S2}) { r.register(new InlineOnlyInvocationPlugin("stubIndexOfB1" + stride.name(), byte[].class, int.class, int.class, int.class) { @Override @@ -392,9 +392,9 @@ public static LocationIdentity inferLocationIdentity(ValueNode isNativeA, ValueN } @SuppressWarnings("try") - private static void registerTStringPlugins(InvocationPlugins plugins, Replacements replacements, Architecture arch) { + private static void registerTStringPlugins(InvocationPlugins plugins, Architecture architecture) { plugins.registerIntrinsificationPredicate(t -> t.getName().equals("Lcom/oracle/truffle/api/strings/TStringOps;")); - InvocationPlugins.Registration r = new InvocationPlugins.Registration(plugins, "com.oracle.truffle.api.strings.TStringOps", replacements); + InvocationPlugins.Registration r = new InvocationPlugins.Registration(plugins, "com.oracle.truffle.api.strings.TStringOps"); OptionalLazySymbol nodeType = new OptionalLazySymbol("com.oracle.truffle.api.nodes.Node"); @@ -592,7 +592,7 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec } }); - r.registerConditional(VectorizedHashCodeNode.isSupported(arch), new InlineOnlyInvocationPlugin( + r.register(new InlineOnlyConditionalInvocationPlugin( "runHashCode", nodeType, byte[].class, long.class, int.class, int.class, boolean.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode location, @@ -612,9 +612,14 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec return true; } } + + @Override + public boolean isApplicable(Architecture arch) { + return VectorizedHashCodeNode.isSupported(arch); + } }); - if (arch instanceof AMD64) { + if (architecture instanceof AMD64) { r.register(new InlineOnlyInvocationPlugin("runCodePointIndexToByteIndexUTF8Valid", nodeType, byte[].class, long.class, int.class, int.class, boolean.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode location, @@ -672,14 +677,13 @@ public static boolean applyIndexOf(GraphBuilderContext b, ResolvedJavaMethod tar return true; } - public static void registerExactMathPlugins(InvocationPlugins plugins, Replacements replacements) { + public static void registerExactMathPlugins(InvocationPlugins plugins) { plugins.registerIntrinsificationPredicate(t -> t.getName().equals("Lcom/oracle/truffle/api/ExactMath;")); - var r = new InvocationPlugins.Registration(plugins, "com.oracle.truffle.api.ExactMath", replacements); - var lowerer = replacements.getProviders().getLowerer(); + var r = new InvocationPlugins.Registration(plugins, "com.oracle.truffle.api.ExactMath"); for (JavaKind floatKind : new JavaKind[]{JavaKind.Float, JavaKind.Double}) { for (JavaKind integerKind : new JavaKind[]{JavaKind.Int, JavaKind.Long}) { - r.registerConditional(lowerer.supportsFloatToUnsignedConvert(), new OptionalInvocationPlugin( + r.register(new ConditionalInvocationPlugin( integerKind == JavaKind.Long ? "truncateToUnsignedLong" : "truncateToUnsignedInt", floatKind.toJavaClass()) { @Override @@ -694,10 +698,20 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec b.addPush(integerKind, FloatConvertNode.create(op, x, NodeView.DEFAULT)); return true; } + + @Override + public boolean isOptional() { + return true; + } + + @Override + public boolean isApplicable(Architecture arch) { + return FloatConvertNode.supportsFloatToUnsignedConvert(arch); + } }); } - r.registerConditional(lowerer.supportsUnsignedToFloatConvert(), new OptionalInvocationPlugin( + r.register(new ConditionalInvocationPlugin( floatKind == JavaKind.Double ? "unsignedToDouble" : "unsignedToFloat", long.class) { @Override @@ -708,6 +722,16 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec b.addPush(floatKind, FloatConvertNode.create(op, x, NodeView.DEFAULT)); return true; } + + @Override + public boolean isOptional() { + return true; + } + + @Override + public boolean isApplicable(Architecture arch) { + return FloatConvertNode.supportsUnsignedToFloatConvert(arch); + } }); } } diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/vector/architecture/amd64/VectorAMD64.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/vector/architecture/amd64/VectorAMD64.java index 3cab935244f3..1b3fc86b824d 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/vector/architecture/amd64/VectorAMD64.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/vector/architecture/amd64/VectorAMD64.java @@ -471,14 +471,6 @@ public int getSupportedVectorGatherLength(Stamp elementStamp, Stamp offsetStamp, return Math.min(getSupportedVectorLength(elementStamp, maxLength, elementSize), getSupportedVectorLength(offsetStamp, maxLength, offsetSize)); } - public boolean supportsCPUFeature(String feature) { - try { - return arch.getFeatures().contains(CPUFeature.valueOf(feature)); - } catch (IllegalArgumentException e) { - return false; - } - } - @Override public int getSupportedVectorPermuteLength(Stamp elementStamp, int maxLength) { if (!hasMinimumVectorizationRequirements(maxLength)) { diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/vector/replacements/vectorapi/VectorAPIIntrinsics.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/vector/replacements/vectorapi/VectorAPIIntrinsics.java index efd50ddcbb69..ac71f8cdfea4 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/vector/replacements/vectorapi/VectorAPIIntrinsics.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/vector/replacements/vectorapi/VectorAPIIntrinsics.java @@ -40,7 +40,6 @@ import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugins.OptionalLazySymbol; import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration; import jdk.graal.compiler.nodes.memory.address.AddressNode; -import jdk.graal.compiler.nodes.spi.Replacements; import jdk.graal.compiler.options.Option; import jdk.graal.compiler.options.OptionKey; import jdk.graal.compiler.options.OptionValues; @@ -91,9 +90,9 @@ public static boolean intrinsificationSupported(OptionValues options) { /** * Register the Vector API plugins. */ - public static void registerPlugins(InvocationPlugins plugins, Replacements replacements) { + public static void registerPlugins(InvocationPlugins plugins) { String vectorSupportPackage = "jdk.internal.vm.vector"; - Registration r = new Registration(plugins, vectorSupportPackage + ".Utils", replacements); + Registration r = new Registration(plugins, vectorSupportPackage + ".Utils"); r.register(new InlineOnlyInvocationPlugin("isNonCapturingLambda", Object.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object) { @@ -111,7 +110,7 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec }); String vectorSupportName = vectorSupportPackage + ".VectorSupport"; - r = new Registration(plugins, vectorSupportName, replacements); + r = new Registration(plugins, vectorSupportName); /* Types of vectors and related data. */ OptionalLazySymbol vectorSpecies = new OptionalLazySymbol(vectorSupportName + "$VectorSpecies"); diff --git a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/virtual/phases/ea/VirtualizerToolImpl.java b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/virtual/phases/ea/VirtualizerToolImpl.java index f01913a3d8ad..2cc584fcb219 100644 --- a/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/virtual/phases/ea/VirtualizerToolImpl.java +++ b/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/virtual/phases/ea/VirtualizerToolImpl.java @@ -417,11 +417,6 @@ public Integer smallestCompareWidth() { } } - @Override - public boolean supportsRounding() { - return getLowerer().supportsRounding(); - } - @Override public VirtualizerTool createSnapshot() { VirtualizerToolImpl snapshot = new VirtualizerToolImpl(getProviders(), closure, assumptions, options, debug); diff --git a/espresso-compiler-stub/src/com.oracle.truffle.espresso.graal/src/com/oracle/truffle/espresso/graal/DummyLoweringProvider.java b/espresso-compiler-stub/src/com.oracle.truffle.espresso.graal/src/com/oracle/truffle/espresso/graal/DummyLoweringProvider.java index 09cf039263ab..6e741e2f0f7d 100644 --- a/espresso-compiler-stub/src/com.oracle.truffle.espresso.graal/src/com/oracle/truffle/espresso/graal/DummyLoweringProvider.java +++ b/espresso-compiler-stub/src/com.oracle.truffle.espresso.graal/src/com/oracle/truffle/espresso/graal/DummyLoweringProvider.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2024, 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 @@ -62,12 +62,6 @@ public boolean supportsOptimizedFilling(OptionValues options) { throw GraalError.unimplementedOverride(); } - @Override - public boolean supportsRounding() { - // used at least by AutomaticUnsafeTransformationSupport.getStaticInitializerGraph - return false; - } - @Override public boolean supportsImplicitNullChecks() { throw GraalError.unimplementedOverride(); diff --git a/espresso-compiler-stub/src/com.oracle.truffle.espresso.graal/src/com/oracle/truffle/espresso/graal/DummyReplacements.java b/espresso-compiler-stub/src/com.oracle.truffle.espresso.graal/src/com/oracle/truffle/espresso/graal/DummyReplacements.java index 445c903057d5..ba25227896b0 100644 --- a/espresso-compiler-stub/src/com.oracle.truffle.espresso.graal/src/com/oracle/truffle/espresso/graal/DummyReplacements.java +++ b/espresso-compiler-stub/src/com.oracle.truffle.espresso.graal/src/com/oracle/truffle/espresso/graal/DummyReplacements.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2024, 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 @@ -34,7 +34,6 @@ import jdk.graal.compiler.nodes.StructuredGraph; import jdk.graal.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration; import jdk.graal.compiler.nodes.graphbuilderconf.GraphBuilderPlugin; -import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugin; import jdk.graal.compiler.nodes.spi.CoreProviders; import jdk.graal.compiler.nodes.spi.Replacements; import jdk.graal.compiler.nodes.spi.SnippetParameterInfo; @@ -101,11 +100,6 @@ public void registerSnippet(ResolvedJavaMethod method, ResolvedJavaMethod origin throw GraalError.unimplementedOverride(); } - @Override - public void registerConditionalPlugin(InvocationPlugin plugin) { - throw GraalError.unimplementedOverride(); - } - @Override public StructuredGraph getInlineSubstitution(ResolvedJavaMethod method, int invokeBci, boolean isInOOMETry, Invoke.InlineControl inlineControl, boolean trackNodeSourcePosition, NodeSourcePosition replaceePosition, StructuredGraph.AllowAssumptions allowAssumptions, OptionValues options) { diff --git a/substratevm/src/com.oracle.graal.pointsto.standalone/src/com/oracle/graal/pointsto/standalone/PointsToAnalyzer.java b/substratevm/src/com.oracle.graal.pointsto.standalone/src/com/oracle/graal/pointsto/standalone/PointsToAnalyzer.java index 326003d06234..c3e5a665aaef 100644 --- a/substratevm/src/com.oracle.graal.pointsto.standalone/src/com/oracle/graal/pointsto/standalone/PointsToAnalyzer.java +++ b/substratevm/src/com.oracle.graal.pointsto.standalone/src/com/oracle/graal/pointsto/standalone/PointsToAnalyzer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2022, 2022, Alibaba Group Holding Limited. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -212,8 +212,7 @@ private PointsToAnalyzer(String mainEntryClass, OptionValues options) { NoClassInitializationPlugin classInitializationPlugin = new NoClassInitializationPlugin(); plugins.setClassInitializationPlugin(classInitializationPlugin); aProviders.setGraphBuilderPlugins(plugins); - registerInvocationPlugins(originalProviders.getSnippetReflection(), plugins.getInvocationPlugins(), originalProviders.getReplacements(), - false, true, false, originalProviders.getLowerer()); + registerInvocationPlugins(originalProviders.getSnippetReflection(), plugins.getInvocationPlugins(), false, true, false); } } diff --git a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/phases/InlineBeforeAnalysisGraphDecoder.java b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/phases/InlineBeforeAnalysisGraphDecoder.java index 36307756c0c0..83445ca6346b 100644 --- a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/phases/InlineBeforeAnalysisGraphDecoder.java +++ b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/phases/InlineBeforeAnalysisGraphDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2023, 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 diff --git a/substratevm/src/com.oracle.svm.core.graal.amd64/src/com/oracle/svm/core/graal/amd64/SubstrateAMD64LoweringProvider.java b/substratevm/src/com.oracle.svm.core.graal.amd64/src/com/oracle/svm/core/graal/amd64/SubstrateAMD64LoweringProvider.java index 0816550df56d..53da1a2600b0 100644 --- a/substratevm/src/com.oracle.svm.core.graal.amd64/src/com/oracle/svm/core/graal/amd64/SubstrateAMD64LoweringProvider.java +++ b/substratevm/src/com.oracle.svm.core.graal.amd64/src/com/oracle/svm/core/graal/amd64/SubstrateAMD64LoweringProvider.java @@ -36,7 +36,6 @@ import jdk.graal.compiler.nodes.spi.LoweringTool; import jdk.graal.compiler.nodes.spi.PlatformConfigurationProvider; import jdk.graal.compiler.vector.architecture.VectorArchitecture; -import jdk.vm.ci.amd64.AMD64; import jdk.vm.ci.code.TargetDescription; import jdk.vm.ci.meta.MetaAccessProvider; @@ -65,10 +64,4 @@ public void lower(Node n, LoweringTool tool) { super.lower(n, tool); } } - - @Override - public boolean supportsRounding() { - return ((AMD64) getTarget().arch).getFeatures().contains(AMD64.CPUFeature.SSE4_1); - } - } diff --git a/substratevm/src/com.oracle.svm.core.graal.llvm/src/com/oracle/svm/core/graal/llvm/lowering/SubstrateLLVMLoweringProvider.java b/substratevm/src/com.oracle.svm.core.graal.llvm/src/com/oracle/svm/core/graal/llvm/lowering/SubstrateLLVMLoweringProvider.java index 478989a4ea55..458282164bdb 100644 --- a/substratevm/src/com.oracle.svm.core.graal.llvm/src/com/oracle/svm/core/graal/llvm/lowering/SubstrateLLVMLoweringProvider.java +++ b/substratevm/src/com.oracle.svm.core.graal.llvm/src/com/oracle/svm/core/graal/llvm/lowering/SubstrateLLVMLoweringProvider.java @@ -79,11 +79,6 @@ public boolean supportsBulkZeroingOfEden() { return false; } - @Override - public boolean supportsRounding() { - return false; - } - @Override public boolean writesStronglyOrdered() { return false; diff --git a/substratevm/src/com.oracle.svm.core.graal.llvm/src/com/oracle/svm/core/graal/llvm/replacements/LLVMGraphBuilderPlugins.java b/substratevm/src/com.oracle.svm.core.graal.llvm/src/com/oracle/svm/core/graal/llvm/replacements/LLVMGraphBuilderPlugins.java index 6b696d86db41..fde0dad64cd0 100644 --- a/substratevm/src/com.oracle.svm.core.graal.llvm/src/com/oracle/svm/core/graal/llvm/replacements/LLVMGraphBuilderPlugins.java +++ b/substratevm/src/com.oracle.svm.core.graal.llvm/src/com/oracle/svm/core/graal/llvm/replacements/LLVMGraphBuilderPlugins.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 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 @@ -35,7 +35,6 @@ import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugin; import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugins; import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration; -import jdk.graal.compiler.nodes.spi.Replacements; import jdk.graal.compiler.options.OptionValues; import jdk.graal.compiler.replacements.TargetGraphBuilderPlugins; import jdk.graal.compiler.replacements.nodes.BinaryMathIntrinsicNode; @@ -46,28 +45,27 @@ import com.oracle.svm.core.graal.llvm.replacements.LLVMIntrinsicNode.LLVMIntrinsicOperation; -import jdk.vm.ci.code.Architecture; import jdk.vm.ci.meta.JavaKind; import jdk.vm.ci.meta.ResolvedJavaMethod; public class LLVMGraphBuilderPlugins implements TargetGraphBuilderPlugins { @Override - public void register(Plugins plugins, Replacements replacements, Architecture arch, boolean registerMathPlugins, OptionValues options) { + public void registerPlugins(Plugins plugins, OptionValues options) { InvocationPlugins invocationPlugins = plugins.getInvocationPlugins(); invocationPlugins.defer(new Runnable() { @Override public void run() { - registerIntegerLongPlugins(invocationPlugins, JavaKind.Int, replacements); - registerIntegerLongPlugins(invocationPlugins, JavaKind.Long, replacements); - registerMathPlugins(invocationPlugins, replacements); + registerIntegerLongPlugins(invocationPlugins, JavaKind.Int); + registerIntegerLongPlugins(invocationPlugins, JavaKind.Long); + registerMathPlugins(invocationPlugins); } }); } - private static void registerIntegerLongPlugins(InvocationPlugins plugins, JavaKind kind, Replacements replacements) { + private static void registerIntegerLongPlugins(InvocationPlugins plugins, JavaKind kind) { Class declaringClass = kind.toBoxedJavaClass(); - Registration r = new Registration(plugins, declaringClass, replacements).setAllowOverwrite(true); + Registration r = new Registration(plugins, declaringClass).setAllowOverwrite(true); registerUnaryLLVMIntrinsic(r, "numberOfLeadingZeros", LLVMIntrinsicOperation.CTLZ, JavaKind.Int, kind.toJavaClass()); registerUnaryLLVMIntrinsic(r, "numberOfTrailingZeros", LLVMIntrinsicOperation.CTTZ, JavaKind.Int, kind.toJavaClass()); r.register(new InvocationPlugin("bitCount", kind.toJavaClass()) { @@ -79,8 +77,8 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec }); } - private static void registerMathPlugins(InvocationPlugins plugins, Replacements replacements) { - Registration r = new Registration(plugins, Math.class, replacements); + private static void registerMathPlugins(InvocationPlugins plugins) { + Registration r = new Registration(plugins, Math.class); registerUnaryMath(r, "log", UnaryOperation.LOG); registerUnaryMath(r, "log10", UnaryOperation.LOG10); registerUnaryMath(r, "exp", UnaryOperation.EXP); diff --git a/substratevm/src/com.oracle.svm.graal/src/com/oracle/svm/graal/RuntimeCPUFeatureRegion.java b/substratevm/src/com.oracle.svm.graal/src/com/oracle/svm/graal/RuntimeCPUFeatureRegion.java index bc333148d169..f72b7ba6d21b 100644 --- a/substratevm/src/com.oracle.svm.graal/src/com/oracle/svm/graal/RuntimeCPUFeatureRegion.java +++ b/substratevm/src/com.oracle.svm.graal/src/com/oracle/svm/graal/RuntimeCPUFeatureRegion.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 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 @@ -65,7 +65,7 @@ class RuntimeCPUFeatureRegionFeature implements InternalFeature { @Override public void registerInvocationPlugins(Providers providers, GraphBuilderConfiguration.Plugins plugins, ParsingReason reason) { - InvocationPlugins.Registration r = new InvocationPlugins.Registration(plugins.getInvocationPlugins(), RuntimeCPUFeatureRegion.class, providers.getReplacements()); + InvocationPlugins.Registration r = new InvocationPlugins.Registration(plugins.getInvocationPlugins(), RuntimeCPUFeatureRegion.class); r.register(new InvocationPlugin.RequiredInlineOnlyInvocationPlugin("enter", Enum.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode arg0) { diff --git a/substratevm/src/com.oracle.svm.graal/src/com/oracle/svm/graal/TruffleRuntimeCompilationSupport.java b/substratevm/src/com.oracle.svm.graal/src/com/oracle/svm/graal/TruffleRuntimeCompilationSupport.java index 5f4e2933895b..71503d59e7cb 100644 --- a/substratevm/src/com.oracle.svm.graal/src/com/oracle/svm/graal/TruffleRuntimeCompilationSupport.java +++ b/substratevm/src/com.oracle.svm.graal/src/com/oracle/svm/graal/TruffleRuntimeCompilationSupport.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 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 @@ -28,10 +28,9 @@ import java.util.Arrays; import java.util.EnumMap; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import java.util.function.Function; -import com.oracle.svm.core.heap.UnknownPrimitiveField; -import jdk.graal.compiler.nodes.NodeClassMap; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.Platforms; @@ -45,10 +44,12 @@ import com.oracle.svm.core.graal.meta.RuntimeConfiguration; import com.oracle.svm.core.graal.meta.SharedRuntimeMethod; import com.oracle.svm.core.heap.UnknownObjectField; +import com.oracle.svm.core.heap.UnknownPrimitiveField; import com.oracle.svm.core.option.RuntimeOptionValues; import com.oracle.svm.graal.meta.SubstrateMethod; import com.oracle.svm.hosted.FeatureImpl.DuringAnalysisAccessImpl; +import jdk.graal.compiler.bytecode.BytecodeProvider; import jdk.graal.compiler.core.CompilationWrapper.ExceptionAction; import jdk.graal.compiler.core.common.CompilationIdentifier; import jdk.graal.compiler.debug.DebugContext; @@ -56,15 +57,21 @@ import jdk.graal.compiler.debug.DebugContext.Description; import jdk.graal.compiler.debug.DiagnosticsOutputDirectory; import jdk.graal.compiler.debug.GlobalMetrics; +import jdk.graal.compiler.debug.GraalError; import jdk.graal.compiler.lir.phases.LIRSuites; import jdk.graal.compiler.nodes.EncodedGraph; -import jdk.graal.compiler.nodes.GraphDecoder; +import jdk.graal.compiler.nodes.NodeClassMap; import jdk.graal.compiler.nodes.StructuredGraph; +import jdk.graal.compiler.nodes.graphbuilderconf.InlineInvokePlugin; +import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugins; +import jdk.graal.compiler.nodes.java.MethodCallTargetNode; import jdk.graal.compiler.options.OptionValues; import jdk.graal.compiler.phases.FloatingGuardPhase; import jdk.graal.compiler.phases.Speculative; import jdk.graal.compiler.phases.tiers.Suites; import jdk.graal.compiler.phases.util.Providers; +import jdk.graal.compiler.replacements.PEGraphDecoder; +import jdk.vm.ci.meta.ResolvedJavaMethod; /** * Holds data that is pre-computed during native image generation and accessed at run time during a @@ -83,6 +90,8 @@ public class TruffleRuntimeCompilationSupport { private LIRSuites firstTierLirSuites; private Providers firstTierProviders; + private InvocationPlugins invocationPlugins; + /* * The following four fields are set late in the image build process. To ensure their values are * not prematurely constant folded we must mark them as unknown fields. @@ -120,7 +129,8 @@ public TruffleRuntimeCompilationSupport() { } @Platforms(Platform.HOSTED_ONLY.class) - public static void setRuntimeConfig(RuntimeConfiguration runtimeConfig, Suites suites, LIRSuites lirSuites, Suites firstTierSuites, LIRSuites firstTierLirSuites) { + public static void setRuntimeConfig(RuntimeConfiguration runtimeConfig, Suites suites, LIRSuites lirSuites, Suites firstTierSuites, LIRSuites firstTierLirSuites, + InvocationPlugins invocationPlugins) { get().runtimeConfig = runtimeConfig; get().fullOptimizationSuites = suites; get().suitesWithoutSpeculation = getWithoutSpeculative(suites); @@ -129,6 +139,7 @@ public static void setRuntimeConfig(RuntimeConfiguration runtimeConfig, Suites s get().firstTierSuites = firstTierSuites; get().firstTierLirSuites = firstTierLirSuites; get().firstTierProviders = runtimeConfig.getBackendForNormalMethod().getProviders(); + get().invocationPlugins = invocationPlugins; } private static Suites getWithoutSpeculative(Suites s) { @@ -286,8 +297,22 @@ public static StructuredGraph decodeGraph(DebugContext debug, String name, Compi .setIsSubstitution(isSubstitution) .speculationLog((caller != null) ? caller.getSpeculationLog() : null) .build(); - GraphDecoder decoder = new GraphDecoder(ConfigurationValues.getTarget().arch, graph); - decoder.decode(encodedGraph); + PEGraphDecoder decoder = new PEGraphDecoder(ConfigurationValues.getTarget().arch, graph, get().runtimeConfig.getProviders(), + null, get().invocationPlugins, new InlineInvokePlugin[0], null, null, + null, null, new ConcurrentHashMap<>(), new ConcurrentHashMap<>(), true, false) { + @Override + protected EncodedGraph lookupEncodedGraph(ResolvedJavaMethod lookupMethod, BytecodeProvider intrinsicBytecodeProvider) { + GraalError.guarantee(method.equals(lookupMethod), lookupMethod.getName()); + return encodedGraph; + } + + @Override + protected LoopScope tryInline(PEMethodScope methodScope, LoopScope loopScope, InvokeData invokeData, MethodCallTargetNode callTarget) { + // disable inlining in PEDecoder + return null; + } + }; + decoder.decode(method); return graph; } diff --git a/substratevm/src/com.oracle.svm.graal/src/com/oracle/svm/graal/hosted/runtimecompilation/RuntimeCompilationFeature.java b/substratevm/src/com.oracle.svm.graal/src/com/oracle/svm/graal/hosted/runtimecompilation/RuntimeCompilationFeature.java index 990b6555af1e..9b63de13feaf 100644 --- a/substratevm/src/com.oracle.svm.graal/src/com/oracle/svm/graal/hosted/runtimecompilation/RuntimeCompilationFeature.java +++ b/substratevm/src/com.oracle.svm.graal/src/com/oracle/svm/graal/hosted/runtimecompilation/RuntimeCompilationFeature.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2024, 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 @@ -44,7 +44,6 @@ import java.util.function.Supplier; import java.util.stream.Stream; -import jdk.graal.compiler.nodes.NodeClassMap; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.hosted.Feature; @@ -132,6 +131,7 @@ import jdk.graal.compiler.nodes.CallTargetNode; import jdk.graal.compiler.nodes.FixedWithNextNode; import jdk.graal.compiler.nodes.GraphEncoder; +import jdk.graal.compiler.nodes.NodeClassMap; import jdk.graal.compiler.nodes.StructuredGraph; import jdk.graal.compiler.nodes.ValueNode; import jdk.graal.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration; @@ -139,6 +139,8 @@ import jdk.graal.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.ExplicitOOMEExceptionEdges; import jdk.graal.compiler.nodes.graphbuilderconf.GraphBuilderContext; import jdk.graal.compiler.nodes.graphbuilderconf.InlineInvokePlugin; +import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugin; +import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugins; import jdk.graal.compiler.nodes.graphbuilderconf.NodePlugin; import jdk.graal.compiler.nodes.spi.CoreProviders; import jdk.graal.compiler.options.Option; @@ -148,6 +150,7 @@ import jdk.graal.compiler.phases.tiers.Suites; import jdk.graal.compiler.phases.util.Providers; import jdk.graal.compiler.truffle.phases.DeoptimizeOnExceptionPhase; +import jdk.vm.ci.code.Architecture; import jdk.vm.ci.meta.JavaConstant; import jdk.vm.ci.meta.JavaKind; import jdk.vm.ci.meta.JavaType; @@ -411,7 +414,15 @@ private void installRuntimeConfig(BeforeAnalysisAccessImpl config) { Suites firstTierSuites = NativeImageGenerator.createFirstTierSuites(featureHandler, runtimeConfig, false); LIRSuites firstTierLirSuites = NativeImageGenerator.createFirstTierLIRSuites(featureHandler, runtimeConfig.getProviders(), false); - TruffleRuntimeCompilationSupport.setRuntimeConfig(runtimeConfig, suites, lirSuites, firstTierSuites, firstTierLirSuites); + TruffleRuntimeCompilationSupport.setRuntimeConfig(runtimeConfig, suites, lirSuites, firstTierSuites, firstTierLirSuites, + createRuntimeInvocationPlugins(hostedProviders.getGraphBuilderPlugins().getInvocationPlugins(), ConfigurationValues.getTarget().arch)); + } + + private static InvocationPlugins createRuntimeInvocationPlugins(InvocationPlugins hostedInvocationPlugins, Architecture arch) { + InvocationPlugins plugins = new InvocationPlugins(); + hostedInvocationPlugins.collectRuntimeCheckedPlugins(plugins, arch); + plugins.closeRegistration(); + return plugins; } @Override @@ -428,6 +439,7 @@ public void beforeAnalysis(BeforeAnalysisAccess c) { /* Initialize configuration with reasonable default values. */ graphBuilderConfig = GraphBuilderConfiguration.getDefault(hostedProviders.getGraphBuilderPlugins()).withBytecodeExceptionMode(BytecodeExceptionMode.ExplicitOnly); + runtimeCompilationCandidatePredicate = RuntimeCompilationFeature::defaultAllowRuntimeCompilation; optimisticOpts = OptimisticOptimizations.ALL.remove(OptimisticOptimizations.Optimization.UseLoopLimitChecks); graphEncoder = new RuntimeCompiledMethodSupport.RuntimeCompilationGraphEncoder(ConfigurationValues.getTarget().arch, config.getUniverse().getHeapScanner()); @@ -873,12 +885,23 @@ protected FixedWithNextNode processInvokeArgs(AnalysisMethod targetMethod, Fixed return newNode; } + private boolean isRuntimeCheckedInvocationPlugin(GraphBuilderContext b, AnalysisMethod method) { + InvocationPlugin plugin = hostedProviders.getGraphBuilderPlugins().getInvocationPlugins().lookupInvocation(method, false, false, b.getOptions()); + if (plugin instanceof InvocationPlugin.ConditionalInvocationPlugin conditionalInvocationPlugin) { + return conditionalInvocationPlugin.isRuntimeChecked(hostedProviders.getLowerer().getTarget().arch); + } + return false; + } + @Override protected boolean shouldInlineInvoke(GraphBuilderContext b, AbstractPolicyScope policyScope, AnalysisMethod method, ValueNode[] args) { if (allowInliningPredicate.allowInlining(b, method) != AllowInliningPredicate.InlineDecision.INLINE) { return false; } - + if (isRuntimeCheckedInvocationPlugin(b, method)) { + // postpone the inlining till runtime compilation + return false; + } InlineBeforeAnalysisPolicyUtils.AccumulativeInlineScope accScope; if (policyScope instanceof RuntimeCompilationAlwaysInlineScope) { /* diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGenerator.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGenerator.java index 32e85f41a044..3ec32211eba6 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGenerator.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGenerator.java @@ -313,7 +313,6 @@ import jdk.graal.compiler.word.WordTypes; import jdk.vm.ci.aarch64.AArch64; import jdk.vm.ci.amd64.AMD64; -import jdk.vm.ci.code.Architecture; import jdk.vm.ci.code.CodeCacheProvider; import jdk.vm.ci.code.TargetDescription; import jdk.vm.ci.meta.Constant; @@ -1454,20 +1453,15 @@ public static void registerGraphBuilderPlugins(FeatureHandler featureHandler, Ru } final boolean useExactMathPlugins = SubstrateOptions.useLIRBackend(); - registerInvocationPlugins(hostedSnippetReflection, plugins.getInvocationPlugins(), replacements, - useExactMathPlugins, true, supportsStubBasedPlugins, providers.getLowerer()); + registerInvocationPlugins(hostedSnippetReflection, plugins.getInvocationPlugins(), useExactMathPlugins, true, supportsStubBasedPlugins); - Architecture architecture = ConfigurationValues.getTarget().arch; OptionValues options = aUniverse.hostVM().options(); - ImageSingletons.lookup(TargetGraphBuilderPlugins.class).register(plugins, replacements, architecture, - /* registerForeignCallMath */ false, options); + ImageSingletons.lookup(TargetGraphBuilderPlugins.class).registerPlugins(plugins, options); SubstrateGraphBuilderPlugins.registerInvocationPlugins(annotationSubstitutionProcessor, loader, plugins.getInvocationPlugins(), - replacements, reason, - architecture, supportsStubBasedPlugins); featureHandler.forEachGraalFeature(feature -> feature.registerInvocationPlugins(providers, plugins, reason)); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/VectorAPIFeature.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/VectorAPIFeature.java index 2ac0efb21a5a..f95c29446150 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/VectorAPIFeature.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/VectorAPIFeature.java @@ -427,7 +427,7 @@ private static Object makeIotaVector(Class vectorClass, Class vectorElemen @Override public void registerInvocationPlugins(Providers providers, GraphBuilderConfiguration.Plugins plugins, ParsingReason reason) { if (VectorAPIIntrinsics.intrinsificationSupported(HostedOptionValues.singleton())) { - VectorAPIIntrinsics.registerPlugins(plugins.getInvocationPlugins(), providers.getReplacements()); + VectorAPIIntrinsics.registerPlugins(plugins.getInvocationPlugins()); } } } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/phases/InlineBeforeAnalysisGraphDecoderImpl.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/phases/InlineBeforeAnalysisGraphDecoderImpl.java index 659f00c8f078..6d72e69c91f2 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/phases/InlineBeforeAnalysisGraphDecoderImpl.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/phases/InlineBeforeAnalysisGraphDecoderImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 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 diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/snippets/SubstrateGraphBuilderPlugins.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/snippets/SubstrateGraphBuilderPlugins.java index da4e04ba4ea3..237448dc77b2 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/snippets/SubstrateGraphBuilderPlugins.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/snippets/SubstrateGraphBuilderPlugins.java @@ -109,6 +109,7 @@ import com.oracle.svm.hosted.nodes.DeoptProxyNode; import com.oracle.svm.hosted.nodes.ReadReservedRegister; import com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor; +import com.oracle.svm.util.ReflectionUtil; import jdk.graal.compiler.core.common.CompressEncoding; import jdk.graal.compiler.core.common.type.AbstractObjectStamp; @@ -118,7 +119,6 @@ import jdk.graal.compiler.java.LambdaUtils; import jdk.graal.compiler.nodes.AbstractBeginNode; import jdk.graal.compiler.nodes.BeginNode; -import jdk.graal.compiler.nodes.ComputeObjectAddressNode; import jdk.graal.compiler.nodes.ConstantNode; import jdk.graal.compiler.nodes.DynamicPiNode; import jdk.graal.compiler.nodes.FieldLocationIdentity; @@ -149,7 +149,6 @@ import jdk.graal.compiler.nodes.java.StoreIndexedNode; import jdk.graal.compiler.nodes.java.ValidateNewInstanceClassNode; import jdk.graal.compiler.nodes.spi.ArrayLengthProvider; -import jdk.graal.compiler.nodes.spi.Replacements; import jdk.graal.compiler.nodes.type.NarrowOopStamp; import jdk.graal.compiler.nodes.type.StampTool; import jdk.graal.compiler.nodes.util.GraphUtil; @@ -160,14 +159,9 @@ import jdk.graal.compiler.options.Option; import jdk.graal.compiler.replacements.StandardGraphBuilderPlugins; import jdk.graal.compiler.replacements.StandardGraphBuilderPlugins.AllocateUninitializedArrayPlugin; -import jdk.graal.compiler.replacements.StandardGraphBuilderPlugins.CounterModeCryptPlugin; import jdk.graal.compiler.replacements.StandardGraphBuilderPlugins.ReachabilityFencePlugin; import jdk.graal.compiler.replacements.nodes.AESNode; -import jdk.graal.compiler.replacements.nodes.CipherBlockChainingAESNode; -import jdk.graal.compiler.replacements.nodes.CounterModeAESNode; import jdk.graal.compiler.replacements.nodes.MacroNode.MacroParams; -import jdk.graal.compiler.replacements.nodes.VectorizedHashCodeNode; -import jdk.graal.compiler.replacements.nodes.VectorizedMismatchNode; import jdk.graal.compiler.word.WordCastNode; import jdk.internal.foreign.MemorySessionImpl; import jdk.vm.ci.code.Architecture; @@ -194,15 +188,13 @@ public static class Options { public static void registerInvocationPlugins(AnnotationSubstitutionProcessor annotationSubstitutions, ImageClassLoader loader, InvocationPlugins plugins, - Replacements replacements, ParsingReason parsingReason, - Architecture architecture, boolean supportsStubBasedPlugins) { // register the substratevm plugins registerArenaPlugins(plugins); registerSystemPlugins(plugins); - registerReflectionPlugins(plugins, replacements); + registerReflectionPlugins(plugins); registerImageInfoPlugins(plugins); registerProxyPlugins(annotationSubstitutions, plugins, parsingReason); registerSerializationPlugins(loader, plugins, parsingReason); @@ -219,8 +211,8 @@ public static void registerInvocationPlugins(AnnotationSubstitutionProcessor ann registerReferencePlugins(plugins, parsingReason); registerReferenceAccessPlugins(plugins); if (supportsStubBasedPlugins) { - registerAESPlugins(plugins, replacements, architecture); - registerArraysSupportPlugins(plugins, replacements, architecture); + registerAESPlugins(plugins); + registerArraysSupportPlugins(plugins); } } @@ -405,8 +397,8 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec }); } - private static void registerReflectionPlugins(InvocationPlugins plugins, Replacements replacements) { - Registration r = new Registration(plugins, "jdk.internal.reflect.Reflection", replacements); + private static void registerReflectionPlugins(InvocationPlugins plugins) { + Registration r = new Registration(plugins, "jdk.internal.reflect.Reflection"); r.register(new RequiredInlineOnlyInvocationPlugin("getCallerClass") { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) { @@ -1332,25 +1324,15 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec }); } - private static void registerArraysSupportPlugins(InvocationPlugins plugins, Replacements replacements, Architecture arch) { - InvocationPlugins.Registration r = new InvocationPlugins.Registration(plugins, "jdk.internal.util.ArraysSupport", replacements); - r.registerConditional(VectorizedMismatchNode.isSupported(arch), new InvocationPlugin("vectorizedMismatch", Object.class, long.class, Object.class, long.class, int.class, int.class) { - @Override - public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, - ValueNode aObject, ValueNode aOffset, ValueNode bObject, ValueNode bOffset, ValueNode length, ValueNode log2ArrayIndexScale) { - ValueNode aAddr = b.add(new ComputeObjectAddressNode(aObject, aOffset)); - ValueNode bAddr = b.add(new ComputeObjectAddressNode(bObject, bOffset)); - b.addPush(JavaKind.Int, new VectorizedMismatchNode(aAddr, bAddr, length, log2ArrayIndexScale)); - return true; - } - }); - r.registerConditional(VectorizedHashCodeNode.isSupported(arch), - new StandardGraphBuilderPlugins.VectorizedHashCodeInvocationPlugin("vectorizedHashCode")); + private static void registerArraysSupportPlugins(InvocationPlugins plugins) { + InvocationPlugins.Registration r = new InvocationPlugins.Registration(plugins, "jdk.internal.util.ArraysSupport"); + r.register(new StandardGraphBuilderPlugins.VectorizedMismatchInvocationPlugin()); + r.register(new StandardGraphBuilderPlugins.VectorizedHashCodeInvocationPlugin()); } - private static class SubstrateCipherBlockChainingCryptPlugin extends StandardGraphBuilderPlugins.CipherBlockChainingCryptPlugin { + public static class SubstrateCipherBlockChainingCryptPlugin extends StandardGraphBuilderPlugins.CipherBlockChainingCryptPlugin { - SubstrateCipherBlockChainingCryptPlugin(AESNode.CryptMode mode) { + public SubstrateCipherBlockChainingCryptPlugin(AESNode.CryptMode mode) { super(mode); } @@ -1361,14 +1343,16 @@ protected boolean canApply(GraphBuilderContext b) { @Override protected ResolvedJavaType getTypeAESCrypt(MetaAccessProvider metaAccess, ResolvedJavaType context) throws ClassNotFoundException { - Class classAESCrypt = Class.forName("com.sun.crypto.provider.AESCrypt", true, ClassLoader.getSystemClassLoader()); + Class classAESCrypt = ReflectionUtil.lookupClass("com.sun.crypto.provider.AESCrypt"); return metaAccess.lookupJavaType(classAESCrypt); } } - private static void registerAESPlugins(InvocationPlugins plugins, Replacements replacements, Architecture arch) { - Registration r = new Registration(plugins, "com.sun.crypto.provider.CounterMode", replacements); - r.registerConditional(CounterModeAESNode.isSupported(arch), new CounterModeCryptPlugin() { + private static void registerAESPlugins(InvocationPlugins plugins) { + // These plugins may generate fallback invocations and thus cannot be used in runtime + // compilation + Registration r = new Registration(plugins, "com.sun.crypto.provider.CounterMode"); + r.register(new StandardGraphBuilderPlugins.CounterModeCryptPlugin() { @Override protected boolean canApply(GraphBuilderContext b) { return b instanceof BytecodeParser; @@ -1380,15 +1364,30 @@ protected ValueNode getFieldOffset(GraphBuilderContext b, ResolvedJavaField fiel } @Override - protected ResolvedJavaType getTypeAESCrypt(MetaAccessProvider metaAccess, ResolvedJavaType context) throws ClassNotFoundException { - Class classAESCrypt = Class.forName("com.sun.crypto.provider.AESCrypt", true, ClassLoader.getSystemClassLoader()); + protected ResolvedJavaType getTypeAESCrypt(MetaAccessProvider metaAccess, ResolvedJavaType context) { + Class classAESCrypt = ReflectionUtil.lookupClass("com.sun.crypto.provider.AESCrypt"); return metaAccess.lookupJavaType(classAESCrypt); } + + @Override + public boolean isRuntimeChecked(Architecture arch) { + return false; + } }); - r = new Registration(plugins, "com.sun.crypto.provider.CipherBlockChaining", replacements); - r.registerConditional(CipherBlockChainingAESNode.isSupported(arch), new SubstrateCipherBlockChainingCryptPlugin(AESNode.CryptMode.ENCRYPT)); - r.registerConditional(CipherBlockChainingAESNode.isSupported(arch), new SubstrateCipherBlockChainingCryptPlugin(AESNode.CryptMode.DECRYPT)); + r = new Registration(plugins, "com.sun.crypto.provider.CipherBlockChaining"); + r.register(new SubstrateCipherBlockChainingCryptPlugin(AESNode.CryptMode.ENCRYPT) { + @Override + public boolean isRuntimeChecked(Architecture arch) { + return false; + } + }); + r.register(new SubstrateCipherBlockChainingCryptPlugin(AESNode.CryptMode.DECRYPT) { + @Override + public boolean isRuntimeChecked(Architecture arch) { + return false; + } + }); } private static T constantObjectParameter(GraphBuilderContext b, ResolvedJavaMethod targetMethod, int parameterIndex, Class declaredType, ValueNode classNode) { diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/SubstitutionInvocationPlugins.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/SubstitutionInvocationPlugins.java index 882c6e0b90d6..37e2cd5a8694 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/SubstitutionInvocationPlugins.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/SubstitutionInvocationPlugins.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2024, 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 diff --git a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/TruffleBaseFeature.java b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/TruffleBaseFeature.java index d76f34887cde..b7d624af6d09 100644 --- a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/TruffleBaseFeature.java +++ b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/TruffleBaseFeature.java @@ -481,7 +481,7 @@ public void cleanup() { @Override public void registerInvocationPlugins(Providers providers, Plugins plugins, ParsingReason reason) { StaticObjectSupport.registerInvocationPlugins(plugins, reason); - TruffleInvocationPlugins.register(providers.getLowerer().getTarget().arch, plugins.getInvocationPlugins(), providers.getReplacements()); + TruffleInvocationPlugins.register(providers.getLowerer().getTarget().arch, plugins.getInvocationPlugins()); /* * We need to constant-fold Profile.isProfilingEnabled already during static analysis, so diff --git a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstratePartialEvaluator.java b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstratePartialEvaluator.java index b9b41ef38ccc..7c33b63ec151 100644 --- a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstratePartialEvaluator.java +++ b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstratePartialEvaluator.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 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 @@ -112,6 +112,7 @@ protected void registerGraphBuilderInvocationPlugins(InvocationPlugins invocatio @Override protected InvocationPlugins createDecodingInvocationPlugins(PartialEvaluatorConfiguration peConfig, Plugins parent, Providers tierProviders) { InvocationPlugins decodingInvocationPlugins = new InvocationPlugins(); + parent.getInvocationPlugins().collectRuntimeCheckedPlugins(decodingInvocationPlugins, config.architecture()); registerGraphBuilderInvocationPlugins(decodingInvocationPlugins, false); peConfig.registerDecodingInvocationPlugins(decodingInvocationPlugins, false, config.lastTier().providers(), config.architecture()); decodingInvocationPlugins.closeRegistration(); diff --git a/web-image/src/com.oracle.svm.hosted.webimage/src/com/oracle/svm/hosted/webimage/JSGraphBuilderPlugins.java b/web-image/src/com.oracle.svm.hosted.webimage/src/com/oracle/svm/hosted/webimage/JSGraphBuilderPlugins.java index 86388fa01058..c733b0608661 100644 --- a/web-image/src/com.oracle.svm.hosted.webimage/src/com/oracle/svm/hosted/webimage/JSGraphBuilderPlugins.java +++ b/web-image/src/com.oracle.svm.hosted.webimage/src/com/oracle/svm/hosted/webimage/JSGraphBuilderPlugins.java @@ -50,7 +50,6 @@ import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugins; import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration; import jdk.graal.compiler.nodes.memory.address.IndexAddressNode; -import jdk.graal.compiler.nodes.spi.Replacements; import jdk.graal.compiler.options.OptionValues; import jdk.graal.compiler.replacements.BigIntegerSnippets; import jdk.graal.compiler.replacements.SnippetSubstitutionInvocationPlugin; @@ -58,7 +57,6 @@ import jdk.graal.compiler.replacements.StringUTF16Snippets; import jdk.graal.compiler.replacements.TargetGraphBuilderPlugins; import jdk.graal.compiler.word.Word; -import jdk.vm.ci.code.Architecture; import jdk.vm.ci.meta.JavaConstant; import jdk.vm.ci.meta.JavaKind; import jdk.vm.ci.meta.ResolvedJavaMethod; @@ -71,21 +69,21 @@ public class JSGraphBuilderPlugins implements TargetGraphBuilderPlugins { private static final Word SINGLE_THREAD_SENTINEL = Word.unsigned(0x150_150_150_150_777L); @Override - public void register(GraphBuilderConfiguration.Plugins plugins, Replacements replacements, Architecture arch, boolean registerForeignCallMath, OptionValues options) { + public void registerPlugins(GraphBuilderConfiguration.Plugins plugins, OptionValues options) { InvocationPlugins invocationPlugins = plugins.getInvocationPlugins(); invocationPlugins.defer(() -> { registerCharacterPlugins(invocationPlugins); registerShortPlugins(invocationPlugins); registerIntegerLongPlugins(invocationPlugins, JavaKind.Int); registerIntegerLongPlugins(invocationPlugins, JavaKind.Long); - registerStringPlugins(invocationPlugins, replacements); + registerStringPlugins(invocationPlugins); registerJSCopyOfPlugins(invocationPlugins); registerMathPlugins(invocationPlugins); - registerBigIntegerPlugins(invocationPlugins, replacements); - registerThreadPlugins(invocationPlugins, replacements); - registerCurrentIsolatePlugins(invocationPlugins, replacements); + registerBigIntegerPlugins(invocationPlugins); + registerThreadPlugins(invocationPlugins); + registerCurrentIsolatePlugins(invocationPlugins); // TODO GR-61725 Support ArrayFillNodes - WasmLMGraphBuilderPlugins.unregisterArrayFillPlugins(invocationPlugins, replacements); + WasmLMGraphBuilderPlugins.unregisterArrayFillPlugins(invocationPlugins); }); } @@ -164,7 +162,7 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec }); } - public static void registerStringPlugins(InvocationPlugins plugins, Replacements replacements) { + public static void registerStringPlugins(InvocationPlugins plugins) { /* * Disable getChar and putChar substitutions from StandardGraphBuilderPlugins. The * substitution there would generate raw memory accesses which is only partially supported. @@ -190,7 +188,7 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec } }); - Registration r2 = new Registration(plugins, StringUTF16Snippets.class, replacements); + Registration r2 = new Registration(plugins, StringUTF16Snippets.class); r2.register(new InvocationPlugin("getChar", byte[].class, int.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode arg1, ValueNode arg2) { @@ -356,8 +354,8 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec }); } - private static void registerBigIntegerPlugins(InvocationPlugins plugins, Replacements replacements) { - Registration r = new Registration(plugins, BigInteger.class, replacements).setAllowOverwrite(true); + private static void registerBigIntegerPlugins(InvocationPlugins plugins) { + Registration r = new Registration(plugins, BigInteger.class).setAllowOverwrite(true); // the upstream plugin introduces a ComputeObjectAddressNode that is not supported (yet) r.register(new SnippetSubstitutionInvocationPlugin<>(BigIntegerSnippets.Templates.class, "implMultiplyToLen", int[].class, int.class, int[].class, int.class, int[].class) { @@ -373,8 +371,8 @@ public boolean execute(GraphBuilderContext b, ResolvedJavaMethod targetMethod, R }); } - public static void registerThreadPlugins(InvocationPlugins plugins, Replacements replacements) { - Registration r = new Registration(plugins, Thread.class, replacements).setAllowOverwrite(true); + public static void registerThreadPlugins(InvocationPlugins plugins) { + Registration r = new Registration(plugins, Thread.class).setAllowOverwrite(true); r.register(new InvocationPlugin("onSpinWait") { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) { @@ -389,8 +387,8 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec *

* This is called for all Web Image backends. */ - public static void registerCurrentIsolatePlugins(InvocationPlugins plugins, Replacements replacements) { - Registration r = new Registration(plugins, CurrentIsolate.class, replacements).setAllowOverwrite(true); + public static void registerCurrentIsolatePlugins(InvocationPlugins plugins) { + Registration r = new Registration(plugins, CurrentIsolate.class).setAllowOverwrite(true); r.register(new InvocationPlugin.RequiredInvocationPlugin("getCurrentThread") { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) { diff --git a/web-image/src/com.oracle.svm.hosted.webimage/src/com/oracle/svm/hosted/webimage/js/WebImageJSLoweringProvider.java b/web-image/src/com.oracle.svm.hosted.webimage/src/com/oracle/svm/hosted/webimage/js/WebImageJSLoweringProvider.java index 7b552539404f..531c550c1b24 100644 --- a/web-image/src/com.oracle.svm.hosted.webimage/src/com/oracle/svm/hosted/webimage/js/WebImageJSLoweringProvider.java +++ b/web-image/src/com.oracle.svm.hosted.webimage/src/com/oracle/svm/hosted/webimage/js/WebImageJSLoweringProvider.java @@ -91,11 +91,6 @@ public boolean supportsBulkZeroingOfEden() { return false; } - @Override - public boolean supportsRounding() { - return false; - } - @Override public boolean writesStronglyOrdered() { return true; diff --git a/web-image/src/com.oracle.svm.hosted.webimage/src/com/oracle/svm/hosted/webimage/wasm/WasmLMGraphBuilderPlugins.java b/web-image/src/com.oracle.svm.hosted.webimage/src/com/oracle/svm/hosted/webimage/wasm/WasmLMGraphBuilderPlugins.java index 90ae2dd7889b..ebe2513d2838 100644 --- a/web-image/src/com.oracle.svm.hosted.webimage/src/com/oracle/svm/hosted/webimage/wasm/WasmLMGraphBuilderPlugins.java +++ b/web-image/src/com.oracle.svm.hosted.webimage/src/com/oracle/svm/hosted/webimage/wasm/WasmLMGraphBuilderPlugins.java @@ -22,7 +22,6 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ - package com.oracle.svm.hosted.webimage.wasm; import static jdk.graal.compiler.replacements.nodes.BinaryMathIntrinsicNode.BinaryOperation.POW; @@ -50,6 +49,7 @@ import jdk.graal.compiler.core.common.memory.BarrierType; import jdk.graal.compiler.core.common.memory.MemoryOrderMode; +import jdk.graal.compiler.lir.gen.ArithmeticLIRGeneratorTool.RoundingMode; import jdk.graal.compiler.nodes.ConstantNode; import jdk.graal.compiler.nodes.NamedLocationIdentity; import jdk.graal.compiler.nodes.NodeView; @@ -60,6 +60,7 @@ import jdk.graal.compiler.nodes.calc.MaxNode; import jdk.graal.compiler.nodes.calc.MinNode; import jdk.graal.compiler.nodes.calc.NarrowNode; +import jdk.graal.compiler.nodes.calc.RoundNode; import jdk.graal.compiler.nodes.extended.JavaReadNode; import jdk.graal.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration; import jdk.graal.compiler.nodes.graphbuilderconf.GraphBuilderContext; @@ -67,7 +68,6 @@ import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugins; import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration; import jdk.graal.compiler.nodes.memory.address.IndexAddressNode; -import jdk.graal.compiler.nodes.spi.Replacements; import jdk.graal.compiler.options.OptionValues; import jdk.graal.compiler.replacements.BigIntegerSnippets; import jdk.graal.compiler.replacements.SnippetSubstitutionInvocationPlugin; @@ -79,7 +79,6 @@ import jdk.graal.compiler.replacements.nodes.UnaryMathIntrinsicNode; import jdk.graal.compiler.replacements.nodes.UnaryMathIntrinsicNode.UnaryOperation; import jdk.graal.compiler.word.WordCastNode; -import jdk.vm.ci.code.Architecture; import jdk.vm.ci.meta.JavaKind; import jdk.vm.ci.meta.ResolvedJavaMethod; @@ -90,31 +89,31 @@ */ public class WasmLMGraphBuilderPlugins implements TargetGraphBuilderPlugins { @Override - public void register(GraphBuilderConfiguration.Plugins plugins, Replacements replacements, Architecture arch, boolean registerForeignCallMath, OptionValues options) { + public void registerPlugins(GraphBuilderConfiguration.Plugins plugins, OptionValues options) { InvocationPlugins invocationPlugins = plugins.getInvocationPlugins(); invocationPlugins.defer(() -> { - registerStringPlugins(invocationPlugins, replacements); - registerIntegerLongPlugins(invocationPlugins, JavaKind.Int, replacements); - registerIntegerLongPlugins(invocationPlugins, JavaKind.Long, replacements); - registerCharacterPlugins(invocationPlugins, replacements); - registerShortPlugins(invocationPlugins, replacements); - registerMathPlugins(Math.class, invocationPlugins, replacements); - registerMathPlugins(StrictMath.class, invocationPlugins, replacements); - registerBigIntegerPlugins(invocationPlugins, replacements); - registerArraysPlugins(invocationPlugins, replacements); - unregisterArrayFillPlugins(invocationPlugins, replacements); + registerStringPlugins(invocationPlugins); + registerIntegerLongPlugins(invocationPlugins, JavaKind.Int); + registerIntegerLongPlugins(invocationPlugins, JavaKind.Long); + registerCharacterPlugins(invocationPlugins); + registerShortPlugins(invocationPlugins); + registerMathPlugins(Math.class, invocationPlugins); + registerMathPlugins(StrictMath.class, invocationPlugins); + registerBigIntegerPlugins(invocationPlugins); + registerArraysPlugins(invocationPlugins); + unregisterArrayFillPlugins(invocationPlugins); registerMemoryPlugins(invocationPlugins); - JSGraphBuilderPlugins.registerThreadPlugins(invocationPlugins, replacements); - JSGraphBuilderPlugins.registerCurrentIsolatePlugins(invocationPlugins, replacements); + JSGraphBuilderPlugins.registerThreadPlugins(invocationPlugins); + JSGraphBuilderPlugins.registerCurrentIsolatePlugins(invocationPlugins); }); } - private static void registerStringPlugins(InvocationPlugins plugins, Replacements replacements) { - final Registration r = new Registration(plugins, String.class, replacements).setAllowOverwrite(true); + private static void registerStringPlugins(InvocationPlugins plugins) { + final Registration r = new Registration(plugins, String.class).setAllowOverwrite(true); // String.equals produces ArrayEqualsNodes which have no counterpart in WASM. unregisterEquals(r, InvocationPlugin.Receiver.class, Object.class); - Registration utf16r = new Registration(plugins, StringUTF16Snippets.class, replacements); + Registration utf16r = new Registration(plugins, StringUTF16Snippets.class); utf16r.register(new InvocationPlugin("getChar", byte[].class, int.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode arg1, ValueNode arg2) { @@ -126,8 +125,8 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec }); } - public static void registerMathPlugins(Class mathImpl, InvocationPlugins plugins, Replacements replacements) { - Registration r = new Registration(plugins, mathImpl, replacements).setAllowOverwrite(true); + public static void registerMathPlugins(Class mathImpl, InvocationPlugins plugins) { + Registration r = new Registration(plugins, mathImpl).setAllowOverwrite(true); registerUnaryMath(r, "log", LOG); registerUnaryMath(r, "log10", LOG10); registerUnaryMath(r, "exp", EXP); @@ -152,6 +151,27 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec return true; } }); + r.register(new InvocationPlugin("rint", double.class) { + @Override + public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode arg) { + b.push(JavaKind.Double, b.append(RoundNode.create(arg, RoundingMode.NEAREST))); + return true; + } + }); + r.register(new InvocationPlugin("ceil", double.class) { + @Override + public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode arg) { + b.push(JavaKind.Double, b.append(RoundNode.create(arg, RoundingMode.UP))); + return true; + } + }); + r.register(new InvocationPlugin("floor", double.class) { + @Override + public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode arg) { + b.push(JavaKind.Double, b.append(RoundNode.create(arg, RoundingMode.DOWN))); + return true; + } + }); // WASM does not have a signum operation (but it does support copySign) @@ -244,10 +264,10 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec } } - public static void registerIntegerLongPlugins(InvocationPlugins plugins, JavaKind kind, Replacements replacements) { + public static void registerIntegerLongPlugins(InvocationPlugins plugins, JavaKind kind) { Class declaringClass = kind.toBoxedJavaClass(); Class type = kind.toJavaClass(); - Registration r = new Registration(plugins, declaringClass, replacements).setAllowOverwrite(true); + Registration r = new Registration(plugins, declaringClass).setAllowOverwrite(true); r.register(new InvocationPlugin("bitCount", type) { @Override @@ -277,8 +297,8 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec }); } - public static void registerCharacterPlugins(InvocationPlugins plugins, Replacements replacements) { - Registration r = new Registration(plugins, Character.class, replacements).setAllowOverwrite(true); + public static void registerCharacterPlugins(InvocationPlugins plugins) { + Registration r = new Registration(plugins, Character.class).setAllowOverwrite(true); r.register(new InvocationPlugin("reverseBytes", char.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) { @@ -291,8 +311,8 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec }); } - public static void registerShortPlugins(InvocationPlugins plugins, Replacements replacements) { - Registration r = new Registration(plugins, Short.class, replacements).setAllowOverwrite(true); + public static void registerShortPlugins(InvocationPlugins plugins) { + Registration r = new Registration(plugins, Short.class).setAllowOverwrite(true); r.register(new InvocationPlugin("reverseBytes", short.class) { @Override public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) { @@ -305,8 +325,8 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec }); } - public static void registerArraysPlugins(InvocationPlugins plugins, Replacements replacements) { - Registration r = new Registration(plugins, Arrays.class, replacements).setAllowOverwrite(true); + public static void registerArraysPlugins(InvocationPlugins plugins) { + Registration r = new Registration(plugins, Arrays.class).setAllowOverwrite(true); // Arrays.equals produces ArrayEqualsNodes which have no counterpart in WASM. unregisterEquals(r, boolean[].class, boolean[].class); unregisterEquals(r, byte[].class, byte[].class); @@ -344,8 +364,8 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec * {@link jdk.graal.compiler.replacements.nodes.ArrayFillNode}, for which there is no equivalent * in WasmLM (filling memory only works at the byte level). */ - public static void unregisterArrayFillPlugins(InvocationPlugins plugins, Replacements replacements) { - Registration r = new Registration(plugins, Arrays.class, replacements).setAllowOverwrite(true); + public static void unregisterArrayFillPlugins(InvocationPlugins plugins) { + Registration r = new Registration(plugins, Arrays.class).setAllowOverwrite(true); unregisterArrayFill(r, boolean.class); unregisterArrayFill(r, byte.class); @@ -381,8 +401,8 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec }); } - public static void registerBigIntegerPlugins(InvocationPlugins plugins, Replacements replacements) { - Registration r = new Registration(plugins, BigInteger.class, replacements).setAllowOverwrite(true); + public static void registerBigIntegerPlugins(InvocationPlugins plugins) { + Registration r = new Registration(plugins, BigInteger.class).setAllowOverwrite(true); // the upstream plugin introduces a BigIntegerMultiplyToLenNode that is not supported r.register(new SnippetSubstitutionInvocationPlugin<>(BigIntegerSnippets.Templates.class, "implMultiplyToLen", int[].class, int.class, int[].class, int.class, int[].class) { diff --git a/web-image/src/com.oracle.svm.hosted.webimage/src/com/oracle/svm/hosted/webimage/wasm/WebImageWasmLMLoweringProvider.java b/web-image/src/com.oracle.svm.hosted.webimage/src/com/oracle/svm/hosted/webimage/wasm/WebImageWasmLMLoweringProvider.java index 18205483b1b9..d070c3763e5b 100644 --- a/web-image/src/com.oracle.svm.hosted.webimage/src/com/oracle/svm/hosted/webimage/wasm/WebImageWasmLMLoweringProvider.java +++ b/web-image/src/com.oracle.svm.hosted.webimage/src/com/oracle/svm/hosted/webimage/wasm/WebImageWasmLMLoweringProvider.java @@ -154,16 +154,6 @@ public boolean supportsBulkZeroingOfEden() { return true; } - /** - * WASM has instructions to model all rounding modes except for - * {@link jdk.graal.compiler.lir.gen.ArithmeticLIRGeneratorTool.RoundingMode#TRUNCATE}, which is - * not used by Graal. - */ - @Override - public boolean supportsRounding() { - return true; - } - /** * WASM is single-threaded for now, but in the threading proposal, memory accesses are * sequentially consistent. diff --git a/web-image/src/com.oracle.svm.hosted.webimage/src/com/oracle/svm/hosted/webimage/wasmgc/WasmGCGraphBuilderPlugins.java b/web-image/src/com.oracle.svm.hosted.webimage/src/com/oracle/svm/hosted/webimage/wasmgc/WasmGCGraphBuilderPlugins.java index 8bc8349b3645..c3e4e5f4017c 100644 --- a/web-image/src/com.oracle.svm.hosted.webimage/src/com/oracle/svm/hosted/webimage/wasmgc/WasmGCGraphBuilderPlugins.java +++ b/web-image/src/com.oracle.svm.hosted.webimage/src/com/oracle/svm/hosted/webimage/wasmgc/WasmGCGraphBuilderPlugins.java @@ -35,41 +35,39 @@ import jdk.graal.compiler.nodes.graphbuilderconf.GraphBuilderContext; import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugin; import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugins; -import jdk.graal.compiler.nodes.spi.Replacements; import jdk.graal.compiler.options.OptionValues; import jdk.graal.compiler.replacements.SnippetSubstitutionInvocationPlugin; import jdk.graal.compiler.replacements.SnippetTemplate; import jdk.graal.compiler.replacements.TargetGraphBuilderPlugins; -import jdk.vm.ci.code.Architecture; import jdk.vm.ci.meta.JavaKind; import jdk.vm.ci.meta.ResolvedJavaMethod; public class WasmGCGraphBuilderPlugins implements TargetGraphBuilderPlugins { @Override - public void register(GraphBuilderConfiguration.Plugins plugins, Replacements replacements, Architecture arch, boolean registerForeignCallMath, OptionValues options) { + public void registerPlugins(GraphBuilderConfiguration.Plugins plugins, OptionValues options) { InvocationPlugins invocationPlugins = plugins.getInvocationPlugins(); invocationPlugins.defer(() -> { - JSGraphBuilderPlugins.registerStringPlugins(invocationPlugins, replacements); - JSGraphBuilderPlugins.registerCurrentIsolatePlugins(invocationPlugins, replacements); - JSGraphBuilderPlugins.registerThreadPlugins(invocationPlugins, replacements); - WasmLMGraphBuilderPlugins.registerIntegerLongPlugins(invocationPlugins, JavaKind.Int, replacements); - WasmLMGraphBuilderPlugins.registerIntegerLongPlugins(invocationPlugins, JavaKind.Long, replacements); - WasmLMGraphBuilderPlugins.registerShortPlugins(invocationPlugins, replacements); - WasmLMGraphBuilderPlugins.registerCharacterPlugins(invocationPlugins, replacements); - WasmLMGraphBuilderPlugins.registerArraysPlugins(invocationPlugins, replacements); - WasmLMGraphBuilderPlugins.registerBigIntegerPlugins(invocationPlugins, replacements); - WasmLMGraphBuilderPlugins.registerMathPlugins(Math.class, invocationPlugins, replacements); - WasmLMGraphBuilderPlugins.registerMathPlugins(StrictMath.class, invocationPlugins, replacements); + JSGraphBuilderPlugins.registerStringPlugins(invocationPlugins); + JSGraphBuilderPlugins.registerCurrentIsolatePlugins(invocationPlugins); + JSGraphBuilderPlugins.registerThreadPlugins(invocationPlugins); + WasmLMGraphBuilderPlugins.registerIntegerLongPlugins(invocationPlugins, JavaKind.Int); + WasmLMGraphBuilderPlugins.registerIntegerLongPlugins(invocationPlugins, JavaKind.Long); + WasmLMGraphBuilderPlugins.registerShortPlugins(invocationPlugins); + WasmLMGraphBuilderPlugins.registerCharacterPlugins(invocationPlugins); + WasmLMGraphBuilderPlugins.registerArraysPlugins(invocationPlugins); + WasmLMGraphBuilderPlugins.registerBigIntegerPlugins(invocationPlugins); + WasmLMGraphBuilderPlugins.registerMathPlugins(Math.class, invocationPlugins); + WasmLMGraphBuilderPlugins.registerMathPlugins(StrictMath.class, invocationPlugins); // TODO GR-61725 Support ArrayFillNodes - WasmLMGraphBuilderPlugins.unregisterArrayFillPlugins(invocationPlugins, replacements); - registerAllocationPlugins(invocationPlugins, replacements); - registerArraysSupportPlugins(invocationPlugins, replacements); + WasmLMGraphBuilderPlugins.unregisterArrayFillPlugins(invocationPlugins); + registerAllocationPlugins(invocationPlugins); + registerArraysSupportPlugins(invocationPlugins); }); } - private static void registerAllocationPlugins(InvocationPlugins plugins, Replacements replacements) { - InvocationPlugins.Registration r = new InvocationPlugins.Registration(plugins, WasmGCAllocationSupport.class, replacements); + private static void registerAllocationPlugins(InvocationPlugins plugins) { + InvocationPlugins.Registration r = new InvocationPlugins.Registration(plugins, WasmGCAllocationSupport.class); r.register(new SnippetSubstitutionInvocationPlugin<>(WasmGCAllocationSnippets.Templates.class, "dynamicNewArrayImpl", Class.class, int.class) { @Override @@ -79,8 +77,8 @@ public SnippetTemplate.SnippetInfo getSnippet(WasmGCAllocationSnippets.Templates }); } - private static void registerArraysSupportPlugins(InvocationPlugins plugins, Replacements replacements) { - InvocationPlugins.Registration r = new InvocationPlugins.Registration(plugins, "jdk.internal.util.ArraysSupport", replacements).setAllowOverwrite(true); + private static void registerArraysSupportPlugins(InvocationPlugins plugins) { + InvocationPlugins.Registration r = new InvocationPlugins.Registration(plugins, "jdk.internal.util.ArraysSupport").setAllowOverwrite(true); /* * Under WasmGC, the vectorizedMismatch will be much slower than just element-wise checking * because there exists no efficient way to load large chunks of arbitrary primitive arrays diff --git a/web-image/src/com.oracle.svm.hosted.webimage/src/com/oracle/svm/hosted/webimage/wasmgc/WebImageWasmGCLoweringProvider.java b/web-image/src/com.oracle.svm.hosted.webimage/src/com/oracle/svm/hosted/webimage/wasmgc/WebImageWasmGCLoweringProvider.java index aaaa884e4c6c..79fa5914f765 100644 --- a/web-image/src/com.oracle.svm.hosted.webimage/src/com/oracle/svm/hosted/webimage/wasmgc/WebImageWasmGCLoweringProvider.java +++ b/web-image/src/com.oracle.svm.hosted.webimage/src/com/oracle/svm/hosted/webimage/wasmgc/WebImageWasmGCLoweringProvider.java @@ -207,14 +207,6 @@ public boolean supportsBulkZeroingOfEden() { return true; } - /** - * @see WebImageWasmLMLoweringProvider#supportsRounding() - */ - @Override - public boolean supportsRounding() { - return true; - } - /** * @see WebImageWasmLMLoweringProvider#writesStronglyOrdered() */ diff --git a/web-image/src/com.oracle.svm.webimage/src/com/oracle/svm/webimage/truffle/WebImageTruffleFeature.java b/web-image/src/com.oracle.svm.webimage/src/com/oracle/svm/webimage/truffle/WebImageTruffleFeature.java index b89286ec7e7c..9e5d963d1a5b 100644 --- a/web-image/src/com.oracle.svm.webimage/src/com/oracle/svm/webimage/truffle/WebImageTruffleFeature.java +++ b/web-image/src/com.oracle.svm.webimage/src/com/oracle/svm/webimage/truffle/WebImageTruffleFeature.java @@ -22,7 +22,6 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ - package com.oracle.svm.webimage.truffle; import java.util.ArrayList; @@ -88,7 +87,7 @@ public boolean isInConfiguration(IsInConfigurationAccess access) { @Override public void registerInvocationPlugins(Providers providers, GraphBuilderConfiguration.Plugins plugins, ParsingReason reason) { - WebImageTruffleGraphBuilderPlugins.register(plugins.getInvocationPlugins(), providers.getReplacements()); + WebImageTruffleGraphBuilderPlugins.register(plugins.getInvocationPlugins()); } @Override diff --git a/web-image/src/com.oracle.svm.webimage/src/com/oracle/svm/webimage/truffle/WebImageTruffleGraphBuilderPlugins.java b/web-image/src/com.oracle.svm.webimage/src/com/oracle/svm/webimage/truffle/WebImageTruffleGraphBuilderPlugins.java index cbe53bd0431d..b8719c3c2c99 100644 --- a/web-image/src/com.oracle.svm.webimage/src/com/oracle/svm/webimage/truffle/WebImageTruffleGraphBuilderPlugins.java +++ b/web-image/src/com.oracle.svm.webimage/src/com/oracle/svm/webimage/truffle/WebImageTruffleGraphBuilderPlugins.java @@ -31,9 +31,9 @@ import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugin; import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugin.InlineOnlyInvocationPlugin; import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugins; -import jdk.graal.compiler.nodes.spi.Replacements; import jdk.graal.compiler.replacements.nodes.IntrinsicMethodNodeInterface; import jdk.graal.compiler.truffle.substitutions.TruffleInvocationPlugins; +import jdk.vm.ci.meta.JavaKind; import jdk.vm.ci.meta.ResolvedJavaMethod; /** @@ -47,13 +47,14 @@ */ public class WebImageTruffleGraphBuilderPlugins { - public static void register(InvocationPlugins plugins, Replacements replacements) { - registerTStringPlugins(plugins, replacements); - registerArrayUtilsPlugins(plugins, replacements); + public static void register(InvocationPlugins plugins) { + registerTStringPlugins(plugins); + registerArrayUtilsPlugins(plugins); + registerExactMathPlugins(plugins); } - private static void registerTStringPlugins(InvocationPlugins plugins, Replacements replacements) { - InvocationPlugins.Registration r = new InvocationPlugins.Registration(plugins, "com.oracle.truffle.api.strings.TStringOps", replacements).setAllowOverwrite(true); + private static void registerTStringPlugins(InvocationPlugins plugins) { + InvocationPlugins.Registration r = new InvocationPlugins.Registration(plugins, "com.oracle.truffle.api.strings.TStringOps").setAllowOverwrite(true); InvocationPlugins.OptionalLazySymbol nodeType = new InvocationPlugins.OptionalLazySymbol("com.oracle.truffle.api.nodes.Node"); @@ -229,8 +230,8 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec }); } - private static void registerArrayUtilsPlugins(InvocationPlugins plugins, Replacements replacements) { - InvocationPlugins.Registration r = new InvocationPlugins.Registration(plugins, "com.oracle.truffle.api.ArrayUtils", replacements).setAllowOverwrite(true); + private static void registerArrayUtilsPlugins(InvocationPlugins plugins) { + InvocationPlugins.Registration r = new InvocationPlugins.Registration(plugins, "com.oracle.truffle.api.ArrayUtils").setAllowOverwrite(true); for (Stride stride : new Stride[]{Stride.S1, Stride.S2}) { r.register(new InlineOnlyInvocationPlugin("stubIndexOfB1" + stride.name(), byte[].class, int.class, int.class, int.class) { @Override @@ -333,4 +334,32 @@ public boolean apply(GraphBuilderContext graph, ResolvedJavaMethod targetMethod, } }); } + + public static void registerExactMathPlugins(InvocationPlugins plugins) { + plugins.registerIntrinsificationPredicate(t -> t.getName().equals("Lcom/oracle/truffle/api/ExactMath;")); + var r = new InvocationPlugins.Registration(plugins, "com.oracle.truffle.api.ExactMath").setAllowOverwrite(true); + + // TODO GR-65897 Remove this once we support unsigned float conversions in Wasm backend + for (JavaKind floatKind : new JavaKind[]{JavaKind.Float, JavaKind.Double}) { + for (JavaKind integerKind : new JavaKind[]{JavaKind.Int, JavaKind.Long}) { + r.register(new InvocationPlugin.OptionalInvocationPlugin( + integerKind == JavaKind.Long ? "truncateToUnsignedLong" : "truncateToUnsignedInt", + floatKind.toJavaClass()) { + @Override + public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode x) { + return false; + } + }); + } + + r.register(new InvocationPlugin.OptionalInvocationPlugin( + floatKind == JavaKind.Double ? "unsignedToDouble" : "unsignedToFloat", + long.class) { + @Override + public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode x) { + return false; + } + }); + } + } }