hotspot/src/share/vm/runtime/deoptimization.cpp
changeset 33148 68fa8b6c4340
parent 31593 7b9e292896d2
child 33198 b37ad9fbf681
equal deleted inserted replaced
33146:77349b58b4c0 33148:68fa8b6c4340
    51 #include "runtime/vframeArray.hpp"
    51 #include "runtime/vframeArray.hpp"
    52 #include "runtime/vframe_hp.hpp"
    52 #include "runtime/vframe_hp.hpp"
    53 #include "utilities/events.hpp"
    53 #include "utilities/events.hpp"
    54 #include "utilities/xmlstream.hpp"
    54 #include "utilities/xmlstream.hpp"
    55 
    55 
    56 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
       
    57 
       
    58 bool DeoptimizationMarker::_is_active = false;
    56 bool DeoptimizationMarker::_is_active = false;
    59 
    57 
    60 Deoptimization::UnrollBlock::UnrollBlock(int  size_of_deoptimized_frame,
    58 Deoptimization::UnrollBlock::UnrollBlock(int  size_of_deoptimized_frame,
    61                                          int  caller_adjustment,
    59                                          int  caller_adjustment,
    62                                          int  caller_actual_parameters,
    60                                          int  caller_actual_parameters,
   110   ttyLocker ttyl;
   108   ttyLocker ttyl;
   111   tty->print_cr("UnrollBlock");
   109   tty->print_cr("UnrollBlock");
   112   tty->print_cr("  size_of_deoptimized_frame = %d", _size_of_deoptimized_frame);
   110   tty->print_cr("  size_of_deoptimized_frame = %d", _size_of_deoptimized_frame);
   113   tty->print(   "  frame_sizes: ");
   111   tty->print(   "  frame_sizes: ");
   114   for (int index = 0; index < number_of_frames(); index++) {
   112   for (int index = 0; index < number_of_frames(); index++) {
   115     tty->print("%d ", frame_sizes()[index]);
   113     tty->print(INTX_FORMAT " ", frame_sizes()[index]);
   116   }
   114   }
   117   tty->cr();
   115   tty->cr();
   118 }
   116 }
   119 
   117 
   120 
   118 
   204         assert(result == NULL || result->is_oop(), "must be oop");
   202         assert(result == NULL || result->is_oop(), "must be oop");
   205         return_value = Handle(thread, result);
   203         return_value = Handle(thread, result);
   206         assert(Universe::heap()->is_in_or_null(result), "must be heap pointer");
   204         assert(Universe::heap()->is_in_or_null(result), "must be heap pointer");
   207         if (TraceDeoptimization) {
   205         if (TraceDeoptimization) {
   208           ttyLocker ttyl;
   206           ttyLocker ttyl;
   209           tty->print_cr("SAVED OOP RESULT " INTPTR_FORMAT " in thread " INTPTR_FORMAT, (void *)result, thread);
   207           tty->print_cr("SAVED OOP RESULT " INTPTR_FORMAT " in thread " INTPTR_FORMAT, p2i(result), p2i(thread));
   210         }
   208         }
   211       }
   209       }
   212       if (objects != NULL) {
   210       if (objects != NULL) {
   213         JRT_BLOCK
   211         JRT_BLOCK
   214           realloc_failures = realloc_objects(thread, &deoptee, objects, THREAD);
   212           realloc_failures = realloc_objects(thread, &deoptee, objects, THREAD);
   215         JRT_END
   213         JRT_END
   216         reassign_fields(&deoptee, &map, objects, realloc_failures);
   214         reassign_fields(&deoptee, &map, objects, realloc_failures);
   217 #ifndef PRODUCT
   215 #ifndef PRODUCT
   218         if (TraceDeoptimization) {
   216         if (TraceDeoptimization) {
   219           ttyLocker ttyl;
   217           ttyLocker ttyl;
   220           tty->print_cr("REALLOC OBJECTS in thread " INTPTR_FORMAT, thread);
   218           tty->print_cr("REALLOC OBJECTS in thread " INTPTR_FORMAT, p2i(thread));
   221           print_objects(objects, realloc_failures);
   219           print_objects(objects, realloc_failures);
   222         }
   220         }
   223 #endif
   221 #endif
   224       }
   222       }
   225       if (save_oop_result) {
   223       if (save_oop_result) {
   243             for (int j = 0; j < monitors->length(); j++) {
   241             for (int j = 0; j < monitors->length(); j++) {
   244               MonitorInfo* mi = monitors->at(j);
   242               MonitorInfo* mi = monitors->at(j);
   245               if (mi->eliminated()) {
   243               if (mi->eliminated()) {
   246                 if (first) {
   244                 if (first) {
   247                   first = false;
   245                   first = false;
   248                   tty->print_cr("RELOCK OBJECTS in thread " INTPTR_FORMAT, thread);
   246                   tty->print_cr("RELOCK OBJECTS in thread " INTPTR_FORMAT, p2i(thread));
   249                 }
   247                 }
   250                 if (mi->owner_is_scalar_replaced()) {
   248                 if (mi->owner_is_scalar_replaced()) {
   251                   Klass* k = java_lang_Class::as_Klass(mi->owner_klass());
   249                   Klass* k = java_lang_Class::as_Klass(mi->owner_klass());
   252                   tty->print_cr("     failed reallocation for klass %s", k->external_name());
   250                   tty->print_cr("     failed reallocation for klass %s", k->external_name());
   253                 } else {
   251                 } else {
   254                   tty->print_cr("     object <" INTPTR_FORMAT "> locked", (void *)mi->owner());
   252                   tty->print_cr("     object <" INTPTR_FORMAT "> locked", p2i(mi->owner()));
   255                 }
   253                 }
   256               }
   254               }
   257             }
   255             }
   258           }
   256           }
   259 #endif
   257 #endif
   548   vframeArray* array = thread->vframe_array_head();
   546   vframeArray* array = thread->vframe_array_head();
   549 
   547 
   550 #ifndef PRODUCT
   548 #ifndef PRODUCT
   551   if (TraceDeoptimization) {
   549   if (TraceDeoptimization) {
   552     ttyLocker ttyl;
   550     ttyLocker ttyl;
   553     tty->print_cr("DEOPT UNPACKING thread " INTPTR_FORMAT " vframeArray " INTPTR_FORMAT " mode %d", thread, array, exec_mode);
   551     tty->print_cr("DEOPT UNPACKING thread " INTPTR_FORMAT " vframeArray " INTPTR_FORMAT " mode %d",
       
   552                   p2i(thread), p2i(array), exec_mode);
   554   }
   553   }
   555 #endif
   554 #endif
   556   Events::log(thread, "DEOPT UNPACKING pc=" INTPTR_FORMAT " sp=" INTPTR_FORMAT " mode %d",
   555   Events::log(thread, "DEOPT UNPACKING pc=" INTPTR_FORMAT " sp=" INTPTR_FORMAT " mode %d",
   557               stub_frame.pc(), stub_frame.sp(), exec_mode);
   556               p2i(stub_frame.pc()), p2i(stub_frame.sp()), exec_mode);
   558 
   557 
   559   UnrollBlock* info = array->unroll_block();
   558   UnrollBlock* info = array->unroll_block();
   560 
   559 
   561   // Unpack the interpreter frames and any adapter frame (c2 only) we might create.
   560   // Unpack the interpreter frames and any adapter frame (c2 only) we might create.
   562   array->unpack_to_stack(stub_frame, exec_mode, info->caller_actual_parameters());
   561   array->unpack_to_stack(stub_frame, exec_mode, info->caller_actual_parameters());
   688         tty->print_cr("  callee_size_of_parameters = %d", callee_size_of_parameters);
   687         tty->print_cr("  callee_size_of_parameters = %d", callee_size_of_parameters);
   689         tty->print_cr("  callee_max_locals = %d", callee_max_locals);
   688         tty->print_cr("  callee_max_locals = %d", callee_max_locals);
   690         tty->print_cr("  top_frame_expression_stack_adjustment = %d", top_frame_expression_stack_adjustment);
   689         tty->print_cr("  top_frame_expression_stack_adjustment = %d", top_frame_expression_stack_adjustment);
   691         tty->print_cr("  exec_mode = %d", exec_mode);
   690         tty->print_cr("  exec_mode = %d", exec_mode);
   692         tty->print_cr("  cur_invoke_parameter_size = %d", cur_invoke_parameter_size);
   691         tty->print_cr("  cur_invoke_parameter_size = %d", cur_invoke_parameter_size);
   693         tty->print_cr("  Thread = " INTPTR_FORMAT ", thread ID = " UINTX_FORMAT, thread, thread->osthread()->thread_id());
   692         tty->print_cr("  Thread = " INTPTR_FORMAT ", thread ID = %d", p2i(thread), thread->osthread()->thread_id());
   694         tty->print_cr("  Interpreted frames:");
   693         tty->print_cr("  Interpreted frames:");
   695         for (int k = 0; k < cur_array->frames(); k++) {
   694         for (int k = 0; k < cur_array->frames(); k++) {
   696           vframeArrayElement* el = cur_array->element(k);
   695           vframeArrayElement* el = cur_array->element(k);
   697           tty->print_cr("    %s (bci %d)", el->method()->name_and_sig_as_C_string(), el->bci());
   696           tty->print_cr("    %s (bci %d)", el->method()->name_and_sig_as_C_string(), el->bci());
   698         }
   697         }
   964   for (int i = 0; i < objects->length(); i++) {
   963   for (int i = 0; i < objects->length(); i++) {
   965     ObjectValue* sv = (ObjectValue*) objects->at(i);
   964     ObjectValue* sv = (ObjectValue*) objects->at(i);
   966     KlassHandle k(java_lang_Class::as_Klass(sv->klass()->as_ConstantOopReadValue()->value()()));
   965     KlassHandle k(java_lang_Class::as_Klass(sv->klass()->as_ConstantOopReadValue()->value()()));
   967     Handle obj = sv->value();
   966     Handle obj = sv->value();
   968 
   967 
   969     tty->print("     object <" INTPTR_FORMAT "> of type ", (void *)sv->value()());
   968     tty->print("     object <" INTPTR_FORMAT "> of type ", p2i(sv->value()()));
   970     k->print_value();
   969     k->print_value();
   971     assert(obj.not_null() || realloc_failures, "reallocation was missed");
   970     assert(obj.not_null() || realloc_failures, "reallocation was missed");
   972     if (obj.is_null()) {
   971     if (obj.is_null()) {
   973       tty->print(" allocation failed");
   972       tty->print(" allocation failed");
   974     } else {
   973     } else {
   983 }
   982 }
   984 #endif
   983 #endif
   985 #endif // COMPILER2
   984 #endif // COMPILER2
   986 
   985 
   987 vframeArray* Deoptimization::create_vframeArray(JavaThread* thread, frame fr, RegisterMap *reg_map, GrowableArray<compiledVFrame*>* chunk, bool realloc_failures) {
   986 vframeArray* Deoptimization::create_vframeArray(JavaThread* thread, frame fr, RegisterMap *reg_map, GrowableArray<compiledVFrame*>* chunk, bool realloc_failures) {
   988   Events::log(thread, "DEOPT PACKING pc=" INTPTR_FORMAT " sp=" INTPTR_FORMAT, fr.pc(), fr.sp());
   987   Events::log(thread, "DEOPT PACKING pc=" INTPTR_FORMAT " sp=" INTPTR_FORMAT, p2i(fr.pc()), p2i(fr.sp()));
   989 
   988 
   990 #ifndef PRODUCT
   989 #ifndef PRODUCT
   991   if (TraceDeoptimization) {
   990   if (TraceDeoptimization) {
   992     ttyLocker ttyl;
   991     ttyLocker ttyl;
   993     tty->print("DEOPT PACKING thread " INTPTR_FORMAT " ", thread);
   992     tty->print("DEOPT PACKING thread " INTPTR_FORMAT " ", p2i(thread));
   994     fr.print_on(tty);
   993     fr.print_on(tty);
   995     tty->print_cr("     Virtual frames (innermost first):");
   994     tty->print_cr("     Virtual frames (innermost first):");
   996     for (int index = 0; index < chunk->length(); index++) {
   995     for (int index = 0; index < chunk->length(); index++) {
   997       compiledVFrame* vf = chunk->at(index);
   996       compiledVFrame* vf = chunk->at(index);
   998       tty->print("       %2d - ", index);
   997       tty->print("       %2d - ", index);
  1033   assert(array->structural_compare(thread, chunk), "just checking");
  1032   assert(array->structural_compare(thread, chunk), "just checking");
  1034 
  1033 
  1035 #ifndef PRODUCT
  1034 #ifndef PRODUCT
  1036   if (TraceDeoptimization) {
  1035   if (TraceDeoptimization) {
  1037     ttyLocker ttyl;
  1036     ttyLocker ttyl;
  1038     tty->print_cr("     Created vframeArray " INTPTR_FORMAT, array);
  1037     tty->print_cr("     Created vframeArray " INTPTR_FORMAT, p2i(array));
  1039   }
  1038   }
  1040 #endif // PRODUCT
  1039 #endif // PRODUCT
  1041 
  1040 
  1042   return array;
  1041   return array;
  1043 }
  1042 }
  1295   // before we are done with it.
  1294   // before we are done with it.
  1296   nmethodLocker nl(fr.pc());
  1295   nmethodLocker nl(fr.pc());
  1297 
  1296 
  1298   // Log a message
  1297   // Log a message
  1299   Events::log(thread, "Uncommon trap: trap_request=" PTR32_FORMAT " fr.pc=" INTPTR_FORMAT,
  1298   Events::log(thread, "Uncommon trap: trap_request=" PTR32_FORMAT " fr.pc=" INTPTR_FORMAT,
  1300               trap_request, fr.pc());
  1299               trap_request, p2i(fr.pc()));
  1301 
  1300 
  1302   {
  1301   {
  1303     ResourceMark rm;
  1302     ResourceMark rm;
  1304 
  1303 
  1305     // Revoke biases of any monitors in the frame to ensure we can migrate them
  1304     // Revoke biases of any monitors in the frame to ensure we can migrate them
  1329     MethodData* trap_mdo =
  1328     MethodData* trap_mdo =
  1330       get_method_data(thread, trap_method, create_if_missing);
  1329       get_method_data(thread, trap_method, create_if_missing);
  1331 
  1330 
  1332     // Log a message
  1331     // Log a message
  1333     Events::log_deopt_message(thread, "Uncommon trap: reason=%s action=%s pc=" INTPTR_FORMAT " method=%s @ %d",
  1332     Events::log_deopt_message(thread, "Uncommon trap: reason=%s action=%s pc=" INTPTR_FORMAT " method=%s @ %d",
  1334                               trap_reason_name(reason), trap_action_name(action), fr.pc(),
  1333                               trap_reason_name(reason), trap_action_name(action), p2i(fr.pc()),
  1335                               trap_method->name_and_sig_as_C_string(), trap_bci);
  1334                               trap_method->name_and_sig_as_C_string(), trap_bci);
  1336 
  1335 
  1337     // Print a bunch of diagnostics, if requested.
  1336     // Print a bunch of diagnostics, if requested.
  1338     if (TraceDeoptimization || LogCompilation) {
  1337     if (TraceDeoptimization || LogCompilation) {
  1339       ResourceMark rm;
  1338       ResourceMark rm;
  1384       }
  1383       }
  1385       if (TraceDeoptimization) {  // make noise on the tty
  1384       if (TraceDeoptimization) {  // make noise on the tty
  1386         tty->print("Uncommon trap occurred in");
  1385         tty->print("Uncommon trap occurred in");
  1387         nm->method()->print_short_name(tty);
  1386         nm->method()->print_short_name(tty);
  1388         tty->print(" (@" INTPTR_FORMAT ") thread=" UINTX_FORMAT " reason=%s action=%s unloaded_class_index=%d",
  1387         tty->print(" (@" INTPTR_FORMAT ") thread=" UINTX_FORMAT " reason=%s action=%s unloaded_class_index=%d",
  1389                    fr.pc(),
  1388                    p2i(fr.pc()),
  1390                    os::current_thread_id(),
  1389                    os::current_thread_id(),
  1391                    trap_reason_name(reason),
  1390                    trap_reason_name(reason),
  1392                    trap_action_name(action),
  1391                    trap_action_name(action),
  1393                    unloaded_class_index);
  1392                    unloaded_class_index);
  1394         if (class_name != NULL) {
  1393         if (class_name != NULL) {