comparison src/share/vm/ci/ciMethodData.cpp @ 17728:b8413a9cbb84

8031752: Failed speculative optimizations should be reattempted when root of compilation is different Summary: support for speculative traps that keep track of the root of the compilation in which a trap occurs. Reviewed-by: kvn, twisti
author roland
date Tue, 25 Feb 2014 18:16:24 +0100
parents 55fb97c4c58d
children 53ed0f89f44e 4ca6dc0799b6
comparison
equal deleted inserted replaced
17727:cfd4aac53239 17728:b8413a9cbb84
76 // Initialize the escape information (to "don't know."); 76 // Initialize the escape information (to "don't know.");
77 _eflags = _arg_local = _arg_stack = _arg_returned = 0; 77 _eflags = _arg_local = _arg_stack = _arg_returned = 0;
78 _parameters = NULL; 78 _parameters = NULL;
79 } 79 }
80 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 assert(dp_src->tag() == dp_dst->tag(), err_msg("should be same tags %d != %d", dp_src->tag(), dp_dst->tag()));
91 switch(dp_src->tag()) {
92 case DataLayout::speculative_trap_data_tag: {
93 ciSpeculativeTrapData* data_dst = new ciSpeculativeTrapData(dp_dst);
94 SpeculativeTrapData* data_src = new SpeculativeTrapData(dp_src);
95 data_dst->translate_from(data_src);
96 break;
97 }
98 case DataLayout::bit_data_tag:
99 break;
100 case DataLayout::no_tag:
101 case DataLayout::arg_info_data_tag:
102 // An empty slot or ArgInfoData entry marks the end of the trap data
103 return;
104 default:
105 fatal(err_msg("bad tag = %d", dp_src->tag()));
106 }
107 }
108 }
109
81 void ciMethodData::load_data() { 110 void ciMethodData::load_data() {
82 MethodData* mdo = get_MethodData(); 111 MethodData* mdo = get_MethodData();
83 if (mdo == NULL) { 112 if (mdo == NULL) {
84 return; 113 return;
85 } 114 }
114 _parameters = data_layout_at(mdo->parameters_type_data_di()); 143 _parameters = data_layout_at(mdo->parameters_type_data_di());
115 ciParametersTypeData* parameters = new ciParametersTypeData(_parameters); 144 ciParametersTypeData* parameters = new ciParametersTypeData(_parameters);
116 parameters->translate_from(mdo->parameters_type_data()); 145 parameters->translate_from(mdo->parameters_type_data());
117 } 146 }
118 147
148 load_extra_data();
149
119 // Note: Extra data are all BitData, and do not need translation. 150 // Note: Extra data are all BitData, and do not need translation.
120 _current_mileage = MethodData::mileage_of(mdo->method()); 151 _current_mileage = MethodData::mileage_of(mdo->method());
121 _invocation_counter = mdo->invocation_count(); 152 _invocation_counter = mdo->invocation_count();
122 _backedge_counter = mdo->backedge_count(); 153 _backedge_counter = mdo->backedge_count();
123 _state = mdo->is_mature()? mature_state: immature_state; 154 _state = mdo->is_mature()? mature_state: immature_state;
152 } 183 }
153 184
154 void ciReturnTypeEntry::translate_type_data_from(const ReturnTypeEntry* ret) { 185 void ciReturnTypeEntry::translate_type_data_from(const ReturnTypeEntry* ret) {
155 intptr_t k = ret->type(); 186 intptr_t k = ret->type();
156 set_type(translate_klass(k)); 187 set_type(translate_klass(k));
188 }
189
190 void ciSpeculativeTrapData::translate_from(const ProfileData* data) {
191 Method* m = data->as_SpeculativeTrapData()->method();
192 ciMethod* ci_m = CURRENT_ENV->get_method(m);
193 set_method(ci_m);
157 } 194 }
158 195
159 // Get the data at an arbitrary (sort of) data index. 196 // Get the data at an arbitrary (sort of) data index.
160 ciProfileData* ciMethodData::data_at(int data_index) { 197 ciProfileData* ciMethodData::data_at(int data_index) {
161 if (out_of_bounds(data_index)) { 198 if (out_of_bounds(data_index)) {
201 int next_index = current_index + current->size_in_bytes(); 238 int next_index = current_index + current->size_in_bytes();
202 ciProfileData* next = data_at(next_index); 239 ciProfileData* next = data_at(next_index);
203 return next; 240 return next;
204 } 241 }
205 242
206 // Translate a bci to its corresponding data, or NULL. 243 ciProfileData* ciMethodData::bci_to_extra_data(int bci, ciMethod* m, bool& two_free_slots) {
207 ciProfileData* ciMethodData::bci_to_data(int bci) {
208 ciProfileData* data = data_before(bci);
209 for ( ; is_valid(data); data = next_data(data)) {
210 if (data->bci() == bci) {
211 set_hint_di(dp_to_di(data->dp()));
212 return data;
213 } else if (data->bci() > bci) {
214 break;
215 }
216 }
217 // bci_to_extra_data(bci) ... 244 // bci_to_extra_data(bci) ...
218 DataLayout* dp = data_layout_at(data_size()); 245 DataLayout* dp = data_layout_at(data_size());
219 DataLayout* end = data_layout_at(data_size() + extra_data_size()); 246 DataLayout* end = data_layout_at(data_size() + extra_data_size());
220 for (; dp < end; dp = MethodData::next_extra(dp)) { 247 two_free_slots = false;
221 if (dp->tag() == DataLayout::no_tag) { 248 for (;dp < end; dp = MethodData::next_extra(dp)) {
249 switch(dp->tag()) {
250 case DataLayout::no_tag:
222 _saw_free_extra_data = true; // observed an empty slot (common case) 251 _saw_free_extra_data = true; // observed an empty slot (common case)
252 two_free_slots = (MethodData::next_extra(dp)->tag() == DataLayout::no_tag);
223 return NULL; 253 return NULL;
224 } 254 case DataLayout::arg_info_data_tag:
225 if (dp->tag() == DataLayout::arg_info_data_tag) { 255 return NULL; // ArgInfoData is at the end of extra data section.
226 break; // ArgInfoData is at the end of extra data section. 256 case DataLayout::bit_data_tag:
227 } 257 if (m == NULL && dp->bci() == bci) {
228 if (dp->bci() == bci) { 258 return new ciBitData(dp);
229 assert(dp->tag() == DataLayout::bit_data_tag, "sane"); 259 }
230 return new ciBitData(dp); 260 break;
231 } 261 case DataLayout::speculative_trap_data_tag: {
262 ciSpeculativeTrapData* data = new ciSpeculativeTrapData(dp);
263 // data->method() might be null if the MDO is snapshotted
264 // concurrently with a trap
265 if (m != NULL && data->method() == m && dp->bci() == bci) {
266 return data;
267 }
268 break;
269 }
270 default:
271 fatal(err_msg("bad tag = %d", dp->tag()));
272 }
273 }
274 return NULL;
275 }
276
277 // Translate a bci to its corresponding data, or NULL.
278 ciProfileData* ciMethodData::bci_to_data(int bci, ciMethod* m) {
279 // If m is not NULL we look for a SpeculativeTrapData entry
280 if (m == NULL) {
281 ciProfileData* data = data_before(bci);
282 for ( ; is_valid(data); data = next_data(data)) {
283 if (data->bci() == bci) {
284 set_hint_di(dp_to_di(data->dp()));
285 return data;
286 } else if (data->bci() > bci) {
287 break;
288 }
289 }
290 }
291 bool two_free_slots = false;
292 ciProfileData* result = bci_to_extra_data(bci, m, two_free_slots);
293 if (result != NULL) {
294 return result;
295 }
296 if (m != NULL && !two_free_slots) {
297 // We were looking for a SpeculativeTrapData entry we didn't
298 // find. Room is not available for more SpeculativeTrapData
299 // entries, look in the non SpeculativeTrapData entries.
300 return bci_to_data(bci, NULL);
232 } 301 }
233 return NULL; 302 return NULL;
234 } 303 }
235 304
236 // Conservatively decode the trap_state of a ciProfileData. 305 // Conservatively decode the trap_state of a ciProfileData.
523 data->print_data_on(st); 592 data->print_data_on(st);
524 } 593 }
525 st->print_cr("--- Extra data:"); 594 st->print_cr("--- Extra data:");
526 DataLayout* dp = data_layout_at(data_size()); 595 DataLayout* dp = data_layout_at(data_size());
527 DataLayout* end = data_layout_at(data_size() + extra_data_size()); 596 DataLayout* end = data_layout_at(data_size() + extra_data_size());
528 for (; dp < end; dp = MethodData::next_extra(dp)) { 597 for (;; dp = MethodData::next_extra(dp)) {
529 if (dp->tag() == DataLayout::no_tag) continue; 598 assert(dp < end, "moved past end of extra data");
530 if (dp->tag() == DataLayout::bit_data_tag) { 599 switch (dp->tag()) {
600 case DataLayout::no_tag:
601 continue;
602 case DataLayout::bit_data_tag:
531 data = new BitData(dp); 603 data = new BitData(dp);
532 } else { 604 break;
533 assert(dp->tag() == DataLayout::arg_info_data_tag, "must be BitData or ArgInfo"); 605 case DataLayout::arg_info_data_tag:
534 data = new ciArgInfoData(dp); 606 data = new ciArgInfoData(dp);
535 dp = end; // ArgInfoData is at the end of extra data section. 607 dp = end; // ArgInfoData is at the end of extra data section.
608 break;
609 default:
610 fatal(err_msg("unexpected tag %d", dp->tag()));
536 } 611 }
537 st->print("%d", dp_to_di(data->dp())); 612 st->print("%d", dp_to_di(data->dp()));
538 st->fill_to(6); 613 st->fill_to(6);
539 data->print_data_on(st); 614 data->print_data_on(st);
615 if (dp >= end) return;
540 } 616 }
541 } 617 }
542 618
543 void ciTypeEntries::print_ciklass(outputStream* st, intptr_t k) { 619 void ciTypeEntries::print_ciklass(outputStream* st, intptr_t k) {
544 if (TypeEntries::is_type_none(k)) { 620 if (TypeEntries::is_type_none(k)) {
567 st->print("ret "); 643 st->print("ret ");
568 print_ciklass(st, type()); 644 print_ciklass(st, type());
569 st->cr(); 645 st->cr();
570 } 646 }
571 647
572 void ciCallTypeData::print_data_on(outputStream* st) const { 648 void ciCallTypeData::print_data_on(outputStream* st, const char* extra) const {
573 print_shared(st, "ciCallTypeData"); 649 print_shared(st, "ciCallTypeData", extra);
574 if (has_arguments()) { 650 if (has_arguments()) {
575 tab(st, true); 651 tab(st, true);
576 st->print("argument types"); 652 st->print("argument types");
577 args()->print_data_on(st); 653 args()->print_data_on(st);
578 } 654 }
597 st->print_cr("(%u)", receiver_count(row)); 673 st->print_cr("(%u)", receiver_count(row));
598 } 674 }
599 } 675 }
600 } 676 }
601 677
602 void ciReceiverTypeData::print_data_on(outputStream* st) const { 678 void ciReceiverTypeData::print_data_on(outputStream* st, const char* extra) const {
603 print_shared(st, "ciReceiverTypeData"); 679 print_shared(st, "ciReceiverTypeData", extra);
604 print_receiver_data_on(st); 680 print_receiver_data_on(st);
605 } 681 }
606 682
607 void ciVirtualCallData::print_data_on(outputStream* st) const { 683 void ciVirtualCallData::print_data_on(outputStream* st, const char* extra) const {
608 print_shared(st, "ciVirtualCallData"); 684 print_shared(st, "ciVirtualCallData", extra);
609 rtd_super()->print_receiver_data_on(st); 685 rtd_super()->print_receiver_data_on(st);
610 } 686 }
611 687
612 void ciVirtualCallTypeData::print_data_on(outputStream* st) const { 688 void ciVirtualCallTypeData::print_data_on(outputStream* st, const char* extra) const {
613 print_shared(st, "ciVirtualCallTypeData"); 689 print_shared(st, "ciVirtualCallTypeData", extra);
614 rtd_super()->print_receiver_data_on(st); 690 rtd_super()->print_receiver_data_on(st);
615 if (has_arguments()) { 691 if (has_arguments()) {
616 tab(st, true); 692 tab(st, true);
617 st->print("argument types"); 693 st->print("argument types");
618 args()->print_data_on(st); 694 args()->print_data_on(st);
622 st->print("return type"); 698 st->print("return type");
623 ret()->print_data_on(st); 699 ret()->print_data_on(st);
624 } 700 }
625 } 701 }
626 702
627 void ciParametersTypeData::print_data_on(outputStream* st) const { 703 void ciParametersTypeData::print_data_on(outputStream* st, const char* extra) const {
628 st->print_cr("Parametertypes"); 704 st->print_cr("ciParametersTypeData");
629 parameters()->print_data_on(st); 705 parameters()->print_data_on(st);
630 } 706 }
707
708 void ciSpeculativeTrapData::print_data_on(outputStream* st, const char* extra) const {
709 st->print_cr("ciSpeculativeTrapData");
710 tab(st);
711 method()->print_short_name(st);
712 st->cr();
713 }
631 #endif 714 #endif