use of org.graalvm.compiler.core.common.type.TypeReference in project graal by oracle.
the class BytecodeParser method createExceptionDispatch.
private void createExceptionDispatch(ExceptionDispatchBlock block) {
lastInstr = finishInstruction(lastInstr, frameState);
assert frameState.stackSize() == 1 : frameState;
if (block.handler.isCatchAll()) {
assert block.getSuccessorCount() == 1;
appendGoto(block.getSuccessor(0));
return;
}
JavaType catchType = block.handler.getCatchType();
if (graphBuilderConfig.eagerResolving()) {
catchType = lookupType(block.handler.catchTypeCPI(), INSTANCEOF);
}
if (catchType instanceof ResolvedJavaType) {
TypeReference checkedCatchType = TypeReference.createTrusted(graph.getAssumptions(), (ResolvedJavaType) catchType);
if (graphBuilderConfig.getSkippedExceptionTypes() != null) {
for (ResolvedJavaType skippedType : graphBuilderConfig.getSkippedExceptionTypes()) {
if (skippedType.isAssignableFrom(checkedCatchType.getType())) {
BciBlock nextBlock = block.getSuccessorCount() == 1 ? blockMap.getUnwindBlock() : block.getSuccessor(1);
ValueNode exception = frameState.stack[0];
FixedNode trueSuccessor = graph.add(new DeoptimizeNode(InvalidateReprofile, UnreachedCode));
FixedNode nextDispatch = createTarget(nextBlock, frameState);
append(new IfNode(graph.addOrUniqueWithInputs(createInstanceOf(checkedCatchType, exception)), trueSuccessor, nextDispatch, 0));
return;
}
}
}
BciBlock nextBlock = block.getSuccessorCount() == 1 ? blockMap.getUnwindBlock() : block.getSuccessor(1);
ValueNode exception = frameState.stack[0];
/* Anchor for the piNode, which must be before any LoopExit inserted by createTarget. */
BeginNode piNodeAnchor = graph.add(new BeginNode());
ObjectStamp checkedStamp = StampFactory.objectNonNull(checkedCatchType);
PiNode piNode = graph.addWithoutUnique(new PiNode(exception, checkedStamp));
frameState.pop(JavaKind.Object);
frameState.push(JavaKind.Object, piNode);
FixedNode catchSuccessor = createTarget(block.getSuccessor(0), frameState);
frameState.pop(JavaKind.Object);
frameState.push(JavaKind.Object, exception);
FixedNode nextDispatch = createTarget(nextBlock, frameState);
piNodeAnchor.setNext(catchSuccessor);
IfNode ifNode = append(new IfNode(graph.unique(createInstanceOf(checkedCatchType, exception)), piNodeAnchor, nextDispatch, 0.5));
assert ifNode.trueSuccessor() == piNodeAnchor;
piNode.setGuard(ifNode.trueSuccessor());
} else {
handleUnresolvedExceptionType(catchType);
}
}
use of org.graalvm.compiler.core.common.type.TypeReference in project graal by oracle.
the class LoadHubNode method virtualize.
@Override
public void virtualize(VirtualizerTool tool) {
if (!GeneratePIC.getValue(tool.getOptions())) {
ValueNode alias = tool.getAlias(getValue());
TypeReference type = StampTool.typeReferenceOrNull(alias);
if (type != null && type.isExact()) {
tool.replaceWithValue(ConstantNode.forConstant(stamp(NodeView.DEFAULT), tool.getConstantReflectionProvider().asObjectHub(type.getType()), tool.getMetaAccessProvider(), graph()));
}
}
}
use of org.graalvm.compiler.core.common.type.TypeReference in project graal by oracle.
the class LoadMethodNode method canonical.
@Override
public Node canonical(CanonicalizerTool tool) {
if (hub instanceof LoadHubNode) {
ValueNode object = ((LoadHubNode) hub).getValue();
TypeReference type = StampTool.typeReferenceOrNull(object);
if (type != null) {
if (type.isExact()) {
return resolveExactMethod(tool, type.getType());
}
Assumptions assumptions = graph().getAssumptions();
AssumptionResult<ResolvedJavaMethod> resolvedMethod = type.getType().findUniqueConcreteMethod(method);
if (resolvedMethod != null && resolvedMethod.canRecordTo(assumptions) && !type.getType().isInterface() && method.getDeclaringClass().isAssignableFrom(type.getType())) {
NodeView view = NodeView.from(tool);
resolvedMethod.recordTo(assumptions);
return ConstantNode.forConstant(stamp(view), resolvedMethod.getResult().getEncoding(), tool.getMetaAccess());
}
}
}
if (hub.isConstant()) {
return resolveExactMethod(tool, tool.getConstantReflection().asJavaType(hub.asConstant()));
}
return this;
}
use of org.graalvm.compiler.core.common.type.TypeReference in project graal by oracle.
the class SubstrateObjectCloneNode method genLoadFieldNode.
@Override
protected LoadFieldNode genLoadFieldNode(Assumptions assumptions, ValueNode originalAlias, ResolvedJavaField field) {
if (field.getJavaKind() == JavaKind.Object && field.getType() instanceof SharedType) {
/*
* We have the static analysis to check interface types, e.g.., if a parameter of field
* has a declared interface type and is assigned something that does not implement the
* interface, the static analysis reports an error.
*/
TypeReference trusted = TypeReference.createTrustedWithoutAssumptions((SharedType) field.getType());
StampPair pair = StampPair.createSingle(StampFactory.object(trusted, false));
return LoadFieldNode.createOverrideStamp(pair, originalAlias, field);
} else {
return super.genLoadFieldNode(assumptions, originalAlias, field);
}
}
use of org.graalvm.compiler.core.common.type.TypeReference in project graal by oracle.
the class MethodCallTargetNode method devirtualizeCall.
public static ResolvedJavaMethod devirtualizeCall(InvokeKind invokeKind, ResolvedJavaMethod targetMethod, ResolvedJavaType contextType, Assumptions assumptions, Stamp receiverStamp) {
TypeReference type = StampTool.typeReferenceOrNull(receiverStamp);
if (type == null && invokeKind == InvokeKind.Virtual) {
// For virtual calls, we are guaranteed to receive a correct receiver type.
type = TypeReference.createTrusted(assumptions, targetMethod.getDeclaringClass());
}
if (type != null) {
/*
* either the holder class is exact, or the receiver object has an exact type, or it's
* an array type
*/
ResolvedJavaMethod resolvedMethod = type.getType().resolveConcreteMethod(targetMethod, contextType);
if (resolvedMethod != null && (resolvedMethod.canBeStaticallyBound() || type.isExact() || type.getType().isArray())) {
return resolvedMethod;
}
AssumptionResult<ResolvedJavaMethod> uniqueConcreteMethod = type.getType().findUniqueConcreteMethod(targetMethod);
if (uniqueConcreteMethod != null && uniqueConcreteMethod.canRecordTo(assumptions)) {
uniqueConcreteMethod.recordTo(assumptions);
return uniqueConcreteMethod.getResult();
}
}
return null;
}
Aggregations