595 // call this when compiler finds that this method is not compilable
596 void methodOopDesc::set_not_compilable(int comp_level) {
597 if ((TraceDeoptimization || LogCompilation) && (xtty != NULL)) {
598 ttyLocker ttyl;
599 xtty->begin_elem("make_not_compilable thread='%d'", (int) os::current_thread_id());
600 xtty->method(methodOop(this));
601 xtty->stamp();
602 xtty->end_elem();
603 }
604 #ifdef COMPILER2
605 if (is_tier1_compile(comp_level)) {
606 set_not_tier1_compilable();
607 return;
608 }
609 #endif /* COMPILER2 */
610 assert(comp_level == CompLevel_highest_tier, "unexpected compilation level");
611 invocation_counter()->set_state(InvocationCounter::wait_for_nothing);
612 backedge_counter()->set_state(InvocationCounter::wait_for_nothing);
613 }
614
615 // Revert to using the interpreter and clear out the nmethod
616 void methodOopDesc::clear_code() {
617
618 // this may be NULL if c2i adapters have not been made yet
619 // Only should happen at allocate time.
620 if (_adapter == NULL) {
621 _from_compiled_entry = NULL;
622 } else {
623 _from_compiled_entry = _adapter->get_c2i_entry();
624 }
625 OrderAccess::storestore();
626 _from_interpreted_entry = _i2i_entry;
627 OrderAccess::storestore();
628 _code = NULL;
629 }
630
631 // Called by class data sharing to remove any entry points (which are not shared)
632 void methodOopDesc::unlink_method() {
633 _code = NULL;
634 _i2i_entry = NULL;
635 _from_interpreted_entry = NULL;
636 if (is_native()) {
637 *native_function_addr() = NULL;
638 set_signature_handler(NULL);
639 }
640 NOT_PRODUCT(set_compiled_invocation_count(0);)
641 invocation_counter()->reset();
642 backedge_counter()->reset();
643 _adapter = NULL;
644 _from_compiled_entry = NULL;
645 assert(_method_data == NULL, "unexpected method data?");
646 set_method_data(NULL);
647 set_interpreter_throwout_count(0);
648 set_interpreter_invocation_count(0);
688 // so making them eagerly shouldn't be too expensive.
689 AdapterHandlerEntry* adapter = AdapterHandlerLibrary::get_adapter(mh);
690 if (adapter == NULL ) {
691 THROW_0(vmSymbols::java_lang_OutOfMemoryError());
692 }
693
694 mh->set_adapter_entry(adapter);
695 mh->_from_compiled_entry = adapter->get_c2i_entry();
696 return adapter->get_c2i_entry();
697 }
698
699 // The verified_code_entry() must be called when a invoke is resolved
700 // on this method.
701
702 // It returns the compiled code entry point, after asserting not null.
703 // This function is called after potential safepoints so that nmethod
704 // or adapter that it points to is still live and valid.
705 // This function must not hit a safepoint!
706 address methodOopDesc::verified_code_entry() {
707 debug_only(No_Safepoint_Verifier nsv;)
708 assert(_from_compiled_entry != NULL, "must be set");
709 return _from_compiled_entry;
710 }
711
712 // Check that if an nmethod ref exists, it has a backlink to this or no backlink at all
713 // (could be racing a deopt).
714 // Not inline to avoid circular ref.
715 bool methodOopDesc::check_code() const {
716 // cached in a register or local. There's a race on the value of the field.
717 nmethod *code = (nmethod *)OrderAccess::load_ptr_acquire(&_code);
718 return code == NULL || (code->method() == NULL) || (code->method() == (methodOop)this && !code->is_osr_method());
719 }
720
721 // Install compiled code. Instantly it can execute.
722 void methodOopDesc::set_code(methodHandle mh, nmethod *code) {
723 assert( code, "use clear_code to remove code" );
724 assert( mh->check_code(), "" );
725
726 guarantee(mh->adapter() != NULL, "Adapter blob must already exist!");
727
728 // These writes must happen in this order, because the interpreter will
729 // directly jump to from_interpreted_entry which jumps to an i2c adapter
730 // which jumps to _from_compiled_entry.
731 mh->_code = code; // Assign before allowing compiled code to exec
732
733 int comp_level = code->comp_level();
734 // In theory there could be a race here. In practice it is unlikely
735 // and not worth worrying about.
736 if (comp_level > highest_tier_compile()) {
737 set_highest_tier_compile(comp_level);
738 }
739
740 OrderAccess::storestore();
741 mh->_from_compiled_entry = code->verified_entry_point();
742 OrderAccess::storestore();
743 // Instantly compiled code can execute.
744 mh->_from_interpreted_entry = mh->get_i2c_entry();
745
746 }
747
|
595 // call this when compiler finds that this method is not compilable
596 void methodOopDesc::set_not_compilable(int comp_level) {
597 if ((TraceDeoptimization || LogCompilation) && (xtty != NULL)) {
598 ttyLocker ttyl;
599 xtty->begin_elem("make_not_compilable thread='%d'", (int) os::current_thread_id());
600 xtty->method(methodOop(this));
601 xtty->stamp();
602 xtty->end_elem();
603 }
604 #ifdef COMPILER2
605 if (is_tier1_compile(comp_level)) {
606 set_not_tier1_compilable();
607 return;
608 }
609 #endif /* COMPILER2 */
610 assert(comp_level == CompLevel_highest_tier, "unexpected compilation level");
611 invocation_counter()->set_state(InvocationCounter::wait_for_nothing);
612 backedge_counter()->set_state(InvocationCounter::wait_for_nothing);
613 }
614
615 // Clear the code ptr during emergency code cache sweeping
616 // It will be restored if it is actually called
617 void methodOopDesc::clear_code_hedge() {
618 // should guarantee at safepoint
619 nmethod* tmp = code();
620 clear_code();
621 _saved_code = tmp;
622 assert( ! _saved_code->is_osr_method(), "should not get here for osr" );
623 }
624
625 // Revert to using the interpreter and clear out the nmethod
626 void methodOopDesc::clear_code() {
627
628 // this may be NULL if c2i adapters have not been made yet
629 // Only should happen at allocate time.
630 if (_adapter == NULL) {
631 _from_compiled_entry = NULL;
632 } else {
633 _from_compiled_entry = _adapter->get_c2i_entry();
634 }
635 OrderAccess::storestore();
636 _from_interpreted_entry = _i2i_entry;
637 OrderAccess::storestore();
638 _code = NULL;
639 _saved_code = NULL;
640 }
641
642 // Called by class data sharing to remove any entry points (which are not shared)
643 void methodOopDesc::unlink_method() {
644 _code = NULL;
645 _i2i_entry = NULL;
646 _from_interpreted_entry = NULL;
647 if (is_native()) {
648 *native_function_addr() = NULL;
649 set_signature_handler(NULL);
650 }
651 NOT_PRODUCT(set_compiled_invocation_count(0);)
652 invocation_counter()->reset();
653 backedge_counter()->reset();
654 _adapter = NULL;
655 _from_compiled_entry = NULL;
656 assert(_method_data == NULL, "unexpected method data?");
657 set_method_data(NULL);
658 set_interpreter_throwout_count(0);
659 set_interpreter_invocation_count(0);
699 // so making them eagerly shouldn't be too expensive.
700 AdapterHandlerEntry* adapter = AdapterHandlerLibrary::get_adapter(mh);
701 if (adapter == NULL ) {
702 THROW_0(vmSymbols::java_lang_OutOfMemoryError());
703 }
704
705 mh->set_adapter_entry(adapter);
706 mh->_from_compiled_entry = adapter->get_c2i_entry();
707 return adapter->get_c2i_entry();
708 }
709
710 // The verified_code_entry() must be called when a invoke is resolved
711 // on this method.
712
713 // It returns the compiled code entry point, after asserting not null.
714 // This function is called after potential safepoints so that nmethod
715 // or adapter that it points to is still live and valid.
716 // This function must not hit a safepoint!
717 address methodOopDesc::verified_code_entry() {
718 debug_only(No_Safepoint_Verifier nsv;)
719 nmethod *code = (nmethod *)OrderAccess::load_ptr_acquire(&_code);
720 nmethod *saved_code = (nmethod *)OrderAccess::load_ptr_acquire(&_saved_code);
721 if (( code == NULL) && (saved_code != NULL) && (saved_code->is_in_use())) {
722 methodHandle method(this);
723 assert(UseCodeCacheFlushing, "UseCodeCacheFlushing should be on");
724 assert( ! saved_code->is_osr_method(), "should not get here for osr" );
725 set_code( method, saved_code );
726 }
727
728 assert(_from_compiled_entry != NULL, "must be set");
729 return _from_compiled_entry;
730 }
731
732 // Check that if an nmethod ref exists, it has a backlink to this or no backlink at all
733 // (could be racing a deopt).
734 // Not inline to avoid circular ref.
735 bool methodOopDesc::check_code() const {
736 // cached in a register or local. There's a race on the value of the field.
737 nmethod *code = (nmethod *)OrderAccess::load_ptr_acquire(&_code);
738 return code == NULL || (code->method() == NULL) || (code->method() == (methodOop)this && !code->is_osr_method());
739 }
740
741 // Install compiled code. Instantly it can execute.
742 void methodOopDesc::set_code(methodHandle mh, nmethod *code) {
743 assert( code, "use clear_code to remove code" );
744 assert( mh->check_code(), "" );
745
746 guarantee(mh->adapter() != NULL, "Adapter blob must already exist!");
747
748 mh->set_saved_code(NULL);
749
750 // These writes must happen in this order, because the interpreter will
751 // directly jump to from_interpreted_entry which jumps to an i2c adapter
752 // which jumps to _from_compiled_entry.
753 mh->_code = code; // Assign before allowing compiled code to exec
754
755 int comp_level = code->comp_level();
756 // In theory there could be a race here. In practice it is unlikely
757 // and not worth worrying about.
758 if (comp_level > highest_tier_compile()) {
759 set_highest_tier_compile(comp_level);
760 }
761
762 OrderAccess::storestore();
763 mh->_from_compiled_entry = code->verified_entry_point();
764 OrderAccess::storestore();
765 // Instantly compiled code can execute.
766 mh->_from_interpreted_entry = mh->get_i2c_entry();
767
768 }
769
|