Print this page
rev 6907 : 8056071: compiler/whitebox/IsMethodCompilableTest.java fails with 'method() is not compilable after 3 iterations'
Summary: Always use MDO if valid and always compile trivial methods with C1 if available.
Reviewed-by: kvn, iveresov
Split |
Split |
Close |
Expand all |
Collapse all |
--- old/hotspot/src/share/vm/oops/methodData.cpp
+++ new/hotspot/src/share/vm/oops/methodData.cpp
1 1 /*
2 2 * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 4 *
5 5 * This code is free software; you can redistribute it and/or modify it
6 6 * under the terms of the GNU General Public License version 2 only, as
7 7 * published by the Free Software Foundation.
8 8 *
9 9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 12 * version 2 for more details (a copy is included in the LICENSE file that
13 13 * accompanied this code).
14 14 *
15 15 * You should have received a copy of the GNU General Public License version
16 16 * 2 along with this work; if not, write to the Free Software Foundation,
17 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 18 *
19 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 20 * or visit www.oracle.com if you need additional information or have any
21 21 * questions.
22 22 *
23 23 */
24 24
25 25 #include "precompiled.hpp"
26 26 #include "classfile/systemDictionary.hpp"
27 27 #include "compiler/compilerOracle.hpp"
28 28 #include "interpreter/bytecode.hpp"
29 29 #include "interpreter/bytecodeStream.hpp"
30 30 #include "interpreter/linkResolver.hpp"
31 31 #include "memory/heapInspection.hpp"
32 32 #include "oops/methodData.hpp"
33 33 #include "prims/jvmtiRedefineClasses.hpp"
34 34 #include "runtime/compilationPolicy.hpp"
35 35 #include "runtime/deoptimization.hpp"
36 36 #include "runtime/handles.inline.hpp"
37 37 #include "runtime/orderAccess.inline.hpp"
38 38
39 39 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
40 40
41 41 // ==================================================================
42 42 // DataLayout
43 43 //
44 44 // Overlay for generic profiling data.
45 45
46 46 // Some types of data layouts need a length field.
47 47 bool DataLayout::needs_array_len(u1 tag) {
48 48 return (tag == multi_branch_data_tag) || (tag == arg_info_data_tag) || (tag == parameters_type_data_tag);
49 49 }
50 50
51 51 // Perform generic initialization of the data. More specific
52 52 // initialization occurs in overrides of ProfileData::post_initialize.
53 53 void DataLayout::initialize(u1 tag, u2 bci, int cell_count) {
54 54 _header._bits = (intptr_t)0;
55 55 _header._struct._tag = tag;
56 56 _header._struct._bci = bci;
57 57 for (int i = 0; i < cell_count; i++) {
58 58 set_cell_at(i, (intptr_t)0);
59 59 }
60 60 if (needs_array_len(tag)) {
61 61 set_cell_at(ArrayData::array_len_off_set, cell_count - 1); // -1 for header.
62 62 }
63 63 if (tag == call_type_data_tag) {
64 64 CallTypeData::initialize(this, cell_count);
65 65 } else if (tag == virtual_call_type_data_tag) {
66 66 VirtualCallTypeData::initialize(this, cell_count);
67 67 }
68 68 }
69 69
70 70 void DataLayout::clean_weak_klass_links(BoolObjectClosure* cl) {
71 71 ResourceMark m;
72 72 data_in()->clean_weak_klass_links(cl);
73 73 }
74 74
75 75
76 76 // ==================================================================
77 77 // ProfileData
78 78 //
79 79 // A ProfileData object is created to refer to a section of profiling
80 80 // data in a structured way.
81 81
82 82 // Constructor for invalid ProfileData.
83 83 ProfileData::ProfileData() {
84 84 _data = NULL;
85 85 }
86 86
87 87 char* ProfileData::print_data_on_helper(const MethodData* md) const {
88 88 DataLayout* dp = md->extra_data_base();
89 89 DataLayout* end = md->extra_data_limit();
90 90 stringStream ss;
91 91 for (;; dp = MethodData::next_extra(dp)) {
92 92 assert(dp < end, "moved past end of extra data");
93 93 switch(dp->tag()) {
94 94 case DataLayout::speculative_trap_data_tag:
95 95 if (dp->bci() == bci()) {
96 96 SpeculativeTrapData* data = new SpeculativeTrapData(dp);
97 97 int trap = data->trap_state();
98 98 char buf[100];
99 99 ss.print("trap/");
100 100 data->method()->print_short_name(&ss);
101 101 ss.print("(%s) ", Deoptimization::format_trap_state(buf, sizeof(buf), trap));
102 102 }
103 103 break;
104 104 case DataLayout::bit_data_tag:
105 105 break;
106 106 case DataLayout::no_tag:
107 107 case DataLayout::arg_info_data_tag:
108 108 return ss.as_string();
109 109 break;
110 110 default:
111 111 fatal(err_msg("unexpected tag %d", dp->tag()));
112 112 }
113 113 }
114 114 return NULL;
115 115 }
116 116
117 117 void ProfileData::print_data_on(outputStream* st, const MethodData* md) const {
118 118 print_data_on(st, print_data_on_helper(md));
119 119 }
120 120
121 121 #ifndef PRODUCT
122 122 void ProfileData::print_shared(outputStream* st, const char* name, const char* extra) const {
123 123 st->print("bci: %d", bci());
124 124 st->fill_to(tab_width_one);
125 125 st->print("%s", name);
126 126 tab(st);
127 127 int trap = trap_state();
128 128 if (trap != 0) {
129 129 char buf[100];
130 130 st->print("trap(%s) ", Deoptimization::format_trap_state(buf, sizeof(buf), trap));
131 131 }
132 132 if (extra != NULL) {
133 133 st->print("%s", extra);
134 134 }
135 135 int flags = data()->flags();
136 136 if (flags != 0) {
137 137 st->print("flags(%d) ", flags);
138 138 }
139 139 }
140 140
141 141 void ProfileData::tab(outputStream* st, bool first) const {
142 142 st->fill_to(first ? tab_width_one : tab_width_two);
143 143 }
144 144 #endif // !PRODUCT
145 145
146 146 // ==================================================================
147 147 // BitData
148 148 //
149 149 // A BitData corresponds to a one-bit flag. This is used to indicate
150 150 // whether a checkcast bytecode has seen a null value.
151 151
152 152
153 153 #ifndef PRODUCT
154 154 void BitData::print_data_on(outputStream* st, const char* extra) const {
155 155 print_shared(st, "BitData", extra);
156 156 }
157 157 #endif // !PRODUCT
158 158
159 159 // ==================================================================
160 160 // CounterData
161 161 //
162 162 // A CounterData corresponds to a simple counter.
163 163
164 164 #ifndef PRODUCT
165 165 void CounterData::print_data_on(outputStream* st, const char* extra) const {
166 166 print_shared(st, "CounterData", extra);
167 167 st->print_cr("count(%u)", count());
168 168 }
169 169 #endif // !PRODUCT
170 170
171 171 // ==================================================================
172 172 // JumpData
173 173 //
174 174 // A JumpData is used to access profiling information for a direct
175 175 // branch. It is a counter, used for counting the number of branches,
176 176 // plus a data displacement, used for realigning the data pointer to
177 177 // the corresponding target bci.
178 178
179 179 void JumpData::post_initialize(BytecodeStream* stream, MethodData* mdo) {
180 180 assert(stream->bci() == bci(), "wrong pos");
181 181 int target;
182 182 Bytecodes::Code c = stream->code();
183 183 if (c == Bytecodes::_goto_w || c == Bytecodes::_jsr_w) {
184 184 target = stream->dest_w();
185 185 } else {
186 186 target = stream->dest();
187 187 }
188 188 int my_di = mdo->dp_to_di(dp());
189 189 int target_di = mdo->bci_to_di(target);
190 190 int offset = target_di - my_di;
191 191 set_displacement(offset);
192 192 }
193 193
194 194 #ifndef PRODUCT
195 195 void JumpData::print_data_on(outputStream* st, const char* extra) const {
196 196 print_shared(st, "JumpData", extra);
197 197 st->print_cr("taken(%u) displacement(%d)", taken(), displacement());
198 198 }
199 199 #endif // !PRODUCT
200 200
201 201 int TypeStackSlotEntries::compute_cell_count(Symbol* signature, bool include_receiver, int max) {
202 202 // Parameter profiling include the receiver
203 203 int args_count = include_receiver ? 1 : 0;
204 204 ResourceMark rm;
205 205 SignatureStream ss(signature);
206 206 args_count += ss.reference_parameter_count();
207 207 args_count = MIN2(args_count, max);
208 208 return args_count * per_arg_cell_count;
209 209 }
210 210
211 211 int TypeEntriesAtCall::compute_cell_count(BytecodeStream* stream) {
212 212 assert(Bytecodes::is_invoke(stream->code()), "should be invoke");
213 213 assert(TypeStackSlotEntries::per_arg_count() > ReturnTypeEntry::static_cell_count(), "code to test for arguments/results broken");
214 214 Bytecode_invoke inv(stream->method(), stream->bci());
215 215 int args_cell = 0;
216 216 if (arguments_profiling_enabled()) {
217 217 args_cell = TypeStackSlotEntries::compute_cell_count(inv.signature(), false, TypeProfileArgsLimit);
218 218 }
219 219 int ret_cell = 0;
220 220 if (return_profiling_enabled() && (inv.result_type() == T_OBJECT || inv.result_type() == T_ARRAY)) {
221 221 ret_cell = ReturnTypeEntry::static_cell_count();
222 222 }
223 223 int header_cell = 0;
224 224 if (args_cell + ret_cell > 0) {
225 225 header_cell = header_cell_count();
226 226 }
227 227
228 228 return header_cell + args_cell + ret_cell;
229 229 }
230 230
231 231 class ArgumentOffsetComputer : public SignatureInfo {
232 232 private:
233 233 int _max;
234 234 GrowableArray<int> _offsets;
235 235
236 236 void set(int size, BasicType type) { _size += size; }
237 237 void do_object(int begin, int end) {
238 238 if (_offsets.length() < _max) {
239 239 _offsets.push(_size);
240 240 }
241 241 SignatureInfo::do_object(begin, end);
242 242 }
243 243 void do_array (int begin, int end) {
244 244 if (_offsets.length() < _max) {
245 245 _offsets.push(_size);
246 246 }
247 247 SignatureInfo::do_array(begin, end);
248 248 }
249 249
250 250 public:
251 251 ArgumentOffsetComputer(Symbol* signature, int max)
252 252 : SignatureInfo(signature), _max(max), _offsets(Thread::current(), max) {
253 253 }
254 254
255 255 int total() { lazy_iterate_parameters(); return _size; }
256 256
257 257 int off_at(int i) const { return _offsets.at(i); }
258 258 };
259 259
260 260 void TypeStackSlotEntries::post_initialize(Symbol* signature, bool has_receiver, bool include_receiver) {
261 261 ResourceMark rm;
262 262 int start = 0;
263 263 // Parameter profiling include the receiver
264 264 if (include_receiver && has_receiver) {
265 265 set_stack_slot(0, 0);
266 266 set_type(0, type_none());
267 267 start += 1;
268 268 }
269 269 ArgumentOffsetComputer aos(signature, _number_of_entries-start);
270 270 aos.total();
271 271 for (int i = start; i < _number_of_entries; i++) {
272 272 set_stack_slot(i, aos.off_at(i-start) + (has_receiver ? 1 : 0));
273 273 set_type(i, type_none());
274 274 }
275 275 }
276 276
277 277 void CallTypeData::post_initialize(BytecodeStream* stream, MethodData* mdo) {
278 278 assert(Bytecodes::is_invoke(stream->code()), "should be invoke");
279 279 Bytecode_invoke inv(stream->method(), stream->bci());
280 280
281 281 SignatureStream ss(inv.signature());
282 282 if (has_arguments()) {
283 283 #ifdef ASSERT
284 284 ResourceMark rm;
285 285 int count = MIN2(ss.reference_parameter_count(), (int)TypeProfileArgsLimit);
286 286 assert(count > 0, "room for args type but none found?");
287 287 check_number_of_arguments(count);
288 288 #endif
289 289 _args.post_initialize(inv.signature(), inv.has_receiver(), false);
290 290 }
291 291
292 292 if (has_return()) {
293 293 assert(inv.result_type() == T_OBJECT || inv.result_type() == T_ARRAY, "room for a ret type but doesn't return obj?");
294 294 _ret.post_initialize();
295 295 }
296 296 }
297 297
298 298 void VirtualCallTypeData::post_initialize(BytecodeStream* stream, MethodData* mdo) {
299 299 assert(Bytecodes::is_invoke(stream->code()), "should be invoke");
300 300 Bytecode_invoke inv(stream->method(), stream->bci());
301 301
302 302 if (has_arguments()) {
303 303 #ifdef ASSERT
304 304 ResourceMark rm;
305 305 SignatureStream ss(inv.signature());
306 306 int count = MIN2(ss.reference_parameter_count(), (int)TypeProfileArgsLimit);
307 307 assert(count > 0, "room for args type but none found?");
308 308 check_number_of_arguments(count);
309 309 #endif
310 310 _args.post_initialize(inv.signature(), inv.has_receiver(), false);
311 311 }
312 312
313 313 if (has_return()) {
314 314 assert(inv.result_type() == T_OBJECT || inv.result_type() == T_ARRAY, "room for a ret type but doesn't return obj?");
315 315 _ret.post_initialize();
316 316 }
317 317 }
318 318
319 319 bool TypeEntries::is_loader_alive(BoolObjectClosure* is_alive_cl, intptr_t p) {
320 320 Klass* k = (Klass*)klass_part(p);
321 321 return k != NULL && k->is_loader_alive(is_alive_cl);
322 322 }
323 323
324 324 void TypeStackSlotEntries::clean_weak_klass_links(BoolObjectClosure* is_alive_cl) {
325 325 for (int i = 0; i < _number_of_entries; i++) {
326 326 intptr_t p = type(i);
327 327 if (!is_loader_alive(is_alive_cl, p)) {
328 328 set_type(i, with_status((Klass*)NULL, p));
329 329 }
330 330 }
331 331 }
332 332
333 333 void ReturnTypeEntry::clean_weak_klass_links(BoolObjectClosure* is_alive_cl) {
334 334 intptr_t p = type();
335 335 if (!is_loader_alive(is_alive_cl, p)) {
336 336 set_type(with_status((Klass*)NULL, p));
337 337 }
338 338 }
339 339
340 340 bool TypeEntriesAtCall::return_profiling_enabled() {
341 341 return MethodData::profile_return();
342 342 }
343 343
344 344 bool TypeEntriesAtCall::arguments_profiling_enabled() {
345 345 return MethodData::profile_arguments();
346 346 }
347 347
348 348 #ifndef PRODUCT
349 349 void TypeEntries::print_klass(outputStream* st, intptr_t k) {
350 350 if (is_type_none(k)) {
351 351 st->print("none");
352 352 } else if (is_type_unknown(k)) {
353 353 st->print("unknown");
354 354 } else {
355 355 valid_klass(k)->print_value_on(st);
356 356 }
357 357 if (was_null_seen(k)) {
358 358 st->print(" (null seen)");
359 359 }
360 360 }
361 361
362 362 void TypeStackSlotEntries::print_data_on(outputStream* st) const {
363 363 for (int i = 0; i < _number_of_entries; i++) {
364 364 _pd->tab(st);
365 365 st->print("%d: stack(%u) ", i, stack_slot(i));
366 366 print_klass(st, type(i));
367 367 st->cr();
368 368 }
369 369 }
370 370
371 371 void ReturnTypeEntry::print_data_on(outputStream* st) const {
372 372 _pd->tab(st);
373 373 print_klass(st, type());
374 374 st->cr();
375 375 }
376 376
377 377 void CallTypeData::print_data_on(outputStream* st, const char* extra) const {
378 378 CounterData::print_data_on(st, extra);
379 379 if (has_arguments()) {
380 380 tab(st, true);
381 381 st->print("argument types");
382 382 _args.print_data_on(st);
383 383 }
384 384 if (has_return()) {
385 385 tab(st, true);
386 386 st->print("return type");
387 387 _ret.print_data_on(st);
388 388 }
389 389 }
390 390
391 391 void VirtualCallTypeData::print_data_on(outputStream* st, const char* extra) const {
392 392 VirtualCallData::print_data_on(st, extra);
393 393 if (has_arguments()) {
394 394 tab(st, true);
395 395 st->print("argument types");
396 396 _args.print_data_on(st);
397 397 }
398 398 if (has_return()) {
399 399 tab(st, true);
400 400 st->print("return type");
401 401 _ret.print_data_on(st);
402 402 }
403 403 }
404 404 #endif
405 405
406 406 // ==================================================================
407 407 // ReceiverTypeData
408 408 //
409 409 // A ReceiverTypeData is used to access profiling information about a
410 410 // dynamic type check. It consists of a counter which counts the total times
411 411 // that the check is reached, and a series of (Klass*, count) pairs
412 412 // which are used to store a type profile for the receiver of the check.
413 413
414 414 void ReceiverTypeData::clean_weak_klass_links(BoolObjectClosure* is_alive_cl) {
415 415 for (uint row = 0; row < row_limit(); row++) {
416 416 Klass* p = receiver(row);
417 417 if (p != NULL && !p->is_loader_alive(is_alive_cl)) {
418 418 clear_row(row);
419 419 }
420 420 }
421 421 }
422 422
423 423 #ifndef PRODUCT
424 424 void ReceiverTypeData::print_receiver_data_on(outputStream* st) const {
425 425 uint row;
426 426 int entries = 0;
427 427 for (row = 0; row < row_limit(); row++) {
428 428 if (receiver(row) != NULL) entries++;
429 429 }
430 430 st->print_cr("count(%u) entries(%u)", count(), entries);
431 431 int total = count();
432 432 for (row = 0; row < row_limit(); row++) {
433 433 if (receiver(row) != NULL) {
434 434 total += receiver_count(row);
435 435 }
436 436 }
437 437 for (row = 0; row < row_limit(); row++) {
438 438 if (receiver(row) != NULL) {
439 439 tab(st);
440 440 receiver(row)->print_value_on(st);
441 441 st->print_cr("(%u %4.2f)", receiver_count(row), (float) receiver_count(row) / (float) total);
442 442 }
443 443 }
444 444 }
445 445 void ReceiverTypeData::print_data_on(outputStream* st, const char* extra) const {
446 446 print_shared(st, "ReceiverTypeData", extra);
447 447 print_receiver_data_on(st);
448 448 }
449 449 void VirtualCallData::print_data_on(outputStream* st, const char* extra) const {
450 450 print_shared(st, "VirtualCallData", extra);
451 451 print_receiver_data_on(st);
452 452 }
453 453 #endif // !PRODUCT
454 454
455 455 // ==================================================================
456 456 // RetData
457 457 //
458 458 // A RetData is used to access profiling information for a ret bytecode.
459 459 // It is composed of a count of the number of times that the ret has
460 460 // been executed, followed by a series of triples of the form
461 461 // (bci, count, di) which count the number of times that some bci was the
462 462 // target of the ret and cache a corresponding displacement.
463 463
464 464 void RetData::post_initialize(BytecodeStream* stream, MethodData* mdo) {
465 465 for (uint row = 0; row < row_limit(); row++) {
466 466 set_bci_displacement(row, -1);
467 467 set_bci(row, no_bci);
468 468 }
469 469 // release so other threads see a consistent state. bci is used as
470 470 // a valid flag for bci_displacement.
471 471 OrderAccess::release();
472 472 }
473 473
474 474 // This routine needs to atomically update the RetData structure, so the
475 475 // caller needs to hold the RetData_lock before it gets here. Since taking
476 476 // the lock can block (and allow GC) and since RetData is a ProfileData is a
477 477 // wrapper around a derived oop, taking the lock in _this_ method will
478 478 // basically cause the 'this' pointer's _data field to contain junk after the
479 479 // lock. We require the caller to take the lock before making the ProfileData
480 480 // structure. Currently the only caller is InterpreterRuntime::update_mdp_for_ret
481 481 address RetData::fixup_ret(int return_bci, MethodData* h_mdo) {
482 482 // First find the mdp which corresponds to the return bci.
483 483 address mdp = h_mdo->bci_to_dp(return_bci);
484 484
485 485 // Now check to see if any of the cache slots are open.
486 486 for (uint row = 0; row < row_limit(); row++) {
487 487 if (bci(row) == no_bci) {
488 488 set_bci_displacement(row, mdp - dp());
489 489 set_bci_count(row, DataLayout::counter_increment);
490 490 // Barrier to ensure displacement is written before the bci; allows
491 491 // the interpreter to read displacement without fear of race condition.
492 492 release_set_bci(row, return_bci);
493 493 break;
494 494 }
495 495 }
496 496 return mdp;
497 497 }
498 498
499 499 #ifdef CC_INTERP
500 500 DataLayout* RetData::advance(MethodData *md, int bci) {
501 501 return (DataLayout*) md->bci_to_dp(bci);
502 502 }
503 503 #endif // CC_INTERP
504 504
505 505 #ifndef PRODUCT
506 506 void RetData::print_data_on(outputStream* st, const char* extra) const {
507 507 print_shared(st, "RetData", extra);
508 508 uint row;
509 509 int entries = 0;
510 510 for (row = 0; row < row_limit(); row++) {
511 511 if (bci(row) != no_bci) entries++;
512 512 }
513 513 st->print_cr("count(%u) entries(%u)", count(), entries);
514 514 for (row = 0; row < row_limit(); row++) {
515 515 if (bci(row) != no_bci) {
516 516 tab(st);
517 517 st->print_cr("bci(%d: count(%u) displacement(%d))",
518 518 bci(row), bci_count(row), bci_displacement(row));
519 519 }
520 520 }
521 521 }
522 522 #endif // !PRODUCT
523 523
524 524 // ==================================================================
525 525 // BranchData
526 526 //
527 527 // A BranchData is used to access profiling data for a two-way branch.
528 528 // It consists of taken and not_taken counts as well as a data displacement
529 529 // for the taken case.
530 530
531 531 void BranchData::post_initialize(BytecodeStream* stream, MethodData* mdo) {
532 532 assert(stream->bci() == bci(), "wrong pos");
533 533 int target = stream->dest();
534 534 int my_di = mdo->dp_to_di(dp());
535 535 int target_di = mdo->bci_to_di(target);
536 536 int offset = target_di - my_di;
537 537 set_displacement(offset);
538 538 }
539 539
540 540 #ifndef PRODUCT
541 541 void BranchData::print_data_on(outputStream* st, const char* extra) const {
542 542 print_shared(st, "BranchData", extra);
543 543 st->print_cr("taken(%u) displacement(%d)",
544 544 taken(), displacement());
545 545 tab(st);
546 546 st->print_cr("not taken(%u)", not_taken());
547 547 }
548 548 #endif
549 549
550 550 // ==================================================================
551 551 // MultiBranchData
552 552 //
553 553 // A MultiBranchData is used to access profiling information for
554 554 // a multi-way branch (*switch bytecodes). It consists of a series
555 555 // of (count, displacement) pairs, which count the number of times each
556 556 // case was taken and specify the data displacment for each branch target.
557 557
558 558 int MultiBranchData::compute_cell_count(BytecodeStream* stream) {
559 559 int cell_count = 0;
560 560 if (stream->code() == Bytecodes::_tableswitch) {
561 561 Bytecode_tableswitch sw(stream->method()(), stream->bcp());
562 562 cell_count = 1 + per_case_cell_count * (1 + sw.length()); // 1 for default
563 563 } else {
564 564 Bytecode_lookupswitch sw(stream->method()(), stream->bcp());
565 565 cell_count = 1 + per_case_cell_count * (sw.number_of_pairs() + 1); // 1 for default
566 566 }
567 567 return cell_count;
568 568 }
569 569
570 570 void MultiBranchData::post_initialize(BytecodeStream* stream,
571 571 MethodData* mdo) {
572 572 assert(stream->bci() == bci(), "wrong pos");
573 573 int target;
574 574 int my_di;
575 575 int target_di;
576 576 int offset;
577 577 if (stream->code() == Bytecodes::_tableswitch) {
578 578 Bytecode_tableswitch sw(stream->method()(), stream->bcp());
579 579 int len = sw.length();
580 580 assert(array_len() == per_case_cell_count * (len + 1), "wrong len");
581 581 for (int count = 0; count < len; count++) {
582 582 target = sw.dest_offset_at(count) + bci();
583 583 my_di = mdo->dp_to_di(dp());
584 584 target_di = mdo->bci_to_di(target);
585 585 offset = target_di - my_di;
586 586 set_displacement_at(count, offset);
587 587 }
588 588 target = sw.default_offset() + bci();
589 589 my_di = mdo->dp_to_di(dp());
590 590 target_di = mdo->bci_to_di(target);
591 591 offset = target_di - my_di;
592 592 set_default_displacement(offset);
593 593
594 594 } else {
595 595 Bytecode_lookupswitch sw(stream->method()(), stream->bcp());
596 596 int npairs = sw.number_of_pairs();
597 597 assert(array_len() == per_case_cell_count * (npairs + 1), "wrong len");
598 598 for (int count = 0; count < npairs; count++) {
599 599 LookupswitchPair pair = sw.pair_at(count);
600 600 target = pair.offset() + bci();
601 601 my_di = mdo->dp_to_di(dp());
602 602 target_di = mdo->bci_to_di(target);
603 603 offset = target_di - my_di;
604 604 set_displacement_at(count, offset);
605 605 }
606 606 target = sw.default_offset() + bci();
607 607 my_di = mdo->dp_to_di(dp());
608 608 target_di = mdo->bci_to_di(target);
609 609 offset = target_di - my_di;
610 610 set_default_displacement(offset);
611 611 }
612 612 }
613 613
614 614 #ifndef PRODUCT
615 615 void MultiBranchData::print_data_on(outputStream* st, const char* extra) const {
616 616 print_shared(st, "MultiBranchData", extra);
617 617 st->print_cr("default_count(%u) displacement(%d)",
618 618 default_count(), default_displacement());
619 619 int cases = number_of_cases();
620 620 for (int i = 0; i < cases; i++) {
621 621 tab(st);
622 622 st->print_cr("count(%u) displacement(%d)",
623 623 count_at(i), displacement_at(i));
624 624 }
625 625 }
626 626 #endif
627 627
628 628 #ifndef PRODUCT
629 629 void ArgInfoData::print_data_on(outputStream* st, const char* extra) const {
630 630 print_shared(st, "ArgInfoData", extra);
631 631 int nargs = number_of_args();
632 632 for (int i = 0; i < nargs; i++) {
633 633 st->print(" 0x%x", arg_modified(i));
634 634 }
635 635 st->cr();
636 636 }
637 637
638 638 #endif
639 639
640 640 int ParametersTypeData::compute_cell_count(Method* m) {
641 641 if (!MethodData::profile_parameters_for_method(m)) {
642 642 return 0;
643 643 }
644 644 int max = TypeProfileParmsLimit == -1 ? INT_MAX : TypeProfileParmsLimit;
645 645 int obj_args = TypeStackSlotEntries::compute_cell_count(m->signature(), !m->is_static(), max);
646 646 if (obj_args > 0) {
647 647 return obj_args + 1; // 1 cell for array len
648 648 }
649 649 return 0;
650 650 }
651 651
652 652 void ParametersTypeData::post_initialize(BytecodeStream* stream, MethodData* mdo) {
653 653 _parameters.post_initialize(mdo->method()->signature(), !mdo->method()->is_static(), true);
654 654 }
655 655
656 656 bool ParametersTypeData::profiling_enabled() {
657 657 return MethodData::profile_parameters();
658 658 }
659 659
660 660 #ifndef PRODUCT
661 661 void ParametersTypeData::print_data_on(outputStream* st, const char* extra) const {
662 662 st->print("parameter types"); // FIXME extra ignored?
663 663 _parameters.print_data_on(st);
664 664 }
665 665
666 666 void SpeculativeTrapData::print_data_on(outputStream* st, const char* extra) const {
667 667 print_shared(st, "SpeculativeTrapData", extra);
668 668 tab(st);
669 669 method()->print_short_name(st);
670 670 st->cr();
671 671 }
672 672 #endif
673 673
674 674 // ==================================================================
675 675 // MethodData*
676 676 //
677 677 // A MethodData* holds information which has been collected about
678 678 // a method.
679 679
680 680 MethodData* MethodData::allocate(ClassLoaderData* loader_data, methodHandle method, TRAPS) {
681 681 int size = MethodData::compute_allocation_size_in_words(method);
682 682
683 683 return new (loader_data, size, false, MetaspaceObj::MethodDataType, THREAD)
684 684 MethodData(method(), size, CHECK_NULL);
685 685 }
686 686
687 687 int MethodData::bytecode_cell_count(Bytecodes::Code code) {
688 688 #if defined(COMPILER1) && !defined(COMPILER2)
689 689 return no_profile_data;
690 690 #else
691 691 switch (code) {
692 692 case Bytecodes::_checkcast:
693 693 case Bytecodes::_instanceof:
694 694 case Bytecodes::_aastore:
695 695 if (TypeProfileCasts) {
696 696 return ReceiverTypeData::static_cell_count();
697 697 } else {
698 698 return BitData::static_cell_count();
699 699 }
700 700 case Bytecodes::_invokespecial:
701 701 case Bytecodes::_invokestatic:
702 702 if (MethodData::profile_arguments() || MethodData::profile_return()) {
703 703 return variable_cell_count;
704 704 } else {
705 705 return CounterData::static_cell_count();
706 706 }
707 707 case Bytecodes::_goto:
708 708 case Bytecodes::_goto_w:
709 709 case Bytecodes::_jsr:
710 710 case Bytecodes::_jsr_w:
711 711 return JumpData::static_cell_count();
712 712 case Bytecodes::_invokevirtual:
713 713 case Bytecodes::_invokeinterface:
714 714 if (MethodData::profile_arguments() || MethodData::profile_return()) {
715 715 return variable_cell_count;
716 716 } else {
717 717 return VirtualCallData::static_cell_count();
718 718 }
719 719 case Bytecodes::_invokedynamic:
720 720 if (MethodData::profile_arguments() || MethodData::profile_return()) {
721 721 return variable_cell_count;
722 722 } else {
723 723 return CounterData::static_cell_count();
724 724 }
725 725 case Bytecodes::_ret:
726 726 return RetData::static_cell_count();
727 727 case Bytecodes::_ifeq:
728 728 case Bytecodes::_ifne:
729 729 case Bytecodes::_iflt:
730 730 case Bytecodes::_ifge:
731 731 case Bytecodes::_ifgt:
732 732 case Bytecodes::_ifle:
733 733 case Bytecodes::_if_icmpeq:
734 734 case Bytecodes::_if_icmpne:
735 735 case Bytecodes::_if_icmplt:
736 736 case Bytecodes::_if_icmpge:
737 737 case Bytecodes::_if_icmpgt:
738 738 case Bytecodes::_if_icmple:
739 739 case Bytecodes::_if_acmpeq:
740 740 case Bytecodes::_if_acmpne:
741 741 case Bytecodes::_ifnull:
742 742 case Bytecodes::_ifnonnull:
743 743 return BranchData::static_cell_count();
744 744 case Bytecodes::_lookupswitch:
745 745 case Bytecodes::_tableswitch:
746 746 return variable_cell_count;
747 747 }
748 748 return no_profile_data;
749 749 #endif
750 750 }
751 751
752 752 // Compute the size of the profiling information corresponding to
753 753 // the current bytecode.
754 754 int MethodData::compute_data_size(BytecodeStream* stream) {
755 755 int cell_count = bytecode_cell_count(stream->code());
756 756 if (cell_count == no_profile_data) {
757 757 return 0;
758 758 }
759 759 if (cell_count == variable_cell_count) {
760 760 switch (stream->code()) {
761 761 case Bytecodes::_lookupswitch:
762 762 case Bytecodes::_tableswitch:
763 763 cell_count = MultiBranchData::compute_cell_count(stream);
764 764 break;
765 765 case Bytecodes::_invokespecial:
766 766 case Bytecodes::_invokestatic:
767 767 case Bytecodes::_invokedynamic:
768 768 assert(MethodData::profile_arguments() || MethodData::profile_return(), "should be collecting args profile");
769 769 if (profile_arguments_for_invoke(stream->method(), stream->bci()) ||
770 770 profile_return_for_invoke(stream->method(), stream->bci())) {
771 771 cell_count = CallTypeData::compute_cell_count(stream);
772 772 } else {
773 773 cell_count = CounterData::static_cell_count();
774 774 }
775 775 break;
776 776 case Bytecodes::_invokevirtual:
777 777 case Bytecodes::_invokeinterface: {
778 778 assert(MethodData::profile_arguments() || MethodData::profile_return(), "should be collecting args profile");
779 779 if (profile_arguments_for_invoke(stream->method(), stream->bci()) ||
780 780 profile_return_for_invoke(stream->method(), stream->bci())) {
781 781 cell_count = VirtualCallTypeData::compute_cell_count(stream);
782 782 } else {
783 783 cell_count = VirtualCallData::static_cell_count();
784 784 }
785 785 break;
786 786 }
787 787 default:
788 788 fatal("unexpected bytecode for var length profile data");
789 789 }
790 790 }
791 791 // Note: cell_count might be zero, meaning that there is just
792 792 // a DataLayout header, with no extra cells.
793 793 assert(cell_count >= 0, "sanity");
794 794 return DataLayout::compute_size_in_bytes(cell_count);
795 795 }
796 796
797 797 bool MethodData::is_speculative_trap_bytecode(Bytecodes::Code code) {
798 798 // Bytecodes for which we may use speculation
799 799 switch (code) {
800 800 case Bytecodes::_checkcast:
801 801 case Bytecodes::_instanceof:
802 802 case Bytecodes::_aastore:
803 803 case Bytecodes::_invokevirtual:
804 804 case Bytecodes::_invokeinterface:
805 805 case Bytecodes::_if_acmpeq:
806 806 case Bytecodes::_if_acmpne:
807 807 case Bytecodes::_invokestatic:
808 808 #ifdef COMPILER2
809 809 return UseTypeSpeculation;
810 810 #endif
811 811 default:
812 812 return false;
813 813 }
814 814 return false;
815 815 }
816 816
817 817 int MethodData::compute_extra_data_count(int data_size, int empty_bc_count, bool needs_speculative_traps) {
818 818 if (ProfileTraps) {
819 819 // Assume that up to 3% of BCIs with no MDP will need to allocate one.
820 820 int extra_data_count = (uint)(empty_bc_count * 3) / 128 + 1;
821 821 // If the method is large, let the extra BCIs grow numerous (to ~1%).
822 822 int one_percent_of_data
823 823 = (uint)data_size / (DataLayout::header_size_in_bytes()*128);
824 824 if (extra_data_count < one_percent_of_data)
825 825 extra_data_count = one_percent_of_data;
826 826 if (extra_data_count > empty_bc_count)
827 827 extra_data_count = empty_bc_count; // no need for more
828 828
829 829 // Make sure we have a minimum number of extra data slots to
830 830 // allocate SpeculativeTrapData entries. We would want to have one
831 831 // entry per compilation that inlines this method and for which
832 832 // some type speculation assumption fails. So the room we need for
833 833 // the SpeculativeTrapData entries doesn't directly depend on the
834 834 // size of the method. Because it's hard to estimate, we reserve
835 835 // space for an arbitrary number of entries.
836 836 int spec_data_count = (needs_speculative_traps ? SpecTrapLimitExtraEntries : 0) *
837 837 (SpeculativeTrapData::static_cell_count() + DataLayout::header_size_in_cells());
838 838
839 839 return MAX2(extra_data_count, spec_data_count);
840 840 } else {
841 841 return 0;
842 842 }
843 843 }
844 844
845 845 // Compute the size of the MethodData* necessary to store
846 846 // profiling information about a given method. Size is in bytes.
847 847 int MethodData::compute_allocation_size_in_bytes(methodHandle method) {
848 848 int data_size = 0;
849 849 BytecodeStream stream(method);
850 850 Bytecodes::Code c;
851 851 int empty_bc_count = 0; // number of bytecodes lacking data
852 852 bool needs_speculative_traps = false;
853 853 while ((c = stream.next()) >= 0) {
854 854 int size_in_bytes = compute_data_size(&stream);
855 855 data_size += size_in_bytes;
856 856 if (size_in_bytes == 0) empty_bc_count += 1;
857 857 needs_speculative_traps = needs_speculative_traps || is_speculative_trap_bytecode(c);
858 858 }
859 859 int object_size = in_bytes(data_offset()) + data_size;
860 860
861 861 // Add some extra DataLayout cells (at least one) to track stray traps.
862 862 int extra_data_count = compute_extra_data_count(data_size, empty_bc_count, needs_speculative_traps);
863 863 object_size += extra_data_count * DataLayout::compute_size_in_bytes(0);
864 864
865 865 // Add a cell to record information about modified arguments.
866 866 int arg_size = method->size_of_parameters();
867 867 object_size += DataLayout::compute_size_in_bytes(arg_size+1);
868 868
869 869 // Reserve room for an area of the MDO dedicated to profiling of
870 870 // parameters
871 871 int args_cell = ParametersTypeData::compute_cell_count(method());
872 872 if (args_cell > 0) {
873 873 object_size += DataLayout::compute_size_in_bytes(args_cell);
874 874 }
875 875 return object_size;
876 876 }
877 877
878 878 // Compute the size of the MethodData* necessary to store
879 879 // profiling information about a given method. Size is in words
880 880 int MethodData::compute_allocation_size_in_words(methodHandle method) {
881 881 int byte_size = compute_allocation_size_in_bytes(method);
882 882 int word_size = align_size_up(byte_size, BytesPerWord) / BytesPerWord;
883 883 return align_object_size(word_size);
884 884 }
885 885
886 886 // Initialize an individual data segment. Returns the size of
887 887 // the segment in bytes.
888 888 int MethodData::initialize_data(BytecodeStream* stream,
889 889 int data_index) {
890 890 #if defined(COMPILER1) && !defined(COMPILER2)
891 891 return 0;
892 892 #else
893 893 int cell_count = -1;
894 894 int tag = DataLayout::no_tag;
895 895 DataLayout* data_layout = data_layout_at(data_index);
896 896 Bytecodes::Code c = stream->code();
897 897 switch (c) {
898 898 case Bytecodes::_checkcast:
899 899 case Bytecodes::_instanceof:
900 900 case Bytecodes::_aastore:
901 901 if (TypeProfileCasts) {
902 902 cell_count = ReceiverTypeData::static_cell_count();
903 903 tag = DataLayout::receiver_type_data_tag;
904 904 } else {
905 905 cell_count = BitData::static_cell_count();
906 906 tag = DataLayout::bit_data_tag;
907 907 }
908 908 break;
909 909 case Bytecodes::_invokespecial:
910 910 case Bytecodes::_invokestatic: {
911 911 int counter_data_cell_count = CounterData::static_cell_count();
912 912 if (profile_arguments_for_invoke(stream->method(), stream->bci()) ||
913 913 profile_return_for_invoke(stream->method(), stream->bci())) {
914 914 cell_count = CallTypeData::compute_cell_count(stream);
915 915 } else {
916 916 cell_count = counter_data_cell_count;
917 917 }
918 918 if (cell_count > counter_data_cell_count) {
919 919 tag = DataLayout::call_type_data_tag;
920 920 } else {
921 921 tag = DataLayout::counter_data_tag;
922 922 }
923 923 break;
924 924 }
925 925 case Bytecodes::_goto:
926 926 case Bytecodes::_goto_w:
927 927 case Bytecodes::_jsr:
928 928 case Bytecodes::_jsr_w:
929 929 cell_count = JumpData::static_cell_count();
930 930 tag = DataLayout::jump_data_tag;
931 931 break;
932 932 case Bytecodes::_invokevirtual:
933 933 case Bytecodes::_invokeinterface: {
934 934 int virtual_call_data_cell_count = VirtualCallData::static_cell_count();
935 935 if (profile_arguments_for_invoke(stream->method(), stream->bci()) ||
936 936 profile_return_for_invoke(stream->method(), stream->bci())) {
937 937 cell_count = VirtualCallTypeData::compute_cell_count(stream);
938 938 } else {
939 939 cell_count = virtual_call_data_cell_count;
940 940 }
941 941 if (cell_count > virtual_call_data_cell_count) {
942 942 tag = DataLayout::virtual_call_type_data_tag;
943 943 } else {
944 944 tag = DataLayout::virtual_call_data_tag;
945 945 }
946 946 break;
947 947 }
948 948 case Bytecodes::_invokedynamic: {
949 949 // %%% should make a type profile for any invokedynamic that takes a ref argument
950 950 int counter_data_cell_count = CounterData::static_cell_count();
951 951 if (profile_arguments_for_invoke(stream->method(), stream->bci()) ||
952 952 profile_return_for_invoke(stream->method(), stream->bci())) {
953 953 cell_count = CallTypeData::compute_cell_count(stream);
954 954 } else {
955 955 cell_count = counter_data_cell_count;
956 956 }
957 957 if (cell_count > counter_data_cell_count) {
958 958 tag = DataLayout::call_type_data_tag;
959 959 } else {
960 960 tag = DataLayout::counter_data_tag;
961 961 }
962 962 break;
963 963 }
964 964 case Bytecodes::_ret:
965 965 cell_count = RetData::static_cell_count();
966 966 tag = DataLayout::ret_data_tag;
967 967 break;
968 968 case Bytecodes::_ifeq:
969 969 case Bytecodes::_ifne:
970 970 case Bytecodes::_iflt:
971 971 case Bytecodes::_ifge:
972 972 case Bytecodes::_ifgt:
973 973 case Bytecodes::_ifle:
974 974 case Bytecodes::_if_icmpeq:
975 975 case Bytecodes::_if_icmpne:
976 976 case Bytecodes::_if_icmplt:
977 977 case Bytecodes::_if_icmpge:
978 978 case Bytecodes::_if_icmpgt:
979 979 case Bytecodes::_if_icmple:
980 980 case Bytecodes::_if_acmpeq:
981 981 case Bytecodes::_if_acmpne:
982 982 case Bytecodes::_ifnull:
983 983 case Bytecodes::_ifnonnull:
984 984 cell_count = BranchData::static_cell_count();
985 985 tag = DataLayout::branch_data_tag;
986 986 break;
987 987 case Bytecodes::_lookupswitch:
988 988 case Bytecodes::_tableswitch:
989 989 cell_count = MultiBranchData::compute_cell_count(stream);
990 990 tag = DataLayout::multi_branch_data_tag;
991 991 break;
992 992 }
993 993 assert(tag == DataLayout::multi_branch_data_tag ||
994 994 ((MethodData::profile_arguments() || MethodData::profile_return()) &&
995 995 (tag == DataLayout::call_type_data_tag ||
996 996 tag == DataLayout::counter_data_tag ||
997 997 tag == DataLayout::virtual_call_type_data_tag ||
998 998 tag == DataLayout::virtual_call_data_tag)) ||
999 999 cell_count == bytecode_cell_count(c), "cell counts must agree");
1000 1000 if (cell_count >= 0) {
1001 1001 assert(tag != DataLayout::no_tag, "bad tag");
1002 1002 assert(bytecode_has_profile(c), "agree w/ BHP");
1003 1003 data_layout->initialize(tag, stream->bci(), cell_count);
1004 1004 return DataLayout::compute_size_in_bytes(cell_count);
1005 1005 } else {
1006 1006 assert(!bytecode_has_profile(c), "agree w/ !BHP");
1007 1007 return 0;
1008 1008 }
1009 1009 #endif
1010 1010 }
1011 1011
1012 1012 // Get the data at an arbitrary (sort of) data index.
1013 1013 ProfileData* MethodData::data_at(int data_index) const {
1014 1014 if (out_of_bounds(data_index)) {
1015 1015 return NULL;
1016 1016 }
1017 1017 DataLayout* data_layout = data_layout_at(data_index);
1018 1018 return data_layout->data_in();
1019 1019 }
1020 1020
1021 1021 ProfileData* DataLayout::data_in() {
1022 1022 switch (tag()) {
1023 1023 case DataLayout::no_tag:
1024 1024 default:
1025 1025 ShouldNotReachHere();
1026 1026 return NULL;
1027 1027 case DataLayout::bit_data_tag:
1028 1028 return new BitData(this);
1029 1029 case DataLayout::counter_data_tag:
1030 1030 return new CounterData(this);
1031 1031 case DataLayout::jump_data_tag:
1032 1032 return new JumpData(this);
1033 1033 case DataLayout::receiver_type_data_tag:
1034 1034 return new ReceiverTypeData(this);
1035 1035 case DataLayout::virtual_call_data_tag:
1036 1036 return new VirtualCallData(this);
1037 1037 case DataLayout::ret_data_tag:
1038 1038 return new RetData(this);
1039 1039 case DataLayout::branch_data_tag:
1040 1040 return new BranchData(this);
1041 1041 case DataLayout::multi_branch_data_tag:
1042 1042 return new MultiBranchData(this);
1043 1043 case DataLayout::arg_info_data_tag:
1044 1044 return new ArgInfoData(this);
1045 1045 case DataLayout::call_type_data_tag:
1046 1046 return new CallTypeData(this);
1047 1047 case DataLayout::virtual_call_type_data_tag:
1048 1048 return new VirtualCallTypeData(this);
1049 1049 case DataLayout::parameters_type_data_tag:
1050 1050 return new ParametersTypeData(this);
1051 1051 };
1052 1052 }
1053 1053
1054 1054 // Iteration over data.
1055 1055 ProfileData* MethodData::next_data(ProfileData* current) const {
1056 1056 int current_index = dp_to_di(current->dp());
1057 1057 int next_index = current_index + current->size_in_bytes();
1058 1058 ProfileData* next = data_at(next_index);
1059 1059 return next;
1060 1060 }
1061 1061
1062 1062 // Give each of the data entries a chance to perform specific
1063 1063 // data initialization.
1064 1064 void MethodData::post_initialize(BytecodeStream* stream) {
1065 1065 ResourceMark rm;
1066 1066 ProfileData* data;
1067 1067 for (data = first_data(); is_valid(data); data = next_data(data)) {
1068 1068 stream->set_start(data->bci());
1069 1069 stream->next();
1070 1070 data->post_initialize(stream, this);
1071 1071 }
1072 1072 if (_parameters_type_data_di != -1) {
1073 1073 parameters_type_data()->post_initialize(NULL, this);
1074 1074 }
1075 1075 }
1076 1076
1077 1077 // Initialize the MethodData* corresponding to a given method.
1078 1078 MethodData::MethodData(methodHandle method, int size, TRAPS)
1079 1079 : _extra_data_lock(Monitor::leaf, "MDO extra data lock") {
1080 1080 No_Safepoint_Verifier no_safepoint; // init function atomic wrt GC
1081 1081 ResourceMark rm;
1082 1082 // Set the method back-pointer.
1083 1083 _method = method();
1084 1084
1085 1085 init();
1086 1086 set_creation_mileage(mileage_of(method()));
1087 1087
1088 1088 // Go through the bytecodes and allocate and initialize the
1089 1089 // corresponding data cells.
1090 1090 int data_size = 0;
1091 1091 int empty_bc_count = 0; // number of bytecodes lacking data
1092 1092 _data[0] = 0; // apparently not set below.
1093 1093 BytecodeStream stream(method);
1094 1094 Bytecodes::Code c;
1095 1095 bool needs_speculative_traps = false;
1096 1096 while ((c = stream.next()) >= 0) {
1097 1097 int size_in_bytes = initialize_data(&stream, data_size);
1098 1098 data_size += size_in_bytes;
1099 1099 if (size_in_bytes == 0) empty_bc_count += 1;
1100 1100 needs_speculative_traps = needs_speculative_traps || is_speculative_trap_bytecode(c);
1101 1101 }
1102 1102 _data_size = data_size;
1103 1103 int object_size = in_bytes(data_offset()) + data_size;
1104 1104
1105 1105 // Add some extra DataLayout cells (at least one) to track stray traps.
1106 1106 int extra_data_count = compute_extra_data_count(data_size, empty_bc_count, needs_speculative_traps);
1107 1107 int extra_size = extra_data_count * DataLayout::compute_size_in_bytes(0);
1108 1108
1109 1109 // Let's zero the space for the extra data
1110 1110 Copy::zero_to_bytes(((address)_data) + data_size, extra_size);
1111 1111
1112 1112 // Add a cell to record information about modified arguments.
1113 1113 // Set up _args_modified array after traps cells so that
1114 1114 // the code for traps cells works.
1115 1115 DataLayout *dp = data_layout_at(data_size + extra_size);
1116 1116
1117 1117 int arg_size = method->size_of_parameters();
1118 1118 dp->initialize(DataLayout::arg_info_data_tag, 0, arg_size+1);
1119 1119
1120 1120 int arg_data_size = DataLayout::compute_size_in_bytes(arg_size+1);
1121 1121 object_size += extra_size + arg_data_size;
1122 1122
1123 1123 int parms_cell = ParametersTypeData::compute_cell_count(method());
1124 1124 // If we are profiling parameters, we reserver an area near the end
1125 1125 // of the MDO after the slots for bytecodes (because there's no bci
1126 1126 // for method entry so they don't fit with the framework for the
1127 1127 // profiling of bytecodes). We store the offset within the MDO of
1128 1128 // this area (or -1 if no parameter is profiled)
1129 1129 if (parms_cell > 0) {
1130 1130 object_size += DataLayout::compute_size_in_bytes(parms_cell);
1131 1131 _parameters_type_data_di = data_size + extra_size + arg_data_size;
1132 1132 DataLayout *dp = data_layout_at(data_size + extra_size + arg_data_size);
1133 1133 dp->initialize(DataLayout::parameters_type_data_tag, 0, parms_cell);
1134 1134 } else {
1135 1135 _parameters_type_data_di = -1;
1136 1136 }
1137 1137
1138 1138 // Set an initial hint. Don't use set_hint_di() because
1139 1139 // first_di() may be out of bounds if data_size is 0.
1140 1140 // In that situation, _hint_di is never used, but at
1141 1141 // least well-defined.
1142 1142 _hint_di = first_di();
1143 1143
1144 1144 post_initialize(&stream);
1145 1145
↓ open down ↓ |
1145 lines elided |
↑ open up ↑ |
1146 1146 set_size(object_size);
1147 1147 }
1148 1148
1149 1149 void MethodData::init() {
1150 1150 _invocation_counter.init();
1151 1151 _backedge_counter.init();
1152 1152 _invocation_counter_start = 0;
1153 1153 _backedge_counter_start = 0;
1154 1154 _num_loops = 0;
1155 1155 _num_blocks = 0;
1156 - _would_profile = true;
1156 + _would_profile = unknown;
1157 1157
1158 1158 #if INCLUDE_RTM_OPT
1159 1159 _rtm_state = NoRTM; // No RTM lock eliding by default
1160 1160 if (UseRTMLocking &&
1161 1161 !CompilerOracle::has_option_string(_method, "NoRTMLockEliding")) {
1162 1162 if (CompilerOracle::has_option_string(_method, "UseRTMLockEliding") || !UseRTMDeopt) {
1163 1163 // Generate RTM lock eliding code without abort ratio calculation code.
1164 1164 _rtm_state = UseRTM;
1165 1165 } else if (UseRTMDeopt) {
1166 1166 // Generate RTM lock eliding code and include abort ratio calculation
1167 1167 // code if UseRTMDeopt is on.
1168 1168 _rtm_state = ProfileRTM;
1169 1169 }
1170 1170 }
1171 1171 #endif
1172 1172
1173 1173 // Initialize flags and trap history.
1174 1174 _nof_decompiles = 0;
1175 1175 _nof_overflow_recompiles = 0;
1176 1176 _nof_overflow_traps = 0;
1177 1177 clear_escape_info();
1178 1178 assert(sizeof(_trap_hist) % sizeof(HeapWord) == 0, "align");
1179 1179 Copy::zero_to_words((HeapWord*) &_trap_hist,
1180 1180 sizeof(_trap_hist) / sizeof(HeapWord));
1181 1181 }
1182 1182
1183 1183 // Get a measure of how much mileage the method has on it.
1184 1184 int MethodData::mileage_of(Method* method) {
1185 1185 int mileage = 0;
1186 1186 if (TieredCompilation) {
1187 1187 mileage = MAX2(method->invocation_count(), method->backedge_count());
1188 1188 } else {
1189 1189 int iic = method->interpreter_invocation_count();
1190 1190 if (mileage < iic) mileage = iic;
1191 1191 MethodCounters* mcs = method->method_counters();
1192 1192 if (mcs != NULL) {
1193 1193 InvocationCounter* ic = mcs->invocation_counter();
1194 1194 InvocationCounter* bc = mcs->backedge_counter();
1195 1195 int icval = ic->count();
1196 1196 if (ic->carry()) icval += CompileThreshold;
1197 1197 if (mileage < icval) mileage = icval;
1198 1198 int bcval = bc->count();
1199 1199 if (bc->carry()) bcval += CompileThreshold;
1200 1200 if (mileage < bcval) mileage = bcval;
1201 1201 }
1202 1202 }
1203 1203 return mileage;
1204 1204 }
1205 1205
1206 1206 bool MethodData::is_mature() const {
1207 1207 return CompilationPolicy::policy()->is_mature(_method);
1208 1208 }
1209 1209
1210 1210 // Translate a bci to its corresponding data index (di).
1211 1211 address MethodData::bci_to_dp(int bci) {
1212 1212 ResourceMark rm;
1213 1213 ProfileData* data = data_before(bci);
1214 1214 ProfileData* prev = NULL;
1215 1215 for ( ; is_valid(data); data = next_data(data)) {
1216 1216 if (data->bci() >= bci) {
1217 1217 if (data->bci() == bci) set_hint_di(dp_to_di(data->dp()));
1218 1218 else if (prev != NULL) set_hint_di(dp_to_di(prev->dp()));
1219 1219 return data->dp();
1220 1220 }
1221 1221 prev = data;
1222 1222 }
1223 1223 return (address)limit_data_position();
1224 1224 }
1225 1225
1226 1226 // Translate a bci to its corresponding data, or NULL.
1227 1227 ProfileData* MethodData::bci_to_data(int bci) {
1228 1228 ProfileData* data = data_before(bci);
1229 1229 for ( ; is_valid(data); data = next_data(data)) {
1230 1230 if (data->bci() == bci) {
1231 1231 set_hint_di(dp_to_di(data->dp()));
1232 1232 return data;
1233 1233 } else if (data->bci() > bci) {
1234 1234 break;
1235 1235 }
1236 1236 }
1237 1237 return bci_to_extra_data(bci, NULL, false);
1238 1238 }
1239 1239
1240 1240 DataLayout* MethodData::next_extra(DataLayout* dp) {
1241 1241 int nb_cells = 0;
1242 1242 switch(dp->tag()) {
1243 1243 case DataLayout::bit_data_tag:
1244 1244 case DataLayout::no_tag:
1245 1245 nb_cells = BitData::static_cell_count();
1246 1246 break;
1247 1247 case DataLayout::speculative_trap_data_tag:
1248 1248 nb_cells = SpeculativeTrapData::static_cell_count();
1249 1249 break;
1250 1250 default:
1251 1251 fatal(err_msg("unexpected tag %d", dp->tag()));
1252 1252 }
1253 1253 return (DataLayout*)((address)dp + DataLayout::compute_size_in_bytes(nb_cells));
1254 1254 }
1255 1255
1256 1256 ProfileData* MethodData::bci_to_extra_data_helper(int bci, Method* m, DataLayout*& dp, bool concurrent) {
1257 1257 DataLayout* end = extra_data_limit();
1258 1258
1259 1259 for (;; dp = next_extra(dp)) {
1260 1260 assert(dp < end, "moved past end of extra data");
1261 1261 // No need for "OrderAccess::load_acquire" ops,
1262 1262 // since the data structure is monotonic.
1263 1263 switch(dp->tag()) {
1264 1264 case DataLayout::no_tag:
1265 1265 return NULL;
1266 1266 case DataLayout::arg_info_data_tag:
1267 1267 dp = end;
1268 1268 return NULL; // ArgInfoData is at the end of extra data section.
1269 1269 case DataLayout::bit_data_tag:
1270 1270 if (m == NULL && dp->bci() == bci) {
1271 1271 return new BitData(dp);
1272 1272 }
1273 1273 break;
1274 1274 case DataLayout::speculative_trap_data_tag:
1275 1275 if (m != NULL) {
1276 1276 SpeculativeTrapData* data = new SpeculativeTrapData(dp);
1277 1277 // data->method() may be null in case of a concurrent
1278 1278 // allocation. Maybe it's for the same method. Try to use that
1279 1279 // entry in that case.
1280 1280 if (dp->bci() == bci) {
1281 1281 if (data->method() == NULL) {
1282 1282 assert(concurrent, "impossible because no concurrent allocation");
1283 1283 return NULL;
1284 1284 } else if (data->method() == m) {
1285 1285 return data;
1286 1286 }
1287 1287 }
1288 1288 }
1289 1289 break;
1290 1290 default:
1291 1291 fatal(err_msg("unexpected tag %d", dp->tag()));
1292 1292 }
1293 1293 }
1294 1294 return NULL;
1295 1295 }
1296 1296
1297 1297
1298 1298 // Translate a bci to its corresponding extra data, or NULL.
1299 1299 ProfileData* MethodData::bci_to_extra_data(int bci, Method* m, bool create_if_missing) {
1300 1300 // This code assumes an entry for a SpeculativeTrapData is 2 cells
1301 1301 assert(2*DataLayout::compute_size_in_bytes(BitData::static_cell_count()) ==
1302 1302 DataLayout::compute_size_in_bytes(SpeculativeTrapData::static_cell_count()),
1303 1303 "code needs to be adjusted");
1304 1304
1305 1305 DataLayout* dp = extra_data_base();
1306 1306 DataLayout* end = extra_data_limit();
1307 1307
1308 1308 // Allocation in the extra data space has to be atomic because not
1309 1309 // all entries have the same size and non atomic concurrent
1310 1310 // allocation would result in a corrupted extra data space.
1311 1311 ProfileData* result = bci_to_extra_data_helper(bci, m, dp, true);
1312 1312 if (result != NULL) {
1313 1313 return result;
1314 1314 }
1315 1315
1316 1316 if (create_if_missing && dp < end) {
1317 1317 MutexLocker ml(&_extra_data_lock);
1318 1318 // Check again now that we have the lock. Another thread may
1319 1319 // have added extra data entries.
1320 1320 ProfileData* result = bci_to_extra_data_helper(bci, m, dp, false);
1321 1321 if (result != NULL || dp >= end) {
1322 1322 return result;
1323 1323 }
1324 1324
1325 1325 assert(dp->tag() == DataLayout::no_tag || (dp->tag() == DataLayout::speculative_trap_data_tag && m != NULL), "should be free");
1326 1326 assert(next_extra(dp)->tag() == DataLayout::no_tag || next_extra(dp)->tag() == DataLayout::arg_info_data_tag, "should be free or arg info");
1327 1327 u1 tag = m == NULL ? DataLayout::bit_data_tag : DataLayout::speculative_trap_data_tag;
1328 1328 // SpeculativeTrapData is 2 slots. Make sure we have room.
1329 1329 if (m != NULL && next_extra(dp)->tag() != DataLayout::no_tag) {
1330 1330 return NULL;
1331 1331 }
1332 1332 DataLayout temp;
1333 1333 temp.initialize(tag, bci, 0);
1334 1334
1335 1335 dp->set_header(temp.header());
1336 1336 assert(dp->tag() == tag, "sane");
1337 1337 assert(dp->bci() == bci, "no concurrent allocation");
1338 1338 if (tag == DataLayout::bit_data_tag) {
1339 1339 return new BitData(dp);
1340 1340 } else {
1341 1341 SpeculativeTrapData* data = new SpeculativeTrapData(dp);
1342 1342 data->set_method(m);
1343 1343 return data;
1344 1344 }
1345 1345 }
1346 1346 return NULL;
1347 1347 }
1348 1348
1349 1349 ArgInfoData *MethodData::arg_info() {
1350 1350 DataLayout* dp = extra_data_base();
1351 1351 DataLayout* end = extra_data_limit();
1352 1352 for (; dp < end; dp = next_extra(dp)) {
1353 1353 if (dp->tag() == DataLayout::arg_info_data_tag)
1354 1354 return new ArgInfoData(dp);
1355 1355 }
1356 1356 return NULL;
1357 1357 }
1358 1358
1359 1359 // Printing
1360 1360
1361 1361 #ifndef PRODUCT
1362 1362
1363 1363 void MethodData::print_on(outputStream* st) const {
1364 1364 assert(is_methodData(), "should be method data");
1365 1365 st->print("method data for ");
1366 1366 method()->print_value_on(st);
1367 1367 st->cr();
1368 1368 print_data_on(st);
1369 1369 }
1370 1370
1371 1371 #endif //PRODUCT
1372 1372
1373 1373 void MethodData::print_value_on(outputStream* st) const {
1374 1374 assert(is_methodData(), "should be method data");
1375 1375 st->print("method data for ");
1376 1376 method()->print_value_on(st);
1377 1377 }
1378 1378
1379 1379 #ifndef PRODUCT
1380 1380 void MethodData::print_data_on(outputStream* st) const {
1381 1381 ResourceMark rm;
1382 1382 ProfileData* data = first_data();
1383 1383 if (_parameters_type_data_di != -1) {
1384 1384 parameters_type_data()->print_data_on(st);
1385 1385 }
1386 1386 for ( ; is_valid(data); data = next_data(data)) {
1387 1387 st->print("%d", dp_to_di(data->dp()));
1388 1388 st->fill_to(6);
1389 1389 data->print_data_on(st, this);
1390 1390 }
1391 1391 st->print_cr("--- Extra data:");
1392 1392 DataLayout* dp = extra_data_base();
1393 1393 DataLayout* end = extra_data_limit();
1394 1394 for (;; dp = next_extra(dp)) {
1395 1395 assert(dp < end, "moved past end of extra data");
1396 1396 // No need for "OrderAccess::load_acquire" ops,
1397 1397 // since the data structure is monotonic.
1398 1398 switch(dp->tag()) {
1399 1399 case DataLayout::no_tag:
1400 1400 continue;
1401 1401 case DataLayout::bit_data_tag:
1402 1402 data = new BitData(dp);
1403 1403 break;
1404 1404 case DataLayout::speculative_trap_data_tag:
1405 1405 data = new SpeculativeTrapData(dp);
1406 1406 break;
1407 1407 case DataLayout::arg_info_data_tag:
1408 1408 data = new ArgInfoData(dp);
1409 1409 dp = end; // ArgInfoData is at the end of extra data section.
1410 1410 break;
1411 1411 default:
1412 1412 fatal(err_msg("unexpected tag %d", dp->tag()));
1413 1413 }
1414 1414 st->print("%d", dp_to_di(data->dp()));
1415 1415 st->fill_to(6);
1416 1416 data->print_data_on(st);
1417 1417 if (dp >= end) return;
1418 1418 }
1419 1419 }
1420 1420 #endif
1421 1421
1422 1422 #if INCLUDE_SERVICES
1423 1423 // Size Statistics
1424 1424 void MethodData::collect_statistics(KlassSizeStats *sz) const {
1425 1425 int n = sz->count(this);
1426 1426 sz->_method_data_bytes += n;
1427 1427 sz->_method_all_bytes += n;
1428 1428 sz->_rw_bytes += n;
1429 1429 }
1430 1430 #endif // INCLUDE_SERVICES
1431 1431
1432 1432 // Verification
1433 1433
1434 1434 void MethodData::verify_on(outputStream* st) {
1435 1435 guarantee(is_methodData(), "object must be method data");
1436 1436 // guarantee(m->is_perm(), "should be in permspace");
1437 1437 this->verify_data_on(st);
1438 1438 }
1439 1439
1440 1440 void MethodData::verify_data_on(outputStream* st) {
1441 1441 NEEDS_CLEANUP;
1442 1442 // not yet implemented.
1443 1443 }
1444 1444
1445 1445 bool MethodData::profile_jsr292(methodHandle m, int bci) {
1446 1446 if (m->is_compiled_lambda_form()) {
1447 1447 return true;
1448 1448 }
1449 1449
1450 1450 Bytecode_invoke inv(m , bci);
1451 1451 return inv.is_invokedynamic() || inv.is_invokehandle();
1452 1452 }
1453 1453
1454 1454 int MethodData::profile_arguments_flag() {
1455 1455 return TypeProfileLevel % 10;
1456 1456 }
1457 1457
1458 1458 bool MethodData::profile_arguments() {
1459 1459 return profile_arguments_flag() > no_type_profile && profile_arguments_flag() <= type_profile_all;
1460 1460 }
1461 1461
1462 1462 bool MethodData::profile_arguments_jsr292_only() {
1463 1463 return profile_arguments_flag() == type_profile_jsr292;
1464 1464 }
1465 1465
1466 1466 bool MethodData::profile_all_arguments() {
1467 1467 return profile_arguments_flag() == type_profile_all;
1468 1468 }
1469 1469
1470 1470 bool MethodData::profile_arguments_for_invoke(methodHandle m, int bci) {
1471 1471 if (!profile_arguments()) {
1472 1472 return false;
1473 1473 }
1474 1474
1475 1475 if (profile_all_arguments()) {
1476 1476 return true;
1477 1477 }
1478 1478
1479 1479 assert(profile_arguments_jsr292_only(), "inconsistent");
1480 1480 return profile_jsr292(m, bci);
1481 1481 }
1482 1482
1483 1483 int MethodData::profile_return_flag() {
1484 1484 return (TypeProfileLevel % 100) / 10;
1485 1485 }
1486 1486
1487 1487 bool MethodData::profile_return() {
1488 1488 return profile_return_flag() > no_type_profile && profile_return_flag() <= type_profile_all;
1489 1489 }
1490 1490
1491 1491 bool MethodData::profile_return_jsr292_only() {
1492 1492 return profile_return_flag() == type_profile_jsr292;
1493 1493 }
1494 1494
1495 1495 bool MethodData::profile_all_return() {
1496 1496 return profile_return_flag() == type_profile_all;
1497 1497 }
1498 1498
1499 1499 bool MethodData::profile_return_for_invoke(methodHandle m, int bci) {
1500 1500 if (!profile_return()) {
1501 1501 return false;
1502 1502 }
1503 1503
1504 1504 if (profile_all_return()) {
1505 1505 return true;
1506 1506 }
1507 1507
1508 1508 assert(profile_return_jsr292_only(), "inconsistent");
1509 1509 return profile_jsr292(m, bci);
1510 1510 }
1511 1511
1512 1512 int MethodData::profile_parameters_flag() {
1513 1513 return TypeProfileLevel / 100;
1514 1514 }
1515 1515
1516 1516 bool MethodData::profile_parameters() {
1517 1517 return profile_parameters_flag() > no_type_profile && profile_parameters_flag() <= type_profile_all;
1518 1518 }
1519 1519
1520 1520 bool MethodData::profile_parameters_jsr292_only() {
1521 1521 return profile_parameters_flag() == type_profile_jsr292;
1522 1522 }
1523 1523
1524 1524 bool MethodData::profile_all_parameters() {
1525 1525 return profile_parameters_flag() == type_profile_all;
1526 1526 }
1527 1527
1528 1528 bool MethodData::profile_parameters_for_method(methodHandle m) {
1529 1529 if (!profile_parameters()) {
1530 1530 return false;
1531 1531 }
1532 1532
1533 1533 if (profile_all_parameters()) {
1534 1534 return true;
1535 1535 }
1536 1536
1537 1537 assert(profile_parameters_jsr292_only(), "inconsistent");
1538 1538 return m->is_compiled_lambda_form();
1539 1539 }
1540 1540
1541 1541 void MethodData::clean_extra_data_helper(DataLayout* dp, int shift, bool reset) {
1542 1542 if (shift == 0) {
1543 1543 return;
1544 1544 }
1545 1545 if (!reset) {
1546 1546 // Move all cells of trap entry at dp left by "shift" cells
1547 1547 intptr_t* start = (intptr_t*)dp;
1548 1548 intptr_t* end = (intptr_t*)next_extra(dp);
1549 1549 for (intptr_t* ptr = start; ptr < end; ptr++) {
1550 1550 *(ptr-shift) = *ptr;
1551 1551 }
1552 1552 } else {
1553 1553 // Reset "shift" cells stopping at dp
1554 1554 intptr_t* start = ((intptr_t*)dp) - shift;
1555 1555 intptr_t* end = (intptr_t*)dp;
1556 1556 for (intptr_t* ptr = start; ptr < end; ptr++) {
1557 1557 *ptr = 0;
1558 1558 }
1559 1559 }
1560 1560 }
1561 1561
1562 1562 // Remove SpeculativeTrapData entries that reference an unloaded
1563 1563 // method
1564 1564 void MethodData::clean_extra_data(BoolObjectClosure* is_alive) {
1565 1565 DataLayout* dp = extra_data_base();
1566 1566 DataLayout* end = extra_data_limit();
1567 1567
1568 1568 int shift = 0;
1569 1569 for (; dp < end; dp = next_extra(dp)) {
1570 1570 switch(dp->tag()) {
1571 1571 case DataLayout::speculative_trap_data_tag: {
1572 1572 SpeculativeTrapData* data = new SpeculativeTrapData(dp);
1573 1573 Method* m = data->method();
1574 1574 assert(m != NULL, "should have a method");
1575 1575 if (!m->method_holder()->is_loader_alive(is_alive)) {
1576 1576 // "shift" accumulates the number of cells for dead
1577 1577 // SpeculativeTrapData entries that have been seen so
1578 1578 // far. Following entries must be shifted left by that many
1579 1579 // cells to remove the dead SpeculativeTrapData entries.
1580 1580 shift += (int)((intptr_t*)next_extra(dp) - (intptr_t*)dp);
1581 1581 } else {
1582 1582 // Shift this entry left if it follows dead
1583 1583 // SpeculativeTrapData entries
1584 1584 clean_extra_data_helper(dp, shift);
1585 1585 }
1586 1586 break;
1587 1587 }
1588 1588 case DataLayout::bit_data_tag:
1589 1589 // Shift this entry left if it follows dead SpeculativeTrapData
1590 1590 // entries
1591 1591 clean_extra_data_helper(dp, shift);
1592 1592 continue;
1593 1593 case DataLayout::no_tag:
1594 1594 case DataLayout::arg_info_data_tag:
1595 1595 // We are at end of the live trap entries. The previous "shift"
1596 1596 // cells contain entries that are either dead or were shifted
1597 1597 // left. They need to be reset to no_tag
1598 1598 clean_extra_data_helper(dp, shift, true);
1599 1599 return;
1600 1600 default:
1601 1601 fatal(err_msg("unexpected tag %d", dp->tag()));
1602 1602 }
1603 1603 }
1604 1604 }
1605 1605
1606 1606 // Verify there's no unloaded method referenced by a
1607 1607 // SpeculativeTrapData entry
1608 1608 void MethodData::verify_extra_data_clean(BoolObjectClosure* is_alive) {
1609 1609 #ifdef ASSERT
1610 1610 DataLayout* dp = extra_data_base();
1611 1611 DataLayout* end = extra_data_limit();
1612 1612
1613 1613 for (; dp < end; dp = next_extra(dp)) {
1614 1614 switch(dp->tag()) {
1615 1615 case DataLayout::speculative_trap_data_tag: {
1616 1616 SpeculativeTrapData* data = new SpeculativeTrapData(dp);
1617 1617 Method* m = data->method();
1618 1618 assert(m != NULL && m->method_holder()->is_loader_alive(is_alive), "Method should exist");
1619 1619 break;
1620 1620 }
1621 1621 case DataLayout::bit_data_tag:
1622 1622 continue;
1623 1623 case DataLayout::no_tag:
1624 1624 case DataLayout::arg_info_data_tag:
1625 1625 return;
1626 1626 default:
1627 1627 fatal(err_msg("unexpected tag %d", dp->tag()));
1628 1628 }
1629 1629 }
1630 1630 #endif
1631 1631 }
1632 1632
1633 1633 void MethodData::clean_method_data(BoolObjectClosure* is_alive) {
1634 1634 for (ProfileData* data = first_data();
1635 1635 is_valid(data);
1636 1636 data = next_data(data)) {
1637 1637 data->clean_weak_klass_links(is_alive);
1638 1638 }
1639 1639 ParametersTypeData* parameters = parameters_type_data();
1640 1640 if (parameters != NULL) {
1641 1641 parameters->clean_weak_klass_links(is_alive);
1642 1642 }
1643 1643
1644 1644 clean_extra_data(is_alive);
1645 1645 verify_extra_data_clean(is_alive);
1646 1646 }
↓ open down ↓ |
480 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX