< prev index next >

src/hotspot/share/oops/method.cpp

Print this page




  31 #include "gc/shared/collectedHeap.inline.hpp"
  32 #include "interpreter/bytecodeStream.hpp"
  33 #include "interpreter/bytecodeTracer.hpp"
  34 #include "interpreter/bytecodes.hpp"
  35 #include "interpreter/interpreter.hpp"
  36 #include "interpreter/oopMapCache.hpp"
  37 #include "memory/allocation.inline.hpp"
  38 #include "memory/heapInspection.hpp"
  39 #include "memory/metadataFactory.hpp"
  40 #include "memory/metaspaceClosure.hpp"
  41 #include "memory/metaspaceShared.hpp"
  42 #include "memory/oopFactory.hpp"
  43 #include "memory/resourceArea.hpp"
  44 #include "oops/constMethod.hpp"
  45 #include "oops/constantPool.hpp"
  46 #include "oops/method.inline.hpp"
  47 #include "oops/methodData.hpp"
  48 #include "oops/objArrayOop.inline.hpp"
  49 #include "oops/oop.inline.hpp"
  50 #include "oops/symbol.hpp"

  51 #include "prims/jvmtiExport.hpp"
  52 #include "prims/methodHandles.hpp"
  53 #include "prims/nativeLookup.hpp"
  54 #include "runtime/arguments.hpp"
  55 #include "runtime/compilationPolicy.hpp"
  56 #include "runtime/frame.inline.hpp"
  57 #include "runtime/handles.inline.hpp"
  58 #include "runtime/init.hpp"
  59 #include "runtime/orderAccess.hpp"
  60 #include "runtime/relocator.hpp"
  61 #include "runtime/safepointVerifiers.hpp"
  62 #include "runtime/sharedRuntime.hpp"
  63 #include "runtime/signature.hpp"
  64 #include "utilities/align.hpp"
  65 #include "utilities/quickSort.hpp"
  66 #include "utilities/vmError.hpp"
  67 #include "utilities/xmlstream.hpp"
  68 
  69 // Implementation of Method
  70 


  90   set_constMethod(xconst);
  91   set_access_flags(access_flags);
  92   set_intrinsic_id(vmIntrinsics::_none);
  93   set_force_inline(false);
  94   set_hidden(false);
  95   set_dont_inline(false);
  96   set_has_injected_profile(false);
  97   set_method_data(NULL);
  98   clear_method_counters();
  99   set_vtable_index(Method::garbage_vtable_index);
 100 
 101   // Fix and bury in Method*
 102   set_interpreter_entry(NULL); // sets i2i entry and from_int
 103   set_adapter_entry(NULL);
 104   clear_code(false /* don't need a lock */); // from_c/from_i get set to c2i/i2i
 105 
 106   if (access_flags.is_native()) {
 107     clear_native_function();
 108     set_signature_handler(NULL);
 109   }
 110 
 111   NOT_PRODUCT(set_compiled_invocation_count(0);)
 112 }
 113 
 114 // Release Method*.  The nmethod will be gone when we get here because
 115 // we've walked the code cache.
 116 void Method::deallocate_contents(ClassLoaderData* loader_data) {
 117   MetadataFactory::free_metadata(loader_data, constMethod());
 118   set_constMethod(NULL);
 119   MetadataFactory::free_metadata(loader_data, method_data());
 120   set_method_data(NULL);
 121   MetadataFactory::free_metadata(loader_data, method_counters());
 122   clear_method_counters();
 123   // The nmethod will be gone when we get here.
 124   if (code() != NULL) _code = NULL;
 125 }
 126 
 127 address Method::get_i2c_entry() {
 128   assert(adapter() != NULL, "must have");
 129   return adapter()->get_i2c_entry();
 130 }


 450   // Try to install a pointer to MethodCounters, return true on success.
 451   return Atomic::replace_if_null(counters, &_method_counters);
 452 }
 453 
 454 int Method::extra_stack_words() {
 455   // not an inline function, to avoid a header dependency on Interpreter
 456   return extra_stack_entries() * Interpreter::stackElementSize;
 457 }
 458 
 459 
 460 void Method::compute_size_of_parameters(Thread *thread) {
 461   ArgumentSizeComputer asc(signature());
 462   set_size_of_parameters(asc.size() + (is_static() ? 0 : 1));
 463 }
 464 
 465 BasicType Method::result_type() const {
 466   ResultTypeFinder rtf(signature());
 467   return rtf.type();
 468 }
 469 




















 470 
 471 bool Method::is_empty_method() const {
 472   return  code_size() == 1
 473       && *code_base() == Bytecodes::_return;
 474 }
 475 
 476 
 477 bool Method::is_vanilla_constructor() const {
 478   // Returns true if this method is a vanilla constructor, i.e. an "<init>" "()V" method
 479   // which only calls the superclass vanilla constructor and possibly does stores of
 480   // zero constants to local fields:
 481   //
 482   //   aload_0
 483   //   invokespecial
 484   //   indexbyte1
 485   //   indexbyte2
 486   //
 487   // followed by an (optional) sequence of:
 488   //
 489   //   aload_0


 700     // Not necessarily sorted and not necessarily one-to-one.
 701     CompressedLineNumberReadStream stream(compressed_linenumber_table());
 702     while (stream.read_pair()) {
 703       if (stream.bci() == bci) {
 704         // perfect match
 705         return stream.line();
 706       } else {
 707         // update best_bci/line
 708         if (stream.bci() < bci && stream.bci() >= best_bci) {
 709           best_bci  = stream.bci();
 710           best_line = stream.line();
 711         }
 712       }
 713     }
 714   }
 715   return best_line;
 716 }
 717 
 718 
 719 bool Method::is_klass_loaded_by_klass_index(int klass_index) const {
 720   if( constants()->tag_at(klass_index).is_unresolved_klass() ) {
 721     Thread *thread = Thread::current();
 722     Symbol* klass_name = constants()->klass_name_at(klass_index);
 723     Handle loader(thread, method_holder()->class_loader());
 724     Handle prot  (thread, method_holder()->protection_domain());
 725     return SystemDictionary::find(klass_name, loader, prot, thread) != NULL;
 726   } else {
 727     return true;
 728   }
 729 }
 730 
 731 
 732 bool Method::is_klass_loaded(int refinfo_index, bool must_be_resolved) const {
 733   int klass_index = constants()->klass_ref_index_at(refinfo_index);
 734   if (must_be_resolved) {
 735     // Make sure klass is resolved in constantpool.
 736     if (constants()->tag_at(klass_index).is_unresolved_klass()) return false;


 737   }
 738   return is_klass_loaded_by_klass_index(klass_index);
 739 }
 740 
 741 
 742 void Method::set_native_function(address function, bool post_event_flag) {
 743   assert(function != NULL, "use clear_native_function to unregister natives");
 744   assert(!is_method_handle_intrinsic() || function == SharedRuntime::native_method_throw_unsatisfied_link_error_entry(), "");
 745   address* native_function = native_function_addr();
 746 
 747   // We can see racers trying to place the same native function into place. Once
 748   // is plenty.
 749   address current = *native_function;
 750   if (current == function) return;
 751   if (post_event_flag && JvmtiExport::should_post_native_method_bind() &&
 752       function != NULL) {
 753     // native_method_throw_unsatisfied_link_error_entry() should only
 754     // be passed when post_event_flag is false.
 755     assert(function !=
 756       SharedRuntime::native_method_throw_unsatisfied_link_error_entry(),


 895   if (comp_level == CompLevel_all) {
 896     set_not_c1_osr_compilable();
 897     set_not_c2_osr_compilable();
 898   } else {
 899     if (is_c1_compile(comp_level))
 900       set_not_c1_osr_compilable();
 901     if (is_c2_compile(comp_level))
 902       set_not_c2_osr_compilable();
 903   }
 904   CompilationPolicy::policy()->disable_compilation(this);
 905   assert(!CompilationPolicy::can_be_osr_compiled(this, comp_level), "sanity check");
 906 }
 907 
 908 // Revert to using the interpreter and clear out the nmethod
 909 void Method::clear_code(bool acquire_lock /* = true */) {
 910   MutexLockerEx pl(acquire_lock ? Patching_lock : NULL, Mutex::_no_safepoint_check_flag);
 911   // this may be NULL if c2i adapters have not been made yet
 912   // Only should happen at allocate time.
 913   if (adapter() == NULL) {
 914     _from_compiled_entry    = NULL;


 915   } else {
 916     _from_compiled_entry    = adapter()->get_c2i_entry();


 917   }
 918   OrderAccess::storestore();
 919   _from_interpreted_entry = _i2i_entry;
 920   OrderAccess::storestore();
 921   _code = NULL;
 922 }
 923 
 924 #if INCLUDE_CDS
 925 // Called by class data sharing to remove any entry points (which are not shared)
 926 void Method::unlink_method() {
 927   _code = NULL;
 928 
 929   assert(DumpSharedSpaces, "dump time only");
 930   // Set the values to what they should be at run time. Note that
 931   // this Method can no longer be executed during dump time.
 932   _i2i_entry = Interpreter::entry_for_cds_method(this);
 933   _from_interpreted_entry = _i2i_entry;
 934 
 935   if (is_native()) {
 936     *native_function_addr() = NULL;
 937     set_signature_handler(NULL);
 938   }
 939   NOT_PRODUCT(set_compiled_invocation_count(0);)
 940 
 941   CDSAdapterHandlerEntry* cds_adapter = (CDSAdapterHandlerEntry*)adapter();
 942   constMethod()->set_adapter_trampoline(cds_adapter->get_adapter_trampoline());
 943   _from_compiled_entry = cds_adapter->get_c2i_entry_trampoline();
 944   assert(*((int*)_from_compiled_entry) == 0, "must be NULL during dump time, to be initialized at run time");




 945 
 946   set_method_data(NULL);
 947   clear_method_counters();
 948 }
 949 #endif
 950 
 951 /****************************************************************************
 952 // The following illustrates how the entries work for CDS shared Methods:
 953 //
 954 // Our goal is to delay writing into a shared Method until it's compiled.
 955 // Hence, we want to determine the initial values for _i2i_entry,
 956 // _from_interpreted_entry and _from_compiled_entry during CDS dump time.
 957 //
 958 // In this example, both Methods A and B have the _i2i_entry of "zero_locals".
 959 // They also have similar signatures so that they will share the same
 960 // AdapterHandlerEntry.
 961 //
 962 // _adapter_trampoline points to a fixed location in the RW section of
 963 // the CDS archive. This location initially contains a NULL pointer. When the
 964 // first of method A or B is linked, an AdapterHandlerEntry is allocated


1072 
1073 address Method::make_adapters(const methodHandle& mh, TRAPS) {
1074   // Adapters for compiled code are made eagerly here.  They are fairly
1075   // small (generally < 100 bytes) and quick to make (and cached and shared)
1076   // so making them eagerly shouldn't be too expensive.
1077   AdapterHandlerEntry* adapter = AdapterHandlerLibrary::get_adapter(mh);
1078   if (adapter == NULL ) {
1079     if (!is_init_completed()) {
1080       // Don't throw exceptions during VM initialization because java.lang.* classes
1081       // might not have been initialized, causing problems when constructing the
1082       // Java exception object.
1083       vm_exit_during_initialization("Out of space in CodeCache for adapters");
1084     } else {
1085       THROW_MSG_NULL(vmSymbols::java_lang_VirtualMachineError(), "Out of space in CodeCache for adapters");
1086     }
1087   }
1088 
1089   if (mh->is_shared()) {
1090     assert(mh->adapter() == adapter, "must be");
1091     assert(mh->_from_compiled_entry != NULL, "must be");


1092   } else {
1093     mh->set_adapter_entry(adapter);
1094     mh->_from_compiled_entry = adapter->get_c2i_entry();


1095   }
1096   return adapter->get_c2i_entry();
1097 }
1098 
1099 void Method::restore_unshareable_info(TRAPS) {
1100   assert(is_method() && is_valid_method(this), "ensure C++ vtable is restored");
1101 
1102   // Since restore_unshareable_info can be called more than once for a method, don't
1103   // redo any work.
1104   if (adapter() == NULL) {
1105     methodHandle mh(THREAD, this);
1106     link_method(mh, CHECK);
1107   }
1108 }
1109 
1110 address Method::from_compiled_entry_no_trampoline() const {
1111   CompiledMethod *code = OrderAccess::load_acquire(&_code);
1112   if (code) {
1113     return code->verified_entry_point();
1114   } else {
1115     return adapter()->get_c2i_entry();
1116   }
1117 }
1118 
1119 // The verified_code_entry() must be called when a invoke is resolved
1120 // on this method.
1121 
1122 // It returns the compiled code entry point, after asserting not null.
1123 // This function is called after potential safepoints so that nmethod
1124 // or adapter that it points to is still live and valid.
1125 // This function must not hit a safepoint!
1126 address Method::verified_code_entry() {
1127   debug_only(NoSafepointVerifier nsv;)
1128   assert(_from_compiled_entry != NULL, "must be set");
1129   return _from_compiled_entry;
1130 }
1131 






1132 // Check that if an nmethod ref exists, it has a backlink to this or no backlink at all
1133 // (could be racing a deopt).
1134 // Not inline to avoid circular ref.
1135 bool Method::check_code() const {
1136   // cached in a register or local.  There's a race on the value of the field.
1137   CompiledMethod *code = OrderAccess::load_acquire(&_code);
1138   return code == NULL || (code->method() == NULL) || (code->method() == (Method*)this && !code->is_osr_method());
1139 }
1140 
1141 // Install compiled code.  Instantly it can execute.
1142 void Method::set_code(const methodHandle& mh, CompiledMethod *code) {
1143   MutexLockerEx pl(Patching_lock, Mutex::_no_safepoint_check_flag);
1144   assert( code, "use clear_code to remove code" );
1145   assert( mh->check_code(), "" );
1146 
1147   guarantee(mh->adapter() != NULL, "Adapter blob must already exist!");
1148 
1149   // These writes must happen in this order, because the interpreter will
1150   // directly jump to from_interpreted_entry which jumps to an i2c adapter
1151   // which jumps to _from_compiled_entry.
1152   mh->_code = code;             // Assign before allowing compiled code to exec
1153 
1154   int comp_level = code->comp_level();
1155   // In theory there could be a race here. In practice it is unlikely
1156   // and not worth worrying about.
1157   if (comp_level > mh->highest_comp_level()) {
1158     mh->set_highest_comp_level(comp_level);
1159   }
1160 
1161   OrderAccess::storestore();
1162   mh->_from_compiled_entry = code->verified_entry_point();


1163   OrderAccess::storestore();
1164   // Instantly compiled code can execute.
1165   if (!mh->is_method_handle_intrinsic())
1166     mh->_from_interpreted_entry = mh->get_i2c_entry();
1167 }
1168 
1169 
1170 bool Method::is_overridden_in(Klass* k) const {
1171   InstanceKlass* ik = InstanceKlass::cast(k);
1172 
1173   if (ik->is_interface()) return false;
1174 
1175   // If method is an interface, we skip it - except if it
1176   // is a miranda method
1177   if (method_holder()->is_interface()) {
1178     // Check that method is not a miranda method
1179     if (ik->lookup_method(name(), signature()) == NULL) {
1180       // No implementation exist - so miranda method
1181       return false;
1182     }


2200 void Method::print_on(outputStream* st) const {
2201   ResourceMark rm;
2202   assert(is_method(), "must be method");
2203   st->print_cr("%s", internal_name());
2204   st->print_cr(" - this oop:          " INTPTR_FORMAT, p2i(this));
2205   st->print   (" - method holder:     "); method_holder()->print_value_on(st); st->cr();
2206   st->print   (" - constants:         " INTPTR_FORMAT " ", p2i(constants()));
2207   constants()->print_value_on(st); st->cr();
2208   st->print   (" - access:            0x%x  ", access_flags().as_int()); access_flags().print_on(st); st->cr();
2209   st->print   (" - name:              ");    name()->print_value_on(st); st->cr();
2210   st->print   (" - signature:         ");    signature()->print_value_on(st); st->cr();
2211   st->print_cr(" - max stack:         %d",   max_stack());
2212   st->print_cr(" - max locals:        %d",   max_locals());
2213   st->print_cr(" - size of params:    %d",   size_of_parameters());
2214   st->print_cr(" - method size:       %d",   method_size());
2215   if (intrinsic_id() != vmIntrinsics::_none)
2216     st->print_cr(" - intrinsic id:      %d %s", intrinsic_id(), vmIntrinsics::name_at(intrinsic_id()));
2217   if (highest_comp_level() != CompLevel_none)
2218     st->print_cr(" - highest level:     %d", highest_comp_level());
2219   st->print_cr(" - vtable index:      %d",   _vtable_index);


2220   st->print_cr(" - i2i entry:         " INTPTR_FORMAT, p2i(interpreter_entry()));
2221   st->print(   " - adapters:          ");
2222   AdapterHandlerEntry* a = ((Method*)this)->adapter();
2223   if (a == NULL)
2224     st->print_cr(INTPTR_FORMAT, p2i(a));
2225   else
2226     a->print_adapter_on(st);
2227   st->print_cr(" - compiled entry     " INTPTR_FORMAT, p2i(from_compiled_entry()));
2228   st->print_cr(" - code size:         %d",   code_size());
2229   if (code_size() != 0) {
2230     st->print_cr(" - code start:        " INTPTR_FORMAT, p2i(code_base()));
2231     st->print_cr(" - code end (excl):   " INTPTR_FORMAT, p2i(code_base() + code_size()));
2232   }
2233   if (method_data() != NULL) {
2234     st->print_cr(" - method data:       " INTPTR_FORMAT, p2i(method_data()));
2235   }
2236   st->print_cr(" - checked ex length: %d",   checked_exceptions_length());
2237   if (checked_exceptions_length() > 0) {
2238     CheckedExceptionElement* table = checked_exceptions_start();
2239     st->print_cr(" - checked ex start:  " INTPTR_FORMAT, p2i(table));


2277     st->print_cr(" - signature handler: " INTPTR_FORMAT, p2i(signature_handler()));
2278   }
2279 }
2280 
2281 void Method::print_linkage_flags(outputStream* st) {
2282   access_flags().print_on(st);
2283   if (is_default_method()) {
2284     st->print("default ");
2285   }
2286   if (is_overpass()) {
2287     st->print("overpass ");
2288   }
2289 }
2290 #endif //PRODUCT
2291 
2292 void Method::print_value_on(outputStream* st) const {
2293   assert(is_method(), "must be method");
2294   st->print("%s", internal_name());
2295   print_address_on(st);
2296   st->print(" ");

2297   name()->print_value_on(st);
2298   st->print(" ");
2299   signature()->print_value_on(st);
2300   st->print(" in ");
2301   method_holder()->print_value_on(st);
2302   if (WizardMode) st->print("#%d", _vtable_index);
2303   if (WizardMode) st->print("[%d,%d]", size_of_parameters(), max_locals());
2304   if (WizardMode && code() != NULL) st->print(" ((nmethod*)%p)", code());
2305 }
2306 
2307 #if INCLUDE_SERVICES
2308 // Size Statistics
2309 void Method::collect_statistics(KlassSizeStats *sz) const {
2310   int mysize = sz->count(this);
2311   sz->_method_bytes += mysize;
2312   sz->_method_all_bytes += mysize;
2313   sz->_rw_bytes += mysize;
2314 
2315   if (constMethod()) {
2316     constMethod()->collect_statistics(sz);




  31 #include "gc/shared/collectedHeap.inline.hpp"
  32 #include "interpreter/bytecodeStream.hpp"
  33 #include "interpreter/bytecodeTracer.hpp"
  34 #include "interpreter/bytecodes.hpp"
  35 #include "interpreter/interpreter.hpp"
  36 #include "interpreter/oopMapCache.hpp"
  37 #include "memory/allocation.inline.hpp"
  38 #include "memory/heapInspection.hpp"
  39 #include "memory/metadataFactory.hpp"
  40 #include "memory/metaspaceClosure.hpp"
  41 #include "memory/metaspaceShared.hpp"
  42 #include "memory/oopFactory.hpp"
  43 #include "memory/resourceArea.hpp"
  44 #include "oops/constMethod.hpp"
  45 #include "oops/constantPool.hpp"
  46 #include "oops/method.inline.hpp"
  47 #include "oops/methodData.hpp"
  48 #include "oops/objArrayOop.inline.hpp"
  49 #include "oops/oop.inline.hpp"
  50 #include "oops/symbol.hpp"
  51 #include "oops/valueKlass.hpp"
  52 #include "prims/jvmtiExport.hpp"
  53 #include "prims/methodHandles.hpp"
  54 #include "prims/nativeLookup.hpp"
  55 #include "runtime/arguments.hpp"
  56 #include "runtime/compilationPolicy.hpp"
  57 #include "runtime/frame.inline.hpp"
  58 #include "runtime/handles.inline.hpp"
  59 #include "runtime/init.hpp"
  60 #include "runtime/orderAccess.hpp"
  61 #include "runtime/relocator.hpp"
  62 #include "runtime/safepointVerifiers.hpp"
  63 #include "runtime/sharedRuntime.hpp"
  64 #include "runtime/signature.hpp"
  65 #include "utilities/align.hpp"
  66 #include "utilities/quickSort.hpp"
  67 #include "utilities/vmError.hpp"
  68 #include "utilities/xmlstream.hpp"
  69 
  70 // Implementation of Method
  71 


  91   set_constMethod(xconst);
  92   set_access_flags(access_flags);
  93   set_intrinsic_id(vmIntrinsics::_none);
  94   set_force_inline(false);
  95   set_hidden(false);
  96   set_dont_inline(false);
  97   set_has_injected_profile(false);
  98   set_method_data(NULL);
  99   clear_method_counters();
 100   set_vtable_index(Method::garbage_vtable_index);
 101 
 102   // Fix and bury in Method*
 103   set_interpreter_entry(NULL); // sets i2i entry and from_int
 104   set_adapter_entry(NULL);
 105   clear_code(false /* don't need a lock */); // from_c/from_i get set to c2i/i2i
 106 
 107   if (access_flags.is_native()) {
 108     clear_native_function();
 109     set_signature_handler(NULL);
 110   }

 111   NOT_PRODUCT(set_compiled_invocation_count(0);)
 112 }
 113 
 114 // Release Method*.  The nmethod will be gone when we get here because
 115 // we've walked the code cache.
 116 void Method::deallocate_contents(ClassLoaderData* loader_data) {
 117   MetadataFactory::free_metadata(loader_data, constMethod());
 118   set_constMethod(NULL);
 119   MetadataFactory::free_metadata(loader_data, method_data());
 120   set_method_data(NULL);
 121   MetadataFactory::free_metadata(loader_data, method_counters());
 122   clear_method_counters();
 123   // The nmethod will be gone when we get here.
 124   if (code() != NULL) _code = NULL;
 125 }
 126 
 127 address Method::get_i2c_entry() {
 128   assert(adapter() != NULL, "must have");
 129   return adapter()->get_i2c_entry();
 130 }


 450   // Try to install a pointer to MethodCounters, return true on success.
 451   return Atomic::replace_if_null(counters, &_method_counters);
 452 }
 453 
 454 int Method::extra_stack_words() {
 455   // not an inline function, to avoid a header dependency on Interpreter
 456   return extra_stack_entries() * Interpreter::stackElementSize;
 457 }
 458 
 459 
 460 void Method::compute_size_of_parameters(Thread *thread) {
 461   ArgumentSizeComputer asc(signature());
 462   set_size_of_parameters(asc.size() + (is_static() ? 0 : 1));
 463 }
 464 
 465 BasicType Method::result_type() const {
 466   ResultTypeFinder rtf(signature());
 467   return rtf.type();
 468 }
 469 
 470 #ifdef ASSERT
 471 // ValueKlass the method is declared to return. This must not
 472 // safepoint as it is called with references live on the stack at
 473 // locations the GC is unaware of.
 474 ValueKlass* Method::returned_value_type(Thread* thread) const {
 475   SignatureStream ss(signature());
 476   while (!ss.at_return_type()) {
 477     ss.next();
 478   }
 479   Handle class_loader(thread, method_holder()->class_loader());
 480   Handle protection_domain(thread, method_holder()->protection_domain());
 481   Klass* k = NULL;
 482   {
 483     NoSafepointVerifier nsv;
 484     k = ss.as_klass(class_loader, protection_domain, SignatureStream::ReturnNull, thread);
 485   }
 486   assert(k != NULL && !thread->has_pending_exception(), "can't resolve klass");
 487   return ValueKlass::cast(k);
 488 }
 489 #endif
 490 
 491 bool Method::is_empty_method() const {
 492   return  code_size() == 1
 493       && *code_base() == Bytecodes::_return;
 494 }
 495 
 496 
 497 bool Method::is_vanilla_constructor() const {
 498   // Returns true if this method is a vanilla constructor, i.e. an "<init>" "()V" method
 499   // which only calls the superclass vanilla constructor and possibly does stores of
 500   // zero constants to local fields:
 501   //
 502   //   aload_0
 503   //   invokespecial
 504   //   indexbyte1
 505   //   indexbyte2
 506   //
 507   // followed by an (optional) sequence of:
 508   //
 509   //   aload_0


 720     // Not necessarily sorted and not necessarily one-to-one.
 721     CompressedLineNumberReadStream stream(compressed_linenumber_table());
 722     while (stream.read_pair()) {
 723       if (stream.bci() == bci) {
 724         // perfect match
 725         return stream.line();
 726       } else {
 727         // update best_bci/line
 728         if (stream.bci() < bci && stream.bci() >= best_bci) {
 729           best_bci  = stream.bci();
 730           best_line = stream.line();
 731         }
 732       }
 733     }
 734   }
 735   return best_line;
 736 }
 737 
 738 
 739 bool Method::is_klass_loaded_by_klass_index(int klass_index) const {
 740   if( constants()->tag_at(klass_index).is_unresolved_klass()) {
 741     Thread *thread = Thread::current();
 742     Symbol* klass_name = constants()->klass_name_at(klass_index);
 743     Handle loader(thread, method_holder()->class_loader());
 744     Handle prot  (thread, method_holder()->protection_domain());
 745     return SystemDictionary::find(klass_name, loader, prot, thread) != NULL;
 746   } else {
 747     return true;
 748   }
 749 }
 750 
 751 
 752 bool Method::is_klass_loaded(int refinfo_index, bool must_be_resolved) const {
 753   int klass_index = constants()->klass_ref_index_at(refinfo_index);
 754   if (must_be_resolved) {
 755     // Make sure klass is resolved in constantpool.
 756     if (constants()->tag_at(klass_index).is_unresolved_klass()) {
 757       return false;
 758     }
 759   }
 760   return is_klass_loaded_by_klass_index(klass_index);
 761 }
 762 
 763 
 764 void Method::set_native_function(address function, bool post_event_flag) {
 765   assert(function != NULL, "use clear_native_function to unregister natives");
 766   assert(!is_method_handle_intrinsic() || function == SharedRuntime::native_method_throw_unsatisfied_link_error_entry(), "");
 767   address* native_function = native_function_addr();
 768 
 769   // We can see racers trying to place the same native function into place. Once
 770   // is plenty.
 771   address current = *native_function;
 772   if (current == function) return;
 773   if (post_event_flag && JvmtiExport::should_post_native_method_bind() &&
 774       function != NULL) {
 775     // native_method_throw_unsatisfied_link_error_entry() should only
 776     // be passed when post_event_flag is false.
 777     assert(function !=
 778       SharedRuntime::native_method_throw_unsatisfied_link_error_entry(),


 917   if (comp_level == CompLevel_all) {
 918     set_not_c1_osr_compilable();
 919     set_not_c2_osr_compilable();
 920   } else {
 921     if (is_c1_compile(comp_level))
 922       set_not_c1_osr_compilable();
 923     if (is_c2_compile(comp_level))
 924       set_not_c2_osr_compilable();
 925   }
 926   CompilationPolicy::policy()->disable_compilation(this);
 927   assert(!CompilationPolicy::can_be_osr_compiled(this, comp_level), "sanity check");
 928 }
 929 
 930 // Revert to using the interpreter and clear out the nmethod
 931 void Method::clear_code(bool acquire_lock /* = true */) {
 932   MutexLockerEx pl(acquire_lock ? Patching_lock : NULL, Mutex::_no_safepoint_check_flag);
 933   // this may be NULL if c2i adapters have not been made yet
 934   // Only should happen at allocate time.
 935   if (adapter() == NULL) {
 936     _from_compiled_entry    = NULL;
 937     _from_compiled_value_entry = NULL;
 938     _from_compiled_value_ro_entry = NULL;
 939   } else {
 940     _from_compiled_entry    = adapter()->get_c2i_entry();
 941     _from_compiled_value_entry = adapter()->get_c2i_value_entry();
 942     _from_compiled_value_ro_entry = adapter()->get_c2i_value_ro_entry();
 943   }
 944   OrderAccess::storestore();
 945   _from_interpreted_entry = _i2i_entry;
 946   OrderAccess::storestore();
 947   _code = NULL;
 948 }
 949 
 950 #if INCLUDE_CDS
 951 // Called by class data sharing to remove any entry points (which are not shared)
 952 void Method::unlink_method() {
 953   _code = NULL;
 954 
 955   assert(DumpSharedSpaces, "dump time only");
 956   // Set the values to what they should be at run time. Note that
 957   // this Method can no longer be executed during dump time.
 958   _i2i_entry = Interpreter::entry_for_cds_method(this);
 959   _from_interpreted_entry = _i2i_entry;
 960 
 961   if (is_native()) {
 962     *native_function_addr() = NULL;
 963     set_signature_handler(NULL);
 964   }
 965   NOT_PRODUCT(set_compiled_invocation_count(0);)
 966 
 967   CDSAdapterHandlerEntry* cds_adapter = (CDSAdapterHandlerEntry*)adapter();
 968   constMethod()->set_adapter_trampoline(cds_adapter->get_adapter_trampoline());
 969   _from_compiled_entry = cds_adapter->get_c2i_entry_trampoline();
 970   assert(*((int*)_from_compiled_entry) == 0, "must be NULL during dump time, to be initialized at run time");
 971   _from_compiled_value_entry = cds_adapter->get_c2i_entry_trampoline();
 972   assert(*((int*)_from_compiled_value_entry) == 0, "must be NULL during dump time, to be initialized at run time");
 973   _from_compiled_value_ro_entry = cds_adapter->get_c2i_entry_trampoline();
 974   assert(*((int*)_from_compiled_value_ro_entry) == 0, "must be NULL during dump time, to be initialized at run time");
 975 
 976   set_method_data(NULL);
 977   clear_method_counters();
 978 }
 979 #endif
 980 
 981 /****************************************************************************
 982 // The following illustrates how the entries work for CDS shared Methods:
 983 //
 984 // Our goal is to delay writing into a shared Method until it's compiled.
 985 // Hence, we want to determine the initial values for _i2i_entry,
 986 // _from_interpreted_entry and _from_compiled_entry during CDS dump time.
 987 //
 988 // In this example, both Methods A and B have the _i2i_entry of "zero_locals".
 989 // They also have similar signatures so that they will share the same
 990 // AdapterHandlerEntry.
 991 //
 992 // _adapter_trampoline points to a fixed location in the RW section of
 993 // the CDS archive. This location initially contains a NULL pointer. When the
 994 // first of method A or B is linked, an AdapterHandlerEntry is allocated


1102 
1103 address Method::make_adapters(const methodHandle& mh, TRAPS) {
1104   // Adapters for compiled code are made eagerly here.  They are fairly
1105   // small (generally < 100 bytes) and quick to make (and cached and shared)
1106   // so making them eagerly shouldn't be too expensive.
1107   AdapterHandlerEntry* adapter = AdapterHandlerLibrary::get_adapter(mh);
1108   if (adapter == NULL ) {
1109     if (!is_init_completed()) {
1110       // Don't throw exceptions during VM initialization because java.lang.* classes
1111       // might not have been initialized, causing problems when constructing the
1112       // Java exception object.
1113       vm_exit_during_initialization("Out of space in CodeCache for adapters");
1114     } else {
1115       THROW_MSG_NULL(vmSymbols::java_lang_VirtualMachineError(), "Out of space in CodeCache for adapters");
1116     }
1117   }
1118 
1119   if (mh->is_shared()) {
1120     assert(mh->adapter() == adapter, "must be");
1121     assert(mh->_from_compiled_entry != NULL, "must be");
1122     assert(mh->_from_compiled_value_entry != NULL, "must be");
1123     assert(mh->_from_compiled_value_ro_entry != NULL, "must be");
1124   } else {
1125     mh->set_adapter_entry(adapter);
1126     mh->_from_compiled_entry = adapter->get_c2i_entry();
1127     mh->_from_compiled_value_entry = adapter->get_c2i_value_entry();
1128     mh->_from_compiled_value_ro_entry = adapter->get_c2i_value_ro_entry();
1129   }
1130   return adapter->get_c2i_entry();
1131 }
1132 
1133 void Method::restore_unshareable_info(TRAPS) {
1134   assert(is_method() && is_valid_method(this), "ensure C++ vtable is restored");
1135 
1136   // Since restore_unshareable_info can be called more than once for a method, don't
1137   // redo any work.
1138   if (adapter() == NULL) {
1139     methodHandle mh(THREAD, this);
1140     link_method(mh, CHECK);
1141   }
1142 }
1143 
1144 address Method::from_compiled_entry_no_trampoline() const {
1145   CompiledMethod *code = OrderAccess::load_acquire(&_code);
1146   if (code) {
1147     return code->verified_entry_point();
1148   } else {
1149     return adapter()->get_c2i_entry();
1150   }
1151 }
1152 
1153 // The verified_code_entry() must be called when a invoke is resolved
1154 // on this method.
1155 
1156 // It returns the compiled code entry point, after asserting not null.
1157 // This function is called after potential safepoints so that nmethod
1158 // or adapter that it points to is still live and valid.
1159 // This function must not hit a safepoint!
1160 address Method::verified_code_entry() {
1161   debug_only(NoSafepointVerifier nsv;)
1162   assert(_from_compiled_entry != NULL, "must be set");
1163   return _from_compiled_entry;
1164 }
1165 
1166 address Method::verified_value_ro_code_entry() {
1167   debug_only(NoSafepointVerifier nsv;)
1168   assert(_from_compiled_value_ro_entry != NULL, "must be set");
1169   return _from_compiled_value_ro_entry;
1170 }
1171 
1172 // Check that if an nmethod ref exists, it has a backlink to this or no backlink at all
1173 // (could be racing a deopt).
1174 // Not inline to avoid circular ref.
1175 bool Method::check_code() const {
1176   // cached in a register or local.  There's a race on the value of the field.
1177   CompiledMethod *code = OrderAccess::load_acquire(&_code);
1178   return code == NULL || (code->method() == NULL) || (code->method() == (Method*)this && !code->is_osr_method());
1179 }
1180 
1181 // Install compiled code.  Instantly it can execute.
1182 void Method::set_code(const methodHandle& mh, CompiledMethod *code) {
1183   MutexLockerEx pl(Patching_lock, Mutex::_no_safepoint_check_flag);
1184   assert( code, "use clear_code to remove code" );
1185   assert( mh->check_code(), "" );
1186 
1187   guarantee(mh->adapter() != NULL, "Adapter blob must already exist!");
1188 
1189   // These writes must happen in this order, because the interpreter will
1190   // directly jump to from_interpreted_entry which jumps to an i2c adapter
1191   // which jumps to _from_compiled_entry.
1192   mh->_code = code;             // Assign before allowing compiled code to exec
1193 
1194   int comp_level = code->comp_level();
1195   // In theory there could be a race here. In practice it is unlikely
1196   // and not worth worrying about.
1197   if (comp_level > mh->highest_comp_level()) {
1198     mh->set_highest_comp_level(comp_level);
1199   }
1200 
1201   OrderAccess::storestore();
1202   mh->_from_compiled_entry = code->verified_entry_point();
1203   mh->_from_compiled_value_entry = code->verified_value_entry_point();
1204   mh->_from_compiled_value_ro_entry = code->verified_value_ro_entry_point();
1205   OrderAccess::storestore();
1206   // Instantly compiled code can execute.
1207   if (!mh->is_method_handle_intrinsic())
1208     mh->_from_interpreted_entry = mh->get_i2c_entry();
1209 }
1210 
1211 
1212 bool Method::is_overridden_in(Klass* k) const {
1213   InstanceKlass* ik = InstanceKlass::cast(k);
1214 
1215   if (ik->is_interface()) return false;
1216 
1217   // If method is an interface, we skip it - except if it
1218   // is a miranda method
1219   if (method_holder()->is_interface()) {
1220     // Check that method is not a miranda method
1221     if (ik->lookup_method(name(), signature()) == NULL) {
1222       // No implementation exist - so miranda method
1223       return false;
1224     }


2242 void Method::print_on(outputStream* st) const {
2243   ResourceMark rm;
2244   assert(is_method(), "must be method");
2245   st->print_cr("%s", internal_name());
2246   st->print_cr(" - this oop:          " INTPTR_FORMAT, p2i(this));
2247   st->print   (" - method holder:     "); method_holder()->print_value_on(st); st->cr();
2248   st->print   (" - constants:         " INTPTR_FORMAT " ", p2i(constants()));
2249   constants()->print_value_on(st); st->cr();
2250   st->print   (" - access:            0x%x  ", access_flags().as_int()); access_flags().print_on(st); st->cr();
2251   st->print   (" - name:              ");    name()->print_value_on(st); st->cr();
2252   st->print   (" - signature:         ");    signature()->print_value_on(st); st->cr();
2253   st->print_cr(" - max stack:         %d",   max_stack());
2254   st->print_cr(" - max locals:        %d",   max_locals());
2255   st->print_cr(" - size of params:    %d",   size_of_parameters());
2256   st->print_cr(" - method size:       %d",   method_size());
2257   if (intrinsic_id() != vmIntrinsics::_none)
2258     st->print_cr(" - intrinsic id:      %d %s", intrinsic_id(), vmIntrinsics::name_at(intrinsic_id()));
2259   if (highest_comp_level() != CompLevel_none)
2260     st->print_cr(" - highest level:     %d", highest_comp_level());
2261   st->print_cr(" - vtable index:      %d",   _vtable_index);
2262   if (valid_itable_index())
2263     st->print_cr(" - itable index:      %d",   itable_index());
2264   st->print_cr(" - i2i entry:         " INTPTR_FORMAT, p2i(interpreter_entry()));
2265   st->print(   " - adapters:          ");
2266   AdapterHandlerEntry* a = ((Method*)this)->adapter();
2267   if (a == NULL)
2268     st->print_cr(INTPTR_FORMAT, p2i(a));
2269   else
2270     a->print_adapter_on(st);
2271   st->print_cr(" - compiled entry     " INTPTR_FORMAT, p2i(from_compiled_entry()));
2272   st->print_cr(" - code size:         %d",   code_size());
2273   if (code_size() != 0) {
2274     st->print_cr(" - code start:        " INTPTR_FORMAT, p2i(code_base()));
2275     st->print_cr(" - code end (excl):   " INTPTR_FORMAT, p2i(code_base() + code_size()));
2276   }
2277   if (method_data() != NULL) {
2278     st->print_cr(" - method data:       " INTPTR_FORMAT, p2i(method_data()));
2279   }
2280   st->print_cr(" - checked ex length: %d",   checked_exceptions_length());
2281   if (checked_exceptions_length() > 0) {
2282     CheckedExceptionElement* table = checked_exceptions_start();
2283     st->print_cr(" - checked ex start:  " INTPTR_FORMAT, p2i(table));


2321     st->print_cr(" - signature handler: " INTPTR_FORMAT, p2i(signature_handler()));
2322   }
2323 }
2324 
2325 void Method::print_linkage_flags(outputStream* st) {
2326   access_flags().print_on(st);
2327   if (is_default_method()) {
2328     st->print("default ");
2329   }
2330   if (is_overpass()) {
2331     st->print("overpass ");
2332   }
2333 }
2334 #endif //PRODUCT
2335 
2336 void Method::print_value_on(outputStream* st) const {
2337   assert(is_method(), "must be method");
2338   st->print("%s", internal_name());
2339   print_address_on(st);
2340   st->print(" ");
2341   if (WizardMode) access_flags().print_on(st);
2342   name()->print_value_on(st);
2343   st->print(" ");
2344   signature()->print_value_on(st);
2345   st->print(" in ");
2346   method_holder()->print_value_on(st);
2347   if (WizardMode) st->print("#%d", _vtable_index);
2348   if (WizardMode) st->print("[%d,%d]", size_of_parameters(), max_locals());
2349   if (WizardMode && code() != NULL) st->print(" ((nmethod*)%p)", code());
2350 }
2351 
2352 #if INCLUDE_SERVICES
2353 // Size Statistics
2354 void Method::collect_statistics(KlassSizeStats *sz) const {
2355   int mysize = sz->count(this);
2356   sz->_method_bytes += mysize;
2357   sz->_method_all_bytes += mysize;
2358   sz->_rw_bytes += mysize;
2359 
2360   if (constMethod()) {
2361     constMethod()->collect_statistics(sz);


< prev index next >