interpreter.cpp revision 9867:3125c4a60cc9
1336809Sdim/* 2336809Sdim * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. 3353358Sdim * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4353358Sdim * 5353358Sdim * This code is free software; you can redistribute it and/or modify it 6336809Sdim * under the terms of the GNU General Public License version 2 only, as 7336809Sdim * published by the Free Software Foundation. 8336809Sdim * 9336809Sdim * This code is distributed in the hope that it will be useful, but WITHOUT 10336809Sdim * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11336809Sdim * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12336809Sdim * version 2 for more details (a copy is included in the LICENSE file that 13336809Sdim * accompanied this code). 14336809Sdim * 15336809Sdim * You should have received a copy of the GNU General Public License version 16336809Sdim * 2 along with this work; if not, write to the Free Software Foundation, 17336809Sdim * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18336809Sdim * 19336809Sdim * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20336809Sdim * or visit www.oracle.com if you need additional information or have any 21336809Sdim * questions. 22336809Sdim * 23336809Sdim */ 24336809Sdim 25336809Sdim#include "precompiled.hpp" 26336809Sdim#include "asm/macroAssembler.hpp" 27336809Sdim#include "asm/macroAssembler.inline.hpp" 28336809Sdim#include "compiler/disassembler.hpp" 29336809Sdim#include "interpreter/bytecodeHistogram.hpp" 30336809Sdim#include "interpreter/bytecodeInterpreter.hpp" 31336809Sdim#include "interpreter/interpreter.hpp" 32336809Sdim#include "interpreter/interpreterGenerator.hpp" 33336809Sdim#include "interpreter/interpreterRuntime.hpp" 34336809Sdim#include "interpreter/interp_masm.hpp" 35336809Sdim#include "interpreter/templateTable.hpp" 36336809Sdim#include "memory/allocation.inline.hpp" 37336809Sdim#include "memory/resourceArea.hpp" 38360784Sdim#include "oops/arrayOop.hpp" 39336809Sdim#include "oops/methodData.hpp" 40336809Sdim#include "oops/method.hpp" 41336809Sdim#include "oops/oop.inline.hpp" 42336809Sdim#include "prims/forte.hpp" 43336809Sdim#include "prims/jvmtiExport.hpp" 44336809Sdim#include "prims/methodHandles.hpp" 45336809Sdim#include "runtime/handles.inline.hpp" 46336809Sdim#include "runtime/sharedRuntime.hpp" 47336809Sdim#include "runtime/stubRoutines.hpp" 48336809Sdim#include "runtime/timer.hpp" 49360784Sdim 50336809Sdim# define __ _masm-> 51336809Sdim 52336809Sdim 53336809Sdim//------------------------------------------------------------------------------------------------------------------------ 54336809Sdim// Implementation of InterpreterCodelet 55336809Sdim 56336809Sdimvoid InterpreterCodelet::initialize(const char* description, Bytecodes::Code bytecode) { 57336809Sdim _description = description; 58336809Sdim _bytecode = bytecode; 59336809Sdim} 60336809Sdim 61336809Sdim 62336809Sdimvoid InterpreterCodelet::verify() { 63336809Sdim} 64336809Sdim 65336809Sdim 66336809Sdimvoid InterpreterCodelet::print_on(outputStream* st) const { 67336809Sdim ttyLocker ttyl; 68336809Sdim 69336809Sdim if (PrintInterpreter) { 70336809Sdim st->cr(); 71336809Sdim st->print_cr("----------------------------------------------------------------------"); 72336809Sdim } 73353358Sdim 74336809Sdim if (description() != NULL) st->print("%s ", description()); 75336809Sdim if (bytecode() >= 0 ) st->print("%d %s ", bytecode(), Bytecodes::name(bytecode())); 76336809Sdim st->print_cr("[" INTPTR_FORMAT ", " INTPTR_FORMAT "] %d bytes", 77336809Sdim p2i(code_begin()), p2i(code_end()), code_size()); 78336809Sdim 79336809Sdim if (PrintInterpreter) { 80336809Sdim st->cr(); 81336809Sdim Disassembler::decode(code_begin(), code_end(), st, DEBUG_ONLY(_strings) NOT_DEBUG(CodeStrings())); 82336809Sdim } 83336809Sdim} 84336809Sdim 85336809SdimCodeletMark::CodeletMark(InterpreterMacroAssembler*& masm, 86336809Sdim const char* description, 87360784Sdim Bytecodes::Code bytecode) : 88360784Sdim _clet((InterpreterCodelet*)AbstractInterpreter::code()->request(codelet_size())), 89360784Sdim _cb(_clet->code_begin(), _clet->code_size()) { 90336809Sdim // Request all space (add some slack for Codelet data). 91336809Sdim assert(_clet != NULL, "we checked not enough space already"); 92336809Sdim 93360784Sdim // Initialize Codelet attributes. 94336809Sdim _clet->initialize(description, bytecode); 95336809Sdim // Create assembler for code generation. 96336809Sdim masm = new InterpreterMacroAssembler(&_cb); 97336809Sdim _masm = &masm; 98336809Sdim} 99336809Sdim 100336809SdimCodeletMark::~CodeletMark() { 101336809Sdim // Align so printing shows nop's instead of random code at the end (Codelets are aligned). 102336809Sdim (*_masm)->align(wordSize); 103336809Sdim // Make sure all code is in code buffer. 104336809Sdim (*_masm)->flush(); 105336809Sdim 106336809Sdim // Commit Codelet. 107336809Sdim int committed_code_size = (*_masm)->code()->pure_insts_size(); 108336809Sdim if (committed_code_size) { 109336809Sdim AbstractInterpreter::code()->commit(committed_code_size, (*_masm)->code()->strings()); 110336809Sdim } 111336809Sdim // Make sure nobody can use _masm outside a CodeletMark lifespan. 112336809Sdim *_masm = NULL; 113336809Sdim} 114336809Sdim 115336809Sdim//------------------------------------------------------------------------------------------------------------------------ 116336809Sdim// Implementation of platform independent aspects of Interpreter 117336809Sdim 118336809Sdimvoid AbstractInterpreter::initialize() { 119336809Sdim if (_code != NULL) return; 120336809Sdim 121336809Sdim // make sure 'imported' classes are initialized 122336809Sdim if (CountBytecodes || TraceBytecodes || StopInterpreterAt) BytecodeCounter::reset(); 123336809Sdim if (PrintBytecodeHistogram) BytecodeHistogram::reset(); 124336809Sdim if (PrintBytecodePairHistogram) BytecodePairHistogram::reset(); 125336809Sdim 126336809Sdim InvocationCounter::reinitialize(DelayCompilationDuringStartup); 127336809Sdim 128336809Sdim} 129336809Sdim 130336809Sdimvoid AbstractInterpreter::print() { 131336809Sdim tty->cr(); 132336809Sdim tty->print_cr("----------------------------------------------------------------------"); 133336809Sdim tty->print_cr("Interpreter"); 134336809Sdim tty->cr(); 135336809Sdim tty->print_cr("code size = %6dK bytes", (int)_code->used_space()/1024); 136336809Sdim tty->print_cr("total space = %6dK bytes", (int)_code->total_space()/1024); 137336809Sdim tty->print_cr("wasted space = %6dK bytes", (int)_code->available_space()/1024); 138336809Sdim tty->cr(); 139336809Sdim tty->print_cr("# of codelets = %6d" , _code->number_of_stubs()); 140336809Sdim if (_code->number_of_stubs() != 0) { 141336809Sdim tty->print_cr("avg codelet size = %6d bytes", _code->used_space() / _code->number_of_stubs()); 142336809Sdim tty->cr(); 143336809Sdim } 144336809Sdim _code->print(); 145336809Sdim tty->print_cr("----------------------------------------------------------------------"); 146336809Sdim tty->cr(); 147336809Sdim} 148336809Sdim 149336809Sdim 150336809Sdimvoid interpreter_init() { 151336809Sdim Interpreter::initialize(); 152336809Sdim#ifndef PRODUCT 153336809Sdim if (TraceBytecodes) BytecodeTracer::set_closure(BytecodeTracer::std_closure()); 154336809Sdim#endif // PRODUCT 155336809Sdim // need to hit every safepoint in order to call zapping routine 156336809Sdim // register the interpreter 157336809Sdim Forte::register_stub( 158336809Sdim "Interpreter", 159336809Sdim AbstractInterpreter::code()->code_start(), 160336809Sdim AbstractInterpreter::code()->code_end() 161336809Sdim ); 162336809Sdim 163336809Sdim // notify JVMTI profiler 164336809Sdim if (JvmtiExport::should_post_dynamic_code_generated()) { 165336809Sdim JvmtiExport::post_dynamic_code_generated("Interpreter", 166336809Sdim AbstractInterpreter::code()->code_start(), 167336809Sdim AbstractInterpreter::code()->code_end()); 168336809Sdim } 169336809Sdim} 170336809Sdim 171336809Sdim//------------------------------------------------------------------------------------------------------------------------ 172336809Sdim// Implementation of interpreter 173336809Sdim 174336809SdimStubQueue* AbstractInterpreter::_code = NULL; 175336809Sdimbool AbstractInterpreter::_notice_safepoints = false; 176336809Sdimaddress AbstractInterpreter::_rethrow_exception_entry = NULL; 177336809Sdim 178336809Sdimaddress AbstractInterpreter::_native_entry_begin = NULL; 179336809Sdimaddress AbstractInterpreter::_native_entry_end = NULL; 180336809Sdimaddress AbstractInterpreter::_slow_signature_handler; 181336809Sdimaddress AbstractInterpreter::_entry_table [AbstractInterpreter::number_of_method_entries]; 182336809Sdimaddress AbstractInterpreter::_native_abi_to_tosca [AbstractInterpreter::number_of_result_handlers]; 183336809Sdim 184336809Sdim//------------------------------------------------------------------------------------------------------------------------ 185336809Sdim// Generation of complete interpreter 186336809Sdim 187336809SdimAbstractInterpreterGenerator::AbstractInterpreterGenerator(StubQueue* _code) { 188336809Sdim _masm = NULL; 189336809Sdim} 190336809Sdim 191336809Sdim 192336809Sdimstatic const BasicType types[Interpreter::number_of_result_handlers] = { 193336809Sdim T_BOOLEAN, 194336809Sdim T_CHAR , 195336809Sdim T_BYTE , 196336809Sdim T_SHORT , 197336809Sdim T_INT , 198336809Sdim T_LONG , 199336809Sdim T_VOID , 200336809Sdim T_FLOAT , 201336809Sdim T_DOUBLE , 202336809Sdim T_OBJECT 203336809Sdim}; 204336809Sdim 205336809Sdimvoid AbstractInterpreterGenerator::generate_all() { 206336809Sdim 207336809Sdim 208336809Sdim { CodeletMark cm(_masm, "slow signature handler"); 209336809Sdim Interpreter::_slow_signature_handler = generate_slow_signature_handler(); 210336809Sdim } 211336809Sdim 212336809Sdim} 213336809Sdim 214336809Sdim//------------------------------------------------------------------------------------------------------------------------ 215336809Sdim// Entry points 216336809Sdim 217336809SdimAbstractInterpreter::MethodKind AbstractInterpreter::method_kind(methodHandle m) { 218336809Sdim // Abstract method? 219336809Sdim if (m->is_abstract()) return abstract; 220336809Sdim 221336809Sdim // Method handle primitive? 222336809Sdim if (m->is_method_handle_intrinsic()) { 223336809Sdim vmIntrinsics::ID id = m->intrinsic_id(); 224336809Sdim assert(MethodHandles::is_signature_polymorphic(id), "must match an intrinsic"); 225336809Sdim MethodKind kind = (MethodKind)( method_handle_invoke_FIRST + 226336809Sdim ((int)id - vmIntrinsics::FIRST_MH_SIG_POLY) ); 227336809Sdim assert(kind <= method_handle_invoke_LAST, "parallel enum ranges"); 228336809Sdim return kind; 229336809Sdim } 230336809Sdim 231336809Sdim#ifndef CC_INTERP 232336809Sdim if (UseCRC32Intrinsics && m->is_native()) { 233336809Sdim // Use optimized stub code for CRC32 native methods. 234336809Sdim switch (m->intrinsic_id()) { 235336809Sdim case vmIntrinsics::_updateCRC32 : return java_util_zip_CRC32_update; 236336809Sdim case vmIntrinsics::_updateBytesCRC32 : return java_util_zip_CRC32_updateBytes; 237336809Sdim case vmIntrinsics::_updateByteBufferCRC32 : return java_util_zip_CRC32_updateByteBuffer; 238336809Sdim } 239336809Sdim } 240336809Sdim if (UseCRC32CIntrinsics) { 241336809Sdim // Use optimized stub code for CRC32C methods. 242336809Sdim switch (m->intrinsic_id()) { 243336809Sdim case vmIntrinsics::_updateBytesCRC32C : return java_util_zip_CRC32C_updateBytes; 244336809Sdim case vmIntrinsics::_updateDirectByteBufferCRC32C : return java_util_zip_CRC32C_updateDirectByteBuffer; 245336809Sdim } 246336809Sdim } 247336809Sdim 248336809Sdim switch(m->intrinsic_id()) { 249336809Sdim case vmIntrinsics::_intBitsToFloat: return java_lang_Float_intBitsToFloat; 250336809Sdim case vmIntrinsics::_floatToRawIntBits: return java_lang_Float_floatToRawIntBits; 251336809Sdim case vmIntrinsics::_longBitsToDouble: return java_lang_Double_longBitsToDouble; 252336809Sdim case vmIntrinsics::_doubleToRawLongBits: return java_lang_Double_doubleToRawLongBits; 253336809Sdim } 254336809Sdim 255336809Sdim#endif // CC_INTERP 256336809Sdim 257336809Sdim // Native method? 258336809Sdim // Note: This test must come _before_ the test for intrinsic 259336809Sdim // methods. See also comments below. 260336809Sdim if (m->is_native()) { 261336809Sdim assert(!m->is_method_handle_intrinsic(), "overlapping bits here, watch out"); 262336809Sdim return m->is_synchronized() ? native_synchronized : native; 263336809Sdim } 264336809Sdim 265336809Sdim // Synchronized? 266336809Sdim if (m->is_synchronized()) { 267336809Sdim return zerolocals_synchronized; 268336809Sdim } 269336809Sdim 270336809Sdim if (RegisterFinalizersAtInit && m->code_size() == 1 && 271336809Sdim m->intrinsic_id() == vmIntrinsics::_Object_init) { 272336809Sdim // We need to execute the special return bytecode to check for 273336809Sdim // finalizer registration so create a normal frame. 274336809Sdim return zerolocals; 275336809Sdim } 276336809Sdim 277336809Sdim // Empty method? 278336809Sdim if (m->is_empty_method()) { 279336809Sdim return empty; 280336809Sdim } 281336809Sdim 282336809Sdim // Special intrinsic method? 283336809Sdim // Note: This test must come _after_ the test for native methods, 284336809Sdim // otherwise we will run into problems with JDK 1.2, see also 285336809Sdim // InterpreterGenerator::generate_method_entry() for 286336809Sdim // for details. 287336809Sdim switch (m->intrinsic_id()) { 288336809Sdim case vmIntrinsics::_dsin : return java_lang_math_sin ; 289336809Sdim case vmIntrinsics::_dcos : return java_lang_math_cos ; 290336809Sdim case vmIntrinsics::_dtan : return java_lang_math_tan ; 291336809Sdim case vmIntrinsics::_dabs : return java_lang_math_abs ; 292336809Sdim case vmIntrinsics::_dsqrt : return java_lang_math_sqrt ; 293336809Sdim case vmIntrinsics::_dlog : return java_lang_math_log ; 294336809Sdim case vmIntrinsics::_dlog10: return java_lang_math_log10; 295336809Sdim case vmIntrinsics::_dpow : return java_lang_math_pow ; 296336809Sdim case vmIntrinsics::_dexp : return java_lang_math_exp ; 297336809Sdim 298336809Sdim case vmIntrinsics::_Reference_get: 299336809Sdim return java_lang_ref_reference_get; 300336809Sdim } 301336809Sdim 302336809Sdim // Accessor method? 303336809Sdim if (m->is_getter()) { 304336809Sdim // TODO: We should have used ::is_accessor above, but fast accessors in Zero expect only getters. 305336809Sdim // See CppInterpreter::accessor_entry in cppInterpreter_zero.cpp. This should be fixed in Zero, 306336809Sdim // then the call above updated to ::is_accessor 307336809Sdim assert(m->size_of_parameters() == 1, "fast code for accessors assumes parameter size = 1"); 308336809Sdim return accessor; 309336809Sdim } 310336809Sdim 311336809Sdim // Note: for now: zero locals for all non-empty methods 312336809Sdim return zerolocals; 313336809Sdim} 314336809Sdim 315336809Sdim 316336809Sdimvoid AbstractInterpreter::set_entry_for_kind(AbstractInterpreter::MethodKind kind, address entry) { 317336809Sdim assert(kind >= method_handle_invoke_FIRST && 318336809Sdim kind <= method_handle_invoke_LAST, "late initialization only for MH entry points"); 319336809Sdim assert(_entry_table[kind] == _entry_table[abstract], "previous value must be AME entry"); 320336809Sdim _entry_table[kind] = entry; 321336809Sdim} 322336809Sdim 323336809Sdim 324336809Sdim// Return true if the interpreter can prove that the given bytecode has 325336809Sdim// not yet been executed (in Java semantics, not in actual operation). 326336809Sdimbool AbstractInterpreter::is_not_reached(const methodHandle& method, int bci) { 327336809Sdim Bytecodes::Code code = method()->code_at(bci); 328336809Sdim 329336809Sdim if (!Bytecodes::must_rewrite(code)) { 330336809Sdim // might have been reached 331336809Sdim return false; 332336809Sdim } 333336809Sdim 334336809Sdim // the bytecode might not be rewritten if the method is an accessor, etc. 335336809Sdim address ientry = method->interpreter_entry(); 336336809Sdim if (ientry != entry_for_kind(AbstractInterpreter::zerolocals) && 337336809Sdim ientry != entry_for_kind(AbstractInterpreter::zerolocals_synchronized)) 338336809Sdim return false; // interpreter does not run this method! 339336809Sdim 340336809Sdim // otherwise, we can be sure this bytecode has never been executed 341336809Sdim return true; 342336809Sdim} 343336809Sdim 344336809Sdim 345353358Sdim#ifndef PRODUCT 346353358Sdimvoid AbstractInterpreter::print_method_kind(MethodKind kind) { 347336809Sdim switch (kind) { 348336809Sdim case zerolocals : tty->print("zerolocals" ); break; 349336809Sdim case zerolocals_synchronized: tty->print("zerolocals_synchronized"); break; 350336809Sdim case native : tty->print("native" ); break; 351336809Sdim case native_synchronized : tty->print("native_synchronized" ); break; 352336809Sdim case empty : tty->print("empty" ); break; 353336809Sdim case accessor : tty->print("accessor" ); break; 354336809Sdim case abstract : tty->print("abstract" ); break; 355336809Sdim case java_lang_math_sin : tty->print("java_lang_math_sin" ); break; 356336809Sdim case java_lang_math_cos : tty->print("java_lang_math_cos" ); break; 357336809Sdim case java_lang_math_tan : tty->print("java_lang_math_tan" ); break; 358336809Sdim case java_lang_math_abs : tty->print("java_lang_math_abs" ); break; 359336809Sdim case java_lang_math_sqrt : tty->print("java_lang_math_sqrt" ); break; 360336809Sdim case java_lang_math_log : tty->print("java_lang_math_log" ); break; 361336809Sdim case java_lang_math_log10 : tty->print("java_lang_math_log10" ); break; 362336809Sdim case java_util_zip_CRC32_update : tty->print("java_util_zip_CRC32_update"); break; 363336809Sdim case java_util_zip_CRC32_updateBytes : tty->print("java_util_zip_CRC32_updateBytes"); break; 364336809Sdim case java_util_zip_CRC32_updateByteBuffer : tty->print("java_util_zip_CRC32_updateByteBuffer"); break; 365336809Sdim case java_util_zip_CRC32C_updateBytes : tty->print("java_util_zip_CRC32C_updateBytes"); break; 366336809Sdim case java_util_zip_CRC32C_updateDirectByteBuffer: tty->print("java_util_zip_CRC32C_updateDirectByteByffer"); break; 367336809Sdim default: 368336809Sdim if (kind >= method_handle_invoke_FIRST && 369336809Sdim kind <= method_handle_invoke_LAST) { 370353358Sdim const char* kind_name = vmIntrinsics::name_at(method_handle_intrinsic(kind)); 371353358Sdim if (kind_name[0] == '_') kind_name = &kind_name[1]; // '_invokeExact' => 'invokeExact' 372336809Sdim tty->print("method_handle_%s", kind_name); 373336809Sdim break; 374336809Sdim } 375336809Sdim ShouldNotReachHere(); 376336809Sdim break; 377336809Sdim } 378336809Sdim} 379336809Sdim#endif // PRODUCT 380336809Sdim 381336809Sdim 382336809Sdim//------------------------------------------------------------------------------------------------------------------------ 383336809Sdim// Deoptimization support 384336809Sdim 385336809Sdim/** 386336809Sdim * If a deoptimization happens, this function returns the point of next bytecode to continue execution. 387336809Sdim */ 388336809Sdimaddress AbstractInterpreter::deopt_continue_after_entry(Method* method, address bcp, int callee_parameters, bool is_top_frame) { 389336809Sdim assert(method->contains(bcp), "just checkin'"); 390336809Sdim 391336809Sdim // Get the original and rewritten bytecode. 392336809Sdim Bytecodes::Code code = Bytecodes::java_code_at(method, bcp); 393336809Sdim assert(!Interpreter::bytecode_should_reexecute(code), "should not reexecute"); 394336809Sdim 395360784Sdim const int bci = method->bci_from(bcp); 396336809Sdim 397336809Sdim // compute continuation length 398336809Sdim const int length = Bytecodes::length_at(method, bcp); 399336809Sdim 400336809Sdim // compute result type 401336809Sdim BasicType type = T_ILLEGAL; 402336809Sdim 403336809Sdim switch (code) { 404336809Sdim case Bytecodes::_invokevirtual : 405336809Sdim case Bytecodes::_invokespecial : 406336809Sdim case Bytecodes::_invokestatic : 407336809Sdim case Bytecodes::_invokeinterface: { 408336809Sdim Thread *thread = Thread::current(); 409336809Sdim ResourceMark rm(thread); 410336809Sdim methodHandle mh(thread, method); 411336809Sdim type = Bytecode_invoke(mh, bci).result_type(); 412336809Sdim // since the cache entry might not be initialized: 413353358Sdim // (NOT needed for the old calling convension) 414353358Sdim if (!is_top_frame) { 415353358Sdim int index = Bytes::get_native_u2(bcp+1); 416353358Sdim method->constants()->cache()->entry_at(index)->set_parameter_size(callee_parameters); 417336809Sdim } 418336809Sdim break; 419336809Sdim } 420336809Sdim 421336809Sdim case Bytecodes::_invokedynamic: { 422336809Sdim Thread *thread = Thread::current(); 423336809Sdim ResourceMark rm(thread); 424336809Sdim methodHandle mh(thread, method); 425336809Sdim type = Bytecode_invoke(mh, bci).result_type(); 426336809Sdim // since the cache entry might not be initialized: 427336809Sdim // (NOT needed for the old calling convension) 428336809Sdim if (!is_top_frame) { 429336809Sdim int index = Bytes::get_native_u4(bcp+1); 430336809Sdim method->constants()->invokedynamic_cp_cache_entry_at(index)->set_parameter_size(callee_parameters); 431336809Sdim } 432336809Sdim break; 433336809Sdim } 434336809Sdim 435336809Sdim case Bytecodes::_ldc : 436336809Sdim case Bytecodes::_ldc_w : // fall through 437336809Sdim case Bytecodes::_ldc2_w: 438336809Sdim { 439336809Sdim Thread *thread = Thread::current(); 440336809Sdim ResourceMark rm(thread); 441336809Sdim methodHandle mh(thread, method); 442336809Sdim type = Bytecode_loadconstant(mh, bci).result_type(); 443336809Sdim break; 444336809Sdim } 445336809Sdim 446336809Sdim default: 447336809Sdim type = Bytecodes::result_type(code); 448336809Sdim break; 449336809Sdim } 450336809Sdim 451336809Sdim // return entry point for computed continuation state & bytecode length 452336809Sdim return 453336809Sdim is_top_frame 454336809Sdim ? Interpreter::deopt_entry (as_TosState(type), length) 455336809Sdim : Interpreter::return_entry(as_TosState(type), length, code); 456336809Sdim} 457336809Sdim 458336809Sdim// If deoptimization happens, this function returns the point where the interpreter reexecutes 459336809Sdim// the bytecode. 460336809Sdim// Note: Bytecodes::_athrow is a special case in that it does not return 461336809Sdim// Interpreter::deopt_entry(vtos, 0) like others 462336809Sdimaddress AbstractInterpreter::deopt_reexecute_entry(Method* method, address bcp) { 463336809Sdim assert(method->contains(bcp), "just checkin'"); 464336809Sdim Bytecodes::Code code = Bytecodes::java_code_at(method, bcp); 465336809Sdim#if defined(COMPILER1) || INCLUDE_JVMCI 466336809Sdim if(code == Bytecodes::_athrow ) { 467336809Sdim return Interpreter::rethrow_exception_entry(); 468336809Sdim } 469336809Sdim#endif /* COMPILER1 || INCLUDE_JVMCI */ 470336809Sdim return Interpreter::deopt_entry(vtos, 0); 471336809Sdim} 472336809Sdim 473336809Sdim// If deoptimization happens, the interpreter should reexecute these bytecodes. 474336809Sdim// This function mainly helps the compilers to set up the reexecute bit. 475336809Sdimbool AbstractInterpreter::bytecode_should_reexecute(Bytecodes::Code code) { 476336809Sdim switch (code) { 477336809Sdim case Bytecodes::_lookupswitch: 478336809Sdim case Bytecodes::_tableswitch: 479336809Sdim case Bytecodes::_fast_binaryswitch: 480336809Sdim case Bytecodes::_fast_linearswitch: 481336809Sdim // recompute condtional expression folded into _if<cond> 482336809Sdim case Bytecodes::_lcmp : 483336809Sdim case Bytecodes::_fcmpl : 484336809Sdim case Bytecodes::_fcmpg : 485336809Sdim case Bytecodes::_dcmpl : 486336809Sdim case Bytecodes::_dcmpg : 487336809Sdim case Bytecodes::_ifnull : 488336809Sdim case Bytecodes::_ifnonnull : 489336809Sdim case Bytecodes::_goto : 490336809Sdim case Bytecodes::_goto_w : 491336809Sdim case Bytecodes::_ifeq : 492336809Sdim case Bytecodes::_ifne : 493336809Sdim case Bytecodes::_iflt : 494336809Sdim case Bytecodes::_ifge : 495336809Sdim case Bytecodes::_ifgt : 496336809Sdim case Bytecodes::_ifle : 497336809Sdim case Bytecodes::_if_icmpeq : 498336809Sdim case Bytecodes::_if_icmpne : 499336809Sdim case Bytecodes::_if_icmplt : 500336809Sdim case Bytecodes::_if_icmpge : 501353358Sdim case Bytecodes::_if_icmpgt : 502353358Sdim case Bytecodes::_if_icmple : 503353358Sdim case Bytecodes::_if_acmpeq : 504336809Sdim case Bytecodes::_if_acmpne : 505336809Sdim // special cases 506336809Sdim case Bytecodes::_getfield : 507336809Sdim case Bytecodes::_putfield : 508336809Sdim case Bytecodes::_getstatic : 509336809Sdim case Bytecodes::_putstatic : 510353358Sdim case Bytecodes::_aastore : 511336809Sdim#ifdef COMPILER1 512336809Sdim //special case of reexecution 513336809Sdim case Bytecodes::_athrow : 514336809Sdim#endif 515336809Sdim return true; 516353358Sdim 517336809Sdim default: 518336809Sdim return false; 519336809Sdim } 520336809Sdim} 521336809Sdim 522336809Sdimvoid AbstractInterpreterGenerator::bang_stack_shadow_pages(bool native_call) { 523336809Sdim // Quick & dirty stack overflow checking: bang the stack & handle trap. 524336809Sdim // Note that we do the banging after the frame is setup, since the exception 525336809Sdim // handling code expects to find a valid interpreter frame on the stack. 526336809Sdim // Doing the banging earlier fails if the caller frame is not an interpreter 527336809Sdim // frame. 528336809Sdim // (Also, the exception throwing code expects to unlock any synchronized 529336809Sdim // method receiever, so do the banging after locking the receiver.) 530336809Sdim 531336809Sdim // Bang each page in the shadow zone. We can't assume it's been done for 532336809Sdim // an interpreter frame with greater than a page of locals, so each page 533336809Sdim // needs to be checked. Only true for non-native. 534336809Sdim if (UseStackBanging) { 535336809Sdim const int page_size = os::vm_page_size(); 536336809Sdim const int n_shadow_pages = ((int)JavaThread::stack_shadow_zone_size()) / page_size; 537336809Sdim const int start_page = native_call ? n_shadow_pages : 1; 538336809Sdim for (int pages = start_page; pages <= n_shadow_pages; pages++) { 539336809Sdim __ bang_stack_with_offset(pages*page_size); 540336809Sdim } 541336809Sdim } 542336809Sdim} 543353358Sdim 544336809Sdimvoid AbstractInterpreterGenerator::initialize_method_handle_entries() { 545336809Sdim // method handle entry kinds are generated later in MethodHandlesAdapterGenerator::generate: 546336809Sdim for (int i = Interpreter::method_handle_invoke_FIRST; i <= Interpreter::method_handle_invoke_LAST; i++) { 547336809Sdim Interpreter::MethodKind kind = (Interpreter::MethodKind) i; 548336809Sdim Interpreter::_entry_table[kind] = Interpreter::_entry_table[Interpreter::abstract]; 549336809Sdim } 550336809Sdim} 551336809Sdim 552336809Sdim// Generate method entries 553336809Sdimaddress InterpreterGenerator::generate_method_entry( 554336809Sdim AbstractInterpreter::MethodKind kind) { 555336809Sdim // determine code generation flags 556336809Sdim bool native = false; 557336809Sdim bool synchronized = false; 558336809Sdim address entry_point = NULL; 559336809Sdim 560336809Sdim switch (kind) { 561336809Sdim case Interpreter::zerolocals : break; 562336809Sdim case Interpreter::zerolocals_synchronized: synchronized = true; break; 563336809Sdim case Interpreter::native : native = true; break; 564336809Sdim case Interpreter::native_synchronized : native = true; synchronized = true; break; 565336809Sdim case Interpreter::empty : entry_point = generate_empty_entry(); break; 566336809Sdim case Interpreter::accessor : entry_point = generate_accessor_entry(); break; 567336809Sdim case Interpreter::abstract : entry_point = generate_abstract_entry(); break; 568336809Sdim 569336809Sdim case Interpreter::java_lang_math_sin : // fall thru 570336809Sdim case Interpreter::java_lang_math_cos : // fall thru 571336809Sdim case Interpreter::java_lang_math_tan : // fall thru 572336809Sdim case Interpreter::java_lang_math_abs : // fall thru 573336809Sdim case Interpreter::java_lang_math_log : // fall thru 574336809Sdim case Interpreter::java_lang_math_log10 : // fall thru 575336809Sdim case Interpreter::java_lang_math_sqrt : // fall thru 576336809Sdim case Interpreter::java_lang_math_pow : // fall thru 577336809Sdim case Interpreter::java_lang_math_exp : entry_point = generate_math_entry(kind); break; 578336809Sdim case Interpreter::java_lang_ref_reference_get 579336809Sdim : entry_point = generate_Reference_get_entry(); break; 580336809Sdim#ifndef CC_INTERP 581336809Sdim case Interpreter::java_util_zip_CRC32_update 582336809Sdim : native = true; entry_point = generate_CRC32_update_entry(); break; 583336809Sdim case Interpreter::java_util_zip_CRC32_updateBytes 584336809Sdim : // fall thru 585336809Sdim case Interpreter::java_util_zip_CRC32_updateByteBuffer 586336809Sdim : native = true; entry_point = generate_CRC32_updateBytes_entry(kind); break; 587336809Sdim case Interpreter::java_util_zip_CRC32C_updateBytes 588336809Sdim : // fall thru 589336809Sdim case Interpreter::java_util_zip_CRC32C_updateDirectByteBuffer 590336809Sdim : entry_point = generate_CRC32C_updateBytes_entry(kind); break; 591336809Sdim#if defined(TARGET_ARCH_x86) && !defined(_LP64) 592336809Sdim // On x86_32 platforms, a special entry is generated for the following four methods. 593336809Sdim // On other platforms the normal entry is used to enter these methods. 594336809Sdim case Interpreter::java_lang_Float_intBitsToFloat 595336809Sdim : native = true; entry_point = generate_Float_intBitsToFloat_entry(); break; 596336809Sdim case Interpreter::java_lang_Float_floatToRawIntBits 597336809Sdim : native = true; entry_point = generate_Float_floatToRawIntBits_entry(); break; 598344779Sdim case Interpreter::java_lang_Double_longBitsToDouble 599336809Sdim : native = true; entry_point = generate_Double_longBitsToDouble_entry(); break; 600336809Sdim case Interpreter::java_lang_Double_doubleToRawLongBits 601336809Sdim : native = true; entry_point = generate_Double_doubleToRawLongBits_entry(); break; 602336809Sdim#else 603336809Sdim case Interpreter::java_lang_Float_intBitsToFloat: 604336809Sdim case Interpreter::java_lang_Float_floatToRawIntBits: 605336809Sdim case Interpreter::java_lang_Double_longBitsToDouble: 606336809Sdim case Interpreter::java_lang_Double_doubleToRawLongBits: 607336809Sdim native = true; 608336809Sdim break; 609336809Sdim#endif // defined(TARGET_ARCH_x86) && !defined(_LP64) 610336809Sdim#endif // CC_INTERP 611336809Sdim default: 612336809Sdim fatal("unexpected method kind: %d", kind); 613336809Sdim break; 614336809Sdim } 615336809Sdim 616336809Sdim if (entry_point) { 617336809Sdim return entry_point; 618336809Sdim } 619336809Sdim 620336809Sdim // We expect the normal and native entry points to be generated first so we can reuse them. 621336809Sdim if (native) { 622336809Sdim entry_point = Interpreter::entry_for_kind(synchronized ? Interpreter::native_synchronized : Interpreter::native); 623336809Sdim if (entry_point == NULL) { 624336809Sdim entry_point = generate_native_entry(synchronized); 625336809Sdim } 626336809Sdim } else { 627336809Sdim entry_point = Interpreter::entry_for_kind(synchronized ? Interpreter::zerolocals_synchronized : Interpreter::zerolocals); 628336809Sdim if (entry_point == NULL) { 629336809Sdim entry_point = generate_normal_entry(synchronized); 630336809Sdim } 631336809Sdim } 632336809Sdim 633336809Sdim return entry_point; 634336809Sdim} 635336809Sdim