# HG changeset patch # User Gilles Duboscq # Date 1416393408 -3600 # Node ID 0c6504598b65d0fad722f4e2a0f5c8d61a91a016 # Parent 6dc4f0be9a70815bf3bed1286c0b0bea78cbabd1 StampTool: add more methods to create object stamps to avoid using too many boolean arguments, add some javadoc, use them. diff -r 6dc4f0be9a70 -r 0c6504598b65 graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/type/StampFactory.java --- a/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/type/StampFactory.java Wed Nov 19 13:32:05 2014 +0100 +++ b/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/type/StampFactory.java Wed Nov 19 11:36:48 2014 +0100 @@ -232,24 +232,69 @@ return objectAlwaysNullStamp; } + /** + * Returns a {@link Stamp} for objects of type {@code type}, or one of its subtypes, or null. + */ public static Stamp declared(ResolvedJavaType type) { - return declared(type, false); + return object(type, false, false, false); } + /** + * Returns a {@link Stamp} for objects of type {@code type}, or one of its subtypes, but not + * null. + */ public static Stamp declaredNonNull(ResolvedJavaType type) { - return declared(type, true); + return object(type, false, true, false); + } + + /** + * Returns a {@link Stamp} for objects of type {@code type}, or one of its subtypes, or null. + * Contrary to {@link #declared(ResolvedJavaType)}, interface types will be preserved in the + * stamp. + * + * In general interface types are not verified at class loading or run-time so this should be + * used with care. + */ + public static Stamp declaredTrusted(ResolvedJavaType type) { + return object(type, false, false, true); } - public static Stamp declared(ResolvedJavaType type, boolean nonNull) { - return object(type, false, nonNull, false); + /** + * Returns a {@link Stamp} for objects of type {@code type}, or one of its subtypes, but not + * null. Contrary to {@link #declaredNonNull(ResolvedJavaType)}, interface types will be + * preserved in the stamp. + * + * In general interface types are not verified at class loading or run-time so this should be + * used with care. + */ + public static Stamp declaredTrustedNonNull(ResolvedJavaType type) { + return declaredTrusted(type, true); + } + + public static Stamp declaredTrusted(ResolvedJavaType type, boolean nonNull) { + return object(type, false, nonNull, true); } - public static Stamp declaredNonNull(ResolvedJavaType type, boolean trustInterfaces) { - return declared(type, true, trustInterfaces); + /** + * Returns a {@link Stamp} for objects of exactly type {@code type}, or null. + */ + public static Stamp exact(ResolvedJavaType type) { + if (ObjectStamp.isConcreteType(type)) { + return new ObjectStamp(type, true, false, false); + } else { + return illegal(Kind.Object); + } } - public static Stamp declared(ResolvedJavaType type, boolean nonNull, boolean trustInterfaces) { - return object(type, false, nonNull, trustInterfaces); + /** + * Returns a {@link Stamp} for non-null objects of exactly type {@code type}. + */ + public static Stamp exactNonNull(ResolvedJavaType type) { + if (ObjectStamp.isConcreteType(type)) { + return new ObjectStamp(type, true, true, false); + } else { + return illegal(Kind.Object); + } } private static ResolvedJavaType filterInterfaceTypesOut(ResolvedJavaType type) { @@ -285,22 +330,6 @@ return new ObjectStamp(trustedtype, exactType, nonNull, false); } - public static Stamp exactNonNull(ResolvedJavaType type) { - if (ObjectStamp.isConcreteType(type)) { - return new ObjectStamp(type, true, true, false); - } else { - return illegal(Kind.Object); - } - } - - public static Stamp exact(ResolvedJavaType type) { - if (ObjectStamp.isConcreteType(type)) { - return new ObjectStamp(type, true, false, false); - } else { - return illegal(Kind.Object); - } - } - public static Stamp[] createParameterStamps(ResolvedJavaMethod method) { Signature sig = method.getSignature(); Stamp[] result = new Stamp[sig.getParameterCount(!method.isStatic())]; diff -r 6dc4f0be9a70 -r 0c6504598b65 graal/com.oracle.graal.nodes.test/src/com/oracle/graal/nodes/test/ObjectStampJoinTest.java --- a/graal/com.oracle.graal.nodes.test/src/com/oracle/graal/nodes/test/ObjectStampJoinTest.java Wed Nov 19 13:32:05 2014 +0100 +++ b/graal/com.oracle.graal.nodes.test/src/com/oracle/graal/nodes/test/ObjectStampJoinTest.java Wed Nov 19 11:36:48 2014 +0100 @@ -124,14 +124,14 @@ @Test public void testJoinInterface0() { Stamp a = StampFactory.declared(getType(A.class)); - Stamp i = StampFactory.declared(getType(I.class), false, true); + Stamp i = StampFactory.declaredTrusted(getType(I.class)); Assert.assertNotSame(StampFactory.illegal(Kind.Object), join(a, i)); } @Test public void testJoinInterface1() { Stamp aNonNull = StampFactory.declaredNonNull(getType(A.class)); - Stamp i = StampFactory.declared(getType(I.class), false, true); + Stamp i = StampFactory.declaredTrusted(getType(I.class)); Stamp join = join(aNonNull, i); Assert.assertTrue(join instanceof ObjectStamp); Assert.assertTrue(((ObjectStamp) join).nonNull()); @@ -140,7 +140,7 @@ @Test public void testJoinInterface2() { Stamp bExact = StampFactory.exactNonNull(getType(B.class)); - Stamp i = StampFactory.declared(getType(I.class), false, true); + Stamp i = StampFactory.declaredTrusted(getType(I.class)); Stamp join = join(i, bExact); Assert.assertEquals(StampFactory.illegal(Kind.Object), join); } diff -r 6dc4f0be9a70 -r 0c6504598b65 graal/com.oracle.graal.nodes.test/src/com/oracle/graal/nodes/test/ObjectStampMeetTest.java --- a/graal/com.oracle.graal.nodes.test/src/com/oracle/graal/nodes/test/ObjectStampMeetTest.java Wed Nov 19 13:32:05 2014 +0100 +++ b/graal/com.oracle.graal.nodes.test/src/com/oracle/graal/nodes/test/ObjectStampMeetTest.java Wed Nov 19 11:36:48 2014 +0100 @@ -104,7 +104,7 @@ @Test public void testMeetInterface0() { Stamp a = StampFactory.declared(getType(A.class)); - Stamp i = StampFactory.declared(getType(I.class), false, true); + Stamp i = StampFactory.declaredTrusted(getType(I.class)); Assert.assertEquals(StampFactory.declared(getType(Object.class)), meet(a, i)); } diff -r 6dc4f0be9a70 -r 0c6504598b65 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/CheckCastNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/CheckCastNode.java Wed Nov 19 13:32:05 2014 +0100 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/CheckCastNode.java Wed Nov 19 11:36:48 2014 +0100 @@ -64,7 +64,7 @@ } protected CheckCastNode(ResolvedJavaType type, ValueNode object, JavaTypeProfile profile, boolean forStoreCheck) { - super(StampFactory.declared(type, false, true)); + super(StampFactory.declaredTrusted(type)); assert type != null; this.type = type; this.object = object; @@ -104,7 +104,7 @@ */ @Override public void lower(LoweringTool tool) { - Stamp newStamp = StampFactory.declared(type, false, true); + Stamp newStamp = StampFactory.declaredTrusted(type); if (stamp() instanceof ObjectStamp && object().stamp() instanceof ObjectStamp) { newStamp = ((ObjectStamp) object().stamp()).castTo((ObjectStamp) newStamp); } @@ -113,7 +113,7 @@ if (newStamp instanceof IllegalStamp) { // This is a check cast that will always fail condition = LogicConstantNode.contradiction(graph()); - newStamp = StampFactory.declared(type, false, true); + newStamp = StampFactory.declaredTrusted(type); } else if (StampTool.isObjectNonNull(object)) { condition = graph().addWithoutUnique(InstanceOfNode.create(type, object, profile)); } else { @@ -146,7 +146,7 @@ @Override public boolean inferStamp() { if (object().stamp() instanceof ObjectStamp) { - ObjectStamp castStamp = (ObjectStamp) StampFactory.declared(type, false, true); + ObjectStamp castStamp = (ObjectStamp) StampFactory.declaredTrusted(type); return updateStamp(((ObjectStamp) object().stamp()).castTo(castStamp)); } return false; diff -r 6dc4f0be9a70 -r 0c6504598b65 graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/ConditionalEliminationPhase.java --- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/ConditionalEliminationPhase.java Wed Nov 19 13:32:05 2014 +0100 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/ConditionalEliminationPhase.java Wed Nov 19 11:36:48 2014 +0100 @@ -704,7 +704,7 @@ ConstantNode nullObject = ConstantNode.defaultForKind(Kind.Object, graph); piNode = graph.unique(PiNode.create(nullObject, StampFactory.forConstant(nullObject.asJavaConstant(), metaAccess), replacementAnchor.asNode())); } else { - piNode = graph.unique(PiNode.create(object, StampFactory.declared(type, nonNull, true), replacementAnchor.asNode())); + piNode = graph.unique(PiNode.create(object, StampFactory.declaredTrusted(type, nonNull), replacementAnchor.asNode())); } checkCast.replaceAtUsages(piNode); graph.removeFixed(checkCast); diff -r 6dc4f0be9a70 -r 0c6504598b65 graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/cfs/CheckCastReduction.java --- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/cfs/CheckCastReduction.java Wed Nov 19 13:32:05 2014 +0100 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/cfs/CheckCastReduction.java Wed Nov 19 11:36:48 2014 +0100 @@ -206,7 +206,7 @@ ObjectStamp subjectStamp = (ObjectStamp) subject.stamp(); final ResolvedJavaType toType = checkCast.type(); - ObjectStamp resultStamp = (ObjectStamp) StampFactory.declared(toType, false, true); + ObjectStamp resultStamp = (ObjectStamp) StampFactory.declaredTrusted(toType); JavaTypeProfile profile = checkCast.profile(); assert FlowUtil.isLegalObjectStamp(subjectStamp); @@ -214,13 +214,13 @@ /* * Depending on what is known about the subject: - * + * * (a) definitely-non-null - * + * * (b) null-not-seen-in-profiling - * + * * (c) runtime-null-check-needed - * + * * the condition (of the cast-guard to be emitted) and the stamp (of the PiNode to be * emitted) are going to be different. Each of the three branches below deals with one of * the cases above. diff -r 6dc4f0be9a70 -r 0c6504598b65 graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/InliningUtil.java --- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/InliningUtil.java Wed Nov 19 13:32:05 2014 +0100 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/InliningUtil.java Wed Nov 19 11:36:48 2014 +0100 @@ -181,7 +181,7 @@ } public static GuardedValueNode createAnchoredReceiver(StructuredGraph graph, GuardingNode anchor, ResolvedJavaType commonType, ValueNode receiver, boolean exact) { - return createAnchoredReceiver(graph, anchor, receiver, exact ? StampFactory.exactNonNull(commonType) : StampFactory.declaredNonNull(commonType, true)); + return createAnchoredReceiver(graph, anchor, receiver, exact ? StampFactory.exactNonNull(commonType) : StampFactory.declaredTrustedNonNull(commonType)); } private static GuardedValueNode createAnchoredReceiver(StructuredGraph graph, GuardingNode anchor, ValueNode receiver, Stamp stamp) { diff -r 6dc4f0be9a70 -r 0c6504598b65 graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/nodes/typesystem/UnsafeTypeCastMacroNode.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/nodes/typesystem/UnsafeTypeCastMacroNode.java Wed Nov 19 13:32:05 2014 +0100 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/nodes/typesystem/UnsafeTypeCastMacroNode.java Wed Nov 19 11:36:48 2014 +0100 @@ -67,7 +67,7 @@ replaceAtUsages(objectArgument); GraphUtil.removeFixedWithUnusedInputs(this); } else { - Stamp piStamp = StampFactory.declared(lookupJavaType, nonNullArgument.asJavaConstant().asInt() != 0, true); + Stamp piStamp = StampFactory.declaredTrusted(lookupJavaType, nonNullArgument.asJavaConstant().asInt() != 0); ConditionAnchorNode valueAnchorNode = graph().add( ConditionAnchorNode.create(CompareNode.createCompareNode(graph(), Condition.EQ, conditionArgument, ConstantNode.forBoolean(true, graph())))); PiNode piCast = graph().unique(PiNode.create(objectArgument, piStamp, valueAnchorNode));