< prev index next >

src/share/vm/code/compiledMethod.cpp

Print this page
rev 13185 : 8183299: Improve inlining of CompiledMethod methods into frame::sender
Reviewed-by: duke


   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 "code/compiledIC.hpp"

  27 #include "code/scopeDesc.hpp"
  28 #include "code/codeCache.hpp"
  29 #include "prims/methodHandles.hpp"
  30 #include "interpreter/bytecode.hpp"
  31 #include "memory/resourceArea.hpp"
  32 #include "runtime/mutexLocker.hpp"
  33 
  34 CompiledMethod::CompiledMethod(Method* method, const char* name, CompilerType type, const CodeBlobLayout& layout, int frame_complete_offset, int frame_size, ImmutableOopMapSet* oop_maps, bool caller_must_gc_arguments)
  35   : CodeBlob(name, type, layout, frame_complete_offset, frame_size, oop_maps, caller_must_gc_arguments),
  36   _method(method), _mark_for_deoptimization_status(not_marked) {
  37   init_defaults();
  38 }
  39 
  40 CompiledMethod::CompiledMethod(Method* method, const char* name, CompilerType type, int size, int header_size, CodeBuffer* cb, int frame_complete_offset, int frame_size, OopMapSet* oop_maps, bool caller_must_gc_arguments)
  41   : CodeBlob(name, type, CodeBlobLayout((address) this, size, header_size, cb), cb, frame_complete_offset, frame_size, oop_maps, caller_must_gc_arguments),
  42   _method(method), _mark_for_deoptimization_status(not_marked) {
  43   init_defaults();
  44 }
  45 
  46 void CompiledMethod::init_defaults() {
  47   _has_unsafe_access          = 0;
  48   _has_method_handle_invokes  = 0;
  49   _lazy_critical_native       = 0;
  50   _has_wide_vectors           = 0;
  51   _unloading_clock            = 0;
  52 }
  53 
  54 bool CompiledMethod::is_method_handle_return(address return_pc) {
  55   if (!has_method_handle_invokes())  return false;
  56   PcDesc* pd = pc_desc_at(return_pc);
  57   if (pd == NULL)
  58     return false;
  59   return pd->is_method_handle_invoke();
  60 }
  61 
  62 // When using JVMCI the address might be off by the size of a call instruction.
  63 bool CompiledMethod::is_deopt_entry(address pc) {
  64   return pc == deopt_handler_begin()
  65 #if INCLUDE_JVMCI
  66     || (is_compiled_by_jvmci() && pc == (deopt_handler_begin() + NativeCall::instruction_size))
  67 #endif
  68     ;
  69 }
  70 
  71 // Returns a string version of the method state.
  72 const char* CompiledMethod::state() const {
  73   int state = get_state();
  74   switch (state) {
  75   case in_use:
  76     return "in use";
  77   case not_used:
  78     return "not_used";
  79   case not_entrant:
  80     return "not_entrant";
  81   case zombie:
  82     return "zombie";
  83   case unloaded:
  84     return "unloaded";
  85   default:
  86     fatal("unexpected method state: %d", state);
  87     return NULL;
  88   }
  89 }
  90 


 304     // The method attached by JIT-compilers should be used, if present.
 305     // Bytecode can be inaccurate in such case.
 306     Method* callee = attached_method_before_pc(pc);
 307     if (callee != NULL) {
 308       has_receiver = !(callee->access_flags().is_static());
 309       has_appendix = false;
 310       signature = callee->signature();
 311     }
 312 
 313     fr.oops_compiled_arguments_do(signature, has_receiver, has_appendix, reg_map, f);
 314   }
 315 #endif // !SHARK
 316 }
 317 
 318 // -----------------------------------------------------------------------------
 319 // CompiledMethod::get_deopt_original_pc
 320 //
 321 // Return the original PC for the given PC if:
 322 // (a) the given PC belongs to a nmethod and
 323 // (b) it is a deopt PC
 324 address CompiledMethod::get_deopt_original_pc(const frame* fr) {
 325   if (fr->cb() == NULL)  return NULL;
 326 
 327   CompiledMethod* cm = fr->cb()->as_compiled_method_or_null();
 328   if (cm != NULL && cm->is_deopt_pc(fr->pc()))
 329     return cm->get_original_pc(fr);
 330 
 331   return NULL;
 332 }
 333 
 334 Method* CompiledMethod::attached_method(address call_instr) {
 335   assert(code_contains(call_instr), "not part of the nmethod");
 336   RelocIterator iter(this, call_instr, call_instr + 1);
 337   while (iter.next()) {
 338     if (iter.addr() == call_instr) {
 339       switch(iter.type()) {
 340         case relocInfo::static_call_type:      return iter.static_call_reloc()->method_value();
 341         case relocInfo::opt_virtual_call_type: return iter.opt_virtual_call_reloc()->method_value();
 342         case relocInfo::virtual_call_type:     return iter.virtual_call_reloc()->method_value();
 343       }
 344     }
 345   }
 346   return NULL; // not found
 347 }
 348 
 349 Method* CompiledMethod::attached_method_before_pc(address pc) {
 350   if (NativeCall::is_call_before(pc)) {
 351     NativeCall* ncall = nativeCall_before(pc);
 352     return attached_method(ncall->instruction_address());




   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 "code/compiledIC.hpp"
  27 #include "code/compiledMethod.inline.hpp"
  28 #include "code/scopeDesc.hpp"
  29 #include "code/codeCache.hpp"
  30 #include "prims/methodHandles.hpp"
  31 #include "interpreter/bytecode.hpp"
  32 #include "memory/resourceArea.hpp"
  33 #include "runtime/mutexLocker.hpp"
  34 
  35 CompiledMethod::CompiledMethod(Method* method, const char* name, CompilerType type, const CodeBlobLayout& layout, int frame_complete_offset, int frame_size, ImmutableOopMapSet* oop_maps, bool caller_must_gc_arguments)
  36   : CodeBlob(name, type, layout, frame_complete_offset, frame_size, oop_maps, caller_must_gc_arguments),
  37   _method(method), _mark_for_deoptimization_status(not_marked) {
  38   init_defaults();
  39 }
  40 
  41 CompiledMethod::CompiledMethod(Method* method, const char* name, CompilerType type, int size, int header_size, CodeBuffer* cb, int frame_complete_offset, int frame_size, OopMapSet* oop_maps, bool caller_must_gc_arguments)
  42   : CodeBlob(name, type, CodeBlobLayout((address) this, size, header_size, cb), cb, frame_complete_offset, frame_size, oop_maps, caller_must_gc_arguments),
  43   _method(method), _mark_for_deoptimization_status(not_marked) {
  44   init_defaults();
  45 }
  46 
  47 void CompiledMethod::init_defaults() {
  48   _has_unsafe_access          = 0;
  49   _has_method_handle_invokes  = 0;
  50   _lazy_critical_native       = 0;
  51   _has_wide_vectors           = 0;
  52   _unloading_clock            = 0;
  53 }
  54 
  55 bool CompiledMethod::is_method_handle_return(address return_pc) {
  56   if (!has_method_handle_invokes())  return false;
  57   PcDesc* pd = pc_desc_at(return_pc);
  58   if (pd == NULL)
  59     return false;
  60   return pd->is_method_handle_invoke();
  61 }
  62 









  63 // Returns a string version of the method state.
  64 const char* CompiledMethod::state() const {
  65   int state = get_state();
  66   switch (state) {
  67   case in_use:
  68     return "in use";
  69   case not_used:
  70     return "not_used";
  71   case not_entrant:
  72     return "not_entrant";
  73   case zombie:
  74     return "zombie";
  75   case unloaded:
  76     return "unloaded";
  77   default:
  78     fatal("unexpected method state: %d", state);
  79     return NULL;
  80   }
  81 }
  82 


 296     // The method attached by JIT-compilers should be used, if present.
 297     // Bytecode can be inaccurate in such case.
 298     Method* callee = attached_method_before_pc(pc);
 299     if (callee != NULL) {
 300       has_receiver = !(callee->access_flags().is_static());
 301       has_appendix = false;
 302       signature = callee->signature();
 303     }
 304 
 305     fr.oops_compiled_arguments_do(signature, has_receiver, has_appendix, reg_map, f);
 306   }
 307 #endif // !SHARK
 308 }
 309 
 310 // -----------------------------------------------------------------------------
 311 // CompiledMethod::get_deopt_original_pc
 312 //
 313 // Return the original PC for the given PC if:
 314 // (a) the given PC belongs to a nmethod and
 315 // (b) it is a deopt PC






 316 


 317 
 318 Method* CompiledMethod::attached_method(address call_instr) {
 319   assert(code_contains(call_instr), "not part of the nmethod");
 320   RelocIterator iter(this, call_instr, call_instr + 1);
 321   while (iter.next()) {
 322     if (iter.addr() == call_instr) {
 323       switch(iter.type()) {
 324         case relocInfo::static_call_type:      return iter.static_call_reloc()->method_value();
 325         case relocInfo::opt_virtual_call_type: return iter.opt_virtual_call_reloc()->method_value();
 326         case relocInfo::virtual_call_type:     return iter.virtual_call_reloc()->method_value();
 327       }
 328     }
 329   }
 330   return NULL; // not found
 331 }
 332 
 333 Method* CompiledMethod::attached_method_before_pc(address pc) {
 334   if (NativeCall::is_call_before(pc)) {
 335     NativeCall* ncall = nativeCall_before(pc);
 336     return attached_method(ncall->instruction_address());


< prev index next >