duke@435: /* mikael@6198: * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #ifndef SHARE_VM_INTERPRETER_TEMPLATEINTERPRETER_HPP stefank@2314: #define SHARE_VM_INTERPRETER_TEMPLATEINTERPRETER_HPP stefank@2314: stefank@2314: #include "interpreter/abstractInterpreter.hpp" stefank@2314: #include "interpreter/templateTable.hpp" stefank@2314: twisti@1040: // This file contains the platform-independent parts duke@435: // of the template interpreter and the template interpreter generator. duke@435: duke@435: #ifndef CC_INTERP duke@435: duke@435: //------------------------------------------------------------------------------------------------------------------------ duke@435: // A little wrapper class to group tosca-specific entry points into a unit. duke@435: // (tosca = Top-Of-Stack CAche) duke@435: duke@435: class EntryPoint VALUE_OBJ_CLASS_SPEC { duke@435: private: duke@435: address _entry[number_of_states]; duke@435: duke@435: public: duke@435: // Construction duke@435: EntryPoint(); duke@435: EntryPoint(address bentry, address centry, address sentry, address aentry, address ientry, address lentry, address fentry, address dentry, address ventry); duke@435: duke@435: // Attributes duke@435: address entry(TosState state) const; // return target address for a given tosca state duke@435: void set_entry(TosState state, address entry); // set target address for a given tosca state duke@435: void print(); duke@435: duke@435: // Comparison duke@435: bool operator == (const EntryPoint& y); // for debugging only duke@435: }; duke@435: duke@435: duke@435: //------------------------------------------------------------------------------------------------------------------------ duke@435: // A little wrapper class to group tosca-specific dispatch tables into a unit. duke@435: duke@435: class DispatchTable VALUE_OBJ_CLASS_SPEC { duke@435: public: duke@435: enum { length = 1 << BitsPerByte }; // an entry point for each byte value (also for undefined bytecodes) duke@435: duke@435: private: duke@435: address _table[number_of_states][length]; // dispatch tables, indexed by tosca and bytecode duke@435: duke@435: public: duke@435: // Attributes duke@435: EntryPoint entry(int i) const; // return entry point for a given bytecode i duke@435: void set_entry(int i, EntryPoint& entry); // set entry point for a given bytecode i duke@435: address* table_for(TosState state) { return _table[state]; } duke@435: address* table_for() { return table_for((TosState)0); } duke@435: int distance_from(address *table) { return table - table_for(); } duke@435: int distance_from(TosState state) { return distance_from(table_for(state)); } duke@435: duke@435: // Comparison duke@435: bool operator == (DispatchTable& y); // for debugging only duke@435: }; duke@435: duke@435: class TemplateInterpreter: public AbstractInterpreter { duke@435: friend class VMStructs; duke@435: friend class InterpreterMacroAssembler; duke@435: friend class TemplateInterpreterGenerator; jrose@1145: friend class InterpreterGenerator; duke@435: friend class TemplateTable; duke@435: // friend class Interpreter; duke@435: public: duke@435: duke@435: enum MoreConstants { jrose@1161: number_of_return_entries = number_of_states, // number of return entry points jrose@1161: number_of_deopt_entries = number_of_states, // number of deoptimization entry points jrose@1161: number_of_return_addrs = number_of_states // number of return addresses duke@435: }; duke@435: duke@435: protected: duke@435: duke@435: static address _throw_ArrayIndexOutOfBoundsException_entry; duke@435: static address _throw_ArrayStoreException_entry; duke@435: static address _throw_ArithmeticException_entry; duke@435: static address _throw_ClassCastException_entry; jrose@1145: static address _throw_WrongMethodType_entry; duke@435: static address _throw_NullPointerException_entry; duke@435: static address _throw_exception_entry; duke@435: duke@435: static address _throw_StackOverflowError_entry; duke@435: duke@435: static address _remove_activation_entry; // continuation address if an exception is not handled by current frame duke@435: #ifdef HOTSWAP duke@435: static address _remove_activation_preserving_args_entry; // continuation address when current frame is being popped duke@435: #endif // HOTSWAP duke@435: duke@435: #ifndef PRODUCT duke@435: static EntryPoint _trace_code; duke@435: #endif // !PRODUCT duke@435: static EntryPoint _return_entry[number_of_return_entries]; // entry points to return to from a call duke@435: static EntryPoint _earlyret_entry; // entry point to return early from a call duke@435: static EntryPoint _deopt_entry[number_of_deopt_entries]; // entry points to return to from a deoptimization duke@435: static EntryPoint _continuation_entry; duke@435: static EntryPoint _safept_entry; duke@435: twisti@6039: static address _invoke_return_entry[number_of_return_addrs]; // for invokestatic, invokespecial, invokevirtual return entries twisti@6039: static address _invokeinterface_return_entry[number_of_return_addrs]; // for invokeinterface return entries twisti@6039: static address _invokedynamic_return_entry[number_of_return_addrs]; // for invokedynamic return entries duke@435: duke@435: static DispatchTable _active_table; // the active dispatch table (used by the interpreter for dispatch) duke@435: static DispatchTable _normal_table; // the normal dispatch table (used to set the active table in normal mode) duke@435: static DispatchTable _safept_table; // the safepoint dispatch table (used to set the active table for safepoints) duke@435: static address _wentry_point[DispatchTable::length]; // wide instructions only (vtos tosca always) duke@435: duke@435: duke@435: public: duke@435: // Initialization/debugging duke@435: static void initialize(); duke@435: // this only returns whether a pc is within generated code for the interpreter. duke@435: static bool contains(address pc) { return _code != NULL && _code->contains(pc); } duke@435: duke@435: public: duke@435: duke@435: static address remove_activation_early_entry(TosState state) { return _earlyret_entry.entry(state); } duke@435: #ifdef HOTSWAP duke@435: static address remove_activation_preserving_args_entry() { return _remove_activation_preserving_args_entry; } duke@435: #endif // HOTSWAP duke@435: duke@435: static address remove_activation_entry() { return _remove_activation_entry; } duke@435: static address throw_exception_entry() { return _throw_exception_entry; } duke@435: static address throw_ArithmeticException_entry() { return _throw_ArithmeticException_entry; } jrose@1145: static address throw_WrongMethodType_entry() { return _throw_WrongMethodType_entry; } duke@435: static address throw_NullPointerException_entry() { return _throw_NullPointerException_entry; } duke@435: static address throw_StackOverflowError_entry() { return _throw_StackOverflowError_entry; } duke@435: duke@435: // Code generation duke@435: #ifndef PRODUCT duke@435: static address trace_code (TosState state) { return _trace_code.entry(state); } duke@435: #endif // !PRODUCT duke@435: static address continuation (TosState state) { return _continuation_entry.entry(state); } duke@435: static address* dispatch_table(TosState state) { return _active_table.table_for(state); } duke@435: static address* dispatch_table() { return _active_table.table_for(); } duke@435: static int distance_from_dispatch_table(TosState state){ return _active_table.distance_from(state); } duke@435: static address* normal_table(TosState state) { return _normal_table.table_for(state); } duke@435: static address* normal_table() { return _normal_table.table_for(); } duke@435: duke@435: // Support for invokes twisti@6039: static address* invoke_return_entry_table() { return _invoke_return_entry; } twisti@6039: static address* invokeinterface_return_entry_table() { return _invokeinterface_return_entry; } twisti@6039: static address* invokedynamic_return_entry_table() { return _invokedynamic_return_entry; } twisti@6039: static int TosState_as_index(TosState state); duke@435: twisti@6039: static address* invoke_return_entry_table_for(Bytecodes::Code code); twisti@6039: twisti@6039: static address deopt_entry(TosState state, int length); twisti@6039: static address return_entry(TosState state, int length, Bytecodes::Code code); duke@435: duke@435: // Safepoint support duke@435: static void notice_safepoints(); // stops the thread when reaching a safepoint duke@435: static void ignore_safepoints(); // ignores safepoints duke@435: duke@435: // Deoptimization support cfang@1335: // Compute the entry address for continuation after coleenp@4037: static address deopt_continue_after_entry(Method* method, cfang@1335: address bcp, cfang@1335: int callee_parameters, cfang@1335: bool is_top_frame); cfang@1335: // Deoptimization should reexecute this bytecode cfang@1335: static bool bytecode_should_reexecute(Bytecodes::Code code); cfang@1335: // Compute the address for reexecution coleenp@4037: static address deopt_reexecute_entry(Method* method, address bcp); duke@435: stefank@2314: #ifdef TARGET_ARCH_x86 stefank@2314: # include "templateInterpreter_x86.hpp" stefank@2314: #endif stefank@2314: #ifdef TARGET_ARCH_sparc stefank@2314: # include "templateInterpreter_sparc.hpp" stefank@2314: #endif stefank@2314: #ifdef TARGET_ARCH_zero stefank@2314: # include "templateInterpreter_zero.hpp" stefank@2314: #endif bobv@2508: #ifdef TARGET_ARCH_arm bobv@2508: # include "templateInterpreter_arm.hpp" bobv@2508: #endif bobv@2508: #ifdef TARGET_ARCH_ppc bobv@2508: # include "templateInterpreter_ppc.hpp" bobv@2508: #endif stefank@2314: duke@435: duke@435: }; duke@435: duke@435: #endif // !CC_INTERP stefank@2314: stefank@2314: #endif // SHARE_VM_INTERPRETER_TEMPLATEINTERPRETER_HPP