comparison graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java @ 2709:7b7dbe19fafb

Remove all unresolved cases from HotspotXirGenerator, use more explicit Deopt, Deopt to lastState instead of stateBefore
author Gilles Duboscq <gilles.duboscq@oracle.com>
date Thu, 19 May 2011 11:36:41 +0200
parents ed36daed4c43
children 0efd77a02ea9
comparison
equal deleted inserted replaced
2690:abb4cc15283d 2709:7b7dbe19fafb
346 346
347 if (con instanceof RiType) { 347 if (con instanceof RiType) {
348 // this is a load of class constant which might be unresolved 348 // this is a load of class constant which might be unresolved
349 RiType riType = (RiType) con; 349 RiType riType = (RiType) con;
350 if (!riType.isResolved()) { 350 if (!riType.isResolved()) {
351 append(new Deoptimize(graph, frameState.create(bci()))); 351 append(new Deoptimize(graph));
352 frameState.push(CiKind.Object, append(Constant.forObject(null, graph))); 352 frameState.push(CiKind.Object, append(Constant.forObject(null, graph)));
353 } else { 353 } else {
354 frameState.push(CiKind.Object, append(new Constant(riType.getEncoding(Representation.JavaClass), graph))); 354 frameState.push(CiKind.Object, append(new Constant(riType.getEncoding(Representation.JavaClass), graph)));
355 } 355 }
356 } else if (con instanceof CiConstant) { 356 } else if (con instanceof CiConstant) {
560 560
561 private void genCheckCast() { 561 private void genCheckCast() {
562 int cpi = stream().readCPI(); 562 int cpi = stream().readCPI();
563 RiType type = constantPool().lookupType(cpi, CHECKCAST); 563 RiType type = constantPool().lookupType(cpi, CHECKCAST);
564 boolean isInitialized = type.isResolved(); 564 boolean isInitialized = type.isResolved();
565 Value typeInstruction = genTypeOrDeopt(RiType.Representation.ObjectHub, type, isInitialized, cpi, frameState); 565 Value typeInstruction = genTypeOrDeopt(RiType.Representation.ObjectHub, type, isInitialized, cpi);
566 CheckCast c = new CheckCast(type, typeInstruction, frameState.apop(), graph); 566 Value object = frameState.apop();
567 frameState.apush(append(c)); 567 if (typeInstruction != null) {
568 frameState.apush(append(new CheckCast(type, typeInstruction, object, graph)));
569 } else {
570 frameState.apush(appendConstant(CiConstant.NULL_OBJECT));
571 }
568 } 572 }
569 573
570 private void genInstanceOf() { 574 private void genInstanceOf() {
571 int cpi = stream().readCPI(); 575 int cpi = stream().readCPI();
572 RiType type = constantPool().lookupType(cpi, INSTANCEOF); 576 RiType type = constantPool().lookupType(cpi, INSTANCEOF);
573 boolean isInitialized = type.isResolved(); 577 boolean isInitialized = type.isResolved();
574 //System.out.println("instanceof : type.isResolved() = " + type.isResolved() + "; type.isInitialized() = " + type.isInitialized()); 578 Value typeInstruction = genTypeOrDeopt(RiType.Representation.ObjectHub, type, isInitialized, cpi);
575 Value typeInstruction = genTypeOrDeopt(RiType.Representation.ObjectHub, type, isInitialized, cpi, frameState);
576 Instruction result;
577 Value object = frameState.apop(); 579 Value object = frameState.apop();
578 if (typeInstruction != null) { 580 if (typeInstruction != null) {
579 result = new InstanceOf(type, typeInstruction, object, graph); 581 frameState.ipush(append(new InstanceOf(type, typeInstruction, object, graph)));
580 } else { 582 } else {
581 result = Constant.forInt(0, graph); 583 frameState.ipush(appendConstant(CiConstant.INT_0));
582 } 584 }
583 frameState.ipush(append(result));
584 } 585 }
585 586
586 void genNewInstance(int cpi) { 587 void genNewInstance(int cpi) {
587 RiType type = constantPool().lookupType(cpi, NEW); 588 RiType type = constantPool().lookupType(cpi, NEW);
588 FrameState stateBefore = null; 589 if (type.isResolved()) {
589 if (!type.isResolved()) { 590 NewInstance n = new NewInstance(type, cpi, constantPool(), graph);
590 stateBefore = frameState.create(bci()); 591 frameState.apush(append(n));
591 } 592 } else {
592 NewInstance n = new NewInstance(type, cpi, constantPool(), graph); 593 append(new Deoptimize(graph));
593 n.setStateBefore(stateBefore); 594 frameState.apush(appendConstant(CiConstant.NULL_OBJECT));
594 frameState.apush(append(n)); 595 }
595 } 596 }
596 597
597 private void genNewTypeArray(int typeCode) { 598 private void genNewTypeArray(int typeCode) {
598 CiKind kind = CiKind.fromArrayTypeCode(typeCode); 599 CiKind kind = CiKind.fromArrayTypeCode(typeCode);
599 RiType elementType = compilation.runtime.asRiType(kind); 600 RiType elementType = compilation.runtime.asRiType(kind);
601 frameState.apush(append(nta)); 602 frameState.apush(append(nta));
602 } 603 }
603 604
604 private void genNewObjectArray(int cpi) { 605 private void genNewObjectArray(int cpi) {
605 RiType type = constantPool().lookupType(cpi, ANEWARRAY); 606 RiType type = constantPool().lookupType(cpi, ANEWARRAY);
606 FrameState stateBefore = null; 607 Value length = frameState.ipop();
607 if (!type.isResolved()) { 608 if (type.isResolved()) {
608 stateBefore = frameState.create(bci()); 609 NewArray n = new NewObjectArray(type, length, graph);
609 } 610 frameState.apush(append(n));
610 NewArray n = new NewObjectArray(type, frameState.ipop(), graph); 611 } else {
611 frameState.apush(append(n)); 612 append(new Deoptimize(graph));
612 n.setStateBefore(stateBefore); 613 frameState.apush(appendConstant(CiConstant.NULL_OBJECT));
614 }
615
613 } 616 }
614 617
615 private void genNewMultiArray(int cpi) { 618 private void genNewMultiArray(int cpi) {
616 RiType type = constantPool().lookupType(cpi, MULTIANEWARRAY); 619 RiType type = constantPool().lookupType(cpi, MULTIANEWARRAY);
617 FrameState stateBefore = null;
618 if (!type.isResolved()) {
619 stateBefore = frameState.create(bci());
620 }
621 int rank = stream().readUByte(bci() + 3); 620 int rank = stream().readUByte(bci() + 3);
622 Value[] dims = new Value[rank]; 621 Value[] dims = new Value[rank];
623 for (int i = rank - 1; i >= 0; i--) { 622 for (int i = rank - 1; i >= 0; i--) {
624 dims[i] = frameState.ipop(); 623 dims[i] = frameState.ipop();
625 } 624 }
626 NewArray n = new NewMultiArray(type, dims, cpi, constantPool(), graph); 625 if (type.isResolved()) {
627 frameState.apush(append(n)); 626 NewArray n = new NewMultiArray(type, dims, cpi, constantPool(), graph);
628 n.setStateBefore(stateBefore); 627 frameState.apush(append(n));
628 } else {
629 append(new Deoptimize(graph));
630 frameState.apush(appendConstant(CiConstant.NULL_OBJECT));
631 }
629 } 632 }
630 633
631 private void genGetField(int cpi, RiField field) { 634 private void genGetField(int cpi, RiField field) {
632 // Must copy the state here, because the field holder must still be on the stack. 635 CiKind kind = field.kind();
633 FrameState stateBefore = null; 636 Value receiver = frameState.apop();
634 if (!field.isResolved()) { 637 if (field.isResolved()) {
635 stateBefore = frameState.create(bci()); 638 LoadField load = new LoadField(receiver, field, graph);
636 } 639 appendOptimizedLoadField(kind, load);
637 LoadField load = new LoadField(frameState.apop(), field, stateBefore, graph); 640 } else {
638 appendOptimizedLoadField(field.kind(), load); 641 append(new Deoptimize(graph));
642 frameState.push(kind.stackKind(), append(Constant.defaultForKind(kind, graph)));
643 }
639 } 644 }
640 645
641 private void genPutField(int cpi, RiField field) { 646 private void genPutField(int cpi, RiField field) {
642 // Must copy the state here, because the field holder must still be on the stack.
643 FrameState stateBefore = null;
644 if (!field.isResolved()) {
645 stateBefore = frameState.create(bci());
646 }
647 Value value = frameState.pop(field.kind().stackKind()); 647 Value value = frameState.pop(field.kind().stackKind());
648 StoreField store = new StoreField(frameState.apop(), field, value, graph); 648 Value receiver = frameState.apop();
649 appendOptimizedStoreField(store); 649 if (field.isResolved()) {
650 store.setStateBefore(stateBefore); 650 StoreField store = new StoreField(receiver, field, value, graph);
651 appendOptimizedStoreField(store);
652 } else {
653 append(new Deoptimize(graph));
654 }
651 } 655 }
652 656
653 private void genGetStatic(int cpi, RiField field) { 657 private void genGetStatic(int cpi, RiField field) {
654 RiType holder = field.holder(); 658 RiType holder = field.holder();
655 boolean isInitialized = field.isResolved(); 659 boolean isInitialized = field.isResolved();
658 constantValue = field.constantValue(null); 662 constantValue = field.constantValue(null);
659 } 663 }
660 if (constantValue != null) { 664 if (constantValue != null) {
661 frameState.push(constantValue.kind.stackKind(), appendConstant(constantValue)); 665 frameState.push(constantValue.kind.stackKind(), appendConstant(constantValue));
662 } else { 666 } else {
663 FrameState stateBefore = frameState.create(bci()); 667 Value container = genTypeOrDeopt(RiType.Representation.StaticFields, holder, isInitialized, cpi);
664 Value container = genTypeOrDeopt(RiType.Representation.StaticFields, holder, isInitialized, cpi, frameState); 668 CiKind kind = field.kind();
665 if (container == null) { 669 if (container != null) {
666 container = Constant.forObject(null, graph); 670 LoadField load = new LoadField(container, field, graph);
667 } 671 appendOptimizedLoadField(kind, load);
668 LoadField load = new LoadField(container, field, stateBefore, graph); 672 } else {
669 appendOptimizedLoadField(field.kind(), load); 673 append(new Deoptimize(graph));
674 frameState.push(kind.stackKind(), append(Constant.defaultForKind(kind, graph)));
675 }
670 } 676 }
671 } 677 }
672 678
673 private void genPutStatic(int cpi, RiField field) { 679 private void genPutStatic(int cpi, RiField field) {
674 RiType holder = field.holder(); 680 RiType holder = field.holder();
675 FrameState stateBefore = frameState.create(bci()); 681 Value container = genTypeOrDeopt(RiType.Representation.StaticFields, holder, field.isResolved(), cpi);
676 Value container = genTypeOrDeopt(RiType.Representation.StaticFields, holder, field.isResolved(), cpi, frameState);
677 Value value = frameState.pop(field.kind().stackKind()); 682 Value value = frameState.pop(field.kind().stackKind());
678 if (container != null) { 683 if (container != null) {
679 StoreField store = new StoreField(container, field, value, graph); 684 StoreField store = new StoreField(container, field, value, graph);
680 appendOptimizedStoreField(store); 685 appendOptimizedStoreField(store);
681 if (!field.isResolved()) { 686 } else {
682 store.setStateBefore(stateBefore); 687 append(new Deoptimize(graph));
683 } 688 }
684 } 689 }
685 } 690
686 691 private Value genTypeOrDeopt(RiType.Representation representation, RiType holder, boolean initialized, int cpi) {
687 private Value genTypeOrDeopt(RiType.Representation representation, RiType holder, boolean initialized, int cpi, FrameStateAccess stateBefore) {
688 if (initialized) { 692 if (initialized) {
689 return appendConstant(holder.getEncoding(representation)); 693 return appendConstant(holder.getEncoding(representation));
690 } else { 694 } else {
691 append(new Deoptimize(graph, stateBefore.duplicate(bci()))); 695 append(new Deoptimize(graph));
692 return null; 696 return null;
693 } 697 }
694 } 698 }
695 699
696 private void appendOptimizedStoreField(StoreField store) { 700 private void appendOptimizedStoreField(StoreField store) {
708 boolean isInitialized = target.isResolved() && holder.isInitialized(); 712 boolean isInitialized = target.isResolved() && holder.isInitialized();
709 if (!isInitialized && C1XOptions.ResolveClassBeforeStaticInvoke) { 713 if (!isInitialized && C1XOptions.ResolveClassBeforeStaticInvoke) {
710 // Re-use the same resolution code as for accessing a static field. Even though 714 // Re-use the same resolution code as for accessing a static field. Even though
711 // the result of resolution is not used by the invocation (only the side effect 715 // the result of resolution is not used by the invocation (only the side effect
712 // of initialization is required), it can be commoned with static field accesses. 716 // of initialization is required), it can be commoned with static field accesses.
713 genTypeOrDeopt(RiType.Representation.StaticFields, holder, isInitialized, cpi, frameState); 717 genTypeOrDeopt(RiType.Representation.StaticFields, holder, isInitialized, cpi);
714 } 718 }
715 Value[] args = frameState.popArguments(target.signature().argumentSlots(false)); 719 Value[] args = frameState.popArguments(target.signature().argumentSlots(false));
716 appendInvoke(INVOKESTATIC, target, args, cpi, constantPool); 720 appendInvoke(INVOKESTATIC, target, args, cpi, constantPool);
717 } 721 }
718 722
942 boolean isSafepoint = isBackwards && !noSafepoints(); 946 boolean isSafepoint = isBackwards && !noSafepoints();
943 FrameState stateBefore = isSafepoint ? frameState.create(bci()) : null; 947 FrameState stateBefore = isSafepoint ? frameState.create(bci()) : null;
944 append(new LookupSwitch(frameState.ipop(), list, keys, stateBefore, isSafepoint, graph)); 948 append(new LookupSwitch(frameState.ipop(), list, keys, stateBefore, isSafepoint, graph));
945 } 949 }
946 950
947 private Value appendConstant(CiConstant type) { 951 private Value appendConstant(CiConstant constant) {
948 return appendWithBCI(new Constant(type, graph), bci()); 952 return appendWithBCI(new Constant(constant, graph), bci());
949 } 953 }
950 954
951 private Value append(Instruction x) { 955 private Value append(Instruction x) {
952 return appendWithBCI(x, bci()); 956 return appendWithBCI(x, bci());
953 } 957 }