src/share/vm/opto/doCall.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File 8034812 Sdiff src/share/vm/opto

src/share/vm/opto/doCall.cpp

Print this page




 579     if (Bytecodes::has_optional_appendix(iter().cur_bc_raw()) || is_signature_polymorphic) {
 580       // Be careful here with return types.
 581       if (ctype != rtype) {
 582         BasicType rt = rtype->basic_type();
 583         BasicType ct = ctype->basic_type();
 584         if (ct == T_VOID) {
 585           // It's OK for a method  to return a value that is discarded.
 586           // The discarding does not require any special action from the caller.
 587           // The Java code knows this, at VerifyType.isNullConversion.
 588           pop_node(rt);  // whatever it was, pop it
 589         } else if (rt == T_INT || is_subword_type(rt)) {
 590           // Nothing.  These cases are handled in lambda form bytecode.
 591           assert(ct == T_INT || is_subword_type(ct), err_msg_res("must match: rt=%s, ct=%s", type2name(rt), type2name(ct)));
 592         } else if (rt == T_OBJECT || rt == T_ARRAY) {
 593           assert(ct == T_OBJECT || ct == T_ARRAY, err_msg_res("rt=%s, ct=%s", type2name(rt), type2name(ct)));
 594           if (ctype->is_loaded()) {
 595             const TypeOopPtr* arg_type = TypeOopPtr::make_from_klass(rtype->as_klass());
 596             const Type*       sig_type = TypeOopPtr::make_from_klass(ctype->as_klass());
 597             if (arg_type != NULL && !arg_type->higher_equal(sig_type)) {
 598               Node* retnode = pop();
 599               Node* cast_obj = _gvn.transform(new (C) CheckCastPPNode(control(), retnode, sig_type));
 600               push(cast_obj);
 601             }
 602           }
 603         } else {
 604           assert(rt == ct, err_msg_res("unexpected mismatch: rt=%s, ct=%s", type2name(rt), type2name(ct)));
 605           // push a zero; it's better than getting an oop/int mismatch
 606           pop_node(rt);
 607           Node* retnode = zerocon(ct);
 608           push_node(ct, retnode);
 609         }
 610         // Now that the value is well-behaved, continue with the call-site type.
 611         rtype = ctype;
 612       }
 613     } else {
 614       // Symbolic resolution enforces the types to be the same.
 615       // NOTE: We must relax the assert for unloaded types because two
 616       // different ciType instances of the same unloaded class type
 617       // can appear to be "loaded" by different loaders (depending on
 618       // the accessing class).
 619       assert(!rtype->is_loaded() || !ctype->is_loaded() || rtype == ctype,


 672     if (!h_klass->is_loaded()) {
 673       if (saw_unloaded->contains(h_bci)) {
 674         /* We've already seen an unloaded exception with h_bci,
 675            so don't duplicate. Duplication will cause the CatchNode to be
 676            unnecessarily large. See 4713716. */
 677         continue;
 678       } else {
 679         saw_unloaded->append(h_bci);
 680       }
 681     }
 682     const Type*         h_extype = TypeOopPtr::make_from_klass(h_klass);
 683     // (We use make_from_klass because it respects UseUniqueSubclasses.)
 684     h_extype = h_extype->join(TypeInstPtr::NOTNULL);
 685     assert(!h_extype->empty(), "sanity");
 686     // Note:  It's OK if the BCIs repeat themselves.
 687     bcis->append(h_bci);
 688     extypes->append(h_extype);
 689   }
 690 
 691   int len = bcis->length();
 692   CatchNode *cn = new (C) CatchNode(control(), i_o, len+1);
 693   Node *catch_ = _gvn.transform(cn);
 694 
 695   // now branch with the exception state to each of the (potential)
 696   // handlers
 697   for(int i=0; i < len; i++) {
 698     // Setup JVM state to enter the handler.
 699     PreserveJVMState pjvms(this);
 700     // Locals are just copied from before the call.
 701     // Get control from the CatchNode.
 702     int handler_bci = bcis->at(i);
 703     Node* ctrl = _gvn.transform( new (C) CatchProjNode(catch_, i+1,handler_bci));
 704     // This handler cannot happen?
 705     if (ctrl == top())  continue;
 706     set_control(ctrl);
 707 
 708     // Create exception oop
 709     const TypeInstPtr* extype = extypes->at(i)->is_instptr();
 710     Node *ex_oop = _gvn.transform(new (C) CreateExNode(extypes->at(i), ctrl, i_o));
 711 
 712     // Handle unloaded exception classes.
 713     if (saw_unloaded->contains(handler_bci)) {
 714       // An unloaded exception type is coming here.  Do an uncommon trap.
 715 #ifndef PRODUCT
 716       // We do not expect the same handler bci to take both cold unloaded
 717       // and hot loaded exceptions.  But, watch for it.
 718       if ((Verbose || WizardMode) && extype->is_loaded()) {
 719         tty->print("Warning: Handler @%d takes mixed loaded/unloaded exceptions in ", bci());
 720         method()->print_name(); tty->cr();
 721       } else if (PrintOpto && (Verbose || WizardMode)) {
 722         tty->print("Bailing out on unloaded exception type ");
 723         extype->klass()->print_name();
 724         tty->print(" at bci:%d in ", bci());
 725         method()->print_name(); tty->cr();
 726       }
 727 #endif
 728       // Emit an uncommon trap instead of processing the block.
 729       set_bci(handler_bci);
 730       push_ex_oop(ex_oop);
 731       uncommon_trap(Deoptimization::Reason_unloaded,
 732                     Deoptimization::Action_reinterpret,
 733                     extype->klass(), "!loaded exception");
 734       set_bci(iter().cur_bci()); // put it back
 735       continue;
 736     }
 737 
 738     // go to the exception handler
 739     if (handler_bci < 0) {     // merge with corresponding rethrow node
 740       throw_to_exit(make_exception_state(ex_oop));
 741     } else {                      // Else jump to corresponding handle
 742       push_ex_oop(ex_oop);        // Clear stack and push just the oop.
 743       merge_exception(handler_bci);
 744     }
 745   }
 746 
 747   // The first CatchProj is for the normal return.
 748   // (Note:  If this is a call to rethrow_Java, this node goes dead.)
 749   set_control(_gvn.transform( new (C) CatchProjNode(catch_, CatchProjNode::fall_through_index, CatchProjNode::no_handler_bci)));
 750 }
 751 
 752 
 753 //----------------------------catch_inline_exceptions--------------------------
 754 // Handle all exceptions thrown by an inlined method or individual bytecode.
 755 // Common case 1: we have no handler, so all exceptions merge right into
 756 // the rethrow case.
 757 // Case 2: we have some handlers, with loaded exception klasses that have
 758 // no subklasses.  We do a Deutsch-Shiffman style type-check on the incoming
 759 // exception oop and branch to the handler directly.
 760 // Case 3: We have some handlers with subklasses or are not loaded at
 761 // compile-time.  We have to call the runtime to resolve the exception.
 762 // So we insert a RethrowCall and all the logic that goes with it.
 763 void Parse::catch_inline_exceptions(SafePointNode* ex_map) {
 764   // Caller is responsible for saving away the map for normal control flow!
 765   assert(stopped(), "call set_map(NULL) first");
 766   assert(method()->has_exception_handlers(), "don't come here w/o work to do");
 767 
 768   Node* ex_node = saved_ex_oop(ex_map);
 769   if (ex_node == top()) {


 780                                     ex_type->klass()->as_instance_klass(),
 781                                     ex_type->klass_is_exact());
 782 
 783   // Start executing from the given throw state.  (Keep its stack, for now.)
 784   // Get the exception oop as known at compile time.
 785   ex_node = use_exception_state(ex_map);
 786 
 787   // Get the exception oop klass from its header
 788   Node* ex_klass_node = NULL;
 789   if (has_ex_handler() && !ex_type->klass_is_exact()) {
 790     Node* p = basic_plus_adr( ex_node, ex_node, oopDesc::klass_offset_in_bytes());
 791     ex_klass_node = _gvn.transform( LoadKlassNode::make(_gvn, immutable_memory(), p, TypeInstPtr::KLASS, TypeKlassPtr::OBJECT) );
 792 
 793     // Compute the exception klass a little more cleverly.
 794     // Obvious solution is to simple do a LoadKlass from the 'ex_node'.
 795     // However, if the ex_node is a PhiNode, I'm going to do a LoadKlass for
 796     // each arm of the Phi.  If I know something clever about the exceptions
 797     // I'm loading the class from, I can replace the LoadKlass with the
 798     // klass constant for the exception oop.
 799     if( ex_node->is_Phi() ) {
 800       ex_klass_node = new (C) PhiNode( ex_node->in(0), TypeKlassPtr::OBJECT );
 801       for( uint i = 1; i < ex_node->req(); i++ ) {
 802         Node* p = basic_plus_adr( ex_node->in(i), ex_node->in(i), oopDesc::klass_offset_in_bytes() );
 803         Node* k = _gvn.transform( LoadKlassNode::make(_gvn, immutable_memory(), p, TypeInstPtr::KLASS, TypeKlassPtr::OBJECT) );
 804         ex_klass_node->init_req( i, k );
 805       }
 806       _gvn.set_type(ex_klass_node, TypeKlassPtr::OBJECT);
 807 
 808     }
 809   }
 810 
 811   // Scan the exception table for applicable handlers.
 812   // If none, we can call rethrow() and be done!
 813   // If precise (loaded with no subklasses), insert a D.S. style
 814   // pointer compare to the correct handler and loop back.
 815   // If imprecise, switch to the Rethrow VM-call style handling.
 816 
 817   int remaining = handlers.count_remaining();
 818 
 819   // iterate through all entries sequentially
 820   for (;!handlers.is_done(); handlers.next()) {


 846     // Get the handler's klass
 847     ciInstanceKlass* klass = handler->catch_klass();
 848 
 849     if (!klass->is_loaded()) {  // klass is not loaded?
 850       // fall through into catch_call_exceptions which will emit a
 851       // handler with an uncommon trap.
 852       break;
 853     }
 854 
 855     if (klass->is_interface())  // should not happen, but...
 856       break;                    // bail out
 857 
 858     // Check the type of the exception against the catch type
 859     const TypeKlassPtr *tk = TypeKlassPtr::make(klass);
 860     Node* con = _gvn.makecon(tk);
 861     Node* not_subtype_ctrl = gen_subtype_check(ex_klass_node, con);
 862     if (!stopped()) {
 863       PreserveJVMState pjvms(this);
 864       const TypeInstPtr* tinst = TypeOopPtr::make_from_klass_unique(klass)->cast_to_ptr_type(TypePtr::NotNull)->is_instptr();
 865       assert(klass->has_subklass() || tinst->klass_is_exact(), "lost exactness");
 866       Node* ex_oop = _gvn.transform(new (C) CheckCastPPNode(control(), ex_node, tinst));
 867       push_ex_oop(ex_oop);      // Push exception oop for handler
 868 #ifndef PRODUCT
 869       if (PrintOpto && WizardMode) {
 870         tty->print("  Catching inline exception bci:%d -> handler_bci:%d -- ", bci(), handler_bci);
 871         klass->print_name();
 872         tty->cr();
 873       }
 874 #endif
 875       merge_exception(handler_bci);
 876     }
 877     set_control(not_subtype_ctrl);
 878 
 879     // Come here if exception does not match handler.
 880     // Carry on with more handler checks.
 881     --remaining;
 882   }
 883 
 884   assert(!stopped(), "you should return if you finish the chain");
 885 
 886   // Oops, need to call into the VM to resolve the klasses at runtime.




 579     if (Bytecodes::has_optional_appendix(iter().cur_bc_raw()) || is_signature_polymorphic) {
 580       // Be careful here with return types.
 581       if (ctype != rtype) {
 582         BasicType rt = rtype->basic_type();
 583         BasicType ct = ctype->basic_type();
 584         if (ct == T_VOID) {
 585           // It's OK for a method  to return a value that is discarded.
 586           // The discarding does not require any special action from the caller.
 587           // The Java code knows this, at VerifyType.isNullConversion.
 588           pop_node(rt);  // whatever it was, pop it
 589         } else if (rt == T_INT || is_subword_type(rt)) {
 590           // Nothing.  These cases are handled in lambda form bytecode.
 591           assert(ct == T_INT || is_subword_type(ct), err_msg_res("must match: rt=%s, ct=%s", type2name(rt), type2name(ct)));
 592         } else if (rt == T_OBJECT || rt == T_ARRAY) {
 593           assert(ct == T_OBJECT || ct == T_ARRAY, err_msg_res("rt=%s, ct=%s", type2name(rt), type2name(ct)));
 594           if (ctype->is_loaded()) {
 595             const TypeOopPtr* arg_type = TypeOopPtr::make_from_klass(rtype->as_klass());
 596             const Type*       sig_type = TypeOopPtr::make_from_klass(ctype->as_klass());
 597             if (arg_type != NULL && !arg_type->higher_equal(sig_type)) {
 598               Node* retnode = pop();
 599               Node* cast_obj = _gvn.transform(new CheckCastPPNode(control(), retnode, sig_type));
 600               push(cast_obj);
 601             }
 602           }
 603         } else {
 604           assert(rt == ct, err_msg_res("unexpected mismatch: rt=%s, ct=%s", type2name(rt), type2name(ct)));
 605           // push a zero; it's better than getting an oop/int mismatch
 606           pop_node(rt);
 607           Node* retnode = zerocon(ct);
 608           push_node(ct, retnode);
 609         }
 610         // Now that the value is well-behaved, continue with the call-site type.
 611         rtype = ctype;
 612       }
 613     } else {
 614       // Symbolic resolution enforces the types to be the same.
 615       // NOTE: We must relax the assert for unloaded types because two
 616       // different ciType instances of the same unloaded class type
 617       // can appear to be "loaded" by different loaders (depending on
 618       // the accessing class).
 619       assert(!rtype->is_loaded() || !ctype->is_loaded() || rtype == ctype,


 672     if (!h_klass->is_loaded()) {
 673       if (saw_unloaded->contains(h_bci)) {
 674         /* We've already seen an unloaded exception with h_bci,
 675            so don't duplicate. Duplication will cause the CatchNode to be
 676            unnecessarily large. See 4713716. */
 677         continue;
 678       } else {
 679         saw_unloaded->append(h_bci);
 680       }
 681     }
 682     const Type*         h_extype = TypeOopPtr::make_from_klass(h_klass);
 683     // (We use make_from_klass because it respects UseUniqueSubclasses.)
 684     h_extype = h_extype->join(TypeInstPtr::NOTNULL);
 685     assert(!h_extype->empty(), "sanity");
 686     // Note:  It's OK if the BCIs repeat themselves.
 687     bcis->append(h_bci);
 688     extypes->append(h_extype);
 689   }
 690 
 691   int len = bcis->length();
 692   CatchNode *cn = new CatchNode(control(), i_o, len+1);
 693   Node *catch_ = _gvn.transform(cn);
 694 
 695   // now branch with the exception state to each of the (potential)
 696   // handlers
 697   for(int i=0; i < len; i++) {
 698     // Setup JVM state to enter the handler.
 699     PreserveJVMState pjvms(this);
 700     // Locals are just copied from before the call.
 701     // Get control from the CatchNode.
 702     int handler_bci = bcis->at(i);
 703     Node* ctrl = _gvn.transform( new CatchProjNode(catch_, i+1,handler_bci));
 704     // This handler cannot happen?
 705     if (ctrl == top())  continue;
 706     set_control(ctrl);
 707 
 708     // Create exception oop
 709     const TypeInstPtr* extype = extypes->at(i)->is_instptr();
 710     Node *ex_oop = _gvn.transform(new CreateExNode(extypes->at(i), ctrl, i_o));
 711 
 712     // Handle unloaded exception classes.
 713     if (saw_unloaded->contains(handler_bci)) {
 714       // An unloaded exception type is coming here.  Do an uncommon trap.
 715 #ifndef PRODUCT
 716       // We do not expect the same handler bci to take both cold unloaded
 717       // and hot loaded exceptions.  But, watch for it.
 718       if ((Verbose || WizardMode) && extype->is_loaded()) {
 719         tty->print("Warning: Handler @%d takes mixed loaded/unloaded exceptions in ", bci());
 720         method()->print_name(); tty->cr();
 721       } else if (PrintOpto && (Verbose || WizardMode)) {
 722         tty->print("Bailing out on unloaded exception type ");
 723         extype->klass()->print_name();
 724         tty->print(" at bci:%d in ", bci());
 725         method()->print_name(); tty->cr();
 726       }
 727 #endif
 728       // Emit an uncommon trap instead of processing the block.
 729       set_bci(handler_bci);
 730       push_ex_oop(ex_oop);
 731       uncommon_trap(Deoptimization::Reason_unloaded,
 732                     Deoptimization::Action_reinterpret,
 733                     extype->klass(), "!loaded exception");
 734       set_bci(iter().cur_bci()); // put it back
 735       continue;
 736     }
 737 
 738     // go to the exception handler
 739     if (handler_bci < 0) {     // merge with corresponding rethrow node
 740       throw_to_exit(make_exception_state(ex_oop));
 741     } else {                      // Else jump to corresponding handle
 742       push_ex_oop(ex_oop);        // Clear stack and push just the oop.
 743       merge_exception(handler_bci);
 744     }
 745   }
 746 
 747   // The first CatchProj is for the normal return.
 748   // (Note:  If this is a call to rethrow_Java, this node goes dead.)
 749   set_control(_gvn.transform( new CatchProjNode(catch_, CatchProjNode::fall_through_index, CatchProjNode::no_handler_bci)));
 750 }
 751 
 752 
 753 //----------------------------catch_inline_exceptions--------------------------
 754 // Handle all exceptions thrown by an inlined method or individual bytecode.
 755 // Common case 1: we have no handler, so all exceptions merge right into
 756 // the rethrow case.
 757 // Case 2: we have some handlers, with loaded exception klasses that have
 758 // no subklasses.  We do a Deutsch-Shiffman style type-check on the incoming
 759 // exception oop and branch to the handler directly.
 760 // Case 3: We have some handlers with subklasses or are not loaded at
 761 // compile-time.  We have to call the runtime to resolve the exception.
 762 // So we insert a RethrowCall and all the logic that goes with it.
 763 void Parse::catch_inline_exceptions(SafePointNode* ex_map) {
 764   // Caller is responsible for saving away the map for normal control flow!
 765   assert(stopped(), "call set_map(NULL) first");
 766   assert(method()->has_exception_handlers(), "don't come here w/o work to do");
 767 
 768   Node* ex_node = saved_ex_oop(ex_map);
 769   if (ex_node == top()) {


 780                                     ex_type->klass()->as_instance_klass(),
 781                                     ex_type->klass_is_exact());
 782 
 783   // Start executing from the given throw state.  (Keep its stack, for now.)
 784   // Get the exception oop as known at compile time.
 785   ex_node = use_exception_state(ex_map);
 786 
 787   // Get the exception oop klass from its header
 788   Node* ex_klass_node = NULL;
 789   if (has_ex_handler() && !ex_type->klass_is_exact()) {
 790     Node* p = basic_plus_adr( ex_node, ex_node, oopDesc::klass_offset_in_bytes());
 791     ex_klass_node = _gvn.transform( LoadKlassNode::make(_gvn, immutable_memory(), p, TypeInstPtr::KLASS, TypeKlassPtr::OBJECT) );
 792 
 793     // Compute the exception klass a little more cleverly.
 794     // Obvious solution is to simple do a LoadKlass from the 'ex_node'.
 795     // However, if the ex_node is a PhiNode, I'm going to do a LoadKlass for
 796     // each arm of the Phi.  If I know something clever about the exceptions
 797     // I'm loading the class from, I can replace the LoadKlass with the
 798     // klass constant for the exception oop.
 799     if( ex_node->is_Phi() ) {
 800       ex_klass_node = new PhiNode( ex_node->in(0), TypeKlassPtr::OBJECT );
 801       for( uint i = 1; i < ex_node->req(); i++ ) {
 802         Node* p = basic_plus_adr( ex_node->in(i), ex_node->in(i), oopDesc::klass_offset_in_bytes() );
 803         Node* k = _gvn.transform( LoadKlassNode::make(_gvn, immutable_memory(), p, TypeInstPtr::KLASS, TypeKlassPtr::OBJECT) );
 804         ex_klass_node->init_req( i, k );
 805       }
 806       _gvn.set_type(ex_klass_node, TypeKlassPtr::OBJECT);
 807 
 808     }
 809   }
 810 
 811   // Scan the exception table for applicable handlers.
 812   // If none, we can call rethrow() and be done!
 813   // If precise (loaded with no subklasses), insert a D.S. style
 814   // pointer compare to the correct handler and loop back.
 815   // If imprecise, switch to the Rethrow VM-call style handling.
 816 
 817   int remaining = handlers.count_remaining();
 818 
 819   // iterate through all entries sequentially
 820   for (;!handlers.is_done(); handlers.next()) {


 846     // Get the handler's klass
 847     ciInstanceKlass* klass = handler->catch_klass();
 848 
 849     if (!klass->is_loaded()) {  // klass is not loaded?
 850       // fall through into catch_call_exceptions which will emit a
 851       // handler with an uncommon trap.
 852       break;
 853     }
 854 
 855     if (klass->is_interface())  // should not happen, but...
 856       break;                    // bail out
 857 
 858     // Check the type of the exception against the catch type
 859     const TypeKlassPtr *tk = TypeKlassPtr::make(klass);
 860     Node* con = _gvn.makecon(tk);
 861     Node* not_subtype_ctrl = gen_subtype_check(ex_klass_node, con);
 862     if (!stopped()) {
 863       PreserveJVMState pjvms(this);
 864       const TypeInstPtr* tinst = TypeOopPtr::make_from_klass_unique(klass)->cast_to_ptr_type(TypePtr::NotNull)->is_instptr();
 865       assert(klass->has_subklass() || tinst->klass_is_exact(), "lost exactness");
 866       Node* ex_oop = _gvn.transform(new CheckCastPPNode(control(), ex_node, tinst));
 867       push_ex_oop(ex_oop);      // Push exception oop for handler
 868 #ifndef PRODUCT
 869       if (PrintOpto && WizardMode) {
 870         tty->print("  Catching inline exception bci:%d -> handler_bci:%d -- ", bci(), handler_bci);
 871         klass->print_name();
 872         tty->cr();
 873       }
 874 #endif
 875       merge_exception(handler_bci);
 876     }
 877     set_control(not_subtype_ctrl);
 878 
 879     // Come here if exception does not match handler.
 880     // Carry on with more handler checks.
 881     --remaining;
 882   }
 883 
 884   assert(!stopped(), "you should return if you finish the chain");
 885 
 886   // Oops, need to call into the VM to resolve the klasses at runtime.


src/share/vm/opto/doCall.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File