hotspot/src/share/vm/opto/graphKit.cpp
changeset 14621 fd9265ab0f67
parent 13967 bf7c8dfb5121
child 14623 70c4c1be0a14
equal deleted inserted replaced
14620:45167d2bc15a 14621:fd9265ab0f67
    88 JVMState* GraphKit::sync_jvms() const {
    88 JVMState* GraphKit::sync_jvms() const {
    89   JVMState* jvms = this->jvms();
    89   JVMState* jvms = this->jvms();
    90   jvms->set_bci(bci());       // Record the new bci in the JVMState
    90   jvms->set_bci(bci());       // Record the new bci in the JVMState
    91   jvms->set_sp(sp());         // Record the new sp in the JVMState
    91   jvms->set_sp(sp());         // Record the new sp in the JVMState
    92   assert(jvms_in_sync(), "jvms is now in sync");
    92   assert(jvms_in_sync(), "jvms is now in sync");
       
    93   return jvms;
       
    94 }
       
    95 
       
    96 //--------------------------------sync_jvms_for_reexecute---------------------
       
    97 // Make sure our current jvms agrees with our parse state.  This version
       
    98 // uses the reexecute_sp for reexecuting bytecodes.
       
    99 JVMState* GraphKit::sync_jvms_for_reexecute() {
       
   100   JVMState* jvms = this->jvms();
       
   101   jvms->set_bci(bci());          // Record the new bci in the JVMState
       
   102   jvms->set_sp(reexecute_sp());  // Record the new sp in the JVMState
    93   return jvms;
   103   return jvms;
    94 }
   104 }
    95 
   105 
    96 #ifdef ASSERT
   106 #ifdef ASSERT
    97 bool GraphKit::jvms_in_sync() const {
   107 bool GraphKit::jvms_in_sync() const {
   824   assert(dead_locals_are_killed(), "garbage in debug info before safepoint");
   834   assert(dead_locals_are_killed(), "garbage in debug info before safepoint");
   825 
   835 
   826   // Walk the inline list to fill in the correct set of JVMState's
   836   // Walk the inline list to fill in the correct set of JVMState's
   827   // Also fill in the associated edges for each JVMState.
   837   // Also fill in the associated edges for each JVMState.
   828 
   838 
   829   JVMState* youngest_jvms = sync_jvms();
   839   // If the bytecode needs to be reexecuted we need to put
       
   840   // the arguments back on the stack.
       
   841   const bool should_reexecute = jvms()->should_reexecute();
       
   842   JVMState* youngest_jvms = should_reexecute ? sync_jvms_for_reexecute() : sync_jvms();
       
   843 
       
   844   // NOTE: set_bci (called from sync_jvms) might reset the reexecute bit to
       
   845   // undefined if the bci is different.  This is normal for Parse but it
       
   846   // should not happen for LibraryCallKit because only one bci is processed.
       
   847   assert(!is_LibraryCallKit() || (jvms()->should_reexecute() == should_reexecute),
       
   848          "in LibraryCallKit the reexecute bit should not change");
   830 
   849 
   831   // If we are guaranteed to throw, we can prune everything but the
   850   // If we are guaranteed to throw, we can prune everything but the
   832   // input to the current bytecode.
   851   // input to the current bytecode.
   833   bool can_prune_locals = false;
   852   bool can_prune_locals = false;
   834   uint stack_slots_not_pruned = 0;
   853   uint stack_slots_not_pruned = 0;
   858       should_reexecute_implied_by_bytecode(out_jvms, call->is_AllocateArray())) {
   877       should_reexecute_implied_by_bytecode(out_jvms, call->is_AllocateArray())) {
   859     out_jvms->set_should_reexecute(true); //NOTE: youngest_jvms not changed
   878     out_jvms->set_should_reexecute(true); //NOTE: youngest_jvms not changed
   860   }
   879   }
   861 
   880 
   862   // Presize the call:
   881   // Presize the call:
   863   debug_only(uint non_debug_edges = call->req());
   882   DEBUG_ONLY(uint non_debug_edges = call->req());
   864   call->add_req_batch(top(), youngest_jvms->debug_depth());
   883   call->add_req_batch(top(), youngest_jvms->debug_depth());
   865   assert(call->req() == non_debug_edges + youngest_jvms->debug_depth(), "");
   884   assert(call->req() == non_debug_edges + youngest_jvms->debug_depth(), "");
   866 
   885 
   867   // Set up edges so that the call looks like this:
   886   // Set up edges so that the call looks like this:
   868   //  Call [state:] ctl io mem fptr retadr
   887   //  Call [state:] ctl io mem fptr retadr
   963   assert(call->jvms()->debug_start() == non_debug_edges, "");
   982   assert(call->jvms()->debug_start() == non_debug_edges, "");
   964   assert(call->jvms()->debug_end()   == call->req(), "");
   983   assert(call->jvms()->debug_end()   == call->req(), "");
   965   assert(call->jvms()->debug_depth() == call->req() - non_debug_edges, "");
   984   assert(call->jvms()->debug_depth() == call->req() - non_debug_edges, "");
   966 }
   985 }
   967 
   986 
   968 bool GraphKit::compute_stack_effects(int& inputs, int& depth, bool for_parse) {
   987 bool GraphKit::compute_stack_effects(int& inputs, int& depth) {
   969   Bytecodes::Code code = java_bc();
   988   Bytecodes::Code code = java_bc();
   970   if (code == Bytecodes::_wide) {
   989   if (code == Bytecodes::_wide) {
   971     code = method()->java_code_at_bci(bci() + 1);
   990     code = method()->java_code_at_bci(bci() + 1);
   972   }
   991   }
   973 
   992 
  1003   case Bytecodes::_getstatic:
  1022   case Bytecodes::_getstatic:
  1004   case Bytecodes::_putstatic:
  1023   case Bytecodes::_putstatic:
  1005   case Bytecodes::_getfield:
  1024   case Bytecodes::_getfield:
  1006   case Bytecodes::_putfield:
  1025   case Bytecodes::_putfield:
  1007     {
  1026     {
       
  1027       bool ignored_will_link;
       
  1028       ciField* field = method()->get_field_at_bci(bci(), ignored_will_link);
       
  1029       int      size  = field->type()->size();
  1008       bool is_get = (depth >= 0), is_static = (depth & 1);
  1030       bool is_get = (depth >= 0), is_static = (depth & 1);
  1009       ciBytecodeStream iter(method());
  1031       inputs = (is_static ? 0 : 1);
  1010       iter.reset_to_bci(bci());
       
  1011       iter.next();
       
  1012       bool ignored_will_link;
       
  1013       ciField* field = iter.get_field(ignored_will_link);
       
  1014       int      size  = field->type()->size();
       
  1015       inputs  = (is_static ? 0 : 1);
       
  1016       if (is_get) {
  1032       if (is_get) {
  1017         depth = size - inputs;
  1033         depth = size - inputs;
  1018       } else {
  1034       } else {
  1019         inputs += size;        // putxxx pops the value from the stack
  1035         inputs += size;        // putxxx pops the value from the stack
  1020         depth = - inputs;
  1036         depth = - inputs;
  1026   case Bytecodes::_invokespecial:
  1042   case Bytecodes::_invokespecial:
  1027   case Bytecodes::_invokestatic:
  1043   case Bytecodes::_invokestatic:
  1028   case Bytecodes::_invokedynamic:
  1044   case Bytecodes::_invokedynamic:
  1029   case Bytecodes::_invokeinterface:
  1045   case Bytecodes::_invokeinterface:
  1030     {
  1046     {
  1031       ciBytecodeStream iter(method());
       
  1032       iter.reset_to_bci(bci());
       
  1033       iter.next();
       
  1034       bool ignored_will_link;
  1047       bool ignored_will_link;
  1035       ciSignature* declared_signature = NULL;
  1048       ciSignature* declared_signature = NULL;
  1036       ciMethod* callee = iter.get_method(ignored_will_link, &declared_signature);
  1049       ciMethod* ignored_callee = method()->get_method_at_bci(bci(), ignored_will_link, &declared_signature);
  1037       assert(declared_signature != NULL, "cannot be null");
  1050       assert(declared_signature != NULL, "cannot be null");
  1038       // (Do not use ciMethod::arg_size(), because
  1051       inputs   = declared_signature->arg_size_for_bc(code);
  1039       // it might be an unloaded method, which doesn't
       
  1040       // know whether it is static or not.)
       
  1041       if (for_parse) {
       
  1042         // Case 1: When called from parse we are *before* the invoke (in the
       
  1043         //         caller) and need to to adjust the inputs by an appendix
       
  1044         //         argument that will be pushed implicitly.
       
  1045         inputs = callee->invoke_arg_size(code) - (iter.has_appendix() ? 1 : 0);
       
  1046       } else {
       
  1047         // Case 2: Here we are *after* the invoke (in the callee) and need to
       
  1048         //         remove any appendix arguments that were popped.
       
  1049         inputs = callee->invoke_arg_size(code) - (callee->has_member_arg() ? 1 : 0);
       
  1050       }
       
  1051       int size = declared_signature->return_type()->size();
  1052       int size = declared_signature->return_type()->size();
  1052       depth = size - inputs;
  1053       depth = size - inputs;
  1053     }
  1054     }
  1054     break;
  1055     break;
  1055 
  1056 
  1176 
  1177 
  1177   // Construct NULL check
  1178   // Construct NULL check
  1178   Node *chk = NULL;
  1179   Node *chk = NULL;
  1179   switch(type) {
  1180   switch(type) {
  1180     case T_LONG   : chk = new (C) CmpLNode(value, _gvn.zerocon(T_LONG)); break;
  1181     case T_LONG   : chk = new (C) CmpLNode(value, _gvn.zerocon(T_LONG)); break;
  1181     case T_INT    : chk = new (C) CmpINode( value, _gvn.intcon(0)); break;
  1182     case T_INT    : chk = new (C) CmpINode(value, _gvn.intcon(0)); break;
  1182     case T_ARRAY  : // fall through
  1183     case T_ARRAY  : // fall through
  1183       type = T_OBJECT;  // simplify further tests
  1184       type = T_OBJECT;  // simplify further tests
  1184     case T_OBJECT : {
  1185     case T_OBJECT : {
  1185       const Type *t = _gvn.type( value );
  1186       const Type *t = _gvn.type( value );
  1186 
  1187 
  1227       }
  1228       }
  1228       chk = new (C) CmpPNode( value, null() );
  1229       chk = new (C) CmpPNode( value, null() );
  1229       break;
  1230       break;
  1230     }
  1231     }
  1231 
  1232 
  1232     default      : ShouldNotReachHere();
  1233     default:
       
  1234       fatal(err_msg_res("unexpected type: %s", type2name(type)));
  1233   }
  1235   }
  1234   assert(chk != NULL, "sanity check");
  1236   assert(chk != NULL, "sanity check");
  1235   chk = _gvn.transform(chk);
  1237   chk = _gvn.transform(chk);
  1236 
  1238 
  1237   BoolTest::mask btest = assert_null ? BoolTest::eq : BoolTest::ne;
  1239   BoolTest::mask btest = assert_null ? BoolTest::eq : BoolTest::ne;
  1859 
  1861 
  1860   // Note:  If ProfileTraps is true, and if a deopt. actually
  1862   // Note:  If ProfileTraps is true, and if a deopt. actually
  1861   // occurs here, the runtime will make sure an MDO exists.  There is
  1863   // occurs here, the runtime will make sure an MDO exists.  There is
  1862   // no need to call method()->ensure_method_data() at this point.
  1864   // no need to call method()->ensure_method_data() at this point.
  1863 
  1865 
       
  1866   // Set the stack pointer to the right value for reexecution:
       
  1867   set_sp(reexecute_sp());
       
  1868 
  1864 #ifdef ASSERT
  1869 #ifdef ASSERT
  1865   if (!must_throw) {
  1870   if (!must_throw) {
  1866     // Make sure the stack has at least enough depth to execute
  1871     // Make sure the stack has at least enough depth to execute
  1867     // the current bytecode.
  1872     // the current bytecode.
  1868     int inputs, ignore;
  1873     int inputs, ignored_depth;
  1869     if (compute_stack_effects(inputs, ignore)) {
  1874     if (compute_stack_effects(inputs, ignored_depth)) {
  1870       assert(sp() >= inputs, "must have enough JVMS stack to execute");
  1875       assert(sp() >= inputs, err_msg_res("must have enough JVMS stack to execute %s: sp=%d, inputs=%d",
  1871       // It is a frequent error in library_call.cpp to issue an
  1876              Bytecodes::name(java_bc()), sp(), inputs));
  1872       // uncommon trap with the _sp value already popped.
       
  1873     }
  1877     }
  1874   }
  1878   }
  1875 #endif
  1879 #endif
  1876 
  1880 
  1877   Deoptimization::DeoptReason reason = Deoptimization::trap_request_reason(trap_request);
  1881   Deoptimization::DeoptReason reason = Deoptimization::trap_request_reason(trap_request);
  1898 #ifdef ASSERT
  1902 #ifdef ASSERT
  1899   case Deoptimization::Action_none:
  1903   case Deoptimization::Action_none:
  1900   case Deoptimization::Action_make_not_compilable:
  1904   case Deoptimization::Action_make_not_compilable:
  1901     break;
  1905     break;
  1902   default:
  1906   default:
  1903     assert(false, "bad action");
  1907     fatal(err_msg_res("unknown action %d: %s", action, Deoptimization::trap_action_name(action)));
       
  1908     break;
  1904 #endif
  1909 #endif
  1905   }
  1910   }
  1906 
  1911 
  1907   if (TraceOptoParse) {
  1912   if (TraceOptoParse) {
  1908     char buf[100];
  1913     char buf[100];
  2665       case SSC_always_true:
  2670       case SSC_always_true:
  2666         return obj;
  2671         return obj;
  2667       case SSC_always_false:
  2672       case SSC_always_false:
  2668         // It needs a null check because a null will *pass* the cast check.
  2673         // It needs a null check because a null will *pass* the cast check.
  2669         // A non-null value will always produce an exception.
  2674         // A non-null value will always produce an exception.
  2670         return do_null_assert(obj, T_OBJECT);
  2675         return null_assert(obj);
  2671       }
  2676       }
  2672     }
  2677     }
  2673   }
  2678   }
  2674 
  2679 
  2675   ciProfileData* data = NULL;
  2680   ciProfileData* data = NULL;
  2784 Node* GraphKit::insert_mem_bar(int opcode, Node* precedent) {
  2789 Node* GraphKit::insert_mem_bar(int opcode, Node* precedent) {
  2785   MemBarNode* mb = MemBarNode::make(C, opcode, Compile::AliasIdxBot, precedent);
  2790   MemBarNode* mb = MemBarNode::make(C, opcode, Compile::AliasIdxBot, precedent);
  2786   mb->init_req(TypeFunc::Control, control());
  2791   mb->init_req(TypeFunc::Control, control());
  2787   mb->init_req(TypeFunc::Memory,  reset_memory());
  2792   mb->init_req(TypeFunc::Memory,  reset_memory());
  2788   Node* membar = _gvn.transform(mb);
  2793   Node* membar = _gvn.transform(mb);
  2789   set_control(_gvn.transform(new (C) ProjNode(membar,TypeFunc::Control) ));
  2794   set_control(_gvn.transform(new (C) ProjNode(membar, TypeFunc::Control)));
  2790   set_all_memory_call(membar);
  2795   set_all_memory_call(membar);
  2791   return membar;
  2796   return membar;
  2792 }
  2797 }
  2793 
  2798 
  2794 //-------------------------insert_mem_bar_volatile----------------------------
  2799 //-------------------------insert_mem_bar_volatile----------------------------
  3146     // so that we can fold up all the address arithmetic.
  3151     // so that we can fold up all the address arithmetic.
  3147     layout_con = Klass::array_layout_helper(T_OBJECT);
  3152     layout_con = Klass::array_layout_helper(T_OBJECT);
  3148     Node* cmp_lh = _gvn.transform( new(C) CmpINode(layout_val, intcon(layout_con)) );
  3153     Node* cmp_lh = _gvn.transform( new(C) CmpINode(layout_val, intcon(layout_con)) );
  3149     Node* bol_lh = _gvn.transform( new(C) BoolNode(cmp_lh, BoolTest::eq) );
  3154     Node* bol_lh = _gvn.transform( new(C) BoolNode(cmp_lh, BoolTest::eq) );
  3150     { BuildCutout unless(this, bol_lh, PROB_MAX);
  3155     { BuildCutout unless(this, bol_lh, PROB_MAX);
  3151       _sp += nargs;
  3156       inc_sp(nargs);
  3152       uncommon_trap(Deoptimization::Reason_class_check,
  3157       uncommon_trap(Deoptimization::Reason_class_check,
  3153                     Deoptimization::Action_maybe_recompile);
  3158                     Deoptimization::Action_maybe_recompile);
  3154     }
  3159     }
  3155     layout_val = NULL;
  3160     layout_val = NULL;
  3156     layout_is_con = true;
  3161     layout_is_con = true;
  3389   Node* iffalse = _gvn.transform(new (C) IfFalseNode(iff));
  3394   Node* iffalse = _gvn.transform(new (C) IfFalseNode(iff));
  3390   C->add_predicate_opaq(opq);
  3395   C->add_predicate_opaq(opq);
  3391   {
  3396   {
  3392     PreserveJVMState pjvms(this);
  3397     PreserveJVMState pjvms(this);
  3393     set_control(iffalse);
  3398     set_control(iffalse);
  3394     _sp += nargs;
  3399     inc_sp(nargs);
  3395     uncommon_trap(reason, Deoptimization::Action_maybe_recompile);
  3400     uncommon_trap(reason, Deoptimization::Action_maybe_recompile);
  3396   }
  3401   }
  3397   Node* iftrue = _gvn.transform(new (C) IfTrueNode(iff));
  3402   Node* iftrue = _gvn.transform(new (C) IfTrueNode(iff));
  3398   set_control(iftrue);
  3403   set_control(iftrue);
  3399 }
  3404 }