Wed, 25 Aug 2010 05:27:54 -0700
6978355: renaming for 6961697
Summary: This is the renaming part of 6961697 to keep the actual changes small for review.
Reviewed-by: kvn, never
1 /*
2 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
25 #include "incls/_precompiled.incl"
26 #include "incls/_ciMethod.cpp.incl"
28 // ciMethod
29 //
30 // This class represents a methodOop in the HotSpot virtual
31 // machine.
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");
41 // These fields are always filled in in loaded methods.
42 _flags = ciFlags(h_m()->access_flags());
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 _method_blocks = NULL;
58 #if defined(COMPILER2) || defined(SHARK)
59 _flow = NULL;
60 _bcea = NULL;
61 #endif // COMPILER2 || SHARK
63 ciEnv *env = CURRENT_ENV;
64 if (env->jvmti_can_hotswap_or_post_breakpoint() && _is_compilable) {
65 // 6328518 check hotswap conditions under the right lock.
66 MutexLocker locker(Compile_lock);
67 if (Dependencies::check_evol_method(h_m()) != NULL) {
68 _is_compilable = false;
69 }
70 } else {
71 CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops());
72 }
74 if (instanceKlass::cast(h_m()->method_holder())->is_linked()) {
75 _can_be_statically_bound = h_m()->can_be_statically_bound();
76 } else {
77 // Have to use a conservative value in this case.
78 _can_be_statically_bound = false;
79 }
81 // Adjust the definition of this condition to be more useful:
82 // %%% take these conditions into account in vtable generation
83 if (!_can_be_statically_bound && h_m()->is_private())
84 _can_be_statically_bound = true;
85 if (_can_be_statically_bound && h_m()->is_abstract())
86 _can_be_statically_bound = false;
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 }
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 _method_blocks = NULL;
125 _method_data = NULL;
126 #if defined(COMPILER2) || defined(SHARK)
127 _flow = NULL;
128 _bcea = NULL;
129 #endif // COMPILER2 || SHARK
130 }
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");
141 methodOop me = get_methodOop();
142 Arena* arena = CURRENT_THREAD_ENV->arena();
144 // Load the bytecodes.
145 _code = (address)arena->Amalloc(code_size());
146 memcpy(_code, me->code_base(), code_size());
148 // Revert any breakpoint bytecodes in ci's copy
149 if (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 }
158 // And load the exception table.
159 typeArrayOop exc_table = me->exception_table();
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 }
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);
185 if (CIPrintMethodCodes) {
186 print_codes();
187 }
188 }
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 }
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 }
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 }
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 }
232 #ifdef SHARK
233 // ------------------------------------------------------------------
234 // ciMethod::itable_index
235 //
236 // Get the position of this method's entry in the itable, if any.
237 int ciMethod::itable_index() {
238 check_is_loaded();
239 assert(holder()->is_linked(), "must be linked");
240 VM_ENTRY_MARK;
241 return klassItable::compute_itable_index(get_methodOop());
242 }
243 #endif // SHARK
246 // ------------------------------------------------------------------
247 // ciMethod::native_entry
248 //
249 // Get the address of this method's native code, if any.
250 address ciMethod::native_entry() {
251 check_is_loaded();
252 assert(flags().is_native(), "must be native method");
253 VM_ENTRY_MARK;
254 methodOop method = get_methodOop();
255 address entry = method->native_function();
256 assert(entry != NULL, "must be valid entry point");
257 return entry;
258 }
261 // ------------------------------------------------------------------
262 // ciMethod::interpreter_entry
263 //
264 // Get the entry point for running this method in the interpreter.
265 address ciMethod::interpreter_entry() {
266 check_is_loaded();
267 VM_ENTRY_MARK;
268 methodHandle mh(THREAD, get_methodOop());
269 return Interpreter::entry_for_method(mh);
270 }
273 // ------------------------------------------------------------------
274 // ciMethod::uses_balanced_monitors
275 //
276 // Does this method use monitors in a strict stack-disciplined manner?
277 bool ciMethod::has_balanced_monitors() {
278 check_is_loaded();
279 if (_balanced_monitors) return true;
281 // Analyze the method to see if monitors are used properly.
282 VM_ENTRY_MARK;
283 methodHandle method(THREAD, get_methodOop());
284 assert(method->has_monitor_bytecodes(), "should have checked this");
286 // Check to see if a previous compilation computed the
287 // monitor-matching analysis.
288 if (method->guaranteed_monitor_matching()) {
289 _balanced_monitors = true;
290 return true;
291 }
293 {
294 EXCEPTION_MARK;
295 ResourceMark rm(THREAD);
296 GeneratePairingInfo gpi(method);
297 gpi.compute_map(CATCH);
298 if (!gpi.monitor_safe()) {
299 return false;
300 }
301 method->set_guaranteed_monitor_matching();
302 _balanced_monitors = true;
303 }
304 return true;
305 }
308 // ------------------------------------------------------------------
309 // ciMethod::get_flow_analysis
310 ciTypeFlow* ciMethod::get_flow_analysis() {
311 #if defined(COMPILER2) || defined(SHARK)
312 if (_flow == NULL) {
313 ciEnv* env = CURRENT_ENV;
314 _flow = new (env->arena()) ciTypeFlow(env, this);
315 _flow->do_flow();
316 }
317 return _flow;
318 #else // COMPILER2 || SHARK
319 ShouldNotReachHere();
320 return NULL;
321 #endif // COMPILER2 || SHARK
322 }
325 // ------------------------------------------------------------------
326 // ciMethod::get_osr_flow_analysis
327 ciTypeFlow* ciMethod::get_osr_flow_analysis(int osr_bci) {
328 #if defined(COMPILER2) || defined(SHARK)
329 // OSR entry points are always place after a call bytecode of some sort
330 assert(osr_bci >= 0, "must supply valid OSR entry point");
331 ciEnv* env = CURRENT_ENV;
332 ciTypeFlow* flow = new (env->arena()) ciTypeFlow(env, this, osr_bci);
333 flow->do_flow();
334 return flow;
335 #else // COMPILER2 || SHARK
336 ShouldNotReachHere();
337 return NULL;
338 #endif // COMPILER2 || SHARK
339 }
341 // ------------------------------------------------------------------
342 // ciMethod::raw_liveness_at_bci
343 //
344 // Which local variables are live at a specific bci?
345 MethodLivenessResult ciMethod::raw_liveness_at_bci(int bci) {
346 check_is_loaded();
347 if (_liveness == NULL) {
348 // Create the liveness analyzer.
349 Arena* arena = CURRENT_ENV->arena();
350 _liveness = new (arena) MethodLiveness(arena, this);
351 _liveness->compute_liveness();
352 }
353 return _liveness->get_liveness_at(bci);
354 }
356 // ------------------------------------------------------------------
357 // ciMethod::liveness_at_bci
358 //
359 // Which local variables are live at a specific bci? When debugging
360 // will return true for all locals in some cases to improve debug
361 // information.
362 MethodLivenessResult ciMethod::liveness_at_bci(int bci) {
363 MethodLivenessResult result = raw_liveness_at_bci(bci);
364 if (CURRENT_ENV->jvmti_can_access_local_variables() || DeoptimizeALot || CompileTheWorld) {
365 // Keep all locals live for the user's edification and amusement.
366 result.at_put_range(0, result.size(), true);
367 }
368 return result;
369 }
371 // ciMethod::live_local_oops_at_bci
372 //
373 // find all the live oops in the locals array for a particular bci
374 // Compute what the interpreter believes by using the interpreter
375 // oopmap generator. This is used as a double check during osr to
376 // guard against conservative result from MethodLiveness making us
377 // think a dead oop is live. MethodLiveness is conservative in the
378 // sense that it may consider locals to be live which cannot be live,
379 // like in the case where a local could contain an oop or a primitive
380 // along different paths. In that case the local must be dead when
381 // those paths merge. Since the interpreter's viewpoint is used when
382 // gc'ing an interpreter frame we need to use its viewpoint during
383 // OSR when loading the locals.
385 BitMap ciMethod::live_local_oops_at_bci(int bci) {
386 VM_ENTRY_MARK;
387 InterpreterOopMap mask;
388 OopMapCache::compute_one_oop_map(get_methodOop(), bci, &mask);
389 int mask_size = max_locals();
390 BitMap result(mask_size);
391 result.clear();
392 int i;
393 for (i = 0; i < mask_size ; i++ ) {
394 if (mask.is_oop(i)) result.set_bit(i);
395 }
396 return result;
397 }
400 #ifdef COMPILER1
401 // ------------------------------------------------------------------
402 // ciMethod::bci_block_start
403 //
404 // Marks all bcis where a new basic block starts
405 const BitMap ciMethod::bci_block_start() {
406 check_is_loaded();
407 if (_liveness == NULL) {
408 // Create the liveness analyzer.
409 Arena* arena = CURRENT_ENV->arena();
410 _liveness = new (arena) MethodLiveness(arena, this);
411 _liveness->compute_liveness();
412 }
414 return _liveness->get_bci_block_start();
415 }
416 #endif // COMPILER1
419 // ------------------------------------------------------------------
420 // ciMethod::call_profile_at_bci
421 //
422 // Get the ciCallProfile for the invocation of this method.
423 // Also reports receiver types for non-call type checks (if TypeProfileCasts).
424 ciCallProfile ciMethod::call_profile_at_bci(int bci) {
425 ResourceMark rm;
426 ciCallProfile result;
427 if (method_data() != NULL && method_data()->is_mature()) {
428 ciProfileData* data = method_data()->bci_to_data(bci);
429 if (data != NULL && data->is_CounterData()) {
430 // Every profiled call site has a counter.
431 int count = data->as_CounterData()->count();
433 if (!data->is_ReceiverTypeData()) {
434 result._receiver_count[0] = 0; // that's a definite zero
435 } else { // ReceiverTypeData is a subclass of CounterData
436 ciReceiverTypeData* call = (ciReceiverTypeData*)data->as_ReceiverTypeData();
437 // In addition, virtual call sites have receiver type information
438 int receivers_count_total = 0;
439 int morphism = 0;
440 for (uint i = 0; i < call->row_limit(); i++) {
441 ciKlass* receiver = call->receiver(i);
442 if (receiver == NULL) continue;
443 morphism += 1;
444 int rcount = call->receiver_count(i);
445 if (rcount == 0) rcount = 1; // Should be valid value
446 receivers_count_total += rcount;
447 // Add the receiver to result data.
448 result.add_receiver(receiver, rcount);
449 // If we extend profiling to record methods,
450 // we will set result._method also.
451 }
452 // Determine call site's morphism.
453 // The call site count is 0 with known morphism (onlt 1 or 2 receivers)
454 // or < 0 in the case of a type check failured for checkcast, aastore, instanceof.
455 // The call site count is > 0 in the case of a polymorphic virtual call.
456 if (morphism > 0 && morphism == result._limit) {
457 // The morphism <= MorphismLimit.
458 if ((morphism < ciCallProfile::MorphismLimit) ||
459 (morphism == ciCallProfile::MorphismLimit && count == 0)) {
460 #ifdef ASSERT
461 if (count > 0) {
462 this->print_short_name(tty);
463 tty->print_cr(" @ bci:%d", bci);
464 this->print_codes();
465 assert(false, "this call site should not be polymorphic");
466 }
467 #endif
468 result._morphism = morphism;
469 }
470 }
471 // Make the count consistent if this is a call profile. If count is
472 // zero or less, presume that this is a typecheck profile and
473 // do nothing. Otherwise, increase count to be the sum of all
474 // receiver's counts.
475 if (count >= 0) {
476 count += receivers_count_total;
477 }
478 }
479 result._count = count;
480 }
481 }
482 return result;
483 }
485 // ------------------------------------------------------------------
486 // Add new receiver and sort data by receiver's profile count.
487 void ciCallProfile::add_receiver(ciKlass* receiver, int receiver_count) {
488 // Add new receiver and sort data by receiver's counts when we have space
489 // for it otherwise replace the less called receiver (less called receiver
490 // is placed to the last array element which is not used).
491 // First array's element contains most called receiver.
492 int i = _limit;
493 for (; i > 0 && receiver_count > _receiver_count[i-1]; i--) {
494 _receiver[i] = _receiver[i-1];
495 _receiver_count[i] = _receiver_count[i-1];
496 }
497 _receiver[i] = receiver;
498 _receiver_count[i] = receiver_count;
499 if (_limit < MorphismLimit) _limit++;
500 }
502 // ------------------------------------------------------------------
503 // ciMethod::find_monomorphic_target
504 //
505 // Given a certain calling environment, find the monomorphic target
506 // for the call. Return NULL if the call is not monomorphic in
507 // its calling environment, or if there are only abstract methods.
508 // The returned method is never abstract.
509 // Note: If caller uses a non-null result, it must inform dependencies
510 // via assert_unique_concrete_method or assert_leaf_type.
511 ciMethod* ciMethod::find_monomorphic_target(ciInstanceKlass* caller,
512 ciInstanceKlass* callee_holder,
513 ciInstanceKlass* actual_recv) {
514 check_is_loaded();
516 if (actual_recv->is_interface()) {
517 // %%% We cannot trust interface types, yet. See bug 6312651.
518 return NULL;
519 }
521 ciMethod* root_m = resolve_invoke(caller, actual_recv);
522 if (root_m == NULL) {
523 // Something went wrong looking up the actual receiver method.
524 return NULL;
525 }
526 assert(!root_m->is_abstract(), "resolve_invoke promise");
528 // Make certain quick checks even if UseCHA is false.
530 // Is it private or final?
531 if (root_m->can_be_statically_bound()) {
532 return root_m;
533 }
535 if (actual_recv->is_leaf_type() && actual_recv == root_m->holder()) {
536 // Easy case. There is no other place to put a method, so don't bother
537 // to go through the VM_ENTRY_MARK and all the rest.
538 return root_m;
539 }
541 // Array methods (clone, hashCode, etc.) are always statically bound.
542 // If we were to see an array type here, we'd return root_m.
543 // However, this method processes only ciInstanceKlasses. (See 4962591.)
544 // The inline_native_clone intrinsic narrows Object to T[] properly,
545 // so there is no need to do the same job here.
547 if (!UseCHA) return NULL;
549 VM_ENTRY_MARK;
551 methodHandle target;
552 {
553 MutexLocker locker(Compile_lock);
554 klassOop context = actual_recv->get_klassOop();
555 target = Dependencies::find_unique_concrete_method(context,
556 root_m->get_methodOop());
557 // %%% Should upgrade this ciMethod API to look for 1 or 2 concrete methods.
558 }
560 #ifndef PRODUCT
561 if (TraceDependencies && target() != NULL && target() != root_m->get_methodOop()) {
562 tty->print("found a non-root unique target method");
563 tty->print_cr(" context = %s", instanceKlass::cast(actual_recv->get_klassOop())->external_name());
564 tty->print(" method = ");
565 target->print_short_name(tty);
566 tty->cr();
567 }
568 #endif //PRODUCT
570 if (target() == NULL) {
571 return NULL;
572 }
573 if (target() == root_m->get_methodOop()) {
574 return root_m;
575 }
576 if (!root_m->is_public() &&
577 !root_m->is_protected()) {
578 // If we are going to reason about inheritance, it's easiest
579 // if the method in question is public, protected, or private.
580 // If the answer is not root_m, it is conservatively correct
581 // to return NULL, even if the CHA encountered irrelevant
582 // methods in other packages.
583 // %%% TO DO: Work out logic for package-private methods
584 // with the same name but different vtable indexes.
585 return NULL;
586 }
587 return CURRENT_THREAD_ENV->get_object(target())->as_method();
588 }
590 // ------------------------------------------------------------------
591 // ciMethod::resolve_invoke
592 //
593 // Given a known receiver klass, find the target for the call.
594 // Return NULL if the call has no target or the target is abstract.
595 ciMethod* ciMethod::resolve_invoke(ciKlass* caller, ciKlass* exact_receiver) {
596 check_is_loaded();
597 VM_ENTRY_MARK;
599 KlassHandle caller_klass (THREAD, caller->get_klassOop());
600 KlassHandle h_recv (THREAD, exact_receiver->get_klassOop());
601 KlassHandle h_resolved (THREAD, holder()->get_klassOop());
602 symbolHandle h_name (THREAD, name()->get_symbolOop());
603 symbolHandle h_signature (THREAD, signature()->get_symbolOop());
605 methodHandle m;
606 // Only do exact lookup if receiver klass has been linked. Otherwise,
607 // the vtable has not been setup, and the LinkResolver will fail.
608 if (h_recv->oop_is_javaArray()
609 ||
610 instanceKlass::cast(h_recv())->is_linked() && !exact_receiver->is_interface()) {
611 if (holder()->is_interface()) {
612 m = LinkResolver::resolve_interface_call_or_null(h_recv, h_resolved, h_name, h_signature, caller_klass);
613 } else {
614 m = LinkResolver::resolve_virtual_call_or_null(h_recv, h_resolved, h_name, h_signature, caller_klass);
615 }
616 }
618 if (m.is_null()) {
619 // Return NULL only if there was a problem with lookup (uninitialized class, etc.)
620 return NULL;
621 }
623 ciMethod* result = this;
624 if (m() != get_methodOop()) {
625 result = CURRENT_THREAD_ENV->get_object(m())->as_method();
626 }
628 // Don't return abstract methods because they aren't
629 // optimizable or interesting.
630 if (result->is_abstract()) {
631 return NULL;
632 } else {
633 return result;
634 }
635 }
637 // ------------------------------------------------------------------
638 // ciMethod::resolve_vtable_index
639 //
640 // Given a known receiver klass, find the vtable index for the call.
641 // Return methodOopDesc::invalid_vtable_index if the vtable_index is unknown.
642 int ciMethod::resolve_vtable_index(ciKlass* caller, ciKlass* receiver) {
643 check_is_loaded();
645 int vtable_index = methodOopDesc::invalid_vtable_index;
646 // Only do lookup if receiver klass has been linked. Otherwise,
647 // the vtable has not been setup, and the LinkResolver will fail.
648 if (!receiver->is_interface()
649 && (!receiver->is_instance_klass() ||
650 receiver->as_instance_klass()->is_linked())) {
651 VM_ENTRY_MARK;
653 KlassHandle caller_klass (THREAD, caller->get_klassOop());
654 KlassHandle h_recv (THREAD, receiver->get_klassOop());
655 symbolHandle h_name (THREAD, name()->get_symbolOop());
656 symbolHandle h_signature (THREAD, signature()->get_symbolOop());
658 vtable_index = LinkResolver::resolve_virtual_vtable_index(h_recv, h_recv, h_name, h_signature, caller_klass);
659 if (vtable_index == methodOopDesc::nonvirtual_vtable_index) {
660 // A statically bound method. Return "no such index".
661 vtable_index = methodOopDesc::invalid_vtable_index;
662 }
663 }
665 return vtable_index;
666 }
668 // ------------------------------------------------------------------
669 // ciMethod::interpreter_call_site_count
670 int ciMethod::interpreter_call_site_count(int bci) {
671 if (method_data() != NULL) {
672 ResourceMark rm;
673 ciProfileData* data = method_data()->bci_to_data(bci);
674 if (data != NULL && data->is_CounterData()) {
675 return scale_count(data->as_CounterData()->count());
676 }
677 }
678 return -1; // unknown
679 }
681 // ------------------------------------------------------------------
682 // Adjust a CounterData count to be commensurate with
683 // interpreter_invocation_count. If the MDO exists for
684 // only 25% of the time the method exists, then the
685 // counts in the MDO should be scaled by 4X, so that
686 // they can be usefully and stably compared against the
687 // invocation counts in methods.
688 int ciMethod::scale_count(int count, float prof_factor) {
689 if (count > 0 && method_data() != NULL) {
690 int current_mileage = method_data()->current_mileage();
691 int creation_mileage = method_data()->creation_mileage();
692 int counter_life = current_mileage - creation_mileage;
693 int method_life = interpreter_invocation_count();
694 // counter_life due to backedge_counter could be > method_life
695 if (counter_life > method_life)
696 counter_life = method_life;
697 if (0 < counter_life && counter_life <= method_life) {
698 count = (int)((double)count * prof_factor * method_life / counter_life + 0.5);
699 count = (count > 0) ? count : 1;
700 }
701 }
702 return count;
703 }
705 // ------------------------------------------------------------------
706 // invokedynamic support
708 // ------------------------------------------------------------------
709 // ciMethod::is_method_handle_invoke
710 //
711 // Return true if the method is an instance of one of the two
712 // signature-polymorphic MethodHandle methods, invokeExact or invokeGeneric.
713 bool ciMethod::is_method_handle_invoke() const {
714 if (!is_loaded()) return false;
715 VM_ENTRY_MARK;
716 return get_methodOop()->is_method_handle_invoke();
717 }
719 // ------------------------------------------------------------------
720 // ciMethod::is_method_handle_adapter
721 //
722 // Return true if the method is a generated MethodHandle adapter.
723 // These are built by MethodHandleCompiler.
724 bool ciMethod::is_method_handle_adapter() const {
725 if (!is_loaded()) return false;
726 VM_ENTRY_MARK;
727 return get_methodOop()->is_method_handle_adapter();
728 }
730 ciInstance* ciMethod::method_handle_type() {
731 check_is_loaded();
732 VM_ENTRY_MARK;
733 oop mtype = get_methodOop()->method_handle_type();
734 return CURRENT_THREAD_ENV->get_object(mtype)->as_instance();
735 }
738 // ------------------------------------------------------------------
739 // ciMethod::build_method_data
740 //
741 // Generate new methodDataOop objects at compile time.
742 void ciMethod::build_method_data(methodHandle h_m) {
743 EXCEPTION_CONTEXT;
744 if (is_native() || is_abstract() || h_m()->is_accessor()) return;
745 if (h_m()->method_data() == NULL) {
746 methodOopDesc::build_interpreter_method_data(h_m, THREAD);
747 if (HAS_PENDING_EXCEPTION) {
748 CLEAR_PENDING_EXCEPTION;
749 }
750 }
751 if (h_m()->method_data() != NULL) {
752 _method_data = CURRENT_ENV->get_object(h_m()->method_data())->as_method_data();
753 _method_data->load_data();
754 } else {
755 _method_data = CURRENT_ENV->get_empty_methodData();
756 }
757 }
759 // public, retroactive version
760 void ciMethod::build_method_data() {
761 if (_method_data == NULL || _method_data->is_empty()) {
762 GUARDED_VM_ENTRY({
763 build_method_data(get_methodOop());
764 });
765 }
766 }
769 // ------------------------------------------------------------------
770 // ciMethod::method_data
771 //
772 ciMethodData* ciMethod::method_data() {
773 if (_method_data != NULL) {
774 return _method_data;
775 }
776 VM_ENTRY_MARK;
777 ciEnv* env = CURRENT_ENV;
778 Thread* my_thread = JavaThread::current();
779 methodHandle h_m(my_thread, get_methodOop());
781 if (Tier1UpdateMethodData && is_tier1_compile(env->comp_level())) {
782 build_method_data(h_m);
783 }
785 if (h_m()->method_data() != NULL) {
786 _method_data = CURRENT_ENV->get_object(h_m()->method_data())->as_method_data();
787 _method_data->load_data();
788 } else {
789 _method_data = CURRENT_ENV->get_empty_methodData();
790 }
791 return _method_data;
793 }
796 // ------------------------------------------------------------------
797 // ciMethod::will_link
798 //
799 // Will this method link in a specific calling context?
800 bool ciMethod::will_link(ciKlass* accessing_klass,
801 ciKlass* declared_method_holder,
802 Bytecodes::Code bc) {
803 if (!is_loaded()) {
804 // Method lookup failed.
805 return false;
806 }
808 // The link checks have been front-loaded into the get_method
809 // call. This method (ciMethod::will_link()) will be removed
810 // in the future.
812 return true;
813 }
815 // ------------------------------------------------------------------
816 // ciMethod::should_exclude
817 //
818 // Should this method be excluded from compilation?
819 bool ciMethod::should_exclude() {
820 check_is_loaded();
821 VM_ENTRY_MARK;
822 methodHandle mh(THREAD, get_methodOop());
823 bool ignore;
824 return CompilerOracle::should_exclude(mh, ignore);
825 }
827 // ------------------------------------------------------------------
828 // ciMethod::should_inline
829 //
830 // Should this method be inlined during compilation?
831 bool ciMethod::should_inline() {
832 check_is_loaded();
833 VM_ENTRY_MARK;
834 methodHandle mh(THREAD, get_methodOop());
835 return CompilerOracle::should_inline(mh);
836 }
838 // ------------------------------------------------------------------
839 // ciMethod::should_not_inline
840 //
841 // Should this method be disallowed from inlining during compilation?
842 bool ciMethod::should_not_inline() {
843 check_is_loaded();
844 VM_ENTRY_MARK;
845 methodHandle mh(THREAD, get_methodOop());
846 return CompilerOracle::should_not_inline(mh);
847 }
849 // ------------------------------------------------------------------
850 // ciMethod::should_print_assembly
851 //
852 // Should the compiler print the generated code for this method?
853 bool ciMethod::should_print_assembly() {
854 check_is_loaded();
855 VM_ENTRY_MARK;
856 methodHandle mh(THREAD, get_methodOop());
857 return CompilerOracle::should_print(mh);
858 }
860 // ------------------------------------------------------------------
861 // ciMethod::break_at_execute
862 //
863 // Should the compiler insert a breakpoint into the generated code
864 // method?
865 bool ciMethod::break_at_execute() {
866 check_is_loaded();
867 VM_ENTRY_MARK;
868 methodHandle mh(THREAD, get_methodOop());
869 return CompilerOracle::should_break_at(mh);
870 }
872 // ------------------------------------------------------------------
873 // ciMethod::has_option
874 //
875 bool ciMethod::has_option(const char* option) {
876 check_is_loaded();
877 VM_ENTRY_MARK;
878 methodHandle mh(THREAD, get_methodOop());
879 return CompilerOracle::has_option_string(mh, option);
880 }
882 // ------------------------------------------------------------------
883 // ciMethod::can_be_compiled
884 //
885 // Have previous compilations of this method succeeded?
886 bool ciMethod::can_be_compiled() {
887 check_is_loaded();
888 return _is_compilable;
889 }
891 // ------------------------------------------------------------------
892 // ciMethod::set_not_compilable
893 //
894 // Tell the VM that this method cannot be compiled at all.
895 void ciMethod::set_not_compilable() {
896 check_is_loaded();
897 VM_ENTRY_MARK;
898 _is_compilable = false;
899 get_methodOop()->set_not_compilable();
900 }
902 // ------------------------------------------------------------------
903 // ciMethod::can_be_osr_compiled
904 //
905 // Have previous compilations of this method succeeded?
906 //
907 // Implementation note: the VM does not currently keep track
908 // of failed OSR compilations per bci. The entry_bci parameter
909 // is currently unused.
910 bool ciMethod::can_be_osr_compiled(int entry_bci) {
911 check_is_loaded();
912 VM_ENTRY_MARK;
913 return !get_methodOop()->access_flags().is_not_osr_compilable();
914 }
916 // ------------------------------------------------------------------
917 // ciMethod::has_compiled_code
918 bool ciMethod::has_compiled_code() {
919 VM_ENTRY_MARK;
920 return get_methodOop()->code() != NULL;
921 }
923 // ------------------------------------------------------------------
924 // ciMethod::instructions_size
925 //
926 // This is a rough metric for "fat" methods, compared before inlining
927 // with InlineSmallCode. The CodeBlob::code_size accessor includes
928 // junk like exception handler, stubs, and constant table, which are
929 // not highly relevant to an inlined method. So we use the more
930 // specific accessor nmethod::insts_size.
931 int ciMethod::instructions_size() {
932 GUARDED_VM_ENTRY(
933 nmethod* code = get_methodOop()->code();
934 // if there's no compiled code or the code was produced by the
935 // tier1 profiler return 0 for the code size. This should
936 // probably be based on the compilation level of the nmethod but
937 // that currently isn't properly recorded.
938 if (code == NULL ||
939 (TieredCompilation && code->compiler() != NULL && code->compiler()->is_c1())) {
940 return 0;
941 }
942 return code->insts_end() - code->verified_entry_point();
943 )
944 }
946 // ------------------------------------------------------------------
947 // ciMethod::log_nmethod_identity
948 void ciMethod::log_nmethod_identity(xmlStream* log) {
949 GUARDED_VM_ENTRY(
950 nmethod* code = get_methodOop()->code();
951 if (code != NULL) {
952 code->log_identity(log);
953 }
954 )
955 }
957 // ------------------------------------------------------------------
958 // ciMethod::is_not_reached
959 bool ciMethod::is_not_reached(int bci) {
960 check_is_loaded();
961 VM_ENTRY_MARK;
962 return Interpreter::is_not_reached(
963 methodHandle(THREAD, get_methodOop()), bci);
964 }
966 // ------------------------------------------------------------------
967 // ciMethod::was_never_executed
968 bool ciMethod::was_executed_more_than(int times) {
969 VM_ENTRY_MARK;
970 return get_methodOop()->was_executed_more_than(times);
971 }
973 // ------------------------------------------------------------------
974 // ciMethod::has_unloaded_classes_in_signature
975 bool ciMethod::has_unloaded_classes_in_signature() {
976 VM_ENTRY_MARK;
977 {
978 EXCEPTION_MARK;
979 methodHandle m(THREAD, get_methodOop());
980 bool has_unloaded = methodOopDesc::has_unloaded_classes_in_signature(m, (JavaThread *)THREAD);
981 if( HAS_PENDING_EXCEPTION ) {
982 CLEAR_PENDING_EXCEPTION;
983 return true; // Declare that we may have unloaded classes
984 }
985 return has_unloaded;
986 }
987 }
989 // ------------------------------------------------------------------
990 // ciMethod::is_klass_loaded
991 bool ciMethod::is_klass_loaded(int refinfo_index, bool must_be_resolved) const {
992 VM_ENTRY_MARK;
993 return get_methodOop()->is_klass_loaded(refinfo_index, must_be_resolved);
994 }
996 // ------------------------------------------------------------------
997 // ciMethod::check_call
998 bool ciMethod::check_call(int refinfo_index, bool is_static) const {
999 VM_ENTRY_MARK;
1000 {
1001 EXCEPTION_MARK;
1002 HandleMark hm(THREAD);
1003 constantPoolHandle pool (THREAD, get_methodOop()->constants());
1004 methodHandle spec_method;
1005 KlassHandle spec_klass;
1006 LinkResolver::resolve_method(spec_method, spec_klass, pool, refinfo_index, THREAD);
1007 if (HAS_PENDING_EXCEPTION) {
1008 CLEAR_PENDING_EXCEPTION;
1009 return false;
1010 } else {
1011 return (spec_method->is_static() == is_static);
1012 }
1013 }
1014 return false;
1015 }
1017 // ------------------------------------------------------------------
1018 // ciMethod::print_codes
1019 //
1020 // Print the bytecodes for this method.
1021 void ciMethod::print_codes_on(outputStream* st) {
1022 check_is_loaded();
1023 GUARDED_VM_ENTRY(get_methodOop()->print_codes_on(st);)
1024 }
1027 #define FETCH_FLAG_FROM_VM(flag_accessor) { \
1028 check_is_loaded(); \
1029 VM_ENTRY_MARK; \
1030 return get_methodOop()->flag_accessor(); \
1031 }
1033 bool ciMethod::is_empty_method() const { FETCH_FLAG_FROM_VM(is_empty_method); }
1034 bool ciMethod::is_vanilla_constructor() const { FETCH_FLAG_FROM_VM(is_vanilla_constructor); }
1035 bool ciMethod::has_loops () const { FETCH_FLAG_FROM_VM(has_loops); }
1036 bool ciMethod::has_jsrs () const { FETCH_FLAG_FROM_VM(has_jsrs); }
1037 bool ciMethod::is_accessor () const { FETCH_FLAG_FROM_VM(is_accessor); }
1038 bool ciMethod::is_initializer () const { FETCH_FLAG_FROM_VM(is_initializer); }
1040 BCEscapeAnalyzer *ciMethod::get_bcea() {
1041 #ifdef COMPILER2
1042 if (_bcea == NULL) {
1043 _bcea = new (CURRENT_ENV->arena()) BCEscapeAnalyzer(this, NULL);
1044 }
1045 return _bcea;
1046 #else // COMPILER2
1047 ShouldNotReachHere();
1048 return NULL;
1049 #endif // COMPILER2
1050 }
1052 ciMethodBlocks *ciMethod::get_method_blocks() {
1053 Arena *arena = CURRENT_ENV->arena();
1054 if (_method_blocks == NULL) {
1055 _method_blocks = new (arena) ciMethodBlocks(arena, this);
1056 }
1057 return _method_blocks;
1058 }
1060 #undef FETCH_FLAG_FROM_VM
1063 // ------------------------------------------------------------------
1064 // ciMethod::print_codes
1065 //
1066 // Print a range of the bytecodes for this method.
1067 void ciMethod::print_codes_on(int from, int to, outputStream* st) {
1068 check_is_loaded();
1069 GUARDED_VM_ENTRY(get_methodOop()->print_codes_on(from, to, st);)
1070 }
1072 // ------------------------------------------------------------------
1073 // ciMethod::print_name
1074 //
1075 // Print the name of this method, including signature and some flags.
1076 void ciMethod::print_name(outputStream* st) {
1077 check_is_loaded();
1078 GUARDED_VM_ENTRY(get_methodOop()->print_name(st);)
1079 }
1081 // ------------------------------------------------------------------
1082 // ciMethod::print_short_name
1083 //
1084 // Print the name of this method, without signature.
1085 void ciMethod::print_short_name(outputStream* st) {
1086 check_is_loaded();
1087 GUARDED_VM_ENTRY(get_methodOop()->print_short_name(st);)
1088 }
1090 // ------------------------------------------------------------------
1091 // ciMethod::print_impl
1092 //
1093 // Implementation of the print method.
1094 void ciMethod::print_impl(outputStream* st) {
1095 ciObject::print_impl(st);
1096 st->print(" name=");
1097 name()->print_symbol_on(st);
1098 st->print(" holder=");
1099 holder()->print_name_on(st);
1100 st->print(" signature=");
1101 signature()->as_symbol()->print_symbol_on(st);
1102 if (is_loaded()) {
1103 st->print(" loaded=true flags=");
1104 flags().print_member_flags(st);
1105 } else {
1106 st->print(" loaded=false");
1107 }
1108 }