use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.RequiredInvocationPlugin in project graal by oracle.
the class VMThreadMTFeature method registerAccessors.
private void registerAccessors(Registration r, Class<?> valueClass, boolean isVolatile) {
String suffix = isVolatile ? "Volatile" : "";
/* get() method without the VMThread parameter. */
r.register(new RequiredInvocationPlugin("get" + suffix, Receiver.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
ValueNode threadNode = currentThread(b);
return handleGet(b, targetMethod, receiver, threadNode, isVolatile);
}
});
/* get() method with the VMThread parameter. */
r.register(new RequiredInvocationPlugin("get" + suffix, Receiver.class, IsolateThread.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode threadNode) {
return handleGet(b, targetMethod, receiver, threadNode, isVolatile);
}
});
/* set() method without the VMThread parameter. */
r.register(new RequiredInvocationPlugin("set" + suffix, Receiver.class, valueClass) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode valueNode) {
ValueNode threadNode = currentThread(b);
return handleSet(b, receiver, threadNode, valueNode, isVolatile);
}
});
/* set() method with the VMThread parameter. */
r.register(new RequiredInvocationPlugin("set" + suffix, Receiver.class, IsolateThread.class, valueClass) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode threadNode, ValueNode valueNode) {
return handleSet(b, receiver, threadNode, valueNode, isVolatile);
}
});
}
use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.RequiredInvocationPlugin in project graal by oracle.
the class StaticFieldBaseNode method registerInvocationPlugins.
@Override
public void registerInvocationPlugins(Providers providers, SnippetReflectionProvider snippetReflection, Plugins plugins, ParsingReason reason) {
Registration r = new Registration(plugins.getInvocationPlugins(), StaticFieldsSupport.class);
r.register(new RequiredInvocationPlugin("getStaticObjectFields") {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver unused) {
b.addPush(JavaKind.Object, new StaticFieldBaseNode(false));
return true;
}
});
r.register(new RequiredInvocationPlugin("getStaticPrimitiveFields") {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver unused) {
b.addPush(JavaKind.Object, new StaticFieldBaseNode(true));
return true;
}
});
}
use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.RequiredInvocationPlugin in project graal by oracle.
the class TruffleGraphBuilderPlugins method registerUnsafeCast.
public static void registerUnsafeCast(Registration r, boolean canDelayIntrinsification, EconomicSet<ResolvedJavaType> primitiveBoxTypes) {
r.register(new RequiredInvocationPlugin("unsafeCast", Object.class, Class.class, boolean.class, boolean.class, boolean.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object, ValueNode clazz, ValueNode condition, ValueNode nonNull, ValueNode isExactType) {
if (clazz.isConstant() && nonNull.isConstant() && isExactType.isConstant()) {
ConstantReflectionProvider constantReflection = b.getConstantReflection();
ResolvedJavaType javaType = constantReflection.asJavaType(clazz.asConstant());
if (javaType == null) {
b.push(JavaKind.Object, object);
} else {
TypeReference type;
if (isExactType.asJavaConstant().asInt() != 0) {
assert javaType.isConcrete() || javaType.isArray() : "exact type is not a concrete class: " + javaType;
type = TypeReference.createExactTrusted(javaType);
} else {
type = TypeReference.createTrusted(b.getAssumptions(), javaType);
}
Stamp piStamp = StampFactory.object(type, nonNull.asJavaConstant().asInt() != 0);
ConditionAnchorNode valueAnchorNode = null;
if (condition.isConstant() && condition.asJavaConstant().asInt() == 1) {
// Nothing to do.
} else {
boolean skipAnchor = false;
LogicNode compareNode = CompareNode.createCompareNode(object.graph(), CanonicalCondition.EQ, condition, ConstantNode.forBoolean(true, object.graph()), constantReflection, NodeView.DEFAULT);
if (compareNode instanceof LogicConstantNode) {
LogicConstantNode logicConstantNode = (LogicConstantNode) compareNode;
if (logicConstantNode.getValue()) {
skipAnchor = true;
}
}
if (!skipAnchor) {
valueAnchorNode = b.add(new ConditionAnchorNode(compareNode));
}
}
b.addPush(JavaKind.Object, trustedBox(type, primitiveBoxTypes, PiNode.create(object, piStamp, valueAnchorNode)));
}
return true;
} else if (canDelayIntrinsification) {
return false;
} else {
logPerformanceWarningUnsafeCastArgNotConst(targetMethod, clazz, nonNull, isExactType);
b.push(JavaKind.Object, object);
return true;
}
}
});
}
use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.RequiredInvocationPlugin in project graal by oracle.
the class TruffleGraphBuilderPlugins method registerNodePlugins.
/**
* @see com.oracle.truffle.api.nodes.Node
*/
public static void registerNodePlugins(InvocationPlugins plugins, MetaAccessProvider metaAccess, boolean canDelayIntrinsification, ConstantReflectionProvider constantReflection, KnownTruffleTypes types) {
final ResolvedJavaType nodeType = getRuntime().resolveType(metaAccess, "com.oracle.truffle.api.nodes.Node");
Registration r = new Registration(plugins, new ResolvedJavaSymbol(nodeType));
r.register(new RequiredInvocationPlugin("getRootNodeImpl", Receiver.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
if (canDelayIntrinsification) {
return false;
}
ValueNode thisValue = receiver.get();
if (!thisValue.isJavaConstant() || thisValue.isNullConstant()) {
throw b.bailout("getRootNode() receiver is not a compile-time constant or is null.");
}
final int parentLimit = MaximumLoopExplosionCount.getValue(b.getOptions());
JavaConstant parentNode = thisValue.asJavaConstant();
JavaConstant prevNode;
int parentsVisited = 0;
do {
if (parentsVisited++ > parentLimit) {
// Protect against parent cycles and extremely long parent chains.
throw b.bailout("getRootNode() did not terminate in " + parentLimit + " iterations.");
}
prevNode = parentNode;
parentNode = constantReflection.readFieldValue(types.fieldNodeParent, prevNode);
} while (parentNode.isNonNull());
JavaConstant rootNode = prevNode;
ConstantNode result = ConstantNode.forConstant(rootNode, metaAccess, b.getGraph());
// getRootNodeImpl() returns null if parent is not an instance of RootNode.
if (rootNode.isNonNull() && !types.classRootNode.isAssignableFrom(result.stamp(NodeView.DEFAULT).javaType(metaAccess))) {
result = ConstantNode.defaultForKind(JavaKind.Object, b.getGraph());
}
b.addPush(JavaKind.Object, result);
return true;
}
});
}
use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.RequiredInvocationPlugin in project graal by oracle.
the class TruffleGraphBuilderPlugins method registerOptimizedAssumptionPlugins.
public static void registerOptimizedAssumptionPlugins(InvocationPlugins plugins, MetaAccessProvider metaAccess, KnownTruffleTypes types) {
ResolvedJavaType optimizedAssumptionType = getRuntime().resolveType(metaAccess, "org.graalvm.compiler.truffle.runtime.OptimizedAssumption");
Registration r = new Registration(plugins, new ResolvedJavaSymbol(optimizedAssumptionType));
r.register(new RequiredInvocationPlugin("isValid", Receiver.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
if (receiver.isConstant() && b.getAssumptions() != null) {
JavaConstant assumption = (JavaConstant) receiver.get().asConstant();
if (b.getConstantReflection().readFieldValue(types.fieldOptimizedAssumptionIsValid, assumption).asBoolean()) {
b.addPush(JavaKind.Boolean, ConstantNode.forBoolean(true));
b.getAssumptions().record(new TruffleAssumption(assumption));
} else {
b.addPush(JavaKind.Boolean, ConstantNode.forBoolean(false));
}
return true;
} else {
return false;
}
}
});
r.register(new RequiredInvocationPlugin("check", Receiver.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
if (receiver.isConstant() && b.getAssumptions() != null) {
JavaConstant assumption = (JavaConstant) receiver.get().asConstant();
if (b.getConstantReflection().readFieldValue(types.fieldOptimizedAssumptionIsValid, assumption).asBoolean()) {
b.getAssumptions().record(new TruffleAssumption(assumption));
} else {
b.add(new DeoptimizeNode(DeoptimizationAction.InvalidateRecompile, DeoptimizationReason.None));
}
return true;
} else {
return false;
}
}
});
}
Aggregations