# HG changeset patch # User Tom Rodriguez # Date 1418675136 28800 # Node ID 2885aafd812f5c1a87f16f7d73e2ee136049cb08 # Parent 0a109f5d587362a57f5be18a20185c3394a47bdb Backout useless changeset c2b23f6e4603 diff -r 0a109f5d5873 -r 2885aafd812f 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 Mon Dec 15 19:15:39 2014 +0100 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/MethodCallTargetNode.java Mon Dec 15 12:25:36 2014 -0800 @@ -112,20 +112,52 @@ } // check if the type of the receiver can narrow the result - if (tryToResolveMethod(tool)) { - return; + 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 + * it's an array type + */ + ResolvedJavaMethod resolvedMethod = type.resolveConcreteMethod(targetMethod(), invoke().getContextType()); + if (resolvedMethod != null && (resolvedMethod.canBeStaticallyBound() || StampTool.isExactType(receiver) || type.isArray())) { + setInvokeKind(InvokeKind.Special); + setTargetMethod(resolvedMethod); + return; + } + if (tool.assumptions() != null && tool.assumptions().useOptimisticAssumptions()) { + ResolvedJavaType uniqueConcreteType = type.findUniqueConcreteSubtype(); + if (uniqueConcreteType != null) { + ResolvedJavaMethod methodFromUniqueType = uniqueConcreteType.resolveConcreteMethod(targetMethod(), invoke().getContextType()); + if (methodFromUniqueType != null) { + tool.assumptions().recordConcreteSubtype(type, uniqueConcreteType); + setInvokeKind(InvokeKind.Special); + setTargetMethod(methodFromUniqueType); + return; + } + } - ValueNode receiver = receiver(); - - // try to turn an interface call into a virtual call + ResolvedJavaMethod uniqueConcreteMethod = type.findUniqueConcreteMethod(targetMethod()); + if (uniqueConcreteMethod != null) { + tool.assumptions().recordConcreteMethod(targetMethod(), type, uniqueConcreteMethod); + setInvokeKind(InvokeKind.Special); + setTargetMethod(uniqueConcreteMethod); + return; + } + } + } + // try to turn a interface call into a virtual call ResolvedJavaType declaredReceiverType = targetMethod().getDeclaringClass(); /* * We need to check the invoke kind to avoid recursive simplification for virtual * interface methods calls. */ if (declaredReceiverType.isInterface() && !invokeKind().equals(InvokeKind.Virtual)) { - tryCheckCastSingleImplementor(tool, receiver, declaredReceiverType); + tryCheckCastSingleImplementor(receiver, declaredReceiverType); } if (invokeKind().equals(InvokeKind.Interface) && receiver instanceof UncheckedInterfaceProvider) { @@ -134,62 +166,14 @@ if (uncheckedStamp != null) { ResolvedJavaType uncheckedReceiverType = StampTool.typeOrNull(uncheckedStamp); if (uncheckedReceiverType.isInterface()) { - tryCheckCastSingleImplementor(tool, receiver, uncheckedReceiverType); + tryCheckCastSingleImplementor(receiver, uncheckedReceiverType); } } } } } - /** - * Try to use receiver type information to statically bind the method. - * - * @param tool - * @return true if successfully converted to InvokeKind.Special - */ - private boolean tryToResolveMethod(SimplifierTool tool) { - 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 it's - * an array type - */ - ResolvedJavaMethod resolvedMethod = type.resolveConcreteMethod(targetMethod(), invoke().getContextType()); - if (resolvedMethod != null && (resolvedMethod.canBeStaticallyBound() || StampTool.isExactType(receiver) || type.isArray())) { - setInvokeKind(InvokeKind.Special); - setTargetMethod(resolvedMethod); - return true; - } - if (tool.assumptions() != null && tool.assumptions().useOptimisticAssumptions()) { - ResolvedJavaType uniqueConcreteType = type.findUniqueConcreteSubtype(); - if (uniqueConcreteType != null) { - ResolvedJavaMethod methodFromUniqueType = uniqueConcreteType.resolveConcreteMethod(targetMethod(), invoke().getContextType()); - if (methodFromUniqueType != null) { - tool.assumptions().recordConcreteSubtype(type, uniqueConcreteType); - setInvokeKind(InvokeKind.Special); - setTargetMethod(methodFromUniqueType); - return true; - } - } - - ResolvedJavaMethod uniqueConcreteMethod = type.findUniqueConcreteMethod(targetMethod()); - if (uniqueConcreteMethod != null) { - tool.assumptions().recordConcreteMethod(targetMethod(), type, uniqueConcreteMethod); - setInvokeKind(InvokeKind.Special); - setTargetMethod(uniqueConcreteMethod); - return true; - } - } - } - return false; - } - - private void tryCheckCastSingleImplementor(SimplifierTool tool, ValueNode receiver, ResolvedJavaType declaredReceiverType) { + private void tryCheckCastSingleImplementor(ValueNode receiver, ResolvedJavaType declaredReceiverType) { ResolvedJavaType singleImplementor = declaredReceiverType.getSingleImplementor(); if (singleImplementor != null && !singleImplementor.equals(declaredReceiverType)) { ResolvedJavaMethod singleImplementorMethod = singleImplementor.resolveMethod(targetMethod(), invoke().getContextType(), true); @@ -214,8 +198,6 @@ arguments().set(0, piNode); setInvokeKind(InvokeKind.Virtual); setTargetMethod(singleImplementorMethod); - // Now try to bind the method exactly. - tryToResolveMethod(tool); } } }