# HG changeset patch # User Thomas Wuerthinger # Date 1406752089 -7200 # Node ID 691e2b53dc6389e2bff19cfe89e418f03762b764 # Parent 4221c8332c3461d0ff5a7c11a80d09b7736442b1# Parent b363053f6cac621b44bad3d02dd23680cfa1d3e8 Merge. diff -r 4221c8332c34 -r 691e2b53dc63 graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/JavaType.java --- a/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/JavaType.java Tue Nov 04 14:06:35 2014 +0100 +++ b/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/JavaType.java Wed Jul 30 22:28:09 2014 +0200 @@ -43,6 +43,25 @@ String getName(); /** + * Returns an unqualified name of this type. + * + *
+     *     "Object"
+     *     "Integer"
+     * 
+ */ + default String getUnqualifiedName() { + String name = getName(); + if (name.indexOf('/') != -1) { + name = name.substring(name.lastIndexOf('/') + 1); + } + if (name.endsWith(";")) { + name = name.substring(0, name.length() - 1); + } + return name; + } + + /** * For array types, gets the type of the components, or {@code null} if this is not an array * type. This method is analogous to {@link Class#getComponentType()}. */ diff -r 4221c8332c34 -r 691e2b53dc63 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 Nov 04 14:06:35 2014 +0100 +++ b/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/type/Stamp.java Wed Jul 30 22:28:09 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 4221c8332c34 -r 691e2b53dc63 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 Nov 04 14:06:35 2014 +0100 +++ b/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/type/StampFactory.java Wed Jul 30 22:28:09 2014 +0200 @@ -284,4 +284,30 @@ return illegal(Kind.Object); } } + + 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; + } } diff -r 4221c8332c34 -r 691e2b53dc63 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/StructuredGraph.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/StructuredGraph.java Tue Nov 04 14:06:35 2014 +0100 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/StructuredGraph.java Wed Jul 30 22:28:09 2014 +0200 @@ -26,6 +26,7 @@ import java.util.concurrent.atomic.*; import com.oracle.graal.api.meta.*; +import com.oracle.graal.compiler.common.type.*; import com.oracle.graal.graph.*; import com.oracle.graal.graph.spi.*; import com.oracle.graal.nodes.calc.*; @@ -110,6 +111,21 @@ this.entryBCI = entryBCI; } + public Stamp getReturnStamp() { + Stamp returnStamp = null; + for (ReturnNode returnNode : getNodes(ReturnNode.class)) { + ValueNode result = returnNode.result(); + if (result != null) { + if (returnStamp == null) { + returnStamp = result.stamp(); + } else { + returnStamp = returnStamp.meet(result.stamp()); + } + } + } + return returnStamp; + } + @Override public String toString() { StringBuilder buf = new StringBuilder(getClass().getSimpleName() + ":" + graphId); diff -r 4221c8332c34 -r 691e2b53dc63 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/MethodCallTargetNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/MethodCallTargetNode.java Tue Nov 04 14:06:35 2014 +0100 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/MethodCallTargetNode.java Wed Jul 30 22:28:09 2014 +0200 @@ -113,6 +113,10 @@ // check if the type of the receiver can narrow the result ValueNode receiver = receiver(); ResolvedJavaType type = StampTool.typeOrNull(receiver); + if (type == null && invokeKind == InvokeKind.Virtual) { + // For virtual calls, we are guaranteed to receive a correct receiver type. + type = targetMethod.getDeclaringClass(); + } if (type != null && (invoke().stateAfter() != null || invoke().stateDuring() != null)) { /* * either the holder class is exact, or the receiver object has an exact type, or