260 // Return bci if it appears to be a valid bcp
261 // Return -1 otherwise.
262 // Used by profiling code, when invalid data is a possibility.
263 // The caller is responsible for validating the Method* itself.
264 int Method::validate_bci_from_bcp(address bcp) const {
265 // keep bci as -1 if not a valid bci
266 int bci = -1;
267 if (bcp == 0 || bcp == code_base()) {
268 // code_size() may return 0 and we allow 0 here
269 // the method may be native
270 bci = 0;
271 } else if (contains(bcp)) {
272 bci = bcp - code_base();
273 }
274 // Assert that if we have dodged any asserts, bci is negative.
275 assert(bci == -1 || bci == bci_from(bcp_from(bci)), "sane bci if >=0");
276 return bci;
277 }
278
279 address Method::bcp_from(int bci) const {
280 assert((is_native() && bci == 0) || (!is_native() && 0 <= bci && bci < code_size()), "illegal bci: %d", bci);
281 address bcp = code_base() + bci;
282 assert(is_native() && bcp == code_base() || contains(bcp), "bcp doesn't belong to this method");
283 return bcp;
284 }
285
286 address Method::bcp_from(address bcp) const {
287 if (is_native() && bcp == NULL) {
288 return code_base();
289 } else {
290 return bcp;
291 }
292 }
293
294 int Method::size(bool is_native) {
295 // If native, then include pointers for native_function and signature_handler
296 int extra_bytes = (is_native) ? 2*sizeof(address*) : 0;
297 int extra_words = align_size_up(extra_bytes, BytesPerWord) / BytesPerWord;
298 return align_metadata_size(header_size() + extra_words);
299 }
300
541 case Bytecodes::_if_acmpeq:
542 case Bytecodes::_if_acmpne:
543 case Bytecodes::_goto:
544 case Bytecodes::_jsr:
545 if( bcs.dest() < bcs.next_bci() ) _access_flags.set_has_loops();
546 break;
547
548 case Bytecodes::_goto_w:
549 case Bytecodes::_jsr_w:
550 if( bcs.dest_w() < bcs.next_bci() ) _access_flags.set_has_loops();
551 break;
552 }
553 }
554 _access_flags.set_loops_flag_init();
555 return _access_flags.has_loops();
556 }
557
558 bool Method::is_final_method(AccessFlags class_access_flags) const {
559 // or "does_not_require_vtable_entry"
560 // default method or overpass can occur, is not final (reuses vtable entry)
561 // private methods get vtable entries for backward class compatibility.
562 if (is_overpass() || is_default_method()) return false;
563 return is_final() || class_access_flags.is_final();
564 }
565
566 bool Method::is_final_method() const {
567 return is_final_method(method_holder()->access_flags());
568 }
569
570 bool Method::is_default_method() const {
571 if (method_holder() != NULL &&
572 method_holder()->is_interface() &&
573 !is_abstract()) {
574 return true;
575 } else {
576 return false;
577 }
578 }
579
580 bool Method::can_be_statically_bound(AccessFlags class_access_flags) const {
581 if (is_final_method(class_access_flags)) return true;
582 #ifdef ASSERT
583 ResourceMark rm;
584 bool is_nonv = (vtable_index() == nonvirtual_vtable_index);
585 if (class_access_flags.is_interface()) {
586 assert(is_nonv == is_static(), "is_nonv=%s", name_and_sig_as_C_string());
587 }
588 #endif
589 assert(valid_vtable_index() || valid_itable_index(), "method must be linked before we ask this question");
590 return vtable_index() == nonvirtual_vtable_index;
591 }
592
593 bool Method::can_be_statically_bound() const {
594 return can_be_statically_bound(method_holder()->access_flags());
595 }
596
597 bool Method::is_accessor() const {
598 return is_getter() || is_setter();
599 }
600
601 bool Method::is_getter() const {
602 if (code_size() != 5) return false;
603 if (size_of_parameters() != 1) return false;
604 if (java_code_at(0) != Bytecodes::_aload_0) return false;
605 if (java_code_at(1) != Bytecodes::_getfield) return false;
606 switch (java_code_at(4)) {
|
260 // Return bci if it appears to be a valid bcp
261 // Return -1 otherwise.
262 // Used by profiling code, when invalid data is a possibility.
263 // The caller is responsible for validating the Method* itself.
264 int Method::validate_bci_from_bcp(address bcp) const {
265 // keep bci as -1 if not a valid bci
266 int bci = -1;
267 if (bcp == 0 || bcp == code_base()) {
268 // code_size() may return 0 and we allow 0 here
269 // the method may be native
270 bci = 0;
271 } else if (contains(bcp)) {
272 bci = bcp - code_base();
273 }
274 // Assert that if we have dodged any asserts, bci is negative.
275 assert(bci == -1 || bci == bci_from(bcp_from(bci)), "sane bci if >=0");
276 return bci;
277 }
278
279 address Method::bcp_from(int bci) const {
280 assert((is_native() && bci == 0) || (!is_native() && 0 <= bci && bci < code_size()),
281 "illegal bci: %d for %s method", bci, is_native() ? "native" : "non-native");
282 address bcp = code_base() + bci;
283 assert(is_native() && bcp == code_base() || contains(bcp), "bcp doesn't belong to this method");
284 return bcp;
285 }
286
287 address Method::bcp_from(address bcp) const {
288 if (is_native() && bcp == NULL) {
289 return code_base();
290 } else {
291 return bcp;
292 }
293 }
294
295 int Method::size(bool is_native) {
296 // If native, then include pointers for native_function and signature_handler
297 int extra_bytes = (is_native) ? 2*sizeof(address*) : 0;
298 int extra_words = align_size_up(extra_bytes, BytesPerWord) / BytesPerWord;
299 return align_metadata_size(header_size() + extra_words);
300 }
301
542 case Bytecodes::_if_acmpeq:
543 case Bytecodes::_if_acmpne:
544 case Bytecodes::_goto:
545 case Bytecodes::_jsr:
546 if( bcs.dest() < bcs.next_bci() ) _access_flags.set_has_loops();
547 break;
548
549 case Bytecodes::_goto_w:
550 case Bytecodes::_jsr_w:
551 if( bcs.dest_w() < bcs.next_bci() ) _access_flags.set_has_loops();
552 break;
553 }
554 }
555 _access_flags.set_loops_flag_init();
556 return _access_flags.has_loops();
557 }
558
559 bool Method::is_final_method(AccessFlags class_access_flags) const {
560 // or "does_not_require_vtable_entry"
561 // default method or overpass can occur, is not final (reuses vtable entry)
562 // private methods in classes get vtable entries for backward class compatibility.
563 if (is_overpass() || is_default_method()) return false;
564 return is_final() || class_access_flags.is_final();
565 }
566
567 bool Method::is_final_method() const {
568 return is_final_method(method_holder()->access_flags());
569 }
570
571 bool Method::is_default_method() const {
572 if (method_holder() != NULL &&
573 method_holder()->is_interface() &&
574 !is_abstract() && !is_private()) {
575 return true;
576 } else {
577 return false;
578 }
579 }
580
581 bool Method::can_be_statically_bound(AccessFlags class_access_flags) const {
582 if (is_final_method(class_access_flags)) return true;
583 #ifdef ASSERT
584 ResourceMark rm;
585 bool is_nonv = (vtable_index() == nonvirtual_vtable_index);
586 if (class_access_flags.is_interface()) {
587 assert(is_nonv == is_static() || is_nonv == is_private(),
588 "nonvirtual unexpected for non-static, non-private: %s",
589 name_and_sig_as_C_string());
590 }
591 #endif
592 assert(valid_vtable_index() || valid_itable_index(), "method must be linked before we ask this question");
593 return vtable_index() == nonvirtual_vtable_index;
594 }
595
596 bool Method::can_be_statically_bound() const {
597 return can_be_statically_bound(method_holder()->access_flags());
598 }
599
600 bool Method::is_accessor() const {
601 return is_getter() || is_setter();
602 }
603
604 bool Method::is_getter() const {
605 if (code_size() != 5) return false;
606 if (size_of_parameters() != 1) return false;
607 if (java_code_at(0) != Bytecodes::_aload_0) return false;
608 if (java_code_at(1) != Bytecodes::_getfield) return false;
609 switch (java_code_at(4)) {
|