use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.RequiredInvocationPlugin in project graal by oracle.
the class SubstrateGraphBuilderPlugins method registerSystemPlugins.
private static void registerSystemPlugins(MetaAccessProvider metaAccess, InvocationPlugins plugins) {
Registration r = new Registration(plugins, System.class);
if (SubstrateOptions.FoldSecurityManagerGetter.getValue()) {
r.register(new RequiredInvocationPlugin("getSecurityManager") {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
/* System.getSecurityManager() always returns null. */
b.addPush(JavaKind.Object, ConstantNode.forConstant(SubstrateObjectConstant.forObject(null), metaAccess, b.getGraph()));
return true;
}
});
}
r.register(new RequiredInvocationPlugin("identityHashCode", Object.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object) {
b.addPush(JavaKind.Int, new SubstrateIdentityHashCodeNode(object, b.bci()));
return true;
}
});
}
use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.RequiredInvocationPlugin in project graal by oracle.
the class SubstrateGraphBuilderPlugins method registerClassDesiredAssertionStatusPlugin.
public static void registerClassDesiredAssertionStatusPlugin(InvocationPlugins plugins, SnippetReflectionProvider snippetReflection) {
Registration r = new Registration(plugins, Class.class);
r.register(new RequiredInvocationPlugin("desiredAssertionStatus", Receiver.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
JavaConstant constantReceiver = receiver.get().asJavaConstant();
if (constantReceiver != null && constantReceiver.isNonNull()) {
Object clazzOrHub = snippetReflection.asObject(Object.class, constantReceiver);
boolean desiredAssertionStatus;
if (clazzOrHub instanceof Class) {
desiredAssertionStatus = RuntimeAssertionsSupport.singleton().desiredAssertionStatus((Class<?>) clazzOrHub);
} else if (clazzOrHub instanceof DynamicHub) {
desiredAssertionStatus = ((DynamicHub) clazzOrHub).desiredAssertionStatus();
} else {
throw VMError.shouldNotReachHere("Unexpected class object: " + clazzOrHub);
}
b.addPush(JavaKind.Boolean, ConstantNode.forBoolean(desiredAssertionStatus));
return true;
}
return false;
}
});
}
use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.RequiredInvocationPlugin in project graal by oracle.
the class SubstrateGraphBuilderPlugins method registerImageInfoPlugins.
private static void registerImageInfoPlugins(MetaAccessProvider metaAccess, InvocationPlugins plugins) {
Registration proxyRegistration = new Registration(plugins, ImageInfo.class);
proxyRegistration.register(new RequiredInvocationPlugin("inImageCode") {
/**
* See {@link ImageInfo#inImageCode()}.
*/
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
b.push(JavaKind.Boolean, ConstantNode.forConstant(JavaConstant.TRUE, metaAccess, b.getGraph()));
return true;
}
});
proxyRegistration.register(new RequiredInvocationPlugin("inImageBuildtimeCode") {
/**
* See {@link ImageInfo#inImageBuildtimeCode()}.
*/
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
b.push(JavaKind.Boolean, ConstantNode.forConstant(JavaConstant.FALSE, metaAccess, b.getGraph()));
return true;
}
});
proxyRegistration.register(new RequiredInvocationPlugin("inImageRuntimeCode") {
/**
* See {@link ImageInfo#inImageRuntimeCode()}.
*/
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
b.push(JavaKind.Boolean, ConstantNode.forConstant(JavaConstant.TRUE, metaAccess, b.getGraph()));
return true;
}
});
}
use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.RequiredInvocationPlugin in project graal by oracle.
the class PointstoGraphBuilderPlugins method registerObjectPlugins.
public static void registerObjectPlugins(InvocationPlugins plugins) {
Registration r = new Registration(plugins, Object.class);
r.register(new RequiredInvocationPlugin("clone", Receiver.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
ValueNode object = receiver.get();
b.addPush(JavaKind.Object, new AnalysisObjectCloneNode(MacroParams.of(b, targetMethod, object)));
return true;
}
});
}
use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.RequiredInvocationPlugin in project graal by oracle.
the class CGlobalDataFeature method registerInvocationPlugins.
@Override
public void registerInvocationPlugins(Providers providers, SnippetReflectionProvider snippetReflection, Plugins plugins, ParsingReason reason) {
Registration r = new Registration(plugins.getInvocationPlugins(), CGlobalData.class);
r.register(new RequiredInvocationPlugin("get", Receiver.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
ValueNode cGlobalDataNode = receiver.get();
if (cGlobalDataNode.isConstant()) {
CGlobalDataImpl<?> data = (CGlobalDataImpl<?>) SubstrateObjectConstant.asObject(cGlobalDataNode.asConstant());
CGlobalDataInfo info = CGlobalDataFeature.this.map.get(data);
b.addPush(targetMethod.getSignature().getReturnKind(), new CGlobalDataLoadAddressNode(info));
} else {
ConstantNode registry = ConstantNode.forConstant(nonConstantRegistryJavaConstant, b.getMetaAccess(), b.getGraph());
ValueNode info = (ValueNode) b.handleReplacedInvoke(InvokeKind.Virtual, b.getMetaAccess().lookupJavaMethod(getCGlobalDataInfoMethod), new ValueNode[] { registry, cGlobalDataNode }, false);
b.pop(info.getStackKind());
info = b.nullCheckedValue(info);
ResolvedJavaType infoType = b.getMetaAccess().lookupJavaType(CGlobalDataInfo.class);
if (infoType instanceof AnalysisType) {
((AnalysisType) infoType).registerAsReachable();
}
ValueNode offset = b.add(LoadFieldNode.create(b.getAssumptions(), info, b.getMetaAccess().lookupJavaField(offsetField)));
CGlobalDataLoadAddressNode baseAddress = b.add(new CGlobalDataLoadAddressNode(cGlobalDataBaseAddress));
/* Both operands should have the same bits size */
ValueNode offsetWidened = b.getGraph().addOrUnique(SignExtendNode.create(offset, IntegerStamp.getBits(baseAddress.stamp(NodeView.DEFAULT)), NodeView.DEFAULT));
ValueNode address = b.add(new AddNode(baseAddress, offsetWidened));
/* Do not dereference the address if CGlobalDataInfo is not a reference */
ValueNode isSymbolReference = b.add(LoadFieldNode.create(b.getAssumptions(), info, b.getMetaAccess().lookupJavaField(isSymbolReferenceField)));
LogicNode condition = IntegerEqualsNode.create(isSymbolReference, ConstantNode.forBoolean(false, b.getGraph()), NodeView.DEFAULT);
ReadNode readValue = b.add(new ReadNode(b.add(OffsetAddressNode.create(address)), NamedLocationIdentity.ANY_LOCATION, baseAddress.stamp(NodeView.DEFAULT), OnHeapMemoryAccess.BarrierType.NONE));
AbstractBeginNode trueBegin = b.add(new BeginNode());
FixedWithNextNode predecessor = (FixedWithNextNode) trueBegin.predecessor();
predecessor.setNext(null);
AbstractBeginNode falseBegin = b.add(new BeginNode());
trueBegin.setNext(null);
IfNode ifNode = b.add(new IfNode(condition, trueBegin, falseBegin, BranchProbabilityNode.NOT_LIKELY_PROFILE));
falseBegin.setNext(null);
predecessor.setNext(ifNode);
EndNode thenEnd = b.add(new EndNode());
trueBegin.setNext(thenEnd);
EndNode elseEnd = b.add(new EndNode());
falseBegin.setNext(elseEnd);
AbstractMergeNode merge = b.add(new MergeNode());
merge.addForwardEnd(thenEnd);
merge.addForwardEnd(elseEnd);
ValuePhiNode phiNode = new ValuePhiNode(StampFactory.pointer(), merge, new ValueNode[] { address, readValue });
phiNode.inferStamp();
b.push(targetMethod.getSignature().getReturnKind(), b.getGraph().addOrUnique(phiNode));
b.setStateAfter(merge);
}
return true;
}
});
}
Aggregations