Mercurial > hg > truffle
changeset 18240:b7b85f57a21a
Add utility for testing whether a stamp can be improved. And a utility for getting the default stamps of the parameters of a method.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Tue, 01 Jul 2014 15:43:48 +0200 |
parents | 9670aff0388b |
children | 57511d7d5a10 |
files | graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/type/Stamp.java graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/type/StampFactory.java |
diffstat | 2 files changed, 41 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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; + } }
--- 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; + } }