Mercurial > hg > truffle
comparison graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java @ 2673:98447ab8bd83
Create less nodes in case of Deopt
author | Gilles Duboscq <gilles.duboscq@oracle.com> |
---|---|
date | Fri, 13 May 2011 11:19:25 +0200 |
parents | d8601d421b96 |
children | 6ab73784566a |
comparison
equal
deleted
inserted
replaced
2672:35453d725a2a | 2673:98447ab8bd83 |
---|---|
538 private void genCheckCast() { | 538 private void genCheckCast() { |
539 int cpi = stream().readCPI(); | 539 int cpi = stream().readCPI(); |
540 RiType type = constantPool().lookupType(cpi, CHECKCAST); | 540 RiType type = constantPool().lookupType(cpi, CHECKCAST); |
541 boolean isInitialized = type.isResolved(); | 541 boolean isInitialized = type.isResolved(); |
542 Value typeInstruction = genTypeOrDeopt(RiType.Representation.ObjectHub, type, isInitialized, cpi, frameState.create(bci())); | 542 Value typeInstruction = genTypeOrDeopt(RiType.Representation.ObjectHub, type, isInitialized, cpi, frameState.create(bci())); |
543 CheckCast c = new CheckCast(type, typeInstruction, frameState.apop(), graph); | 543 Instruction result; |
544 frameState.apush(append(c)); | 544 Value object = frameState.apop(); |
545 if (typeInstruction != null) { | |
546 result = new CheckCast(type, typeInstruction, object, graph); | |
547 } else { | |
548 result = Constant.forObject(null, graph); | |
549 } | |
550 frameState.apush(append(result)); | |
545 } | 551 } |
546 | 552 |
547 private void genInstanceOf() { | 553 private void genInstanceOf() { |
548 int cpi = stream().readCPI(); | 554 int cpi = stream().readCPI(); |
549 RiType type = constantPool().lookupType(cpi, INSTANCEOF); | 555 RiType type = constantPool().lookupType(cpi, INSTANCEOF); |
550 boolean isInitialized = type.isResolved(); | 556 boolean isInitialized = type.isResolved(); |
551 //System.out.println("instanceof : type.isResolved() = " + type.isResolved() + "; type.isInitialized() = " + type.isInitialized()); | 557 //System.out.println("instanceof : type.isResolved() = " + type.isResolved() + "; type.isInitialized() = " + type.isInitialized()); |
552 Value typeInstruction = genTypeOrDeopt(RiType.Representation.ObjectHub, type, isInitialized, cpi, frameState.create(bci())); | 558 Value typeInstruction = genTypeOrDeopt(RiType.Representation.ObjectHub, type, isInitialized, cpi, frameState.create(bci())); |
553 InstanceOf i = new InstanceOf(type, typeInstruction, frameState.apop(), graph); | 559 Instruction result; |
554 frameState.ipush(append(i)); | 560 Value object = frameState.apop(); |
561 if (typeInstruction != null) { | |
562 result = new InstanceOf(type, typeInstruction, object, graph); | |
563 } else { | |
564 result = Constant.forInt(0, graph); | |
565 } | |
566 frameState.ipush(append(result)); | |
555 } | 567 } |
556 | 568 |
557 void genNewInstance(int cpi) { | 569 void genNewInstance(int cpi) { |
558 RiType type = constantPool().lookupType(cpi, NEW); | 570 RiType type = constantPool().lookupType(cpi, NEW); |
559 FrameState stateBefore = null; | 571 FrameState stateBefore = null; |
603 // Must copy the state here, because the field holder must still be on the stack. | 615 // Must copy the state here, because the field holder must still be on the stack. |
604 FrameState stateBefore = null; | 616 FrameState stateBefore = null; |
605 if (!field.isResolved()) { | 617 if (!field.isResolved()) { |
606 stateBefore = frameState.create(bci()); | 618 stateBefore = frameState.create(bci()); |
607 } | 619 } |
608 LoadField load = new LoadField(frameState.apop(), field, graph); | 620 LoadField load = new LoadField(frameState.apop(), field, stateBefore, graph); |
609 appendOptimizedLoadField(field.kind(), load); | 621 appendOptimizedLoadField(field.kind(), load); |
610 load.setStateBefore(stateBefore); | |
611 } | 622 } |
612 | 623 |
613 private void genPutField(int cpi, RiField field) { | 624 private void genPutField(int cpi, RiField field) { |
614 // Must copy the state here, because the field holder must still be on the stack. | 625 // Must copy the state here, because the field holder must still be on the stack. |
615 FrameState stateBefore = null; | 626 FrameState stateBefore = null; |
632 } | 643 } |
633 if (constantValue != null) { | 644 if (constantValue != null) { |
634 frameState.push(constantValue.kind.stackKind(), appendConstant(constantValue)); | 645 frameState.push(constantValue.kind.stackKind(), appendConstant(constantValue)); |
635 } else { | 646 } else { |
636 Value container = genTypeOrDeopt(RiType.Representation.StaticFields, holder, isInitialized, cpi, stateBefore); | 647 Value container = genTypeOrDeopt(RiType.Representation.StaticFields, holder, isInitialized, cpi, stateBefore); |
637 LoadField load = new LoadField(container, field, graph); | 648 if (container == null) { |
649 container = Constant.forObject(null, graph); | |
650 } | |
651 LoadField load = new LoadField(container, field, stateBefore, graph); | |
638 appendOptimizedLoadField(field.kind(), load); | 652 appendOptimizedLoadField(field.kind(), load); |
639 load.setStateBefore(stateBefore); | |
640 } | 653 } |
641 } | 654 } |
642 | 655 |
643 private void genPutStatic(int cpi, RiField field) { | 656 private void genPutStatic(int cpi, RiField field) { |
644 RiType holder = field.holder(); | 657 RiType holder = field.holder(); |
645 FrameState stateBefore = frameState.create(bci()); | 658 FrameState stateBefore = frameState.create(bci()); |
646 Value container = genTypeOrDeopt(RiType.Representation.StaticFields, holder, field.isResolved(), cpi, stateBefore); | 659 Value container = genTypeOrDeopt(RiType.Representation.StaticFields, holder, field.isResolved(), cpi, stateBefore); |
647 Value value = frameState.pop(field.kind().stackKind()); | 660 Value value = frameState.pop(field.kind().stackKind()); |
648 StoreField store = new StoreField(container, field, value, graph); | 661 if (container != null) { |
649 appendOptimizedStoreField(store); | 662 StoreField store = new StoreField(container, field, value, graph); |
650 if (!field.isResolved()) { | 663 appendOptimizedStoreField(store); |
651 store.setStateBefore(stateBefore); | 664 if (!field.isResolved()) { |
665 store.setStateBefore(stateBefore); | |
666 } | |
652 } | 667 } |
653 } | 668 } |
654 | 669 |
655 private Value genTypeOrDeopt(RiType.Representation representation, RiType holder, boolean initialized, int cpi, FrameState stateBefore) { | 670 private Value genTypeOrDeopt(RiType.Representation representation, RiType holder, boolean initialized, int cpi, FrameState stateBefore) { |
656 Value holderInstr; | |
657 if (initialized) { | 671 if (initialized) { |
658 holderInstr = appendConstant(holder.getEncoding(representation)); | 672 return appendConstant(holder.getEncoding(representation)); |
659 } else { | 673 } else { |
660 append(new Deoptimize(graph, stateBefore)); | 674 append(new Deoptimize(graph, stateBefore)); |
661 holderInstr = append(Constant.forObject(null, graph)); | 675 return null; |
662 } | 676 } |
663 return holderInstr; | |
664 } | 677 } |
665 | 678 |
666 private void appendOptimizedStoreField(StoreField store) { | 679 private void appendOptimizedStoreField(StoreField store) { |
667 append(store); | 680 append(store); |
668 } | 681 } |