src/share/vm/ci/ciMethodData.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Sdiff src/share/vm/ci

src/share/vm/ci/ciMethodData.cpp

Print this page
rev 6953 : 8057038: Speculative traps not robust when compilation and class unloading are concurrent
Summary: speculative traps can be removed from MDO while being copied by compiler
Reviewed-by:


  64   Copy::zero_to_words((HeapWord*) &_orig, sizeof(_orig) / sizeof(HeapWord));
  65   _data = NULL;
  66   _data_size = 0;
  67   _extra_data_size = 0;
  68   _current_mileage = 0;
  69   _invocation_counter = 0;
  70   _backedge_counter = 0;
  71   _state = empty_state;
  72   _saw_free_extra_data = false;
  73   // Set an initial hint. Don't use set_hint_di() because
  74   // first_di() may be out of bounds if data_size is 0.
  75   _hint_di = first_di();
  76   // Initialize the escape information (to "don't know.");
  77   _eflags = _arg_local = _arg_stack = _arg_returned = 0;
  78   _parameters = NULL;
  79 }
  80 
  81 void ciMethodData::load_extra_data() {
  82   MethodData* mdo = get_MethodData();
  83 


  84   // speculative trap entries also hold a pointer to a Method so need to be translated
  85   DataLayout* dp_src  = mdo->extra_data_base();
  86   DataLayout* end_src = mdo->extra_data_limit();
  87   DataLayout* dp_dst  = extra_data_base();
  88   for (;; dp_src = MethodData::next_extra(dp_src), dp_dst = MethodData::next_extra(dp_dst)) {
  89     assert(dp_src < end_src, "moved past end of extra data");
  90     // New traps in the MDO can be added as we translate the copy so
  91     // look at the entries in the copy.
  92     switch(dp_dst->tag()) {










  93     case DataLayout::speculative_trap_data_tag: {
  94       ciSpeculativeTrapData* data_dst = new ciSpeculativeTrapData(dp_dst);
  95       SpeculativeTrapData* data_src = new SpeculativeTrapData(dp_src);

  96       data_dst->translate_from(data_src);






  97       break;
  98     }
  99     case DataLayout::bit_data_tag:
 100       break;
 101     case DataLayout::no_tag:
 102     case DataLayout::arg_info_data_tag:
 103       // An empty slot or ArgInfoData entry marks the end of the trap data
 104       return;
 105     default:
 106       fatal(err_msg("bad tag = %d", dp_dst->tag()));
 107     }
 108   }
 109 }
 110 
 111 void ciMethodData::load_data() {
 112   MethodData* mdo = get_MethodData();
 113   if (mdo == NULL) {
 114     return;
 115   }
 116 


 227   case DataLayout::arg_info_data_tag:
 228     return new ciArgInfoData(data_layout);
 229   case DataLayout::call_type_data_tag:
 230     return new ciCallTypeData(data_layout);
 231   case DataLayout::virtual_call_type_data_tag:
 232     return new ciVirtualCallTypeData(data_layout);
 233   case DataLayout::parameters_type_data_tag:
 234     return new ciParametersTypeData(data_layout);
 235   };
 236 }
 237 
 238 // Iteration over data.
 239 ciProfileData* ciMethodData::next_data(ciProfileData* current) {
 240   int current_index = dp_to_di(current->dp());
 241   int next_index = current_index + current->size_in_bytes();
 242   ciProfileData* next = data_at(next_index);
 243   return next;
 244 }
 245 
 246 ciProfileData* ciMethodData::bci_to_extra_data(int bci, ciMethod* m, bool& two_free_slots) {
 247   DataLayout* dp  = data_layout_at(data_size());
 248   DataLayout* end = data_layout_at(data_size() + extra_data_size());
 249   two_free_slots = false;
 250   for (;dp < end; dp = MethodData::next_extra(dp)) {
 251     switch(dp->tag()) {
 252     case DataLayout::no_tag:
 253       _saw_free_extra_data = true;  // observed an empty slot (common case)
 254       two_free_slots = (MethodData::next_extra(dp)->tag() == DataLayout::no_tag);
 255       return NULL;
 256     case DataLayout::arg_info_data_tag:
 257       return NULL; // ArgInfoData is at the end of extra data section.
 258     case DataLayout::bit_data_tag:
 259       if (m == NULL && dp->bci() == bci) {
 260         return new ciBitData(dp);
 261       }
 262       break;
 263     case DataLayout::speculative_trap_data_tag: {
 264       ciSpeculativeTrapData* data = new ciSpeculativeTrapData(dp);
 265       // data->method() might be null if the MDO is snapshotted
 266       // concurrently with a trap
 267       if (m != NULL && data->method() == m && dp->bci() == bci) {
 268         return data;


 475     return 0;
 476   assert(arg >= 0 && arg < aid->number_of_args(), "valid argument number");
 477   return aid->arg_modified(arg);
 478 }
 479 
 480 ByteSize ciMethodData::offset_of_slot(ciProfileData* data, ByteSize slot_offset_in_data) {
 481   // Get offset within MethodData* of the data array
 482   ByteSize data_offset = MethodData::data_offset();
 483 
 484   // Get cell offset of the ProfileData within data array
 485   int cell_offset = dp_to_di(data->dp());
 486 
 487   // Add in counter_offset, the # of bytes into the ProfileData of counter or flag
 488   int offset = in_bytes(data_offset) + cell_offset + in_bytes(slot_offset_in_data);
 489 
 490   return in_ByteSize(offset);
 491 }
 492 
 493 ciArgInfoData *ciMethodData::arg_info() const {
 494   // Should be last, have to skip all traps.
 495   DataLayout* dp  = data_layout_at(data_size());
 496   DataLayout* end = data_layout_at(data_size() + extra_data_size());
 497   for (; dp < end; dp = MethodData::next_extra(dp)) {
 498     if (dp->tag() == DataLayout::arg_info_data_tag)
 499       return new ciArgInfoData(dp);
 500   }
 501   return NULL;
 502 }
 503 
 504 
 505 // Implementation of the print method.
 506 void ciMethodData::print_impl(outputStream* st) {
 507   ciMetadata::print_impl(st);
 508 }
 509 
 510 void ciMethodData::dump_replay_data_type_helper(outputStream* out, int round, int& count, ProfileData* pdata, ByteSize offset, ciKlass* k) {
 511   if (k != NULL) {
 512     if (round == 0) {
 513       count++;
 514     } else {
 515       out->print(" %d %s", (int)(dp_to_di(pdata->dp() + in_bytes(offset)) / sizeof(intptr_t)), k->name()->as_quoted_ascii());
 516     }


 518 }
 519 
 520 template<class T> void ciMethodData::dump_replay_data_receiver_type_helper(outputStream* out, int round, int& count, T* vdata) {
 521   for (uint i = 0; i < vdata->row_limit(); i++) {
 522     dump_replay_data_type_helper(out, round, count, vdata, vdata->receiver_offset(i), vdata->receiver(i));
 523   }
 524 }
 525 
 526 template<class T> void ciMethodData::dump_replay_data_call_type_helper(outputStream* out, int round, int& count, T* call_type_data) {
 527   if (call_type_data->has_arguments()) {
 528     for (int i = 0; i < call_type_data->number_of_arguments(); i++) {
 529       dump_replay_data_type_helper(out, round, count, call_type_data, call_type_data->argument_type_offset(i), call_type_data->valid_argument_type(i));
 530     }
 531   }
 532   if (call_type_data->has_return()) {
 533     dump_replay_data_type_helper(out, round, count, call_type_data, call_type_data->return_type_offset(), call_type_data->valid_return_type());
 534   }
 535 }
 536 
 537 void ciMethodData::dump_replay_data_extra_data_helper(outputStream* out, int round, int& count) {
 538   DataLayout* dp  = data_layout_at(data_size());
 539   DataLayout* end = data_layout_at(data_size() + extra_data_size());
 540 
 541   for (;dp < end; dp = MethodData::next_extra(dp)) {
 542     switch(dp->tag()) {
 543     case DataLayout::no_tag:
 544     case DataLayout::arg_info_data_tag:
 545       return;
 546     case DataLayout::bit_data_tag:
 547       break;
 548     case DataLayout::speculative_trap_data_tag: {
 549       ciSpeculativeTrapData* data = new ciSpeculativeTrapData(dp);
 550       ciMethod* m = data->method();
 551       if (m != NULL) {
 552         if (round == 0) {
 553           count++;
 554         } else {
 555           out->print(" %d ", (int)(dp_to_di(((address)dp) + in_bytes(ciSpeculativeTrapData::method_offset())) / sizeof(intptr_t)));
 556           m->dump_name_as_ascii(out);
 557         }
 558       }
 559       break;


 636 }
 637 
 638 #ifndef PRODUCT
 639 void ciMethodData::print() {
 640   print_data_on(tty);
 641 }
 642 
 643 void ciMethodData::print_data_on(outputStream* st) {
 644   ResourceMark rm;
 645   ciParametersTypeData* parameters = parameters_type_data();
 646   if (parameters != NULL) {
 647     parameters->print_data_on(st);
 648   }
 649   ciProfileData* data;
 650   for (data = first_data(); is_valid(data); data = next_data(data)) {
 651     st->print("%d", dp_to_di(data->dp()));
 652     st->fill_to(6);
 653     data->print_data_on(st);
 654   }
 655   st->print_cr("--- Extra data:");
 656   DataLayout* dp  = data_layout_at(data_size());
 657   DataLayout* end = data_layout_at(data_size() + extra_data_size());
 658   for (;; dp = MethodData::next_extra(dp)) {
 659     assert(dp < end, "moved past end of extra data");
 660     switch (dp->tag()) {
 661     case DataLayout::no_tag:
 662       continue;
 663     case DataLayout::bit_data_tag:
 664       data = new BitData(dp);
 665       break;
 666     case DataLayout::arg_info_data_tag:
 667       data = new ciArgInfoData(dp);
 668       dp = end; // ArgInfoData is at the end of extra data section.
 669       break;
 670     case DataLayout::speculative_trap_data_tag:
 671       data = new ciSpeculativeTrapData(dp);
 672       break;
 673     default:
 674       fatal(err_msg("unexpected tag %d", dp->tag()));
 675     }
 676     st->print("%d", dp_to_di(data->dp()));
 677     st->fill_to(6);




  64   Copy::zero_to_words((HeapWord*) &_orig, sizeof(_orig) / sizeof(HeapWord));
  65   _data = NULL;
  66   _data_size = 0;
  67   _extra_data_size = 0;
  68   _current_mileage = 0;
  69   _invocation_counter = 0;
  70   _backedge_counter = 0;
  71   _state = empty_state;
  72   _saw_free_extra_data = false;
  73   // Set an initial hint. Don't use set_hint_di() because
  74   // first_di() may be out of bounds if data_size is 0.
  75   _hint_di = first_di();
  76   // Initialize the escape information (to "don't know.");
  77   _eflags = _arg_local = _arg_stack = _arg_returned = 0;
  78   _parameters = NULL;
  79 }
  80 
  81 void ciMethodData::load_extra_data() {
  82   MethodData* mdo = get_MethodData();
  83 
  84   MutexLocker(mdo->extra_data_lock());
  85 
  86   // speculative trap entries also hold a pointer to a Method so need to be translated
  87   DataLayout* dp_src  = mdo->extra_data_base();
  88   DataLayout* end_src = mdo->args_data_limit();
  89   DataLayout* dp_dst  = extra_data_base();
  90   for (;; dp_src = MethodData::next_extra(dp_src), dp_dst = MethodData::next_extra(dp_dst)) {
  91     assert(dp_src < end_src, "moved past end of extra data");
  92     assert(((intptr_t)dp_dst) - ((intptr_t)extra_data_base()) == ((intptr_t)dp_src) - ((intptr_t)mdo->extra_data_base()), "source and destination don't match");
  93 
  94     // New traps in the MDO may have been added since we copied the
  95     // data (concurrent deoptimizations before we acquired
  96     // extra_data_lock above) or can be removed (a safepoint may occur
  97     // in the translate_from call below) as we translate the copy:
  98     // update the copy as we go.
  99     int tag = dp_src->tag();
 100     if (tag != DataLayout::arg_info_data_tag) {
 101       memcpy(dp_dst, dp_src, ((intptr_t)MethodData::next_extra(dp_src)) - ((intptr_t)dp_src));
 102     }
 103 
 104     switch(tag) {
 105     case DataLayout::speculative_trap_data_tag: {
 106       ciSpeculativeTrapData* data_dst = new ciSpeculativeTrapData(dp_dst);
 107       SpeculativeTrapData* data_src = new SpeculativeTrapData(dp_src);
 108 
 109       data_dst->translate_from(data_src);
 110 
 111 #ifdef ASSERT
 112       SpeculativeTrapData* data_src2 = new SpeculativeTrapData(dp_src);
 113       assert(data_src2->method() == data_src->method() && data_src2->bci() == data_src->bci(), "entries changed while translating");
 114 #endif
 115 
 116       break;
 117     }
 118     case DataLayout::bit_data_tag:
 119       break;
 120     case DataLayout::no_tag:
 121     case DataLayout::arg_info_data_tag:
 122       // An empty slot or ArgInfoData entry marks the end of the trap data
 123       return;
 124     default:
 125       fatal(err_msg("bad tag = %d", dp_dst->tag()));
 126     }
 127   }
 128 }
 129 
 130 void ciMethodData::load_data() {
 131   MethodData* mdo = get_MethodData();
 132   if (mdo == NULL) {
 133     return;
 134   }
 135 


 246   case DataLayout::arg_info_data_tag:
 247     return new ciArgInfoData(data_layout);
 248   case DataLayout::call_type_data_tag:
 249     return new ciCallTypeData(data_layout);
 250   case DataLayout::virtual_call_type_data_tag:
 251     return new ciVirtualCallTypeData(data_layout);
 252   case DataLayout::parameters_type_data_tag:
 253     return new ciParametersTypeData(data_layout);
 254   };
 255 }
 256 
 257 // Iteration over data.
 258 ciProfileData* ciMethodData::next_data(ciProfileData* current) {
 259   int current_index = dp_to_di(current->dp());
 260   int next_index = current_index + current->size_in_bytes();
 261   ciProfileData* next = data_at(next_index);
 262   return next;
 263 }
 264 
 265 ciProfileData* ciMethodData::bci_to_extra_data(int bci, ciMethod* m, bool& two_free_slots) {
 266   DataLayout* dp  = extra_data_base();
 267   DataLayout* end = args_data_limit();
 268   two_free_slots = false;
 269   for (;dp < end; dp = MethodData::next_extra(dp)) {
 270     switch(dp->tag()) {
 271     case DataLayout::no_tag:
 272       _saw_free_extra_data = true;  // observed an empty slot (common case)
 273       two_free_slots = (MethodData::next_extra(dp)->tag() == DataLayout::no_tag);
 274       return NULL;
 275     case DataLayout::arg_info_data_tag:
 276       return NULL; // ArgInfoData is at the end of extra data section.
 277     case DataLayout::bit_data_tag:
 278       if (m == NULL && dp->bci() == bci) {
 279         return new ciBitData(dp);
 280       }
 281       break;
 282     case DataLayout::speculative_trap_data_tag: {
 283       ciSpeculativeTrapData* data = new ciSpeculativeTrapData(dp);
 284       // data->method() might be null if the MDO is snapshotted
 285       // concurrently with a trap
 286       if (m != NULL && data->method() == m && dp->bci() == bci) {
 287         return data;


 494     return 0;
 495   assert(arg >= 0 && arg < aid->number_of_args(), "valid argument number");
 496   return aid->arg_modified(arg);
 497 }
 498 
 499 ByteSize ciMethodData::offset_of_slot(ciProfileData* data, ByteSize slot_offset_in_data) {
 500   // Get offset within MethodData* of the data array
 501   ByteSize data_offset = MethodData::data_offset();
 502 
 503   // Get cell offset of the ProfileData within data array
 504   int cell_offset = dp_to_di(data->dp());
 505 
 506   // Add in counter_offset, the # of bytes into the ProfileData of counter or flag
 507   int offset = in_bytes(data_offset) + cell_offset + in_bytes(slot_offset_in_data);
 508 
 509   return in_ByteSize(offset);
 510 }
 511 
 512 ciArgInfoData *ciMethodData::arg_info() const {
 513   // Should be last, have to skip all traps.
 514   DataLayout* dp  = extra_data_base();
 515   DataLayout* end = args_data_limit();
 516   for (; dp < end; dp = MethodData::next_extra(dp)) {
 517     if (dp->tag() == DataLayout::arg_info_data_tag)
 518       return new ciArgInfoData(dp);
 519   }
 520   return NULL;
 521 }
 522 
 523 
 524 // Implementation of the print method.
 525 void ciMethodData::print_impl(outputStream* st) {
 526   ciMetadata::print_impl(st);
 527 }
 528 
 529 void ciMethodData::dump_replay_data_type_helper(outputStream* out, int round, int& count, ProfileData* pdata, ByteSize offset, ciKlass* k) {
 530   if (k != NULL) {
 531     if (round == 0) {
 532       count++;
 533     } else {
 534       out->print(" %d %s", (int)(dp_to_di(pdata->dp() + in_bytes(offset)) / sizeof(intptr_t)), k->name()->as_quoted_ascii());
 535     }


 537 }
 538 
 539 template<class T> void ciMethodData::dump_replay_data_receiver_type_helper(outputStream* out, int round, int& count, T* vdata) {
 540   for (uint i = 0; i < vdata->row_limit(); i++) {
 541     dump_replay_data_type_helper(out, round, count, vdata, vdata->receiver_offset(i), vdata->receiver(i));
 542   }
 543 }
 544 
 545 template<class T> void ciMethodData::dump_replay_data_call_type_helper(outputStream* out, int round, int& count, T* call_type_data) {
 546   if (call_type_data->has_arguments()) {
 547     for (int i = 0; i < call_type_data->number_of_arguments(); i++) {
 548       dump_replay_data_type_helper(out, round, count, call_type_data, call_type_data->argument_type_offset(i), call_type_data->valid_argument_type(i));
 549     }
 550   }
 551   if (call_type_data->has_return()) {
 552     dump_replay_data_type_helper(out, round, count, call_type_data, call_type_data->return_type_offset(), call_type_data->valid_return_type());
 553   }
 554 }
 555 
 556 void ciMethodData::dump_replay_data_extra_data_helper(outputStream* out, int round, int& count) {
 557   DataLayout* dp  = extra_data_base();
 558   DataLayout* end = args_data_limit();
 559 
 560   for (;dp < end; dp = MethodData::next_extra(dp)) {
 561     switch(dp->tag()) {
 562     case DataLayout::no_tag:
 563     case DataLayout::arg_info_data_tag:
 564       return;
 565     case DataLayout::bit_data_tag:
 566       break;
 567     case DataLayout::speculative_trap_data_tag: {
 568       ciSpeculativeTrapData* data = new ciSpeculativeTrapData(dp);
 569       ciMethod* m = data->method();
 570       if (m != NULL) {
 571         if (round == 0) {
 572           count++;
 573         } else {
 574           out->print(" %d ", (int)(dp_to_di(((address)dp) + in_bytes(ciSpeculativeTrapData::method_offset())) / sizeof(intptr_t)));
 575           m->dump_name_as_ascii(out);
 576         }
 577       }
 578       break;


 655 }
 656 
 657 #ifndef PRODUCT
 658 void ciMethodData::print() {
 659   print_data_on(tty);
 660 }
 661 
 662 void ciMethodData::print_data_on(outputStream* st) {
 663   ResourceMark rm;
 664   ciParametersTypeData* parameters = parameters_type_data();
 665   if (parameters != NULL) {
 666     parameters->print_data_on(st);
 667   }
 668   ciProfileData* data;
 669   for (data = first_data(); is_valid(data); data = next_data(data)) {
 670     st->print("%d", dp_to_di(data->dp()));
 671     st->fill_to(6);
 672     data->print_data_on(st);
 673   }
 674   st->print_cr("--- Extra data:");
 675   DataLayout* dp  = extra_data_base();
 676   DataLayout* end = args_data_limit();
 677   for (;; dp = MethodData::next_extra(dp)) {
 678     assert(dp < end, "moved past end of extra data");
 679     switch (dp->tag()) {
 680     case DataLayout::no_tag:
 681       continue;
 682     case DataLayout::bit_data_tag:
 683       data = new BitData(dp);
 684       break;
 685     case DataLayout::arg_info_data_tag:
 686       data = new ciArgInfoData(dp);
 687       dp = end; // ArgInfoData is at the end of extra data section.
 688       break;
 689     case DataLayout::speculative_trap_data_tag:
 690       data = new ciSpeculativeTrapData(dp);
 691       break;
 692     default:
 693       fatal(err_msg("unexpected tag %d", dp->tag()));
 694     }
 695     st->print("%d", dp_to_di(data->dp()));
 696     st->fill_to(6);


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