393 if (method() != NULL && is_native_method()) return "c2n";
394 return NULL;
395 }
396
397 // Fill in default values for various flag fields
398 void nmethod::init_defaults() {
399 _state = in_use;
400 _has_flushed_dependencies = 0;
401 _lock_count = 0;
402 _stack_traversal_mark = 0;
403 _unload_reported = false; // jvmti state
404 _is_far_code = false; // nmethods are located in CodeCache
405
406 #ifdef ASSERT
407 _oops_are_stale = false;
408 #endif
409
410 _oops_do_mark_link = NULL;
411 _jmethod_id = NULL;
412 _osr_link = NULL;
413 if (UseG1GC) {
414 _unloading_next = NULL;
415 } else {
416 _scavenge_root_link = NULL;
417 }
418 _scavenge_root_state = 0;
419 #if INCLUDE_RTM_OPT
420 _rtm_state = NoRTM;
421 #endif
422 #if INCLUDE_JVMCI
423 _jvmci_installed_code = NULL;
424 _speculation_log = NULL;
425 #endif
426 }
427
428 nmethod* nmethod::new_native_nmethod(const methodHandle& method,
429 int compile_id,
430 CodeBuffer *code_buffer,
431 int vep_offset,
432 int frame_complete,
433 int frame_size,
434 ByteSize basic_lock_owner_sp_offset,
435 ByteSize basic_lock_sp_offset,
436 OopMapSet* oop_maps) {
437 code_buffer->finalize_oop_references(method);
581 _dependencies_offset = _scopes_pcs_offset;
582 _handler_table_offset = _dependencies_offset;
583 _nul_chk_table_offset = _handler_table_offset;
584 _nmethod_end_offset = _nul_chk_table_offset;
585 _compile_id = compile_id;
586 _comp_level = CompLevel_none;
587 _entry_point = code_begin() + offsets->value(CodeOffsets::Entry);
588 _verified_entry_point = code_begin() + offsets->value(CodeOffsets::Verified_Entry);
589 _osr_entry_point = NULL;
590 _exception_cache = NULL;
591 _pc_desc_container.reset_to(NULL);
592 _hotness_counter = NMethodSweeper::hotness_counter_reset_val();
593
594 _scopes_data_begin = (address) this + scopes_data_offset;
595 _deopt_handler_begin = (address) this + deoptimize_offset;
596 _deopt_mh_handler_begin = (address) this + deoptimize_mh_offset;
597
598 code_buffer->copy_code_and_locs_to(this);
599 code_buffer->copy_values_to(this);
600 if (ScavengeRootsInCode) {
601 if (detect_scavenge_root_oops()) {
602 CodeCache::add_scavenge_root_nmethod(this);
603 }
604 Universe::heap()->register_nmethod(this);
605 }
606 debug_only(verify_scavenge_root_oops());
607 CodeCache::commit(this);
608 }
609
610 if (PrintNativeNMethods || PrintDebugInfo || PrintRelocations || PrintDependencies) {
611 ttyLocker ttyl; // keep the following output all in one block
612 // This output goes directly to the tty, not the compiler log.
613 // To enable tools to match it up with the compilation activity,
614 // be sure to tag this tty output with the compile ID.
615 if (xtty != NULL) {
616 xtty->begin_head("print_native_nmethod");
617 xtty->method(_method);
618 xtty->stamp();
619 xtty->end_head(" address='" INTPTR_FORMAT "'", (intptr_t) this);
620 }
621 // print the header part first
622 print();
623 // then print the requested information
624 if (PrintNativeNMethods) {
625 print_code();
626 if (oop_maps != NULL) {
736 _scopes_pcs_offset = scopes_data_offset + align_up(debug_info->data_size (), oopSize);
737 _dependencies_offset = _scopes_pcs_offset + adjust_pcs_size(debug_info->pcs_size());
738 _handler_table_offset = _dependencies_offset + align_up((int)dependencies->size_in_bytes (), oopSize);
739 _nul_chk_table_offset = _handler_table_offset + align_up(handler_table->size_in_bytes(), oopSize);
740 _nmethod_end_offset = _nul_chk_table_offset + align_up(nul_chk_table->size_in_bytes(), oopSize);
741 _entry_point = code_begin() + offsets->value(CodeOffsets::Entry);
742 _verified_entry_point = code_begin() + offsets->value(CodeOffsets::Verified_Entry);
743 _osr_entry_point = code_begin() + offsets->value(CodeOffsets::OSR_Entry);
744 _exception_cache = NULL;
745
746 _scopes_data_begin = (address) this + scopes_data_offset;
747
748 _pc_desc_container.reset_to(scopes_pcs_begin());
749
750 code_buffer->copy_code_and_locs_to(this);
751 // Copy contents of ScopeDescRecorder to nmethod
752 code_buffer->copy_values_to(this);
753 debug_info->copy_to(this);
754 dependencies->copy_to(this);
755 if (ScavengeRootsInCode) {
756 if (detect_scavenge_root_oops()) {
757 CodeCache::add_scavenge_root_nmethod(this);
758 }
759 Universe::heap()->register_nmethod(this);
760 }
761 debug_only(verify_scavenge_root_oops());
762
763 CodeCache::commit(this);
764
765 // Copy contents of ExceptionHandlerTable to nmethod
766 handler_table->copy_to(this);
767 nul_chk_table->copy_to(this);
768
769 // we use the information of entry points to find out if a method is
770 // static or non static
771 assert(compiler->is_c2() || compiler->is_jvmci() ||
772 _method->is_static() == (entry_point() == _verified_entry_point),
773 " entry points must be same for static methods and vice versa");
774 }
775 }
776
777 // Print a short set of xml attributes to identify this nmethod. The
778 // output should be embedded in some other element.
779 void nmethod::log_identity(xmlStream* log) const {
780 log->print(" compile_id='%d'", compile_id());
781 const char* nm_kind = compile_kind();
2118 fatal("nmethod at " INTPTR_FORMAT " not in zone", p2i(this));
2119 }
2120
2121 if(is_native_method() )
2122 return;
2123
2124 nmethod* nm = CodeCache::find_nmethod(verified_entry_point());
2125 if (nm != this) {
2126 fatal("findNMethod did not find this nmethod (" INTPTR_FORMAT ")", p2i(this));
2127 }
2128
2129 for (PcDesc* p = scopes_pcs_begin(); p < scopes_pcs_end(); p++) {
2130 if (! p->verify(this)) {
2131 tty->print_cr("\t\tin nmethod at " INTPTR_FORMAT " (pcs)", p2i(this));
2132 }
2133 }
2134
2135 VerifyOopsClosure voc(this);
2136 oops_do(&voc);
2137 assert(voc.ok(), "embedded oops must be OK");
2138 verify_scavenge_root_oops();
2139
2140 verify_scopes();
2141 }
2142
2143
2144 void nmethod::verify_interrupt_point(address call_site) {
2145 // Verify IC only when nmethod installation is finished.
2146 bool is_installed = (method()->code() == this) // nmethod is in state 'in_use' and installed
2147 || !this->is_in_use(); // nmethod is installed, but not in 'in_use' state
2148 if (is_installed) {
2149 Thread *cur = Thread::current();
2150 if (CompiledIC_lock->owner() == cur ||
2151 ((cur->is_VM_thread() || cur->is_ConcurrentGC_thread()) &&
2152 SafepointSynchronize::is_at_safepoint())) {
2153 CompiledIC_at(this, call_site);
2154 CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops());
2155 } else {
2156 MutexLocker ml_verify (CompiledIC_lock);
2157 CompiledIC_at(this, call_site);
2158 }
2211 class DebugScavengeRoot: public OopClosure {
2212 nmethod* _nm;
2213 bool _ok;
2214 public:
2215 DebugScavengeRoot(nmethod* nm) : _nm(nm), _ok(true) { }
2216 bool ok() { return _ok; }
2217 virtual void do_oop(oop* p) {
2218 if ((*p) == NULL || !(*p)->is_scavengable()) return;
2219 if (_ok) {
2220 _nm->print_nmethod(true);
2221 _ok = false;
2222 }
2223 tty->print_cr("*** scavengable oop " PTR_FORMAT " found at " PTR_FORMAT " (offset %d)",
2224 p2i(*p), p2i(p), (int)((intptr_t)p - (intptr_t)_nm));
2225 (*p)->print();
2226 }
2227 virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); }
2228 };
2229
2230 void nmethod::verify_scavenge_root_oops() {
2231 if (UseG1GC) {
2232 return;
2233 }
2234
2235 if (!on_scavenge_root_list()) {
2236 // Actually look inside, to verify the claim that it's clean.
2237 DebugScavengeRoot debug_scavenge_root(this);
2238 oops_do(&debug_scavenge_root);
2239 if (!debug_scavenge_root.ok())
2240 fatal("found an unadvertised bad scavengable oop in the code cache");
2241 }
2242 assert(scavenge_root_not_marked(), "");
2243 }
2244
2245 #endif // PRODUCT
2246
2247 // Printing operations
2248
2249 void nmethod::print() const {
2250 ResourceMark rm;
2251 ttyLocker ttyl; // keep the following output all in one block
2252
2253 tty->print("Compiled method ");
2254
|
393 if (method() != NULL && is_native_method()) return "c2n";
394 return NULL;
395 }
396
397 // Fill in default values for various flag fields
398 void nmethod::init_defaults() {
399 _state = in_use;
400 _has_flushed_dependencies = 0;
401 _lock_count = 0;
402 _stack_traversal_mark = 0;
403 _unload_reported = false; // jvmti state
404 _is_far_code = false; // nmethods are located in CodeCache
405
406 #ifdef ASSERT
407 _oops_are_stale = false;
408 #endif
409
410 _oops_do_mark_link = NULL;
411 _jmethod_id = NULL;
412 _osr_link = NULL;
413 _unloading_next = NULL;
414 _scavenge_root_link = NULL;
415 _scavenge_root_state = 0;
416 #if INCLUDE_RTM_OPT
417 _rtm_state = NoRTM;
418 #endif
419 #if INCLUDE_JVMCI
420 _jvmci_installed_code = NULL;
421 _speculation_log = NULL;
422 #endif
423 }
424
425 nmethod* nmethod::new_native_nmethod(const methodHandle& method,
426 int compile_id,
427 CodeBuffer *code_buffer,
428 int vep_offset,
429 int frame_complete,
430 int frame_size,
431 ByteSize basic_lock_owner_sp_offset,
432 ByteSize basic_lock_sp_offset,
433 OopMapSet* oop_maps) {
434 code_buffer->finalize_oop_references(method);
578 _dependencies_offset = _scopes_pcs_offset;
579 _handler_table_offset = _dependencies_offset;
580 _nul_chk_table_offset = _handler_table_offset;
581 _nmethod_end_offset = _nul_chk_table_offset;
582 _compile_id = compile_id;
583 _comp_level = CompLevel_none;
584 _entry_point = code_begin() + offsets->value(CodeOffsets::Entry);
585 _verified_entry_point = code_begin() + offsets->value(CodeOffsets::Verified_Entry);
586 _osr_entry_point = NULL;
587 _exception_cache = NULL;
588 _pc_desc_container.reset_to(NULL);
589 _hotness_counter = NMethodSweeper::hotness_counter_reset_val();
590
591 _scopes_data_begin = (address) this + scopes_data_offset;
592 _deopt_handler_begin = (address) this + deoptimize_offset;
593 _deopt_mh_handler_begin = (address) this + deoptimize_mh_offset;
594
595 code_buffer->copy_code_and_locs_to(this);
596 code_buffer->copy_values_to(this);
597 if (ScavengeRootsInCode) {
598 Universe::heap()->register_nmethod(this);
599 }
600 debug_only(Universe::heap()->verify_nmethod_roots(this));
601 CodeCache::commit(this);
602 }
603
604 if (PrintNativeNMethods || PrintDebugInfo || PrintRelocations || PrintDependencies) {
605 ttyLocker ttyl; // keep the following output all in one block
606 // This output goes directly to the tty, not the compiler log.
607 // To enable tools to match it up with the compilation activity,
608 // be sure to tag this tty output with the compile ID.
609 if (xtty != NULL) {
610 xtty->begin_head("print_native_nmethod");
611 xtty->method(_method);
612 xtty->stamp();
613 xtty->end_head(" address='" INTPTR_FORMAT "'", (intptr_t) this);
614 }
615 // print the header part first
616 print();
617 // then print the requested information
618 if (PrintNativeNMethods) {
619 print_code();
620 if (oop_maps != NULL) {
730 _scopes_pcs_offset = scopes_data_offset + align_up(debug_info->data_size (), oopSize);
731 _dependencies_offset = _scopes_pcs_offset + adjust_pcs_size(debug_info->pcs_size());
732 _handler_table_offset = _dependencies_offset + align_up((int)dependencies->size_in_bytes (), oopSize);
733 _nul_chk_table_offset = _handler_table_offset + align_up(handler_table->size_in_bytes(), oopSize);
734 _nmethod_end_offset = _nul_chk_table_offset + align_up(nul_chk_table->size_in_bytes(), oopSize);
735 _entry_point = code_begin() + offsets->value(CodeOffsets::Entry);
736 _verified_entry_point = code_begin() + offsets->value(CodeOffsets::Verified_Entry);
737 _osr_entry_point = code_begin() + offsets->value(CodeOffsets::OSR_Entry);
738 _exception_cache = NULL;
739
740 _scopes_data_begin = (address) this + scopes_data_offset;
741
742 _pc_desc_container.reset_to(scopes_pcs_begin());
743
744 code_buffer->copy_code_and_locs_to(this);
745 // Copy contents of ScopeDescRecorder to nmethod
746 code_buffer->copy_values_to(this);
747 debug_info->copy_to(this);
748 dependencies->copy_to(this);
749 if (ScavengeRootsInCode) {
750 Universe::heap()->register_nmethod(this);
751 }
752 debug_only(Universe::heap()->verify_nmethod_roots(this));
753
754 CodeCache::commit(this);
755
756 // Copy contents of ExceptionHandlerTable to nmethod
757 handler_table->copy_to(this);
758 nul_chk_table->copy_to(this);
759
760 // we use the information of entry points to find out if a method is
761 // static or non static
762 assert(compiler->is_c2() || compiler->is_jvmci() ||
763 _method->is_static() == (entry_point() == _verified_entry_point),
764 " entry points must be same for static methods and vice versa");
765 }
766 }
767
768 // Print a short set of xml attributes to identify this nmethod. The
769 // output should be embedded in some other element.
770 void nmethod::log_identity(xmlStream* log) const {
771 log->print(" compile_id='%d'", compile_id());
772 const char* nm_kind = compile_kind();
2109 fatal("nmethod at " INTPTR_FORMAT " not in zone", p2i(this));
2110 }
2111
2112 if(is_native_method() )
2113 return;
2114
2115 nmethod* nm = CodeCache::find_nmethod(verified_entry_point());
2116 if (nm != this) {
2117 fatal("findNMethod did not find this nmethod (" INTPTR_FORMAT ")", p2i(this));
2118 }
2119
2120 for (PcDesc* p = scopes_pcs_begin(); p < scopes_pcs_end(); p++) {
2121 if (! p->verify(this)) {
2122 tty->print_cr("\t\tin nmethod at " INTPTR_FORMAT " (pcs)", p2i(this));
2123 }
2124 }
2125
2126 VerifyOopsClosure voc(this);
2127 oops_do(&voc);
2128 assert(voc.ok(), "embedded oops must be OK");
2129 Universe::heap()->verify_nmethod_roots(this);
2130
2131 verify_scopes();
2132 }
2133
2134
2135 void nmethod::verify_interrupt_point(address call_site) {
2136 // Verify IC only when nmethod installation is finished.
2137 bool is_installed = (method()->code() == this) // nmethod is in state 'in_use' and installed
2138 || !this->is_in_use(); // nmethod is installed, but not in 'in_use' state
2139 if (is_installed) {
2140 Thread *cur = Thread::current();
2141 if (CompiledIC_lock->owner() == cur ||
2142 ((cur->is_VM_thread() || cur->is_ConcurrentGC_thread()) &&
2143 SafepointSynchronize::is_at_safepoint())) {
2144 CompiledIC_at(this, call_site);
2145 CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops());
2146 } else {
2147 MutexLocker ml_verify (CompiledIC_lock);
2148 CompiledIC_at(this, call_site);
2149 }
2202 class DebugScavengeRoot: public OopClosure {
2203 nmethod* _nm;
2204 bool _ok;
2205 public:
2206 DebugScavengeRoot(nmethod* nm) : _nm(nm), _ok(true) { }
2207 bool ok() { return _ok; }
2208 virtual void do_oop(oop* p) {
2209 if ((*p) == NULL || !(*p)->is_scavengable()) return;
2210 if (_ok) {
2211 _nm->print_nmethod(true);
2212 _ok = false;
2213 }
2214 tty->print_cr("*** scavengable oop " PTR_FORMAT " found at " PTR_FORMAT " (offset %d)",
2215 p2i(*p), p2i(p), (int)((intptr_t)p - (intptr_t)_nm));
2216 (*p)->print();
2217 }
2218 virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); }
2219 };
2220
2221 void nmethod::verify_scavenge_root_oops() {
2222 if (!on_scavenge_root_list()) {
2223 // Actually look inside, to verify the claim that it's clean.
2224 DebugScavengeRoot debug_scavenge_root(this);
2225 oops_do(&debug_scavenge_root);
2226 if (!debug_scavenge_root.ok())
2227 fatal("found an unadvertised bad scavengable oop in the code cache");
2228 }
2229 assert(scavenge_root_not_marked(), "");
2230 }
2231
2232 #endif // PRODUCT
2233
2234 // Printing operations
2235
2236 void nmethod::print() const {
2237 ResourceMark rm;
2238 ttyLocker ttyl; // keep the following output all in one block
2239
2240 tty->print("Compiled method ");
2241
|