use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration in project graal by oracle.
the class StandardGraphBuilderPlugins method registerJMHBlackholePlugins.
private static void registerJMHBlackholePlugins(InvocationPlugins plugins, BytecodeProvider bytecodeProvider) {
InvocationPlugin blackholePlugin = new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver blackhole, ValueNode value) {
blackhole.get();
b.add(new BlackholeNode(value));
return true;
}
};
String[] names = { "org.openjdk.jmh.infra.Blackhole", "org.openjdk.jmh.logic.BlackHole" };
for (String name : names) {
Registration r = new Registration(plugins, name, bytecodeProvider);
for (JavaKind kind : JavaKind.values()) {
if ((kind.isPrimitive() && kind != JavaKind.Void) || kind == JavaKind.Object) {
Class<?> javaClass = kind == JavaKind.Object ? Object.class : kind.toJavaClass();
r.registerOptional2("consume", Receiver.class, javaClass, blackholePlugin);
}
}
r.registerOptional2("consume", Receiver.class, Object[].class, blackholePlugin);
}
}
use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration in project graal by oracle.
the class StandardGraphBuilderPlugins method registerMethodHandleImplPlugins.
private static void registerMethodHandleImplPlugins(InvocationPlugins plugins, SnippetReflectionProvider snippetReflection, BytecodeProvider bytecodeProvider) {
Registration r = new Registration(plugins, "java.lang.invoke.MethodHandleImpl", bytecodeProvider);
r.register2("profileBoolean", boolean.class, int[].class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode result, ValueNode counters) {
if (result.isConstant()) {
b.push(JavaKind.Boolean, result);
return true;
}
if (counters.isConstant()) {
ValueNode newResult = result;
int[] ctrs = snippetReflection.asObject(int[].class, (JavaConstant) counters.asConstant());
if (ctrs != null && ctrs.length == 2) {
int falseCount = ctrs[0];
int trueCount = ctrs[1];
int totalCount = trueCount + falseCount;
if (totalCount == 0) {
b.add(new DeoptimizeNode(DeoptimizationAction.InvalidateReprofile, DeoptimizationReason.TransferToInterpreter));
} else if (falseCount == 0 || trueCount == 0) {
boolean expected = falseCount == 0;
LogicNode condition = b.addWithInputs(IntegerEqualsNode.create(b.getConstantReflection(), b.getMetaAccess(), b.getOptions(), null, result, b.add(ConstantNode.forBoolean(!expected)), NodeView.DEFAULT));
b.append(new FixedGuardNode(condition, DeoptimizationReason.UnreachedCode, DeoptimizationAction.InvalidateReprofile, true));
newResult = b.add(ConstantNode.forBoolean(expected));
} else {
// We cannot use BranchProbabilityNode here since there's no guarantee
// the result of MethodHandleImpl.profileBoolean() is used as the
// test in an `if` statement (as required by BranchProbabilityNode).
}
}
b.addPush(JavaKind.Boolean, newResult);
return true;
}
return false;
}
});
}
use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration in project graal by oracle.
the class StandardGraphBuilderPlugins method registerArrayPlugins.
private static void registerArrayPlugins(InvocationPlugins plugins, BytecodeProvider bytecodeProvider) {
Registration r = new Registration(plugins, Array.class, bytecodeProvider);
r.register2("newInstance", Class.class, int.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver unused, ValueNode componentType, ValueNode length) {
b.addPush(JavaKind.Object, new DynamicNewArrayNode(componentType, length, true));
return true;
}
});
r.registerMethodSubstitution(ArraySubstitutions.class, "getLength", Object.class);
}
use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration in project graal by oracle.
the class StandardGraphBuilderPlugins method registerShortPlugins.
private static void registerShortPlugins(InvocationPlugins plugins) {
Registration r = new Registration(plugins, Short.class);
r.register1("reverseBytes", short.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
// return (short) (Integer.reverse(i) >> 16);
ReverseBytesNode reverse = b.add(new ReverseBytesNode(value));
RightShiftNode rightShift = b.add(new RightShiftNode(reverse, b.add(ConstantNode.forInt(16))));
SignExtendNode charCast = b.add(new SignExtendNode(b.add(new NarrowNode(rightShift, 16)), 32));
b.push(JavaKind.Short, b.append(charCast.canonical(null)));
return true;
}
});
}
use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration in project graal by oracle.
the class StandardGraphBuilderPlugins method registerArraysPlugins.
private static void registerArraysPlugins(InvocationPlugins plugins, BytecodeProvider bytecodeProvider) {
Registration r = new Registration(plugins, Arrays.class, bytecodeProvider);
r.registerMethodSubstitution(ArraysSubstitutions.class, "equals", boolean[].class, boolean[].class);
r.registerMethodSubstitution(ArraysSubstitutions.class, "equals", byte[].class, byte[].class);
r.registerMethodSubstitution(ArraysSubstitutions.class, "equals", short[].class, short[].class);
r.registerMethodSubstitution(ArraysSubstitutions.class, "equals", char[].class, char[].class);
r.registerMethodSubstitution(ArraysSubstitutions.class, "equals", int[].class, int[].class);
r.registerMethodSubstitution(ArraysSubstitutions.class, "equals", long[].class, long[].class);
}
Aggregations