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