use of org.graalvm.compiler.core.common.type.ObjectStamp in project graal by oracle.
the class BytecodeParser method genCheckCast.
private void genCheckCast() {
int cpi = getStream().readCPI();
JavaType type = lookupType(cpi, CHECKCAST);
ValueNode object = frameState.pop(JavaKind.Object);
if (!(type instanceof ResolvedJavaType)) {
handleUnresolvedCheckCast(type, object);
return;
}
TypeReference checkedType = TypeReference.createTrusted(graph.getAssumptions(), (ResolvedJavaType) type);
JavaTypeProfile profile = getProfileForTypeCheck(checkedType);
for (NodePlugin plugin : graphBuilderConfig.getPlugins().getNodePlugins()) {
if (plugin.handleCheckCast(this, object, checkedType.getType(), profile)) {
return;
}
}
ValueNode castNode = null;
if (profile != null) {
if (profile.getNullSeen().isFalse()) {
object = nullCheckedValue(object);
ResolvedJavaType singleType = profile.asSingleType();
if (singleType != null && checkedType.getType().isAssignableFrom(singleType)) {
LogicNode typeCheck = append(createInstanceOf(TypeReference.createExactTrusted(singleType), object, profile));
if (typeCheck.isTautology()) {
castNode = object;
} else {
FixedGuardNode fixedGuard = append(new FixedGuardNode(typeCheck, DeoptimizationReason.TypeCheckedInliningViolated, DeoptimizationAction.InvalidateReprofile, false));
castNode = append(PiNode.create(object, StampFactory.objectNonNull(TypeReference.createExactTrusted(singleType)), fixedGuard));
}
}
}
}
boolean nonNull = ((ObjectStamp) object.stamp(NodeView.DEFAULT)).nonNull();
if (castNode == null) {
LogicNode condition = genUnique(createInstanceOfAllowNull(checkedType, object, null));
if (condition.isTautology()) {
castNode = object;
} else {
FixedGuardNode fixedGuard = append(new FixedGuardNode(condition, DeoptimizationReason.ClassCastException, DeoptimizationAction.InvalidateReprofile, false));
castNode = append(PiNode.create(object, StampFactory.object(checkedType, nonNull), fixedGuard));
}
}
frameState.push(JavaKind.Object, castNode);
}
use of org.graalvm.compiler.core.common.type.ObjectStamp 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.ObjectStamp in project graal by oracle.
the class MethodTypeFlow method computeReturnedParamter.
private ParameterNode computeReturnedParamter() {
if (graphRef == null) {
// Some methods, e.g., native ones, don't have a graph.
return null;
}
ParameterNode retParam = null;
for (ParameterNode param : graphRef.getNodes(ParameterNode.TYPE)) {
if (param.stamp(NodeView.DEFAULT) instanceof ObjectStamp) {
boolean returnsParameter = true;
NodeIterable<ReturnNode> retIterable = graphRef.getNodes(ReturnNode.TYPE);
returnsParameter &= retIterable.count() > 0;
for (ReturnNode ret : retIterable) {
returnsParameter &= ret.result() == param;
}
if (returnsParameter) {
retParam = param;
}
}
}
return retParam;
}
use of org.graalvm.compiler.core.common.type.ObjectStamp in project graal by oracle.
the class GraphBuilderContext method nullCheckedValue.
/**
* Gets a version of a given value that has a {@linkplain StampTool#isPointerNonNull(ValueNode)
* non-null} stamp.
*/
default ValueNode nullCheckedValue(ValueNode value, DeoptimizationAction action) {
if (!StampTool.isPointerNonNull(value)) {
LogicNode condition = getGraph().unique(IsNullNode.create(value));
ObjectStamp receiverStamp = (ObjectStamp) value.stamp(NodeView.DEFAULT);
Stamp stamp = receiverStamp.join(objectNonNull());
FixedGuardNode fixedGuard = append(new FixedGuardNode(condition, NullCheckException, action, true));
ValueNode nonNullReceiver = getGraph().addOrUniqueWithInputs(PiNode.create(value, stamp, fixedGuard));
// frameState.replace(value, nonNullReceiver);
return nonNullReceiver;
}
return value;
}
use of org.graalvm.compiler.core.common.type.ObjectStamp in project graal by oracle.
the class DefaultHotSpotLoweringProvider method lowerInvoke.
private void lowerInvoke(Invoke invoke, LoweringTool tool, StructuredGraph graph) {
if (invoke.callTarget() instanceof MethodCallTargetNode) {
MethodCallTargetNode callTarget = (MethodCallTargetNode) invoke.callTarget();
NodeInputList<ValueNode> parameters = callTarget.arguments();
ValueNode receiver = parameters.size() <= 0 ? null : parameters.get(0);
if (!callTarget.isStatic() && receiver.stamp(NodeView.DEFAULT) instanceof ObjectStamp && !StampTool.isPointerNonNull(receiver)) {
ValueNode nonNullReceiver = createNullCheckedValue(receiver, invoke.asNode(), tool);
parameters.set(0, nonNullReceiver);
receiver = nonNullReceiver;
}
JavaType[] signature = callTarget.targetMethod().getSignature().toParameterTypes(callTarget.isStatic() ? null : callTarget.targetMethod().getDeclaringClass());
LoweredCallTargetNode loweredCallTarget = null;
OptionValues options = graph.getOptions();
if (InlineVTableStubs.getValue(options) && callTarget.invokeKind().isIndirect() && (AlwaysInlineVTableStubs.getValue(options) || invoke.isPolymorphic())) {
HotSpotResolvedJavaMethod hsMethod = (HotSpotResolvedJavaMethod) callTarget.targetMethod();
ResolvedJavaType receiverType = invoke.getReceiverType();
if (hsMethod.isInVirtualMethodTable(receiverType)) {
JavaKind wordKind = runtime.getTarget().wordJavaKind;
ValueNode hub = createReadHub(graph, receiver, tool);
ReadNode metaspaceMethod = createReadVirtualMethod(graph, hub, hsMethod, receiverType);
// We use LocationNode.ANY_LOCATION for the reads that access the
// compiled code entry as HotSpot does not guarantee they are final
// values.
int methodCompiledEntryOffset = runtime.getVMConfig().methodCompiledEntryOffset;
AddressNode address = createOffsetAddress(graph, metaspaceMethod, methodCompiledEntryOffset);
ReadNode compiledEntry = graph.add(new ReadNode(address, any(), StampFactory.forKind(wordKind), BarrierType.NONE));
loweredCallTarget = graph.add(new HotSpotIndirectCallTargetNode(metaspaceMethod, compiledEntry, parameters.toArray(new ValueNode[parameters.size()]), callTarget.returnStamp(), signature, callTarget.targetMethod(), HotSpotCallingConventionType.JavaCall, callTarget.invokeKind()));
graph.addBeforeFixed(invoke.asNode(), metaspaceMethod);
graph.addAfterFixed(metaspaceMethod, compiledEntry);
}
}
if (loweredCallTarget == null) {
loweredCallTarget = graph.add(new HotSpotDirectCallTargetNode(parameters.toArray(new ValueNode[parameters.size()]), callTarget.returnStamp(), signature, callTarget.targetMethod(), HotSpotCallingConventionType.JavaCall, callTarget.invokeKind()));
}
callTarget.replaceAndDelete(loweredCallTarget);
}
}
Aggregations