Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/interpreter/interpreter.cpp
32285 views
/*1* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "asm/macroAssembler.hpp"26#include "asm/macroAssembler.inline.hpp"27#include "compiler/disassembler.hpp"28#include "interpreter/bytecodeHistogram.hpp"29#include "interpreter/bytecodeInterpreter.hpp"30#include "interpreter/interpreter.hpp"31#include "interpreter/interpreterRuntime.hpp"32#include "interpreter/templateTable.hpp"33#include "memory/allocation.inline.hpp"34#include "memory/resourceArea.hpp"35#include "oops/arrayOop.hpp"36#include "oops/methodData.hpp"37#include "oops/method.hpp"38#include "oops/oop.inline.hpp"39#include "prims/forte.hpp"40#include "prims/jvmtiExport.hpp"41#include "prims/methodHandles.hpp"42#include "runtime/handles.inline.hpp"43#include "runtime/sharedRuntime.hpp"44#include "runtime/stubRoutines.hpp"45#include "runtime/timer.hpp"4647# define __ _masm->484950//------------------------------------------------------------------------------------------------------------------------51// Implementation of InterpreterCodelet5253void InterpreterCodelet::initialize(const char* description, Bytecodes::Code bytecode) {54_description = description;55_bytecode = bytecode;56}575859void InterpreterCodelet::verify() {60}616263void InterpreterCodelet::print_on(outputStream* st) const {64ttyLocker ttyl;6566if (PrintInterpreter) {67st->cr();68st->print_cr("----------------------------------------------------------------------");69}7071if (description() != NULL) st->print("%s ", description());72if (bytecode() >= 0 ) st->print("%d %s ", bytecode(), Bytecodes::name(bytecode()));73st->print_cr("[" INTPTR_FORMAT ", " INTPTR_FORMAT "] %d bytes",74p2i(code_begin()), p2i(code_end()), code_size());7576if (PrintInterpreter) {77st->cr();78Disassembler::decode(code_begin(), code_end(), st, DEBUG_ONLY(_strings) NOT_DEBUG(CodeStrings()));79}80}818283//------------------------------------------------------------------------------------------------------------------------84// Implementation of platform independent aspects of Interpreter8586void AbstractInterpreter::initialize() {87if (_code != NULL) return;8889// make sure 'imported' classes are initialized90if (CountBytecodes || TraceBytecodes || StopInterpreterAt) BytecodeCounter::reset();91if (PrintBytecodeHistogram) BytecodeHistogram::reset();92if (PrintBytecodePairHistogram) BytecodePairHistogram::reset();9394InvocationCounter::reinitialize(DelayCompilationDuringStartup);9596}9798void AbstractInterpreter::print() {99tty->cr();100tty->print_cr("----------------------------------------------------------------------");101tty->print_cr("Interpreter");102tty->cr();103tty->print_cr("code size = %6dK bytes", (int)_code->used_space()/1024);104tty->print_cr("total space = %6dK bytes", (int)_code->total_space()/1024);105tty->print_cr("wasted space = %6dK bytes", (int)_code->available_space()/1024);106tty->cr();107tty->print_cr("# of codelets = %6d" , _code->number_of_stubs());108tty->print_cr("avg codelet size = %6d bytes", _code->used_space() / _code->number_of_stubs());109tty->cr();110_code->print();111tty->print_cr("----------------------------------------------------------------------");112tty->cr();113}114115116void interpreter_init() {117Interpreter::initialize();118#ifndef PRODUCT119if (TraceBytecodes) BytecodeTracer::set_closure(BytecodeTracer::std_closure());120#endif // PRODUCT121// need to hit every safepoint in order to call zapping routine122// register the interpreter123Forte::register_stub(124"Interpreter",125AbstractInterpreter::code()->code_start(),126AbstractInterpreter::code()->code_end()127);128129// notify JVMTI profiler130if (JvmtiExport::should_post_dynamic_code_generated()) {131JvmtiExport::post_dynamic_code_generated("Interpreter",132AbstractInterpreter::code()->code_start(),133AbstractInterpreter::code()->code_end());134}135}136137//------------------------------------------------------------------------------------------------------------------------138// Implementation of interpreter139140StubQueue* AbstractInterpreter::_code = NULL;141bool AbstractInterpreter::_notice_safepoints = false;142address AbstractInterpreter::_rethrow_exception_entry = NULL;143144address AbstractInterpreter::_native_entry_begin = NULL;145address AbstractInterpreter::_native_entry_end = NULL;146address AbstractInterpreter::_slow_signature_handler;147address AbstractInterpreter::_entry_table [AbstractInterpreter::number_of_method_entries];148address AbstractInterpreter::_native_abi_to_tosca [AbstractInterpreter::number_of_result_handlers];149150//------------------------------------------------------------------------------------------------------------------------151// Generation of complete interpreter152153AbstractInterpreterGenerator::AbstractInterpreterGenerator(StubQueue* _code) {154_masm = NULL;155}156157158static const BasicType types[Interpreter::number_of_result_handlers] = {159T_BOOLEAN,160T_CHAR ,161T_BYTE ,162T_SHORT ,163T_INT ,164T_LONG ,165T_VOID ,166T_FLOAT ,167T_DOUBLE ,168T_OBJECT169};170171void AbstractInterpreterGenerator::generate_all() {172173174{ CodeletMark cm(_masm, "slow signature handler");175Interpreter::_slow_signature_handler = generate_slow_signature_handler();176}177178}179180//------------------------------------------------------------------------------------------------------------------------181// Entry points182183AbstractInterpreter::MethodKind AbstractInterpreter::method_kind(methodHandle m) {184// Abstract method?185if (m->is_abstract()) return abstract;186187// Method handle primitive?188if (m->is_method_handle_intrinsic()) {189vmIntrinsics::ID id = m->intrinsic_id();190assert(MethodHandles::is_signature_polymorphic(id), "must match an intrinsic");191MethodKind kind = (MethodKind)( method_handle_invoke_FIRST +192((int)id - vmIntrinsics::FIRST_MH_SIG_POLY) );193assert(kind <= method_handle_invoke_LAST, "parallel enum ranges");194return kind;195}196197#ifndef CC_INTERP198if (UseCRC32Intrinsics && m->is_native()) {199// Use optimized stub code for CRC32 native methods.200switch (m->intrinsic_id()) {201case vmIntrinsics::_updateCRC32 : return java_util_zip_CRC32_update;202case vmIntrinsics::_updateBytesCRC32 : return java_util_zip_CRC32_updateBytes;203case vmIntrinsics::_updateByteBufferCRC32 : return java_util_zip_CRC32_updateByteBuffer;204}205}206#endif207208// Native method?209// Note: This test must come _before_ the test for intrinsic210// methods. See also comments below.211if (m->is_native()) {212assert(!m->is_method_handle_intrinsic(), "overlapping bits here, watch out");213return m->is_synchronized() ? native_synchronized : native;214}215216// Synchronized?217if (m->is_synchronized()) {218return zerolocals_synchronized;219}220221if (RegisterFinalizersAtInit && m->code_size() == 1 &&222m->intrinsic_id() == vmIntrinsics::_Object_init) {223// We need to execute the special return bytecode to check for224// finalizer registration so create a normal frame.225return zerolocals;226}227228// Empty method?229if (m->is_empty_method()) {230return empty;231}232233// Special intrinsic method?234// Note: This test must come _after_ the test for native methods,235// otherwise we will run into problems with JDK 1.2, see also236// AbstractInterpreterGenerator::generate_method_entry() for237// for details.238switch (m->intrinsic_id()) {239case vmIntrinsics::_dsin : return java_lang_math_sin ;240case vmIntrinsics::_dcos : return java_lang_math_cos ;241case vmIntrinsics::_dtan : return java_lang_math_tan ;242case vmIntrinsics::_dabs : return java_lang_math_abs ;243case vmIntrinsics::_dsqrt : return java_lang_math_sqrt ;244case vmIntrinsics::_dlog : return java_lang_math_log ;245case vmIntrinsics::_dlog10: return java_lang_math_log10;246case vmIntrinsics::_dpow : return java_lang_math_pow ;247case vmIntrinsics::_dexp : return java_lang_math_exp ;248249case vmIntrinsics::_Reference_get:250return java_lang_ref_reference_get;251}252253// Accessor method?254if (m->is_accessor()) {255assert(m->size_of_parameters() == 1, "fast code for accessors assumes parameter size = 1");256return accessor;257}258259// Note: for now: zero locals for all non-empty methods260return zerolocals;261}262263264void AbstractInterpreter::set_entry_for_kind(AbstractInterpreter::MethodKind kind, address entry) {265assert(kind >= method_handle_invoke_FIRST &&266kind <= method_handle_invoke_LAST, "late initialization only for MH entry points");267assert(_entry_table[kind] == _entry_table[abstract], "previous value must be AME entry");268_entry_table[kind] = entry;269}270271272// Return true if the interpreter can prove that the given bytecode has273// not yet been executed (in Java semantics, not in actual operation).274bool AbstractInterpreter::is_not_reached(methodHandle method, int bci) {275Bytecodes::Code code = method()->code_at(bci);276277if (!Bytecodes::must_rewrite(code)) {278// might have been reached279return false;280}281282// the bytecode might not be rewritten if the method is an accessor, etc.283address ientry = method->interpreter_entry();284if (ientry != entry_for_kind(AbstractInterpreter::zerolocals) &&285ientry != entry_for_kind(AbstractInterpreter::zerolocals_synchronized))286return false; // interpreter does not run this method!287288// otherwise, we can be sure this bytecode has never been executed289return true;290}291292293#ifndef PRODUCT294void AbstractInterpreter::print_method_kind(MethodKind kind) {295switch (kind) {296case zerolocals : tty->print("zerolocals" ); break;297case zerolocals_synchronized: tty->print("zerolocals_synchronized"); break;298case native : tty->print("native" ); break;299case native_synchronized : tty->print("native_synchronized" ); break;300case empty : tty->print("empty" ); break;301case accessor : tty->print("accessor" ); break;302case abstract : tty->print("abstract" ); break;303case java_lang_math_sin : tty->print("java_lang_math_sin" ); break;304case java_lang_math_cos : tty->print("java_lang_math_cos" ); break;305case java_lang_math_tan : tty->print("java_lang_math_tan" ); break;306case java_lang_math_abs : tty->print("java_lang_math_abs" ); break;307case java_lang_math_sqrt : tty->print("java_lang_math_sqrt" ); break;308case java_lang_math_log : tty->print("java_lang_math_log" ); break;309case java_lang_math_log10 : tty->print("java_lang_math_log10" ); break;310case java_util_zip_CRC32_update : tty->print("java_util_zip_CRC32_update"); break;311case java_util_zip_CRC32_updateBytes : tty->print("java_util_zip_CRC32_updateBytes"); break;312case java_util_zip_CRC32_updateByteBuffer : tty->print("java_util_zip_CRC32_updateByteBuffer"); break;313default:314if (kind >= method_handle_invoke_FIRST &&315kind <= method_handle_invoke_LAST) {316const char* kind_name = vmIntrinsics::name_at(method_handle_intrinsic(kind));317if (kind_name[0] == '_') kind_name = &kind_name[1]; // '_invokeExact' => 'invokeExact'318tty->print("method_handle_%s", kind_name);319break;320}321ShouldNotReachHere();322break;323}324}325#endif // PRODUCT326327328//------------------------------------------------------------------------------------------------------------------------329// Deoptimization support330331/**332* If a deoptimization happens, this function returns the point of next bytecode to continue execution.333*/334address AbstractInterpreter::deopt_continue_after_entry(Method* method, address bcp, int callee_parameters, bool is_top_frame) {335assert(method->contains(bcp), "just checkin'");336337// Get the original and rewritten bytecode.338Bytecodes::Code code = Bytecodes::java_code_at(method, bcp);339assert(!Interpreter::bytecode_should_reexecute(code), "should not reexecute");340341const int bci = method->bci_from(bcp);342343// compute continuation length344const int length = Bytecodes::length_at(method, bcp);345346// compute result type347BasicType type = T_ILLEGAL;348349switch (code) {350case Bytecodes::_invokevirtual :351case Bytecodes::_invokespecial :352case Bytecodes::_invokestatic :353case Bytecodes::_invokeinterface: {354Thread *thread = Thread::current();355ResourceMark rm(thread);356methodHandle mh(thread, method);357type = Bytecode_invoke(mh, bci).result_type();358// since the cache entry might not be initialized:359// (NOT needed for the old calling convension)360if (!is_top_frame) {361int index = Bytes::get_native_u2(bcp+1);362method->constants()->cache()->entry_at(index)->set_parameter_size(callee_parameters);363}364break;365}366367case Bytecodes::_invokedynamic: {368Thread *thread = Thread::current();369ResourceMark rm(thread);370methodHandle mh(thread, method);371type = Bytecode_invoke(mh, bci).result_type();372// since the cache entry might not be initialized:373// (NOT needed for the old calling convension)374if (!is_top_frame) {375int index = Bytes::get_native_u4(bcp+1);376method->constants()->invokedynamic_cp_cache_entry_at(index)->set_parameter_size(callee_parameters);377}378break;379}380381case Bytecodes::_ldc :382case Bytecodes::_ldc_w : // fall through383case Bytecodes::_ldc2_w:384{385Thread *thread = Thread::current();386ResourceMark rm(thread);387methodHandle mh(thread, method);388type = Bytecode_loadconstant(mh, bci).result_type();389break;390}391392default:393type = Bytecodes::result_type(code);394break;395}396397// return entry point for computed continuation state & bytecode length398return399is_top_frame400? Interpreter::deopt_entry (as_TosState(type), length)401: Interpreter::return_entry(as_TosState(type), length, code);402}403404// If deoptimization happens, this function returns the point where the interpreter reexecutes405// the bytecode.406// Note: Bytecodes::_athrow is a special case in that it does not return407// Interpreter::deopt_entry(vtos, 0) like others408address AbstractInterpreter::deopt_reexecute_entry(Method* method, address bcp) {409assert(method->contains(bcp), "just checkin'");410Bytecodes::Code code = Bytecodes::java_code_at(method, bcp);411#ifdef COMPILER1412if(code == Bytecodes::_athrow ) {413return Interpreter::rethrow_exception_entry();414}415#endif /* COMPILER1 */416return Interpreter::deopt_entry(vtos, 0);417}418419// If deoptimization happens, the interpreter should reexecute these bytecodes.420// This function mainly helps the compilers to set up the reexecute bit.421bool AbstractInterpreter::bytecode_should_reexecute(Bytecodes::Code code) {422switch (code) {423case Bytecodes::_lookupswitch:424case Bytecodes::_tableswitch:425case Bytecodes::_fast_binaryswitch:426case Bytecodes::_fast_linearswitch:427// recompute condtional expression folded into _if<cond>428case Bytecodes::_lcmp :429case Bytecodes::_fcmpl :430case Bytecodes::_fcmpg :431case Bytecodes::_dcmpl :432case Bytecodes::_dcmpg :433case Bytecodes::_ifnull :434case Bytecodes::_ifnonnull :435case Bytecodes::_goto :436case Bytecodes::_goto_w :437case Bytecodes::_ifeq :438case Bytecodes::_ifne :439case Bytecodes::_iflt :440case Bytecodes::_ifge :441case Bytecodes::_ifgt :442case Bytecodes::_ifle :443case Bytecodes::_if_icmpeq :444case Bytecodes::_if_icmpne :445case Bytecodes::_if_icmplt :446case Bytecodes::_if_icmpge :447case Bytecodes::_if_icmpgt :448case Bytecodes::_if_icmple :449case Bytecodes::_if_acmpeq :450case Bytecodes::_if_acmpne :451// special cases452case Bytecodes::_getfield :453case Bytecodes::_putfield :454case Bytecodes::_getstatic :455case Bytecodes::_putstatic :456case Bytecodes::_aastore :457#ifdef COMPILER1458//special case of reexecution459case Bytecodes::_athrow :460#endif461return true;462463default:464return false;465}466}467468void AbstractInterpreterGenerator::bang_stack_shadow_pages(bool native_call) {469// Quick & dirty stack overflow checking: bang the stack & handle trap.470// Note that we do the banging after the frame is setup, since the exception471// handling code expects to find a valid interpreter frame on the stack.472// Doing the banging earlier fails if the caller frame is not an interpreter473// frame.474// (Also, the exception throwing code expects to unlock any synchronized475// method receiever, so do the banging after locking the receiver.)476477// Bang each page in the shadow zone. We can't assume it's been done for478// an interpreter frame with greater than a page of locals, so each page479// needs to be checked. Only true for non-native.480if (UseStackBanging) {481const int start_page = native_call ? StackShadowPages : 1;482const int page_size = os::vm_page_size();483for (int pages = start_page; pages <= StackShadowPages ; pages++) {484__ bang_stack_with_offset(pages*page_size);485}486}487}488489void AbstractInterpreterGenerator::initialize_method_handle_entries() {490// method handle entry kinds are generated later in MethodHandlesAdapterGenerator::generate:491for (int i = Interpreter::method_handle_invoke_FIRST; i <= Interpreter::method_handle_invoke_LAST; i++) {492Interpreter::MethodKind kind = (Interpreter::MethodKind) i;493Interpreter::_entry_table[kind] = Interpreter::_entry_table[Interpreter::abstract];494}495}496497498