< prev index next >

src/hotspot/share/oops/method.cpp

Print this page

  40 #include "interpreter/interpreter.hpp"
  41 #include "interpreter/oopMapCache.hpp"
  42 #include "logging/log.hpp"
  43 #include "logging/logTag.hpp"
  44 #include "logging/logStream.hpp"
  45 #include "memory/allocation.inline.hpp"
  46 #include "memory/metadataFactory.hpp"
  47 #include "memory/metaspaceClosure.hpp"
  48 #include "memory/oopFactory.hpp"
  49 #include "memory/resourceArea.hpp"
  50 #include "memory/universe.hpp"
  51 #include "oops/constMethod.hpp"
  52 #include "oops/constantPool.hpp"
  53 #include "oops/klass.inline.hpp"
  54 #include "oops/method.inline.hpp"
  55 #include "oops/methodData.hpp"
  56 #include "oops/objArrayKlass.hpp"
  57 #include "oops/objArrayOop.inline.hpp"
  58 #include "oops/oop.inline.hpp"
  59 #include "oops/symbol.hpp"

  60 #include "prims/jvmtiExport.hpp"
  61 #include "prims/methodHandles.hpp"
  62 #include "runtime/arguments.hpp"
  63 #include "runtime/atomic.hpp"
  64 #include "runtime/frame.inline.hpp"
  65 #include "runtime/handles.inline.hpp"
  66 #include "runtime/init.hpp"
  67 #include "runtime/orderAccess.hpp"
  68 #include "runtime/relocator.hpp"
  69 #include "runtime/safepointVerifiers.hpp"
  70 #include "runtime/sharedRuntime.hpp"
  71 #include "runtime/signature.hpp"
  72 #include "runtime/vm_version.hpp"
  73 #include "services/memTracker.hpp"
  74 #include "utilities/align.hpp"
  75 #include "utilities/quickSort.hpp"
  76 #include "utilities/vmError.hpp"
  77 #include "utilities/xmlstream.hpp"
  78 
  79 // Implementation of Method

 100   set_constMethod(xconst);
 101   set_access_flags(access_flags);
 102   set_intrinsic_id(vmIntrinsics::_none);
 103   set_force_inline(false);
 104   set_hidden(false);
 105   set_dont_inline(false);
 106   set_has_injected_profile(false);
 107   set_method_data(NULL);
 108   clear_method_counters();
 109   set_vtable_index(Method::garbage_vtable_index);
 110 
 111   // Fix and bury in Method*
 112   set_interpreter_entry(NULL); // sets i2i entry and from_int
 113   set_adapter_entry(NULL);
 114   Method::clear_code(); // from_c/from_i get set to c2i/i2i
 115 
 116   if (access_flags.is_native()) {
 117     clear_native_function();
 118     set_signature_handler(NULL);
 119   }
 120 
 121   NOT_PRODUCT(set_compiled_invocation_count(0);)
 122 }
 123 
 124 // Release Method*.  The nmethod will be gone when we get here because
 125 // we've walked the code cache.
 126 void Method::deallocate_contents(ClassLoaderData* loader_data) {
 127   MetadataFactory::free_metadata(loader_data, constMethod());
 128   set_constMethod(NULL);
 129   MetadataFactory::free_metadata(loader_data, method_data());
 130   set_method_data(NULL);
 131   MetadataFactory::free_metadata(loader_data, method_counters());
 132   clear_method_counters();
 133   // The nmethod will be gone when we get here.
 134   if (code() != NULL) _code = NULL;
 135 }
 136 
 137 void Method::release_C_heap_structures() {
 138   if (method_data()) {
 139 #if INCLUDE_JVMCI
 140     FailedSpeculation::free_failed_speculations(method_data()->get_failed_speculations_address());
 141 #endif
 142     // Destroy MethodData
 143     method_data()->~MethodData();
 144   }
 145 }
 146 
 147 address Method::get_i2c_entry() {
 148   assert(adapter() != NULL, "must have");
 149   return adapter()->get_i2c_entry();
 150 }
 151 
 152 address Method::get_c2i_entry() {
 153   assert(adapter() != NULL, "must have");
 154   return adapter()->get_c2i_entry();
 155 }
 156 





 157 address Method::get_c2i_unverified_entry() {
 158   assert(adapter() != NULL, "must have");
 159   return adapter()->get_c2i_unverified_entry();
 160 }
 161 





 162 address Method::get_c2i_no_clinit_check_entry() {
 163   assert(VM_Version::supports_fast_class_init_checks(), "");
 164   assert(adapter() != NULL, "must have");
 165   return adapter()->get_c2i_no_clinit_check_entry();
 166 }
 167 
 168 char* Method::name_and_sig_as_C_string() const {
 169   return name_and_sig_as_C_string(constants()->pool_holder(), name(), signature());
 170 }
 171 
 172 char* Method::name_and_sig_as_C_string(char* buf, int size) const {
 173   return name_and_sig_as_C_string(constants()->pool_holder(), name(), signature(), buf, size);
 174 }
 175 
 176 char* Method::name_and_sig_as_C_string(Klass* klass, Symbol* method_name, Symbol* signature) {
 177   const char* klass_name = klass->external_name();
 178   int klass_name_len  = (int)strlen(klass_name);
 179   int method_name_len = method_name->utf8_length();
 180   int len             = klass_name_len + 1 + method_name_len + signature->utf8_length();
 181   char* dest          = NEW_RESOURCE_ARRAY(char, len + 1);

 648   return Atomic::replace_if_null(&_method_counters, counters);
 649 }
 650 
 651 int Method::extra_stack_words() {
 652   // not an inline function, to avoid a header dependency on Interpreter
 653   return extra_stack_entries() * Interpreter::stackElementSize;
 654 }
 655 
 656 // Derive size of parameters, return type, and fingerprint,
 657 // all in one pass, which is run at load time.
 658 // We need the first two, and might as well grab the third.
 659 void Method::compute_from_signature(Symbol* sig) {
 660   // At this point, since we are scanning the signature,
 661   // we might as well compute the whole fingerprint.
 662   Fingerprinter fp(sig, is_static());
 663   set_size_of_parameters(fp.size_of_parameters());
 664   constMethod()->set_result_type(fp.return_type());
 665   constMethod()->set_fingerprint(fp.fingerprint());
 666 }
 667 



















 668 bool Method::is_vanilla_constructor() const {
 669   // Returns true if this method is a vanilla constructor, i.e. an "<init>" "()V" method
 670   // which only calls the superclass vanilla constructor and possibly does stores of
 671   // zero constants to local fields:
 672   //
 673   //   aload_0
 674   //   invokespecial
 675   //   indexbyte1
 676   //   indexbyte2
 677   //
 678   // followed by an (optional) sequence of:
 679   //
 680   //   aload_0
 681   //   aconst_null / iconst_0 / fconst_0 / dconst_0
 682   //   putfield
 683   //   indexbyte1
 684   //   indexbyte2
 685   //
 686   // followed by:
 687   //
 688   //   return
 689 
 690   assert(name() == vmSymbols::object_initializer_name(),    "Should only be called for default constructors");
 691   assert(signature() == vmSymbols::void_method_signature(), "Should only be called for default constructors");
 692   int size = code_size();
 693   // Check if size match
 694   if (size == 0 || size % 5 != 0) return false;
 695   address cb = code_base();
 696   int last = size - 1;
 697   if (cb[0] != Bytecodes::_aload_0 || cb[1] != Bytecodes::_invokespecial || cb[last] != Bytecodes::_return) {

 698     // Does not call superclass default constructor
 699     return false;
 700   }
 701   // Check optional sequence
 702   for (int i = 4; i < last; i += 5) {
 703     if (cb[i] != Bytecodes::_aload_0) return false;
 704     if (!Bytecodes::is_zero_const(Bytecodes::cast(cb[i+1]))) return false;
 705     if (cb[i+2] != Bytecodes::_putfield) return false;
 706   }
 707   return true;
 708 }
 709 
 710 
 711 bool Method::compute_has_loops_flag() {
 712   BytecodeStream bcs(methodHandle(Thread::current(), this));
 713   Bytecodes::Code bc;
 714 
 715   while ((bc = bcs.next()) >= 0) {
 716     switch (bc) {
 717       case Bytecodes::_ifeq:

 857       if (size_of_parameters() != 3) return false;
 858       break;
 859     default:
 860       return false;
 861   }
 862   if (java_code_at(2) != Bytecodes::_putfield) return false;
 863   if (java_code_at(5) != Bytecodes::_return)   return false;
 864   return true;
 865 }
 866 
 867 bool Method::is_constant_getter() const {
 868   int last_index = code_size() - 1;
 869   // Check if the first 1-3 bytecodes are a constant push
 870   // and the last bytecode is a return.
 871   return (2 <= code_size() && code_size() <= 4 &&
 872           Bytecodes::is_const(java_code_at(0)) &&
 873           Bytecodes::length_for(java_code_at(0)) == last_index &&
 874           Bytecodes::is_return(java_code_at(last_index)));
 875 }
 876 
 877 bool Method::is_initializer() const {
 878   return is_object_initializer() || is_static_initializer();
 879 }
 880 
 881 bool Method::has_valid_initializer_flags() const {
 882   return (is_static() ||
 883           method_holder()->major_version() < 51);
 884 }
 885 
 886 bool Method::is_static_initializer() const {
 887   // For classfiles version 51 or greater, ensure that the clinit method is
 888   // static.  Non-static methods with the name "<clinit>" are not static
 889   // initializers. (older classfiles exempted for backward compatibility)
 890   return name() == vmSymbols::class_initializer_name() &&
 891          has_valid_initializer_flags();

 892 }
 893 
 894 bool Method::is_object_initializer() const {
 895    return name() == vmSymbols::object_initializer_name();






 896 }
 897 
 898 bool Method::needs_clinit_barrier() const {
 899   return is_static() && !method_holder()->is_initialized();
 900 }
 901 
 902 objArrayHandle Method::resolved_checked_exceptions_impl(Method* method, TRAPS) {
 903   int length = method->checked_exceptions_length();
 904   if (length == 0) {  // common case
 905     return objArrayHandle(THREAD, Universe::the_empty_class_array());
 906   } else {
 907     methodHandle h_this(THREAD, method);
 908     objArrayOop m_oop = oopFactory::new_objArray(vmClasses::Class_klass(), length, CHECK_(objArrayHandle()));
 909     objArrayHandle mirrors (THREAD, m_oop);
 910     for (int i = 0; i < length; i++) {
 911       CheckedExceptionElement* table = h_this->checked_exceptions_start(); // recompute on each iteration, not gc safe
 912       Klass* k = h_this->constants()->klass_at(table[i].class_cp_index, CHECK_(objArrayHandle()));
 913       if (log_is_enabled(Warning, exceptions) &&
 914           !k->is_subclass_of(vmClasses::Throwable_klass())) {
 915         ResourceMark rm(THREAD);

 933     // Not necessarily sorted and not necessarily one-to-one.
 934     CompressedLineNumberReadStream stream(compressed_linenumber_table());
 935     while (stream.read_pair()) {
 936       if (stream.bci() == bci) {
 937         // perfect match
 938         return stream.line();
 939       } else {
 940         // update best_bci/line
 941         if (stream.bci() < bci && stream.bci() >= best_bci) {
 942           best_bci  = stream.bci();
 943           best_line = stream.line();
 944         }
 945       }
 946     }
 947   }
 948   return best_line;
 949 }
 950 
 951 
 952 bool Method::is_klass_loaded_by_klass_index(int klass_index) const {
 953   if( constants()->tag_at(klass_index).is_unresolved_klass() ) {
 954     Thread *thread = Thread::current();
 955     Symbol* klass_name = constants()->klass_name_at(klass_index);
 956     Handle loader(thread, method_holder()->class_loader());
 957     Handle prot  (thread, method_holder()->protection_domain());
 958     return SystemDictionary::find_instance_klass(klass_name, loader, prot) != NULL;
 959   } else {
 960     return true;
 961   }
 962 }
 963 
 964 
 965 bool Method::is_klass_loaded(int refinfo_index, bool must_be_resolved) const {
 966   int klass_index = constants()->klass_ref_index_at(refinfo_index);
 967   if (must_be_resolved) {
 968     // Make sure klass is resolved in constantpool.
 969     if (constants()->tag_at(klass_index).is_unresolved_klass()) return false;


 970   }
 971   return is_klass_loaded_by_klass_index(klass_index);
 972 }
 973 
 974 
 975 void Method::set_native_function(address function, bool post_event_flag) {
 976   assert(function != NULL, "use clear_native_function to unregister natives");
 977   assert(!is_method_handle_intrinsic() || function == SharedRuntime::native_method_throw_unsatisfied_link_error_entry(), "");
 978   address* native_function = native_function_addr();
 979 
 980   // We can see racers trying to place the same native function into place. Once
 981   // is plenty.
 982   address current = *native_function;
 983   if (current == function) return;
 984   if (post_event_flag && JvmtiExport::should_post_native_method_bind() &&
 985       function != NULL) {
 986     // native_method_throw_unsatisfied_link_error_entry() should only
 987     // be passed when post_event_flag is false.
 988     assert(function !=
 989       SharedRuntime::native_method_throw_unsatisfied_link_error_entry(),

1118 void Method::set_not_osr_compilable(const char* reason, int comp_level, bool report) {
1119   print_made_not_compilable(comp_level, /*is_osr*/ true, report, reason);
1120   if (comp_level == CompLevel_all) {
1121     set_not_c1_osr_compilable();
1122     set_not_c2_osr_compilable();
1123   } else {
1124     if (is_c1_compile(comp_level))
1125       set_not_c1_osr_compilable();
1126     if (is_c2_compile(comp_level))
1127       set_not_c2_osr_compilable();
1128   }
1129   assert(!CompilationPolicy::can_be_osr_compiled(methodHandle(Thread::current(), this), comp_level), "sanity check");
1130 }
1131 
1132 // Revert to using the interpreter and clear out the nmethod
1133 void Method::clear_code() {
1134   // this may be NULL if c2i adapters have not been made yet
1135   // Only should happen at allocate time.
1136   if (adapter() == NULL) {
1137     _from_compiled_entry    = NULL;


1138   } else {
1139     _from_compiled_entry    = adapter()->get_c2i_entry();


1140   }
1141   OrderAccess::storestore();
1142   _from_interpreted_entry = _i2i_entry;
1143   OrderAccess::storestore();
1144   _code = NULL;
1145 }
1146 
1147 void Method::unlink_code(CompiledMethod *compare) {
1148   MutexLocker ml(CompiledMethod_lock->owned_by_self() ? NULL : CompiledMethod_lock, Mutex::_no_safepoint_check_flag);
1149   // We need to check if either the _code or _from_compiled_code_entry_point
1150   // refer to this nmethod because there is a race in setting these two fields
1151   // in Method* as seen in bugid 4947125.
1152   // If the vep() points to the zombie nmethod, the memory for the nmethod
1153   // could be flushed and the compiler and vtable stubs could still call
1154   // through it.
1155   if (code() == compare ||
1156       from_compiled_entry() == compare->verified_entry_point()) {
1157     clear_code();
1158   }
1159 }
1160 
1161 void Method::unlink_code() {
1162   MutexLocker ml(CompiledMethod_lock->owned_by_self() ? NULL : CompiledMethod_lock, Mutex::_no_safepoint_check_flag);
1163   clear_code();
1164 }
1165 
1166 #if INCLUDE_CDS
1167 // Called by class data sharing to remove any entry points (which are not shared)
1168 void Method::unlink_method() {
1169   Arguments::assert_is_dumping_archive();
1170   _code = NULL;
1171   _adapter = NULL;
1172   _i2i_entry = NULL;
1173   _from_compiled_entry = NULL;


1174   _from_interpreted_entry = NULL;
1175 
1176   if (is_native()) {
1177     *native_function_addr() = NULL;
1178     set_signature_handler(NULL);
1179   }
1180   NOT_PRODUCT(set_compiled_invocation_count(0);)
1181 
1182   set_method_data(NULL);
1183   clear_method_counters();
1184 }
1185 #endif
1186 
1187 // Called when the method_holder is getting linked. Setup entrypoints so the method
1188 // is ready to be called from interpreter, compiler, and vtables.
1189 void Method::link_method(const methodHandle& h_method, TRAPS) {
1190   // If the code cache is full, we may reenter this function for the
1191   // leftover methods that weren't linked.
1192   if (_i2i_entry != NULL) {
1193     return;

1224 }
1225 
1226 address Method::make_adapters(const methodHandle& mh, TRAPS) {
1227   // Adapters for compiled code are made eagerly here.  They are fairly
1228   // small (generally < 100 bytes) and quick to make (and cached and shared)
1229   // so making them eagerly shouldn't be too expensive.
1230   AdapterHandlerEntry* adapter = AdapterHandlerLibrary::get_adapter(mh);
1231   if (adapter == NULL ) {
1232     if (!is_init_completed()) {
1233       // Don't throw exceptions during VM initialization because java.lang.* classes
1234       // might not have been initialized, causing problems when constructing the
1235       // Java exception object.
1236       vm_exit_during_initialization("Out of space in CodeCache for adapters");
1237     } else {
1238       THROW_MSG_NULL(vmSymbols::java_lang_VirtualMachineError(), "Out of space in CodeCache for adapters");
1239     }
1240   }
1241 
1242   mh->set_adapter_entry(adapter);
1243   mh->_from_compiled_entry = adapter->get_c2i_entry();


1244   return adapter->get_c2i_entry();
1245 }
1246 
1247 void Method::restore_unshareable_info(TRAPS) {
1248   assert(is_method() && is_valid_method(this), "ensure C++ vtable is restored");
1249 }
1250 
1251 address Method::from_compiled_entry_no_trampoline() const {
1252   CompiledMethod *code = Atomic::load_acquire(&_code);
1253   if (code) {
1254     return code->verified_entry_point();





1255   } else {
1256     return adapter()->get_c2i_entry();





1257   }
1258 }
1259 
1260 // The verified_code_entry() must be called when a invoke is resolved
1261 // on this method.
1262 
1263 // It returns the compiled code entry point, after asserting not null.
1264 // This function is called after potential safepoints so that nmethod
1265 // or adapter that it points to is still live and valid.
1266 // This function must not hit a safepoint!
1267 address Method::verified_code_entry() {
1268   debug_only(NoSafepointVerifier nsv;)
1269   assert(_from_compiled_entry != NULL, "must be set");
1270   return _from_compiled_entry;
1271 }
1272 












1273 // Check that if an nmethod ref exists, it has a backlink to this or no backlink at all
1274 // (could be racing a deopt).
1275 // Not inline to avoid circular ref.
1276 bool Method::check_code() const {
1277   // cached in a register or local.  There's a race on the value of the field.
1278   CompiledMethod *code = Atomic::load_acquire(&_code);
1279   return code == NULL || (code->method() == NULL) || (code->method() == (Method*)this && !code->is_osr_method());
1280 }
1281 
1282 // Install compiled code.  Instantly it can execute.
1283 void Method::set_code(const methodHandle& mh, CompiledMethod *code) {
1284   assert_lock_strong(CompiledMethod_lock);
1285   assert( code, "use clear_code to remove code" );
1286   assert( mh->check_code(), "" );
1287 
1288   guarantee(mh->adapter() != NULL, "Adapter blob must already exist!");
1289 
1290   // These writes must happen in this order, because the interpreter will
1291   // directly jump to from_interpreted_entry which jumps to an i2c adapter
1292   // which jumps to _from_compiled_entry.
1293   mh->_code = code;             // Assign before allowing compiled code to exec
1294 
1295   int comp_level = code->comp_level();
1296   // In theory there could be a race here. In practice it is unlikely
1297   // and not worth worrying about.
1298   if (comp_level > mh->highest_comp_level()) {
1299     mh->set_highest_comp_level(comp_level);
1300   }
1301 
1302   OrderAccess::storestore();
1303   mh->_from_compiled_entry = code->verified_entry_point();


1304   OrderAccess::storestore();
1305   // Instantly compiled code can execute.
1306   if (!mh->is_method_handle_intrinsic())
1307     mh->_from_interpreted_entry = mh->get_i2c_entry();
1308 }
1309 
1310 
1311 bool Method::is_overridden_in(Klass* k) const {
1312   InstanceKlass* ik = InstanceKlass::cast(k);
1313 
1314   if (ik->is_interface()) return false;
1315 
1316   // If method is an interface, we skip it - except if it
1317   // is a miranda method
1318   if (method_holder()->is_interface()) {
1319     // Check that method is not a miranda method
1320     if (ik->lookup_method(name(), signature()) == NULL) {
1321       // No implementation exist - so miranda method
1322       return false;
1323     }

2318 void Method::print_on(outputStream* st) const {
2319   ResourceMark rm;
2320   assert(is_method(), "must be method");
2321   st->print_cr("%s", internal_name());
2322   st->print_cr(" - this oop:          " INTPTR_FORMAT, p2i(this));
2323   st->print   (" - method holder:     "); method_holder()->print_value_on(st); st->cr();
2324   st->print   (" - constants:         " INTPTR_FORMAT " ", p2i(constants()));
2325   constants()->print_value_on(st); st->cr();
2326   st->print   (" - access:            0x%x  ", access_flags().as_int()); access_flags().print_on(st); st->cr();
2327   st->print   (" - name:              ");    name()->print_value_on(st); st->cr();
2328   st->print   (" - signature:         ");    signature()->print_value_on(st); st->cr();
2329   st->print_cr(" - max stack:         %d",   max_stack());
2330   st->print_cr(" - max locals:        %d",   max_locals());
2331   st->print_cr(" - size of params:    %d",   size_of_parameters());
2332   st->print_cr(" - method size:       %d",   method_size());
2333   if (intrinsic_id() != vmIntrinsics::_none)
2334     st->print_cr(" - intrinsic id:      %d %s", vmIntrinsics::as_int(intrinsic_id()), vmIntrinsics::name_at(intrinsic_id()));
2335   if (highest_comp_level() != CompLevel_none)
2336     st->print_cr(" - highest level:     %d", highest_comp_level());
2337   st->print_cr(" - vtable index:      %d",   _vtable_index);




2338   st->print_cr(" - i2i entry:         " INTPTR_FORMAT, p2i(interpreter_entry()));
2339   st->print(   " - adapters:          ");
2340   AdapterHandlerEntry* a = ((Method*)this)->adapter();
2341   if (a == NULL)
2342     st->print_cr(INTPTR_FORMAT, p2i(a));
2343   else
2344     a->print_adapter_on(st);
2345   st->print_cr(" - compiled entry     " INTPTR_FORMAT, p2i(from_compiled_entry()));


2346   st->print_cr(" - code size:         %d",   code_size());
2347   if (code_size() != 0) {
2348     st->print_cr(" - code start:        " INTPTR_FORMAT, p2i(code_base()));
2349     st->print_cr(" - code end (excl):   " INTPTR_FORMAT, p2i(code_base() + code_size()));
2350   }
2351   if (method_data() != NULL) {
2352     st->print_cr(" - method data:       " INTPTR_FORMAT, p2i(method_data()));
2353   }
2354   st->print_cr(" - checked ex length: %d",   checked_exceptions_length());
2355   if (checked_exceptions_length() > 0) {
2356     CheckedExceptionElement* table = checked_exceptions_start();
2357     st->print_cr(" - checked ex start:  " INTPTR_FORMAT, p2i(table));
2358     if (Verbose) {
2359       for (int i = 0; i < checked_exceptions_length(); i++) {
2360         st->print_cr("   - throws %s", constants()->printable_name_at(table[i].class_cp_index));
2361       }
2362     }
2363   }
2364   if (has_linenumber_table()) {
2365     u_char* table = compressed_linenumber_table();

2395     st->print_cr(" - signature handler: " INTPTR_FORMAT, p2i(signature_handler()));
2396   }
2397 }
2398 
2399 void Method::print_linkage_flags(outputStream* st) {
2400   access_flags().print_on(st);
2401   if (is_default_method()) {
2402     st->print("default ");
2403   }
2404   if (is_overpass()) {
2405     st->print("overpass ");
2406   }
2407 }
2408 #endif //PRODUCT
2409 
2410 void Method::print_value_on(outputStream* st) const {
2411   assert(is_method(), "must be method");
2412   st->print("%s", internal_name());
2413   print_address_on(st);
2414   st->print(" ");

2415   name()->print_value_on(st);
2416   st->print(" ");
2417   signature()->print_value_on(st);
2418   st->print(" in ");
2419   method_holder()->print_value_on(st);
2420   if (WizardMode) st->print("#%d", _vtable_index);
2421   if (WizardMode) st->print("[%d,%d]", size_of_parameters(), max_locals());
2422   if (WizardMode && code() != NULL) st->print(" ((nmethod*)%p)", code());
2423 }
2424 
2425 // LogTouchedMethods and PrintTouchedMethods
2426 
2427 // TouchedMethodRecord -- we can't use a HashtableEntry<Method*> because
2428 // the Method may be garbage collected. Let's roll our own hash table.
2429 class TouchedMethodRecord : CHeapObj<mtTracing> {
2430 public:
2431   // It's OK to store Symbols here because they will NOT be GC'ed if
2432   // LogTouchedMethods is enabled.
2433   TouchedMethodRecord* _next;
2434   Symbol* _class_name;

  40 #include "interpreter/interpreter.hpp"
  41 #include "interpreter/oopMapCache.hpp"
  42 #include "logging/log.hpp"
  43 #include "logging/logTag.hpp"
  44 #include "logging/logStream.hpp"
  45 #include "memory/allocation.inline.hpp"
  46 #include "memory/metadataFactory.hpp"
  47 #include "memory/metaspaceClosure.hpp"
  48 #include "memory/oopFactory.hpp"
  49 #include "memory/resourceArea.hpp"
  50 #include "memory/universe.hpp"
  51 #include "oops/constMethod.hpp"
  52 #include "oops/constantPool.hpp"
  53 #include "oops/klass.inline.hpp"
  54 #include "oops/method.inline.hpp"
  55 #include "oops/methodData.hpp"
  56 #include "oops/objArrayKlass.hpp"
  57 #include "oops/objArrayOop.inline.hpp"
  58 #include "oops/oop.inline.hpp"
  59 #include "oops/symbol.hpp"
  60 #include "oops/inlineKlass.inline.hpp"
  61 #include "prims/jvmtiExport.hpp"
  62 #include "prims/methodHandles.hpp"
  63 #include "runtime/arguments.hpp"
  64 #include "runtime/atomic.hpp"
  65 #include "runtime/frame.inline.hpp"
  66 #include "runtime/handles.inline.hpp"
  67 #include "runtime/init.hpp"
  68 #include "runtime/orderAccess.hpp"
  69 #include "runtime/relocator.hpp"
  70 #include "runtime/safepointVerifiers.hpp"
  71 #include "runtime/sharedRuntime.hpp"
  72 #include "runtime/signature.hpp"
  73 #include "runtime/vm_version.hpp"
  74 #include "services/memTracker.hpp"
  75 #include "utilities/align.hpp"
  76 #include "utilities/quickSort.hpp"
  77 #include "utilities/vmError.hpp"
  78 #include "utilities/xmlstream.hpp"
  79 
  80 // Implementation of Method

 101   set_constMethod(xconst);
 102   set_access_flags(access_flags);
 103   set_intrinsic_id(vmIntrinsics::_none);
 104   set_force_inline(false);
 105   set_hidden(false);
 106   set_dont_inline(false);
 107   set_has_injected_profile(false);
 108   set_method_data(NULL);
 109   clear_method_counters();
 110   set_vtable_index(Method::garbage_vtable_index);
 111 
 112   // Fix and bury in Method*
 113   set_interpreter_entry(NULL); // sets i2i entry and from_int
 114   set_adapter_entry(NULL);
 115   Method::clear_code(); // from_c/from_i get set to c2i/i2i
 116 
 117   if (access_flags.is_native()) {
 118     clear_native_function();
 119     set_signature_handler(NULL);
 120   }

 121   NOT_PRODUCT(set_compiled_invocation_count(0);)
 122 }
 123 
 124 // Release Method*.  The nmethod will be gone when we get here because
 125 // we've walked the code cache.
 126 void Method::deallocate_contents(ClassLoaderData* loader_data) {
 127   MetadataFactory::free_metadata(loader_data, constMethod());
 128   set_constMethod(NULL);
 129   MetadataFactory::free_metadata(loader_data, method_data());
 130   set_method_data(NULL);
 131   MetadataFactory::free_metadata(loader_data, method_counters());
 132   clear_method_counters();
 133   // The nmethod will be gone when we get here.
 134   if (code() != NULL) _code = NULL;
 135 }
 136 
 137 void Method::release_C_heap_structures() {
 138   if (method_data()) {
 139 #if INCLUDE_JVMCI
 140     FailedSpeculation::free_failed_speculations(method_data()->get_failed_speculations_address());
 141 #endif
 142     // Destroy MethodData
 143     method_data()->~MethodData();
 144   }
 145 }
 146 
 147 address Method::get_i2c_entry() {
 148   assert(adapter() != NULL, "must have");
 149   return adapter()->get_i2c_entry();
 150 }
 151 
 152 address Method::get_c2i_entry() {
 153   assert(adapter() != NULL, "must have");
 154   return adapter()->get_c2i_entry();
 155 }
 156 
 157 address Method::get_c2i_inline_entry() {
 158   assert(adapter() != NULL, "must have");
 159   return adapter()->get_c2i_inline_entry();
 160 }
 161 
 162 address Method::get_c2i_unverified_entry() {
 163   assert(adapter() != NULL, "must have");
 164   return adapter()->get_c2i_unverified_entry();
 165 }
 166 
 167 address Method::get_c2i_unverified_inline_entry() {
 168   assert(adapter() != NULL, "must have");
 169   return adapter()->get_c2i_unverified_inline_entry();
 170 }
 171 
 172 address Method::get_c2i_no_clinit_check_entry() {
 173   assert(VM_Version::supports_fast_class_init_checks(), "");
 174   assert(adapter() != NULL, "must have");
 175   return adapter()->get_c2i_no_clinit_check_entry();
 176 }
 177 
 178 char* Method::name_and_sig_as_C_string() const {
 179   return name_and_sig_as_C_string(constants()->pool_holder(), name(), signature());
 180 }
 181 
 182 char* Method::name_and_sig_as_C_string(char* buf, int size) const {
 183   return name_and_sig_as_C_string(constants()->pool_holder(), name(), signature(), buf, size);
 184 }
 185 
 186 char* Method::name_and_sig_as_C_string(Klass* klass, Symbol* method_name, Symbol* signature) {
 187   const char* klass_name = klass->external_name();
 188   int klass_name_len  = (int)strlen(klass_name);
 189   int method_name_len = method_name->utf8_length();
 190   int len             = klass_name_len + 1 + method_name_len + signature->utf8_length();
 191   char* dest          = NEW_RESOURCE_ARRAY(char, len + 1);

 658   return Atomic::replace_if_null(&_method_counters, counters);
 659 }
 660 
 661 int Method::extra_stack_words() {
 662   // not an inline function, to avoid a header dependency on Interpreter
 663   return extra_stack_entries() * Interpreter::stackElementSize;
 664 }
 665 
 666 // Derive size of parameters, return type, and fingerprint,
 667 // all in one pass, which is run at load time.
 668 // We need the first two, and might as well grab the third.
 669 void Method::compute_from_signature(Symbol* sig) {
 670   // At this point, since we are scanning the signature,
 671   // we might as well compute the whole fingerprint.
 672   Fingerprinter fp(sig, is_static());
 673   set_size_of_parameters(fp.size_of_parameters());
 674   constMethod()->set_result_type(fp.return_type());
 675   constMethod()->set_fingerprint(fp.fingerprint());
 676 }
 677 
 678 // InlineKlass the method is declared to return. This must not
 679 // safepoint as it is called with references live on the stack at
 680 // locations the GC is unaware of.
 681 InlineKlass* Method::returned_inline_type(Thread* thread) const {
 682   SignatureStream ss(signature());
 683   while (!ss.at_return_type()) {
 684     ss.next();
 685   }
 686   Handle class_loader(thread, method_holder()->class_loader());
 687   Handle protection_domain(thread, method_holder()->protection_domain());
 688   Klass* k = NULL;
 689   {
 690     NoSafepointVerifier nsv;
 691     k = ss.as_klass(class_loader, protection_domain, SignatureStream::ReturnNull, JavaThread::cast(thread));
 692   }
 693   assert(k != NULL && !thread->has_pending_exception(), "can't resolve klass");
 694   return InlineKlass::cast(k);
 695 }
 696 
 697 bool Method::is_vanilla_constructor() const {
 698   // Returns true if this method is a vanilla constructor, i.e. an "<init>" "()V" method
 699   // which only calls the superclass vanilla constructor and possibly does stores of
 700   // zero constants to local fields:
 701   //
 702   //   aload_0, _fast_aload_0, or _nofast_aload_0
 703   //   invokespecial
 704   //   indexbyte1
 705   //   indexbyte2
 706   //
 707   // followed by an (optional) sequence of:
 708   //
 709   //   aload_0
 710   //   aconst_null / iconst_0 / fconst_0 / dconst_0
 711   //   putfield
 712   //   indexbyte1
 713   //   indexbyte2
 714   //
 715   // followed by:
 716   //
 717   //   return
 718 
 719   assert(name() == vmSymbols::object_initializer_name(),    "Should only be called for default constructors");
 720   assert(signature() == vmSymbols::void_method_signature(), "Should only be called for default constructors");
 721   int size = code_size();
 722   // Check if size match
 723   if (size == 0 || size % 5 != 0) return false;
 724   address cb = code_base();
 725   int last = size - 1;
 726   if ((cb[0] != Bytecodes::_aload_0 && cb[0] != Bytecodes::_fast_aload_0 && cb[0] != Bytecodes::_nofast_aload_0) ||
 727        cb[1] != Bytecodes::_invokespecial || cb[last] != Bytecodes::_return) {
 728     // Does not call superclass default constructor
 729     return false;
 730   }
 731   // Check optional sequence
 732   for (int i = 4; i < last; i += 5) {
 733     if (cb[i] != Bytecodes::_aload_0) return false;
 734     if (!Bytecodes::is_zero_const(Bytecodes::cast(cb[i+1]))) return false;
 735     if (cb[i+2] != Bytecodes::_putfield) return false;
 736   }
 737   return true;
 738 }
 739 
 740 
 741 bool Method::compute_has_loops_flag() {
 742   BytecodeStream bcs(methodHandle(Thread::current(), this));
 743   Bytecodes::Code bc;
 744 
 745   while ((bc = bcs.next()) >= 0) {
 746     switch (bc) {
 747       case Bytecodes::_ifeq:

 887       if (size_of_parameters() != 3) return false;
 888       break;
 889     default:
 890       return false;
 891   }
 892   if (java_code_at(2) != Bytecodes::_putfield) return false;
 893   if (java_code_at(5) != Bytecodes::_return)   return false;
 894   return true;
 895 }
 896 
 897 bool Method::is_constant_getter() const {
 898   int last_index = code_size() - 1;
 899   // Check if the first 1-3 bytecodes are a constant push
 900   // and the last bytecode is a return.
 901   return (2 <= code_size() && code_size() <= 4 &&
 902           Bytecodes::is_const(java_code_at(0)) &&
 903           Bytecodes::length_for(java_code_at(0)) == last_index &&
 904           Bytecodes::is_return(java_code_at(last_index)));
 905 }
 906 
 907 bool Method::is_object_constructor_or_class_initializer() const {
 908   return (is_object_constructor() || is_class_initializer());





 909 }
 910 
 911 bool Method::is_class_initializer() const {
 912   // For classfiles version 51 or greater, ensure that the clinit method is
 913   // static.  Non-static methods with the name "<clinit>" are not static
 914   // initializers. (older classfiles exempted for backward compatibility)
 915   return (name() == vmSymbols::class_initializer_name() &&
 916           (is_static() ||
 917            method_holder()->major_version() < 51));
 918 }
 919 
 920 // A method named <init>, if non-static, is a classic object constructor.
 921 bool Method::is_object_constructor() const {
 922    return name() == vmSymbols::object_initializer_name() && !is_static();
 923 }
 924 
 925 // A static method named <init> is a factory for an inline class.
 926 bool Method::is_static_init_factory() const {
 927    return name() == vmSymbols::object_initializer_name() && is_static();
 928 }
 929 
 930 bool Method::needs_clinit_barrier() const {
 931   return is_static() && !method_holder()->is_initialized();
 932 }
 933 
 934 objArrayHandle Method::resolved_checked_exceptions_impl(Method* method, TRAPS) {
 935   int length = method->checked_exceptions_length();
 936   if (length == 0) {  // common case
 937     return objArrayHandle(THREAD, Universe::the_empty_class_array());
 938   } else {
 939     methodHandle h_this(THREAD, method);
 940     objArrayOop m_oop = oopFactory::new_objArray(vmClasses::Class_klass(), length, CHECK_(objArrayHandle()));
 941     objArrayHandle mirrors (THREAD, m_oop);
 942     for (int i = 0; i < length; i++) {
 943       CheckedExceptionElement* table = h_this->checked_exceptions_start(); // recompute on each iteration, not gc safe
 944       Klass* k = h_this->constants()->klass_at(table[i].class_cp_index, CHECK_(objArrayHandle()));
 945       if (log_is_enabled(Warning, exceptions) &&
 946           !k->is_subclass_of(vmClasses::Throwable_klass())) {
 947         ResourceMark rm(THREAD);

 965     // Not necessarily sorted and not necessarily one-to-one.
 966     CompressedLineNumberReadStream stream(compressed_linenumber_table());
 967     while (stream.read_pair()) {
 968       if (stream.bci() == bci) {
 969         // perfect match
 970         return stream.line();
 971       } else {
 972         // update best_bci/line
 973         if (stream.bci() < bci && stream.bci() >= best_bci) {
 974           best_bci  = stream.bci();
 975           best_line = stream.line();
 976         }
 977       }
 978     }
 979   }
 980   return best_line;
 981 }
 982 
 983 
 984 bool Method::is_klass_loaded_by_klass_index(int klass_index) const {
 985   if( constants()->tag_at(klass_index).is_unresolved_klass()) {
 986     Thread *thread = Thread::current();
 987     Symbol* klass_name = constants()->klass_name_at(klass_index);
 988     Handle loader(thread, method_holder()->class_loader());
 989     Handle prot  (thread, method_holder()->protection_domain());
 990     return SystemDictionary::find_instance_klass(klass_name, loader, prot) != NULL;
 991   } else {
 992     return true;
 993   }
 994 }
 995 
 996 
 997 bool Method::is_klass_loaded(int refinfo_index, bool must_be_resolved) const {
 998   int klass_index = constants()->klass_ref_index_at(refinfo_index);
 999   if (must_be_resolved) {
1000     // Make sure klass is resolved in constantpool.
1001     if (constants()->tag_at(klass_index).is_unresolved_klass()) {
1002       return false;
1003     }
1004   }
1005   return is_klass_loaded_by_klass_index(klass_index);
1006 }
1007 
1008 
1009 void Method::set_native_function(address function, bool post_event_flag) {
1010   assert(function != NULL, "use clear_native_function to unregister natives");
1011   assert(!is_method_handle_intrinsic() || function == SharedRuntime::native_method_throw_unsatisfied_link_error_entry(), "");
1012   address* native_function = native_function_addr();
1013 
1014   // We can see racers trying to place the same native function into place. Once
1015   // is plenty.
1016   address current = *native_function;
1017   if (current == function) return;
1018   if (post_event_flag && JvmtiExport::should_post_native_method_bind() &&
1019       function != NULL) {
1020     // native_method_throw_unsatisfied_link_error_entry() should only
1021     // be passed when post_event_flag is false.
1022     assert(function !=
1023       SharedRuntime::native_method_throw_unsatisfied_link_error_entry(),

1152 void Method::set_not_osr_compilable(const char* reason, int comp_level, bool report) {
1153   print_made_not_compilable(comp_level, /*is_osr*/ true, report, reason);
1154   if (comp_level == CompLevel_all) {
1155     set_not_c1_osr_compilable();
1156     set_not_c2_osr_compilable();
1157   } else {
1158     if (is_c1_compile(comp_level))
1159       set_not_c1_osr_compilable();
1160     if (is_c2_compile(comp_level))
1161       set_not_c2_osr_compilable();
1162   }
1163   assert(!CompilationPolicy::can_be_osr_compiled(methodHandle(Thread::current(), this), comp_level), "sanity check");
1164 }
1165 
1166 // Revert to using the interpreter and clear out the nmethod
1167 void Method::clear_code() {
1168   // this may be NULL if c2i adapters have not been made yet
1169   // Only should happen at allocate time.
1170   if (adapter() == NULL) {
1171     _from_compiled_entry    = NULL;
1172     _from_compiled_inline_entry = NULL;
1173     _from_compiled_inline_ro_entry = NULL;
1174   } else {
1175     _from_compiled_entry    = adapter()->get_c2i_entry();
1176     _from_compiled_inline_entry = adapter()->get_c2i_inline_entry();
1177     _from_compiled_inline_ro_entry = adapter()->get_c2i_inline_ro_entry();
1178   }
1179   OrderAccess::storestore();
1180   _from_interpreted_entry = _i2i_entry;
1181   OrderAccess::storestore();
1182   _code = NULL;
1183 }
1184 
1185 void Method::unlink_code(CompiledMethod *compare) {
1186   MutexLocker ml(CompiledMethod_lock->owned_by_self() ? NULL : CompiledMethod_lock, Mutex::_no_safepoint_check_flag);
1187   // We need to check if either the _code or _from_compiled_code_entry_point
1188   // refer to this nmethod because there is a race in setting these two fields
1189   // in Method* as seen in bugid 4947125.
1190   // If the vep() points to the zombie nmethod, the memory for the nmethod
1191   // could be flushed and the compiler and vtable stubs could still call
1192   // through it.
1193   if (code() == compare ||
1194       from_compiled_entry() == compare->verified_entry_point()) {
1195     clear_code();
1196   }
1197 }
1198 
1199 void Method::unlink_code() {
1200   MutexLocker ml(CompiledMethod_lock->owned_by_self() ? NULL : CompiledMethod_lock, Mutex::_no_safepoint_check_flag);
1201   clear_code();
1202 }
1203 
1204 #if INCLUDE_CDS
1205 // Called by class data sharing to remove any entry points (which are not shared)
1206 void Method::unlink_method() {
1207   Arguments::assert_is_dumping_archive();
1208   _code = NULL;
1209   _adapter = NULL;
1210   _i2i_entry = NULL;
1211   _from_compiled_entry = NULL;
1212   _from_compiled_inline_entry = NULL;
1213   _from_compiled_inline_ro_entry = NULL;
1214   _from_interpreted_entry = NULL;
1215 
1216   if (is_native()) {
1217     *native_function_addr() = NULL;
1218     set_signature_handler(NULL);
1219   }
1220   NOT_PRODUCT(set_compiled_invocation_count(0);)
1221 
1222   set_method_data(NULL);
1223   clear_method_counters();
1224 }
1225 #endif
1226 
1227 // Called when the method_holder is getting linked. Setup entrypoints so the method
1228 // is ready to be called from interpreter, compiler, and vtables.
1229 void Method::link_method(const methodHandle& h_method, TRAPS) {
1230   // If the code cache is full, we may reenter this function for the
1231   // leftover methods that weren't linked.
1232   if (_i2i_entry != NULL) {
1233     return;

1264 }
1265 
1266 address Method::make_adapters(const methodHandle& mh, TRAPS) {
1267   // Adapters for compiled code are made eagerly here.  They are fairly
1268   // small (generally < 100 bytes) and quick to make (and cached and shared)
1269   // so making them eagerly shouldn't be too expensive.
1270   AdapterHandlerEntry* adapter = AdapterHandlerLibrary::get_adapter(mh);
1271   if (adapter == NULL ) {
1272     if (!is_init_completed()) {
1273       // Don't throw exceptions during VM initialization because java.lang.* classes
1274       // might not have been initialized, causing problems when constructing the
1275       // Java exception object.
1276       vm_exit_during_initialization("Out of space in CodeCache for adapters");
1277     } else {
1278       THROW_MSG_NULL(vmSymbols::java_lang_VirtualMachineError(), "Out of space in CodeCache for adapters");
1279     }
1280   }
1281 
1282   mh->set_adapter_entry(adapter);
1283   mh->_from_compiled_entry = adapter->get_c2i_entry();
1284   mh->_from_compiled_inline_entry = adapter->get_c2i_inline_entry();
1285   mh->_from_compiled_inline_ro_entry = adapter->get_c2i_inline_ro_entry();
1286   return adapter->get_c2i_entry();
1287 }
1288 
1289 void Method::restore_unshareable_info(TRAPS) {
1290   assert(is_method() && is_valid_method(this), "ensure C++ vtable is restored");
1291 }
1292 
1293 address Method::from_compiled_entry_no_trampoline(bool caller_is_c1) const {
1294   CompiledMethod *code = Atomic::load_acquire(&_code);
1295   if (caller_is_c1) {
1296     // C1 - inline type arguments are passed as objects
1297     if (code) {
1298       return code->verified_inline_entry_point();
1299     } else {
1300       return adapter()->get_c2i_inline_entry();
1301     }
1302   } else {
1303     // C2 - inline type arguments may be passed as fields
1304     if (code) {
1305       return code->verified_entry_point();
1306     } else {
1307       return adapter()->get_c2i_entry();
1308     }
1309   }
1310 }
1311 
1312 // The verified_code_entry() must be called when a invoke is resolved
1313 // on this method.
1314 
1315 // It returns the compiled code entry point, after asserting not null.
1316 // This function is called after potential safepoints so that nmethod
1317 // or adapter that it points to is still live and valid.
1318 // This function must not hit a safepoint!
1319 address Method::verified_code_entry() {
1320   debug_only(NoSafepointVerifier nsv;)
1321   assert(_from_compiled_entry != NULL, "must be set");
1322   return _from_compiled_entry;
1323 }
1324 
1325 address Method::verified_inline_code_entry() {
1326   debug_only(NoSafepointVerifier nsv;)
1327   assert(_from_compiled_inline_entry != NULL, "must be set");
1328   return _from_compiled_inline_entry;
1329 }
1330 
1331 address Method::verified_inline_ro_code_entry() {
1332   debug_only(NoSafepointVerifier nsv;)
1333   assert(_from_compiled_inline_ro_entry != NULL, "must be set");
1334   return _from_compiled_inline_ro_entry;
1335 }
1336 
1337 // Check that if an nmethod ref exists, it has a backlink to this or no backlink at all
1338 // (could be racing a deopt).
1339 // Not inline to avoid circular ref.
1340 bool Method::check_code() const {
1341   // cached in a register or local.  There's a race on the value of the field.
1342   CompiledMethod *code = Atomic::load_acquire(&_code);
1343   return code == NULL || (code->method() == NULL) || (code->method() == (Method*)this && !code->is_osr_method());
1344 }
1345 
1346 // Install compiled code.  Instantly it can execute.
1347 void Method::set_code(const methodHandle& mh, CompiledMethod *code) {
1348   assert_lock_strong(CompiledMethod_lock);
1349   assert( code, "use clear_code to remove code" );
1350   assert( mh->check_code(), "" );
1351 
1352   guarantee(mh->adapter() != NULL, "Adapter blob must already exist!");
1353 
1354   // These writes must happen in this order, because the interpreter will
1355   // directly jump to from_interpreted_entry which jumps to an i2c adapter
1356   // which jumps to _from_compiled_entry.
1357   mh->_code = code;             // Assign before allowing compiled code to exec
1358 
1359   int comp_level = code->comp_level();
1360   // In theory there could be a race here. In practice it is unlikely
1361   // and not worth worrying about.
1362   if (comp_level > mh->highest_comp_level()) {
1363     mh->set_highest_comp_level(comp_level);
1364   }
1365 
1366   OrderAccess::storestore();
1367   mh->_from_compiled_entry = code->verified_entry_point();
1368   mh->_from_compiled_inline_entry = code->verified_inline_entry_point();
1369   mh->_from_compiled_inline_ro_entry = code->verified_inline_ro_entry_point();
1370   OrderAccess::storestore();
1371   // Instantly compiled code can execute.
1372   if (!mh->is_method_handle_intrinsic())
1373     mh->_from_interpreted_entry = mh->get_i2c_entry();
1374 }
1375 
1376 
1377 bool Method::is_overridden_in(Klass* k) const {
1378   InstanceKlass* ik = InstanceKlass::cast(k);
1379 
1380   if (ik->is_interface()) return false;
1381 
1382   // If method is an interface, we skip it - except if it
1383   // is a miranda method
1384   if (method_holder()->is_interface()) {
1385     // Check that method is not a miranda method
1386     if (ik->lookup_method(name(), signature()) == NULL) {
1387       // No implementation exist - so miranda method
1388       return false;
1389     }

2384 void Method::print_on(outputStream* st) const {
2385   ResourceMark rm;
2386   assert(is_method(), "must be method");
2387   st->print_cr("%s", internal_name());
2388   st->print_cr(" - this oop:          " INTPTR_FORMAT, p2i(this));
2389   st->print   (" - method holder:     "); method_holder()->print_value_on(st); st->cr();
2390   st->print   (" - constants:         " INTPTR_FORMAT " ", p2i(constants()));
2391   constants()->print_value_on(st); st->cr();
2392   st->print   (" - access:            0x%x  ", access_flags().as_int()); access_flags().print_on(st); st->cr();
2393   st->print   (" - name:              ");    name()->print_value_on(st); st->cr();
2394   st->print   (" - signature:         ");    signature()->print_value_on(st); st->cr();
2395   st->print_cr(" - max stack:         %d",   max_stack());
2396   st->print_cr(" - max locals:        %d",   max_locals());
2397   st->print_cr(" - size of params:    %d",   size_of_parameters());
2398   st->print_cr(" - method size:       %d",   method_size());
2399   if (intrinsic_id() != vmIntrinsics::_none)
2400     st->print_cr(" - intrinsic id:      %d %s", vmIntrinsics::as_int(intrinsic_id()), vmIntrinsics::name_at(intrinsic_id()));
2401   if (highest_comp_level() != CompLevel_none)
2402     st->print_cr(" - highest level:     %d", highest_comp_level());
2403   st->print_cr(" - vtable index:      %d",   _vtable_index);
2404 #ifdef ASSERT
2405   if (valid_itable_index())
2406     st->print_cr(" - itable index:      %d",   itable_index());
2407 #endif
2408   st->print_cr(" - i2i entry:         " INTPTR_FORMAT, p2i(interpreter_entry()));
2409   st->print(   " - adapters:          ");
2410   AdapterHandlerEntry* a = ((Method*)this)->adapter();
2411   if (a == NULL)
2412     st->print_cr(INTPTR_FORMAT, p2i(a));
2413   else
2414     a->print_adapter_on(st);
2415   st->print_cr(" - compiled entry           " INTPTR_FORMAT, p2i(from_compiled_entry()));
2416   st->print_cr(" - compiled inline entry    " INTPTR_FORMAT, p2i(from_compiled_inline_entry()));
2417   st->print_cr(" - compiled inline ro entry " INTPTR_FORMAT, p2i(from_compiled_inline_ro_entry()));
2418   st->print_cr(" - code size:         %d",   code_size());
2419   if (code_size() != 0) {
2420     st->print_cr(" - code start:        " INTPTR_FORMAT, p2i(code_base()));
2421     st->print_cr(" - code end (excl):   " INTPTR_FORMAT, p2i(code_base() + code_size()));
2422   }
2423   if (method_data() != NULL) {
2424     st->print_cr(" - method data:       " INTPTR_FORMAT, p2i(method_data()));
2425   }
2426   st->print_cr(" - checked ex length: %d",   checked_exceptions_length());
2427   if (checked_exceptions_length() > 0) {
2428     CheckedExceptionElement* table = checked_exceptions_start();
2429     st->print_cr(" - checked ex start:  " INTPTR_FORMAT, p2i(table));
2430     if (Verbose) {
2431       for (int i = 0; i < checked_exceptions_length(); i++) {
2432         st->print_cr("   - throws %s", constants()->printable_name_at(table[i].class_cp_index));
2433       }
2434     }
2435   }
2436   if (has_linenumber_table()) {
2437     u_char* table = compressed_linenumber_table();

2467     st->print_cr(" - signature handler: " INTPTR_FORMAT, p2i(signature_handler()));
2468   }
2469 }
2470 
2471 void Method::print_linkage_flags(outputStream* st) {
2472   access_flags().print_on(st);
2473   if (is_default_method()) {
2474     st->print("default ");
2475   }
2476   if (is_overpass()) {
2477     st->print("overpass ");
2478   }
2479 }
2480 #endif //PRODUCT
2481 
2482 void Method::print_value_on(outputStream* st) const {
2483   assert(is_method(), "must be method");
2484   st->print("%s", internal_name());
2485   print_address_on(st);
2486   st->print(" ");
2487   if (WizardMode) access_flags().print_on(st);
2488   name()->print_value_on(st);
2489   st->print(" ");
2490   signature()->print_value_on(st);
2491   st->print(" in ");
2492   method_holder()->print_value_on(st);
2493   if (WizardMode) st->print("#%d", _vtable_index);
2494   if (WizardMode) st->print("[%d,%d]", size_of_parameters(), max_locals());
2495   if (WizardMode && code() != NULL) st->print(" ((nmethod*)%p)", code());
2496 }
2497 
2498 // LogTouchedMethods and PrintTouchedMethods
2499 
2500 // TouchedMethodRecord -- we can't use a HashtableEntry<Method*> because
2501 // the Method may be garbage collected. Let's roll our own hash table.
2502 class TouchedMethodRecord : CHeapObj<mtTracing> {
2503 public:
2504   // It's OK to store Symbols here because they will NOT be GC'ed if
2505   // LogTouchedMethods is enabled.
2506   TouchedMethodRecord* _next;
2507   Symbol* _class_name;
< prev index next >