use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin in project graal by oracle.
the class CountedLoopTest method registerPlugins.
private void registerPlugins(Registration r, JavaKind ivKind) {
r.register2("get", IVProperty.class, ivKind.toJavaClass(), new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode arg1, ValueNode arg2) {
IVProperty property = null;
if (arg1.isConstant()) {
property = getSnippetReflection().asObject(IVProperty.class, arg1.asJavaConstant());
}
if (property != null) {
b.addPush(ivKind, new IVPropertyNode(property, null, null, arg2));
return true;
} else {
return false;
}
}
});
r.register4("get", IVProperty.class, StaticIVProperty.class, IVPredicate.class, ivKind.toJavaClass(), new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode arg1, ValueNode arg2, ValueNode arg3, ValueNode arg4) {
IVProperty property = null;
StaticIVProperty staticProperty = null;
IVPredicate staticCheck = null;
if (arg1.isConstant()) {
property = getSnippetReflection().asObject(IVProperty.class, arg1.asJavaConstant());
}
if (arg2.isConstant()) {
staticProperty = getSnippetReflection().asObject(StaticIVProperty.class, arg2.asJavaConstant());
}
if (arg3.isConstant()) {
staticCheck = getSnippetReflection().asObject(IVPredicate.class, arg3.asJavaConstant());
}
if (property != null && staticProperty != null && staticCheck != null) {
b.addPush(ivKind, new IVPropertyNode(property, staticProperty, staticCheck, arg4));
return true;
} else {
return false;
}
}
});
}
use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin in project graal by oracle.
the class SubstrateGraphBuilderPlugins method registerJFRThrowablePlugins.
/*
* When Java Flight Recorder is enabled during image generation, the bytecodes of some methods
* get instrumented. Undo the instrumentation so that it does not end up in the generated image.
*/
private static void registerJFRThrowablePlugins(InvocationPlugins plugins, BytecodeProvider bytecodeProvider) {
Registration r = new Registration(plugins, "oracle.jrockit.jfr.jdkevents.ThrowableTracer", bytecodeProvider).setAllowOverwrite(true);
r.register2("traceError", Error.class, String.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode throwable, ValueNode message) {
return true;
}
});
r.register2("traceThrowable", Throwable.class, String.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode throwable, ValueNode message) {
return true;
}
});
}
use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin in project graal by oracle.
the class SubstrateGraphBuilderPlugins method registerClassPlugins.
private static void registerClassPlugins(InvocationPlugins plugins) {
/*
* We have our own Java-level implementation of isAssignableFrom() in DynamicHub, so we do
* not need to intrinsifiy that to a Graal node. Therefore, we overwrite and deactivate the
* invocation plugin registered in StandardGraphBuilderPlugins.
*
* TODO we should remove the implementation from DynamicHub to a lowering of
* ClassIsAssignableFromNode. Then we can remove this code.
*/
Registration r = new Registration(plugins, Class.class).setAllowOverwrite(true);
r.register2("isAssignableFrom", Receiver.class, Class.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver type, ValueNode otherType) {
return false;
}
});
r.register2("cast", Receiver.class, Object.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object) {
ValueNode toType = receiver.get();
LogicNode condition = b.append(InstanceOfDynamicNode.create(b.getAssumptions(), b.getConstantReflection(), toType, object, true));
if (condition.isTautology()) {
b.addPush(JavaKind.Object, object);
} else {
FixedGuardNode fixedGuard = b.add(new FixedGuardNode(condition, DeoptimizationReason.ClassCastException, DeoptimizationAction.InvalidateReprofile, false));
b.addPush(JavaKind.Object, DynamicPiNode.create(b.getAssumptions(), b.getConstantReflection(), object, fixedGuard, toType));
}
return true;
}
});
r.register2("isInstance", Receiver.class, Object.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object) {
ValueNode type = receiver.get();
LogicNode condition = b.append(InstanceOfDynamicNode.create(null, b.getConstantReflection(), type, object, false));
b.push(JavaKind.Boolean.getStackKind(), b.append(new ConditionalNode(condition).canonical(null)));
return true;
}
});
}
use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin in project graal by oracle.
the class SubstrateGraphBuilderPlugins method registerStackValuePlugins.
private static void registerStackValuePlugins(InvocationPlugins plugins) {
Registration r = new Registration(plugins, StackValue.class);
r.register1("get", int.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode sizeNode) {
long size = longValue(b, targetMethod, sizeNode, "size");
StackSlotIdentity slotIdentity = new StackSlotIdentity(b.getGraph().method().asStackTraceElement(b.bci()).toString());
b.addPush(JavaKind.Object, new StackValueNode(1, size, slotIdentity));
return true;
}
});
r.register2("get", int.class, int.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode numElementsNode, ValueNode elementSizeNode) {
long numElements = longValue(b, targetMethod, numElementsNode, "numElements");
long elementSize = longValue(b, targetMethod, elementSizeNode, "elementSize");
StackSlotIdentity slotIdentity = new StackSlotIdentity(b.getGraph().method().asStackTraceElement(b.bci()).toString());
b.addPush(JavaKind.Object, new StackValueNode(numElements, elementSize, slotIdentity));
return true;
}
});
}
use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin in project graal by oracle.
the class SubstrateGraphBuilderPlugins method registerUnsafePlugins.
private static void registerUnsafePlugins(InvocationPlugins plugins) {
Registration r = new Registration(plugins, Unsafe.class).setAllowOverwrite(true);
r.register2("allocateInstance", Receiver.class, Class.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode clazz) {
ValueNode clazzNonNull = b.nullCheckedValue(clazz, DeoptimizationAction.None);
b.addPush(JavaKind.Object, new SubstrateDynamicNewInstanceNode(clazzNonNull));
return true;
}
});
}
Aggregations