protected LogicNode createInstanceOfAllowNull(TypeReference type, ValueNode object, JavaTypeProfile profile) { return InstanceOfNode.createAllowNull(type, object, profile, createAnchor(profile)); }
private static ValueNode castObject(JNIGraphKit kit, ValueNode object, ResolvedJavaType type) { ValueNode casted = object; if (!type.isJavaLangObject()) { // safe cast to expected type TypeReference typeRef = TypeReference.createTrusted(kit.getAssumptions(), type); LogicNode condition = kit.append(InstanceOfNode.createAllowNull(typeRef, object, null, null)); if (!condition.isTautology()) { ObjectStamp stamp = StampFactory.object(typeRef, false); FixedGuardNode fixedGuard = kit.append(new FixedGuardNode(condition, DeoptimizationReason.ClassCastException, DeoptimizationAction.None, false)); casted = kit.append(PiNode.create(object, stamp, fixedGuard)); } } return casted; } }
private static LogicNode findSynonym(Assumptions assumptions, ConstantReflectionProvider constantReflection, ValueNode forMirror, ValueNode forObject, boolean allowNull, boolean exact) { if (forMirror.isConstant()) { ResolvedJavaType t = constantReflection.asJavaType(forMirror.asConstant()); if (t != null) { if (t.isPrimitive()) { if (allowNull) { return IsNullNode.create(forObject); } else { return LogicConstantNode.contradiction(); } } else { TypeReference type = exact ? TypeReference.createExactTrusted(t) : TypeReference.createTrusted(assumptions, t); if (allowNull) { return InstanceOfNode.createAllowNull(type, forObject, null, null); } else { return InstanceOfNode.create(type, forObject); } } } } return null; }
private static ValueNode createCheckcast(HostedGraphKit graphKit, ValueNode value, ResolvedJavaType type, boolean nonNull) { TypeReference typeRef = TypeReference.createTrusted(graphKit.getAssumptions(), type); LogicNode condition; if (nonNull) { condition = graphKit.append(InstanceOfNode.create(typeRef, value)); } else { condition = graphKit.append(InstanceOfNode.createAllowNull(typeRef, value, null, null)); } graphKit.startIf(condition, BranchProbabilityNode.FAST_PATH_PROBABILITY); graphKit.thenPart(); PiNode ret = graphKit.createPiNode(value, StampFactory.object(typeRef, nonNull)); graphKit.elsePart(); throwFailedCast(graphKit, type, value); graphKit.endIf(); return ret; }
public ValueNode createEnumLookupInvoke(HostedGraphKit kit, ResolvedJavaType enumType, EnumInfo enumInfo, JavaKind parameterKind, ValueNode arg) { // Create the invoke to the actual target method: EnumRuntimeData.convertCToJava int invokeBci = kit.bci(); int exceptionEdgeBci = kit.bci(); MethodCallTargetNode callTarget = invokeEnumLookup(kit, CallTargetFactory.from(kit), invokeBci, enumInfo, parameterKind, arg); InvokeWithExceptionNode invoke = kit.createInvokeWithExceptionAndUnwind(callTarget, kit.getFrameState(), invokeBci, exceptionEdgeBci); // Create the instanceof guard to narrow the return type for the analysis LogicNode instanceOfNode = kit.append(InstanceOfNode.createAllowNull(TypeReference.createExactTrusted(enumType), invoke, null, null)); FixedGuardNode guard = kit.append(new FixedGuardNode(instanceOfNode, DeoptimizationReason.ClassCastException, DeoptimizationAction.None)); // Create the PiNode anchored at the guard to narrow the return type for compilation ObjectStamp resultStamp = StampFactory.object(TypeReference.create(null, enumType), false); return kit.unique(new PiNode(invoke, resultStamp, guard)); }
ResolvedJavaType argumentType = StampTool.typeOrNull(argument.stamp(NodeView.DEFAULT)); if (argumentType == null || (argumentType.isAssignableFrom(targetType.getType()) && !argumentType.equals(targetType.getType()))) { LogicNode inst = InstanceOfNode.createAllowNull(targetType, argument, null, null); assert !inst.isAlive(); if (!inst.isTautology()) {
if (!type.isPrimitive() && !type.isJavaLangObject()) { TypeReference typeRef = TypeReference.createTrusted(kit.getAssumptions(), type); LogicNode instanceOf = kit.unique(InstanceOfNode.createAllowNull(typeRef, value, null, null)); typeChecks = LogicNode.and(typeChecks, instanceOf, BranchProbabilityNode.FAST_PATH_PROBABILITY); FixedGuardNode guard = kit.append(new FixedGuardNode(instanceOf, DeoptimizationReason.ClassCastException, DeoptimizationAction.None, false));