|
1 /* |
|
2 * Copyright 1999-2007 Sun Microsystems, Inc. All Rights Reserved. |
|
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/_ciMethod.cpp.incl" |
|
27 |
|
28 // ciMethod |
|
29 // |
|
30 // This class represents a methodOop in the HotSpot virtual |
|
31 // machine. |
|
32 |
|
33 |
|
34 // ------------------------------------------------------------------ |
|
35 // ciMethod::ciMethod |
|
36 // |
|
37 // Loaded method. |
|
38 ciMethod::ciMethod(methodHandle h_m) : ciObject(h_m) { |
|
39 assert(h_m() != NULL, "no null method"); |
|
40 |
|
41 // These fields are always filled in in loaded methods. |
|
42 _flags = ciFlags(h_m()->access_flags()); |
|
43 |
|
44 // Easy to compute, so fill them in now. |
|
45 _max_stack = h_m()->max_stack(); |
|
46 _max_locals = h_m()->max_locals(); |
|
47 _code_size = h_m()->code_size(); |
|
48 _intrinsic_id = h_m()->intrinsic_id(); |
|
49 _handler_count = h_m()->exception_table()->length() / 4; |
|
50 _uses_monitors = h_m()->access_flags().has_monitor_bytecodes(); |
|
51 _balanced_monitors = !_uses_monitors || h_m()->access_flags().is_monitor_matching(); |
|
52 _is_compilable = !h_m()->is_not_compilable(); |
|
53 // Lazy fields, filled in on demand. Require allocation. |
|
54 _code = NULL; |
|
55 _exception_handlers = NULL; |
|
56 _liveness = NULL; |
|
57 _bcea = NULL; |
|
58 _method_blocks = NULL; |
|
59 #ifdef COMPILER2 |
|
60 _flow = NULL; |
|
61 #endif // COMPILER2 |
|
62 |
|
63 if (JvmtiExport::can_hotswap_or_post_breakpoint() && _is_compilable) { |
|
64 // 6328518 check hotswap conditions under the right lock. |
|
65 MutexLocker locker(Compile_lock); |
|
66 if (Dependencies::check_evol_method(h_m()) != NULL) { |
|
67 _is_compilable = false; |
|
68 } |
|
69 } else { |
|
70 CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops()); |
|
71 } |
|
72 |
|
73 if (instanceKlass::cast(h_m()->method_holder())->is_linked()) { |
|
74 _can_be_statically_bound = h_m()->can_be_statically_bound(); |
|
75 } else { |
|
76 // Have to use a conservative value in this case. |
|
77 _can_be_statically_bound = false; |
|
78 } |
|
79 |
|
80 // Adjust the definition of this condition to be more useful: |
|
81 // %%% take these conditions into account in vtable generation |
|
82 if (!_can_be_statically_bound && h_m()->is_private()) |
|
83 _can_be_statically_bound = true; |
|
84 if (_can_be_statically_bound && h_m()->is_abstract()) |
|
85 _can_be_statically_bound = false; |
|
86 |
|
87 ciEnv *env = CURRENT_ENV; |
|
88 // generating _signature may allow GC and therefore move m. |
|
89 // These fields are always filled in. |
|
90 _name = env->get_object(h_m()->name())->as_symbol(); |
|
91 _holder = env->get_object(h_m()->method_holder())->as_instance_klass(); |
|
92 ciSymbol* sig_symbol = env->get_object(h_m()->signature())->as_symbol(); |
|
93 _signature = new (env->arena()) ciSignature(_holder, sig_symbol); |
|
94 _method_data = NULL; |
|
95 // Take a snapshot of these values, so they will be commensurate with the MDO. |
|
96 if (ProfileInterpreter) { |
|
97 int invcnt = h_m()->interpreter_invocation_count(); |
|
98 // if the value overflowed report it as max int |
|
99 _interpreter_invocation_count = invcnt < 0 ? max_jint : invcnt ; |
|
100 _interpreter_throwout_count = h_m()->interpreter_throwout_count(); |
|
101 } else { |
|
102 _interpreter_invocation_count = 0; |
|
103 _interpreter_throwout_count = 0; |
|
104 } |
|
105 if (_interpreter_invocation_count == 0) |
|
106 _interpreter_invocation_count = 1; |
|
107 } |
|
108 |
|
109 |
|
110 // ------------------------------------------------------------------ |
|
111 // ciMethod::ciMethod |
|
112 // |
|
113 // Unloaded method. |
|
114 ciMethod::ciMethod(ciInstanceKlass* holder, |
|
115 ciSymbol* name, |
|
116 ciSymbol* signature) : ciObject(ciMethodKlass::make()) { |
|
117 // These fields are always filled in. |
|
118 _name = name; |
|
119 _holder = holder; |
|
120 _signature = new (CURRENT_ENV->arena()) ciSignature(_holder, signature); |
|
121 _intrinsic_id = vmIntrinsics::_none; |
|
122 _liveness = NULL; |
|
123 _can_be_statically_bound = false; |
|
124 _bcea = NULL; |
|
125 _method_blocks = NULL; |
|
126 _method_data = NULL; |
|
127 #ifdef COMPILER2 |
|
128 _flow = NULL; |
|
129 #endif // COMPILER2 |
|
130 } |
|
131 |
|
132 |
|
133 // ------------------------------------------------------------------ |
|
134 // ciMethod::load_code |
|
135 // |
|
136 // Load the bytecodes and exception handler table for this method. |
|
137 void ciMethod::load_code() { |
|
138 VM_ENTRY_MARK; |
|
139 assert(is_loaded(), "only loaded methods have code"); |
|
140 |
|
141 methodOop me = get_methodOop(); |
|
142 Arena* arena = CURRENT_THREAD_ENV->arena(); |
|
143 |
|
144 // Load the bytecodes. |
|
145 _code = (address)arena->Amalloc(code_size()); |
|
146 memcpy(_code, me->code_base(), code_size()); |
|
147 |
|
148 // Revert any breakpoint bytecodes in ci's copy |
|
149 if (_is_compilable && me->number_of_breakpoints() > 0) { |
|
150 BreakpointInfo* bp = instanceKlass::cast(me->method_holder())->breakpoints(); |
|
151 for (; bp != NULL; bp = bp->next()) { |
|
152 if (bp->match(me)) { |
|
153 code_at_put(bp->bci(), bp->orig_bytecode()); |
|
154 } |
|
155 } |
|
156 } |
|
157 |
|
158 // And load the exception table. |
|
159 typeArrayOop exc_table = me->exception_table(); |
|
160 |
|
161 // Allocate one extra spot in our list of exceptions. This |
|
162 // last entry will be used to represent the possibility that |
|
163 // an exception escapes the method. See ciExceptionHandlerStream |
|
164 // for details. |
|
165 _exception_handlers = |
|
166 (ciExceptionHandler**)arena->Amalloc(sizeof(ciExceptionHandler*) |
|
167 * (_handler_count + 1)); |
|
168 if (_handler_count > 0) { |
|
169 for (int i=0; i<_handler_count; i++) { |
|
170 int base = i*4; |
|
171 _exception_handlers[i] = new (arena) ciExceptionHandler( |
|
172 holder(), |
|
173 /* start */ exc_table->int_at(base), |
|
174 /* limit */ exc_table->int_at(base+1), |
|
175 /* goto pc */ exc_table->int_at(base+2), |
|
176 /* cp index */ exc_table->int_at(base+3)); |
|
177 } |
|
178 } |
|
179 |
|
180 // Put an entry at the end of our list to represent the possibility |
|
181 // of exceptional exit. |
|
182 _exception_handlers[_handler_count] = |
|
183 new (arena) ciExceptionHandler(holder(), 0, code_size(), -1, 0); |
|
184 |
|
185 if (CIPrintMethodCodes) { |
|
186 print_codes(); |
|
187 } |
|
188 } |
|
189 |
|
190 |
|
191 // ------------------------------------------------------------------ |
|
192 // ciMethod::has_linenumber_table |
|
193 // |
|
194 // length unknown until decompression |
|
195 bool ciMethod::has_linenumber_table() const { |
|
196 check_is_loaded(); |
|
197 VM_ENTRY_MARK; |
|
198 return get_methodOop()->has_linenumber_table(); |
|
199 } |
|
200 |
|
201 |
|
202 // ------------------------------------------------------------------ |
|
203 // ciMethod::compressed_linenumber_table |
|
204 u_char* ciMethod::compressed_linenumber_table() const { |
|
205 check_is_loaded(); |
|
206 VM_ENTRY_MARK; |
|
207 return get_methodOop()->compressed_linenumber_table(); |
|
208 } |
|
209 |
|
210 |
|
211 // ------------------------------------------------------------------ |
|
212 // ciMethod::line_number_from_bci |
|
213 int ciMethod::line_number_from_bci(int bci) const { |
|
214 check_is_loaded(); |
|
215 VM_ENTRY_MARK; |
|
216 return get_methodOop()->line_number_from_bci(bci); |
|
217 } |
|
218 |
|
219 |
|
220 // ------------------------------------------------------------------ |
|
221 // ciMethod::vtable_index |
|
222 // |
|
223 // Get the position of this method's entry in the vtable, if any. |
|
224 int ciMethod::vtable_index() { |
|
225 check_is_loaded(); |
|
226 assert(holder()->is_linked(), "must be linked"); |
|
227 VM_ENTRY_MARK; |
|
228 return get_methodOop()->vtable_index(); |
|
229 } |
|
230 |
|
231 |
|
232 // ------------------------------------------------------------------ |
|
233 // ciMethod::native_entry |
|
234 // |
|
235 // Get the address of this method's native code, if any. |
|
236 address ciMethod::native_entry() { |
|
237 check_is_loaded(); |
|
238 assert(flags().is_native(), "must be native method"); |
|
239 VM_ENTRY_MARK; |
|
240 methodOop method = get_methodOop(); |
|
241 address entry = method->native_function(); |
|
242 assert(entry != NULL, "must be valid entry point"); |
|
243 return entry; |
|
244 } |
|
245 |
|
246 |
|
247 // ------------------------------------------------------------------ |
|
248 // ciMethod::interpreter_entry |
|
249 // |
|
250 // Get the entry point for running this method in the interpreter. |
|
251 address ciMethod::interpreter_entry() { |
|
252 check_is_loaded(); |
|
253 VM_ENTRY_MARK; |
|
254 methodHandle mh(THREAD, get_methodOop()); |
|
255 return Interpreter::entry_for_method(mh); |
|
256 } |
|
257 |
|
258 |
|
259 // ------------------------------------------------------------------ |
|
260 // ciMethod::uses_balanced_monitors |
|
261 // |
|
262 // Does this method use monitors in a strict stack-disciplined manner? |
|
263 bool ciMethod::has_balanced_monitors() { |
|
264 check_is_loaded(); |
|
265 if (_balanced_monitors) return true; |
|
266 |
|
267 // Analyze the method to see if monitors are used properly. |
|
268 VM_ENTRY_MARK; |
|
269 methodHandle method(THREAD, get_methodOop()); |
|
270 assert(method->has_monitor_bytecodes(), "should have checked this"); |
|
271 |
|
272 // Check to see if a previous compilation computed the |
|
273 // monitor-matching analysis. |
|
274 if (method->guaranteed_monitor_matching()) { |
|
275 _balanced_monitors = true; |
|
276 return true; |
|
277 } |
|
278 |
|
279 { |
|
280 EXCEPTION_MARK; |
|
281 ResourceMark rm(THREAD); |
|
282 GeneratePairingInfo gpi(method); |
|
283 gpi.compute_map(CATCH); |
|
284 if (!gpi.monitor_safe()) { |
|
285 return false; |
|
286 } |
|
287 method->set_guaranteed_monitor_matching(); |
|
288 _balanced_monitors = true; |
|
289 } |
|
290 return true; |
|
291 } |
|
292 |
|
293 |
|
294 // ------------------------------------------------------------------ |
|
295 // ciMethod::get_flow_analysis |
|
296 ciTypeFlow* ciMethod::get_flow_analysis() { |
|
297 #ifdef COMPILER2 |
|
298 if (_flow == NULL) { |
|
299 ciEnv* env = CURRENT_ENV; |
|
300 _flow = new (env->arena()) ciTypeFlow(env, this); |
|
301 _flow->do_flow(); |
|
302 } |
|
303 return _flow; |
|
304 #else // COMPILER2 |
|
305 ShouldNotReachHere(); |
|
306 return NULL; |
|
307 #endif // COMPILER2 |
|
308 } |
|
309 |
|
310 |
|
311 // ------------------------------------------------------------------ |
|
312 // ciMethod::get_osr_flow_analysis |
|
313 ciTypeFlow* ciMethod::get_osr_flow_analysis(int osr_bci) { |
|
314 #ifdef COMPILER2 |
|
315 // OSR entry points are always place after a call bytecode of some sort |
|
316 assert(osr_bci >= 0, "must supply valid OSR entry point"); |
|
317 ciEnv* env = CURRENT_ENV; |
|
318 ciTypeFlow* flow = new (env->arena()) ciTypeFlow(env, this, osr_bci); |
|
319 flow->do_flow(); |
|
320 return flow; |
|
321 #else // COMPILER2 |
|
322 ShouldNotReachHere(); |
|
323 return NULL; |
|
324 #endif // COMPILER2 |
|
325 } |
|
326 |
|
327 // ------------------------------------------------------------------ |
|
328 // ciMethod::liveness_at_bci |
|
329 // |
|
330 // Which local variables are live at a specific bci? |
|
331 MethodLivenessResult ciMethod::liveness_at_bci(int bci) { |
|
332 check_is_loaded(); |
|
333 if (_liveness == NULL) { |
|
334 // Create the liveness analyzer. |
|
335 Arena* arena = CURRENT_ENV->arena(); |
|
336 _liveness = new (arena) MethodLiveness(arena, this); |
|
337 _liveness->compute_liveness(); |
|
338 } |
|
339 MethodLivenessResult result = _liveness->get_liveness_at(bci); |
|
340 if (JvmtiExport::can_access_local_variables() || DeoptimizeALot || CompileTheWorld) { |
|
341 // Keep all locals live for the user's edification and amusement. |
|
342 result.at_put_range(0, result.size(), true); |
|
343 } |
|
344 return result; |
|
345 } |
|
346 |
|
347 // ciMethod::live_local_oops_at_bci |
|
348 // |
|
349 // find all the live oops in the locals array for a particular bci |
|
350 // Compute what the interpreter believes by using the interpreter |
|
351 // oopmap generator. This is used as a double check during osr to |
|
352 // guard against conservative result from MethodLiveness making us |
|
353 // think a dead oop is live. MethodLiveness is conservative in the |
|
354 // sense that it may consider locals to be live which cannot be live, |
|
355 // like in the case where a local could contain an oop or a primitive |
|
356 // along different paths. In that case the local must be dead when |
|
357 // those paths merge. Since the interpreter's viewpoint is used when |
|
358 // gc'ing an interpreter frame we need to use its viewpoint during |
|
359 // OSR when loading the locals. |
|
360 |
|
361 BitMap ciMethod::live_local_oops_at_bci(int bci) { |
|
362 VM_ENTRY_MARK; |
|
363 InterpreterOopMap mask; |
|
364 OopMapCache::compute_one_oop_map(get_methodOop(), bci, &mask); |
|
365 int mask_size = max_locals(); |
|
366 BitMap result(mask_size); |
|
367 result.clear(); |
|
368 int i; |
|
369 for (i = 0; i < mask_size ; i++ ) { |
|
370 if (mask.is_oop(i)) result.set_bit(i); |
|
371 } |
|
372 return result; |
|
373 } |
|
374 |
|
375 |
|
376 #ifdef COMPILER1 |
|
377 // ------------------------------------------------------------------ |
|
378 // ciMethod::bci_block_start |
|
379 // |
|
380 // Marks all bcis where a new basic block starts |
|
381 const BitMap ciMethod::bci_block_start() { |
|
382 check_is_loaded(); |
|
383 if (_liveness == NULL) { |
|
384 // Create the liveness analyzer. |
|
385 Arena* arena = CURRENT_ENV->arena(); |
|
386 _liveness = new (arena) MethodLiveness(arena, this); |
|
387 _liveness->compute_liveness(); |
|
388 } |
|
389 |
|
390 return _liveness->get_bci_block_start(); |
|
391 } |
|
392 #endif // COMPILER1 |
|
393 |
|
394 |
|
395 // ------------------------------------------------------------------ |
|
396 // ciMethod::call_profile_at_bci |
|
397 // |
|
398 // Get the ciCallProfile for the invocation of this method. |
|
399 // Also reports receiver types for non-call type checks (if TypeProfileCasts). |
|
400 ciCallProfile ciMethod::call_profile_at_bci(int bci) { |
|
401 ResourceMark rm; |
|
402 ciCallProfile result; |
|
403 if (method_data() != NULL && method_data()->is_mature()) { |
|
404 ciProfileData* data = method_data()->bci_to_data(bci); |
|
405 if (data != NULL && data->is_CounterData()) { |
|
406 // Every profiled call site has a counter. |
|
407 int count = data->as_CounterData()->count(); |
|
408 |
|
409 if (!data->is_ReceiverTypeData()) { |
|
410 result._receiver_count[0] = 0; // that's a definite zero |
|
411 } else { // ReceiverTypeData is a subclass of CounterData |
|
412 ciReceiverTypeData* call = (ciReceiverTypeData*)data->as_ReceiverTypeData(); |
|
413 // In addition, virtual call sites have receiver type information |
|
414 int receivers_count_total = 0; |
|
415 int morphism = 0; |
|
416 for (uint i = 0; i < call->row_limit(); i++) { |
|
417 ciKlass* receiver = call->receiver(i); |
|
418 if (receiver == NULL) continue; |
|
419 morphism += 1; |
|
420 int rcount = call->receiver_count(i); |
|
421 if (rcount == 0) rcount = 1; // Should be valid value |
|
422 receivers_count_total += rcount; |
|
423 // Add the receiver to result data. |
|
424 result.add_receiver(receiver, rcount); |
|
425 // If we extend profiling to record methods, |
|
426 // we will set result._method also. |
|
427 } |
|
428 // Determine call site's morphism. |
|
429 // The call site count could be == (receivers_count_total + 1) |
|
430 // not only in the case of a polymorphic call but also in the case |
|
431 // when a method data snapshot is taken after the site count was updated |
|
432 // but before receivers counters were updated. |
|
433 if (morphism == result._limit) { |
|
434 // There were no array klasses and morphism <= MorphismLimit. |
|
435 if (morphism < ciCallProfile::MorphismLimit || |
|
436 morphism == ciCallProfile::MorphismLimit && |
|
437 (receivers_count_total+1) >= count) { |
|
438 result._morphism = morphism; |
|
439 } |
|
440 } |
|
441 // Make the count consistent if this is a call profile. If count is |
|
442 // zero or less, presume that this is a typecheck profile and |
|
443 // do nothing. Otherwise, increase count to be the sum of all |
|
444 // receiver's counts. |
|
445 if (count > 0) { |
|
446 if (count < receivers_count_total) { |
|
447 count = receivers_count_total; |
|
448 } |
|
449 } |
|
450 } |
|
451 result._count = count; |
|
452 } |
|
453 } |
|
454 return result; |
|
455 } |
|
456 |
|
457 // ------------------------------------------------------------------ |
|
458 // Add new receiver and sort data by receiver's profile count. |
|
459 void ciCallProfile::add_receiver(ciKlass* receiver, int receiver_count) { |
|
460 // Add new receiver and sort data by receiver's counts when we have space |
|
461 // for it otherwise replace the less called receiver (less called receiver |
|
462 // is placed to the last array element which is not used). |
|
463 // First array's element contains most called receiver. |
|
464 int i = _limit; |
|
465 for (; i > 0 && receiver_count > _receiver_count[i-1]; i--) { |
|
466 _receiver[i] = _receiver[i-1]; |
|
467 _receiver_count[i] = _receiver_count[i-1]; |
|
468 } |
|
469 _receiver[i] = receiver; |
|
470 _receiver_count[i] = receiver_count; |
|
471 if (_limit < MorphismLimit) _limit++; |
|
472 } |
|
473 |
|
474 // ------------------------------------------------------------------ |
|
475 // ciMethod::find_monomorphic_target |
|
476 // |
|
477 // Given a certain calling environment, find the monomorphic target |
|
478 // for the call. Return NULL if the call is not monomorphic in |
|
479 // its calling environment, or if there are only abstract methods. |
|
480 // The returned method is never abstract. |
|
481 // Note: If caller uses a non-null result, it must inform dependencies |
|
482 // via assert_unique_concrete_method or assert_leaf_type. |
|
483 ciMethod* ciMethod::find_monomorphic_target(ciInstanceKlass* caller, |
|
484 ciInstanceKlass* callee_holder, |
|
485 ciInstanceKlass* actual_recv) { |
|
486 check_is_loaded(); |
|
487 |
|
488 if (actual_recv->is_interface()) { |
|
489 // %%% We cannot trust interface types, yet. See bug 6312651. |
|
490 return NULL; |
|
491 } |
|
492 |
|
493 ciMethod* root_m = resolve_invoke(caller, actual_recv); |
|
494 if (root_m == NULL) { |
|
495 // Something went wrong looking up the actual receiver method. |
|
496 return NULL; |
|
497 } |
|
498 assert(!root_m->is_abstract(), "resolve_invoke promise"); |
|
499 |
|
500 // Make certain quick checks even if UseCHA is false. |
|
501 |
|
502 // Is it private or final? |
|
503 if (root_m->can_be_statically_bound()) { |
|
504 return root_m; |
|
505 } |
|
506 |
|
507 if (actual_recv->is_leaf_type() && actual_recv == root_m->holder()) { |
|
508 // Easy case. There is no other place to put a method, so don't bother |
|
509 // to go through the VM_ENTRY_MARK and all the rest. |
|
510 return root_m; |
|
511 } |
|
512 |
|
513 // Array methods (clone, hashCode, etc.) are always statically bound. |
|
514 // If we were to see an array type here, we'd return root_m. |
|
515 // However, this method processes only ciInstanceKlasses. (See 4962591.) |
|
516 // The inline_native_clone intrinsic narrows Object to T[] properly, |
|
517 // so there is no need to do the same job here. |
|
518 |
|
519 if (!UseCHA) return NULL; |
|
520 |
|
521 VM_ENTRY_MARK; |
|
522 |
|
523 methodHandle target; |
|
524 { |
|
525 MutexLocker locker(Compile_lock); |
|
526 klassOop context = actual_recv->get_klassOop(); |
|
527 target = Dependencies::find_unique_concrete_method(context, |
|
528 root_m->get_methodOop()); |
|
529 // %%% Should upgrade this ciMethod API to look for 1 or 2 concrete methods. |
|
530 } |
|
531 |
|
532 #ifndef PRODUCT |
|
533 if (TraceDependencies && target() != NULL && target() != root_m->get_methodOop()) { |
|
534 tty->print("found a non-root unique target method"); |
|
535 tty->print_cr(" context = %s", instanceKlass::cast(actual_recv->get_klassOop())->external_name()); |
|
536 tty->print(" method = "); |
|
537 target->print_short_name(tty); |
|
538 tty->cr(); |
|
539 } |
|
540 #endif //PRODUCT |
|
541 |
|
542 if (target() == NULL) { |
|
543 return NULL; |
|
544 } |
|
545 if (target() == root_m->get_methodOop()) { |
|
546 return root_m; |
|
547 } |
|
548 if (!root_m->is_public() && |
|
549 !root_m->is_protected()) { |
|
550 // If we are going to reason about inheritance, it's easiest |
|
551 // if the method in question is public, protected, or private. |
|
552 // If the answer is not root_m, it is conservatively correct |
|
553 // to return NULL, even if the CHA encountered irrelevant |
|
554 // methods in other packages. |
|
555 // %%% TO DO: Work out logic for package-private methods |
|
556 // with the same name but different vtable indexes. |
|
557 return NULL; |
|
558 } |
|
559 return CURRENT_THREAD_ENV->get_object(target())->as_method(); |
|
560 } |
|
561 |
|
562 // ------------------------------------------------------------------ |
|
563 // ciMethod::resolve_invoke |
|
564 // |
|
565 // Given a known receiver klass, find the target for the call. |
|
566 // Return NULL if the call has no target or the target is abstract. |
|
567 ciMethod* ciMethod::resolve_invoke(ciKlass* caller, ciKlass* exact_receiver) { |
|
568 check_is_loaded(); |
|
569 VM_ENTRY_MARK; |
|
570 |
|
571 KlassHandle caller_klass (THREAD, caller->get_klassOop()); |
|
572 KlassHandle h_recv (THREAD, exact_receiver->get_klassOop()); |
|
573 KlassHandle h_resolved (THREAD, holder()->get_klassOop()); |
|
574 symbolHandle h_name (THREAD, name()->get_symbolOop()); |
|
575 symbolHandle h_signature (THREAD, signature()->get_symbolOop()); |
|
576 |
|
577 methodHandle m; |
|
578 // Only do exact lookup if receiver klass has been linked. Otherwise, |
|
579 // the vtable has not been setup, and the LinkResolver will fail. |
|
580 if (h_recv->oop_is_javaArray() |
|
581 || |
|
582 instanceKlass::cast(h_recv())->is_linked() && !exact_receiver->is_interface()) { |
|
583 if (holder()->is_interface()) { |
|
584 m = LinkResolver::resolve_interface_call_or_null(h_recv, h_resolved, h_name, h_signature, caller_klass); |
|
585 } else { |
|
586 m = LinkResolver::resolve_virtual_call_or_null(h_recv, h_resolved, h_name, h_signature, caller_klass); |
|
587 } |
|
588 } |
|
589 |
|
590 if (m.is_null()) { |
|
591 // Return NULL only if there was a problem with lookup (uninitialized class, etc.) |
|
592 return NULL; |
|
593 } |
|
594 |
|
595 ciMethod* result = this; |
|
596 if (m() != get_methodOop()) { |
|
597 result = CURRENT_THREAD_ENV->get_object(m())->as_method(); |
|
598 } |
|
599 |
|
600 // Don't return abstract methods because they aren't |
|
601 // optimizable or interesting. |
|
602 if (result->is_abstract()) { |
|
603 return NULL; |
|
604 } else { |
|
605 return result; |
|
606 } |
|
607 } |
|
608 |
|
609 // ------------------------------------------------------------------ |
|
610 // ciMethod::resolve_vtable_index |
|
611 // |
|
612 // Given a known receiver klass, find the vtable index for the call. |
|
613 // Return methodOopDesc::invalid_vtable_index if the vtable_index is unknown. |
|
614 int ciMethod::resolve_vtable_index(ciKlass* caller, ciKlass* receiver) { |
|
615 check_is_loaded(); |
|
616 |
|
617 int vtable_index = methodOopDesc::invalid_vtable_index; |
|
618 // Only do lookup if receiver klass has been linked. Otherwise, |
|
619 // the vtable has not been setup, and the LinkResolver will fail. |
|
620 if (!receiver->is_interface() |
|
621 && (!receiver->is_instance_klass() || |
|
622 receiver->as_instance_klass()->is_linked())) { |
|
623 VM_ENTRY_MARK; |
|
624 |
|
625 KlassHandle caller_klass (THREAD, caller->get_klassOop()); |
|
626 KlassHandle h_recv (THREAD, receiver->get_klassOop()); |
|
627 symbolHandle h_name (THREAD, name()->get_symbolOop()); |
|
628 symbolHandle h_signature (THREAD, signature()->get_symbolOop()); |
|
629 |
|
630 vtable_index = LinkResolver::resolve_virtual_vtable_index(h_recv, h_recv, h_name, h_signature, caller_klass); |
|
631 if (vtable_index == methodOopDesc::nonvirtual_vtable_index) { |
|
632 // A statically bound method. Return "no such index". |
|
633 vtable_index = methodOopDesc::invalid_vtable_index; |
|
634 } |
|
635 } |
|
636 |
|
637 return vtable_index; |
|
638 } |
|
639 |
|
640 // ------------------------------------------------------------------ |
|
641 // ciMethod::interpreter_call_site_count |
|
642 int ciMethod::interpreter_call_site_count(int bci) { |
|
643 if (method_data() != NULL) { |
|
644 ResourceMark rm; |
|
645 ciProfileData* data = method_data()->bci_to_data(bci); |
|
646 if (data != NULL && data->is_CounterData()) { |
|
647 return scale_count(data->as_CounterData()->count()); |
|
648 } |
|
649 } |
|
650 return -1; // unknown |
|
651 } |
|
652 |
|
653 // ------------------------------------------------------------------ |
|
654 // Adjust a CounterData count to be commensurate with |
|
655 // interpreter_invocation_count. If the MDO exists for |
|
656 // only 25% of the time the method exists, then the |
|
657 // counts in the MDO should be scaled by 4X, so that |
|
658 // they can be usefully and stably compared against the |
|
659 // invocation counts in methods. |
|
660 int ciMethod::scale_count(int count, float prof_factor) { |
|
661 if (count > 0 && method_data() != NULL) { |
|
662 int current_mileage = method_data()->current_mileage(); |
|
663 int creation_mileage = method_data()->creation_mileage(); |
|
664 int counter_life = current_mileage - creation_mileage; |
|
665 int method_life = interpreter_invocation_count(); |
|
666 // counter_life due to backedge_counter could be > method_life |
|
667 if (counter_life > method_life) |
|
668 counter_life = method_life; |
|
669 if (0 < counter_life && counter_life <= method_life) { |
|
670 count = (int)((double)count * prof_factor * method_life / counter_life + 0.5); |
|
671 count = (count > 0) ? count : 1; |
|
672 } |
|
673 } |
|
674 return count; |
|
675 } |
|
676 |
|
677 // ------------------------------------------------------------------ |
|
678 // ciMethod::build_method_data |
|
679 // |
|
680 // Generate new methodDataOop objects at compile time. |
|
681 void ciMethod::build_method_data(methodHandle h_m) { |
|
682 EXCEPTION_CONTEXT; |
|
683 if (is_native() || is_abstract() || h_m()->is_accessor()) return; |
|
684 if (h_m()->method_data() == NULL) { |
|
685 methodOopDesc::build_interpreter_method_data(h_m, THREAD); |
|
686 if (HAS_PENDING_EXCEPTION) { |
|
687 CLEAR_PENDING_EXCEPTION; |
|
688 } |
|
689 } |
|
690 if (h_m()->method_data() != NULL) { |
|
691 _method_data = CURRENT_ENV->get_object(h_m()->method_data())->as_method_data(); |
|
692 _method_data->load_data(); |
|
693 } else { |
|
694 _method_data = CURRENT_ENV->get_empty_methodData(); |
|
695 } |
|
696 } |
|
697 |
|
698 // public, retroactive version |
|
699 void ciMethod::build_method_data() { |
|
700 if (_method_data == NULL || _method_data->is_empty()) { |
|
701 GUARDED_VM_ENTRY({ |
|
702 build_method_data(get_methodOop()); |
|
703 }); |
|
704 } |
|
705 } |
|
706 |
|
707 |
|
708 // ------------------------------------------------------------------ |
|
709 // ciMethod::method_data |
|
710 // |
|
711 ciMethodData* ciMethod::method_data() { |
|
712 if (_method_data != NULL) { |
|
713 return _method_data; |
|
714 } |
|
715 VM_ENTRY_MARK; |
|
716 ciEnv* env = CURRENT_ENV; |
|
717 Thread* my_thread = JavaThread::current(); |
|
718 methodHandle h_m(my_thread, get_methodOop()); |
|
719 |
|
720 if (Tier1UpdateMethodData && is_tier1_compile(env->comp_level())) { |
|
721 build_method_data(h_m); |
|
722 } |
|
723 |
|
724 if (h_m()->method_data() != NULL) { |
|
725 _method_data = CURRENT_ENV->get_object(h_m()->method_data())->as_method_data(); |
|
726 _method_data->load_data(); |
|
727 } else { |
|
728 _method_data = CURRENT_ENV->get_empty_methodData(); |
|
729 } |
|
730 return _method_data; |
|
731 |
|
732 } |
|
733 |
|
734 |
|
735 // ------------------------------------------------------------------ |
|
736 // ciMethod::will_link |
|
737 // |
|
738 // Will this method link in a specific calling context? |
|
739 bool ciMethod::will_link(ciKlass* accessing_klass, |
|
740 ciKlass* declared_method_holder, |
|
741 Bytecodes::Code bc) { |
|
742 if (!is_loaded()) { |
|
743 // Method lookup failed. |
|
744 return false; |
|
745 } |
|
746 |
|
747 // The link checks have been front-loaded into the get_method |
|
748 // call. This method (ciMethod::will_link()) will be removed |
|
749 // in the future. |
|
750 |
|
751 return true; |
|
752 } |
|
753 |
|
754 // ------------------------------------------------------------------ |
|
755 // ciMethod::should_exclude |
|
756 // |
|
757 // Should this method be excluded from compilation? |
|
758 bool ciMethod::should_exclude() { |
|
759 check_is_loaded(); |
|
760 VM_ENTRY_MARK; |
|
761 methodHandle mh(THREAD, get_methodOop()); |
|
762 bool ignore; |
|
763 return CompilerOracle::should_exclude(mh, ignore); |
|
764 } |
|
765 |
|
766 // ------------------------------------------------------------------ |
|
767 // ciMethod::should_inline |
|
768 // |
|
769 // Should this method be inlined during compilation? |
|
770 bool ciMethod::should_inline() { |
|
771 check_is_loaded(); |
|
772 VM_ENTRY_MARK; |
|
773 methodHandle mh(THREAD, get_methodOop()); |
|
774 return CompilerOracle::should_inline(mh); |
|
775 } |
|
776 |
|
777 // ------------------------------------------------------------------ |
|
778 // ciMethod::should_not_inline |
|
779 // |
|
780 // Should this method be disallowed from inlining during compilation? |
|
781 bool ciMethod::should_not_inline() { |
|
782 check_is_loaded(); |
|
783 VM_ENTRY_MARK; |
|
784 methodHandle mh(THREAD, get_methodOop()); |
|
785 return CompilerOracle::should_not_inline(mh); |
|
786 } |
|
787 |
|
788 // ------------------------------------------------------------------ |
|
789 // ciMethod::should_print_assembly |
|
790 // |
|
791 // Should the compiler print the generated code for this method? |
|
792 bool ciMethod::should_print_assembly() { |
|
793 check_is_loaded(); |
|
794 VM_ENTRY_MARK; |
|
795 methodHandle mh(THREAD, get_methodOop()); |
|
796 return CompilerOracle::should_print(mh); |
|
797 } |
|
798 |
|
799 // ------------------------------------------------------------------ |
|
800 // ciMethod::break_at_execute |
|
801 // |
|
802 // Should the compiler insert a breakpoint into the generated code |
|
803 // method? |
|
804 bool ciMethod::break_at_execute() { |
|
805 check_is_loaded(); |
|
806 VM_ENTRY_MARK; |
|
807 methodHandle mh(THREAD, get_methodOop()); |
|
808 return CompilerOracle::should_break_at(mh); |
|
809 } |
|
810 |
|
811 // ------------------------------------------------------------------ |
|
812 // ciMethod::has_option |
|
813 // |
|
814 bool ciMethod::has_option(const char* option) { |
|
815 check_is_loaded(); |
|
816 VM_ENTRY_MARK; |
|
817 methodHandle mh(THREAD, get_methodOop()); |
|
818 return CompilerOracle::has_option_string(mh, option); |
|
819 } |
|
820 |
|
821 // ------------------------------------------------------------------ |
|
822 // ciMethod::can_be_compiled |
|
823 // |
|
824 // Have previous compilations of this method succeeded? |
|
825 bool ciMethod::can_be_compiled() { |
|
826 check_is_loaded(); |
|
827 return _is_compilable; |
|
828 } |
|
829 |
|
830 // ------------------------------------------------------------------ |
|
831 // ciMethod::set_not_compilable |
|
832 // |
|
833 // Tell the VM that this method cannot be compiled at all. |
|
834 void ciMethod::set_not_compilable() { |
|
835 check_is_loaded(); |
|
836 VM_ENTRY_MARK; |
|
837 _is_compilable = false; |
|
838 get_methodOop()->set_not_compilable(); |
|
839 } |
|
840 |
|
841 // ------------------------------------------------------------------ |
|
842 // ciMethod::can_be_osr_compiled |
|
843 // |
|
844 // Have previous compilations of this method succeeded? |
|
845 // |
|
846 // Implementation note: the VM does not currently keep track |
|
847 // of failed OSR compilations per bci. The entry_bci parameter |
|
848 // is currently unused. |
|
849 bool ciMethod::can_be_osr_compiled(int entry_bci) { |
|
850 check_is_loaded(); |
|
851 VM_ENTRY_MARK; |
|
852 return !get_methodOop()->access_flags().is_not_osr_compilable(); |
|
853 } |
|
854 |
|
855 // ------------------------------------------------------------------ |
|
856 // ciMethod::has_compiled_code |
|
857 bool ciMethod::has_compiled_code() { |
|
858 VM_ENTRY_MARK; |
|
859 return get_methodOop()->code() != NULL; |
|
860 } |
|
861 |
|
862 // ------------------------------------------------------------------ |
|
863 // ciMethod::instructions_size |
|
864 // This is a rough metric for "fat" methods, compared |
|
865 // before inlining with InlineSmallCode. |
|
866 // The CodeBlob::instructions_size accessor includes |
|
867 // junk like exception handler, stubs, and constant table, |
|
868 // which are not highly relevant to an inlined method. |
|
869 // So we use the more specific accessor nmethod::code_size. |
|
870 int ciMethod::instructions_size() { |
|
871 GUARDED_VM_ENTRY( |
|
872 nmethod* code = get_methodOop()->code(); |
|
873 // if there's no compiled code or the code was produced by the |
|
874 // tier1 profiler return 0 for the code size. This should |
|
875 // probably be based on the compilation level of the nmethod but |
|
876 // that currently isn't properly recorded. |
|
877 if (code == NULL || |
|
878 (TieredCompilation && code->compiler() != NULL && code->compiler()->is_c1())) { |
|
879 return 0; |
|
880 } |
|
881 return code->code_size(); |
|
882 ) |
|
883 } |
|
884 |
|
885 // ------------------------------------------------------------------ |
|
886 // ciMethod::log_nmethod_identity |
|
887 void ciMethod::log_nmethod_identity(xmlStream* log) { |
|
888 GUARDED_VM_ENTRY( |
|
889 nmethod* code = get_methodOop()->code(); |
|
890 if (code != NULL) { |
|
891 code->log_identity(log); |
|
892 } |
|
893 ) |
|
894 } |
|
895 |
|
896 // ------------------------------------------------------------------ |
|
897 // ciMethod::is_not_reached |
|
898 bool ciMethod::is_not_reached(int bci) { |
|
899 check_is_loaded(); |
|
900 VM_ENTRY_MARK; |
|
901 return Interpreter::is_not_reached( |
|
902 methodHandle(THREAD, get_methodOop()), bci); |
|
903 } |
|
904 |
|
905 // ------------------------------------------------------------------ |
|
906 // ciMethod::was_never_executed |
|
907 bool ciMethod::was_executed_more_than(int times) { |
|
908 VM_ENTRY_MARK; |
|
909 return get_methodOop()->was_executed_more_than(times); |
|
910 } |
|
911 |
|
912 // ------------------------------------------------------------------ |
|
913 // ciMethod::has_unloaded_classes_in_signature |
|
914 bool ciMethod::has_unloaded_classes_in_signature() { |
|
915 VM_ENTRY_MARK; |
|
916 { |
|
917 EXCEPTION_MARK; |
|
918 methodHandle m(THREAD, get_methodOop()); |
|
919 bool has_unloaded = methodOopDesc::has_unloaded_classes_in_signature(m, (JavaThread *)THREAD); |
|
920 if( HAS_PENDING_EXCEPTION ) { |
|
921 CLEAR_PENDING_EXCEPTION; |
|
922 return true; // Declare that we may have unloaded classes |
|
923 } |
|
924 return has_unloaded; |
|
925 } |
|
926 } |
|
927 |
|
928 // ------------------------------------------------------------------ |
|
929 // ciMethod::is_klass_loaded |
|
930 bool ciMethod::is_klass_loaded(int refinfo_index, bool must_be_resolved) const { |
|
931 VM_ENTRY_MARK; |
|
932 return get_methodOop()->is_klass_loaded(refinfo_index, must_be_resolved); |
|
933 } |
|
934 |
|
935 // ------------------------------------------------------------------ |
|
936 // ciMethod::check_call |
|
937 bool ciMethod::check_call(int refinfo_index, bool is_static) const { |
|
938 VM_ENTRY_MARK; |
|
939 { |
|
940 EXCEPTION_MARK; |
|
941 HandleMark hm(THREAD); |
|
942 constantPoolHandle pool (THREAD, get_methodOop()->constants()); |
|
943 methodHandle spec_method; |
|
944 KlassHandle spec_klass; |
|
945 LinkResolver::resolve_method(spec_method, spec_klass, pool, refinfo_index, THREAD); |
|
946 if (HAS_PENDING_EXCEPTION) { |
|
947 CLEAR_PENDING_EXCEPTION; |
|
948 return false; |
|
949 } else { |
|
950 return (spec_method->is_static() == is_static); |
|
951 } |
|
952 } |
|
953 return false; |
|
954 } |
|
955 |
|
956 // ------------------------------------------------------------------ |
|
957 // ciMethod::print_codes |
|
958 // |
|
959 // Print the bytecodes for this method. |
|
960 void ciMethod::print_codes_on(outputStream* st) { |
|
961 check_is_loaded(); |
|
962 GUARDED_VM_ENTRY(get_methodOop()->print_codes_on(st);) |
|
963 } |
|
964 |
|
965 |
|
966 #define FETCH_FLAG_FROM_VM(flag_accessor) { \ |
|
967 check_is_loaded(); \ |
|
968 VM_ENTRY_MARK; \ |
|
969 return get_methodOop()->flag_accessor(); \ |
|
970 } |
|
971 |
|
972 bool ciMethod::is_empty_method() const { FETCH_FLAG_FROM_VM(is_empty_method); } |
|
973 bool ciMethod::is_vanilla_constructor() const { FETCH_FLAG_FROM_VM(is_vanilla_constructor); } |
|
974 bool ciMethod::has_loops () const { FETCH_FLAG_FROM_VM(has_loops); } |
|
975 bool ciMethod::has_jsrs () const { FETCH_FLAG_FROM_VM(has_jsrs); } |
|
976 bool ciMethod::is_accessor () const { FETCH_FLAG_FROM_VM(is_accessor); } |
|
977 bool ciMethod::is_initializer () const { FETCH_FLAG_FROM_VM(is_initializer); } |
|
978 |
|
979 BCEscapeAnalyzer *ciMethod::get_bcea() { |
|
980 if (_bcea == NULL) { |
|
981 _bcea = new (CURRENT_ENV->arena()) BCEscapeAnalyzer(this, NULL); |
|
982 } |
|
983 return _bcea; |
|
984 } |
|
985 |
|
986 ciMethodBlocks *ciMethod::get_method_blocks() { |
|
987 Arena *arena = CURRENT_ENV->arena(); |
|
988 if (_method_blocks == NULL) { |
|
989 _method_blocks = new (arena) ciMethodBlocks(arena, this); |
|
990 } |
|
991 return _method_blocks; |
|
992 } |
|
993 |
|
994 #undef FETCH_FLAG_FROM_VM |
|
995 |
|
996 |
|
997 // ------------------------------------------------------------------ |
|
998 // ciMethod::print_codes |
|
999 // |
|
1000 // Print a range of the bytecodes for this method. |
|
1001 void ciMethod::print_codes_on(int from, int to, outputStream* st) { |
|
1002 check_is_loaded(); |
|
1003 GUARDED_VM_ENTRY(get_methodOop()->print_codes_on(from, to, st);) |
|
1004 } |
|
1005 |
|
1006 // ------------------------------------------------------------------ |
|
1007 // ciMethod::print_name |
|
1008 // |
|
1009 // Print the name of this method, including signature and some flags. |
|
1010 void ciMethod::print_name(outputStream* st) { |
|
1011 check_is_loaded(); |
|
1012 GUARDED_VM_ENTRY(get_methodOop()->print_name(st);) |
|
1013 } |
|
1014 |
|
1015 // ------------------------------------------------------------------ |
|
1016 // ciMethod::print_short_name |
|
1017 // |
|
1018 // Print the name of this method, without signature. |
|
1019 void ciMethod::print_short_name(outputStream* st) { |
|
1020 check_is_loaded(); |
|
1021 GUARDED_VM_ENTRY(get_methodOop()->print_short_name(st);) |
|
1022 } |
|
1023 |
|
1024 // ------------------------------------------------------------------ |
|
1025 // ciMethod::print_impl |
|
1026 // |
|
1027 // Implementation of the print method. |
|
1028 void ciMethod::print_impl(outputStream* st) { |
|
1029 ciObject::print_impl(st); |
|
1030 st->print(" name="); |
|
1031 name()->print_symbol_on(st); |
|
1032 st->print(" holder="); |
|
1033 holder()->print_name_on(st); |
|
1034 st->print(" signature="); |
|
1035 signature()->as_symbol()->print_symbol_on(st); |
|
1036 if (is_loaded()) { |
|
1037 st->print(" loaded=true flags="); |
|
1038 flags().print_member_flags(st); |
|
1039 } else { |
|
1040 st->print(" loaded=false"); |
|
1041 } |
|
1042 } |