aoqi@0: /* dlong@7598: * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@1: /* aoqi@1: * This file has been modified by Loongson Technology in 2015. These aoqi@1: * modifications are Copyright (c) 2015 Loongson Technology, and are made aoqi@1: * available on the same license terms set forth above. aoqi@1: */ aoqi@1: aoqi@0: #ifndef SHARE_VM_INTERPRETER_ABSTRACTINTERPRETER_HPP aoqi@0: #define SHARE_VM_INTERPRETER_ABSTRACTINTERPRETER_HPP aoqi@0: aoqi@0: #include "code/stubs.hpp" aoqi@0: #include "interpreter/bytecodes.hpp" aoqi@0: #include "runtime/thread.inline.hpp" aoqi@0: #include "runtime/vmThread.hpp" aoqi@0: #include "utilities/top.hpp" dlong@7598: #if defined INTERP_MASM_MD_HPP dlong@7598: # include INTERP_MASM_MD_HPP dlong@7598: #elif defined TARGET_ARCH_x86 aoqi@0: # include "interp_masm_x86.hpp" dlong@7598: #elif defined TARGET_ARCH_MODEL_sparc roland@6723: # include "interp_masm_sparc.hpp" dlong@7598: #elif defined TARGET_ARCH_MODEL_zero roland@6723: # include "interp_masm_zero.hpp" dlong@7598: #elif defined TARGET_ARCH_MODEL_ppc_64 roland@6723: # include "interp_masm_ppc_64.hpp" aoqi@7994: #elif defined TARGET_ARCH_MODEL_mips_64 aoqi@1: # include "interp_masm_mips_64.hpp" aoqi@1: #endif aoqi@0: aoqi@0: // This file contains the platform-independent parts aoqi@0: // of the abstract interpreter and the abstract interpreter generator. aoqi@0: aoqi@0: // Organization of the interpreter(s). There exists two different interpreters in hotpot aoqi@0: // an assembly language version (aka template interpreter) and a high level language version aoqi@0: // (aka c++ interpreter). Th division of labor is as follows: aoqi@0: aoqi@0: // Template Interpreter C++ Interpreter Functionality aoqi@0: // aoqi@0: // templateTable* bytecodeInterpreter* actual interpretation of bytecodes aoqi@0: // aoqi@0: // templateInterpreter* cppInterpreter* generation of assembly code that creates aoqi@0: // and manages interpreter runtime frames. aoqi@0: // Also code for populating interpreter aoqi@0: // frames created during deoptimization. aoqi@0: // aoqi@0: // For both template and c++ interpreter. There are common files for aspects of the interpreter aoqi@0: // that are generic to both interpreters. This is the layout: aoqi@0: // aoqi@0: // abstractInterpreter.hpp: generic description of the interpreter. aoqi@0: // interpreter*: generic frame creation and handling. aoqi@0: // aoqi@0: aoqi@0: //------------------------------------------------------------------------------------------------------------------------ aoqi@0: // The C++ interface to the bytecode interpreter(s). aoqi@0: aoqi@0: class AbstractInterpreter: AllStatic { aoqi@0: friend class VMStructs; aoqi@0: friend class Interpreter; aoqi@0: friend class CppInterpreterGenerator; aoqi@0: public: aoqi@0: enum MethodKind { aoqi@0: zerolocals, // method needs locals initialization aoqi@0: zerolocals_synchronized, // method needs locals initialization & is synchronized aoqi@0: native, // native method aoqi@0: native_synchronized, // native method & is synchronized aoqi@0: empty, // empty method (code: _return) aoqi@0: accessor, // accessor method (code: _aload_0, _getfield, _(a|i)return) aoqi@0: abstract, // abstract method (throws an AbstractMethodException) aoqi@0: method_handle_invoke_FIRST, // java.lang.invoke.MethodHandles::invokeExact, etc. aoqi@0: method_handle_invoke_LAST = (method_handle_invoke_FIRST aoqi@0: + (vmIntrinsics::LAST_MH_SIG_POLY aoqi@0: - vmIntrinsics::FIRST_MH_SIG_POLY)), aoqi@0: java_lang_math_sin, // implementation of java.lang.Math.sin (x) aoqi@0: java_lang_math_cos, // implementation of java.lang.Math.cos (x) aoqi@0: java_lang_math_tan, // implementation of java.lang.Math.tan (x) aoqi@0: java_lang_math_abs, // implementation of java.lang.Math.abs (x) aoqi@0: java_lang_math_sqrt, // implementation of java.lang.Math.sqrt (x) aoqi@0: java_lang_math_log, // implementation of java.lang.Math.log (x) aoqi@0: java_lang_math_log10, // implementation of java.lang.Math.log10 (x) aoqi@0: java_lang_math_pow, // implementation of java.lang.Math.pow (x,y) aoqi@0: java_lang_math_exp, // implementation of java.lang.Math.exp (x) aoqi@0: java_lang_ref_reference_get, // implementation of java.lang.ref.Reference.get() aoqi@0: java_util_zip_CRC32_update, // implementation of java.util.zip.CRC32.update() aoqi@0: java_util_zip_CRC32_updateBytes, // implementation of java.util.zip.CRC32.updateBytes() aoqi@0: java_util_zip_CRC32_updateByteBuffer, // implementation of java.util.zip.CRC32.updateByteBuffer() aoqi@0: number_of_method_entries, aoqi@0: invalid = -1 aoqi@0: }; aoqi@0: aoqi@0: // Conversion from the part of the above enum to vmIntrinsics::_invokeExact, etc. aoqi@0: static vmIntrinsics::ID method_handle_intrinsic(MethodKind kind) { aoqi@0: if (kind >= method_handle_invoke_FIRST && kind <= method_handle_invoke_LAST) aoqi@0: return (vmIntrinsics::ID)( vmIntrinsics::FIRST_MH_SIG_POLY + (kind - method_handle_invoke_FIRST) ); aoqi@0: else aoqi@0: return vmIntrinsics::_none; aoqi@0: } aoqi@0: aoqi@0: enum SomeConstants { aoqi@0: number_of_result_handlers = 10 // number of result handlers for native calls aoqi@0: }; aoqi@0: aoqi@0: protected: aoqi@0: static StubQueue* _code; // the interpreter code (codelets) aoqi@0: aoqi@0: static bool _notice_safepoints; // true if safepoints are activated aoqi@0: aoqi@0: static address _native_entry_begin; // Region for native entry code aoqi@0: static address _native_entry_end; aoqi@0: aoqi@0: // method entry points aoqi@0: static address _entry_table[number_of_method_entries]; // entry points for a given method aoqi@0: static address _native_abi_to_tosca[number_of_result_handlers]; // for native method result handlers aoqi@0: static address _slow_signature_handler; // the native method generic (slow) signature handler aoqi@0: aoqi@0: static address _rethrow_exception_entry; // rethrows an activation in previous frame aoqi@0: aoqi@0: friend class AbstractInterpreterGenerator; aoqi@0: friend class InterpreterGenerator; aoqi@0: friend class InterpreterMacroAssembler; aoqi@0: aoqi@0: public: aoqi@0: // Initialization/debugging aoqi@0: static void initialize(); aoqi@0: static StubQueue* code() { return _code; } aoqi@0: aoqi@0: aoqi@0: // Method activation aoqi@0: static MethodKind method_kind(methodHandle m); aoqi@0: static address entry_for_kind(MethodKind k) { assert(0 <= k && k < number_of_method_entries, "illegal kind"); return _entry_table[k]; } aoqi@0: static address entry_for_method(methodHandle m) { return entry_for_kind(method_kind(m)); } aoqi@0: aoqi@0: // used for bootstrapping method handles: aoqi@0: static void set_entry_for_kind(MethodKind k, address e); aoqi@0: aoqi@0: static void print_method_kind(MethodKind kind) PRODUCT_RETURN; aoqi@0: aoqi@0: static bool can_be_compiled(methodHandle m); aoqi@0: aoqi@0: // Runtime support aoqi@0: aoqi@0: // length = invoke bytecode length (to advance to next bytecode) aoqi@0: static address deopt_entry(TosState state, int length) { ShouldNotReachHere(); return NULL; } aoqi@0: static address return_entry(TosState state, int length, Bytecodes::Code code) { ShouldNotReachHere(); return NULL; } aoqi@0: aoqi@0: static address rethrow_exception_entry() { return _rethrow_exception_entry; } aoqi@0: aoqi@0: // Activation size in words for a method that is just being called. aoqi@0: // Parameters haven't been pushed so count them too. aoqi@0: static int size_top_interpreter_activation(Method* method); aoqi@0: aoqi@0: // Deoptimization support aoqi@0: // Compute the entry address for continuation after aoqi@0: static address deopt_continue_after_entry(Method* method, aoqi@0: address bcp, aoqi@0: int callee_parameters, aoqi@0: bool is_top_frame); aoqi@0: // Compute the entry address for reexecution aoqi@0: static address deopt_reexecute_entry(Method* method, address bcp); aoqi@0: // Deoptimization should reexecute this bytecode aoqi@0: static bool bytecode_should_reexecute(Bytecodes::Code code); aoqi@0: aoqi@0: // deoptimization support aoqi@0: static int size_activation(int max_stack, aoqi@0: int temps, aoqi@0: int extra_args, aoqi@0: int monitors, aoqi@0: int callee_params, aoqi@0: int callee_locals, aoqi@0: bool is_top_frame); aoqi@0: aoqi@0: static void layout_activation(Method* method, aoqi@0: int temps, aoqi@0: int popframe_args, aoqi@0: int monitors, aoqi@0: int caller_actual_parameters, aoqi@0: int callee_params, aoqi@0: int callee_locals, aoqi@0: frame* caller, aoqi@0: frame* interpreter_frame, aoqi@0: bool is_top_frame, aoqi@0: bool is_bottom_frame); aoqi@0: aoqi@0: // Runtime support aoqi@0: static bool is_not_reached( methodHandle method, int bci); aoqi@0: // Safepoint support aoqi@0: static void notice_safepoints() { ShouldNotReachHere(); } // stops the thread when reaching a safepoint aoqi@0: static void ignore_safepoints() { ShouldNotReachHere(); } // ignores safepoints aoqi@0: aoqi@0: // Support for native calls aoqi@0: static address slow_signature_handler() { return _slow_signature_handler; } aoqi@0: static address result_handler(BasicType type) { return _native_abi_to_tosca[BasicType_as_index(type)]; } aoqi@0: static int BasicType_as_index(BasicType type); // computes index into result_handler_by_index table aoqi@0: static bool in_native_entry(address pc) { return _native_entry_begin <= pc && pc < _native_entry_end; } aoqi@0: // Debugging/printing aoqi@0: static void print(); // prints the interpreter code aoqi@0: aoqi@0: public: aoqi@0: // Interpreter helpers aoqi@0: const static int stackElementWords = 1; aoqi@0: const static int stackElementSize = stackElementWords * wordSize; aoqi@0: const static int logStackElementSize = LogBytesPerWord; aoqi@0: aoqi@0: // Local values relative to locals[n] aoqi@0: static int local_offset_in_bytes(int n) { aoqi@0: return ((frame::interpreter_frame_expression_stack_direction() * n) * stackElementSize); aoqi@0: } aoqi@0: aoqi@0: // access to stacked values according to type: aoqi@0: static oop* oop_addr_in_slot(intptr_t* slot_addr) { aoqi@0: return (oop*) slot_addr; aoqi@0: } aoqi@0: static jint* int_addr_in_slot(intptr_t* slot_addr) { aoqi@0: if ((int) sizeof(jint) < wordSize && !Bytes::is_Java_byte_ordering_different()) aoqi@0: // big-endian LP64 aoqi@0: return (jint*)(slot_addr + 1) - 1; aoqi@0: else aoqi@0: return (jint*) slot_addr; aoqi@0: } aoqi@0: static jlong long_in_slot(intptr_t* slot_addr) { aoqi@0: if (sizeof(intptr_t) >= sizeof(jlong)) { aoqi@0: return *(jlong*) slot_addr; aoqi@0: } else { aoqi@0: return Bytes::get_native_u8((address)slot_addr); aoqi@0: } aoqi@0: } aoqi@0: static void set_long_in_slot(intptr_t* slot_addr, jlong value) { aoqi@0: if (sizeof(intptr_t) >= sizeof(jlong)) { aoqi@0: *(jlong*) slot_addr = value; aoqi@0: } else { aoqi@0: Bytes::put_native_u8((address)slot_addr, value); aoqi@0: } aoqi@0: } aoqi@0: static void get_jvalue_in_slot(intptr_t* slot_addr, BasicType type, jvalue* value) { aoqi@0: switch (type) { aoqi@0: case T_BOOLEAN: value->z = *int_addr_in_slot(slot_addr); break; aoqi@0: case T_CHAR: value->c = *int_addr_in_slot(slot_addr); break; aoqi@0: case T_BYTE: value->b = *int_addr_in_slot(slot_addr); break; aoqi@0: case T_SHORT: value->s = *int_addr_in_slot(slot_addr); break; aoqi@0: case T_INT: value->i = *int_addr_in_slot(slot_addr); break; aoqi@0: case T_LONG: value->j = long_in_slot(slot_addr); break; aoqi@0: case T_FLOAT: value->f = *(jfloat*)int_addr_in_slot(slot_addr); break; aoqi@0: case T_DOUBLE: value->d = jdouble_cast(long_in_slot(slot_addr)); break; aoqi@0: case T_OBJECT: value->l = (jobject)*oop_addr_in_slot(slot_addr); break; aoqi@0: default: ShouldNotReachHere(); aoqi@0: } aoqi@0: } aoqi@0: static void set_jvalue_in_slot(intptr_t* slot_addr, BasicType type, jvalue* value) { aoqi@0: switch (type) { aoqi@0: case T_BOOLEAN: *int_addr_in_slot(slot_addr) = (value->z != 0); break; aoqi@0: case T_CHAR: *int_addr_in_slot(slot_addr) = value->c; break; aoqi@0: case T_BYTE: *int_addr_in_slot(slot_addr) = value->b; break; aoqi@0: case T_SHORT: *int_addr_in_slot(slot_addr) = value->s; break; aoqi@0: case T_INT: *int_addr_in_slot(slot_addr) = value->i; break; aoqi@0: case T_LONG: set_long_in_slot(slot_addr, value->j); break; aoqi@0: case T_FLOAT: *(jfloat*)int_addr_in_slot(slot_addr) = value->f; break; aoqi@0: case T_DOUBLE: set_long_in_slot(slot_addr, jlong_cast(value->d)); break; aoqi@0: case T_OBJECT: *oop_addr_in_slot(slot_addr) = (oop) value->l; break; aoqi@0: default: ShouldNotReachHere(); aoqi@0: } aoqi@0: } aoqi@0: }; aoqi@0: aoqi@0: //------------------------------------------------------------------------------------------------------------------------ aoqi@0: // The interpreter generator. aoqi@0: aoqi@0: class Template; aoqi@0: class AbstractInterpreterGenerator: public StackObj { aoqi@0: protected: aoqi@0: InterpreterMacroAssembler* _masm; aoqi@0: aoqi@0: // shared code sequences aoqi@0: // Converter for native abi result to tosca result aoqi@0: address generate_result_handler_for(BasicType type); aoqi@0: address generate_slow_signature_handler(); aoqi@0: aoqi@0: // entry point generator aoqi@0: address generate_method_entry(AbstractInterpreter::MethodKind kind); aoqi@0: aoqi@0: void bang_stack_shadow_pages(bool native_call); aoqi@0: aoqi@0: void generate_all(); aoqi@0: void initialize_method_handle_entries(); aoqi@0: aoqi@0: public: aoqi@0: AbstractInterpreterGenerator(StubQueue* _code); aoqi@0: }; aoqi@0: aoqi@0: #endif // SHARE_VM_INTERPRETER_ABSTRACTINTERPRETER_HPP