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
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
122 NOT_PRODUCT(set_compiled_invocation_count(0);)
123 // Name is very useful for debugging.
124 NOT_PRODUCT(_name = name;)
125 }
126
127 // Release Method*. The nmethod will be gone when we get here because
128 // we've walked the code cache.
129 void Method::deallocate_contents(ClassLoaderData* loader_data) {
130 MetadataFactory::free_metadata(loader_data, constMethod());
131 set_constMethod(NULL);
132 MetadataFactory::free_metadata(loader_data, method_data());
133 set_method_data(NULL);
134 MetadataFactory::free_metadata(loader_data, method_counters());
135 clear_method_counters();
136 // The nmethod will be gone when we get here.
137 if (code() != NULL) _code = NULL;
138 }
139
140 void Method::release_C_heap_structures() {
141 if (method_data()) {
142 #if INCLUDE_JVMCI
143 FailedSpeculation::free_failed_speculations(method_data()->get_failed_speculations_address());
144 #endif
145 // Destroy MethodData
146 method_data()->~MethodData();
147 }
148 }
149
150 address Method::get_i2c_entry() {
151 assert(adapter() != NULL, "must have");
152 return adapter()->get_i2c_entry();
153 }
154
155 address Method::get_c2i_entry() {
156 assert(adapter() != NULL, "must have");
157 return adapter()->get_c2i_entry();
158 }
159
160 address Method::get_c2i_unverified_entry() {
161 assert(adapter() != NULL, "must have");
162 return adapter()->get_c2i_unverified_entry();
163 }
164
165 address Method::get_c2i_no_clinit_check_entry() {
166 assert(VM_Version::supports_fast_class_init_checks(), "");
167 assert(adapter() != NULL, "must have");
168 return adapter()->get_c2i_no_clinit_check_entry();
169 }
170
171 char* Method::name_and_sig_as_C_string() const {
172 return name_and_sig_as_C_string(constants()->pool_holder(), name(), signature());
173 }
174
175 char* Method::name_and_sig_as_C_string(char* buf, int size) const {
176 return name_and_sig_as_C_string(constants()->pool_holder(), name(), signature(), buf, size);
177 }
178
179 char* Method::name_and_sig_as_C_string(Klass* klass, Symbol* method_name, Symbol* signature) {
180 const char* klass_name = klass->external_name();
181 int klass_name_len = (int)strlen(klass_name);
182 int method_name_len = method_name->utf8_length();
183 int len = klass_name_len + 1 + method_name_len + signature->utf8_length();
184 char* dest = NEW_RESOURCE_ARRAY(char, len + 1);
649 return Atomic::replace_if_null(&_method_counters, counters);
650 }
651
652 int Method::extra_stack_words() {
653 // not an inline function, to avoid a header dependency on Interpreter
654 return extra_stack_entries() * Interpreter::stackElementSize;
655 }
656
657 // Derive size of parameters, return type, and fingerprint,
658 // all in one pass, which is run at load time.
659 // We need the first two, and might as well grab the third.
660 void Method::compute_from_signature(Symbol* sig) {
661 // At this point, since we are scanning the signature,
662 // we might as well compute the whole fingerprint.
663 Fingerprinter fp(sig, is_static());
664 set_size_of_parameters(fp.size_of_parameters());
665 constMethod()->set_result_type(fp.return_type());
666 constMethod()->set_fingerprint(fp.fingerprint());
667 }
668
669 bool Method::is_vanilla_constructor() const {
670 // Returns true if this method is a vanilla constructor, i.e. an "<init>" "()V" method
671 // which only calls the superclass vanilla constructor and possibly does stores of
672 // zero constants to local fields:
673 //
674 // aload_0
675 // invokespecial
676 // indexbyte1
677 // indexbyte2
678 //
679 // followed by an (optional) sequence of:
680 //
681 // aload_0
682 // aconst_null / iconst_0 / fconst_0 / dconst_0
683 // putfield
684 // indexbyte1
685 // indexbyte2
686 //
687 // followed by:
688 //
689 // return
690
691 assert(name() == vmSymbols::object_initializer_name(), "Should only be called for default constructors");
692 assert(signature() == vmSymbols::void_method_signature(), "Should only be called for default constructors");
693 int size = code_size();
694 // Check if size match
695 if (size == 0 || size % 5 != 0) return false;
696 address cb = code_base();
697 int last = size - 1;
698 if (cb[0] != Bytecodes::_aload_0 || cb[1] != Bytecodes::_invokespecial || cb[last] != Bytecodes::_return) {
699 // Does not call superclass default constructor
700 return false;
701 }
702 // Check optional sequence
703 for (int i = 4; i < last; i += 5) {
704 if (cb[i] != Bytecodes::_aload_0) return false;
705 if (!Bytecodes::is_zero_const(Bytecodes::cast(cb[i+1]))) return false;
706 if (cb[i+2] != Bytecodes::_putfield) return false;
707 }
708 return true;
709 }
710
711
712 bool Method::compute_has_loops_flag() {
713 BytecodeStream bcs(methodHandle(Thread::current(), this));
714 Bytecodes::Code bc;
715
716 while ((bc = bcs.next()) >= 0) {
717 switch (bc) {
718 case Bytecodes::_ifeq:
836
837 bool Method::is_accessor() const {
838 return is_getter() || is_setter();
839 }
840
841 bool Method::is_getter() const {
842 if (code_size() != 5) return false;
843 if (size_of_parameters() != 1) return false;
844 if (java_code_at(0) != Bytecodes::_aload_0) return false;
845 if (java_code_at(1) != Bytecodes::_getfield) return false;
846 switch (java_code_at(4)) {
847 case Bytecodes::_ireturn:
848 case Bytecodes::_lreturn:
849 case Bytecodes::_freturn:
850 case Bytecodes::_dreturn:
851 case Bytecodes::_areturn:
852 break;
853 default:
854 return false;
855 }
856 return true;
857 }
858
859 bool Method::is_setter() const {
860 if (code_size() != 6) return false;
861 if (java_code_at(0) != Bytecodes::_aload_0) return false;
862 switch (java_code_at(1)) {
863 case Bytecodes::_iload_1:
864 case Bytecodes::_aload_1:
865 case Bytecodes::_fload_1:
866 if (size_of_parameters() != 2) return false;
867 break;
868 case Bytecodes::_dload_1:
869 case Bytecodes::_lload_1:
870 if (size_of_parameters() != 3) return false;
871 break;
872 default:
873 return false;
874 }
875 if (java_code_at(2) != Bytecodes::_putfield) return false;
876 if (java_code_at(5) != Bytecodes::_return) return false;
877 return true;
878 }
879
880 bool Method::is_constant_getter() const {
881 int last_index = code_size() - 1;
882 // Check if the first 1-3 bytecodes are a constant push
883 // and the last bytecode is a return.
884 return (2 <= code_size() && code_size() <= 4 &&
885 Bytecodes::is_const(java_code_at(0)) &&
886 Bytecodes::length_for(java_code_at(0)) == last_index &&
887 Bytecodes::is_return(java_code_at(last_index)));
888 }
889
890 bool Method::is_initializer() const {
891 return is_object_initializer() || is_static_initializer();
892 }
893
894 bool Method::has_valid_initializer_flags() const {
895 return (is_static() ||
896 method_holder()->major_version() < 51);
897 }
898
899 bool Method::is_static_initializer() const {
900 // For classfiles version 51 or greater, ensure that the clinit method is
901 // static. Non-static methods with the name "<clinit>" are not static
902 // initializers. (older classfiles exempted for backward compatibility)
903 return name() == vmSymbols::class_initializer_name() &&
904 has_valid_initializer_flags();
905 }
906
907 bool Method::is_object_initializer() const {
908 return name() == vmSymbols::object_initializer_name();
909 }
910
911 bool Method::needs_clinit_barrier() const {
912 return is_static() && !method_holder()->is_initialized();
913 }
914
915 objArrayHandle Method::resolved_checked_exceptions_impl(Method* method, TRAPS) {
916 int length = method->checked_exceptions_length();
917 if (length == 0) { // common case
918 return objArrayHandle(THREAD, Universe::the_empty_class_array());
919 } else {
920 methodHandle h_this(THREAD, method);
921 objArrayOop m_oop = oopFactory::new_objArray(vmClasses::Class_klass(), length, CHECK_(objArrayHandle()));
922 objArrayHandle mirrors (THREAD, m_oop);
923 for (int i = 0; i < length; i++) {
924 CheckedExceptionElement* table = h_this->checked_exceptions_start(); // recompute on each iteration, not gc safe
925 Klass* k = h_this->constants()->klass_at(table[i].class_cp_index, CHECK_(objArrayHandle()));
926 if (log_is_enabled(Warning, exceptions) &&
927 !k->is_subclass_of(vmClasses::Throwable_klass())) {
928 ResourceMark rm(THREAD);
946 // Not necessarily sorted and not necessarily one-to-one.
947 CompressedLineNumberReadStream stream(compressed_linenumber_table());
948 while (stream.read_pair()) {
949 if (stream.bci() == bci) {
950 // perfect match
951 return stream.line();
952 } else {
953 // update best_bci/line
954 if (stream.bci() < bci && stream.bci() >= best_bci) {
955 best_bci = stream.bci();
956 best_line = stream.line();
957 }
958 }
959 }
960 }
961 return best_line;
962 }
963
964
965 bool Method::is_klass_loaded_by_klass_index(int klass_index) const {
966 if( constants()->tag_at(klass_index).is_unresolved_klass() ) {
967 Thread *thread = Thread::current();
968 Symbol* klass_name = constants()->klass_name_at(klass_index);
969 Handle loader(thread, method_holder()->class_loader());
970 Handle prot (thread, method_holder()->protection_domain());
971 return SystemDictionary::find_instance_klass(klass_name, loader, prot) != NULL;
972 } else {
973 return true;
974 }
975 }
976
977
978 bool Method::is_klass_loaded(int refinfo_index, bool must_be_resolved) const {
979 int klass_index = constants()->klass_ref_index_at(refinfo_index);
980 if (must_be_resolved) {
981 // Make sure klass is resolved in constantpool.
982 if (constants()->tag_at(klass_index).is_unresolved_klass()) return false;
983 }
984 return is_klass_loaded_by_klass_index(klass_index);
985 }
986
987
988 void Method::set_native_function(address function, bool post_event_flag) {
989 assert(function != NULL, "use clear_native_function to unregister natives");
990 assert(!is_method_handle_intrinsic() || function == SharedRuntime::native_method_throw_unsatisfied_link_error_entry(), "");
991 address* native_function = native_function_addr();
992
993 // We can see racers trying to place the same native function into place. Once
994 // is plenty.
995 address current = *native_function;
996 if (current == function) return;
997 if (post_event_flag && JvmtiExport::should_post_native_method_bind() &&
998 function != NULL) {
999 // native_method_throw_unsatisfied_link_error_entry() should only
1000 // be passed when post_event_flag is false.
1001 assert(function !=
1002 SharedRuntime::native_method_throw_unsatisfied_link_error_entry(),
1131 void Method::set_not_osr_compilable(const char* reason, int comp_level, bool report) {
1132 print_made_not_compilable(comp_level, /*is_osr*/ true, report, reason);
1133 if (comp_level == CompLevel_all) {
1134 set_not_c1_osr_compilable();
1135 set_not_c2_osr_compilable();
1136 } else {
1137 if (is_c1_compile(comp_level))
1138 set_not_c1_osr_compilable();
1139 if (is_c2_compile(comp_level))
1140 set_not_c2_osr_compilable();
1141 }
1142 assert(!CompilationPolicy::can_be_osr_compiled(methodHandle(Thread::current(), this), comp_level), "sanity check");
1143 }
1144
1145 // Revert to using the interpreter and clear out the nmethod
1146 void Method::clear_code() {
1147 // this may be NULL if c2i adapters have not been made yet
1148 // Only should happen at allocate time.
1149 if (adapter() == NULL) {
1150 _from_compiled_entry = NULL;
1151 } else {
1152 _from_compiled_entry = adapter()->get_c2i_entry();
1153 }
1154 OrderAccess::storestore();
1155 _from_interpreted_entry = _i2i_entry;
1156 OrderAccess::storestore();
1157 _code = NULL;
1158 }
1159
1160 void Method::unlink_code(CompiledMethod *compare) {
1161 MutexLocker ml(CompiledMethod_lock->owned_by_self() ? NULL : CompiledMethod_lock, Mutex::_no_safepoint_check_flag);
1162 // We need to check if either the _code or _from_compiled_code_entry_point
1163 // refer to this nmethod because there is a race in setting these two fields
1164 // in Method* as seen in bugid 4947125.
1165 // If the vep() points to the zombie nmethod, the memory for the nmethod
1166 // could be flushed and the compiler and vtable stubs could still call
1167 // through it.
1168 if (code() == compare ||
1169 from_compiled_entry() == compare->verified_entry_point()) {
1170 clear_code();
1171 }
1172 }
1173
1174 void Method::unlink_code() {
1175 MutexLocker ml(CompiledMethod_lock->owned_by_self() ? NULL : CompiledMethod_lock, Mutex::_no_safepoint_check_flag);
1176 clear_code();
1177 }
1178
1179 #if INCLUDE_CDS
1180 // Called by class data sharing to remove any entry points (which are not shared)
1181 void Method::unlink_method() {
1182 Arguments::assert_is_dumping_archive();
1183 _code = NULL;
1184 _adapter = NULL;
1185 _i2i_entry = NULL;
1186 _from_compiled_entry = NULL;
1187 _from_interpreted_entry = NULL;
1188
1189 if (is_native()) {
1190 *native_function_addr() = NULL;
1191 set_signature_handler(NULL);
1192 }
1193 NOT_PRODUCT(set_compiled_invocation_count(0);)
1194
1195 set_method_data(NULL);
1196 clear_method_counters();
1197 }
1198 #endif
1199
1200 // Called when the method_holder is getting linked. Setup entrypoints so the method
1201 // is ready to be called from interpreter, compiler, and vtables.
1202 void Method::link_method(const methodHandle& h_method, TRAPS) {
1203 // If the code cache is full, we may reenter this function for the
1204 // leftover methods that weren't linked.
1205 if (adapter() != NULL) {
1206 return;
1237 }
1238
1239 address Method::make_adapters(const methodHandle& mh, TRAPS) {
1240 // Adapters for compiled code are made eagerly here. They are fairly
1241 // small (generally < 100 bytes) and quick to make (and cached and shared)
1242 // so making them eagerly shouldn't be too expensive.
1243 AdapterHandlerEntry* adapter = AdapterHandlerLibrary::get_adapter(mh);
1244 if (adapter == NULL ) {
1245 if (!is_init_completed()) {
1246 // Don't throw exceptions during VM initialization because java.lang.* classes
1247 // might not have been initialized, causing problems when constructing the
1248 // Java exception object.
1249 vm_exit_during_initialization("Out of space in CodeCache for adapters");
1250 } else {
1251 THROW_MSG_NULL(vmSymbols::java_lang_VirtualMachineError(), "Out of space in CodeCache for adapters");
1252 }
1253 }
1254
1255 mh->set_adapter_entry(adapter);
1256 mh->_from_compiled_entry = adapter->get_c2i_entry();
1257 return adapter->get_c2i_entry();
1258 }
1259
1260 void Method::restore_unshareable_info(TRAPS) {
1261 assert(is_method() && is_valid_method(this), "ensure C++ vtable is restored");
1262 }
1263
1264 address Method::from_compiled_entry_no_trampoline() const {
1265 CompiledMethod *code = Atomic::load_acquire(&_code);
1266 if (code) {
1267 return code->verified_entry_point();
1268 } else {
1269 return adapter()->get_c2i_entry();
1270 }
1271 }
1272
1273 // The verified_code_entry() must be called when a invoke is resolved
1274 // on this method.
1275
1276 // It returns the compiled code entry point, after asserting not null.
1277 // This function is called after potential safepoints so that nmethod
1278 // or adapter that it points to is still live and valid.
1279 // This function must not hit a safepoint!
1280 address Method::verified_code_entry() {
1281 debug_only(NoSafepointVerifier nsv;)
1282 assert(_from_compiled_entry != NULL, "must be set");
1283 return _from_compiled_entry;
1284 }
1285
1286 // Check that if an nmethod ref exists, it has a backlink to this or no backlink at all
1287 // (could be racing a deopt).
1288 // Not inline to avoid circular ref.
1289 bool Method::check_code() const {
1290 // cached in a register or local. There's a race on the value of the field.
1291 CompiledMethod *code = Atomic::load_acquire(&_code);
1292 return code == NULL || (code->method() == NULL) || (code->method() == (Method*)this && !code->is_osr_method());
1293 }
1294
1295 // Install compiled code. Instantly it can execute.
1296 void Method::set_code(const methodHandle& mh, CompiledMethod *code) {
1297 assert_lock_strong(CompiledMethod_lock);
1298 assert( code, "use clear_code to remove code" );
1299 assert( mh->check_code(), "" );
1300
1301 guarantee(mh->adapter() != NULL, "Adapter blob must already exist!");
1302
1303 // These writes must happen in this order, because the interpreter will
1304 // directly jump to from_interpreted_entry which jumps to an i2c adapter
1305 // which jumps to _from_compiled_entry.
1306 mh->_code = code; // Assign before allowing compiled code to exec
1307
1308 int comp_level = code->comp_level();
1309 // In theory there could be a race here. In practice it is unlikely
1310 // and not worth worrying about.
1311 if (comp_level > mh->highest_comp_level()) {
1312 mh->set_highest_comp_level(comp_level);
1313 }
1314
1315 OrderAccess::storestore();
1316 mh->_from_compiled_entry = code->verified_entry_point();
1317 OrderAccess::storestore();
1318 // Instantly compiled code can execute.
1319 if (!mh->is_method_handle_intrinsic())
1320 mh->_from_interpreted_entry = mh->get_i2c_entry();
1321 }
1322
1323
1324 bool Method::is_overridden_in(Klass* k) const {
1325 InstanceKlass* ik = InstanceKlass::cast(k);
1326
1327 if (ik->is_interface()) return false;
1328
1329 // If method is an interface, we skip it - except if it
1330 // is a miranda method
1331 if (method_holder()->is_interface()) {
1332 // Check that method is not a miranda method
1333 if (ik->lookup_method(name(), signature()) == NULL) {
1334 // No implementation exist - so miranda method
1335 return false;
1336 }
2288 // This assumes that the vtbl pointer is the first word of a C++ object.
2289 return dereference_vptr(&m) == dereference_vptr(ptr);
2290 }
2291
2292 // Check that this pointer is valid by checking that the vtbl pointer matches
2293 bool Method::is_valid_method(const Method* m) {
2294 if (m == NULL) {
2295 return false;
2296 } else if ((intptr_t(m) & (wordSize-1)) != 0) {
2297 // Quick sanity check on pointer.
2298 return false;
2299 } else if (m->is_shared()) {
2300 return CppVtables::is_valid_shared_method(m);
2301 } else if (Metaspace::contains_non_shared(m)) {
2302 return has_method_vptr((const void*)m);
2303 } else {
2304 return false;
2305 }
2306 }
2307
2308 #ifndef PRODUCT
2309 void Method::print_jmethod_ids_count(const ClassLoaderData* loader_data, outputStream* out) {
2310 out->print("%d", loader_data->jmethod_ids()->count_methods());
2311 }
2312 #endif // PRODUCT
2313
2314
2315 // Printing
2316
2317 #ifndef PRODUCT
2318
2319 void Method::print_on(outputStream* st) const {
2320 ResourceMark rm;
2321 assert(is_method(), "must be method");
2322 st->print_cr("%s", internal_name());
2323 st->print_cr(" - this oop: " INTPTR_FORMAT, p2i(this));
2324 st->print (" - method holder: "); method_holder()->print_value_on(st); st->cr();
2325 st->print (" - constants: " INTPTR_FORMAT " ", p2i(constants()));
2326 constants()->print_value_on(st); st->cr();
2327 st->print (" - access: 0x%x ", access_flags().as_int()); access_flags().print_on(st); st->cr();
2328 st->print (" - name: "); name()->print_value_on(st); st->cr();
2329 st->print (" - signature: "); signature()->print_value_on(st); st->cr();
2330 st->print_cr(" - max stack: %d", max_stack());
2331 st->print_cr(" - max locals: %d", max_locals());
2332 st->print_cr(" - size of params: %d", size_of_parameters());
2333 st->print_cr(" - method size: %d", method_size());
2334 if (intrinsic_id() != vmIntrinsics::_none)
2335 st->print_cr(" - intrinsic id: %d %s", vmIntrinsics::as_int(intrinsic_id()), vmIntrinsics::name_at(intrinsic_id()));
2336 if (highest_comp_level() != CompLevel_none)
2337 st->print_cr(" - highest level: %d", highest_comp_level());
2338 st->print_cr(" - vtable index: %d", _vtable_index);
2339 st->print_cr(" - i2i entry: " INTPTR_FORMAT, p2i(interpreter_entry()));
2340 st->print( " - adapters: ");
2341 AdapterHandlerEntry* a = ((Method*)this)->adapter();
2342 if (a == NULL)
2343 st->print_cr(INTPTR_FORMAT, p2i(a));
2344 else
2345 a->print_adapter_on(st);
2346 st->print_cr(" - compiled entry " INTPTR_FORMAT, p2i(from_compiled_entry()));
2347 st->print_cr(" - code size: %d", code_size());
2348 if (code_size() != 0) {
2349 st->print_cr(" - code start: " INTPTR_FORMAT, p2i(code_base()));
2350 st->print_cr(" - code end (excl): " INTPTR_FORMAT, p2i(code_base() + code_size()));
2351 }
2352 if (method_data() != NULL) {
2353 st->print_cr(" - method data: " INTPTR_FORMAT, p2i(method_data()));
2354 }
2355 st->print_cr(" - checked ex length: %d", checked_exceptions_length());
2356 if (checked_exceptions_length() > 0) {
2357 CheckedExceptionElement* table = checked_exceptions_start();
2358 st->print_cr(" - checked ex start: " INTPTR_FORMAT, p2i(table));
2359 if (Verbose) {
2360 for (int i = 0; i < checked_exceptions_length(); i++) {
2361 st->print_cr(" - throws %s", constants()->printable_name_at(table[i].class_cp_index));
2362 }
2363 }
2364 }
2365 if (has_linenumber_table()) {
2366 u_char* table = compressed_linenumber_table();
2396 st->print_cr(" - signature handler: " INTPTR_FORMAT, p2i(signature_handler()));
2397 }
2398 }
2399
2400 void Method::print_linkage_flags(outputStream* st) {
2401 access_flags().print_on(st);
2402 if (is_default_method()) {
2403 st->print("default ");
2404 }
2405 if (is_overpass()) {
2406 st->print("overpass ");
2407 }
2408 }
2409 #endif //PRODUCT
2410
2411 void Method::print_value_on(outputStream* st) const {
2412 assert(is_method(), "must be method");
2413 st->print("%s", internal_name());
2414 print_address_on(st);
2415 st->print(" ");
2416 name()->print_value_on(st);
2417 st->print(" ");
2418 signature()->print_value_on(st);
2419 st->print(" in ");
2420 method_holder()->print_value_on(st);
2421 if (WizardMode) st->print("#%d", _vtable_index);
2422 if (WizardMode) st->print("[%d,%d]", size_of_parameters(), max_locals());
2423 if (WizardMode && code() != NULL) st->print(" ((nmethod*)%p)", code());
2424 }
2425
2426 // LogTouchedMethods and PrintTouchedMethods
2427
2428 // TouchedMethodRecord -- we can't use a HashtableEntry<Method*> because
2429 // the Method may be garbage collected. Let's roll our own hash table.
2430 class TouchedMethodRecord : CHeapObj<mtTracing> {
2431 public:
2432 // It's OK to store Symbols here because they will NOT be GC'ed if
2433 // LogTouchedMethods is enabled.
2434 TouchedMethodRecord* _next;
2435 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
102 set_constMethod(xconst);
103 set_access_flags(access_flags);
104 set_intrinsic_id(vmIntrinsics::_none);
105 set_force_inline(false);
106 set_hidden(false);
107 set_dont_inline(false);
108 set_has_injected_profile(false);
109 set_method_data(NULL);
110 clear_method_counters();
111 set_vtable_index(Method::garbage_vtable_index);
112
113 // Fix and bury in Method*
114 set_interpreter_entry(NULL); // sets i2i entry and from_int
115 set_adapter_entry(NULL);
116 Method::clear_code(); // from_c/from_i get set to c2i/i2i
117
118 if (access_flags.is_native()) {
119 clear_native_function();
120 set_signature_handler(NULL);
121 }
122 NOT_PRODUCT(set_compiled_invocation_count(0);)
123 // Name is very useful for debugging.
124 NOT_PRODUCT(_name = name;)
125 }
126
127 // Release Method*. The nmethod will be gone when we get here because
128 // we've walked the code cache.
129 void Method::deallocate_contents(ClassLoaderData* loader_data) {
130 MetadataFactory::free_metadata(loader_data, constMethod());
131 set_constMethod(NULL);
132 MetadataFactory::free_metadata(loader_data, method_data());
133 set_method_data(NULL);
134 MetadataFactory::free_metadata(loader_data, method_counters());
135 clear_method_counters();
136 // The nmethod will be gone when we get here.
137 if (code() != NULL) _code = NULL;
138 }
139
140 void Method::release_C_heap_structures() {
141 if (method_data()) {
142 #if INCLUDE_JVMCI
143 FailedSpeculation::free_failed_speculations(method_data()->get_failed_speculations_address());
144 #endif
145 // Destroy MethodData
146 method_data()->~MethodData();
147 }
148 }
149
150 address Method::get_i2c_entry() {
151 assert(adapter() != NULL, "must have");
152 return adapter()->get_i2c_entry();
153 }
154
155 address Method::get_c2i_entry() {
156 assert(adapter() != NULL, "must have");
157 return adapter()->get_c2i_entry();
158 }
159
160 address Method::get_c2i_inline_entry() {
161 assert(adapter() != NULL, "must have");
162 return adapter()->get_c2i_inline_entry();
163 }
164
165 address Method::get_c2i_unverified_entry() {
166 assert(adapter() != NULL, "must have");
167 return adapter()->get_c2i_unverified_entry();
168 }
169
170 address Method::get_c2i_unverified_inline_entry() {
171 assert(adapter() != NULL, "must have");
172 return adapter()->get_c2i_unverified_inline_entry();
173 }
174
175 address Method::get_c2i_no_clinit_check_entry() {
176 assert(VM_Version::supports_fast_class_init_checks(), "");
177 assert(adapter() != NULL, "must have");
178 return adapter()->get_c2i_no_clinit_check_entry();
179 }
180
181 char* Method::name_and_sig_as_C_string() const {
182 return name_and_sig_as_C_string(constants()->pool_holder(), name(), signature());
183 }
184
185 char* Method::name_and_sig_as_C_string(char* buf, int size) const {
186 return name_and_sig_as_C_string(constants()->pool_holder(), name(), signature(), buf, size);
187 }
188
189 char* Method::name_and_sig_as_C_string(Klass* klass, Symbol* method_name, Symbol* signature) {
190 const char* klass_name = klass->external_name();
191 int klass_name_len = (int)strlen(klass_name);
192 int method_name_len = method_name->utf8_length();
193 int len = klass_name_len + 1 + method_name_len + signature->utf8_length();
194 char* dest = NEW_RESOURCE_ARRAY(char, len + 1);
659 return Atomic::replace_if_null(&_method_counters, counters);
660 }
661
662 int Method::extra_stack_words() {
663 // not an inline function, to avoid a header dependency on Interpreter
664 return extra_stack_entries() * Interpreter::stackElementSize;
665 }
666
667 // Derive size of parameters, return type, and fingerprint,
668 // all in one pass, which is run at load time.
669 // We need the first two, and might as well grab the third.
670 void Method::compute_from_signature(Symbol* sig) {
671 // At this point, since we are scanning the signature,
672 // we might as well compute the whole fingerprint.
673 Fingerprinter fp(sig, is_static());
674 set_size_of_parameters(fp.size_of_parameters());
675 constMethod()->set_result_type(fp.return_type());
676 constMethod()->set_fingerprint(fp.fingerprint());
677 }
678
679 // InlineKlass the method is declared to return. This must not
680 // safepoint as it is called with references live on the stack at
681 // locations the GC is unaware of.
682 InlineKlass* Method::returns_inline_type(Thread* thread) const {
683 assert(InlineTypeReturnedAsFields, "Inline types should never be returned as fields");
684 NoSafepointVerifier nsv;
685 SignatureStream ss(signature());
686 while (!ss.at_return_type()) {
687 ss.next();
688 }
689 return ss.as_inline_klass(method_holder());
690 }
691
692 bool Method::is_vanilla_constructor() const {
693 // Returns true if this method is a vanilla constructor, i.e. an "<init>" "()V" method
694 // which only calls the superclass vanilla constructor and possibly does stores of
695 // zero constants to local fields:
696 //
697 // aload_0, _fast_aload_0, or _nofast_aload_0
698 // invokespecial
699 // indexbyte1
700 // indexbyte2
701 //
702 // followed by an (optional) sequence of:
703 //
704 // aload_0
705 // aconst_null / iconst_0 / fconst_0 / dconst_0
706 // putfield
707 // indexbyte1
708 // indexbyte2
709 //
710 // followed by:
711 //
712 // return
713
714 assert(name() == vmSymbols::object_initializer_name(), "Should only be called for default constructors");
715 assert(signature() == vmSymbols::void_method_signature(), "Should only be called for default constructors");
716 int size = code_size();
717 // Check if size match
718 if (size == 0 || size % 5 != 0) return false;
719 address cb = code_base();
720 int last = size - 1;
721 if ((cb[0] != Bytecodes::_aload_0 && cb[0] != Bytecodes::_fast_aload_0 && cb[0] != Bytecodes::_nofast_aload_0) ||
722 cb[1] != Bytecodes::_invokespecial || cb[last] != Bytecodes::_return) {
723 // Does not call superclass default constructor
724 return false;
725 }
726 // Check optional sequence
727 for (int i = 4; i < last; i += 5) {
728 if (cb[i] != Bytecodes::_aload_0) return false;
729 if (!Bytecodes::is_zero_const(Bytecodes::cast(cb[i+1]))) return false;
730 if (cb[i+2] != Bytecodes::_putfield) return false;
731 }
732 return true;
733 }
734
735
736 bool Method::compute_has_loops_flag() {
737 BytecodeStream bcs(methodHandle(Thread::current(), this));
738 Bytecodes::Code bc;
739
740 while ((bc = bcs.next()) >= 0) {
741 switch (bc) {
742 case Bytecodes::_ifeq:
860
861 bool Method::is_accessor() const {
862 return is_getter() || is_setter();
863 }
864
865 bool Method::is_getter() const {
866 if (code_size() != 5) return false;
867 if (size_of_parameters() != 1) return false;
868 if (java_code_at(0) != Bytecodes::_aload_0) return false;
869 if (java_code_at(1) != Bytecodes::_getfield) return false;
870 switch (java_code_at(4)) {
871 case Bytecodes::_ireturn:
872 case Bytecodes::_lreturn:
873 case Bytecodes::_freturn:
874 case Bytecodes::_dreturn:
875 case Bytecodes::_areturn:
876 break;
877 default:
878 return false;
879 }
880 if (InlineTypeReturnedAsFields && result_type() == T_PRIMITIVE_OBJECT) {
881 // Don't treat this as (trivial) getter method because the
882 // inline type should be returned in a scalarized form.
883 return false;
884 }
885 return true;
886 }
887
888 bool Method::is_setter() const {
889 if (code_size() != 6) return false;
890 if (java_code_at(0) != Bytecodes::_aload_0) return false;
891 switch (java_code_at(1)) {
892 case Bytecodes::_iload_1:
893 case Bytecodes::_aload_1:
894 case Bytecodes::_fload_1:
895 if (size_of_parameters() != 2) return false;
896 break;
897 case Bytecodes::_dload_1:
898 case Bytecodes::_lload_1:
899 if (size_of_parameters() != 3) return false;
900 break;
901 default:
902 return false;
903 }
904 if (java_code_at(2) != Bytecodes::_putfield) return false;
905 if (java_code_at(5) != Bytecodes::_return) return false;
906 if (has_scalarized_args()) {
907 // Don't treat this as (trivial) setter method because the
908 // inline type argument should be passed in a scalarized form.
909 return false;
910 }
911 return true;
912 }
913
914 bool Method::is_constant_getter() const {
915 int last_index = code_size() - 1;
916 // Check if the first 1-3 bytecodes are a constant push
917 // and the last bytecode is a return.
918 return (2 <= code_size() && code_size() <= 4 &&
919 Bytecodes::is_const(java_code_at(0)) &&
920 Bytecodes::length_for(java_code_at(0)) == last_index &&
921 Bytecodes::is_return(java_code_at(last_index)));
922 }
923
924 bool Method::is_object_constructor_or_class_initializer() const {
925 return (is_object_constructor() || is_class_initializer());
926 }
927
928 bool Method::is_class_initializer() const {
929 // For classfiles version 51 or greater, ensure that the clinit method is
930 // static. Non-static methods with the name "<clinit>" are not static
931 // initializers. (older classfiles exempted for backward compatibility)
932 return (name() == vmSymbols::class_initializer_name() &&
933 (is_static() ||
934 method_holder()->major_version() < 51));
935 }
936
937 // A method named <init>, if non-static, is a classic object constructor.
938 bool Method::is_object_constructor() const {
939 return name() == vmSymbols::object_initializer_name() && !is_static();
940 }
941
942 // A static method named <init> is a factory for an inline class.
943 bool Method::is_static_init_factory() const {
944 return name() == vmSymbols::object_initializer_name() && is_static();
945 }
946
947 bool Method::needs_clinit_barrier() const {
948 return is_static() && !method_holder()->is_initialized();
949 }
950
951 objArrayHandle Method::resolved_checked_exceptions_impl(Method* method, TRAPS) {
952 int length = method->checked_exceptions_length();
953 if (length == 0) { // common case
954 return objArrayHandle(THREAD, Universe::the_empty_class_array());
955 } else {
956 methodHandle h_this(THREAD, method);
957 objArrayOop m_oop = oopFactory::new_objArray(vmClasses::Class_klass(), length, CHECK_(objArrayHandle()));
958 objArrayHandle mirrors (THREAD, m_oop);
959 for (int i = 0; i < length; i++) {
960 CheckedExceptionElement* table = h_this->checked_exceptions_start(); // recompute on each iteration, not gc safe
961 Klass* k = h_this->constants()->klass_at(table[i].class_cp_index, CHECK_(objArrayHandle()));
962 if (log_is_enabled(Warning, exceptions) &&
963 !k->is_subclass_of(vmClasses::Throwable_klass())) {
964 ResourceMark rm(THREAD);
982 // Not necessarily sorted and not necessarily one-to-one.
983 CompressedLineNumberReadStream stream(compressed_linenumber_table());
984 while (stream.read_pair()) {
985 if (stream.bci() == bci) {
986 // perfect match
987 return stream.line();
988 } else {
989 // update best_bci/line
990 if (stream.bci() < bci && stream.bci() >= best_bci) {
991 best_bci = stream.bci();
992 best_line = stream.line();
993 }
994 }
995 }
996 }
997 return best_line;
998 }
999
1000
1001 bool Method::is_klass_loaded_by_klass_index(int klass_index) const {
1002 if( constants()->tag_at(klass_index).is_unresolved_klass()) {
1003 Thread *thread = Thread::current();
1004 Symbol* klass_name = constants()->klass_name_at(klass_index);
1005 Handle loader(thread, method_holder()->class_loader());
1006 Handle prot (thread, method_holder()->protection_domain());
1007 return SystemDictionary::find_instance_klass(klass_name, loader, prot) != NULL;
1008 } else {
1009 return true;
1010 }
1011 }
1012
1013
1014 bool Method::is_klass_loaded(int refinfo_index, bool must_be_resolved) const {
1015 int klass_index = constants()->klass_ref_index_at(refinfo_index);
1016 if (must_be_resolved) {
1017 // Make sure klass is resolved in constantpool.
1018 if (constants()->tag_at(klass_index).is_unresolved_klass()) {
1019 return false;
1020 }
1021 }
1022 return is_klass_loaded_by_klass_index(klass_index);
1023 }
1024
1025
1026 void Method::set_native_function(address function, bool post_event_flag) {
1027 assert(function != NULL, "use clear_native_function to unregister natives");
1028 assert(!is_method_handle_intrinsic() || function == SharedRuntime::native_method_throw_unsatisfied_link_error_entry(), "");
1029 address* native_function = native_function_addr();
1030
1031 // We can see racers trying to place the same native function into place. Once
1032 // is plenty.
1033 address current = *native_function;
1034 if (current == function) return;
1035 if (post_event_flag && JvmtiExport::should_post_native_method_bind() &&
1036 function != NULL) {
1037 // native_method_throw_unsatisfied_link_error_entry() should only
1038 // be passed when post_event_flag is false.
1039 assert(function !=
1040 SharedRuntime::native_method_throw_unsatisfied_link_error_entry(),
1169 void Method::set_not_osr_compilable(const char* reason, int comp_level, bool report) {
1170 print_made_not_compilable(comp_level, /*is_osr*/ true, report, reason);
1171 if (comp_level == CompLevel_all) {
1172 set_not_c1_osr_compilable();
1173 set_not_c2_osr_compilable();
1174 } else {
1175 if (is_c1_compile(comp_level))
1176 set_not_c1_osr_compilable();
1177 if (is_c2_compile(comp_level))
1178 set_not_c2_osr_compilable();
1179 }
1180 assert(!CompilationPolicy::can_be_osr_compiled(methodHandle(Thread::current(), this), comp_level), "sanity check");
1181 }
1182
1183 // Revert to using the interpreter and clear out the nmethod
1184 void Method::clear_code() {
1185 // this may be NULL if c2i adapters have not been made yet
1186 // Only should happen at allocate time.
1187 if (adapter() == NULL) {
1188 _from_compiled_entry = NULL;
1189 _from_compiled_inline_entry = NULL;
1190 _from_compiled_inline_ro_entry = NULL;
1191 } else {
1192 _from_compiled_entry = adapter()->get_c2i_entry();
1193 _from_compiled_inline_entry = adapter()->get_c2i_inline_entry();
1194 _from_compiled_inline_ro_entry = adapter()->get_c2i_inline_ro_entry();
1195 }
1196 OrderAccess::storestore();
1197 _from_interpreted_entry = _i2i_entry;
1198 OrderAccess::storestore();
1199 _code = NULL;
1200 }
1201
1202 void Method::unlink_code(CompiledMethod *compare) {
1203 MutexLocker ml(CompiledMethod_lock->owned_by_self() ? NULL : CompiledMethod_lock, Mutex::_no_safepoint_check_flag);
1204 // We need to check if either the _code or _from_compiled_code_entry_point
1205 // refer to this nmethod because there is a race in setting these two fields
1206 // in Method* as seen in bugid 4947125.
1207 // If the vep() points to the zombie nmethod, the memory for the nmethod
1208 // could be flushed and the compiler and vtable stubs could still call
1209 // through it.
1210 if (code() == compare ||
1211 from_compiled_entry() == compare->verified_entry_point()) {
1212 clear_code();
1213 }
1214 }
1215
1216 void Method::unlink_code() {
1217 MutexLocker ml(CompiledMethod_lock->owned_by_self() ? NULL : CompiledMethod_lock, Mutex::_no_safepoint_check_flag);
1218 clear_code();
1219 }
1220
1221 #if INCLUDE_CDS
1222 // Called by class data sharing to remove any entry points (which are not shared)
1223 void Method::unlink_method() {
1224 Arguments::assert_is_dumping_archive();
1225 _code = NULL;
1226 _adapter = NULL;
1227 _i2i_entry = NULL;
1228 _from_compiled_entry = NULL;
1229 _from_compiled_inline_entry = NULL;
1230 _from_compiled_inline_ro_entry = NULL;
1231 _from_interpreted_entry = NULL;
1232
1233 if (is_native()) {
1234 *native_function_addr() = NULL;
1235 set_signature_handler(NULL);
1236 }
1237 NOT_PRODUCT(set_compiled_invocation_count(0);)
1238
1239 set_method_data(NULL);
1240 clear_method_counters();
1241 }
1242 #endif
1243
1244 // Called when the method_holder is getting linked. Setup entrypoints so the method
1245 // is ready to be called from interpreter, compiler, and vtables.
1246 void Method::link_method(const methodHandle& h_method, TRAPS) {
1247 // If the code cache is full, we may reenter this function for the
1248 // leftover methods that weren't linked.
1249 if (adapter() != NULL) {
1250 return;
1281 }
1282
1283 address Method::make_adapters(const methodHandle& mh, TRAPS) {
1284 // Adapters for compiled code are made eagerly here. They are fairly
1285 // small (generally < 100 bytes) and quick to make (and cached and shared)
1286 // so making them eagerly shouldn't be too expensive.
1287 AdapterHandlerEntry* adapter = AdapterHandlerLibrary::get_adapter(mh);
1288 if (adapter == NULL ) {
1289 if (!is_init_completed()) {
1290 // Don't throw exceptions during VM initialization because java.lang.* classes
1291 // might not have been initialized, causing problems when constructing the
1292 // Java exception object.
1293 vm_exit_during_initialization("Out of space in CodeCache for adapters");
1294 } else {
1295 THROW_MSG_NULL(vmSymbols::java_lang_VirtualMachineError(), "Out of space in CodeCache for adapters");
1296 }
1297 }
1298
1299 mh->set_adapter_entry(adapter);
1300 mh->_from_compiled_entry = adapter->get_c2i_entry();
1301 mh->_from_compiled_inline_entry = adapter->get_c2i_inline_entry();
1302 mh->_from_compiled_inline_ro_entry = adapter->get_c2i_inline_ro_entry();
1303 return adapter->get_c2i_entry();
1304 }
1305
1306 void Method::restore_unshareable_info(TRAPS) {
1307 assert(is_method() && is_valid_method(this), "ensure C++ vtable is restored");
1308 }
1309
1310 address Method::from_compiled_entry_no_trampoline(bool caller_is_c1) const {
1311 CompiledMethod *code = Atomic::load_acquire(&_code);
1312 if (caller_is_c1) {
1313 // C1 - inline type arguments are passed as objects
1314 if (code) {
1315 return code->verified_inline_entry_point();
1316 } else {
1317 return adapter()->get_c2i_inline_entry();
1318 }
1319 } else {
1320 // C2 - inline type arguments may be passed as fields
1321 if (code) {
1322 return code->verified_entry_point();
1323 } else {
1324 return adapter()->get_c2i_entry();
1325 }
1326 }
1327 }
1328
1329 // The verified_code_entry() must be called when a invoke is resolved
1330 // on this method.
1331
1332 // It returns the compiled code entry point, after asserting not null.
1333 // This function is called after potential safepoints so that nmethod
1334 // or adapter that it points to is still live and valid.
1335 // This function must not hit a safepoint!
1336 address Method::verified_code_entry() {
1337 debug_only(NoSafepointVerifier nsv;)
1338 assert(_from_compiled_entry != NULL, "must be set");
1339 return _from_compiled_entry;
1340 }
1341
1342 address Method::verified_inline_code_entry() {
1343 debug_only(NoSafepointVerifier nsv;)
1344 assert(_from_compiled_inline_entry != NULL, "must be set");
1345 return _from_compiled_inline_entry;
1346 }
1347
1348 address Method::verified_inline_ro_code_entry() {
1349 debug_only(NoSafepointVerifier nsv;)
1350 assert(_from_compiled_inline_ro_entry != NULL, "must be set");
1351 return _from_compiled_inline_ro_entry;
1352 }
1353
1354 // Check that if an nmethod ref exists, it has a backlink to this or no backlink at all
1355 // (could be racing a deopt).
1356 // Not inline to avoid circular ref.
1357 bool Method::check_code() const {
1358 // cached in a register or local. There's a race on the value of the field.
1359 CompiledMethod *code = Atomic::load_acquire(&_code);
1360 return code == NULL || (code->method() == NULL) || (code->method() == (Method*)this && !code->is_osr_method());
1361 }
1362
1363 // Install compiled code. Instantly it can execute.
1364 void Method::set_code(const methodHandle& mh, CompiledMethod *code) {
1365 assert_lock_strong(CompiledMethod_lock);
1366 assert( code, "use clear_code to remove code" );
1367 assert( mh->check_code(), "" );
1368
1369 guarantee(mh->adapter() != NULL, "Adapter blob must already exist!");
1370
1371 // These writes must happen in this order, because the interpreter will
1372 // directly jump to from_interpreted_entry which jumps to an i2c adapter
1373 // which jumps to _from_compiled_entry.
1374 mh->_code = code; // Assign before allowing compiled code to exec
1375
1376 int comp_level = code->comp_level();
1377 // In theory there could be a race here. In practice it is unlikely
1378 // and not worth worrying about.
1379 if (comp_level > mh->highest_comp_level()) {
1380 mh->set_highest_comp_level(comp_level);
1381 }
1382
1383 OrderAccess::storestore();
1384 mh->_from_compiled_entry = code->verified_entry_point();
1385 mh->_from_compiled_inline_entry = code->verified_inline_entry_point();
1386 mh->_from_compiled_inline_ro_entry = code->verified_inline_ro_entry_point();
1387 OrderAccess::storestore();
1388 // Instantly compiled code can execute.
1389 if (!mh->is_method_handle_intrinsic())
1390 mh->_from_interpreted_entry = mh->get_i2c_entry();
1391 }
1392
1393
1394 bool Method::is_overridden_in(Klass* k) const {
1395 InstanceKlass* ik = InstanceKlass::cast(k);
1396
1397 if (ik->is_interface()) return false;
1398
1399 // If method is an interface, we skip it - except if it
1400 // is a miranda method
1401 if (method_holder()->is_interface()) {
1402 // Check that method is not a miranda method
1403 if (ik->lookup_method(name(), signature()) == NULL) {
1404 // No implementation exist - so miranda method
1405 return false;
1406 }
2358 // This assumes that the vtbl pointer is the first word of a C++ object.
2359 return dereference_vptr(&m) == dereference_vptr(ptr);
2360 }
2361
2362 // Check that this pointer is valid by checking that the vtbl pointer matches
2363 bool Method::is_valid_method(const Method* m) {
2364 if (m == NULL) {
2365 return false;
2366 } else if ((intptr_t(m) & (wordSize-1)) != 0) {
2367 // Quick sanity check on pointer.
2368 return false;
2369 } else if (m->is_shared()) {
2370 return CppVtables::is_valid_shared_method(m);
2371 } else if (Metaspace::contains_non_shared(m)) {
2372 return has_method_vptr((const void*)m);
2373 } else {
2374 return false;
2375 }
2376 }
2377
2378 bool Method::is_scalarized_arg(int idx) const {
2379 if (!has_scalarized_args()) {
2380 return false;
2381 }
2382 // Search through signature and check if argument is wrapped in T_PRIMITIVE_OBJECT/T_VOID
2383 int depth = 0;
2384 const GrowableArray<SigEntry>* sig = adapter()->get_sig_cc();
2385 for (int i = 0; i < sig->length(); i++) {
2386 BasicType bt = sig->at(i)._bt;
2387 if (bt == T_PRIMITIVE_OBJECT) {
2388 depth++;
2389 }
2390 if (idx == 0) {
2391 break; // Argument found
2392 }
2393 if (bt == T_VOID && (sig->at(i-1)._bt != T_LONG && sig->at(i-1)._bt != T_DOUBLE)) {
2394 depth--;
2395 }
2396 if (depth == 0 && bt != T_LONG && bt != T_DOUBLE) {
2397 idx--; // Advance to next argument
2398 }
2399 }
2400 return depth != 0;
2401 }
2402
2403 #ifndef PRODUCT
2404 void Method::print_jmethod_ids_count(const ClassLoaderData* loader_data, outputStream* out) {
2405 out->print("%d", loader_data->jmethod_ids()->count_methods());
2406 }
2407 #endif // PRODUCT
2408
2409
2410 // Printing
2411
2412 #ifndef PRODUCT
2413
2414 void Method::print_on(outputStream* st) const {
2415 ResourceMark rm;
2416 assert(is_method(), "must be method");
2417 st->print_cr("%s", internal_name());
2418 st->print_cr(" - this oop: " INTPTR_FORMAT, p2i(this));
2419 st->print (" - method holder: "); method_holder()->print_value_on(st); st->cr();
2420 st->print (" - constants: " INTPTR_FORMAT " ", p2i(constants()));
2421 constants()->print_value_on(st); st->cr();
2422 st->print (" - access: 0x%x ", access_flags().as_int()); access_flags().print_on(st); st->cr();
2423 st->print (" - name: "); name()->print_value_on(st); st->cr();
2424 st->print (" - signature: "); signature()->print_value_on(st); st->cr();
2425 st->print_cr(" - max stack: %d", max_stack());
2426 st->print_cr(" - max locals: %d", max_locals());
2427 st->print_cr(" - size of params: %d", size_of_parameters());
2428 st->print_cr(" - method size: %d", method_size());
2429 if (intrinsic_id() != vmIntrinsics::_none)
2430 st->print_cr(" - intrinsic id: %d %s", vmIntrinsics::as_int(intrinsic_id()), vmIntrinsics::name_at(intrinsic_id()));
2431 if (highest_comp_level() != CompLevel_none)
2432 st->print_cr(" - highest level: %d", highest_comp_level());
2433 st->print_cr(" - vtable index: %d", _vtable_index);
2434 #ifdef ASSERT
2435 if (valid_itable_index())
2436 st->print_cr(" - itable index: %d", itable_index());
2437 #endif
2438 st->print_cr(" - i2i entry: " INTPTR_FORMAT, p2i(interpreter_entry()));
2439 st->print( " - adapters: ");
2440 AdapterHandlerEntry* a = ((Method*)this)->adapter();
2441 if (a == NULL)
2442 st->print_cr(INTPTR_FORMAT, p2i(a));
2443 else
2444 a->print_adapter_on(st);
2445 st->print_cr(" - compiled entry " INTPTR_FORMAT, p2i(from_compiled_entry()));
2446 st->print_cr(" - compiled inline entry " INTPTR_FORMAT, p2i(from_compiled_inline_entry()));
2447 st->print_cr(" - compiled inline ro entry " INTPTR_FORMAT, p2i(from_compiled_inline_ro_entry()));
2448 st->print_cr(" - code size: %d", code_size());
2449 if (code_size() != 0) {
2450 st->print_cr(" - code start: " INTPTR_FORMAT, p2i(code_base()));
2451 st->print_cr(" - code end (excl): " INTPTR_FORMAT, p2i(code_base() + code_size()));
2452 }
2453 if (method_data() != NULL) {
2454 st->print_cr(" - method data: " INTPTR_FORMAT, p2i(method_data()));
2455 }
2456 st->print_cr(" - checked ex length: %d", checked_exceptions_length());
2457 if (checked_exceptions_length() > 0) {
2458 CheckedExceptionElement* table = checked_exceptions_start();
2459 st->print_cr(" - checked ex start: " INTPTR_FORMAT, p2i(table));
2460 if (Verbose) {
2461 for (int i = 0; i < checked_exceptions_length(); i++) {
2462 st->print_cr(" - throws %s", constants()->printable_name_at(table[i].class_cp_index));
2463 }
2464 }
2465 }
2466 if (has_linenumber_table()) {
2467 u_char* table = compressed_linenumber_table();
2497 st->print_cr(" - signature handler: " INTPTR_FORMAT, p2i(signature_handler()));
2498 }
2499 }
2500
2501 void Method::print_linkage_flags(outputStream* st) {
2502 access_flags().print_on(st);
2503 if (is_default_method()) {
2504 st->print("default ");
2505 }
2506 if (is_overpass()) {
2507 st->print("overpass ");
2508 }
2509 }
2510 #endif //PRODUCT
2511
2512 void Method::print_value_on(outputStream* st) const {
2513 assert(is_method(), "must be method");
2514 st->print("%s", internal_name());
2515 print_address_on(st);
2516 st->print(" ");
2517 if (WizardMode) access_flags().print_on(st);
2518 name()->print_value_on(st);
2519 st->print(" ");
2520 signature()->print_value_on(st);
2521 st->print(" in ");
2522 method_holder()->print_value_on(st);
2523 if (WizardMode) st->print("#%d", _vtable_index);
2524 if (WizardMode) st->print("[%d,%d]", size_of_parameters(), max_locals());
2525 if (WizardMode && code() != NULL) st->print(" ((nmethod*)%p)", code());
2526 }
2527
2528 // LogTouchedMethods and PrintTouchedMethods
2529
2530 // TouchedMethodRecord -- we can't use a HashtableEntry<Method*> because
2531 // the Method may be garbage collected. Let's roll our own hash table.
2532 class TouchedMethodRecord : CHeapObj<mtTracing> {
2533 public:
2534 // It's OK to store Symbols here because they will NOT be GC'ed if
2535 // LogTouchedMethods is enabled.
2536 TouchedMethodRecord* _next;
2537 Symbol* _class_name;
|