comparison graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java @ 2713:95e2aa413d95

Merge.
author Thomas Wuerthinger <thomas@wuerthinger.net>
date Thu, 19 May 2011 13:09:51 +0200
parents a0dd2b907806 fb4cc9812591
children 3ac3dd97d8df
comparison
equal deleted inserted replaced
2712:a0dd2b907806 2713:95e2aa413d95
342 ExceptionDispatch end = new ExceptionDispatch(null, handler.entryBlock(), null, handler, null, graph); 342 ExceptionDispatch end = new ExceptionDispatch(null, handler.entryBlock(), null, handler, null, graph);
343 end.setBlockSuccessor(0, successor); 343 end.setBlockSuccessor(0, successor);
344 dispatchEntry.appendNext(end, handler.handlerBCI()); 344 dispatchEntry.appendNext(end, handler.handlerBCI());
345 dispatchEntry.setEnd(end); 345 dispatchEntry.setEnd(end);
346 } else { 346 } else {
347 Deoptimize deopt = new Deoptimize(graph, null); 347 Deoptimize deopt = new Deoptimize(graph);
348 dispatchEntry.appendNext(deopt, bci); 348 dispatchEntry.appendNext(deopt, bci);
349 Goto end = new Goto(successor, null, graph); 349 Goto end = new Goto(successor, null, graph);
350 deopt.appendNext(end, bci); 350 deopt.appendNext(end, bci);
351 dispatchEntry.setEnd(end); 351 dispatchEntry.setEnd(end);
352 } 352 }
393 dispatch.catchSuccessor().setStateBefore(mergedState.duplicate(bci)); 393 dispatch.catchSuccessor().setStateBefore(mergedState.duplicate(bci));
394 updateDispatchChain(dispatch.otherSuccessor(), mergedState, bci); 394 updateDispatchChain(dispatch.otherSuccessor(), mergedState, bci);
395 } else if (dispatchEntry.next() instanceof Deoptimize) { 395 } else if (dispatchEntry.next() instanceof Deoptimize) {
396 // deoptimizing handler 396 // deoptimizing handler
397 Deoptimize deopt = (Deoptimize) dispatchEntry.next(); 397 Deoptimize deopt = (Deoptimize) dispatchEntry.next();
398 deopt.setStateBefore(mergedState.duplicate(bci)); 398 //deopt.setStateBefore(mergedState.duplicate(bci));
399 dispatchEntry.end().setStateAfter(mergedState.duplicate(bci)); 399 dispatchEntry.end().setStateAfter(mergedState.duplicate(bci));
400 updateDispatchChain(dispatchEntry.end().blockSuccessor(0), mergedState, bci); 400 updateDispatchChain(dispatchEntry.end().blockSuccessor(0), mergedState, bci);
401 } else if (dispatchEntry.next() instanceof Unwind) { 401 } else if (dispatchEntry.next() instanceof Unwind) {
402 // unwind handler 402 // unwind handler
403 Unwind unwind = (Unwind) dispatchEntry.next(); 403 Unwind unwind = (Unwind) dispatchEntry.next();
438 438
439 if (con instanceof RiType) { 439 if (con instanceof RiType) {
440 // this is a load of class constant which might be unresolved 440 // this is a load of class constant which might be unresolved
441 RiType riType = (RiType) con; 441 RiType riType = (RiType) con;
442 if (!riType.isResolved()) { 442 if (!riType.isResolved()) {
443 append(new Deoptimize(graph, frameState.create(bci()))); 443 append(new Deoptimize(graph));
444 frameState.push(CiKind.Object, append(Constant.forObject(null, graph))); 444 frameState.push(CiKind.Object, append(Constant.forObject(null, graph)));
445 } else { 445 } else {
446 frameState.push(CiKind.Object, append(new Constant(riType.getEncoding(Representation.JavaClass), graph))); 446 frameState.push(CiKind.Object, append(new Constant(riType.getEncoding(Representation.JavaClass), graph)));
447 } 447 }
448 } else if (con instanceof CiConstant) { 448 } else if (con instanceof CiConstant) {
651 651
652 private void genCheckCast() { 652 private void genCheckCast() {
653 int cpi = stream().readCPI(); 653 int cpi = stream().readCPI();
654 RiType type = constantPool().lookupType(cpi, CHECKCAST); 654 RiType type = constantPool().lookupType(cpi, CHECKCAST);
655 boolean isInitialized = type.isResolved(); 655 boolean isInitialized = type.isResolved();
656 Value typeInstruction = genTypeOrDeopt(RiType.Representation.ObjectHub, type, isInitialized, cpi, frameState); 656 Value typeInstruction = genTypeOrDeopt(RiType.Representation.ObjectHub, type, isInitialized, cpi);
657 CheckCast c = new CheckCast(type, typeInstruction, frameState.apop(), graph); 657 Value object = frameState.apop();
658 frameState.apush(append(c)); 658 if (typeInstruction != null) {
659 frameState.apush(append(new CheckCast(type, typeInstruction, object, graph)));
660 } else {
661 frameState.apush(appendConstant(CiConstant.NULL_OBJECT));
662 }
659 } 663 }
660 664
661 private void genInstanceOf() { 665 private void genInstanceOf() {
662 int cpi = stream().readCPI(); 666 int cpi = stream().readCPI();
663 RiType type = constantPool().lookupType(cpi, INSTANCEOF); 667 RiType type = constantPool().lookupType(cpi, INSTANCEOF);
664 boolean isInitialized = type.isResolved(); 668 boolean isInitialized = type.isResolved();
665 //System.out.println("instanceof : type.isResolved() = " + type.isResolved() + "; type.isInitialized() = " + type.isInitialized()); 669 Value typeInstruction = genTypeOrDeopt(RiType.Representation.ObjectHub, type, isInitialized, cpi);
666 Value typeInstruction = genTypeOrDeopt(RiType.Representation.ObjectHub, type, isInitialized, cpi, frameState);
667 Instruction result;
668 Value object = frameState.apop(); 670 Value object = frameState.apop();
669 if (typeInstruction != null) { 671 if (typeInstruction != null) {
670 result = new InstanceOf(type, typeInstruction, object, graph); 672 frameState.ipush(append(new InstanceOf(type, typeInstruction, object, graph)));
671 } else { 673 } else {
672 result = Constant.forInt(0, graph); 674 frameState.ipush(appendConstant(CiConstant.INT_0));
673 } 675 }
674 frameState.ipush(append(result));
675 } 676 }
676 677
677 void genNewInstance(int cpi) { 678 void genNewInstance(int cpi) {
678 RiType type = constantPool().lookupType(cpi, NEW); 679 RiType type = constantPool().lookupType(cpi, NEW);
679 FrameState stateBefore = null; 680 if (type.isResolved()) {
680 if (!type.isResolved()) { 681 NewInstance n = new NewInstance(type, cpi, constantPool(), graph);
681 stateBefore = frameState.create(bci()); 682 frameState.apush(append(n));
682 } 683 } else {
683 NewInstance n = new NewInstance(type, cpi, constantPool(), graph); 684 append(new Deoptimize(graph));
684 n.setStateBefore(stateBefore); 685 frameState.apush(appendConstant(CiConstant.NULL_OBJECT));
685 frameState.apush(append(n)); 686 }
686 } 687 }
687 688
688 private void genNewTypeArray(int typeCode) { 689 private void genNewTypeArray(int typeCode) {
689 CiKind kind = CiKind.fromArrayTypeCode(typeCode); 690 CiKind kind = CiKind.fromArrayTypeCode(typeCode);
690 RiType elementType = compilation.runtime.asRiType(kind); 691 RiType elementType = compilation.runtime.asRiType(kind);
692 frameState.apush(append(nta)); 693 frameState.apush(append(nta));
693 } 694 }
694 695
695 private void genNewObjectArray(int cpi) { 696 private void genNewObjectArray(int cpi) {
696 RiType type = constantPool().lookupType(cpi, ANEWARRAY); 697 RiType type = constantPool().lookupType(cpi, ANEWARRAY);
697 FrameState stateBefore = null; 698 Value length = frameState.ipop();
698 if (!type.isResolved()) { 699 if (type.isResolved()) {
699 stateBefore = frameState.create(bci()); 700 NewArray n = new NewObjectArray(type, length, graph);
700 } 701 frameState.apush(append(n));
701 NewArray n = new NewObjectArray(type, frameState.ipop(), graph); 702 } else {
702 frameState.apush(append(n)); 703 append(new Deoptimize(graph));
703 n.setStateBefore(stateBefore); 704 frameState.apush(appendConstant(CiConstant.NULL_OBJECT));
705 }
706
704 } 707 }
705 708
706 private void genNewMultiArray(int cpi) { 709 private void genNewMultiArray(int cpi) {
707 RiType type = constantPool().lookupType(cpi, MULTIANEWARRAY); 710 RiType type = constantPool().lookupType(cpi, MULTIANEWARRAY);
708 FrameState stateBefore = null;
709 if (!type.isResolved()) {
710 stateBefore = frameState.create(bci());
711 }
712 int rank = stream().readUByte(bci() + 3); 711 int rank = stream().readUByte(bci() + 3);
713 Value[] dims = new Value[rank]; 712 Value[] dims = new Value[rank];
714 for (int i = rank - 1; i >= 0; i--) { 713 for (int i = rank - 1; i >= 0; i--) {
715 dims[i] = frameState.ipop(); 714 dims[i] = frameState.ipop();
716 } 715 }
717 NewArray n = new NewMultiArray(type, dims, cpi, constantPool(), graph); 716 if (type.isResolved()) {
718 frameState.apush(append(n)); 717 NewArray n = new NewMultiArray(type, dims, cpi, constantPool(), graph);
719 n.setStateBefore(stateBefore); 718 frameState.apush(append(n));
719 } else {
720 append(new Deoptimize(graph));
721 frameState.apush(appendConstant(CiConstant.NULL_OBJECT));
722 }
720 } 723 }
721 724
722 private void genGetField(int cpi, RiField field) { 725 private void genGetField(int cpi, RiField field) {
723 // Must copy the state here, because the field holder must still be on the stack. 726 CiKind kind = field.kind();
724 FrameState stateBefore = null; 727 Value receiver = frameState.apop();
725 if (!field.isResolved()) { 728 if (field.isResolved()) {
726 stateBefore = frameState.create(bci()); 729 LoadField load = new LoadField(receiver, field, graph);
727 } 730 appendOptimizedLoadField(kind, load);
728 LoadField load = new LoadField(frameState.apop(), field, stateBefore, graph); 731 } else {
729 appendOptimizedLoadField(field.kind(), load); 732 append(new Deoptimize(graph));
733 frameState.push(kind.stackKind(), append(Constant.defaultForKind(kind, graph)));
734 }
730 } 735 }
731 736
732 private void genPutField(int cpi, RiField field) { 737 private void genPutField(int cpi, RiField field) {
733 // Must copy the state here, because the field holder must still be on the stack.
734 FrameState stateBefore = null;
735 if (!field.isResolved()) {
736 stateBefore = frameState.create(bci());
737 }
738 Value value = frameState.pop(field.kind().stackKind()); 738 Value value = frameState.pop(field.kind().stackKind());
739 StoreField store = new StoreField(frameState.apop(), field, value, graph); 739 Value receiver = frameState.apop();
740 appendOptimizedStoreField(store); 740 if (field.isResolved()) {
741 store.setStateBefore(stateBefore); 741 StoreField store = new StoreField(receiver, field, value, graph);
742 appendOptimizedStoreField(store);
743 } else {
744 append(new Deoptimize(graph));
745 }
742 } 746 }
743 747
744 private void genGetStatic(int cpi, RiField field) { 748 private void genGetStatic(int cpi, RiField field) {
745 RiType holder = field.holder(); 749 RiType holder = field.holder();
746 boolean isInitialized = field.isResolved(); 750 boolean isInitialized = field.isResolved();
749 constantValue = field.constantValue(null); 753 constantValue = field.constantValue(null);
750 } 754 }
751 if (constantValue != null) { 755 if (constantValue != null) {
752 frameState.push(constantValue.kind.stackKind(), appendConstant(constantValue)); 756 frameState.push(constantValue.kind.stackKind(), appendConstant(constantValue));
753 } else { 757 } else {
754 FrameState stateBefore = frameState.create(bci()); 758 Value container = genTypeOrDeopt(RiType.Representation.StaticFields, holder, isInitialized, cpi);
755 Value container = genTypeOrDeopt(RiType.Representation.StaticFields, holder, isInitialized, cpi, frameState); 759 CiKind kind = field.kind();
756 if (container == null) { 760 if (container != null) {
757 container = Constant.forObject(null, graph); 761 LoadField load = new LoadField(container, field, graph);
758 } 762 appendOptimizedLoadField(kind, load);
759 LoadField load = new LoadField(container, field, stateBefore, graph); 763 } else {
760 appendOptimizedLoadField(field.kind(), load); 764 append(new Deoptimize(graph));
765 frameState.push(kind.stackKind(), append(Constant.defaultForKind(kind, graph)));
766 }
761 } 767 }
762 } 768 }
763 769
764 private void genPutStatic(int cpi, RiField field) { 770 private void genPutStatic(int cpi, RiField field) {
765 RiType holder = field.holder(); 771 RiType holder = field.holder();
766 FrameState stateBefore = frameState.create(bci()); 772 Value container = genTypeOrDeopt(RiType.Representation.StaticFields, holder, field.isResolved(), cpi);
767 Value container = genTypeOrDeopt(RiType.Representation.StaticFields, holder, field.isResolved(), cpi, frameState);
768 Value value = frameState.pop(field.kind().stackKind()); 773 Value value = frameState.pop(field.kind().stackKind());
769 if (container != null) { 774 if (container != null) {
770 StoreField store = new StoreField(container, field, value, graph); 775 StoreField store = new StoreField(container, field, value, graph);
771 appendOptimizedStoreField(store); 776 appendOptimizedStoreField(store);
772 if (!field.isResolved()) { 777 } else {
773 store.setStateBefore(stateBefore); 778 append(new Deoptimize(graph));
774 } 779 }
775 } 780 }
776 } 781
777 782 private Value genTypeOrDeopt(RiType.Representation representation, RiType holder, boolean initialized, int cpi) {
778 private Value genTypeOrDeopt(RiType.Representation representation, RiType holder, boolean initialized, int cpi, FrameStateAccess stateBefore) {
779 if (initialized) { 783 if (initialized) {
780 return appendConstant(holder.getEncoding(representation)); 784 return appendConstant(holder.getEncoding(representation));
781 } else { 785 } else {
782 append(new Deoptimize(graph, stateBefore.duplicate(bci()))); 786 append(new Deoptimize(graph));
783 return null; 787 return null;
784 } 788 }
785 } 789 }
786 790
787 private void appendOptimizedStoreField(StoreField store) { 791 private void appendOptimizedStoreField(StoreField store) {
799 boolean isInitialized = target.isResolved() && holder.isInitialized(); 803 boolean isInitialized = target.isResolved() && holder.isInitialized();
800 if (!isInitialized && C1XOptions.ResolveClassBeforeStaticInvoke) { 804 if (!isInitialized && C1XOptions.ResolveClassBeforeStaticInvoke) {
801 // Re-use the same resolution code as for accessing a static field. Even though 805 // Re-use the same resolution code as for accessing a static field. Even though
802 // the result of resolution is not used by the invocation (only the side effect 806 // the result of resolution is not used by the invocation (only the side effect
803 // of initialization is required), it can be commoned with static field accesses. 807 // of initialization is required), it can be commoned with static field accesses.
804 genTypeOrDeopt(RiType.Representation.StaticFields, holder, isInitialized, cpi, frameState); 808 genTypeOrDeopt(RiType.Representation.StaticFields, holder, isInitialized, cpi);
805 } 809 }
806 Value[] args = frameState.popArguments(target.signature().argumentSlots(false)); 810 Value[] args = frameState.popArguments(target.signature().argumentSlots(false));
807 appendInvoke(INVOKESTATIC, target, args, cpi, constantPool); 811 appendInvoke(INVOKESTATIC, target, args, cpi, constantPool);
808 } 812 }
809 813
1033 boolean isSafepoint = isBackwards && !noSafepoints(); 1037 boolean isSafepoint = isBackwards && !noSafepoints();
1034 FrameState stateBefore = isSafepoint ? frameState.create(bci()) : null; 1038 FrameState stateBefore = isSafepoint ? frameState.create(bci()) : null;
1035 append(new LookupSwitch(frameState.ipop(), list, keys, stateBefore, graph)); 1039 append(new LookupSwitch(frameState.ipop(), list, keys, stateBefore, graph));
1036 } 1040 }
1037 1041
1038 private Value appendConstant(CiConstant type) { 1042 private Value appendConstant(CiConstant constant) {
1039 return appendWithBCI(new Constant(type, graph), bci()); 1043 return appendWithBCI(new Constant(constant, graph), bci());
1040 } 1044 }
1041 1045
1042 private Value append(Instruction x) { 1046 private Value append(Instruction x) {
1043 return appendWithBCI(x, bci()); 1047 return appendWithBCI(x, bci());
1044 } 1048 }