use of org.graalvm.compiler.nodes.spi.UncheckedInterfaceProvider in project graal by oracle.
the class MethodCallTargetNode method simplify.
@Override
public void simplify(SimplifierTool tool) {
// attempt to devirtualize the call
if (invoke().getContextMethod() == null) {
// avoid invokes that have placeholder bcis: they do not have a valid contextType
assert (invoke().stateAfter() != null && BytecodeFrame.isPlaceholderBci(invoke().stateAfter().bci)) || BytecodeFrame.isPlaceholderBci(invoke().stateDuring().bci);
return;
}
ResolvedJavaType contextType = (invoke().stateAfter() == null && invoke().stateDuring() == null) ? null : invoke().getContextType();
ResolvedJavaMethod specialCallTarget = findSpecialCallTarget(invokeKind, receiver(), targetMethod, contextType);
if (specialCallTarget != null) {
this.setTargetMethod(specialCallTarget);
setInvokeKind(InvokeKind.Special);
return;
}
Assumptions assumptions = graph().getAssumptions();
/*
* Even though we are not registering an assumption (see comment below), the optimization is
* only valid when speculative optimizations are enabled.
*/
if (invokeKind().isIndirect() && invokeKind().isInterface() && assumptions != null) {
// check if the type of the receiver can narrow the result
ValueNode receiver = receiver();
// try to turn a interface call into a virtual call
ResolvedJavaType declaredReceiverType = targetMethod().getDeclaringClass();
/*
* We need to check the invoke kind to avoid recursive simplification for virtual
* interface methods calls.
*/
if (declaredReceiverType.isInterface()) {
ResolvedJavaType singleImplementor = declaredReceiverType.getSingleImplementor();
if (singleImplementor != null && !singleImplementor.equals(declaredReceiverType)) {
TypeReference speculatedType = TypeReference.createTrusted(assumptions, singleImplementor);
if (tryCheckCastSingleImplementor(receiver, speculatedType)) {
return;
}
}
}
if (receiver instanceof UncheckedInterfaceProvider) {
UncheckedInterfaceProvider uncheckedInterfaceProvider = (UncheckedInterfaceProvider) receiver;
Stamp uncheckedStamp = uncheckedInterfaceProvider.uncheckedStamp();
if (uncheckedStamp != null) {
TypeReference speculatedType = StampTool.typeReferenceOrNull(uncheckedStamp);
if (speculatedType != null) {
tryCheckCastSingleImplementor(receiver, speculatedType);
}
}
}
}
}
use of org.graalvm.compiler.nodes.spi.UncheckedInterfaceProvider in project graal by oracle.
the class UncheckedInterfaceProviderTest method test.
@Test
public void test() {
StructuredGraph graph = parseEager("snippet", StructuredGraph.AllowAssumptions.YES);
for (BlackholeNode b : graph.getNodes().filter(BlackholeNode.class)) {
Assert.assertThat(b.getValue(), is(instanceOf(UncheckedInterfaceProvider.class)));
Stamp uncheckedStamp = ((UncheckedInterfaceProvider) b.getValue()).uncheckedStamp();
String context = b.getValue().toString(Verbosity.Debugger);
Assert.assertNotNull(context, uncheckedStamp);
ResolvedJavaType uncheckedType = StampTool.typeOrNull(uncheckedStamp);
ResolvedJavaType type = StampTool.typeOrNull(b.getValue());
Assert.assertEquals(context, arrayDepth(type), arrayDepth(uncheckedType));
Assert.assertTrue(context + ": " + type, type == null || type.getElementalType().isJavaLangObject());
Assert.assertNotNull(context, uncheckedType);
Assert.assertTrue(context, uncheckedType.getElementalType().isInterface());
}
}
use of org.graalvm.compiler.nodes.spi.UncheckedInterfaceProvider in project graal by oracle.
the class VerifyUsageWithEquals method isAssignableToRestrictedType.
/**
* Determines whether the type of {@code node} is assignable to the {@link #restrictedClass}.
*/
private boolean isAssignableToRestrictedType(ValueNode node, MetaAccessProvider metaAccess) {
if (node.stamp(NodeView.DEFAULT) instanceof ObjectStamp) {
ResolvedJavaType restrictedType = metaAccess.lookupJavaType(restrictedClass);
ResolvedJavaType nodeType = StampTool.typeOrNull(node);
if (nodeType == null && node instanceof LoadFieldNode) {
nodeType = (ResolvedJavaType) ((LoadFieldNode) node).field().getType();
}
if (nodeType == null && node instanceof Invoke) {
ResolvedJavaMethod target = ((Invoke) node).callTarget().targetMethod();
nodeType = (ResolvedJavaType) target.getSignature().getReturnType(target.getDeclaringClass());
}
if (nodeType == null && node instanceof UncheckedInterfaceProvider) {
nodeType = StampTool.typeOrNull(((UncheckedInterfaceProvider) node).uncheckedStamp());
}
if (nodeType != null && restrictedType.isAssignableFrom(nodeType)) {
return true;
}
}
return false;
}
Aggregations