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 "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 #include "memory/resourceArea.hpp"
  37 #include "oops/arrayOop.hpp"
  38 #include "oops/methodData.hpp"
  39 #include "oops/method.hpp"
  40 #include "oops/oop.inline.hpp"
  41 #include "prims/forte.hpp"
  42 #include "prims/jvmtiExport.hpp"
  43 #include "prims/methodHandles.hpp"
  44 #include "runtime/handles.inline.hpp"
  45 #include "runtime/sharedRuntime.hpp"
  46 #include "runtime/stubRoutines.hpp"
  47 #include "runtime/timer.hpp"
  48 
  49 # define __ _masm->
  50 
  51 
  52 //------------------------------------------------------------------------------------------------------------------------
  53 // Implementation of InterpreterCodelet
  54 
  55 void InterpreterCodelet::initialize(const char* description, Bytecodes::Code bytecode) {
  56   _description       = description;
  57   _bytecode          = bytecode;
  58 }
  59 
  60 
  61 void InterpreterCodelet::verify() {
  62 }
  63 
  64 
  65 void InterpreterCodelet::print_on(outputStream* st) const {
  66   ttyLocker ttyl;
  67 
  68   if (PrintInterpreter) {
  69     st->cr();
  70     st->print_cr("----------------------------------------------------------------------");
  71   }
  72 
  73   if (description() != NULL) st->print("%s  ", description());
  74   if (bytecode()    >= 0   ) st->print("%d %s  ", bytecode(), Bytecodes::name(bytecode()));
  75   st->print_cr("[" INTPTR_FORMAT ", " INTPTR_FORMAT "]  %d bytes",
  76                 p2i(code_begin()), p2i(code_end()), code_size());
  77 
  78   if (PrintInterpreter) {
  79     st->cr();
  80     Disassembler::decode(code_begin(), code_end(), st, DEBUG_ONLY(_strings) NOT_DEBUG(CodeStrings()));
  81   }
  82 }
  83 
  84 CodeletMark::CodeletMark(InterpreterMacroAssembler*& masm,
  85                          const char* description,
  86                          Bytecodes::Code bytecode) :
  87   _clet((InterpreterCodelet*)AbstractInterpreter::code()->request(codelet_size())),
  88   _cb(_clet->code_begin(), _clet->code_size()) {
  89   // Request all space (add some slack for Codelet data).
  90   assert(_clet != NULL, "we checked not enough space already");
  91 
  92   // Initialize Codelet attributes.
  93   _clet->initialize(description, bytecode);
  94   // Create assembler for code generation.
  95   masm = new InterpreterMacroAssembler(&_cb);
  96   _masm = &masm;
  97 }
  98 
  99 CodeletMark::~CodeletMark() {
 100   // Align so printing shows nop's instead of random code at the end (Codelets are aligned).
 101   (*_masm)->align(wordSize);
 102   // Make sure all code is in code buffer.
 103   (*_masm)->flush();
 104 
 105   // Commit Codelet.
 106   int committed_code_size = (*_masm)->code()->pure_insts_size();
 107   if (committed_code_size) {
 108     AbstractInterpreter::code()->commit(committed_code_size, (*_masm)->code()->strings());
 109   }
 110   // Make sure nobody can use _masm outside a CodeletMark lifespan.
 111   *_masm = NULL;
 112 }
 113 
 114 //------------------------------------------------------------------------------------------------------------------------
 115 // Implementation of platform independent aspects of Interpreter
 116 
 117 void AbstractInterpreter::initialize() {
 118   if (_code != NULL) return;
 119 
 120   // make sure 'imported' classes are initialized
 121   if (CountBytecodes || TraceBytecodes || StopInterpreterAt) BytecodeCounter::reset();
 122   if (PrintBytecodeHistogram)                                BytecodeHistogram::reset();
 123   if (PrintBytecodePairHistogram)                            BytecodePairHistogram::reset();
 124 
 125   InvocationCounter::reinitialize(DelayCompilationDuringStartup);
 126 
 127 }
 128 
 129 void AbstractInterpreter::print() {
 130   tty->cr();
 131   tty->print_cr("----------------------------------------------------------------------");
 132   tty->print_cr("Interpreter");
 133   tty->cr();
 134   tty->print_cr("code size        = %6dK bytes", (int)_code->used_space()/1024);
 135   tty->print_cr("total space      = %6dK bytes", (int)_code->total_space()/1024);
 136   tty->print_cr("wasted space     = %6dK bytes", (int)_code->available_space()/1024);
 137   tty->cr();
 138   tty->print_cr("# of codelets    = %6d"      , _code->number_of_stubs());
 139   if (_code->number_of_stubs() != 0) {
 140     tty->print_cr("avg codelet size = %6d bytes", _code->used_space() / _code->number_of_stubs());
 141     tty->cr();
 142   }
 143   _code->print();
 144   tty->print_cr("----------------------------------------------------------------------");
 145   tty->cr();
 146 }
 147 
 148 
 149 void interpreter_init() {
 150   Interpreter::initialize();
 151 #ifndef PRODUCT
 152   if (TraceBytecodes) BytecodeTracer::set_closure(BytecodeTracer::std_closure());
 153 #endif // PRODUCT
 154   // need to hit every safepoint in order to call zapping routine
 155   // register the interpreter
 156   Forte::register_stub(
 157     "Interpreter",
 158     AbstractInterpreter::code()->code_start(),
 159     AbstractInterpreter::code()->code_end()
 160   );
 161 
 162   // notify JVMTI profiler
 163   if (JvmtiExport::should_post_dynamic_code_generated()) {
 164     JvmtiExport::post_dynamic_code_generated("Interpreter",
 165                                              AbstractInterpreter::code()->code_start(),
 166                                              AbstractInterpreter::code()->code_end());
 167   }
 168 }
 169 
 170 //------------------------------------------------------------------------------------------------------------------------
 171 // Implementation of interpreter
 172 
 173 StubQueue* AbstractInterpreter::_code                                       = NULL;
 174 bool       AbstractInterpreter::_notice_safepoints                          = false;
 175 address    AbstractInterpreter::_rethrow_exception_entry                    = NULL;
 176 
 177 address    AbstractInterpreter::_native_entry_begin                         = NULL;
 178 address    AbstractInterpreter::_native_entry_end                           = NULL;
 179 address    AbstractInterpreter::_slow_signature_handler;
 180 address    AbstractInterpreter::_entry_table            [AbstractInterpreter::number_of_method_entries];
 181 address    AbstractInterpreter::_native_abi_to_tosca    [AbstractInterpreter::number_of_result_handlers];
 182 
 183 //------------------------------------------------------------------------------------------------------------------------
 184 // Generation of complete interpreter
 185 
 186 AbstractInterpreterGenerator::AbstractInterpreterGenerator(StubQueue* _code) {
 187   _masm                      = NULL;
 188 }
 189 
 190 
 191 static const BasicType types[Interpreter::number_of_result_handlers] = {
 192   T_BOOLEAN,
 193   T_CHAR   ,
 194   T_BYTE   ,
 195   T_SHORT  ,
 196   T_INT    ,
 197   T_LONG   ,
 198   T_VOID   ,
 199   T_FLOAT  ,
 200   T_DOUBLE ,
 201   T_OBJECT
 202 };
 203 
 204 void AbstractInterpreterGenerator::generate_all() {
 205 
 206 
 207   { CodeletMark cm(_masm, "slow signature handler");
 208     Interpreter::_slow_signature_handler = generate_slow_signature_handler();
 209   }
 210 
 211 }
 212 
 213 //------------------------------------------------------------------------------------------------------------------------
 214 // Entry points
 215 
 216 AbstractInterpreter::MethodKind AbstractInterpreter::method_kind(methodHandle m) {
 217   // Abstract method?
 218   if (m->is_abstract()) return abstract;
 219 
 220   // Method handle primitive?
 221   if (m->is_method_handle_intrinsic()) {
 222     vmIntrinsics::ID id = m->intrinsic_id();
 223     assert(MethodHandles::is_signature_polymorphic(id), "must match an intrinsic");
 224     MethodKind kind = (MethodKind)( method_handle_invoke_FIRST +
 225                                     ((int)id - vmIntrinsics::FIRST_MH_SIG_POLY) );
 226     assert(kind <= method_handle_invoke_LAST, "parallel enum ranges");
 227     return kind;
 228   }
 229 
 230 #ifndef CC_INTERP
 231   if (UseCRC32Intrinsics && m->is_native()) {
 232     // Use optimized stub code for CRC32 native methods.


 501     case Bytecodes::_if_icmple :
 502     case Bytecodes::_if_acmpeq :
 503     case Bytecodes::_if_acmpne :
 504     // special cases
 505     case Bytecodes::_getfield  :
 506     case Bytecodes::_putfield  :
 507     case Bytecodes::_getstatic :
 508     case Bytecodes::_putstatic :
 509     case Bytecodes::_aastore   :
 510 #ifdef COMPILER1
 511     //special case of reexecution
 512     case Bytecodes::_athrow    :
 513 #endif
 514       return true;
 515 
 516     default:
 517       return false;
 518   }
 519 }
 520 
 521 void AbstractInterpreterGenerator::bang_stack_shadow_pages(bool native_call) {
 522   // Quick & dirty stack overflow checking: bang the stack & handle trap.
 523   // Note that we do the banging after the frame is setup, since the exception
 524   // handling code expects to find a valid interpreter frame on the stack.
 525   // Doing the banging earlier fails if the caller frame is not an interpreter
 526   // frame.
 527   // (Also, the exception throwing code expects to unlock any synchronized
 528   // method receiever, so do the banging after locking the receiver.)
 529 
 530   // Bang each page in the shadow zone. We can't assume it's been done for
 531   // an interpreter frame with greater than a page of locals, so each page
 532   // needs to be checked.  Only true for non-native.
 533   if (UseStackBanging) {
 534     const int page_size = os::vm_page_size();
 535     const int n_shadow_pages = ((int)JavaThread::stack_shadow_zone_size()) / page_size;
 536     const int start_page = native_call ? n_shadow_pages : 1;
 537     for (int pages = start_page; pages <= n_shadow_pages; pages++) {
 538       __ bang_stack_with_offset(pages*page_size);
 539     }
 540   }
 541 }
 542 
 543 void AbstractInterpreterGenerator::initialize_method_handle_entries() {
 544   // method handle entry kinds are generated later in MethodHandlesAdapterGenerator::generate:
 545   for (int i = Interpreter::method_handle_invoke_FIRST; i <= Interpreter::method_handle_invoke_LAST; i++) {
 546     Interpreter::MethodKind kind = (Interpreter::MethodKind) i;
 547     Interpreter::_entry_table[kind] = Interpreter::_entry_table[Interpreter::abstract];
 548   }
 549 }


   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;
  55 
  56   // make sure 'imported' classes are initialized
  57   if (CountBytecodes || TraceBytecodes || StopInterpreterAt) BytecodeCounter::reset();
  58   if (PrintBytecodeHistogram)                                BytecodeHistogram::reset();
  59   if (PrintBytecodePairHistogram)                            BytecodePairHistogram::reset();
  60 
  61   InvocationCounter::reinitialize(DelayCompilationDuringStartup);
  62 
  63 }
  64 
  65 void AbstractInterpreter::print() {
  66   tty->cr();
  67   tty->print_cr("----------------------------------------------------------------------");
  68   tty->print_cr("Interpreter");
  69   tty->cr();
  70   tty->print_cr("code size        = %6dK bytes", (int)_code->used_space()/1024);
  71   tty->print_cr("total space      = %6dK bytes", (int)_code->total_space()/1024);
  72   tty->print_cr("wasted space     = %6dK bytes", (int)_code->available_space()/1024);
  73   tty->cr();
  74   tty->print_cr("# of codelets    = %6d"      , _code->number_of_stubs());
  75   if (_code->number_of_stubs() != 0) {
  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();
 116     assert(MethodHandles::is_signature_polymorphic(id), "must match an intrinsic");
 117     MethodKind kind = (MethodKind)( method_handle_invoke_FIRST +
 118                                     ((int)id - vmIntrinsics::FIRST_MH_SIG_POLY) );
 119     assert(kind <= method_handle_invoke_LAST, "parallel enum ranges");
 120     return kind;
 121   }
 122 
 123 #ifndef CC_INTERP
 124   if (UseCRC32Intrinsics && m->is_native()) {
 125     // Use optimized stub code for CRC32 native methods.


 394     case Bytecodes::_if_icmple :
 395     case Bytecodes::_if_acmpeq :
 396     case Bytecodes::_if_acmpne :
 397     // special cases
 398     case Bytecodes::_getfield  :
 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 }