# HG changeset patch # User Thomas Wuerthinger # Date 1404222228 -7200 # Node ID b7b85f57a21a7920cae9d7bb095e0d2d27dbeee2 # Parent 9670aff0388b3093a6429ac86b2c2d64dc6b8aa8 Add utility for testing whether a stamp can be improved. And a utility for getting the default stamps of the parameters of a method. diff -r 9670aff0388b -r b7b85f57a21a graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/type/Stamp.java --- a/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/type/Stamp.java Tue Jul 01 15:41:54 2014 +0200 +++ b/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/type/Stamp.java Tue Jul 01 15:43:48 2014 +0200 @@ -115,4 +115,19 @@ public Constant asConstant() { return null; } + + /** + * Tries to improve this stamp with the stamp given as parameter. If successful, returns the new + * improved stamp. Otherwise, returns null. + * + * @param other the stamp that should be used to improve this stamp + * @return the newly improved stamp of null if an improvement was not possible + */ + public Stamp tryImprove(Stamp other) { + Stamp newStamp = this.join(other); + if (newStamp.equals(this)) { + return null; + } + return newStamp; + } } diff -r 9670aff0388b -r b7b85f57a21a 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 Tue Jul 01 15:41:54 2014 +0200 +++ b/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/type/StampFactory.java Tue Jul 01 15:43:48 2014 +0200 @@ -250,4 +250,30 @@ public static Stamp exact(ResolvedJavaType type) { return new ObjectStamp(type, true, false, false); } + + public static Stamp[] createParameterStamps(ResolvedJavaMethod method) { + Signature sig = method.getSignature(); + Stamp[] result = new Stamp[sig.getParameterCount(!method.isStatic())]; + int index = 0; + + if (!method.isStatic()) { + result[index++] = StampFactory.declaredNonNull(method.getDeclaringClass()); + } + + int max = sig.getParameterCount(false); + ResolvedJavaType accessingClass = method.getDeclaringClass(); + for (int i = 0; i < max; i++) { + JavaType type = sig.getParameterType(i, accessingClass); + Kind kind = type.getKind(); + Stamp stamp; + if (kind == Kind.Object && type instanceof ResolvedJavaType) { + stamp = StampFactory.declared((ResolvedJavaType) type); + } else { + stamp = StampFactory.forKind(kind); + } + result[index++] = stamp; + } + + return result; + } }