use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.RequiredInvocationPlugin in project graal by oracle.
the class CEntryPointSupport method registerEntryPointActionsPlugins.
private static void registerEntryPointActionsPlugins(InvocationPlugins plugins) {
Registration r = new Registration(plugins, CEntryPointActions.class);
r.register(new RequiredInvocationPlugin("enterCreateIsolate", CEntryPointCreateIsolateParameters.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode parameters) {
b.addPush(JavaKind.Int, CEntryPointEnterNode.createIsolate(parameters));
return true;
}
});
r.register(new RequiredInvocationPlugin("enterAttachThread", Isolate.class, boolean.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode isolate, ValueNode ensureJavaThreadNode) {
if (!ensureJavaThreadNode.isConstant()) {
b.bailout("Parameter ensureJavaThread of enterAttachThread must be a compile time constant");
}
b.addPush(JavaKind.Int, CEntryPointEnterNode.attachThread(isolate, ensureJavaThreadNode.asJavaConstant().asInt() != 0, false));
return true;
}
});
r.register(new RequiredInvocationPlugin("enter", IsolateThread.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode thread) {
b.addPush(JavaKind.Int, CEntryPointEnterNode.enter(thread));
return true;
}
});
r.register(new RequiredInvocationPlugin("enterIsolate", Isolate.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode isolate) {
b.addPush(JavaKind.Int, CEntryPointEnterNode.enterIsolate(isolate));
return true;
}
});
r.register(new RequiredInvocationPlugin("enterAttachThreadFromCrashHandler", Isolate.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode isolate) {
b.addPush(JavaKind.Int, CEntryPointEnterNode.attachThread(isolate, false, true));
return true;
}
});
r.register(new RequiredInvocationPlugin("leave") {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
StateSplitProxyNode proxy = new StateSplitProxyNode(null);
b.add(proxy);
b.setStateAfter(proxy);
b.addPush(JavaKind.Int, new CEntryPointLeaveNode(LeaveAction.Leave));
return true;
}
});
r.register(new RequiredInvocationPlugin("leaveDetachThread") {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
StateSplitProxyNode proxy = new StateSplitProxyNode(null);
b.add(proxy);
b.setStateAfter(proxy);
b.addPush(JavaKind.Int, new CEntryPointLeaveNode(LeaveAction.DetachThread));
return true;
}
});
r.register(new RequiredInvocationPlugin("leaveTearDownIsolate") {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
StateSplitProxyNode proxy = new StateSplitProxyNode(null);
b.add(proxy);
b.setStateAfter(proxy);
b.addPush(JavaKind.Int, new CEntryPointLeaveNode(LeaveAction.TearDownIsolate));
return true;
}
});
r.register(new RequiredInvocationPlugin("failFatally", int.class, CCharPointer.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode arg1, ValueNode arg2) {
b.add(new CEntryPointUtilityNode(UtilityAction.FailFatally, arg1, arg2));
/*
* FailFatally does not return, so we can cut out any control flow afterwards and
* set the probability of the IfNode that leads to this branch.
*/
LoweredDeadEndNode deadEndNode = b.add(new LoweredDeadEndNode());
AbstractBeginNode prevBegin = AbstractBeginNode.prevBegin(deadEndNode);
if (prevBegin != null && prevBegin.predecessor() instanceof IfNode) {
((IfNode) prevBegin.predecessor()).setProbability(prevBegin, BranchProbabilityNode.EXTREMELY_SLOW_PATH_PROFILE);
}
return true;
}
});
r.register(new RequiredInvocationPlugin("isCurrentThreadAttachedTo", Isolate.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode isolate) {
b.addPush(JavaKind.Boolean, new CEntryPointUtilityNode(UtilityAction.IsAttached, isolate));
return true;
}
});
}
use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.RequiredInvocationPlugin in project graal by oracle.
the class StandardGraphBuilderPlugins method registerGraalDirectivesPlugins.
private static void registerGraalDirectivesPlugins(InvocationPlugins plugins, SnippetReflectionProvider snippetReflection) {
Registration r = new Registration(plugins, GraalDirectives.class);
r.register(new DeoptimizePlugin(snippetReflection, None, TransferToInterpreter, false, "deoptimize"));
r.register(new DeoptimizePlugin(snippetReflection, InvalidateReprofile, TransferToInterpreter, false, "deoptimizeAndInvalidate"));
r.register(new DeoptimizePlugin(snippetReflection, null, null, null, "deoptimize", DeoptimizationAction.class, DeoptimizationReason.class, boolean.class));
r.register(new DeoptimizePlugin(snippetReflection, null, null, null, "deoptimize", DeoptimizationAction.class, DeoptimizationReason.class, SpeculationReason.class));
r.register(new RequiredInlineOnlyInvocationPlugin("inCompiledCode") {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
b.addPush(JavaKind.Boolean, ConstantNode.forBoolean(true));
return true;
}
});
r.register(new RequiredInlineOnlyInvocationPlugin("inIntrinsic") {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
b.addPush(JavaKind.Boolean, ConstantNode.forBoolean(b.parsingIntrinsic()));
return true;
}
});
r.register(new RequiredInlineOnlyInvocationPlugin("controlFlowAnchor") {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
b.add(new ControlFlowAnchorNode());
return true;
}
});
r.register(new RequiredInlineOnlyInvocationPlugin("neverStripMine") {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
b.add(new NeverStripMineNode());
return true;
}
});
r.register(new RequiredInlineOnlyInvocationPlugin("sideEffect") {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
b.add(new SideEffectNode());
return true;
}
});
r.register(new RequiredInlineOnlyInvocationPlugin("sideEffect", int.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode a) {
b.addPush(JavaKind.Int, new SideEffectNode(a));
return true;
}
});
r.register(new RequiredInlineOnlyInvocationPlugin("trustedBox", Object.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode a) {
b.addPush(JavaKind.Object, new TrustedBoxedValue(a));
return true;
}
});
r.register(new RequiredInlineOnlyInvocationPlugin("assumeStableDimension", Object.class, int.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode array, ValueNode dimension) {
if (array instanceof ConstantNode && b.getMetaAccess().lookupJavaType(array.asJavaConstant()).isArray()) {
if (dimension instanceof ConstantNode && dimension.stamp(NodeView.DEFAULT) instanceof IntegerStamp) {
int stableDim = dimension.asJavaConstant().asInt();
ConstantNode c = ConstantNode.forConstant(array.asJavaConstant(), stableDim, false, b.getMetaAccess());
b.addPush(JavaKind.Object, c);
return true;
}
}
throw GraalError.shouldNotReachHere("Illegal usage of stable array intrinsic assumeStableDimension(array, dimension): " + "This compiler intrinsic can only be used iff array is a constant node (i.e., constant field) and iff " + "dimension is a constant int. It will replace the constant array with a new constant that additionally sets the stable" + "dimensions to the int parameter supplied.");
}
});
r.register(new RequiredInlineOnlyInvocationPlugin("injectBranchProbability", double.class, boolean.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode probability, ValueNode condition) {
b.addPush(JavaKind.Boolean, new BranchProbabilityNode(probability, condition));
return true;
}
});
r.register(new RequiredInlineOnlyInvocationPlugin("injectIterationCount", double.class, boolean.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode iterations, ValueNode condition) {
// injectBranchProbability(1. - 1. / iterations, condition)
if (iterations.isJavaConstant()) {
double iterationsConstant;
if (iterations.stamp(NodeView.DEFAULT) instanceof IntegerStamp) {
iterationsConstant = iterations.asJavaConstant().asLong();
} else if (iterations.stamp(NodeView.DEFAULT) instanceof FloatStamp) {
iterationsConstant = iterations.asJavaConstant().asDouble();
} else {
return false;
}
double probability = 1. - 1. / iterationsConstant;
ValueNode probabilityNode = b.add(ConstantNode.forDouble(probability));
b.addPush(JavaKind.Boolean, new BranchProbabilityNode(probabilityNode, condition));
return true;
}
return false;
}
});
for (JavaKind kind : JavaKind.values()) {
if ((kind.isPrimitive() && kind != JavaKind.Void) || kind == JavaKind.Object) {
Class<?> javaClass = getJavaClass(kind);
r.register(new RequiredInlineOnlyInvocationPlugin("blackhole", javaClass) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
b.add(new BlackholeNode(value));
return true;
}
});
r.register(new RequiredInlineOnlyInvocationPlugin("bindToRegister", javaClass) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
b.add(new BindToRegisterNode(value));
return true;
}
});
r.register(new RequiredInvocationPlugin("opaque", javaClass) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
b.addPush(kind, new OpaqueNode(value));
return true;
}
});
}
}
r.register(new RequiredInlineOnlyInvocationPlugin("spillRegisters") {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
b.add(new SpillRegistersNode());
return true;
}
});
r.register(new RequiredInlineOnlyInvocationPlugin("guardingNonNull", Object.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
b.addPush(value.getStackKind(), b.nullCheckedValue(value));
return true;
}
});
r.register(new RequiredInlineOnlyInvocationPlugin("ensureVirtualized", Object.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object) {
b.add(new EnsureVirtualizedNode(object, false));
return true;
}
});
r.register(new RequiredInlineOnlyInvocationPlugin("ensureVirtualizedHere", Object.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object) {
b.add(new EnsureVirtualizedNode(object, true));
return true;
}
});
r.register(new RequiredInvocationPlugin("breakpoint") {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
b.add(new BreakpointNode());
return true;
}
});
for (JavaKind kind : JavaKind.values()) {
if ((kind.isPrimitive() && kind != JavaKind.Void) || kind == JavaKind.Object) {
Class<?> javaClass = getJavaClass(kind);
r.register(new RequiredInlineOnlyInvocationPlugin("isCompilationConstant", javaClass) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
b.addPush(JavaKind.Boolean, ConstantNode.forBoolean(value.isJavaConstant()));
return true;
}
});
}
}
}
Aggregations