use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.OptionalInvocationPlugin in project graal by oracle.
the class StandardGraphBuilderPlugins method registerJMHBlackholePlugins.
private static void registerJMHBlackholePlugins(InvocationPlugins plugins, Replacements replacements) {
// 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);
for (JavaKind kind : JavaKind.values()) {
if ((kind.isPrimitive() && kind != JavaKind.Void) || kind == JavaKind.Object) {
Class<?> javaClass = getJavaClass(kind);
r.register(new OptionalInvocationPlugin("consume", Receiver.class, javaClass) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver blackhole, ValueNode value) {
blackhole.get();
b.add(new BlackholeNode(value));
return true;
}
@Override
public boolean isDecorator() {
return true;
}
});
}
}
r.register(new OptionalInvocationPlugin("consume", Receiver.class, Object[].class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver blackhole, ValueNode value) {
blackhole.get();
b.add(new BlackholeNode(value));
return true;
}
@Override
public boolean isDecorator() {
return true;
}
});
}
}
use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.OptionalInvocationPlugin in project graal by oracle.
the class IntrinsifyMethodHandlesInvocationPlugin method registerInvocationPlugins.
private static void registerInvocationPlugins(InvocationPlugins plugins, Replacements replacements) {
Registration r = new Registration(plugins, "java.lang.invoke.DirectMethodHandle", replacements);
r.register(new RequiredInvocationPlugin("ensureInitialized", Receiver.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
/*
* Method handles for static methods have a guard that initializes the class (if the
* class was not yet initialized when the method handle was created). We emit the
* class initialization check manually later on when appending nodes to the target
* graph.
*/
return true;
}
});
r = new Registration(plugins, "java.lang.invoke.Invokers", replacements);
r.register(new OptionalInvocationPlugin("maybeCustomize", MethodHandle.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode mh) {
/*
* JDK 8 update 60 added an additional customization possibility for method handles.
* For all use cases that we care about, that seems to be unnecessary, so we can
* just do nothing.
*/
return true;
}
});
r = new Registration(plugins, Objects.class, replacements);
r.register(new RequiredInvocationPlugin("requireNonNull", Object.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver unused, ValueNode object) {
/*
* Instead of inlining the method, intrinsify it to a pattern that we can easily
* detect when looking at the parsed graph.
*/
b.push(JavaKind.Object, b.addNonNullCast(object));
return true;
}
});
}
use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.OptionalInvocationPlugin in project graal by oracle.
the class StandardGraphBuilderPlugins method registerMethodHandleImplPlugins.
private static void registerMethodHandleImplPlugins(InvocationPlugins plugins, Replacements replacements) {
Registration r = new Registration(plugins, "java.lang.invoke.MethodHandleImpl", replacements);
// In later JDKs this no longer exists and the usage is replace by Class.cast which is
// already an intrinsic
r.register(new OptionalInvocationPlugin("castReference", Class.class, Object.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode javaClass, ValueNode object) {
b.genCheckcastDynamic(object, javaClass);
return true;
}
@Override
public boolean inlineOnly() {
return true;
}
});
r.register(new InlineOnlyInvocationPlugin("profileBoolean", boolean.class, int[].class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode result, ValueNode counters) {
if (b.needsExplicitException()) {
return false;
}
if (result.isConstant()) {
b.push(JavaKind.Boolean, result);
return true;
}
if (counters.isConstant()) {
ValueNode newResult = result;
int[] ctrs = ConstantReflectionUtil.loadIntArrayConstant(b.getConstantReflection(), (JavaConstant) counters.asConstant(), 2);
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.add(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;
}
b.addPush(JavaKind.Boolean, new ProfileBooleanNode(b.getConstantReflection(), MacroParams.of(b, targetMethod, result, counters)));
return true;
}
});
r.register(new RequiredInlineOnlyInvocationPlugin("isCompileConstant", Object.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode obj) {
b.addPush(JavaKind.Boolean, ConstantNode.forBoolean(obj.isConstant()));
return true;
}
});
}
Aggregations