Mercurial > hg > graal-compiler
annotate src/share/vm/oops/methodDataOop.cpp @ 878:abe076e3636f
6864003: Modify JVM_FindClassFromBootLoader to return null if class not found
Summary: JVM_FindClassFromBootLoader returns null if class not found
Reviewed-by: acorn, alanb, dholmes
author | mchung |
---|---|
date | Mon, 27 Jul 2009 09:06:22 -0700 |
parents | be93aad57795 |
children | bd02caa94611 |
rev | line source |
---|---|
0 | 1 /* |
196 | 2 * Copyright 2000-2008 Sun Microsystems, Inc. All Rights Reserved. |
0 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
20 * CA 95054 USA or visit www.sun.com if you need additional information or | |
21 * have any questions. | |
22 * | |
23 */ | |
24 | |
25 # include "incls/_precompiled.incl" | |
26 # include "incls/_methodDataOop.cpp.incl" | |
27 | |
28 // ================================================================== | |
29 // DataLayout | |
30 // | |
31 // Overlay for generic profiling data. | |
32 | |
33 // Some types of data layouts need a length field. | |
34 bool DataLayout::needs_array_len(u1 tag) { | |
45
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
35 return (tag == multi_branch_data_tag) || (tag == arg_info_data_tag); |
0 | 36 } |
37 | |
38 // Perform generic initialization of the data. More specific | |
39 // initialization occurs in overrides of ProfileData::post_initialize. | |
40 void DataLayout::initialize(u1 tag, u2 bci, int cell_count) { | |
41 _header._bits = (intptr_t)0; | |
42 _header._struct._tag = tag; | |
43 _header._struct._bci = bci; | |
44 for (int i = 0; i < cell_count; i++) { | |
45 set_cell_at(i, (intptr_t)0); | |
46 } | |
47 if (needs_array_len(tag)) { | |
48 set_cell_at(ArrayData::array_len_off_set, cell_count - 1); // -1 for header. | |
49 } | |
50 } | |
51 | |
52 // ================================================================== | |
53 // ProfileData | |
54 // | |
55 // A ProfileData object is created to refer to a section of profiling | |
56 // data in a structured way. | |
57 | |
58 // Constructor for invalid ProfileData. | |
59 ProfileData::ProfileData() { | |
60 _data = NULL; | |
61 } | |
62 | |
63 #ifndef PRODUCT | |
64 void ProfileData::print_shared(outputStream* st, const char* name) { | |
65 st->print("bci: %d", bci()); | |
66 st->fill_to(tab_width_one); | |
67 st->print("%s", name); | |
68 tab(st); | |
69 int trap = trap_state(); | |
70 if (trap != 0) { | |
71 char buf[100]; | |
72 st->print("trap(%s) ", Deoptimization::format_trap_state(buf, sizeof(buf), trap)); | |
73 } | |
74 int flags = data()->flags(); | |
75 if (flags != 0) | |
76 st->print("flags(%d) ", flags); | |
77 } | |
78 | |
79 void ProfileData::tab(outputStream* st) { | |
80 st->fill_to(tab_width_two); | |
81 } | |
82 #endif // !PRODUCT | |
83 | |
84 // ================================================================== | |
85 // BitData | |
86 // | |
87 // A BitData corresponds to a one-bit flag. This is used to indicate | |
88 // whether a checkcast bytecode has seen a null value. | |
89 | |
90 | |
91 #ifndef PRODUCT | |
92 void BitData::print_data_on(outputStream* st) { | |
93 print_shared(st, "BitData"); | |
94 } | |
95 #endif // !PRODUCT | |
96 | |
97 // ================================================================== | |
98 // CounterData | |
99 // | |
100 // A CounterData corresponds to a simple counter. | |
101 | |
102 #ifndef PRODUCT | |
103 void CounterData::print_data_on(outputStream* st) { | |
104 print_shared(st, "CounterData"); | |
105 st->print_cr("count(%u)", count()); | |
106 } | |
107 #endif // !PRODUCT | |
108 | |
109 // ================================================================== | |
110 // JumpData | |
111 // | |
112 // A JumpData is used to access profiling information for a direct | |
113 // branch. It is a counter, used for counting the number of branches, | |
114 // plus a data displacement, used for realigning the data pointer to | |
115 // the corresponding target bci. | |
116 | |
117 void JumpData::post_initialize(BytecodeStream* stream, methodDataOop mdo) { | |
118 assert(stream->bci() == bci(), "wrong pos"); | |
119 int target; | |
120 Bytecodes::Code c = stream->code(); | |
121 if (c == Bytecodes::_goto_w || c == Bytecodes::_jsr_w) { | |
122 target = stream->dest_w(); | |
123 } else { | |
124 target = stream->dest(); | |
125 } | |
126 int my_di = mdo->dp_to_di(dp()); | |
127 int target_di = mdo->bci_to_di(target); | |
128 int offset = target_di - my_di; | |
129 set_displacement(offset); | |
130 } | |
131 | |
132 #ifndef PRODUCT | |
133 void JumpData::print_data_on(outputStream* st) { | |
134 print_shared(st, "JumpData"); | |
135 st->print_cr("taken(%u) displacement(%d)", taken(), displacement()); | |
136 } | |
137 #endif // !PRODUCT | |
138 | |
139 // ================================================================== | |
140 // ReceiverTypeData | |
141 // | |
142 // A ReceiverTypeData is used to access profiling information about a | |
143 // dynamic type check. It consists of a counter which counts the total times | |
144 // that the check is reached, and a series of (klassOop, count) pairs | |
145 // which are used to store a type profile for the receiver of the check. | |
146 | |
147 void ReceiverTypeData::follow_contents() { | |
148 for (uint row = 0; row < row_limit(); row++) { | |
149 if (receiver(row) != NULL) { | |
150 MarkSweep::mark_and_push(adr_receiver(row)); | |
151 } | |
152 } | |
153 } | |
154 | |
155 #ifndef SERIALGC | |
156 void ReceiverTypeData::follow_contents(ParCompactionManager* cm) { | |
157 for (uint row = 0; row < row_limit(); row++) { | |
158 if (receiver(row) != NULL) { | |
159 PSParallelCompact::mark_and_push(cm, adr_receiver(row)); | |
160 } | |
161 } | |
162 } | |
163 #endif // SERIALGC | |
164 | |
165 void ReceiverTypeData::oop_iterate(OopClosure* blk) { | |
166 for (uint row = 0; row < row_limit(); row++) { | |
167 if (receiver(row) != NULL) { | |
168 blk->do_oop(adr_receiver(row)); | |
169 } | |
170 } | |
171 } | |
172 | |
173 void ReceiverTypeData::oop_iterate_m(OopClosure* blk, MemRegion mr) { | |
174 for (uint row = 0; row < row_limit(); row++) { | |
175 if (receiver(row) != NULL) { | |
176 oop* adr = adr_receiver(row); | |
177 if (mr.contains(adr)) { | |
178 blk->do_oop(adr); | |
179 } | |
180 } | |
181 } | |
182 } | |
183 | |
184 void ReceiverTypeData::adjust_pointers() { | |
185 for (uint row = 0; row < row_limit(); row++) { | |
186 if (receiver(row) != NULL) { | |
187 MarkSweep::adjust_pointer(adr_receiver(row)); | |
188 } | |
189 } | |
190 } | |
191 | |
192 #ifndef SERIALGC | |
193 void ReceiverTypeData::update_pointers() { | |
194 for (uint row = 0; row < row_limit(); row++) { | |
195 if (receiver_unchecked(row) != NULL) { | |
196 PSParallelCompact::adjust_pointer(adr_receiver(row)); | |
197 } | |
198 } | |
199 } | |
200 | |
201 void ReceiverTypeData::update_pointers(HeapWord* beg_addr, HeapWord* end_addr) { | |
202 // The loop bounds could be computed based on beg_addr/end_addr and the | |
203 // boundary test hoisted outside the loop (see klassVTable for an example); | |
204 // however, row_limit() is small enough (2) to make that less efficient. | |
205 for (uint row = 0; row < row_limit(); row++) { | |
206 if (receiver_unchecked(row) != NULL) { | |
207 PSParallelCompact::adjust_pointer(adr_receiver(row), beg_addr, end_addr); | |
208 } | |
209 } | |
210 } | |
211 #endif // SERIALGC | |
212 | |
213 #ifndef PRODUCT | |
214 void ReceiverTypeData::print_receiver_data_on(outputStream* st) { | |
215 uint row; | |
216 int entries = 0; | |
217 for (row = 0; row < row_limit(); row++) { | |
218 if (receiver(row) != NULL) entries++; | |
219 } | |
220 st->print_cr("count(%u) entries(%u)", count(), entries); | |
221 for (row = 0; row < row_limit(); row++) { | |
222 if (receiver(row) != NULL) { | |
223 tab(st); | |
224 receiver(row)->print_value_on(st); | |
225 st->print_cr("(%u)", receiver_count(row)); | |
226 } | |
227 } | |
228 } | |
229 void ReceiverTypeData::print_data_on(outputStream* st) { | |
230 print_shared(st, "ReceiverTypeData"); | |
231 print_receiver_data_on(st); | |
232 } | |
233 void VirtualCallData::print_data_on(outputStream* st) { | |
234 print_shared(st, "VirtualCallData"); | |
235 print_receiver_data_on(st); | |
236 } | |
237 #endif // !PRODUCT | |
238 | |
239 // ================================================================== | |
240 // RetData | |
241 // | |
242 // A RetData is used to access profiling information for a ret bytecode. | |
243 // It is composed of a count of the number of times that the ret has | |
244 // been executed, followed by a series of triples of the form | |
245 // (bci, count, di) which count the number of times that some bci was the | |
246 // target of the ret and cache a corresponding displacement. | |
247 | |
248 void RetData::post_initialize(BytecodeStream* stream, methodDataOop mdo) { | |
249 for (uint row = 0; row < row_limit(); row++) { | |
250 set_bci_displacement(row, -1); | |
251 set_bci(row, no_bci); | |
252 } | |
253 // release so other threads see a consistent state. bci is used as | |
254 // a valid flag for bci_displacement. | |
255 OrderAccess::release(); | |
256 } | |
257 | |
258 // This routine needs to atomically update the RetData structure, so the | |
259 // caller needs to hold the RetData_lock before it gets here. Since taking | |
260 // the lock can block (and allow GC) and since RetData is a ProfileData is a | |
261 // wrapper around a derived oop, taking the lock in _this_ method will | |
262 // basically cause the 'this' pointer's _data field to contain junk after the | |
263 // lock. We require the caller to take the lock before making the ProfileData | |
264 // structure. Currently the only caller is InterpreterRuntime::update_mdp_for_ret | |
265 address RetData::fixup_ret(int return_bci, methodDataHandle h_mdo) { | |
266 // First find the mdp which corresponds to the return bci. | |
267 address mdp = h_mdo->bci_to_dp(return_bci); | |
268 | |
269 // Now check to see if any of the cache slots are open. | |
270 for (uint row = 0; row < row_limit(); row++) { | |
271 if (bci(row) == no_bci) { | |
272 set_bci_displacement(row, mdp - dp()); | |
273 set_bci_count(row, DataLayout::counter_increment); | |
274 // Barrier to ensure displacement is written before the bci; allows | |
275 // the interpreter to read displacement without fear of race condition. | |
276 release_set_bci(row, return_bci); | |
277 break; | |
278 } | |
279 } | |
280 return mdp; | |
281 } | |
282 | |
283 | |
284 #ifndef PRODUCT | |
285 void RetData::print_data_on(outputStream* st) { | |
286 print_shared(st, "RetData"); | |
287 uint row; | |
288 int entries = 0; | |
289 for (row = 0; row < row_limit(); row++) { | |
290 if (bci(row) != no_bci) entries++; | |
291 } | |
292 st->print_cr("count(%u) entries(%u)", count(), entries); | |
293 for (row = 0; row < row_limit(); row++) { | |
294 if (bci(row) != no_bci) { | |
295 tab(st); | |
296 st->print_cr("bci(%d: count(%u) displacement(%d))", | |
297 bci(row), bci_count(row), bci_displacement(row)); | |
298 } | |
299 } | |
300 } | |
301 #endif // !PRODUCT | |
302 | |
303 // ================================================================== | |
304 // BranchData | |
305 // | |
306 // A BranchData is used to access profiling data for a two-way branch. | |
307 // It consists of taken and not_taken counts as well as a data displacement | |
308 // for the taken case. | |
309 | |
310 void BranchData::post_initialize(BytecodeStream* stream, methodDataOop mdo) { | |
311 assert(stream->bci() == bci(), "wrong pos"); | |
312 int target = stream->dest(); | |
313 int my_di = mdo->dp_to_di(dp()); | |
314 int target_di = mdo->bci_to_di(target); | |
315 int offset = target_di - my_di; | |
316 set_displacement(offset); | |
317 } | |
318 | |
319 #ifndef PRODUCT | |
320 void BranchData::print_data_on(outputStream* st) { | |
321 print_shared(st, "BranchData"); | |
322 st->print_cr("taken(%u) displacement(%d)", | |
323 taken(), displacement()); | |
324 tab(st); | |
325 st->print_cr("not taken(%u)", not_taken()); | |
326 } | |
327 #endif | |
328 | |
329 // ================================================================== | |
330 // MultiBranchData | |
331 // | |
332 // A MultiBranchData is used to access profiling information for | |
333 // a multi-way branch (*switch bytecodes). It consists of a series | |
334 // of (count, displacement) pairs, which count the number of times each | |
335 // case was taken and specify the data displacment for each branch target. | |
336 | |
337 int MultiBranchData::compute_cell_count(BytecodeStream* stream) { | |
338 int cell_count = 0; | |
339 if (stream->code() == Bytecodes::_tableswitch) { | |
340 Bytecode_tableswitch* sw = Bytecode_tableswitch_at(stream->bcp()); | |
341 cell_count = 1 + per_case_cell_count * (1 + sw->length()); // 1 for default | |
342 } else { | |
343 Bytecode_lookupswitch* sw = Bytecode_lookupswitch_at(stream->bcp()); | |
344 cell_count = 1 + per_case_cell_count * (sw->number_of_pairs() + 1); // 1 for default | |
345 } | |
346 return cell_count; | |
347 } | |
348 | |
349 void MultiBranchData::post_initialize(BytecodeStream* stream, | |
350 methodDataOop mdo) { | |
351 assert(stream->bci() == bci(), "wrong pos"); | |
352 int target; | |
353 int my_di; | |
354 int target_di; | |
355 int offset; | |
356 if (stream->code() == Bytecodes::_tableswitch) { | |
357 Bytecode_tableswitch* sw = Bytecode_tableswitch_at(stream->bcp()); | |
358 int len = sw->length(); | |
359 assert(array_len() == per_case_cell_count * (len + 1), "wrong len"); | |
360 for (int count = 0; count < len; count++) { | |
361 target = sw->dest_offset_at(count) + bci(); | |
362 my_di = mdo->dp_to_di(dp()); | |
363 target_di = mdo->bci_to_di(target); | |
364 offset = target_di - my_di; | |
365 set_displacement_at(count, offset); | |
366 } | |
367 target = sw->default_offset() + bci(); | |
368 my_di = mdo->dp_to_di(dp()); | |
369 target_di = mdo->bci_to_di(target); | |
370 offset = target_di - my_di; | |
371 set_default_displacement(offset); | |
372 | |
373 } else { | |
374 Bytecode_lookupswitch* sw = Bytecode_lookupswitch_at(stream->bcp()); | |
375 int npairs = sw->number_of_pairs(); | |
376 assert(array_len() == per_case_cell_count * (npairs + 1), "wrong len"); | |
377 for (int count = 0; count < npairs; count++) { | |
378 LookupswitchPair *pair = sw->pair_at(count); | |
379 target = pair->offset() + bci(); | |
380 my_di = mdo->dp_to_di(dp()); | |
381 target_di = mdo->bci_to_di(target); | |
382 offset = target_di - my_di; | |
383 set_displacement_at(count, offset); | |
384 } | |
385 target = sw->default_offset() + bci(); | |
386 my_di = mdo->dp_to_di(dp()); | |
387 target_di = mdo->bci_to_di(target); | |
388 offset = target_di - my_di; | |
389 set_default_displacement(offset); | |
390 } | |
391 } | |
392 | |
393 #ifndef PRODUCT | |
394 void MultiBranchData::print_data_on(outputStream* st) { | |
395 print_shared(st, "MultiBranchData"); | |
396 st->print_cr("default_count(%u) displacement(%d)", | |
397 default_count(), default_displacement()); | |
398 int cases = number_of_cases(); | |
399 for (int i = 0; i < cases; i++) { | |
400 tab(st); | |
401 st->print_cr("count(%u) displacement(%d)", | |
402 count_at(i), displacement_at(i)); | |
403 } | |
404 } | |
405 #endif | |
406 | |
45
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
407 #ifndef PRODUCT |
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
408 void ArgInfoData::print_data_on(outputStream* st) { |
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
409 print_shared(st, "ArgInfoData"); |
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
410 int nargs = number_of_args(); |
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
411 for (int i = 0; i < nargs; i++) { |
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
412 st->print(" 0x%x", arg_modified(i)); |
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
413 } |
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
414 st->cr(); |
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
415 } |
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
416 |
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
417 #endif |
0 | 418 // ================================================================== |
419 // methodDataOop | |
420 // | |
421 // A methodDataOop holds information which has been collected about | |
422 // a method. | |
423 | |
424 int methodDataOopDesc::bytecode_cell_count(Bytecodes::Code code) { | |
425 switch (code) { | |
426 case Bytecodes::_checkcast: | |
427 case Bytecodes::_instanceof: | |
428 case Bytecodes::_aastore: | |
429 if (TypeProfileCasts) { | |
430 return ReceiverTypeData::static_cell_count(); | |
431 } else { | |
432 return BitData::static_cell_count(); | |
433 } | |
434 case Bytecodes::_invokespecial: | |
435 case Bytecodes::_invokestatic: | |
436 return CounterData::static_cell_count(); | |
437 case Bytecodes::_goto: | |
438 case Bytecodes::_goto_w: | |
439 case Bytecodes::_jsr: | |
440 case Bytecodes::_jsr_w: | |
441 return JumpData::static_cell_count(); | |
442 case Bytecodes::_invokevirtual: | |
443 case Bytecodes::_invokeinterface: | |
444 return VirtualCallData::static_cell_count(); | |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
196
diff
changeset
|
445 case Bytecodes::_invokedynamic: |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
196
diff
changeset
|
446 return CounterData::static_cell_count(); |
0 | 447 case Bytecodes::_ret: |
448 return RetData::static_cell_count(); | |
449 case Bytecodes::_ifeq: | |
450 case Bytecodes::_ifne: | |
451 case Bytecodes::_iflt: | |
452 case Bytecodes::_ifge: | |
453 case Bytecodes::_ifgt: | |
454 case Bytecodes::_ifle: | |
455 case Bytecodes::_if_icmpeq: | |
456 case Bytecodes::_if_icmpne: | |
457 case Bytecodes::_if_icmplt: | |
458 case Bytecodes::_if_icmpge: | |
459 case Bytecodes::_if_icmpgt: | |
460 case Bytecodes::_if_icmple: | |
461 case Bytecodes::_if_acmpeq: | |
462 case Bytecodes::_if_acmpne: | |
463 case Bytecodes::_ifnull: | |
464 case Bytecodes::_ifnonnull: | |
465 return BranchData::static_cell_count(); | |
466 case Bytecodes::_lookupswitch: | |
467 case Bytecodes::_tableswitch: | |
468 return variable_cell_count; | |
469 } | |
470 return no_profile_data; | |
471 } | |
472 | |
473 // Compute the size of the profiling information corresponding to | |
474 // the current bytecode. | |
475 int methodDataOopDesc::compute_data_size(BytecodeStream* stream) { | |
476 int cell_count = bytecode_cell_count(stream->code()); | |
477 if (cell_count == no_profile_data) { | |
478 return 0; | |
479 } | |
480 if (cell_count == variable_cell_count) { | |
481 cell_count = MultiBranchData::compute_cell_count(stream); | |
482 } | |
483 // Note: cell_count might be zero, meaning that there is just | |
484 // a DataLayout header, with no extra cells. | |
485 assert(cell_count >= 0, "sanity"); | |
486 return DataLayout::compute_size_in_bytes(cell_count); | |
487 } | |
488 | |
489 int methodDataOopDesc::compute_extra_data_count(int data_size, int empty_bc_count) { | |
490 if (ProfileTraps) { | |
491 // Assume that up to 3% of BCIs with no MDP will need to allocate one. | |
492 int extra_data_count = (uint)(empty_bc_count * 3) / 128 + 1; | |
493 // If the method is large, let the extra BCIs grow numerous (to ~1%). | |
494 int one_percent_of_data | |
495 = (uint)data_size / (DataLayout::header_size_in_bytes()*128); | |
496 if (extra_data_count < one_percent_of_data) | |
497 extra_data_count = one_percent_of_data; | |
498 if (extra_data_count > empty_bc_count) | |
499 extra_data_count = empty_bc_count; // no need for more | |
500 return extra_data_count; | |
501 } else { | |
502 return 0; | |
503 } | |
504 } | |
505 | |
506 // Compute the size of the methodDataOop necessary to store | |
507 // profiling information about a given method. Size is in bytes. | |
508 int methodDataOopDesc::compute_allocation_size_in_bytes(methodHandle method) { | |
509 int data_size = 0; | |
510 BytecodeStream stream(method); | |
511 Bytecodes::Code c; | |
512 int empty_bc_count = 0; // number of bytecodes lacking data | |
513 while ((c = stream.next()) >= 0) { | |
514 int size_in_bytes = compute_data_size(&stream); | |
515 data_size += size_in_bytes; | |
516 if (size_in_bytes == 0) empty_bc_count += 1; | |
517 } | |
518 int object_size = in_bytes(data_offset()) + data_size; | |
519 | |
520 // Add some extra DataLayout cells (at least one) to track stray traps. | |
521 int extra_data_count = compute_extra_data_count(data_size, empty_bc_count); | |
522 object_size += extra_data_count * DataLayout::compute_size_in_bytes(0); | |
523 | |
45
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
524 // Add a cell to record information about modified arguments. |
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
525 int arg_size = method->size_of_parameters(); |
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
526 object_size += DataLayout::compute_size_in_bytes(arg_size+1); |
0 | 527 return object_size; |
528 } | |
529 | |
530 // Compute the size of the methodDataOop necessary to store | |
531 // profiling information about a given method. Size is in words | |
532 int methodDataOopDesc::compute_allocation_size_in_words(methodHandle method) { | |
533 int byte_size = compute_allocation_size_in_bytes(method); | |
534 int word_size = align_size_up(byte_size, BytesPerWord) / BytesPerWord; | |
535 return align_object_size(word_size); | |
536 } | |
537 | |
538 // Initialize an individual data segment. Returns the size of | |
539 // the segment in bytes. | |
540 int methodDataOopDesc::initialize_data(BytecodeStream* stream, | |
541 int data_index) { | |
542 int cell_count = -1; | |
543 int tag = DataLayout::no_tag; | |
544 DataLayout* data_layout = data_layout_at(data_index); | |
545 Bytecodes::Code c = stream->code(); | |
546 switch (c) { | |
547 case Bytecodes::_checkcast: | |
548 case Bytecodes::_instanceof: | |
549 case Bytecodes::_aastore: | |
550 if (TypeProfileCasts) { | |
551 cell_count = ReceiverTypeData::static_cell_count(); | |
552 tag = DataLayout::receiver_type_data_tag; | |
553 } else { | |
554 cell_count = BitData::static_cell_count(); | |
555 tag = DataLayout::bit_data_tag; | |
556 } | |
557 break; | |
558 case Bytecodes::_invokespecial: | |
559 case Bytecodes::_invokestatic: | |
560 cell_count = CounterData::static_cell_count(); | |
561 tag = DataLayout::counter_data_tag; | |
562 break; | |
563 case Bytecodes::_goto: | |
564 case Bytecodes::_goto_w: | |
565 case Bytecodes::_jsr: | |
566 case Bytecodes::_jsr_w: | |
567 cell_count = JumpData::static_cell_count(); | |
568 tag = DataLayout::jump_data_tag; | |
569 break; | |
570 case Bytecodes::_invokevirtual: | |
571 case Bytecodes::_invokeinterface: | |
572 cell_count = VirtualCallData::static_cell_count(); | |
573 tag = DataLayout::virtual_call_data_tag; | |
574 break; | |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
196
diff
changeset
|
575 case Bytecodes::_invokedynamic: |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
196
diff
changeset
|
576 // %%% should make a type profile for any invokedynamic that takes a ref argument |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
196
diff
changeset
|
577 cell_count = CounterData::static_cell_count(); |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
196
diff
changeset
|
578 tag = DataLayout::counter_data_tag; |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
196
diff
changeset
|
579 break; |
0 | 580 case Bytecodes::_ret: |
581 cell_count = RetData::static_cell_count(); | |
582 tag = DataLayout::ret_data_tag; | |
583 break; | |
584 case Bytecodes::_ifeq: | |
585 case Bytecodes::_ifne: | |
586 case Bytecodes::_iflt: | |
587 case Bytecodes::_ifge: | |
588 case Bytecodes::_ifgt: | |
589 case Bytecodes::_ifle: | |
590 case Bytecodes::_if_icmpeq: | |
591 case Bytecodes::_if_icmpne: | |
592 case Bytecodes::_if_icmplt: | |
593 case Bytecodes::_if_icmpge: | |
594 case Bytecodes::_if_icmpgt: | |
595 case Bytecodes::_if_icmple: | |
596 case Bytecodes::_if_acmpeq: | |
597 case Bytecodes::_if_acmpne: | |
598 case Bytecodes::_ifnull: | |
599 case Bytecodes::_ifnonnull: | |
600 cell_count = BranchData::static_cell_count(); | |
601 tag = DataLayout::branch_data_tag; | |
602 break; | |
603 case Bytecodes::_lookupswitch: | |
604 case Bytecodes::_tableswitch: | |
605 cell_count = MultiBranchData::compute_cell_count(stream); | |
606 tag = DataLayout::multi_branch_data_tag; | |
607 break; | |
608 } | |
609 assert(tag == DataLayout::multi_branch_data_tag || | |
610 cell_count == bytecode_cell_count(c), "cell counts must agree"); | |
611 if (cell_count >= 0) { | |
612 assert(tag != DataLayout::no_tag, "bad tag"); | |
613 assert(bytecode_has_profile(c), "agree w/ BHP"); | |
614 data_layout->initialize(tag, stream->bci(), cell_count); | |
615 return DataLayout::compute_size_in_bytes(cell_count); | |
616 } else { | |
617 assert(!bytecode_has_profile(c), "agree w/ !BHP"); | |
618 return 0; | |
619 } | |
620 } | |
621 | |
622 // Get the data at an arbitrary (sort of) data index. | |
623 ProfileData* methodDataOopDesc::data_at(int data_index) { | |
624 if (out_of_bounds(data_index)) { | |
625 return NULL; | |
626 } | |
627 DataLayout* data_layout = data_layout_at(data_index); | |
628 | |
629 switch (data_layout->tag()) { | |
630 case DataLayout::no_tag: | |
631 default: | |
632 ShouldNotReachHere(); | |
633 return NULL; | |
634 case DataLayout::bit_data_tag: | |
635 return new BitData(data_layout); | |
636 case DataLayout::counter_data_tag: | |
637 return new CounterData(data_layout); | |
638 case DataLayout::jump_data_tag: | |
639 return new JumpData(data_layout); | |
640 case DataLayout::receiver_type_data_tag: | |
641 return new ReceiverTypeData(data_layout); | |
642 case DataLayout::virtual_call_data_tag: | |
643 return new VirtualCallData(data_layout); | |
644 case DataLayout::ret_data_tag: | |
645 return new RetData(data_layout); | |
646 case DataLayout::branch_data_tag: | |
647 return new BranchData(data_layout); | |
648 case DataLayout::multi_branch_data_tag: | |
649 return new MultiBranchData(data_layout); | |
45
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
650 case DataLayout::arg_info_data_tag: |
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
651 return new ArgInfoData(data_layout); |
0 | 652 }; |
653 } | |
654 | |
655 // Iteration over data. | |
656 ProfileData* methodDataOopDesc::next_data(ProfileData* current) { | |
657 int current_index = dp_to_di(current->dp()); | |
658 int next_index = current_index + current->size_in_bytes(); | |
659 ProfileData* next = data_at(next_index); | |
660 return next; | |
661 } | |
662 | |
663 // Give each of the data entries a chance to perform specific | |
664 // data initialization. | |
665 void methodDataOopDesc::post_initialize(BytecodeStream* stream) { | |
666 ResourceMark rm; | |
667 ProfileData* data; | |
668 for (data = first_data(); is_valid(data); data = next_data(data)) { | |
669 stream->set_start(data->bci()); | |
670 stream->next(); | |
671 data->post_initialize(stream, this); | |
672 } | |
673 } | |
674 | |
675 // Initialize the methodDataOop corresponding to a given method. | |
676 void methodDataOopDesc::initialize(methodHandle method) { | |
677 ResourceMark rm; | |
678 | |
679 // Set the method back-pointer. | |
680 _method = method(); | |
681 set_creation_mileage(mileage_of(method())); | |
682 | |
683 // Initialize flags and trap history. | |
684 _nof_decompiles = 0; | |
685 _nof_overflow_recompiles = 0; | |
686 _nof_overflow_traps = 0; | |
687 assert(sizeof(_trap_hist) % sizeof(HeapWord) == 0, "align"); | |
688 Copy::zero_to_words((HeapWord*) &_trap_hist, | |
689 sizeof(_trap_hist) / sizeof(HeapWord)); | |
690 | |
691 // Go through the bytecodes and allocate and initialize the | |
692 // corresponding data cells. | |
693 int data_size = 0; | |
694 int empty_bc_count = 0; // number of bytecodes lacking data | |
695 BytecodeStream stream(method); | |
696 Bytecodes::Code c; | |
697 while ((c = stream.next()) >= 0) { | |
698 int size_in_bytes = initialize_data(&stream, data_size); | |
699 data_size += size_in_bytes; | |
700 if (size_in_bytes == 0) empty_bc_count += 1; | |
701 } | |
702 _data_size = data_size; | |
703 int object_size = in_bytes(data_offset()) + data_size; | |
704 | |
705 // Add some extra DataLayout cells (at least one) to track stray traps. | |
706 int extra_data_count = compute_extra_data_count(data_size, empty_bc_count); | |
45
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
707 int extra_size = extra_data_count * DataLayout::compute_size_in_bytes(0); |
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
708 |
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
709 // Add a cell to record information about modified arguments. |
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
710 // Set up _args_modified array after traps cells so that |
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
711 // the code for traps cells works. |
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
712 DataLayout *dp = data_layout_at(data_size + extra_size); |
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
713 |
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
714 int arg_size = method->size_of_parameters(); |
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
715 dp->initialize(DataLayout::arg_info_data_tag, 0, arg_size+1); |
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
716 |
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
717 object_size += extra_size + DataLayout::compute_size_in_bytes(arg_size+1); |
0 | 718 |
719 // Set an initial hint. Don't use set_hint_di() because | |
720 // first_di() may be out of bounds if data_size is 0. | |
721 // In that situation, _hint_di is never used, but at | |
722 // least well-defined. | |
723 _hint_di = first_di(); | |
724 | |
725 post_initialize(&stream); | |
726 | |
727 set_object_is_parsable(object_size); | |
728 } | |
729 | |
730 // Get a measure of how much mileage the method has on it. | |
731 int methodDataOopDesc::mileage_of(methodOop method) { | |
732 int mileage = 0; | |
733 int iic = method->interpreter_invocation_count(); | |
734 if (mileage < iic) mileage = iic; | |
735 | |
736 InvocationCounter* ic = method->invocation_counter(); | |
737 InvocationCounter* bc = method->backedge_counter(); | |
738 | |
739 int icval = ic->count(); | |
740 if (ic->carry()) icval += CompileThreshold; | |
741 if (mileage < icval) mileage = icval; | |
742 int bcval = bc->count(); | |
743 if (bc->carry()) bcval += CompileThreshold; | |
744 if (mileage < bcval) mileage = bcval; | |
745 return mileage; | |
746 } | |
747 | |
748 bool methodDataOopDesc::is_mature() const { | |
749 uint current = mileage_of(_method); | |
750 uint initial = creation_mileage(); | |
751 if (current < initial) | |
752 return true; // some sort of overflow | |
753 uint target; | |
754 if (ProfileMaturityPercentage <= 0) | |
755 target = (uint) -ProfileMaturityPercentage; // absolute value | |
756 else | |
757 target = (uint)( (ProfileMaturityPercentage * CompileThreshold) / 100 ); | |
758 return (current >= initial + target); | |
759 } | |
760 | |
761 // Translate a bci to its corresponding data index (di). | |
762 address methodDataOopDesc::bci_to_dp(int bci) { | |
763 ResourceMark rm; | |
764 ProfileData* data = data_before(bci); | |
765 ProfileData* prev = NULL; | |
766 for ( ; is_valid(data); data = next_data(data)) { | |
767 if (data->bci() >= bci) { | |
768 if (data->bci() == bci) set_hint_di(dp_to_di(data->dp())); | |
769 else if (prev != NULL) set_hint_di(dp_to_di(prev->dp())); | |
770 return data->dp(); | |
771 } | |
772 prev = data; | |
773 } | |
774 return (address)limit_data_position(); | |
775 } | |
776 | |
777 // Translate a bci to its corresponding data, or NULL. | |
778 ProfileData* methodDataOopDesc::bci_to_data(int bci) { | |
779 ProfileData* data = data_before(bci); | |
780 for ( ; is_valid(data); data = next_data(data)) { | |
781 if (data->bci() == bci) { | |
782 set_hint_di(dp_to_di(data->dp())); | |
783 return data; | |
784 } else if (data->bci() > bci) { | |
785 break; | |
786 } | |
787 } | |
788 return bci_to_extra_data(bci, false); | |
789 } | |
790 | |
791 // Translate a bci to its corresponding extra data, or NULL. | |
792 ProfileData* methodDataOopDesc::bci_to_extra_data(int bci, bool create_if_missing) { | |
793 DataLayout* dp = extra_data_base(); | |
794 DataLayout* end = extra_data_limit(); | |
795 DataLayout* avail = NULL; | |
796 for (; dp < end; dp = next_extra(dp)) { | |
797 // No need for "OrderAccess::load_acquire" ops, | |
798 // since the data structure is monotonic. | |
799 if (dp->tag() == DataLayout::no_tag) break; | |
45
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
800 if (dp->tag() == DataLayout::arg_info_data_tag) { |
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
801 dp = end; // ArgInfoData is at the end of extra data section. |
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
802 break; |
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
803 } |
0 | 804 if (dp->bci() == bci) { |
805 assert(dp->tag() == DataLayout::bit_data_tag, "sane"); | |
806 return new BitData(dp); | |
807 } | |
808 } | |
809 if (create_if_missing && dp < end) { | |
810 // Allocate this one. There is no mutual exclusion, | |
811 // so two threads could allocate different BCIs to the | |
812 // same data layout. This means these extra data | |
813 // records, like most other MDO contents, must not be | |
814 // trusted too much. | |
815 DataLayout temp; | |
816 temp.initialize(DataLayout::bit_data_tag, bci, 0); | |
817 dp->release_set_header(temp.header()); | |
818 assert(dp->tag() == DataLayout::bit_data_tag, "sane"); | |
819 //NO: assert(dp->bci() == bci, "no concurrent allocation"); | |
820 return new BitData(dp); | |
821 } | |
822 return NULL; | |
823 } | |
824 | |
45
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
825 ArgInfoData *methodDataOopDesc::arg_info() { |
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
826 DataLayout* dp = extra_data_base(); |
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
827 DataLayout* end = extra_data_limit(); |
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
828 for (; dp < end; dp = next_extra(dp)) { |
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
829 if (dp->tag() == DataLayout::arg_info_data_tag) |
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
830 return new ArgInfoData(dp); |
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
831 } |
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
832 return NULL; |
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
833 } |
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
834 |
0 | 835 #ifndef PRODUCT |
836 void methodDataOopDesc::print_data_on(outputStream* st) { | |
837 ResourceMark rm; | |
838 ProfileData* data = first_data(); | |
839 for ( ; is_valid(data); data = next_data(data)) { | |
840 st->print("%d", dp_to_di(data->dp())); | |
841 st->fill_to(6); | |
842 data->print_data_on(st); | |
843 } | |
45
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
844 st->print_cr("--- Extra data:"); |
0 | 845 DataLayout* dp = extra_data_base(); |
846 DataLayout* end = extra_data_limit(); | |
847 for (; dp < end; dp = next_extra(dp)) { | |
848 // No need for "OrderAccess::load_acquire" ops, | |
849 // since the data structure is monotonic. | |
45
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
850 if (dp->tag() == DataLayout::no_tag) continue; |
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
851 if (dp->tag() == DataLayout::bit_data_tag) { |
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
852 data = new BitData(dp); |
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
853 } else { |
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
854 assert(dp->tag() == DataLayout::arg_info_data_tag, "must be BitData or ArgInfo"); |
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
855 data = new ArgInfoData(dp); |
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
856 dp = end; // ArgInfoData is at the end of extra data section. |
48a3fa21394b
6667615: (Escape Analysis) extend MDO to cache arguments escape state
kvn
parents:
0
diff
changeset
|
857 } |
0 | 858 st->print("%d", dp_to_di(data->dp())); |
859 st->fill_to(6); | |
860 data->print_data_on(st); | |
861 } | |
862 } | |
863 #endif | |
864 | |
865 void methodDataOopDesc::verify_data_on(outputStream* st) { | |
866 NEEDS_CLEANUP; | |
867 // not yet implemented. | |
868 } |