src/share/vm/oops/methodOop.cpp

Print this page




 514     // Not necessarily sorted and not necessarily one-to-one.
 515     CompressedLineNumberReadStream stream(compressed_linenumber_table());
 516     while (stream.read_pair()) {
 517       if (stream.bci() == bci) {
 518         // perfect match
 519         return stream.line();
 520       } else {
 521         // update best_bci/line
 522         if (stream.bci() < bci && stream.bci() >= best_bci) {
 523           best_bci  = stream.bci();
 524           best_line = stream.line();
 525         }
 526       }
 527     }
 528   }
 529   return best_line;
 530 }
 531 
 532 
 533 bool methodOopDesc::is_klass_loaded_by_klass_index(int klass_index) const {
 534   if( _constants->tag_at(klass_index).is_unresolved_klass() ) {
 535     Thread *thread = Thread::current();
 536     Symbol* klass_name = _constants->klass_name_at(klass_index);
 537     Handle loader(thread, instanceKlass::cast(method_holder())->class_loader());
 538     Handle prot  (thread, Klass::cast(method_holder())->protection_domain());
 539     return SystemDictionary::find(klass_name, loader, prot, thread) != NULL;
 540   } else {
 541     return true;
 542   }
 543 }
 544 
 545 
 546 bool methodOopDesc::is_klass_loaded(int refinfo_index, bool must_be_resolved) const {
 547   int klass_index = _constants->klass_ref_index_at(refinfo_index);
 548   if (must_be_resolved) {
 549     // Make sure klass is resolved in constantpool.
 550     if (constants()->tag_at(klass_index).is_unresolved_klass()) return false;
 551   }
 552   return is_klass_loaded_by_klass_index(klass_index);
 553 }
 554 
 555 
 556 void methodOopDesc::set_native_function(address function, bool post_event_flag) {
 557   assert(function != NULL, "use clear_native_function to unregister natives");
 558   address* native_function = native_function_addr();
 559 
 560   // We can see racers trying to place the same native function into place. Once
 561   // is plenty.
 562   address current = *native_function;
 563   if (current == function) return;
 564   if (post_event_flag && JvmtiExport::should_post_native_method_bind() &&
 565       function != NULL) {
 566     // native_method_throw_unsatisfied_link_error_entry() should only
 567     // be passed when post_event_flag is false.


 869     return true;
 870   return false;
 871 }
 872 
 873 // Constant pool structure for invoke methods:
 874 enum {
 875   _imcp_invoke_name = 1,        // utf8: 'invokeExact' or 'invokeGeneric'
 876   _imcp_invoke_signature,       // utf8: (variable Symbol*)
 877   _imcp_method_type_value,      // string: (variable java/lang/invoke/MethodType, sic)
 878   _imcp_limit
 879 };
 880 
 881 oop methodOopDesc::method_handle_type() const {
 882   if (!is_method_handle_invoke()) { assert(false, "caller resp."); return NULL; }
 883   oop mt = constants()->resolved_string_at(_imcp_method_type_value);
 884   assert(mt->klass() == SystemDictionary::MethodType_klass(), "");
 885   return mt;
 886 }
 887 
 888 jint* methodOopDesc::method_type_offsets_chain() {
 889   static jint pchase[] = { -1, -1, -1 };
 890   if (pchase[0] == -1) {
 891     jint step0 = in_bytes(constants_offset());
 892     jint step1 = (constantPoolOopDesc::header_size() + _imcp_method_type_value) * HeapWordSize;

 893     // do this in reverse to avoid races:

 894     OrderAccess::release_store(&pchase[1], step1);
 895     OrderAccess::release_store(&pchase[0], step0);
 896   }
 897   return pchase;
 898 }
 899 
 900 //------------------------------------------------------------------------------
 901 // methodOopDesc::is_method_handle_adapter
 902 //
 903 // Tests if this method is an internal adapter frame from the
 904 // MethodHandleCompiler.
 905 // Must be consistent with MethodHandleCompiler::get_method_oop().
 906 bool methodOopDesc::is_method_handle_adapter() const {
 907   if (is_synthetic() &&
 908       !is_native() &&   // has code from MethodHandleCompiler
 909       is_method_handle_invoke_name(name()) &&
 910       MethodHandleCompiler::klass_is_method_handle_adapter_holder(method_holder())) {
 911     assert(!is_method_handle_invoke(), "disjoint");
 912     return true;
 913   } else {


1059   // is_conc_safe initialzied into newcm and the copy should
1060   // not overwrite that value.  During the window during which it is
1061   // tagged as unsafe, some extra work could be needed during precleaning
1062   // or concurrent marking but those phases will be correct.  Setting and
1063   // resetting is done in preference to a careful copying into newcm to
1064   // avoid having to know the precise layout of a constMethodOop.
1065   m->constMethod()->set_is_conc_safe(oopDesc::IsUnsafeConc);
1066   assert(m->constMethod()->is_parsable(), "Should remain parsable");
1067 
1068   // NOTE: this is a reachable object that transiently signals "conc_unsafe"
1069   // However, no allocations are done during this window
1070   // during which it is tagged conc_unsafe, so we are assured that any concurrent
1071   // thread will not wait forever for the object to revert to "conc_safe".
1072   // Further, any such conc_unsafe object will indicate a stable size
1073   // through the transition.
1074   memcpy(newcm, m->constMethod(), sizeof(constMethodOopDesc));
1075   m->constMethod()->set_is_conc_safe(oopDesc::IsSafeConc);
1076   assert(m->constMethod()->is_parsable(), "Should remain parsable");
1077 
1078   // Reset correct method/const method, method size, and parameter info
1079   newcm->set_method(newm());
1080   newm->set_constMethod(newcm);
1081   assert(newcm->method() == newm(), "check");
1082   newm->constMethod()->set_code_size(new_code_length);
1083   newm->constMethod()->set_constMethod_size(new_const_method_size);
1084   newm->set_method_size(new_method_size);
1085   assert(newm->code_size() == new_code_length, "check");
1086   assert(newm->checked_exceptions_length() == checked_exceptions_len, "check");
1087   assert(newm->localvariable_table_length() == localvariable_len, "check");
1088   // Copy new byte codes
1089   memcpy(newm->code_base(), new_code, new_code_length);
1090   // Copy line number table
1091   if (new_compressed_linenumber_size > 0) {
1092     memcpy(newm->compressed_linenumber_table(),
1093            new_compressed_linenumber_table,
1094            new_compressed_linenumber_size);
1095   }
1096   // Copy checked_exceptions
1097   if (checked_exceptions_len > 0) {
1098     memcpy(newm->checked_exceptions_start(),
1099            m->checked_exceptions_start(),
1100            checked_exceptions_len * sizeof(CheckedExceptionElement));
1101   }




 514     // Not necessarily sorted and not necessarily one-to-one.
 515     CompressedLineNumberReadStream stream(compressed_linenumber_table());
 516     while (stream.read_pair()) {
 517       if (stream.bci() == bci) {
 518         // perfect match
 519         return stream.line();
 520       } else {
 521         // update best_bci/line
 522         if (stream.bci() < bci && stream.bci() >= best_bci) {
 523           best_bci  = stream.bci();
 524           best_line = stream.line();
 525         }
 526       }
 527     }
 528   }
 529   return best_line;
 530 }
 531 
 532 
 533 bool methodOopDesc::is_klass_loaded_by_klass_index(int klass_index) const {
 534   if( constants()->tag_at(klass_index).is_unresolved_klass() ) {
 535     Thread *thread = Thread::current();
 536     Symbol* klass_name = constants()->klass_name_at(klass_index);
 537     Handle loader(thread, instanceKlass::cast(method_holder())->class_loader());
 538     Handle prot  (thread, Klass::cast(method_holder())->protection_domain());
 539     return SystemDictionary::find(klass_name, loader, prot, thread) != NULL;
 540   } else {
 541     return true;
 542   }
 543 }
 544 
 545 
 546 bool methodOopDesc::is_klass_loaded(int refinfo_index, bool must_be_resolved) const {
 547   int klass_index = constants()->klass_ref_index_at(refinfo_index);
 548   if (must_be_resolved) {
 549     // Make sure klass is resolved in constantpool.
 550     if (constants()->tag_at(klass_index).is_unresolved_klass()) return false;
 551   }
 552   return is_klass_loaded_by_klass_index(klass_index);
 553 }
 554 
 555 
 556 void methodOopDesc::set_native_function(address function, bool post_event_flag) {
 557   assert(function != NULL, "use clear_native_function to unregister natives");
 558   address* native_function = native_function_addr();
 559 
 560   // We can see racers trying to place the same native function into place. Once
 561   // is plenty.
 562   address current = *native_function;
 563   if (current == function) return;
 564   if (post_event_flag && JvmtiExport::should_post_native_method_bind() &&
 565       function != NULL) {
 566     // native_method_throw_unsatisfied_link_error_entry() should only
 567     // be passed when post_event_flag is false.


 869     return true;
 870   return false;
 871 }
 872 
 873 // Constant pool structure for invoke methods:
 874 enum {
 875   _imcp_invoke_name = 1,        // utf8: 'invokeExact' or 'invokeGeneric'
 876   _imcp_invoke_signature,       // utf8: (variable Symbol*)
 877   _imcp_method_type_value,      // string: (variable java/lang/invoke/MethodType, sic)
 878   _imcp_limit
 879 };
 880 
 881 oop methodOopDesc::method_handle_type() const {
 882   if (!is_method_handle_invoke()) { assert(false, "caller resp."); return NULL; }
 883   oop mt = constants()->resolved_string_at(_imcp_method_type_value);
 884   assert(mt->klass() == SystemDictionary::MethodType_klass(), "");
 885   return mt;
 886 }
 887 
 888 jint* methodOopDesc::method_type_offsets_chain() {
 889   static jint pchase[] = { -1, -1, -1, -1 };
 890   if (pchase[0] == -1) {
 891     jint step0 = in_bytes(const_offset());
 892     jint step1 = in_bytes(constMethodOopDesc::constants_offset());
 893     jint step2 = (constantPoolOopDesc::header_size() + _imcp_method_type_value) * HeapWordSize;
 894     // do this in reverse to avoid races:
 895     OrderAccess::release_store(&pchase[2], step2);
 896     OrderAccess::release_store(&pchase[1], step1);
 897     OrderAccess::release_store(&pchase[0], step0);
 898   }
 899   return pchase;
 900 }
 901 
 902 //------------------------------------------------------------------------------
 903 // methodOopDesc::is_method_handle_adapter
 904 //
 905 // Tests if this method is an internal adapter frame from the
 906 // MethodHandleCompiler.
 907 // Must be consistent with MethodHandleCompiler::get_method_oop().
 908 bool methodOopDesc::is_method_handle_adapter() const {
 909   if (is_synthetic() &&
 910       !is_native() &&   // has code from MethodHandleCompiler
 911       is_method_handle_invoke_name(name()) &&
 912       MethodHandleCompiler::klass_is_method_handle_adapter_holder(method_holder())) {
 913     assert(!is_method_handle_invoke(), "disjoint");
 914     return true;
 915   } else {


1061   // is_conc_safe initialzied into newcm and the copy should
1062   // not overwrite that value.  During the window during which it is
1063   // tagged as unsafe, some extra work could be needed during precleaning
1064   // or concurrent marking but those phases will be correct.  Setting and
1065   // resetting is done in preference to a careful copying into newcm to
1066   // avoid having to know the precise layout of a constMethodOop.
1067   m->constMethod()->set_is_conc_safe(oopDesc::IsUnsafeConc);
1068   assert(m->constMethod()->is_parsable(), "Should remain parsable");
1069 
1070   // NOTE: this is a reachable object that transiently signals "conc_unsafe"
1071   // However, no allocations are done during this window
1072   // during which it is tagged conc_unsafe, so we are assured that any concurrent
1073   // thread will not wait forever for the object to revert to "conc_safe".
1074   // Further, any such conc_unsafe object will indicate a stable size
1075   // through the transition.
1076   memcpy(newcm, m->constMethod(), sizeof(constMethodOopDesc));
1077   m->constMethod()->set_is_conc_safe(oopDesc::IsSafeConc);
1078   assert(m->constMethod()->is_parsable(), "Should remain parsable");
1079 
1080   // Reset correct method/const method, method size, and parameter info

1081   newm->set_constMethod(newcm);

1082   newm->constMethod()->set_code_size(new_code_length);
1083   newm->constMethod()->set_constMethod_size(new_const_method_size);
1084   newm->set_method_size(new_method_size);
1085   assert(newm->code_size() == new_code_length, "check");
1086   assert(newm->checked_exceptions_length() == checked_exceptions_len, "check");
1087   assert(newm->localvariable_table_length() == localvariable_len, "check");
1088   // Copy new byte codes
1089   memcpy(newm->code_base(), new_code, new_code_length);
1090   // Copy line number table
1091   if (new_compressed_linenumber_size > 0) {
1092     memcpy(newm->compressed_linenumber_table(),
1093            new_compressed_linenumber_table,
1094            new_compressed_linenumber_size);
1095   }
1096   // Copy checked_exceptions
1097   if (checked_exceptions_len > 0) {
1098     memcpy(newm->checked_exceptions_start(),
1099            m->checked_exceptions_start(),
1100            checked_exceptions_len * sizeof(CheckedExceptionElement));
1101   }