7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "jvm.h"
27 #include "code/codeCache.hpp"
28 #include "code/compiledIC.hpp"
29 #include "code/compiledMethod.inline.hpp"
30 #include "code/dependencies.hpp"
31 #include "code/nativeInst.hpp"
32 #include "code/nmethod.hpp"
33 #include "code/scopeDesc.hpp"
34 #include "compiler/abstractCompiler.hpp"
35 #include "compiler/compileBroker.hpp"
36 #include "compiler/compileLog.hpp"
37 #include "compiler/compilerDirectives.hpp"
38 #include "compiler/directivesParser.hpp"
39 #include "compiler/disassembler.hpp"
40 #include "interpreter/bytecode.hpp"
41 #include "logging/log.hpp"
42 #include "logging/logStream.hpp"
43 #include "memory/allocation.inline.hpp"
44 #include "memory/resourceArea.hpp"
45 #include "memory/universe.hpp"
46 #include "oops/access.inline.hpp"
439 #if INCLUDE_RTM_OPT
440 _rtm_state = NoRTM;
441 #endif
442 }
443
444 nmethod* nmethod::new_native_nmethod(const methodHandle& method,
445 int compile_id,
446 CodeBuffer *code_buffer,
447 int vep_offset,
448 int frame_complete,
449 int frame_size,
450 ByteSize basic_lock_owner_sp_offset,
451 ByteSize basic_lock_sp_offset,
452 OopMapSet* oop_maps) {
453 code_buffer->finalize_oop_references(method);
454 // create nmethod
455 nmethod* nm = NULL;
456 {
457 MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
458 int native_nmethod_size = CodeBlob::allocation_size(code_buffer, sizeof(nmethod));
459 CodeOffsets offsets;
460 offsets.set_value(CodeOffsets::Verified_Entry, vep_offset);
461 offsets.set_value(CodeOffsets::Frame_Complete, frame_complete);
462 nm = new (native_nmethod_size, CompLevel_none) nmethod(method(), compiler_none, native_nmethod_size,
463 compile_id, &offsets,
464 code_buffer, frame_size,
465 basic_lock_owner_sp_offset,
466 basic_lock_sp_offset, oop_maps);
467 NOT_PRODUCT(if (nm != NULL) native_nmethod_stats.note_native_nmethod(nm));
468 }
469
470 if (nm != NULL) {
471 // verify nmethod
472 debug_only(nm->verify();) // might block
473
474 nm->log_new_nmethod();
475 nm->make_in_use();
476 }
477 return nm;
478 }
479
480 nmethod* nmethod::new_nmethod(const methodHandle& method,
481 int compile_id,
482 int entry_bci,
483 CodeOffsets* offsets,
484 int orig_pc_offset,
485 DebugInformationRecorder* debug_info,
486 Dependencies* dependencies,
641
642 clear_unloading_state();
643
644 Universe::heap()->register_nmethod(this);
645 debug_only(Universe::heap()->verify_nmethod(this));
646
647 CodeCache::commit(this);
648 }
649
650 if (PrintNativeNMethods || PrintDebugInfo || PrintRelocations || PrintDependencies) {
651 ttyLocker ttyl; // keep the following output all in one block
652 // This output goes directly to the tty, not the compiler log.
653 // To enable tools to match it up with the compilation activity,
654 // be sure to tag this tty output with the compile ID.
655 if (xtty != NULL) {
656 xtty->begin_head("print_native_nmethod");
657 xtty->method(_method);
658 xtty->stamp();
659 xtty->end_head(" address='" INTPTR_FORMAT "'", (intptr_t) this);
660 }
661 // print the header part first
662 print();
663 // then print the requested information
664 if (PrintNativeNMethods) {
665 print_code();
666 if (oop_maps != NULL) {
667 oop_maps->print();
668 }
669 }
670 if (PrintRelocations) {
671 print_relocations();
672 }
673 if (xtty != NULL) {
674 xtty->tail("print_native_nmethod");
675 }
676 }
677 }
678
679 void* nmethod::operator new(size_t size, int nmethod_size, int comp_level) throw () {
680 return CodeCache::allocate(nmethod_size, CodeCache::get_code_blob_type(comp_level));
681 }
682
683 nmethod::nmethod(
684 Method* method,
685 CompilerType type,
686 int nmethod_size,
687 int compile_id,
688 int entry_bci,
689 CodeOffsets* offsets,
690 int orig_pc_offset,
691 DebugInformationRecorder* debug_info,
692 Dependencies* dependencies,
729 set_ctable_begin(header_begin() + _consts_offset);
730
731 #if INCLUDE_JVMCI
732 if (compiler->is_jvmci()) {
733 // JVMCI might not produce any stub sections
734 if (offsets->value(CodeOffsets::Exceptions) != -1) {
735 _exception_offset = code_offset() + offsets->value(CodeOffsets::Exceptions);
736 } else {
737 _exception_offset = -1;
738 }
739 if (offsets->value(CodeOffsets::Deopt) != -1) {
740 _deopt_handler_begin = (address) this + code_offset() + offsets->value(CodeOffsets::Deopt);
741 } else {
742 _deopt_handler_begin = NULL;
743 }
744 if (offsets->value(CodeOffsets::DeoptMH) != -1) {
745 _deopt_mh_handler_begin = (address) this + code_offset() + offsets->value(CodeOffsets::DeoptMH);
746 } else {
747 _deopt_mh_handler_begin = NULL;
748 }
749 } else {
750 #endif
751 // Exception handler and deopt handler are in the stub section
752 assert(offsets->value(CodeOffsets::Exceptions) != -1, "must be set");
753 assert(offsets->value(CodeOffsets::Deopt ) != -1, "must be set");
754
755 _exception_offset = _stub_offset + offsets->value(CodeOffsets::Exceptions);
756 _deopt_handler_begin = (address) this + _stub_offset + offsets->value(CodeOffsets::Deopt);
757 if (offsets->value(CodeOffsets::DeoptMH) != -1) {
758 _deopt_mh_handler_begin = (address) this + _stub_offset + offsets->value(CodeOffsets::DeoptMH);
759 } else {
760 _deopt_mh_handler_begin = NULL;
761 }
762 #if INCLUDE_JVMCI
763 }
764 #endif
765 if (offsets->value(CodeOffsets::UnwindHandler) != -1) {
766 _unwind_handler_offset = code_offset() + offsets->value(CodeOffsets::UnwindHandler);
767 } else {
768 _unwind_handler_offset = -1;
769 }
770
771 _oops_offset = data_offset();
772 _metadata_offset = _oops_offset + align_up(code_buffer->total_oop_size(), oopSize);
773 int scopes_data_offset = _metadata_offset + align_up(code_buffer->total_metadata_size(), wordSize);
774
775 _scopes_pcs_offset = scopes_data_offset + align_up(debug_info->data_size (), oopSize);
776 _dependencies_offset = _scopes_pcs_offset + adjust_pcs_size(debug_info->pcs_size());
777 _handler_table_offset = _dependencies_offset + align_up((int)dependencies->size_in_bytes (), oopSize);
778 _nul_chk_table_offset = _handler_table_offset + align_up(handler_table->size_in_bytes(), oopSize);
779 #if INCLUDE_JVMCI
780 _speculations_offset = _nul_chk_table_offset + align_up(nul_chk_table->size_in_bytes(), oopSize);
781 _jvmci_data_offset = _speculations_offset + align_up(speculations_len, oopSize);
782 _nmethod_end_offset = _jvmci_data_offset + align_up(jvmci_data_size, oopSize);
783 #else
784 _nmethod_end_offset = _nul_chk_table_offset + align_up(nul_chk_table->size_in_bytes(), oopSize);
785 #endif
786 _entry_point = code_begin() + offsets->value(CodeOffsets::Entry);
787 _verified_entry_point = code_begin() + offsets->value(CodeOffsets::Verified_Entry);
788 _osr_entry_point = code_begin() + offsets->value(CodeOffsets::OSR_Entry);
789 _exception_cache = NULL;
790
791 _scopes_data_begin = (address) this + scopes_data_offset;
792
793 _pc_desc_container.reset_to(scopes_pcs_begin());
794
795 code_buffer->copy_code_and_locs_to(this);
796 // Copy contents of ScopeDescRecorder to nmethod
797 code_buffer->copy_values_to(this);
798 debug_info->copy_to(this);
799 dependencies->copy_to(this);
800 clear_unloading_state();
801
802 Universe::heap()->register_nmethod(this);
803 debug_only(Universe::heap()->verify_nmethod(this));
804
805 CodeCache::commit(this);
806
807 // Copy contents of ExceptionHandlerTable to nmethod
808 handler_table->copy_to(this);
809 nul_chk_table->copy_to(this);
810
892 } else {
893 CompileTask::print(st, this, msg, /*short_form:*/ false);
894 }
895 }
896 }
897
898 void nmethod::maybe_print_nmethod(DirectiveSet* directive) {
899 bool printnmethods = directive->PrintAssemblyOption || directive->PrintNMethodsOption;
900 if (printnmethods || PrintDebugInfo || PrintRelocations || PrintDependencies || PrintExceptionHandlers) {
901 print_nmethod(printnmethods);
902 }
903 }
904
905 void nmethod::print_nmethod(bool printmethod) {
906 ttyLocker ttyl; // keep the following output all in one block
907 if (xtty != NULL) {
908 xtty->begin_head("print_nmethod");
909 xtty->stamp();
910 xtty->end_head();
911 }
912 // print the header part first
913 print();
914 // then print the requested information
915 if (printmethod) {
916 print_code();
917 print_pcs();
918 if (oop_maps()) {
919 oop_maps()->print();
920 }
921 }
922 if (printmethod || PrintDebugInfo || CompilerOracle::has_option_string(_method, "PrintDebugInfo")) {
923 print_scopes();
924 }
925 if (printmethod || PrintRelocations || CompilerOracle::has_option_string(_method, "PrintRelocations")) {
926 print_relocations();
927 }
928 if (printmethod || PrintDependencies || CompilerOracle::has_option_string(_method, "PrintDependencies")) {
929 print_dependencies();
930 }
931 if (printmethod || PrintExceptionHandlers) {
932 print_handler_table();
933 print_nul_chk_table();
934 }
935 if (printmethod) {
936 print_recorded_oops();
937 print_recorded_metadata();
938 }
939 if (xtty != NULL) {
940 xtty->tail("print_nmethod");
941 }
942 }
943
944
945 // Promote one word from an assembly-time handle to a live embedded oop.
946 inline void nmethod::initialize_immediate_oop(oop* dest, jobject handle) {
947 if (handle == NULL ||
948 // As a special case, IC oops are initialized to 1 or -1.
949 handle == (jobject) Universe::non_oop_word()) {
950 (*dest) = (oop) handle;
951 } else {
952 (*dest) = JNIHandles::resolve_non_null(handle);
953 }
954 }
955
956
957 // Have to have the same name because it's called by a template
958 void nmethod::copy_values(GrowableArray<jobject>* array) {
2046 }
2047 return true;
2048 }
2049
2050
2051 address nmethod::continuation_for_implicit_exception(address pc) {
2052 // Exception happened outside inline-cache check code => we are inside
2053 // an active nmethod => use cpc to determine a return address
2054 int exception_offset = pc - code_begin();
2055 int cont_offset = ImplicitExceptionTable(this).at( exception_offset );
2056 #ifdef ASSERT
2057 if (cont_offset == 0) {
2058 Thread* thread = Thread::current();
2059 ResetNoHandleMark rnm; // Might be called from LEAF/QUICK ENTRY
2060 HandleMark hm(thread);
2061 ResourceMark rm(thread);
2062 CodeBlob* cb = CodeCache::find_blob(pc);
2063 assert(cb != NULL && cb == this, "");
2064 ttyLocker ttyl;
2065 tty->print_cr("implicit exception happened at " INTPTR_FORMAT, p2i(pc));
2066 print();
2067 method()->print_codes();
2068 print_code();
2069 print_pcs();
2070 }
2071 #endif
2072 if (cont_offset == 0) {
2073 // Let the normal error handling report the exception
2074 return NULL;
2075 }
2076 return code_begin() + cont_offset;
2077 }
2078
2079
2080
2081 void nmethod_init() {
2082 // make sure you didn't forget to adjust the filler fields
2083 assert(sizeof(nmethod) % oopSize == 0, "nmethod size must be multiple of a word");
2084 }
2085
2086
2087 //-------------------------------------------------------------------------------------------
2088
2089
2090 // QQQ might we make this work from a frame??
2091 nmethodLocker::nmethodLocker(address pc) {
2092 CodeBlob* cb = CodeCache::find_blob(pc);
2093 guarantee(cb != NULL && cb->is_compiled(), "bad pc for a nmethod found");
2094 _nm = cb->as_compiled_method();
2095 lock_nmethod(_nm);
2096 }
2097
2098 // Only JvmtiDeferredEvent::compiled_method_unload_event()
2099 // should pass zombie_ok == true.
2100 void nmethodLocker::lock_nmethod(CompiledMethod* cm, bool zombie_ok) {
2108 void nmethodLocker::unlock_nmethod(CompiledMethod* cm) {
2109 if (cm == NULL) return;
2110 if (cm->is_aot()) return; // FIXME: Revisit once _lock_count is added to aot_method
2111 nmethod* nm = cm->as_nmethod();
2112 Atomic::dec(&nm->_lock_count);
2113 assert(nm->_lock_count >= 0, "unmatched nmethod lock/unlock");
2114 }
2115
2116
2117 // -----------------------------------------------------------------------------
2118 // Verification
2119
2120 class VerifyOopsClosure: public OopClosure {
2121 nmethod* _nm;
2122 bool _ok;
2123 public:
2124 VerifyOopsClosure(nmethod* nm) : _nm(nm), _ok(true) { }
2125 bool ok() { return _ok; }
2126 virtual void do_oop(oop* p) {
2127 if (oopDesc::is_oop_or_null(*p)) return;
2128 if (_ok) {
2129 _nm->print_nmethod(true);
2130 _ok = false;
2131 }
2132 tty->print_cr("*** non-oop " PTR_FORMAT " found at " PTR_FORMAT " (offset %d)",
2133 p2i(*p), p2i(p), (int)((intptr_t)p - (intptr_t)_nm));
2134 }
2135 virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); }
2136 };
2137
2138 void nmethod::verify() {
2139
2140 // Hmm. OSR methods can be deopted but not marked as zombie or not_entrant
2141 // seems odd.
2142
2143 if (is_zombie() || is_not_entrant() || is_unloaded())
2144 return;
2145
2146 // Make sure all the entry points are correctly aligned for patching.
2147 NativeJump::check_verified_entry_alignment(entry_point(), verified_entry_point());
2148
2149 // assert(oopDesc::is_oop(method()), "must be valid");
2150
2151 ResourceMark rm;
2152
2153 if (!CodeCache::contains(this)) {
2222 case relocInfo::runtime_call_type:
2223 case relocInfo::runtime_call_w_cp_type: {
2224 address destination = iter.reloc()->value();
2225 // Right now there is no way to find out which entries support
2226 // an interrupt point. It would be nice if we had this
2227 // information in a table.
2228 break;
2229 }
2230 default:
2231 break;
2232 }
2233 assert(stub == NULL || stub_contains(stub), "static call stub outside stub section");
2234 }
2235 }
2236
2237
2238 // -----------------------------------------------------------------------------
2239 // Printing operations
2240
2241 void nmethod::print() const {
2242 ResourceMark rm;
2243 ttyLocker ttyl; // keep the following output all in one block
2244
2245 tty->print("Compiled method ");
2246
2247 if (is_compiled_by_c1()) {
2248 tty->print("(c1) ");
2249 } else if (is_compiled_by_c2()) {
2250 tty->print("(c2) ");
2251 } else if (is_compiled_by_jvmci()) {
2252 tty->print("(JVMCI) ");
2253 } else {
2254 tty->print("(nm) ");
2255 }
2256
2257 print_on(tty, NULL);
2258
2259 if (WizardMode) {
2260 tty->print("((nmethod*) " INTPTR_FORMAT ") ", p2i(this));
2261 tty->print(" for method " INTPTR_FORMAT , p2i(method()));
2262 tty->print(" { ");
2263 tty->print_cr("%s ", state());
2264 tty->print_cr("}:");
2265 }
2266 if (size () > 0) tty->print_cr(" total in heap [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2267 p2i(this),
2268 p2i(this) + size(),
2269 size());
2270 if (relocation_size () > 0) tty->print_cr(" relocation [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2271 p2i(relocation_begin()),
2272 p2i(relocation_end()),
2273 relocation_size());
2274 if (consts_size () > 0) tty->print_cr(" constants [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2275 p2i(consts_begin()),
2276 p2i(consts_end()),
2277 consts_size());
2278 if (insts_size () > 0) tty->print_cr(" main code [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2279 p2i(insts_begin()),
2280 p2i(insts_end()),
2281 insts_size());
2282 if (stub_size () > 0) tty->print_cr(" stub code [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2283 p2i(stub_begin()),
2284 p2i(stub_end()),
2285 stub_size());
2286 if (oops_size () > 0) tty->print_cr(" oops [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2287 p2i(oops_begin()),
2288 p2i(oops_end()),
2289 oops_size());
2290 if (metadata_size () > 0) tty->print_cr(" metadata [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2291 p2i(metadata_begin()),
2292 p2i(metadata_end()),
2293 metadata_size());
2294 if (scopes_data_size () > 0) tty->print_cr(" scopes data [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2295 p2i(scopes_data_begin()),
2296 p2i(scopes_data_end()),
2297 scopes_data_size());
2298 if (scopes_pcs_size () > 0) tty->print_cr(" scopes pcs [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2299 p2i(scopes_pcs_begin()),
2300 p2i(scopes_pcs_end()),
2301 scopes_pcs_size());
2302 if (dependencies_size () > 0) tty->print_cr(" dependencies [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2303 p2i(dependencies_begin()),
2304 p2i(dependencies_end()),
2305 dependencies_size());
2306 if (handler_table_size() > 0) tty->print_cr(" handler table [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2307 p2i(handler_table_begin()),
2308 p2i(handler_table_end()),
2309 handler_table_size());
2310 if (nul_chk_table_size() > 0) tty->print_cr(" nul chk table [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2311 p2i(nul_chk_table_begin()),
2312 p2i(nul_chk_table_end()),
2313 nul_chk_table_size());
2314 #if INCLUDE_JVMCI
2315 if (speculations_size () > 0) tty->print_cr(" speculations [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2316 p2i(speculations_begin()),
2317 p2i(speculations_end()),
2318 speculations_size());
2319 if (jvmci_data_size () > 0) tty->print_cr(" JVMCI data [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2320 p2i(jvmci_data_begin()),
2321 p2i(jvmci_data_end()),
2322 jvmci_data_size());
2323 #endif
2324 }
2325
2326 #ifndef PRODUCT
2327
2328 void nmethod::print_scopes() {
2329 // Find the first pc desc for all scopes in the code and print it.
2330 ResourceMark rm;
2331 for (PcDesc* p = scopes_pcs_begin(); p < scopes_pcs_end(); p++) {
2332 if (p->scope_decode_offset() == DebugInformationRecorder::serialized_null)
2333 continue;
2334
2335 ScopeDesc* sd = scope_desc_at(p->real_pc(this));
2336 while (sd != NULL) {
2337 sd->print_on(tty, p);
2338 sd = sd->sender();
2339 }
2340 }
2341 }
2342
2343 void nmethod::print_dependencies() {
2344 ResourceMark rm;
2345 ttyLocker ttyl; // keep the following output all in one block
2346 tty->print_cr("Dependencies:");
2347 for (Dependencies::DepStream deps(this); deps.next(); ) {
2348 deps.print_dependency();
2349 Klass* ctxk = deps.context_type();
2350 if (ctxk != NULL) {
2351 if (ctxk->is_instance_klass() && InstanceKlass::cast(ctxk)->is_dependent_nmethod(this)) {
2352 tty->print_cr(" [nmethod<=klass]%s", ctxk->external_name());
2353 }
2354 }
2355 deps.log_dependency(); // put it into the xml log also
2356 }
2357 }
2358
2359
2360 void nmethod::print_relocations() {
2361 ResourceMark m; // in case methods get printed via the debugger
2362 tty->print_cr("relocations:");
2363 RelocIterator iter(this);
2364 iter.print();
2365 }
2366
2367
2368 void nmethod::print_pcs() {
2369 ResourceMark m; // in case methods get printed via debugger
2370 tty->print_cr("pc-bytecode offsets:");
2371 for (PcDesc* p = scopes_pcs_begin(); p < scopes_pcs_end(); p++) {
2372 p->print(this);
2373 }
2374 }
2375
2376 void nmethod::print_recorded_oops() {
2377 tty->print_cr("Recorded oops:");
2378 for (int i = 0; i < oops_count(); i++) {
2379 oop o = oop_at(i);
2380 tty->print("#%3d: " INTPTR_FORMAT " ", i, p2i(o));
2381 if (o == Universe::non_oop_word()) {
2382 tty->print("non-oop word");
2383 } else {
2384 if (o != NULL) {
2385 o->print_value();
2386 } else {
2387 tty->print_cr("NULL");
2388 }
2389 }
2390 tty->cr();
2391 }
2392 }
2393
2394 void nmethod::print_recorded_metadata() {
2395 tty->print_cr("Recorded metadata:");
2396 for (int i = 0; i < metadata_count(); i++) {
2397 Metadata* m = metadata_at(i);
2398 tty->print("#%3d: " INTPTR_FORMAT " ", i, p2i(m));
2399 if (m == (Metadata*)Universe::non_oop_word()) {
2400 tty->print("non-metadata word");
2401 } else {
2402 Metadata::print_value_on_maybe_null(tty, m);
2403 }
2404 tty->cr();
2405 }
2406 }
2407
2408 #endif // PRODUCT
2409
2410 const char* nmethod::reloc_string_for(u_char* begin, u_char* end) {
2411 RelocIterator iter(this, begin, end);
2412 bool have_one = false;
2413 while (iter.next()) {
2414 have_one = true;
2415 switch (iter.type()) {
2416 case relocInfo::none: return "no_reloc";
2417 case relocInfo::oop_type: {
2418 stringStream st;
2419 oop_Relocation* r = iter.oop_reloc();
2420 oop obj = r->oop_value();
2421 st.print("oop(");
2422 if (obj == NULL) st.print("NULL");
2423 else obj->print_value_on(&st);
2424 st.print(")");
2425 return st.as_string();
2426 }
2427 case relocInfo::metadata_type: {
2428 stringStream st;
2429 metadata_Relocation* r = iter.metadata_reloc();
2430 Metadata* obj = r->metadata_value();
2431 st.print("metadata(");
2432 if (obj == NULL) st.print("NULL");
2433 else obj->print_value_on(&st);
2434 st.print(")");
2435 return st.as_string();
2436 }
2437 case relocInfo::runtime_call_type:
2438 case relocInfo::runtime_call_w_cp_type: {
2500 case relocInfo::type_mask: return "type_bit_mask";
2501
2502 default:
2503 break;
2504 }
2505 }
2506 return have_one ? "other" : NULL;
2507 }
2508
2509 // Return a the last scope in (begin..end]
2510 ScopeDesc* nmethod::scope_desc_in(address begin, address end) {
2511 PcDesc* p = pc_desc_near(begin+1);
2512 if (p != NULL && p->real_pc(this) <= end) {
2513 return new ScopeDesc(this, p->scope_decode_offset(),
2514 p->obj_decode_offset(), p->should_reexecute(), p->rethrow_exception(),
2515 p->return_oop());
2516 }
2517 return NULL;
2518 }
2519
2520 void nmethod::print_nmethod_labels(outputStream* stream, address block_begin) const {
2521 if (block_begin == entry_point()) stream->print_cr("[Entry Point]");
2522 if (block_begin == verified_entry_point()) stream->print_cr("[Verified Entry Point]");
2523 if (JVMCI_ONLY(_exception_offset >= 0 &&) block_begin == exception_begin()) stream->print_cr("[Exception Handler]");
2524 if (block_begin == stub_begin()) stream->print_cr("[Stub Code]");
2525 if (JVMCI_ONLY(_deopt_handler_begin != NULL &&) block_begin == deopt_handler_begin()) stream->print_cr("[Deopt Handler Code]");
2526
2527 if (has_method_handle_invokes())
2528 if (block_begin == deopt_mh_handler_begin()) stream->print_cr("[Deopt MH Handler Code]");
2529
2530 if (block_begin == consts_begin()) stream->print_cr("[Constants]");
2531
2532 if (block_begin == entry_point()) {
2533 methodHandle m = method();
2534 if (m.not_null()) {
2535 stream->print(" # ");
2536 m->print_value_on(stream);
2537 stream->cr();
2538 }
2539 if (m.not_null() && !is_osr_method()) {
2540 ResourceMark rm;
2541 int sizeargs = m->size_of_parameters();
2542 BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, sizeargs);
2543 VMRegPair* regs = NEW_RESOURCE_ARRAY(VMRegPair, sizeargs);
2544 {
2545 int sig_index = 0;
2546 if (!m->is_static())
2547 sig_bt[sig_index++] = T_OBJECT; // 'this'
2548 for (SignatureStream ss(m->signature()); !ss.at_return_type(); ss.next()) {
2549 BasicType t = ss.type();
2550 sig_bt[sig_index++] = t;
2607 if (at_old_sp) {
2608 stream->print(" (%s of caller)", spname);
2609 did_old_sp = true;
2610 }
2611 stream->cr();
2612 sig_index += type2size[t];
2613 arg_index += 1;
2614 if (!at_this) ss.next();
2615 }
2616 if (!did_old_sp) {
2617 stream->print(" # ");
2618 stream->move_to(tab1);
2619 stream->print("[%s+0x%x]", spname, stack_slot_offset);
2620 stream->print(" (%s of caller)", spname);
2621 stream->cr();
2622 }
2623 }
2624 }
2625 }
2626
2627 void nmethod::print_code_comment_on(outputStream* st, int column, u_char* begin, u_char* end) {
2628 // First, find an oopmap in (begin, end].
2629 // We use the odd half-closed interval so that oop maps and scope descs
2630 // which are tied to the byte after a call are printed with the call itself.
2631 address base = code_begin();
2632 ImmutableOopMapSet* oms = oop_maps();
2633 if (oms != NULL) {
2634 for (int i = 0, imax = oms->count(); i < imax; i++) {
2635 const ImmutableOopMapPair* pair = oms->pair_at(i);
2636 const ImmutableOopMap* om = pair->get_from(oms);
2637 address pc = base + pair->pc_offset();
2638 if (pc > begin) {
2639 if (pc <= end) {
2640 st->move_to(column);
2641 st->print("; ");
2642 om->print_on(st);
2643 }
2644 break;
2645 }
2646 }
2647 }
2648
2649 // Print any debug info present at this pc.
2650 ScopeDesc* sd = scope_desc_in(begin, end);
2651 if (sd != NULL) {
2652 st->move_to(column);
2653 if (sd->bci() == SynchronizationEntryBCI) {
2654 st->print(";*synchronization entry");
2655 } else if (sd->bci() == AfterBci) {
2656 st->print(";* method exit (unlocked if synchronized)");
2657 } else if (sd->bci() == UnwindBci) {
2658 st->print(";* unwind (locked if synchronized)");
2659 } else if (sd->bci() == AfterExceptionBci) {
2660 st->print(";* unwind (unlocked if synchronized)");
2661 } else if (sd->bci() == UnknownBci) {
2662 st->print(";* unknown");
2663 } else if (sd->bci() == InvalidFrameStateBci) {
2664 st->print(";* invalid frame state");
2665 } else {
2666 if (sd->method() == NULL) {
2667 st->print("method is NULL");
2668 } else if (sd->method()->is_native()) {
2669 st->print("method is native");
2670 } else {
2671 Bytecodes::Code bc = sd->method()->java_code_at(sd->bci());
2672 st->print(";*%s", Bytecodes::name(bc));
2688 case Bytecodes::_putfield:
2689 case Bytecodes::_getstatic:
2690 case Bytecodes::_putstatic:
2691 {
2692 Bytecode_field field(sd->method(), sd->bci());
2693 st->print(" ");
2694 if (field.name() != NULL)
2695 field.name()->print_symbol_on(st);
2696 else
2697 st->print("<UNKNOWN>");
2698 }
2699 default:
2700 break;
2701 }
2702 }
2703 st->print(" {reexecute=%d rethrow=%d return_oop=%d}", sd->should_reexecute(), sd->rethrow_exception(), sd->return_oop());
2704 }
2705
2706 // Print all scopes
2707 for (;sd != NULL; sd = sd->sender()) {
2708 st->move_to(column);
2709 st->print("; -");
2710 if (sd->method() == NULL) {
2711 st->print("method is NULL");
2712 } else {
2713 sd->method()->print_short_name(st);
2714 }
2715 int lineno = sd->method()->line_number_from_bci(sd->bci());
2716 if (lineno != -1) {
2717 st->print("@%d (line %d)", sd->bci(), lineno);
2718 } else {
2719 st->print("@%d", sd->bci());
2720 }
2721 st->cr();
2722 }
2723 }
2724
2725 // Print relocation information
2726 const char* str = reloc_string_for(begin, end);
2727 if (str != NULL) {
2728 if (sd != NULL) st->cr();
2729 st->move_to(column);
2730 st->print("; {%s}", str);
2731 }
2732 int cont_offset = ImplicitExceptionTable(this).at(begin - code_begin());
2733 if (cont_offset != 0) {
2734 st->move_to(column);
2735 st->print("; implicit exception: dispatches to " INTPTR_FORMAT, p2i(code_begin() + cont_offset));
2736 }
2737
2738 }
2739
2740 class DirectNativeCallWrapper: public NativeCallWrapper {
2741 private:
2742 NativeCall* _call;
2743
2744 public:
2745 DirectNativeCallWrapper(NativeCall* call) : _call(call) {}
2746
2747 virtual address destination() const { return _call->destination(); }
2748 virtual address instruction_address() const { return _call->instruction_address(); }
2749 virtual address next_instruction_address() const { return _call->next_instruction_address(); }
2750 virtual address return_address() const { return _call->return_address(); }
2751
2752 virtual address get_resolve_call_stub(bool is_optimized) const {
2753 if (is_optimized) {
2754 return SharedRuntime::get_resolve_opt_virtual_call_stub();
2755 }
2756 return SharedRuntime::get_resolve_virtual_call_stub();
2757 }
2758
2759 virtual void set_destination_mt_safe(address dest) {
2826 address nmethod::call_instruction_address(address pc) const {
2827 if (NativeCall::is_call_before(pc)) {
2828 NativeCall *ncall = nativeCall_before(pc);
2829 return ncall->instruction_address();
2830 }
2831 return NULL;
2832 }
2833
2834 CompiledStaticCall* nmethod::compiledStaticCall_at(Relocation* call_site) const {
2835 return CompiledDirectStaticCall::at(call_site);
2836 }
2837
2838 CompiledStaticCall* nmethod::compiledStaticCall_at(address call_site) const {
2839 return CompiledDirectStaticCall::at(call_site);
2840 }
2841
2842 CompiledStaticCall* nmethod::compiledStaticCall_before(address return_addr) const {
2843 return CompiledDirectStaticCall::before(return_addr);
2844 }
2845
2846 #ifndef PRODUCT
2847
2848 void nmethod::print_value_on(outputStream* st) const {
2849 st->print("nmethod");
2850 print_on(st, NULL);
2851 }
2852
2853 void nmethod::print_calls(outputStream* st) {
2854 RelocIterator iter(this);
2855 while (iter.next()) {
2856 switch (iter.type()) {
2857 case relocInfo::virtual_call_type:
2858 case relocInfo::opt_virtual_call_type: {
2859 CompiledICLocker ml_verify(this);
2860 CompiledIC_at(&iter)->print();
2861 break;
2862 }
2863 case relocInfo::static_call_type:
2864 st->print_cr("Static call at " INTPTR_FORMAT, p2i(iter.reloc()->addr()));
2865 CompiledDirectStaticCall::at(iter.reloc())->print();
2866 break;
2867 default:
2868 break;
2869 }
2870 }
2871 }
2872
2873 void nmethod::print_handler_table() {
2874 ExceptionHandlerTable(this).print();
2875 }
2876
2877 void nmethod::print_nul_chk_table() {
2878 ImplicitExceptionTable(this).print(code_begin());
2879 }
2880
2881 void nmethod::print_statistics() {
2882 ttyLocker ttyl;
2883 if (xtty != NULL) xtty->head("statistics type='nmethod'");
2884 native_nmethod_stats.print_native_nmethod_stats();
2885 #ifdef COMPILER1
2886 c1_java_nmethod_stats.print_nmethod_stats("C1");
2887 #endif
2888 #ifdef COMPILER2
2889 c2_java_nmethod_stats.print_nmethod_stats("C2");
2890 #endif
2891 #if INCLUDE_JVMCI
2892 jvmci_java_nmethod_stats.print_nmethod_stats("JVMCI");
2893 #endif
2894 unknown_java_nmethod_stats.print_nmethod_stats("Unknown");
2895 DebugInformationRecorder::print_statistics();
2896 #ifndef PRODUCT
2897 pc_nmethod_stats.print_pc_stats();
2898 #endif
|
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "jvm.h"
27 #include "asm/assembler.inline.hpp"
28 #include "code/codeCache.hpp"
29 #include "code/compiledIC.hpp"
30 #include "code/compiledMethod.inline.hpp"
31 #include "code/dependencies.hpp"
32 #include "code/nativeInst.hpp"
33 #include "code/nmethod.hpp"
34 #include "code/scopeDesc.hpp"
35 #include "compiler/abstractCompiler.hpp"
36 #include "compiler/compileBroker.hpp"
37 #include "compiler/compileLog.hpp"
38 #include "compiler/compilerDirectives.hpp"
39 #include "compiler/directivesParser.hpp"
40 #include "compiler/disassembler.hpp"
41 #include "interpreter/bytecode.hpp"
42 #include "logging/log.hpp"
43 #include "logging/logStream.hpp"
44 #include "memory/allocation.inline.hpp"
45 #include "memory/resourceArea.hpp"
46 #include "memory/universe.hpp"
47 #include "oops/access.inline.hpp"
440 #if INCLUDE_RTM_OPT
441 _rtm_state = NoRTM;
442 #endif
443 }
444
445 nmethod* nmethod::new_native_nmethod(const methodHandle& method,
446 int compile_id,
447 CodeBuffer *code_buffer,
448 int vep_offset,
449 int frame_complete,
450 int frame_size,
451 ByteSize basic_lock_owner_sp_offset,
452 ByteSize basic_lock_sp_offset,
453 OopMapSet* oop_maps) {
454 code_buffer->finalize_oop_references(method);
455 // create nmethod
456 nmethod* nm = NULL;
457 {
458 MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
459 int native_nmethod_size = CodeBlob::allocation_size(code_buffer, sizeof(nmethod));
460
461 CodeOffsets offsets;
462 offsets.set_value(CodeOffsets::Verified_Entry, vep_offset);
463 offsets.set_value(CodeOffsets::Frame_Complete, frame_complete);
464 nm = new (native_nmethod_size, CompLevel_none)
465 nmethod(method(), compiler_none, native_nmethod_size,
466 compile_id, &offsets,
467 code_buffer, frame_size,
468 basic_lock_owner_sp_offset,
469 basic_lock_sp_offset,
470 oop_maps);
471 NOT_PRODUCT(if (nm != NULL) native_nmethod_stats.note_native_nmethod(nm));
472 }
473
474 if (nm != NULL) {
475 // verify nmethod
476 debug_only(nm->verify();) // might block
477
478 nm->log_new_nmethod();
479 nm->make_in_use();
480 }
481 return nm;
482 }
483
484 nmethod* nmethod::new_nmethod(const methodHandle& method,
485 int compile_id,
486 int entry_bci,
487 CodeOffsets* offsets,
488 int orig_pc_offset,
489 DebugInformationRecorder* debug_info,
490 Dependencies* dependencies,
645
646 clear_unloading_state();
647
648 Universe::heap()->register_nmethod(this);
649 debug_only(Universe::heap()->verify_nmethod(this));
650
651 CodeCache::commit(this);
652 }
653
654 if (PrintNativeNMethods || PrintDebugInfo || PrintRelocations || PrintDependencies) {
655 ttyLocker ttyl; // keep the following output all in one block
656 // This output goes directly to the tty, not the compiler log.
657 // To enable tools to match it up with the compilation activity,
658 // be sure to tag this tty output with the compile ID.
659 if (xtty != NULL) {
660 xtty->begin_head("print_native_nmethod");
661 xtty->method(_method);
662 xtty->stamp();
663 xtty->end_head(" address='" INTPTR_FORMAT "'", (intptr_t) this);
664 }
665 // Print the header part, then print the requested information.
666 // This is both handled in decode2(), called via print_code() -> decode()
667 if (PrintNativeNMethods) {
668 tty->print_cr("-------------------------- Assembly (native nmethod) ---------------------------");
669 print_code();
670 tty->print_cr("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
671 #if defined(SUPPORT_DATA_STRUCTS)
672 if (AbstractDisassembler::show_structs()) {
673 if (oop_maps != NULL) {
674 tty->print("oop maps:"); // oop_maps->print_on(tty) outputs a cr() at the beginning
675 oop_maps->print_on(tty);
676 tty->print_cr("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
677 }
678 }
679 #endif
680 } else {
681 print(); // print the header part only.
682 }
683 #if defined(SUPPORT_DATA_STRUCTS)
684 if (AbstractDisassembler::show_structs()) {
685 if (PrintRelocations) {
686 print_relocations();
687 tty->print_cr("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
688 }
689 }
690 #endif
691 if (xtty != NULL) {
692 xtty->tail("print_native_nmethod");
693 }
694 }
695 }
696
697 void* nmethod::operator new(size_t size, int nmethod_size, int comp_level) throw () {
698 return CodeCache::allocate(nmethod_size, CodeCache::get_code_blob_type(comp_level));
699 }
700
701 nmethod::nmethod(
702 Method* method,
703 CompilerType type,
704 int nmethod_size,
705 int compile_id,
706 int entry_bci,
707 CodeOffsets* offsets,
708 int orig_pc_offset,
709 DebugInformationRecorder* debug_info,
710 Dependencies* dependencies,
747 set_ctable_begin(header_begin() + _consts_offset);
748
749 #if INCLUDE_JVMCI
750 if (compiler->is_jvmci()) {
751 // JVMCI might not produce any stub sections
752 if (offsets->value(CodeOffsets::Exceptions) != -1) {
753 _exception_offset = code_offset() + offsets->value(CodeOffsets::Exceptions);
754 } else {
755 _exception_offset = -1;
756 }
757 if (offsets->value(CodeOffsets::Deopt) != -1) {
758 _deopt_handler_begin = (address) this + code_offset() + offsets->value(CodeOffsets::Deopt);
759 } else {
760 _deopt_handler_begin = NULL;
761 }
762 if (offsets->value(CodeOffsets::DeoptMH) != -1) {
763 _deopt_mh_handler_begin = (address) this + code_offset() + offsets->value(CodeOffsets::DeoptMH);
764 } else {
765 _deopt_mh_handler_begin = NULL;
766 }
767 } else
768 #endif
769 {
770 // Exception handler and deopt handler are in the stub section
771 assert(offsets->value(CodeOffsets::Exceptions) != -1, "must be set");
772 assert(offsets->value(CodeOffsets::Deopt ) != -1, "must be set");
773
774 _exception_offset = _stub_offset + offsets->value(CodeOffsets::Exceptions);
775 _deopt_handler_begin = (address) this + _stub_offset + offsets->value(CodeOffsets::Deopt);
776 if (offsets->value(CodeOffsets::DeoptMH) != -1) {
777 _deopt_mh_handler_begin = (address) this + _stub_offset + offsets->value(CodeOffsets::DeoptMH);
778 } else {
779 _deopt_mh_handler_begin = NULL;
780 }
781 }
782 if (offsets->value(CodeOffsets::UnwindHandler) != -1) {
783 _unwind_handler_offset = code_offset() + offsets->value(CodeOffsets::UnwindHandler);
784 } else {
785 _unwind_handler_offset = -1;
786 }
787
788 _oops_offset = data_offset();
789 _metadata_offset = _oops_offset + align_up(code_buffer->total_oop_size(), oopSize);
790 int scopes_data_offset = _metadata_offset + align_up(code_buffer->total_metadata_size(), wordSize);
791
792 _scopes_pcs_offset = scopes_data_offset + align_up(debug_info->data_size (), oopSize);
793 _dependencies_offset = _scopes_pcs_offset + adjust_pcs_size(debug_info->pcs_size());
794 _handler_table_offset = _dependencies_offset + align_up((int)dependencies->size_in_bytes (), oopSize);
795 _nul_chk_table_offset = _handler_table_offset + align_up(handler_table->size_in_bytes(), oopSize);
796 #if INCLUDE_JVMCI
797 _speculations_offset = _nul_chk_table_offset + align_up(nul_chk_table->size_in_bytes(), oopSize);
798 _jvmci_data_offset = _speculations_offset + align_up(speculations_len, oopSize);
799 _nmethod_end_offset = _jvmci_data_offset + align_up(jvmci_data_size, oopSize);
800 #else
801 _nmethod_end_offset = _nul_chk_table_offset + align_up(nul_chk_table->size_in_bytes(), oopSize);
802 #endif
803 _entry_point = code_begin() + offsets->value(CodeOffsets::Entry);
804 _verified_entry_point = code_begin() + offsets->value(CodeOffsets::Verified_Entry);
805 _osr_entry_point = code_begin() + offsets->value(CodeOffsets::OSR_Entry);
806 _exception_cache = NULL;
807 _scopes_data_begin = (address) this + scopes_data_offset;
808
809 _pc_desc_container.reset_to(scopes_pcs_begin());
810
811 code_buffer->copy_code_and_locs_to(this);
812 // Copy contents of ScopeDescRecorder to nmethod
813 code_buffer->copy_values_to(this);
814 debug_info->copy_to(this);
815 dependencies->copy_to(this);
816 clear_unloading_state();
817
818 Universe::heap()->register_nmethod(this);
819 debug_only(Universe::heap()->verify_nmethod(this));
820
821 CodeCache::commit(this);
822
823 // Copy contents of ExceptionHandlerTable to nmethod
824 handler_table->copy_to(this);
825 nul_chk_table->copy_to(this);
826
908 } else {
909 CompileTask::print(st, this, msg, /*short_form:*/ false);
910 }
911 }
912 }
913
914 void nmethod::maybe_print_nmethod(DirectiveSet* directive) {
915 bool printnmethods = directive->PrintAssemblyOption || directive->PrintNMethodsOption;
916 if (printnmethods || PrintDebugInfo || PrintRelocations || PrintDependencies || PrintExceptionHandlers) {
917 print_nmethod(printnmethods);
918 }
919 }
920
921 void nmethod::print_nmethod(bool printmethod) {
922 ttyLocker ttyl; // keep the following output all in one block
923 if (xtty != NULL) {
924 xtty->begin_head("print_nmethod");
925 xtty->stamp();
926 xtty->end_head();
927 }
928 // Print the header part, then print the requested information.
929 // This is both handled in decode2().
930 if (printmethod) {
931 HandleMark hm;
932 ResourceMark m;
933 if (is_compiled_by_c1()) {
934 tty->cr();
935 tty->print_cr("============================= C1-compiled nmethod ==============================");
936 }
937 if (is_compiled_by_jvmci()) {
938 tty->cr();
939 tty->print_cr("=========================== JVMCI-compiled nmethod =============================");
940 }
941 tty->print_cr("----------------------------------- Assembly -----------------------------------");
942 decode2(tty);
943 #if defined(SUPPORT_DATA_STRUCTS)
944 if (AbstractDisassembler::show_structs()) {
945 // Print the oops from the underlying CodeBlob as well.
946 tty->print_cr("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
947 print_oops(tty);
948 tty->print_cr("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
949 print_metadata(tty);
950 tty->print_cr("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
951 print_pcs();
952 tty->print_cr("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
953 if (oop_maps() != NULL) {
954 tty->print("oop maps:"); // oop_maps()->print_on(tty) outputs a cr() at the beginning
955 oop_maps()->print_on(tty);
956 tty->print_cr("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
957 }
958 }
959 #endif
960 } else {
961 print(); // print the header part only.
962 }
963
964 #if defined(SUPPORT_DATA_STRUCTS)
965 if (AbstractDisassembler::show_structs()) {
966 if (printmethod || PrintDebugInfo || CompilerOracle::has_option_string(_method, "PrintDebugInfo")) {
967 print_scopes();
968 tty->print_cr("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
969 }
970 if (printmethod || PrintRelocations || CompilerOracle::has_option_string(_method, "PrintRelocations")) {
971 print_relocations();
972 tty->print_cr("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
973 }
974 if (printmethod || PrintDependencies || CompilerOracle::has_option_string(_method, "PrintDependencies")) {
975 print_dependencies();
976 tty->print_cr("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
977 }
978 if (printmethod || PrintExceptionHandlers) {
979 print_handler_table();
980 tty->print_cr("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
981 print_nul_chk_table();
982 tty->print_cr("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
983 }
984
985 if (printmethod) {
986 print_recorded_oops();
987 tty->print_cr("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
988 print_recorded_metadata();
989 tty->print_cr("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
990 }
991 }
992 #endif
993
994 if (xtty != NULL) {
995 xtty->tail("print_nmethod");
996 }
997 }
998
999
1000 // Promote one word from an assembly-time handle to a live embedded oop.
1001 inline void nmethod::initialize_immediate_oop(oop* dest, jobject handle) {
1002 if (handle == NULL ||
1003 // As a special case, IC oops are initialized to 1 or -1.
1004 handle == (jobject) Universe::non_oop_word()) {
1005 (*dest) = (oop) handle;
1006 } else {
1007 (*dest) = JNIHandles::resolve_non_null(handle);
1008 }
1009 }
1010
1011
1012 // Have to have the same name because it's called by a template
1013 void nmethod::copy_values(GrowableArray<jobject>* array) {
2101 }
2102 return true;
2103 }
2104
2105
2106 address nmethod::continuation_for_implicit_exception(address pc) {
2107 // Exception happened outside inline-cache check code => we are inside
2108 // an active nmethod => use cpc to determine a return address
2109 int exception_offset = pc - code_begin();
2110 int cont_offset = ImplicitExceptionTable(this).at( exception_offset );
2111 #ifdef ASSERT
2112 if (cont_offset == 0) {
2113 Thread* thread = Thread::current();
2114 ResetNoHandleMark rnm; // Might be called from LEAF/QUICK ENTRY
2115 HandleMark hm(thread);
2116 ResourceMark rm(thread);
2117 CodeBlob* cb = CodeCache::find_blob(pc);
2118 assert(cb != NULL && cb == this, "");
2119 ttyLocker ttyl;
2120 tty->print_cr("implicit exception happened at " INTPTR_FORMAT, p2i(pc));
2121 // Print all available nmethod info.
2122 print_nmethod(true);
2123 method()->print_codes();
2124 }
2125 #endif
2126 if (cont_offset == 0) {
2127 // Let the normal error handling report the exception
2128 return NULL;
2129 }
2130 return code_begin() + cont_offset;
2131 }
2132
2133
2134 void nmethod_init() {
2135 // make sure you didn't forget to adjust the filler fields
2136 assert(sizeof(nmethod) % oopSize == 0, "nmethod size must be multiple of a word");
2137 }
2138
2139
2140 //-------------------------------------------------------------------------------------------
2141
2142
2143 // QQQ might we make this work from a frame??
2144 nmethodLocker::nmethodLocker(address pc) {
2145 CodeBlob* cb = CodeCache::find_blob(pc);
2146 guarantee(cb != NULL && cb->is_compiled(), "bad pc for a nmethod found");
2147 _nm = cb->as_compiled_method();
2148 lock_nmethod(_nm);
2149 }
2150
2151 // Only JvmtiDeferredEvent::compiled_method_unload_event()
2152 // should pass zombie_ok == true.
2153 void nmethodLocker::lock_nmethod(CompiledMethod* cm, bool zombie_ok) {
2161 void nmethodLocker::unlock_nmethod(CompiledMethod* cm) {
2162 if (cm == NULL) return;
2163 if (cm->is_aot()) return; // FIXME: Revisit once _lock_count is added to aot_method
2164 nmethod* nm = cm->as_nmethod();
2165 Atomic::dec(&nm->_lock_count);
2166 assert(nm->_lock_count >= 0, "unmatched nmethod lock/unlock");
2167 }
2168
2169
2170 // -----------------------------------------------------------------------------
2171 // Verification
2172
2173 class VerifyOopsClosure: public OopClosure {
2174 nmethod* _nm;
2175 bool _ok;
2176 public:
2177 VerifyOopsClosure(nmethod* nm) : _nm(nm), _ok(true) { }
2178 bool ok() { return _ok; }
2179 virtual void do_oop(oop* p) {
2180 if (oopDesc::is_oop_or_null(*p)) return;
2181 // Print diagnostic information before calling print_nmethod().
2182 // Assertions therein might prevent call from returning.
2183 tty->print_cr("*** non-oop " PTR_FORMAT " found at " PTR_FORMAT " (offset %d)",
2184 p2i(*p), p2i(p), (int)((intptr_t)p - (intptr_t)_nm));
2185 if (_ok) {
2186 _nm->print_nmethod(true);
2187 _ok = false;
2188 }
2189 }
2190 virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); }
2191 };
2192
2193 void nmethod::verify() {
2194
2195 // Hmm. OSR methods can be deopted but not marked as zombie or not_entrant
2196 // seems odd.
2197
2198 if (is_zombie() || is_not_entrant() || is_unloaded())
2199 return;
2200
2201 // Make sure all the entry points are correctly aligned for patching.
2202 NativeJump::check_verified_entry_alignment(entry_point(), verified_entry_point());
2203
2204 // assert(oopDesc::is_oop(method()), "must be valid");
2205
2206 ResourceMark rm;
2207
2208 if (!CodeCache::contains(this)) {
2277 case relocInfo::runtime_call_type:
2278 case relocInfo::runtime_call_w_cp_type: {
2279 address destination = iter.reloc()->value();
2280 // Right now there is no way to find out which entries support
2281 // an interrupt point. It would be nice if we had this
2282 // information in a table.
2283 break;
2284 }
2285 default:
2286 break;
2287 }
2288 assert(stub == NULL || stub_contains(stub), "static call stub outside stub section");
2289 }
2290 }
2291
2292
2293 // -----------------------------------------------------------------------------
2294 // Printing operations
2295
2296 void nmethod::print() const {
2297 ttyLocker ttyl; // keep the following output all in one block
2298 print(tty);
2299 }
2300
2301 void nmethod::print(outputStream* st) const {
2302 ResourceMark rm;
2303
2304 st->print("Compiled method ");
2305
2306 if (is_compiled_by_c1()) {
2307 st->print("(c1) ");
2308 } else if (is_compiled_by_c2()) {
2309 st->print("(c2) ");
2310 } else if (is_compiled_by_jvmci()) {
2311 st->print("(JVMCI) ");
2312 } else {
2313 st->print("(n/a) ");
2314 }
2315
2316 print_on(tty, NULL);
2317
2318 if (WizardMode) {
2319 st->print("((nmethod*) " INTPTR_FORMAT ") ", p2i(this));
2320 st->print(" for method " INTPTR_FORMAT , p2i(method()));
2321 st->print(" { ");
2322 st->print_cr("%s ", state());
2323 st->print_cr("}:");
2324 }
2325 if (size () > 0) st->print_cr(" total in heap [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2326 p2i(this),
2327 p2i(this) + size(),
2328 size());
2329 if (relocation_size () > 0) st->print_cr(" relocation [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2330 p2i(relocation_begin()),
2331 p2i(relocation_end()),
2332 relocation_size());
2333 if (consts_size () > 0) st->print_cr(" constants [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2334 p2i(consts_begin()),
2335 p2i(consts_end()),
2336 consts_size());
2337 if (insts_size () > 0) st->print_cr(" main code [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2338 p2i(insts_begin()),
2339 p2i(insts_end()),
2340 insts_size());
2341 if (stub_size () > 0) st->print_cr(" stub code [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2342 p2i(stub_begin()),
2343 p2i(stub_end()),
2344 stub_size());
2345 if (oops_size () > 0) st->print_cr(" oops [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2346 p2i(oops_begin()),
2347 p2i(oops_end()),
2348 oops_size());
2349 if (metadata_size () > 0) st->print_cr(" metadata [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2350 p2i(metadata_begin()),
2351 p2i(metadata_end()),
2352 metadata_size());
2353 if (scopes_data_size () > 0) st->print_cr(" scopes data [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2354 p2i(scopes_data_begin()),
2355 p2i(scopes_data_end()),
2356 scopes_data_size());
2357 if (scopes_pcs_size () > 0) st->print_cr(" scopes pcs [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2358 p2i(scopes_pcs_begin()),
2359 p2i(scopes_pcs_end()),
2360 scopes_pcs_size());
2361 if (dependencies_size () > 0) st->print_cr(" dependencies [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2362 p2i(dependencies_begin()),
2363 p2i(dependencies_end()),
2364 dependencies_size());
2365 if (handler_table_size() > 0) st->print_cr(" handler table [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2366 p2i(handler_table_begin()),
2367 p2i(handler_table_end()),
2368 handler_table_size());
2369 if (nul_chk_table_size() > 0) st->print_cr(" nul chk table [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2370 p2i(nul_chk_table_begin()),
2371 p2i(nul_chk_table_end()),
2372 nul_chk_table_size());
2373 #if INCLUDE_JVMCI
2374 if (speculations_size () > 0) st->print_cr(" speculations [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2375 p2i(speculations_begin()),
2376 p2i(speculations_end()),
2377 speculations_size());
2378 if (jvmci_data_size () > 0) st->print_cr(" JVMCI data [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
2379 p2i(jvmci_data_begin()),
2380 p2i(jvmci_data_end()),
2381 jvmci_data_size());
2382 #endif
2383 }
2384
2385 void nmethod::print_code() {
2386 HandleMark hm;
2387 ResourceMark m;
2388 ttyLocker ttyl;
2389 // Call the specialized decode method of this class.
2390 decode(tty);
2391 }
2392
2393 #ifndef PRODUCT // called InstanceKlass methods are available only then. Declared as PRODUCT_RETURN
2394
2395 void nmethod::print_dependencies() {
2396 ResourceMark rm;
2397 ttyLocker ttyl; // keep the following output all in one block
2398 tty->print_cr("Dependencies:");
2399 for (Dependencies::DepStream deps(this); deps.next(); ) {
2400 deps.print_dependency();
2401 Klass* ctxk = deps.context_type();
2402 if (ctxk != NULL) {
2403 if (ctxk->is_instance_klass() && InstanceKlass::cast(ctxk)->is_dependent_nmethod(this)) {
2404 tty->print_cr(" [nmethod<=klass]%s", ctxk->external_name());
2405 }
2406 }
2407 deps.log_dependency(); // put it into the xml log also
2408 }
2409 }
2410 #endif
2411
2412 #if defined(SUPPORT_DATA_STRUCTS)
2413
2414 // Print the oops from the underlying CodeBlob.
2415 void nmethod::print_oops(outputStream* st) {
2416 HandleMark hm;
2417 ResourceMark m;
2418 st->print("Oops:");
2419 if (oops_begin() < oops_end()) {
2420 st->cr();
2421 for (oop* p = oops_begin(); p < oops_end(); p++) {
2422 Disassembler::print_location((unsigned char*)p, (unsigned char*)oops_begin(), (unsigned char*)oops_end(), st, true, false);
2423 st->print(PTR_FORMAT " ", *((uintptr_t*)p));
2424 if (*p == Universe::non_oop_word()) {
2425 st->print_cr("NON_OOP");
2426 continue; // skip non-oops
2427 }
2428 if (*p == NULL) {
2429 st->print_cr("NULL-oop");
2430 continue; // skip non-oops
2431 }
2432 (*p)->print_value_on(st);
2433 st->cr();
2434 }
2435 } else {
2436 st->print_cr(" <list empty>");
2437 }
2438 }
2439
2440 // Print metadata pool.
2441 void nmethod::print_metadata(outputStream* st) {
2442 HandleMark hm;
2443 ResourceMark m;
2444 st->print("Metadata:");
2445 if (metadata_begin() < metadata_end()) {
2446 st->cr();
2447 for (Metadata** p = metadata_begin(); p < metadata_end(); p++) {
2448 Disassembler::print_location((unsigned char*)p, (unsigned char*)metadata_begin(), (unsigned char*)metadata_end(), st, true, false);
2449 st->print(PTR_FORMAT " ", *((uintptr_t*)p));
2450 if (*p && *p != Universe::non_oop_word()) {
2451 (*p)->print_value_on(st);
2452 }
2453 st->cr();
2454 }
2455 } else {
2456 st->print_cr(" <list empty>");
2457 }
2458 }
2459
2460 #ifndef PRODUCT // ScopeDesc::print_on() is available only then. Declared as PRODUCT_RETURN
2461 void nmethod::print_scopes_on(outputStream* st) {
2462 // Find the first pc desc for all scopes in the code and print it.
2463 ResourceMark rm;
2464 st->print("scopes:");
2465 if (scopes_pcs_begin() < scopes_pcs_end()) {
2466 st->cr();
2467 for (PcDesc* p = scopes_pcs_begin(); p < scopes_pcs_end(); p++) {
2468 if (p->scope_decode_offset() == DebugInformationRecorder::serialized_null)
2469 continue;
2470
2471 ScopeDesc* sd = scope_desc_at(p->real_pc(this));
2472 while (sd != NULL) {
2473 sd->print_on(st, p); // print output ends with a newline
2474 sd = sd->sender();
2475 }
2476 }
2477 } else {
2478 st->print_cr(" <list empty>");
2479 }
2480 }
2481 #endif
2482
2483 #ifndef PRODUCT // RelocIterator does support printing only then.
2484 void nmethod::print_relocations() {
2485 ResourceMark m; // in case methods get printed via the debugger
2486 tty->print_cr("relocations:");
2487 RelocIterator iter(this);
2488 iter.print();
2489 }
2490 #endif
2491
2492 void nmethod::print_pcs_on(outputStream* st) {
2493 ResourceMark m; // in case methods get printed via debugger
2494 st->print("pc-bytecode offsets:");
2495 if (scopes_pcs_begin() < scopes_pcs_end()) {
2496 st->cr();
2497 for (PcDesc* p = scopes_pcs_begin(); p < scopes_pcs_end(); p++) {
2498 p->print_on(st, this); // print output ends with a newline
2499 }
2500 } else {
2501 st->print_cr(" <list empty>");
2502 }
2503 }
2504
2505 void nmethod::print_handler_table() {
2506 ExceptionHandlerTable(this).print();
2507 }
2508
2509 void nmethod::print_nul_chk_table() {
2510 ImplicitExceptionTable(this).print(code_begin());
2511 }
2512
2513 void nmethod::print_recorded_oops() {
2514 const int n = oops_count();
2515 const int log_n = (n<10) ? 1 : (n<100) ? 2 : (n<1000) ? 3 : (n<10000) ? 4 : 6;
2516 tty->print("Recorded oops:");
2517 if (n > 0) {
2518 tty->cr();
2519 for (int i = 0; i < n; i++) {
2520 oop o = oop_at(i);
2521 tty->print("#%*d: " INTPTR_FORMAT " ", log_n, i, p2i(o));
2522 if (o == (oop)Universe::non_oop_word()) {
2523 tty->print("non-oop word");
2524 } else if (o == NULL) {
2525 tty->print("NULL-oop");
2526 } else {
2527 o->print_value_on(tty);
2528 }
2529 tty->cr();
2530 }
2531 } else {
2532 tty->print_cr(" <list empty>");
2533 }
2534 }
2535
2536 void nmethod::print_recorded_metadata() {
2537 const int n = metadata_count();
2538 const int log_n = (n<10) ? 1 : (n<100) ? 2 : (n<1000) ? 3 : (n<10000) ? 4 : 6;
2539 tty->print("Recorded metadata:");
2540 if (n > 0) {
2541 tty->cr();
2542 for (int i = 0; i < n; i++) {
2543 Metadata* m = metadata_at(i);
2544 tty->print("#%*d: " INTPTR_FORMAT " ", log_n, i, p2i(m));
2545 if (m == (Metadata*)Universe::non_oop_word()) {
2546 tty->print("non-metadata word");
2547 } else if (m == NULL) {
2548 tty->print("NULL-oop");
2549 } else {
2550 Metadata::print_value_on_maybe_null(tty, m);
2551 }
2552 tty->cr();
2553 }
2554 } else {
2555 tty->print_cr(" <list empty>");
2556 }
2557 }
2558 #endif
2559
2560 #if defined(SUPPORT_ASSEMBLY) || defined(SUPPORT_ABSTRACT_ASSEMBLY)
2561
2562 void nmethod::print_constant_pool(outputStream* st) {
2563 //-----------------------------------
2564 //---< Print the constant pool >---
2565 //-----------------------------------
2566 int consts_size = this->consts_size();
2567 if ( consts_size > 0 ) {
2568 unsigned char* cstart = this->consts_begin();
2569 unsigned char* cp = cstart;
2570 unsigned char* cend = cp + consts_size;
2571 unsigned int bytes_per_line = 4;
2572 unsigned int CP_alignment = 8;
2573 unsigned int n;
2574
2575 st->cr();
2576
2577 //---< print CP header to make clear what's printed >---
2578 if( ((uintptr_t)cp&(CP_alignment-1)) == 0 ) {
2579 n = bytes_per_line;
2580 st->print_cr("[Constant Pool]");
2581 Disassembler::print_location(cp, cstart, cend, st, true, true);
2582 Disassembler::print_hexdata(cp, n, st, true);
2583 st->cr();
2584 } else {
2585 n = (uintptr_t)cp&(bytes_per_line-1);
2586 st->print_cr("[Constant Pool (unaligned)]");
2587 }
2588
2589 //---< print CP contents, bytes_per_line at a time >---
2590 while (cp < cend) {
2591 Disassembler::print_location(cp, cstart, cend, st, true, false);
2592 Disassembler::print_hexdata(cp, n, st, false);
2593 cp += n;
2594 n = bytes_per_line;
2595 st->cr();
2596 }
2597
2598 //---< Show potential alignment gap between constant pool and code >---
2599 cend = code_begin();
2600 if( cp < cend ) {
2601 n = 4;
2602 st->print_cr("[Code entry alignment]");
2603 while (cp < cend) {
2604 Disassembler::print_location(cp, cstart, cend, st, false, false);
2605 cp += n;
2606 st->cr();
2607 }
2608 }
2609 } else {
2610 st->print_cr("[Constant Pool (empty)]");
2611 }
2612 st->cr();
2613 }
2614
2615 #endif
2616
2617 // Disassemble this nmethod.
2618 // Print additional debug information, if requested. This could be code
2619 // comments, block comments, profiling counters, etc.
2620 // The undisassembled format is useful no disassembler library is available.
2621 // The resulting hex dump (with markers) can be disassembled later, or on
2622 // another system, when/where a disassembler library is available.
2623 void nmethod::decode2(outputStream* ost) const {
2624
2625 // Called from frame::back_trace_with_decode without ResourceMark.
2626 ResourceMark rm;
2627
2628 // Make sure we have a valid stream to print on.
2629 outputStream* st = ost ? ost : tty;
2630
2631 #if defined(SUPPORT_ABSTRACT_ASSEMBLY) && ! defined(SUPPORT_ASSEMBLY)
2632 const bool use_compressed_format = true;
2633 const bool compressed_with_comments = use_compressed_format && (AbstractDisassembler::show_comment() ||
2634 AbstractDisassembler::show_block_comment());
2635 #else
2636 const bool use_compressed_format = Disassembler::is_abstract();
2637 const bool compressed_with_comments = use_compressed_format && (AbstractDisassembler::show_comment() ||
2638 AbstractDisassembler::show_block_comment());
2639 #endif
2640
2641 st->cr();
2642 this->print(st);
2643 st->cr();
2644
2645 #if defined(SUPPORT_ASSEMBLY)
2646 //----------------------------------
2647 //---< Print real disassembly >---
2648 //----------------------------------
2649 if (! use_compressed_format) {
2650 Disassembler::decode(const_cast<nmethod*>(this), st);
2651 return;
2652 }
2653 #endif
2654
2655 #if defined(SUPPORT_ABSTRACT_ASSEMBLY)
2656
2657 // Compressed undisassembled disassembly format.
2658 // The following stati are defined/supported:
2659 // = 0 - currently at bol() position, nothing printed yet on current line.
2660 // = 1 - currently at position after print_location().
2661 // > 1 - in the midst of printing instruction stream bytes.
2662 int compressed_format_idx = 0;
2663 int code_comment_column = 0;
2664 const int instr_maxlen = Assembler::instr_maxlen();
2665 const uint tabspacing = 8;
2666 unsigned char* start = this->code_begin();
2667 unsigned char* p = this->code_begin();
2668 unsigned char* end = this->code_end();
2669 unsigned char* pss = p; // start of a code section (used for offsets)
2670
2671 if ((start == NULL) || (end == NULL)) {
2672 st->print_cr("PrintAssembly not possible due to uninitialized section pointers");
2673 return;
2674 }
2675 #endif
2676
2677 #if defined(SUPPORT_ABSTRACT_ASSEMBLY)
2678 //---< plain abstract disassembly, no comments or anything, just section headers >---
2679 if (use_compressed_format && ! compressed_with_comments) {
2680 const_cast<nmethod*>(this)->print_constant_pool(st);
2681
2682 //---< Open the output (Marker for post-mortem disassembler) >---
2683 st->print_cr("[MachCode]");
2684 const char* header = NULL;
2685 address p0 = p;
2686 while (p < end) {
2687 address pp = p;
2688 while ((p < end) && (header == NULL)) {
2689 header = nmethod_section_label(p);
2690 pp = p;
2691 p += Assembler::instr_len(p);
2692 }
2693 if (pp > p0) {
2694 AbstractDisassembler::decode_range_abstract(p0, pp, start, end, st, Assembler::instr_maxlen());
2695 p0 = pp;
2696 p = pp;
2697 header = NULL;
2698 } else if (header != NULL) {
2699 st->bol();
2700 st->print_cr("%s", header);
2701 header = NULL;
2702 }
2703 }
2704 //---< Close the output (Marker for post-mortem disassembler) >---
2705 st->bol();
2706 st->print_cr("[/MachCode]");
2707 return;
2708 }
2709 #endif
2710
2711 #if defined(SUPPORT_ABSTRACT_ASSEMBLY)
2712 //---< abstract disassembly with comments and section headers merged in >---
2713 if (compressed_with_comments) {
2714 const_cast<nmethod*>(this)->print_constant_pool(st);
2715
2716 //---< Open the output (Marker for post-mortem disassembler) >---
2717 st->print_cr("[MachCode]");
2718 while ((p < end) && (p != NULL)) {
2719 const int instruction_size_in_bytes = Assembler::instr_len(p);
2720
2721 //---< Block comments for nmethod. Interrupts instruction stream, if any. >---
2722 // Outputs a bol() before and a cr() after, but only if a comment is printed.
2723 // Prints nmethod_section_label as well.
2724 if (AbstractDisassembler::show_block_comment()) {
2725 print_block_comment(st, p);
2726 if (st->position() == 0) {
2727 compressed_format_idx = 0;
2728 }
2729 }
2730
2731 //---< New location information after line break >---
2732 if (compressed_format_idx == 0) {
2733 code_comment_column = Disassembler::print_location(p, pss, end, st, false, false);
2734 compressed_format_idx = 1;
2735 }
2736
2737 //---< Code comment for current instruction. Address range [p..(p+len)) >---
2738 unsigned char* p_end = p + (ssize_t)instruction_size_in_bytes;
2739 S390_ONLY(if (p_end > end) p_end = end;) // avoid getting past the end
2740
2741 if (AbstractDisassembler::show_comment() && const_cast<nmethod*>(this)->has_code_comment(p, p_end)) {
2742 //---< interrupt instruction byte stream for code comment >---
2743 if (compressed_format_idx > 1) {
2744 st->cr(); // interrupt byte stream
2745 st->cr(); // add an empty line
2746 code_comment_column = Disassembler::print_location(p, pss, end, st, false, false);
2747 }
2748 const_cast<nmethod*>(this)->print_code_comment_on(st, code_comment_column, p, p_end );
2749 st->bol();
2750 compressed_format_idx = 0;
2751 }
2752
2753 //---< New location information after line break >---
2754 if (compressed_format_idx == 0) {
2755 code_comment_column = Disassembler::print_location(p, pss, end, st, false, false);
2756 compressed_format_idx = 1;
2757 }
2758
2759 //---< Nicely align instructions for readability >---
2760 if (compressed_format_idx > 1) {
2761 Disassembler::print_delimiter(st);
2762 }
2763
2764 //---< Now, finally, print the actual instruction bytes >---
2765 unsigned char* p0 = p;
2766 p = Disassembler::decode_instruction_abstract(p, st, instruction_size_in_bytes, instr_maxlen);
2767 compressed_format_idx += p - p0;
2768
2769 if (Disassembler::start_newline(compressed_format_idx-1)) {
2770 st->cr();
2771 compressed_format_idx = 0;
2772 }
2773 }
2774 //---< Close the output (Marker for post-mortem disassembler) >---
2775 st->bol();
2776 st->print_cr("[/MachCode]");
2777 return;
2778 }
2779 #endif
2780 }
2781
2782 #if defined(SUPPORT_ASSEMBLY) || defined(SUPPORT_ABSTRACT_ASSEMBLY)
2783
2784 const char* nmethod::reloc_string_for(u_char* begin, u_char* end) {
2785 RelocIterator iter(this, begin, end);
2786 bool have_one = false;
2787 while (iter.next()) {
2788 have_one = true;
2789 switch (iter.type()) {
2790 case relocInfo::none: return "no_reloc";
2791 case relocInfo::oop_type: {
2792 // Get a non-resizable resource-allocated stringStream.
2793 // Our callees make use of (nested) ResourceMarks.
2794 stringStream st(NEW_RESOURCE_ARRAY(char, 1024), 1024);
2795 oop_Relocation* r = iter.oop_reloc();
2796 oop obj = r->oop_value();
2797 st.print("oop(");
2798 if (obj == NULL) st.print("NULL");
2799 else obj->print_value_on(&st);
2800 st.print(")");
2801 return st.as_string();
2802 }
2803 case relocInfo::metadata_type: {
2804 stringStream st;
2805 metadata_Relocation* r = iter.metadata_reloc();
2806 Metadata* obj = r->metadata_value();
2807 st.print("metadata(");
2808 if (obj == NULL) st.print("NULL");
2809 else obj->print_value_on(&st);
2810 st.print(")");
2811 return st.as_string();
2812 }
2813 case relocInfo::runtime_call_type:
2814 case relocInfo::runtime_call_w_cp_type: {
2876 case relocInfo::type_mask: return "type_bit_mask";
2877
2878 default:
2879 break;
2880 }
2881 }
2882 return have_one ? "other" : NULL;
2883 }
2884
2885 // Return a the last scope in (begin..end]
2886 ScopeDesc* nmethod::scope_desc_in(address begin, address end) {
2887 PcDesc* p = pc_desc_near(begin+1);
2888 if (p != NULL && p->real_pc(this) <= end) {
2889 return new ScopeDesc(this, p->scope_decode_offset(),
2890 p->obj_decode_offset(), p->should_reexecute(), p->rethrow_exception(),
2891 p->return_oop());
2892 }
2893 return NULL;
2894 }
2895
2896 const char* nmethod::nmethod_section_label(address pos) const {
2897 const char* label = NULL;
2898 if (pos == code_begin()) label = "[Instructions begin]";
2899 if (pos == entry_point()) label = "[Entry Point]";
2900 if (pos == verified_entry_point()) label = "[Verified Entry Point]";
2901 if (has_method_handle_invokes() && (pos == deopt_mh_handler_begin())) label = "[Deopt MH Handler Code]";
2902 if (pos == consts_begin() && pos != insts_begin()) label = "[Constants]";
2903 // Check stub_code before checking exception_handler or deopt_handler.
2904 if (pos == this->stub_begin()) label = "[Stub Code]";
2905 if (JVMCI_ONLY(_exception_offset >= 0 &&) pos == exception_begin()) label = "[Exception Handler]";
2906 if (JVMCI_ONLY(_deopt_handler_begin != NULL &&) pos == deopt_handler_begin()) label = "[Deopt Handler Code]";
2907 return label;
2908 }
2909
2910 void nmethod::print_nmethod_labels(outputStream* stream, address block_begin, bool print_section_labels) const {
2911 if (print_section_labels) {
2912 const char* label = nmethod_section_label(block_begin);
2913 if (label != NULL) {
2914 stream->bol();
2915 stream->print_cr("%s", label);
2916 }
2917 }
2918
2919 if (block_begin == entry_point()) {
2920 methodHandle m = method();
2921 if (m.not_null()) {
2922 stream->print(" # ");
2923 m->print_value_on(stream);
2924 stream->cr();
2925 }
2926 if (m.not_null() && !is_osr_method()) {
2927 ResourceMark rm;
2928 int sizeargs = m->size_of_parameters();
2929 BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, sizeargs);
2930 VMRegPair* regs = NEW_RESOURCE_ARRAY(VMRegPair, sizeargs);
2931 {
2932 int sig_index = 0;
2933 if (!m->is_static())
2934 sig_bt[sig_index++] = T_OBJECT; // 'this'
2935 for (SignatureStream ss(m->signature()); !ss.at_return_type(); ss.next()) {
2936 BasicType t = ss.type();
2937 sig_bt[sig_index++] = t;
2994 if (at_old_sp) {
2995 stream->print(" (%s of caller)", spname);
2996 did_old_sp = true;
2997 }
2998 stream->cr();
2999 sig_index += type2size[t];
3000 arg_index += 1;
3001 if (!at_this) ss.next();
3002 }
3003 if (!did_old_sp) {
3004 stream->print(" # ");
3005 stream->move_to(tab1);
3006 stream->print("[%s+0x%x]", spname, stack_slot_offset);
3007 stream->print(" (%s of caller)", spname);
3008 stream->cr();
3009 }
3010 }
3011 }
3012 }
3013
3014 // Returns whether this nmethod has code comments.
3015 bool nmethod::has_code_comment(address begin, address end) {
3016 // scopes?
3017 ScopeDesc* sd = scope_desc_in(begin, end);
3018 if (sd != NULL) return true;
3019
3020 // relocations?
3021 const char* str = reloc_string_for(begin, end);
3022 if (str != NULL) return true;
3023
3024 // implicit exceptions?
3025 int cont_offset = ImplicitExceptionTable(this).at(begin - code_begin());
3026 if (cont_offset != 0) return true;
3027
3028 return false;
3029 }
3030
3031 void nmethod::print_code_comment_on(outputStream* st, int column, address begin, address end) {
3032 // First, find an oopmap in (begin, end].
3033 // We use the odd half-closed interval so that oop maps and scope descs
3034 // which are tied to the byte after a call are printed with the call itself.
3035 address base = code_begin();
3036 ImmutableOopMapSet* oms = oop_maps();
3037 if (oms != NULL) {
3038 for (int i = 0, imax = oms->count(); i < imax; i++) {
3039 const ImmutableOopMapPair* pair = oms->pair_at(i);
3040 const ImmutableOopMap* om = pair->get_from(oms);
3041 address pc = base + pair->pc_offset();
3042 if (pc > begin) {
3043 if (pc <= end) {
3044 st->move_to(column, 6, 0);
3045 st->print("; ");
3046 om->print_on(st);
3047 }
3048 break;
3049 }
3050 }
3051 }
3052
3053 // Print any debug info present at this pc.
3054 ScopeDesc* sd = scope_desc_in(begin, end);
3055 if (sd != NULL) {
3056 st->move_to(column, 6, 0);
3057 if (sd->bci() == SynchronizationEntryBCI) {
3058 st->print(";*synchronization entry");
3059 } else if (sd->bci() == AfterBci) {
3060 st->print(";* method exit (unlocked if synchronized)");
3061 } else if (sd->bci() == UnwindBci) {
3062 st->print(";* unwind (locked if synchronized)");
3063 } else if (sd->bci() == AfterExceptionBci) {
3064 st->print(";* unwind (unlocked if synchronized)");
3065 } else if (sd->bci() == UnknownBci) {
3066 st->print(";* unknown");
3067 } else if (sd->bci() == InvalidFrameStateBci) {
3068 st->print(";* invalid frame state");
3069 } else {
3070 if (sd->method() == NULL) {
3071 st->print("method is NULL");
3072 } else if (sd->method()->is_native()) {
3073 st->print("method is native");
3074 } else {
3075 Bytecodes::Code bc = sd->method()->java_code_at(sd->bci());
3076 st->print(";*%s", Bytecodes::name(bc));
3092 case Bytecodes::_putfield:
3093 case Bytecodes::_getstatic:
3094 case Bytecodes::_putstatic:
3095 {
3096 Bytecode_field field(sd->method(), sd->bci());
3097 st->print(" ");
3098 if (field.name() != NULL)
3099 field.name()->print_symbol_on(st);
3100 else
3101 st->print("<UNKNOWN>");
3102 }
3103 default:
3104 break;
3105 }
3106 }
3107 st->print(" {reexecute=%d rethrow=%d return_oop=%d}", sd->should_reexecute(), sd->rethrow_exception(), sd->return_oop());
3108 }
3109
3110 // Print all scopes
3111 for (;sd != NULL; sd = sd->sender()) {
3112 st->move_to(column, 6, 0);
3113 st->print("; -");
3114 if (sd->should_reexecute()) {
3115 st->print(" (reexecute)");
3116 }
3117 if (sd->method() == NULL) {
3118 st->print("method is NULL");
3119 } else {
3120 sd->method()->print_short_name(st);
3121 }
3122 int lineno = sd->method()->line_number_from_bci(sd->bci());
3123 if (lineno != -1) {
3124 st->print("@%d (line %d)", sd->bci(), lineno);
3125 } else {
3126 st->print("@%d", sd->bci());
3127 }
3128 st->cr();
3129 }
3130 }
3131
3132 // Print relocation information
3133 // Prevent memory leak: allocating without ResourceMark.
3134 ResourceMark rm;
3135 const char* str = reloc_string_for(begin, end);
3136 if (str != NULL) {
3137 if (sd != NULL) st->cr();
3138 st->move_to(column, 6, 0);
3139 st->print("; {%s}", str);
3140 }
3141 int cont_offset = ImplicitExceptionTable(this).at(begin - code_begin());
3142 if (cont_offset != 0) {
3143 st->move_to(column, 6, 0);
3144 st->print("; implicit exception: dispatches to " INTPTR_FORMAT, p2i(code_begin() + cont_offset));
3145 }
3146
3147 }
3148
3149 #endif
3150
3151 class DirectNativeCallWrapper: public NativeCallWrapper {
3152 private:
3153 NativeCall* _call;
3154
3155 public:
3156 DirectNativeCallWrapper(NativeCall* call) : _call(call) {}
3157
3158 virtual address destination() const { return _call->destination(); }
3159 virtual address instruction_address() const { return _call->instruction_address(); }
3160 virtual address next_instruction_address() const { return _call->next_instruction_address(); }
3161 virtual address return_address() const { return _call->return_address(); }
3162
3163 virtual address get_resolve_call_stub(bool is_optimized) const {
3164 if (is_optimized) {
3165 return SharedRuntime::get_resolve_opt_virtual_call_stub();
3166 }
3167 return SharedRuntime::get_resolve_virtual_call_stub();
3168 }
3169
3170 virtual void set_destination_mt_safe(address dest) {
3237 address nmethod::call_instruction_address(address pc) const {
3238 if (NativeCall::is_call_before(pc)) {
3239 NativeCall *ncall = nativeCall_before(pc);
3240 return ncall->instruction_address();
3241 }
3242 return NULL;
3243 }
3244
3245 CompiledStaticCall* nmethod::compiledStaticCall_at(Relocation* call_site) const {
3246 return CompiledDirectStaticCall::at(call_site);
3247 }
3248
3249 CompiledStaticCall* nmethod::compiledStaticCall_at(address call_site) const {
3250 return CompiledDirectStaticCall::at(call_site);
3251 }
3252
3253 CompiledStaticCall* nmethod::compiledStaticCall_before(address return_addr) const {
3254 return CompiledDirectStaticCall::before(return_addr);
3255 }
3256
3257 #if defined(SUPPORT_DATA_STRUCTS)
3258 void nmethod::print_value_on(outputStream* st) const {
3259 st->print("nmethod");
3260 print_on(st, NULL);
3261 }
3262 #endif
3263
3264 #ifndef PRODUCT
3265
3266 void nmethod::print_calls(outputStream* st) {
3267 RelocIterator iter(this);
3268 while (iter.next()) {
3269 switch (iter.type()) {
3270 case relocInfo::virtual_call_type:
3271 case relocInfo::opt_virtual_call_type: {
3272 CompiledICLocker ml_verify(this);
3273 CompiledIC_at(&iter)->print();
3274 break;
3275 }
3276 case relocInfo::static_call_type:
3277 st->print_cr("Static call at " INTPTR_FORMAT, p2i(iter.reloc()->addr()));
3278 CompiledDirectStaticCall::at(iter.reloc())->print();
3279 break;
3280 default:
3281 break;
3282 }
3283 }
3284 }
3285
3286 void nmethod::print_statistics() {
3287 ttyLocker ttyl;
3288 if (xtty != NULL) xtty->head("statistics type='nmethod'");
3289 native_nmethod_stats.print_native_nmethod_stats();
3290 #ifdef COMPILER1
3291 c1_java_nmethod_stats.print_nmethod_stats("C1");
3292 #endif
3293 #ifdef COMPILER2
3294 c2_java_nmethod_stats.print_nmethod_stats("C2");
3295 #endif
3296 #if INCLUDE_JVMCI
3297 jvmci_java_nmethod_stats.print_nmethod_stats("JVMCI");
3298 #endif
3299 unknown_java_nmethod_stats.print_nmethod_stats("Unknown");
3300 DebugInformationRecorder::print_statistics();
3301 #ifndef PRODUCT
3302 pc_nmethod_stats.print_pc_stats();
3303 #endif
|