comparison graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java @ 2643:3b807c0c5eeb

Removed leaf type and leaf method assumptions.
author Thomas Wuerthinger <thomas@wuerthinger.net>
date Wed, 11 May 2011 14:16:13 +0200
parents 8932f1027050
children 4694daa6af3a
comparison
equal deleted inserted replaced
2642:8932f1027050 2643:3b807c0c5eeb
773 if (exact != null && exact.isResolved()) { 773 if (exact != null && exact.isResolved()) {
774 // either the holder class is exact, or the receiver object has an exact type 774 // either the holder class is exact, or the receiver object has an exact type
775 invokeDirect(exact.resolveMethodImpl(target), args, exact, cpi, constantPool); 775 invokeDirect(exact.resolveMethodImpl(target), args, exact, cpi, constantPool);
776 return; 776 return;
777 } 777 }
778 // 2. check if an assumed leaf method can be found
779 RiMethod leaf = getAssumedLeafMethod(target, receiver);
780 if (leaf != null && leaf.isResolved() && !isAbstract(leaf.accessFlags()) && leaf.holder().isResolved()) {
781 if (C1XOptions.PrintAssumptions) {
782 TTY.println("Optimistic invoke direct because of leaf method to " + leaf);
783 }
784 invokeDirect(leaf, args, null, cpi, constantPool);
785 return;
786 } else if (C1XOptions.PrintAssumptions) {
787 TTY.println("Could not make leaf method assumption for target=" + target + " leaf=" + leaf + " receiver.declaredType=" + receiver.declaredType());
788 }
789 // 3. check if the either of the holder or declared type of receiver can be assumed to be a leaf
790 exact = getAssumedLeafType(klass, receiver);
791 if (exact != null && exact.isResolved()) {
792 RiMethod targetMethod = exact.resolveMethodImpl(target);
793 if (C1XOptions.PrintAssumptions) {
794 TTY.println("Optimistic invoke direct because of leaf type to " + targetMethod);
795 }
796 // either the holder class is exact, or the receiver object has an exact type
797 invokeDirect(targetMethod, args, exact, cpi, constantPool);
798 return;
799 } else if (C1XOptions.PrintAssumptions) {
800 TTY.println("Could not make leaf type assumption for type " + klass);
801 }
802 } 778 }
803 // devirtualization failed, produce an actual invokevirtual 779 // devirtualization failed, produce an actual invokevirtual
804 appendInvoke(opcode, target, args, cpi, constantPool); 780 appendInvoke(opcode, target, args, cpi, constantPool);
805 } 781 }
806 782
845 if (assumed != null) { 821 if (assumed != null) {
846 if (C1XOptions.PrintAssumptions) { 822 if (C1XOptions.PrintAssumptions) {
847 TTY.println("Recording concrete subtype assumption in context of " + type.name() + ": " + assumed.name()); 823 TTY.println("Recording concrete subtype assumption in context of " + type.name() + ": " + assumed.name());
848 } 824 }
849 compilation.assumptions.recordConcreteSubtype(type, assumed); 825 compilation.assumptions.recordConcreteSubtype(type, assumed);
850 }
851 }
852 return assumed;
853 }
854
855 private RiType getAssumedLeafType(RiType staticType, Value receiver) {
856 RiType assumed = getAssumedLeafType(staticType);
857 if (assumed != null) {
858 return assumed;
859 }
860 RiType declared = receiver.declaredType();
861 if (declared != null && declared.isResolved()) {
862 assumed = getAssumedLeafType(declared);
863 return assumed;
864 }
865 return null;
866 }
867
868 private RiMethod getAssumedLeafMethod(RiMethod target, Value receiver) {
869 RiMethod assumed = getAssumedLeafMethod(target);
870 if (assumed != null) {
871 return assumed;
872 }
873 RiType declared = receiver.declaredType();
874 if (declared != null && declared.isResolved() && !declared.isInterface()) {
875 RiMethod impl = declared.resolveMethodImpl(target);
876 if (impl != null) {
877 assumed = getAssumedLeafMethod(impl);
878 } 826 }
879 } 827 }
880 return assumed; 828 return assumed;
881 } 829 }
882 830
1493 1441
1494 private void genArrayLength() { 1442 private void genArrayLength() {
1495 frameState.ipush(append(new ArrayLength(frameState.apop(), graph))); 1443 frameState.ipush(append(new ArrayLength(frameState.apop(), graph)));
1496 } 1444 }
1497 1445
1498 boolean assumeLeafClass(RiType type) {
1499 if (type.isResolved()) {
1500 if (isFinal(type.accessFlags())) {
1501 return true;
1502 }
1503
1504 if (C1XOptions.UseAssumptions) {
1505 RiType assumed = type.uniqueConcreteSubtype();
1506 if (assumed != null && assumed == type) {
1507 if (C1XOptions.PrintAssumptions) {
1508 TTY.println("Recording leaf class assumption for " + type.name());
1509 }
1510 compilation.assumptions.recordConcreteSubtype(type, assumed);
1511 return true;
1512 }
1513 }
1514 }
1515 return false;
1516 }
1517
1518 RiMethod getAssumedLeafMethod(RiMethod method) {
1519 if (method.isResolved()) {
1520 if (method.isLeafMethod()) {
1521 return method;
1522 }
1523
1524 if (C1XOptions.UseAssumptions) {
1525 RiMethod assumed = method.uniqueConcreteMethod();
1526 if (assumed != null) {
1527 if (C1XOptions.PrintAssumptions) {
1528 TTY.println("Recording concrete method assumption in context of " + method.holder().name() + ": " + assumed.name());
1529 }
1530 compilation.assumptions.recordConcreteMethod(method, assumed);
1531 return assumed;
1532 } else {
1533 if (C1XOptions.PrintAssumptions) {
1534 TTY.println("Did not find unique concrete method for " + method);
1535 }
1536 }
1537 }
1538 }
1539 return null;
1540 }
1541
1542 private RiConstantPool constantPool() { 1446 private RiConstantPool constantPool() {
1543 return constantPool; 1447 return constantPool;
1544 } 1448 }
1545 1449
1546 /** 1450 /**