Skip to content

Commit 26b16fa

Browse files
committed
Make Truffle invocation plugins for TStringOps and ArrayUtils optional
1 parent 870f689 commit 26b16fa

File tree

3 files changed

+85
-43
lines changed

3 files changed

+85
-43
lines changed

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/truffle/test/ArrayUtilsTest.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -27,8 +27,17 @@
2727
import java.util.ArrayList;
2828

2929
import jdk.graal.compiler.core.test.GraalCompilerTest;
30+
import jdk.graal.compiler.graph.Node;
31+
import jdk.graal.compiler.nodes.StructuredGraph;
32+
import jdk.graal.compiler.nodes.ValueNode;
33+
import jdk.graal.compiler.nodes.graphbuilderconf.GraphBuilderContext;
34+
import jdk.graal.compiler.nodes.graphbuilderconf.InlineInvokePlugin;
3035
import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugins;
36+
import jdk.graal.compiler.replacements.nodes.ArrayIndexOfNode;
3137
import jdk.graal.compiler.truffle.substitutions.TruffleInvocationPlugins;
38+
import jdk.graal.compiler.truffle.test.strings.TStringTest;
39+
import jdk.vm.ci.meta.ResolvedJavaMethod;
40+
import org.junit.Assert;
3241
import org.junit.Test;
3342
import org.junit.runner.RunWith;
3443
import org.junit.runners.Parameterized;
@@ -134,6 +143,26 @@ public static int indexOfByteArray(byte[] haystack, int fromIndex, int maxIndex,
134143
return ArrayUtils.indexOf(haystack, fromIndex, maxIndex, needle);
135144
}
136145

146+
@Override
147+
protected void checkLowTierGraph(StructuredGraph graph) {
148+
if (TStringTest.isSupportedArchitecture(getArchitecture())) {
149+
for (Node node : graph.getNodes()) {
150+
if (node instanceof ArrayIndexOfNode) {
151+
return;
152+
}
153+
}
154+
Assert.fail("intrinsic not found in graph!");
155+
}
156+
}
157+
158+
@Override
159+
protected InlineInvokePlugin.InlineInfo bytecodeParserShouldInlineInvoke(GraphBuilderContext b, ResolvedJavaMethod method, ValueNode[] args) {
160+
if (method.getDeclaringClass().getUnqualifiedName().equals("ArrayUtils") && !method.getName().startsWith("stub")) {
161+
return InlineInvokePlugin.InlineInfo.createStandardInlineInfo(method);
162+
}
163+
return super.bytecodeParserShouldInlineInvoke(b, method, args);
164+
}
165+
137166
private static byte[] toByteArray(String s) {
138167
byte[] ret = new byte[s.length()];
139168
for (int i = 0; i < s.length(); i++) {

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/graphbuilderconf/InvocationPlugin.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -589,4 +589,16 @@ public boolean inlineOnly() {
589589
return true;
590590
}
591591
}
592+
593+
public abstract static class OptionalInlineOnlyConditionalInvocationPlugin extends InlineOnlyConditionalInvocationPlugin {
594+
595+
public OptionalInlineOnlyConditionalInvocationPlugin(String name, Type... argumentTypes) {
596+
super(name, argumentTypes);
597+
}
598+
599+
@Override
600+
public boolean isOptional() {
601+
return true;
602+
}
603+
}
592604
}

0 commit comments

Comments
 (0)