src/share/vm/interpreter/abstractInterpreter.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File hotspot Sdiff src/share/vm/interpreter

src/share/vm/interpreter/abstractInterpreter.cpp

Print this page




   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 "asm/macroAssembler.hpp"
  27 #include "asm/macroAssembler.inline.hpp"

  28 #include "interpreter/bytecodeHistogram.hpp"
  29 #include "interpreter/bytecodeInterpreter.hpp"
  30 #include "interpreter/interpreter.hpp"
  31 #include "interpreter/interpreterRuntime.hpp"
  32 #include "interpreter/interp_masm.hpp"
  33 #include "interpreter/templateTable.hpp"
  34 #include "memory/allocation.inline.hpp"



  35 #include "memory/resourceArea.hpp"
  36 #include "oops/arrayOop.hpp"
  37 #include "oops/methodData.hpp"
  38 #include "oops/method.hpp"
  39 #include "oops/oop.inline.hpp"
  40 #include "prims/forte.hpp"
  41 #include "prims/jvmtiExport.hpp"
  42 #include "prims/methodHandles.hpp"
  43 #include "runtime/handles.inline.hpp"
  44 #include "runtime/sharedRuntime.hpp"
  45 #include "runtime/stubRoutines.hpp"
  46 #include "runtime/timer.hpp"
  47 
  48 # define __ _masm->
  49 
  50 //------------------------------------------------------------------------------------------------------------------------
  51 // Implementation of platform independent aspects of Interpreter
  52 
  53 void AbstractInterpreter::initialize() {
  54   if (_code != NULL) return;


  76     tty->print_cr("avg codelet size = %6d bytes", _code->used_space() / _code->number_of_stubs());
  77     tty->cr();
  78   }
  79   _code->print();
  80   tty->print_cr("----------------------------------------------------------------------");
  81   tty->cr();
  82 }
  83 
  84 
  85 //------------------------------------------------------------------------------------------------------------------------
  86 // Implementation of interpreter
  87 
  88 StubQueue* AbstractInterpreter::_code                                       = NULL;
  89 bool       AbstractInterpreter::_notice_safepoints                          = false;
  90 address    AbstractInterpreter::_rethrow_exception_entry                    = NULL;
  91 
  92 address    AbstractInterpreter::_native_entry_begin                         = NULL;
  93 address    AbstractInterpreter::_native_entry_end                           = NULL;
  94 address    AbstractInterpreter::_slow_signature_handler;
  95 address    AbstractInterpreter::_entry_table            [AbstractInterpreter::number_of_method_entries];

  96 address    AbstractInterpreter::_native_abi_to_tosca    [AbstractInterpreter::number_of_result_handlers];
  97 
  98 //------------------------------------------------------------------------------------------------------------------------
  99 // Generation of complete interpreter
 100 
 101 AbstractInterpreterGenerator::AbstractInterpreterGenerator(StubQueue* _code) {
 102   _masm                      = NULL;
 103 }
 104 
 105 
 106 //------------------------------------------------------------------------------------------------------------------------
 107 // Entry points
 108 
 109 AbstractInterpreter::MethodKind AbstractInterpreter::method_kind(methodHandle m) {
 110   // Abstract method?
 111   if (m->is_abstract()) return abstract;
 112 
 113   // Method handle primitive?
 114   if (m->is_method_handle_intrinsic()) {
 115     vmIntrinsics::ID id = m->intrinsic_id();


 187     case vmIntrinsics::_dpow  : return java_lang_math_pow  ;
 188     case vmIntrinsics::_dexp  : return java_lang_math_exp  ;
 189 
 190     case vmIntrinsics::_Reference_get:
 191                                 return java_lang_ref_reference_get;
 192   }
 193 
 194   // Accessor method?
 195   if (m->is_getter()) {
 196     // TODO: We should have used ::is_accessor above, but fast accessors in Zero expect only getters.
 197     // See CppInterpreter::accessor_entry in cppInterpreter_zero.cpp. This should be fixed in Zero,
 198     // then the call above updated to ::is_accessor
 199     assert(m->size_of_parameters() == 1, "fast code for accessors assumes parameter size = 1");
 200     return accessor;
 201   }
 202 
 203   // Note: for now: zero locals for all non-empty methods
 204   return zerolocals;
 205 }
 206 


























 207 
 208 void AbstractInterpreter::set_entry_for_kind(AbstractInterpreter::MethodKind kind, address entry) {
 209   assert(kind >= method_handle_invoke_FIRST &&
 210          kind <= method_handle_invoke_LAST, "late initialization only for MH entry points");
 211   assert(_entry_table[kind] == _entry_table[abstract], "previous value must be AME entry");
 212   _entry_table[kind] = entry;
 213 }
 214 


 215 
 216 // Return true if the interpreter can prove that the given bytecode has
 217 // not yet been executed (in Java semantics, not in actual operation).
 218 bool AbstractInterpreter::is_not_reached(const methodHandle& method, int bci) {
 219   Bytecodes::Code code = method()->code_at(bci);
 220 
 221   if (!Bytecodes::must_rewrite(code)) {
 222     // might have been reached
 223     return false;
 224   }
 225 
 226   // the bytecode might not be rewritten if the method is an accessor, etc.
 227   address ientry = method->interpreter_entry();
 228   if (ientry != entry_for_kind(AbstractInterpreter::zerolocals) &&
 229       ientry != entry_for_kind(AbstractInterpreter::zerolocals_synchronized))
 230     return false;  // interpreter does not run this method!
 231 
 232   // otherwise, we can be sure this bytecode has never been executed
 233   return true;
 234 }


 399     case Bytecodes::_putfield  :
 400     case Bytecodes::_getstatic :
 401     case Bytecodes::_putstatic :
 402     case Bytecodes::_aastore   :
 403 #ifdef COMPILER1
 404     //special case of reexecution
 405     case Bytecodes::_athrow    :
 406 #endif
 407       return true;
 408 
 409     default:
 410       return false;
 411   }
 412 }
 413 
 414 void AbstractInterpreter::initialize_method_handle_entries() {
 415   // method handle entry kinds are generated later in MethodHandlesAdapterGenerator::generate:
 416   for (int i = method_handle_invoke_FIRST; i <= method_handle_invoke_LAST; i++) {
 417     MethodKind kind = (MethodKind) i;
 418     _entry_table[kind] = _entry_table[Interpreter::abstract];

 419   }
 420 }


   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 "asm/macroAssembler.hpp"
  27 #include "asm/macroAssembler.inline.hpp"
  28 #include "compiler/disassembler.hpp"
  29 #include "interpreter/bytecodeHistogram.hpp"
  30 #include "interpreter/bytecodeInterpreter.hpp"
  31 #include "interpreter/interpreter.hpp"
  32 #include "interpreter/interpreterRuntime.hpp"
  33 #include "interpreter/interp_masm.hpp"
  34 #include "interpreter/templateTable.hpp"
  35 #include "memory/allocation.inline.hpp"
  36 #if INCLUDE_CDS
  37 #include "memory/metaspaceShared.hpp"
  38 #endif
  39 #include "memory/resourceArea.hpp"
  40 #include "oops/arrayOop.hpp"
  41 #include "oops/methodData.hpp"
  42 #include "oops/method.hpp"
  43 #include "oops/oop.inline.hpp"
  44 #include "prims/forte.hpp"
  45 #include "prims/jvmtiExport.hpp"
  46 #include "prims/methodHandles.hpp"
  47 #include "runtime/handles.inline.hpp"
  48 #include "runtime/sharedRuntime.hpp"
  49 #include "runtime/stubRoutines.hpp"
  50 #include "runtime/timer.hpp"
  51 
  52 # define __ _masm->
  53 
  54 //------------------------------------------------------------------------------------------------------------------------
  55 // Implementation of platform independent aspects of Interpreter
  56 
  57 void AbstractInterpreter::initialize() {
  58   if (_code != NULL) return;


  80     tty->print_cr("avg codelet size = %6d bytes", _code->used_space() / _code->number_of_stubs());
  81     tty->cr();
  82   }
  83   _code->print();
  84   tty->print_cr("----------------------------------------------------------------------");
  85   tty->cr();
  86 }
  87 
  88 
  89 //------------------------------------------------------------------------------------------------------------------------
  90 // Implementation of interpreter
  91 
  92 StubQueue* AbstractInterpreter::_code                                       = NULL;
  93 bool       AbstractInterpreter::_notice_safepoints                          = false;
  94 address    AbstractInterpreter::_rethrow_exception_entry                    = NULL;
  95 
  96 address    AbstractInterpreter::_native_entry_begin                         = NULL;
  97 address    AbstractInterpreter::_native_entry_end                           = NULL;
  98 address    AbstractInterpreter::_slow_signature_handler;
  99 address    AbstractInterpreter::_entry_table            [AbstractInterpreter::number_of_method_entries];
 100 address    AbstractInterpreter::_cds_entry_table        [AbstractInterpreter::number_of_method_entries];
 101 address    AbstractInterpreter::_native_abi_to_tosca    [AbstractInterpreter::number_of_result_handlers];
 102 
 103 //------------------------------------------------------------------------------------------------------------------------
 104 // Generation of complete interpreter
 105 
 106 AbstractInterpreterGenerator::AbstractInterpreterGenerator(StubQueue* _code) {
 107   _masm                      = NULL;
 108 }
 109 
 110 
 111 //------------------------------------------------------------------------------------------------------------------------
 112 // Entry points
 113 
 114 AbstractInterpreter::MethodKind AbstractInterpreter::method_kind(methodHandle m) {
 115   // Abstract method?
 116   if (m->is_abstract()) return abstract;
 117 
 118   // Method handle primitive?
 119   if (m->is_method_handle_intrinsic()) {
 120     vmIntrinsics::ID id = m->intrinsic_id();


 192     case vmIntrinsics::_dpow  : return java_lang_math_pow  ;
 193     case vmIntrinsics::_dexp  : return java_lang_math_exp  ;
 194 
 195     case vmIntrinsics::_Reference_get:
 196                                 return java_lang_ref_reference_get;
 197   }
 198 
 199   // Accessor method?
 200   if (m->is_getter()) {
 201     // TODO: We should have used ::is_accessor above, but fast accessors in Zero expect only getters.
 202     // See CppInterpreter::accessor_entry in cppInterpreter_zero.cpp. This should be fixed in Zero,
 203     // then the call above updated to ::is_accessor
 204     assert(m->size_of_parameters() == 1, "fast code for accessors assumes parameter size = 1");
 205     return accessor;
 206   }
 207 
 208   // Note: for now: zero locals for all non-empty methods
 209   return zerolocals;
 210 }
 211 
 212 #if INCLUDE_CDS
 213 
 214 address AbstractInterpreter::get_trampoline_code_buffer(AbstractInterpreter::MethodKind kind) {
 215   const size_t trampoline_size = SharedRuntime::trampoline_size();
 216   address addr = MetaspaceShared::cds_i2i_entry_code_buffers((size_t)(AbstractInterpreter::number_of_method_entries) * trampoline_size);
 217   addr += (size_t)(kind) * trampoline_size;
 218 
 219   return addr;
 220 }
 221 
 222 void AbstractInterpreter::update_cds_entry_table(AbstractInterpreter::MethodKind kind) {
 223   if (DumpSharedSpaces || UseSharedSpaces) {
 224     address trampoline = get_trampoline_code_buffer(kind);
 225     _cds_entry_table[kind] = trampoline;
 226 
 227     CodeBuffer buffer(trampoline, (int)(SharedRuntime::trampoline_size()));
 228     MacroAssembler _masm(&buffer);
 229     SharedRuntime::generate_trampoline(&_masm, _entry_table[kind]);
 230 
 231     if (PrintInterpreter) {
 232       Disassembler::decode(buffer.insts_begin(), buffer.insts_end());
 233     }
 234   }
 235 }
 236 
 237 #endif
 238 
 239 void AbstractInterpreter::set_entry_for_kind(AbstractInterpreter::MethodKind kind, address entry) {
 240   assert(kind >= method_handle_invoke_FIRST &&
 241          kind <= method_handle_invoke_LAST, "late initialization only for MH entry points");
 242   assert(_entry_table[kind] == _entry_table[abstract], "previous value must be AME entry");
 243   _entry_table[kind] = entry;

 244 
 245   update_cds_entry_table(kind);
 246 }
 247 
 248 // Return true if the interpreter can prove that the given bytecode has
 249 // not yet been executed (in Java semantics, not in actual operation).
 250 bool AbstractInterpreter::is_not_reached(const methodHandle& method, int bci) {
 251   Bytecodes::Code code = method()->code_at(bci);
 252 
 253   if (!Bytecodes::must_rewrite(code)) {
 254     // might have been reached
 255     return false;
 256   }
 257 
 258   // the bytecode might not be rewritten if the method is an accessor, etc.
 259   address ientry = method->interpreter_entry();
 260   if (ientry != entry_for_kind(AbstractInterpreter::zerolocals) &&
 261       ientry != entry_for_kind(AbstractInterpreter::zerolocals_synchronized))
 262     return false;  // interpreter does not run this method!
 263 
 264   // otherwise, we can be sure this bytecode has never been executed
 265   return true;
 266 }


 431     case Bytecodes::_putfield  :
 432     case Bytecodes::_getstatic :
 433     case Bytecodes::_putstatic :
 434     case Bytecodes::_aastore   :
 435 #ifdef COMPILER1
 436     //special case of reexecution
 437     case Bytecodes::_athrow    :
 438 #endif
 439       return true;
 440 
 441     default:
 442       return false;
 443   }
 444 }
 445 
 446 void AbstractInterpreter::initialize_method_handle_entries() {
 447   // method handle entry kinds are generated later in MethodHandlesAdapterGenerator::generate:
 448   for (int i = method_handle_invoke_FIRST; i <= method_handle_invoke_LAST; i++) {
 449     MethodKind kind = (MethodKind) i;
 450     _entry_table[kind] = _entry_table[Interpreter::abstract];
 451     Interpreter::update_cds_entry_table(kind);
 452   }
 453 }
src/share/vm/interpreter/abstractInterpreter.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File