src/share/vm/code/nmethod.cpp

Print this page
rev 2893 : 7121756: Improve C1 inlining policy by using profiling at call sites
Summary: profile based recompilation of methods with C1 with more inlining.
Reviewed-by:


 653     _deoptimize_offset       = 0;
 654     _deoptimize_mh_offset    = 0;
 655     _orig_pc_offset          = 0;
 656 
 657     _consts_offset           = data_offset();
 658     _stub_offset             = data_offset();
 659     _oops_offset             = data_offset();
 660     _scopes_data_offset      = _oops_offset          + round_to(code_buffer->total_oop_size(), oopSize);
 661     _scopes_pcs_offset       = _scopes_data_offset;
 662     _dependencies_offset     = _scopes_pcs_offset;
 663     _handler_table_offset    = _dependencies_offset;
 664     _nul_chk_table_offset    = _handler_table_offset;
 665     _nmethod_end_offset      = _nul_chk_table_offset;
 666     _compile_id              = compile_id;
 667     _comp_level              = CompLevel_none;
 668     _entry_point             = code_begin()          + offsets->value(CodeOffsets::Entry);
 669     _verified_entry_point    = code_begin()          + offsets->value(CodeOffsets::Verified_Entry);
 670     _osr_entry_point         = NULL;
 671     _exception_cache         = NULL;
 672     _pc_desc_cache.reset_to(NULL);



 673 
 674     code_buffer->copy_oops_to(this);
 675     if (ScavengeRootsInCode && detect_scavenge_root_oops()) {
 676       CodeCache::add_scavenge_root_nmethod(this);
 677     }
 678     debug_only(verify_scavenge_root_oops());
 679     CodeCache::commit(this);
 680   }
 681 
 682   if (PrintNativeNMethods || PrintDebugInfo || PrintRelocations || PrintDependencies) {
 683     ttyLocker ttyl;  // keep the following output all in one block
 684     // This output goes directly to the tty, not the compiler log.
 685     // To enable tools to match it up with the compilation activity,
 686     // be sure to tag this tty output with the compile ID.
 687     if (xtty != NULL) {
 688       xtty->begin_head("print_native_nmethod");
 689       xtty->method(_method);
 690       xtty->stamp();
 691       xtty->end_head(" address='" INTPTR_FORMAT "'", (intptr_t) this);
 692     }


 734     _deoptimize_mh_offset    = 0;
 735     _unwind_handler_offset   = -1;
 736     _trap_offset             = offsets->value(CodeOffsets::Dtrace_trap);
 737     _orig_pc_offset          = 0;
 738     _consts_offset           = data_offset();
 739     _stub_offset             = data_offset();
 740     _oops_offset             = data_offset();
 741     _scopes_data_offset      = _oops_offset          + round_to(code_buffer->total_oop_size(), oopSize);
 742     _scopes_pcs_offset       = _scopes_data_offset;
 743     _dependencies_offset     = _scopes_pcs_offset;
 744     _handler_table_offset    = _dependencies_offset;
 745     _nul_chk_table_offset    = _handler_table_offset;
 746     _nmethod_end_offset      = _nul_chk_table_offset;
 747     _compile_id              = 0;  // default
 748     _comp_level              = CompLevel_none;
 749     _entry_point             = code_begin()          + offsets->value(CodeOffsets::Entry);
 750     _verified_entry_point    = code_begin()          + offsets->value(CodeOffsets::Verified_Entry);
 751     _osr_entry_point         = NULL;
 752     _exception_cache         = NULL;
 753     _pc_desc_cache.reset_to(NULL);



 754 
 755     code_buffer->copy_oops_to(this);
 756     debug_only(verify_scavenge_root_oops());
 757     CodeCache::commit(this);
 758   }
 759 
 760   if (PrintNMethods || PrintDebugInfo || PrintRelocations || PrintDependencies) {
 761     ttyLocker ttyl;  // keep the following output all in one block
 762     // This output goes directly to the tty, not the compiler log.
 763     // To enable tools to match it up with the compilation activity,
 764     // be sure to tag this tty output with the compile ID.
 765     if (xtty != NULL) {
 766       xtty->begin_head("print_dtrace_nmethod");
 767       xtty->method(_method);
 768       xtty->stamp();
 769       xtty->end_head(" address='" INTPTR_FORMAT "'", (intptr_t) this);
 770     }
 771     // print the header part first
 772     print();
 773     // then print the requested information


 855     _nul_chk_table_offset    = _handler_table_offset + round_to(handler_table->size_in_bytes(), oopSize);
 856     _nmethod_end_offset      = _nul_chk_table_offset + round_to(nul_chk_table->size_in_bytes(), oopSize);
 857 
 858     _entry_point             = code_begin()          + offsets->value(CodeOffsets::Entry);
 859     _verified_entry_point    = code_begin()          + offsets->value(CodeOffsets::Verified_Entry);
 860     _osr_entry_point         = code_begin()          + offsets->value(CodeOffsets::OSR_Entry);
 861     _exception_cache         = NULL;
 862     _pc_desc_cache.reset_to(scopes_pcs_begin());
 863 
 864     // Copy contents of ScopeDescRecorder to nmethod
 865     code_buffer->copy_oops_to(this);
 866     debug_info->copy_to(this);
 867     dependencies->copy_to(this);
 868     if (ScavengeRootsInCode && detect_scavenge_root_oops()) {
 869       CodeCache::add_scavenge_root_nmethod(this);
 870     }
 871     debug_only(verify_scavenge_root_oops());
 872 
 873     CodeCache::commit(this);
 874 




 875     // Copy contents of ExceptionHandlerTable to nmethod
 876     handler_table->copy_to(this);
 877     nul_chk_table->copy_to(this);
 878 
 879     // we use the information of entry points to find out if a method is
 880     // static or non static
 881     assert(compiler->is_c2() ||
 882            _method->is_static() == (entry_point() == _verified_entry_point),
 883            " entry points must be same for static methods and vice versa");
 884   }
 885 
 886   bool printnmethods = PrintNMethods
 887     || CompilerOracle::should_print(_method)
 888     || CompilerOracle::has_option_string(_method, "PrintNMethods");
 889   if (printnmethods || PrintDebugInfo || PrintRelocations || PrintDependencies || PrintExceptionHandlers) {
 890     print_nmethod(printnmethods);
 891   }
 892 
 893   // Note: Do not verify in here as the CodeCache_lock is
 894   //       taken which would conflict with the CompiledIC_lock


1885 
1886 
1887 void nmethod::copy_scopes_pcs(PcDesc* pcs, int count) {
1888   assert(count >= 2, "must be sentinel values, at least");
1889 
1890 #ifdef ASSERT
1891   // must be sorted and unique; we do a binary search in find_pc_desc()
1892   int prev_offset = pcs[0].pc_offset();
1893   assert(prev_offset == PcDesc::lower_offset_limit,
1894          "must start with a sentinel");
1895   for (int i = 1; i < count; i++) {
1896     int this_offset = pcs[i].pc_offset();
1897     assert(this_offset > prev_offset, "offsets must be sorted");
1898     prev_offset = this_offset;
1899   }
1900   assert(prev_offset == PcDesc::upper_offset_limit,
1901          "must end with a sentinel");
1902 #endif //ASSERT
1903 
1904   // Search for MethodHandle invokes and tag the nmethod.



1905   for (int i = 0; i < count; i++) {
1906     if (pcs[i].is_method_handle_invoke()) {
1907       set_has_method_handle_invokes(true);
1908       break;






1909     }
1910   }
1911   assert(has_method_handle_invokes() == (_deoptimize_mh_offset != -1), "must have deopt mh handler");
1912 
1913   int size = count * sizeof(PcDesc);
1914   assert(scopes_pcs_size() >= size, "oob");
1915   memcpy(scopes_pcs_begin(), pcs, size);
1916 
1917   // Adjust the final sentinel downward.
1918   PcDesc* last_pc = &scopes_pcs_begin()[count-1];
1919   assert(last_pc->pc_offset() == PcDesc::upper_offset_limit, "sanity");
1920   last_pc->set_pc_offset(content_size() + 1);
1921   for (; last_pc + 1 < scopes_pcs_end(); last_pc += 1) {
1922     // Fill any rounding gaps with copies of the last record.
1923     last_pc[1] = last_pc[0];
1924   }
1925   // The following assert could fail if sizeof(PcDesc) is not
1926   // an integral multiple of oopSize (the rounding term).
1927   // If it fails, change the logic to always allocate a multiple
1928   // of sizeof(PcDesc), and fill unused words with copies of *last_pc.


2184 address nmethod::get_deopt_original_pc(const frame* fr) {
2185   if (fr->cb() == NULL)  return NULL;
2186 
2187   nmethod* nm = fr->cb()->as_nmethod_or_null();
2188   if (nm != NULL && nm->is_deopt_pc(fr->pc()))
2189     return nm->get_original_pc(fr);
2190 
2191   return NULL;
2192 }
2193 
2194 
2195 // -----------------------------------------------------------------------------
2196 // MethodHandle
2197 
2198 bool nmethod::is_method_handle_return(address return_pc) {
2199   if (!has_method_handle_invokes())  return false;
2200   PcDesc* pd = pc_desc_at(return_pc);
2201   if (pd == NULL)
2202     return false;
2203   return pd->is_method_handle_invoke();








2204 }
2205 
2206 
2207 // -----------------------------------------------------------------------------
2208 // Verification
2209 
2210 class VerifyOopsClosure: public OopClosure {
2211   nmethod* _nm;
2212   bool     _ok;
2213 public:
2214   VerifyOopsClosure(nmethod* nm) : _nm(nm), _ok(true) { }
2215   bool ok() { return _ok; }
2216   virtual void do_oop(oop* p) {
2217     if ((*p) == NULL || (*p)->is_oop())  return;
2218     if (_ok) {
2219       _nm->print_nmethod(true);
2220       _ok = false;
2221     }
2222     tty->print_cr("*** non-oop "PTR_FORMAT" found at "PTR_FORMAT" (offset %d)",
2223                   (intptr_t)(*p), (intptr_t)p, (int)((intptr_t)p - (intptr_t)_nm));




 653     _deoptimize_offset       = 0;
 654     _deoptimize_mh_offset    = 0;
 655     _orig_pc_offset          = 0;
 656 
 657     _consts_offset           = data_offset();
 658     _stub_offset             = data_offset();
 659     _oops_offset             = data_offset();
 660     _scopes_data_offset      = _oops_offset          + round_to(code_buffer->total_oop_size(), oopSize);
 661     _scopes_pcs_offset       = _scopes_data_offset;
 662     _dependencies_offset     = _scopes_pcs_offset;
 663     _handler_table_offset    = _dependencies_offset;
 664     _nul_chk_table_offset    = _handler_table_offset;
 665     _nmethod_end_offset      = _nul_chk_table_offset;
 666     _compile_id              = compile_id;
 667     _comp_level              = CompLevel_none;
 668     _entry_point             = code_begin()          + offsets->value(CodeOffsets::Entry);
 669     _verified_entry_point    = code_begin()          + offsets->value(CodeOffsets::Verified_Entry);
 670     _osr_entry_point         = NULL;
 671     _exception_cache         = NULL;
 672     _pc_desc_cache.reset_to(NULL);
 673 #ifdef COMPILER1
 674     _needs_recomp = false;
 675 #endif
 676 
 677     code_buffer->copy_oops_to(this);
 678     if (ScavengeRootsInCode && detect_scavenge_root_oops()) {
 679       CodeCache::add_scavenge_root_nmethod(this);
 680     }
 681     debug_only(verify_scavenge_root_oops());
 682     CodeCache::commit(this);
 683   }
 684 
 685   if (PrintNativeNMethods || PrintDebugInfo || PrintRelocations || PrintDependencies) {
 686     ttyLocker ttyl;  // keep the following output all in one block
 687     // This output goes directly to the tty, not the compiler log.
 688     // To enable tools to match it up with the compilation activity,
 689     // be sure to tag this tty output with the compile ID.
 690     if (xtty != NULL) {
 691       xtty->begin_head("print_native_nmethod");
 692       xtty->method(_method);
 693       xtty->stamp();
 694       xtty->end_head(" address='" INTPTR_FORMAT "'", (intptr_t) this);
 695     }


 737     _deoptimize_mh_offset    = 0;
 738     _unwind_handler_offset   = -1;
 739     _trap_offset             = offsets->value(CodeOffsets::Dtrace_trap);
 740     _orig_pc_offset          = 0;
 741     _consts_offset           = data_offset();
 742     _stub_offset             = data_offset();
 743     _oops_offset             = data_offset();
 744     _scopes_data_offset      = _oops_offset          + round_to(code_buffer->total_oop_size(), oopSize);
 745     _scopes_pcs_offset       = _scopes_data_offset;
 746     _dependencies_offset     = _scopes_pcs_offset;
 747     _handler_table_offset    = _dependencies_offset;
 748     _nul_chk_table_offset    = _handler_table_offset;
 749     _nmethod_end_offset      = _nul_chk_table_offset;
 750     _compile_id              = 0;  // default
 751     _comp_level              = CompLevel_none;
 752     _entry_point             = code_begin()          + offsets->value(CodeOffsets::Entry);
 753     _verified_entry_point    = code_begin()          + offsets->value(CodeOffsets::Verified_Entry);
 754     _osr_entry_point         = NULL;
 755     _exception_cache         = NULL;
 756     _pc_desc_cache.reset_to(NULL);
 757 #ifdef COMPILER1
 758     _needs_recomp = false;
 759 #endif
 760 
 761     code_buffer->copy_oops_to(this);
 762     debug_only(verify_scavenge_root_oops());
 763     CodeCache::commit(this);
 764   }
 765 
 766   if (PrintNMethods || PrintDebugInfo || PrintRelocations || PrintDependencies) {
 767     ttyLocker ttyl;  // keep the following output all in one block
 768     // This output goes directly to the tty, not the compiler log.
 769     // To enable tools to match it up with the compilation activity,
 770     // be sure to tag this tty output with the compile ID.
 771     if (xtty != NULL) {
 772       xtty->begin_head("print_dtrace_nmethod");
 773       xtty->method(_method);
 774       xtty->stamp();
 775       xtty->end_head(" address='" INTPTR_FORMAT "'", (intptr_t) this);
 776     }
 777     // print the header part first
 778     print();
 779     // then print the requested information


 861     _nul_chk_table_offset    = _handler_table_offset + round_to(handler_table->size_in_bytes(), oopSize);
 862     _nmethod_end_offset      = _nul_chk_table_offset + round_to(nul_chk_table->size_in_bytes(), oopSize);
 863 
 864     _entry_point             = code_begin()          + offsets->value(CodeOffsets::Entry);
 865     _verified_entry_point    = code_begin()          + offsets->value(CodeOffsets::Verified_Entry);
 866     _osr_entry_point         = code_begin()          + offsets->value(CodeOffsets::OSR_Entry);
 867     _exception_cache         = NULL;
 868     _pc_desc_cache.reset_to(scopes_pcs_begin());
 869 
 870     // Copy contents of ScopeDescRecorder to nmethod
 871     code_buffer->copy_oops_to(this);
 872     debug_info->copy_to(this);
 873     dependencies->copy_to(this);
 874     if (ScavengeRootsInCode && detect_scavenge_root_oops()) {
 875       CodeCache::add_scavenge_root_nmethod(this);
 876     }
 877     debug_only(verify_scavenge_root_oops());
 878 
 879     CodeCache::commit(this);
 880 
 881 #ifdef COMPILER1
 882     _needs_recomp = false;
 883 #endif
 884 
 885     // Copy contents of ExceptionHandlerTable to nmethod
 886     handler_table->copy_to(this);
 887     nul_chk_table->copy_to(this);
 888 
 889     // we use the information of entry points to find out if a method is
 890     // static or non static
 891     assert(compiler->is_c2() ||
 892            _method->is_static() == (entry_point() == _verified_entry_point),
 893            " entry points must be same for static methods and vice versa");
 894   }
 895 
 896   bool printnmethods = PrintNMethods
 897     || CompilerOracle::should_print(_method)
 898     || CompilerOracle::has_option_string(_method, "PrintNMethods");
 899   if (printnmethods || PrintDebugInfo || PrintRelocations || PrintDependencies || PrintExceptionHandlers) {
 900     print_nmethod(printnmethods);
 901   }
 902 
 903   // Note: Do not verify in here as the CodeCache_lock is
 904   //       taken which would conflict with the CompiledIC_lock


1895 
1896 
1897 void nmethod::copy_scopes_pcs(PcDesc* pcs, int count) {
1898   assert(count >= 2, "must be sentinel values, at least");
1899 
1900 #ifdef ASSERT
1901   // must be sorted and unique; we do a binary search in find_pc_desc()
1902   int prev_offset = pcs[0].pc_offset();
1903   assert(prev_offset == PcDesc::lower_offset_limit,
1904          "must start with a sentinel");
1905   for (int i = 1; i < count; i++) {
1906     int this_offset = pcs[i].pc_offset();
1907     assert(this_offset > prev_offset, "offsets must be sorted");
1908     prev_offset = this_offset;
1909   }
1910   assert(prev_offset == PcDesc::upper_offset_limit,
1911          "must end with a sentinel");
1912 #endif //ASSERT
1913 
1914   // Search for MethodHandle invokes and tag the nmethod.
1915   bool searching_method_handle = true; 
1916   bool searching_profiled_call = false;
1917   COMPILER1_PRESENT(searching_profiled_call = searching_profiled_call || C1ProfileInlining);
1918   for (int i = 0; i < count; i++) {
1919     if (pcs[i].is_method_handle_invoke()) {
1920       set_has_method_handle_invokes(true);
1921       searching_method_handle = false;
1922       if (!searching_profiled_call) break;
1923     }
1924     if (pcs[i].is_profiled_call()) {
1925       set_has_profiled_calls(true);
1926       searching_profiled_call =false;
1927       if (!searching_method_handle) break;
1928     }
1929   }
1930   assert(has_method_handle_invokes() == (_deoptimize_mh_offset != -1), "must have deopt mh handler");
1931 
1932   int size = count * sizeof(PcDesc);
1933   assert(scopes_pcs_size() >= size, "oob");
1934   memcpy(scopes_pcs_begin(), pcs, size);
1935 
1936   // Adjust the final sentinel downward.
1937   PcDesc* last_pc = &scopes_pcs_begin()[count-1];
1938   assert(last_pc->pc_offset() == PcDesc::upper_offset_limit, "sanity");
1939   last_pc->set_pc_offset(content_size() + 1);
1940   for (; last_pc + 1 < scopes_pcs_end(); last_pc += 1) {
1941     // Fill any rounding gaps with copies of the last record.
1942     last_pc[1] = last_pc[0];
1943   }
1944   // The following assert could fail if sizeof(PcDesc) is not
1945   // an integral multiple of oopSize (the rounding term).
1946   // If it fails, change the logic to always allocate a multiple
1947   // of sizeof(PcDesc), and fill unused words with copies of *last_pc.


2203 address nmethod::get_deopt_original_pc(const frame* fr) {
2204   if (fr->cb() == NULL)  return NULL;
2205 
2206   nmethod* nm = fr->cb()->as_nmethod_or_null();
2207   if (nm != NULL && nm->is_deopt_pc(fr->pc()))
2208     return nm->get_original_pc(fr);
2209 
2210   return NULL;
2211 }
2212 
2213 
2214 // -----------------------------------------------------------------------------
2215 // MethodHandle
2216 
2217 bool nmethod::is_method_handle_return(address return_pc) {
2218   if (!has_method_handle_invokes())  return false;
2219   PcDesc* pd = pc_desc_at(return_pc);
2220   if (pd == NULL)
2221     return false;
2222   return pd->is_method_handle_invoke();
2223 }
2224 
2225 bool nmethod::is_profiled_call(address call_pc) {
2226   if (!has_profiled_calls())  return false;
2227   PcDesc* pd = pc_desc_at(call_pc);
2228   if (pd == NULL)
2229     return false;
2230   return pd->is_profiled_call();
2231 }
2232 
2233 
2234 // -----------------------------------------------------------------------------
2235 // Verification
2236 
2237 class VerifyOopsClosure: public OopClosure {
2238   nmethod* _nm;
2239   bool     _ok;
2240 public:
2241   VerifyOopsClosure(nmethod* nm) : _nm(nm), _ok(true) { }
2242   bool ok() { return _ok; }
2243   virtual void do_oop(oop* p) {
2244     if ((*p) == NULL || (*p)->is_oop())  return;
2245     if (_ok) {
2246       _nm->print_nmethod(true);
2247       _ok = false;
2248     }
2249     tty->print_cr("*** non-oop "PTR_FORMAT" found at "PTR_FORMAT" (offset %d)",
2250                   (intptr_t)(*p), (intptr_t)p, (int)((intptr_t)p - (intptr_t)_nm));