hotspot/src/share/vm/runtime/deoptimization.cpp
changeset 34185 ee71c590a456
parent 33813 4f376e851453
parent 34173 01bb07d23a5b
child 34651 07b1cc0f6040
equal deleted inserted replaced
33813:4f376e851453 34185:ee71c590a456
    66                                          int  caller_adjustment,
    66                                          int  caller_adjustment,
    67                                          int  caller_actual_parameters,
    67                                          int  caller_actual_parameters,
    68                                          int  number_of_frames,
    68                                          int  number_of_frames,
    69                                          intptr_t* frame_sizes,
    69                                          intptr_t* frame_sizes,
    70                                          address* frame_pcs,
    70                                          address* frame_pcs,
    71                                          BasicType return_type) {
    71                                          BasicType return_type,
       
    72                                          int exec_mode) {
    72   _size_of_deoptimized_frame = size_of_deoptimized_frame;
    73   _size_of_deoptimized_frame = size_of_deoptimized_frame;
    73   _caller_adjustment         = caller_adjustment;
    74   _caller_adjustment         = caller_adjustment;
    74   _caller_actual_parameters  = caller_actual_parameters;
    75   _caller_actual_parameters  = caller_actual_parameters;
    75   _number_of_frames          = number_of_frames;
    76   _number_of_frames          = number_of_frames;
    76   _frame_sizes               = frame_sizes;
    77   _frame_sizes               = frame_sizes;
    78   _register_block            = NEW_C_HEAP_ARRAY(intptr_t, RegisterMap::reg_count * 2, mtCompiler);
    79   _register_block            = NEW_C_HEAP_ARRAY(intptr_t, RegisterMap::reg_count * 2, mtCompiler);
    79   _return_type               = return_type;
    80   _return_type               = return_type;
    80   _initial_info              = 0;
    81   _initial_info              = 0;
    81   // PD (x86 only)
    82   // PD (x86 only)
    82   _counter_temp              = 0;
    83   _counter_temp              = 0;
    83   _unpack_kind               = 0;
    84   _unpack_kind               = exec_mode;
    84   _sender_sp_temp            = 0;
    85   _sender_sp_temp            = 0;
    85 
    86 
    86   _total_frame_sizes         = size_of_frames();
    87   _total_frame_sizes         = size_of_frames();
       
    88   assert(exec_mode >= 0 && exec_mode < Unpack_LIMIT, "Unexpected exec_mode");
    87 }
    89 }
    88 
    90 
    89 
    91 
    90 Deoptimization::UnrollBlock::~UnrollBlock() {
    92 Deoptimization::UnrollBlock::~UnrollBlock() {
    91   FREE_C_HEAP_ARRAY(intptr_t, _frame_sizes);
    93   FREE_C_HEAP_ARRAY(intptr_t, _frame_sizes);
   126 // In order to make fetch_unroll_info work properly with escape
   128 // In order to make fetch_unroll_info work properly with escape
   127 // analysis, The method was changed from JRT_LEAF to JRT_BLOCK_ENTRY and
   129 // analysis, The method was changed from JRT_LEAF to JRT_BLOCK_ENTRY and
   128 // ResetNoHandleMark and HandleMark were removed from it. The actual reallocation
   130 // ResetNoHandleMark and HandleMark were removed from it. The actual reallocation
   129 // of previously eliminated objects occurs in realloc_objects, which is
   131 // of previously eliminated objects occurs in realloc_objects, which is
   130 // called from the method fetch_unroll_info_helper below.
   132 // called from the method fetch_unroll_info_helper below.
   131 JRT_BLOCK_ENTRY(Deoptimization::UnrollBlock*, Deoptimization::fetch_unroll_info(JavaThread* thread))
   133 JRT_BLOCK_ENTRY(Deoptimization::UnrollBlock*, Deoptimization::fetch_unroll_info(JavaThread* thread, int exec_mode))
   132   // It is actually ok to allocate handles in a leaf method. It causes no safepoints,
   134   // It is actually ok to allocate handles in a leaf method. It causes no safepoints,
   133   // but makes the entry a little slower. There is however a little dance we have to
   135   // but makes the entry a little slower. There is however a little dance we have to
   134   // do in debug mode to get around the NoHandleMark code in the JRT_LEAF macro
   136   // do in debug mode to get around the NoHandleMark code in the JRT_LEAF macro
   135 
   137 
   136   // fetch_unroll_info() is called at the beginning of the deoptimization
   138   // fetch_unroll_info() is called at the beginning of the deoptimization
   140   if (TraceDeoptimization) {
   142   if (TraceDeoptimization) {
   141     tty->print_cr("Deoptimizing thread " INTPTR_FORMAT, p2i(thread));
   143     tty->print_cr("Deoptimizing thread " INTPTR_FORMAT, p2i(thread));
   142   }
   144   }
   143   thread->inc_in_deopt_handler();
   145   thread->inc_in_deopt_handler();
   144 
   146 
   145   return fetch_unroll_info_helper(thread);
   147   return fetch_unroll_info_helper(thread, exec_mode);
   146 JRT_END
   148 JRT_END
   147 
   149 
   148 
   150 
   149 // This is factored, since it is both called from a JRT_LEAF (deoptimization) and a JRT_ENTRY (uncommon_trap)
   151 // This is factored, since it is both called from a JRT_LEAF (deoptimization) and a JRT_ENTRY (uncommon_trap)
   150 Deoptimization::UnrollBlock* Deoptimization::fetch_unroll_info_helper(JavaThread* thread) {
   152 Deoptimization::UnrollBlock* Deoptimization::fetch_unroll_info_helper(JavaThread* thread, int exec_mode) {
   151 
   153 
   152   // Note: there is a safepoint safety issue here. No matter whether we enter
   154   // Note: there is a safepoint safety issue here. No matter whether we enter
   153   // via vanilla deopt or uncommon trap we MUST NOT stop at a safepoint once
   155   // via vanilla deopt or uncommon trap we MUST NOT stop at a safepoint once
   154   // the vframeArray is created.
   156   // the vframeArray is created.
   155   //
   157   //
   183     chunk->push(compiledVFrame::cast(vf));
   185     chunk->push(compiledVFrame::cast(vf));
   184     vf = vf->sender();
   186     vf = vf->sender();
   185   }
   187   }
   186   assert(vf->is_compiled_frame(), "Wrong frame type");
   188   assert(vf->is_compiled_frame(), "Wrong frame type");
   187   chunk->push(compiledVFrame::cast(vf));
   189   chunk->push(compiledVFrame::cast(vf));
       
   190 
       
   191   ScopeDesc* trap_scope = chunk->at(0)->scope();
       
   192   Handle exceptionObject;
       
   193   if (trap_scope->rethrow_exception()) {
       
   194     if (PrintDeoptimizationDetails) {
       
   195       tty->print_cr("Exception to be rethrown in the interpreter for method %s::%s at bci %d", trap_scope->method()->method_holder()->name()->as_C_string(), trap_scope->method()->name()->as_C_string(), trap_scope->bci());
       
   196     }
       
   197     GrowableArray<ScopeValue*>* expressions = trap_scope->expressions();
       
   198     guarantee(expressions != NULL && expressions->length() > 0, "must have exception to throw");
       
   199     ScopeValue* topOfStack = expressions->top();
       
   200     exceptionObject = StackValue::create_stack_value(&deoptee, &map, topOfStack)->get_obj();
       
   201     assert(exceptionObject() != NULL, "exception oop can not be null");
       
   202   }
   188 
   203 
   189   bool realloc_failures = false;
   204   bool realloc_failures = false;
   190 
   205 
   191 #if defined(COMPILER2) || INCLUDE_JVMCI
   206 #if defined(COMPILER2) || INCLUDE_JVMCI
   192   // Reallocate the non-escaping objects and restore their fields. Then
   207   // Reallocate the non-escaping objects and restore their fields. Then
   472 
   487 
   473 #ifndef SHARK
   488 #ifndef SHARK
   474   assert(CodeCache::find_blob_unsafe(frame_pcs[0]) != NULL, "bad pc");
   489   assert(CodeCache::find_blob_unsafe(frame_pcs[0]) != NULL, "bad pc");
   475 #endif // SHARK
   490 #endif // SHARK
   476 
   491 
       
   492 #ifdef INCLUDE_JVMCI
       
   493   if (exceptionObject() != NULL) {
       
   494     thread->set_exception_oop(exceptionObject());
       
   495     exec_mode = Unpack_exception;
       
   496   }
       
   497 #endif
       
   498 
   477   UnrollBlock* info = new UnrollBlock(array->frame_size() * BytesPerWord,
   499   UnrollBlock* info = new UnrollBlock(array->frame_size() * BytesPerWord,
   478                                       caller_adjustment * BytesPerWord,
   500                                       caller_adjustment * BytesPerWord,
   479                                       caller_was_method_handle ? 0 : callee_parameters,
   501                                       caller_was_method_handle ? 0 : callee_parameters,
   480                                       number_of_frames,
   502                                       number_of_frames,
   481                                       frame_sizes,
   503                                       frame_sizes,
   482                                       frame_pcs,
   504                                       frame_pcs,
   483                                       return_type);
   505                                       return_type,
       
   506                                       exec_mode);
   484   // On some platforms, we need a way to pass some platform dependent
   507   // On some platforms, we need a way to pass some platform dependent
   485   // information to the unpacking code so the skeletal frames come out
   508   // information to the unpacking code so the skeletal frames come out
   486   // correct (initial fp value, unextended sp, ...)
   509   // correct (initial fp value, unextended sp, ...)
   487   info->set_initial_info((intptr_t) array->sender().initial_deoptimization_info());
   510   info->set_initial_info((intptr_t) array->sender().initial_deoptimization_info());
   488 
   511 
  1493       thread->set_pending_transfer_to_interpreter(true);
  1516       thread->set_pending_transfer_to_interpreter(true);
  1494     }
  1517     }
  1495 #endif
  1518 #endif
  1496 
  1519 
  1497     Bytecodes::Code trap_bc     = trap_method->java_code_at(trap_bci);
  1520     Bytecodes::Code trap_bc     = trap_method->java_code_at(trap_bci);
  1498 
       
  1499     if (trap_scope->rethrow_exception()) {
       
  1500       if (PrintDeoptimizationDetails) {
       
  1501         tty->print_cr("Exception to be rethrown in the interpreter for method %s::%s at bci %d", trap_method->method_holder()->name()->as_C_string(), trap_method->name()->as_C_string(), trap_bci);
       
  1502       }
       
  1503       GrowableArray<ScopeValue*>* expressions = trap_scope->expressions();
       
  1504       guarantee(expressions != NULL, "must have exception to throw");
       
  1505       ScopeValue* topOfStack = expressions->top();
       
  1506       Handle topOfStackObj = StackValue::create_stack_value(&fr, &reg_map, topOfStack)->get_obj();
       
  1507       THREAD->set_pending_exception(topOfStackObj(), NULL, 0);
       
  1508     }
       
  1509 
       
  1510     // Record this event in the histogram.
  1521     // Record this event in the histogram.
  1511     gather_statistics(reason, action, trap_bc);
  1522     gather_statistics(reason, action, trap_bc);
  1512 
  1523 
  1513     // Ensure that we can record deopt. history:
  1524     // Ensure that we can record deopt. history:
  1514     // Need MDO to record RTM code generation state.
  1525     // Need MDO to record RTM code generation state.
  1983                            ignore_this_trap_count,
  1994                            ignore_this_trap_count,
  1984                            ignore_maybe_prior_trap,
  1995                            ignore_maybe_prior_trap,
  1985                            ignore_maybe_prior_recompile);
  1996                            ignore_maybe_prior_recompile);
  1986 }
  1997 }
  1987 
  1998 
  1988 Deoptimization::UnrollBlock* Deoptimization::uncommon_trap(JavaThread* thread, jint trap_request) {
  1999 Deoptimization::UnrollBlock* Deoptimization::uncommon_trap(JavaThread* thread, jint trap_request, jint exec_mode) {
  1989   if (TraceDeoptimization) {
  2000   if (TraceDeoptimization) {
  1990     tty->print("Uncommon trap ");
  2001     tty->print("Uncommon trap ");
  1991   }
  2002   }
  1992   // Still in Java no safepoints
  2003   // Still in Java no safepoints
  1993   {
  2004   {
  1994     // This enters VM and may safepoint
  2005     // This enters VM and may safepoint
  1995     uncommon_trap_inner(thread, trap_request);
  2006     uncommon_trap_inner(thread, trap_request);
  1996   }
  2007   }
  1997   return fetch_unroll_info_helper(thread);
  2008   return fetch_unroll_info_helper(thread, exec_mode);
  1998 }
  2009 }
  1999 
  2010 
  2000 // Local derived constants.
  2011 // Local derived constants.
  2001 // Further breakdown of DataLayout::trap_state, as promised by DataLayout.
  2012 // Further breakdown of DataLayout::trap_state, as promised by DataLayout.
  2002 const int DS_REASON_MASK   = DataLayout::trap_mask >> 1;
  2013 const int DS_REASON_MASK   = DataLayout::trap_mask >> 1;