templateTable.hpp revision 3602:da91efe96a93
133965Sjdp/* 238889Sjdp * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. 333965Sjdp * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 433965Sjdp * 533965Sjdp * This code is free software; you can redistribute it and/or modify it 633965Sjdp * under the terms of the GNU General Public License version 2 only, as 733965Sjdp * published by the Free Software Foundation. 833965Sjdp * 933965Sjdp * This code is distributed in the hope that it will be useful, but WITHOUT 1033965Sjdp * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1133965Sjdp * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1233965Sjdp * version 2 for more details (a copy is included in the LICENSE file that 1333965Sjdp * accompanied this code). 1433965Sjdp * 1533965Sjdp * You should have received a copy of the GNU General Public License version 1633965Sjdp * 2 along with this work; if not, write to the Free Software Foundation, 1733965Sjdp * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1833965Sjdp * 1933965Sjdp * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2033965Sjdp * or visit www.oracle.com if you need additional information or have any 2133965Sjdp * questions. 2233965Sjdp * 2333965Sjdp */ 2433965Sjdp 2533965Sjdp#ifndef SHARE_VM_INTERPRETER_TEMPLATETABLE_HPP 2633965Sjdp#define SHARE_VM_INTERPRETER_TEMPLATETABLE_HPP 2733965Sjdp 2833965Sjdp#include "interpreter/bytecodes.hpp" 2933965Sjdp#include "memory/allocation.hpp" 3033965Sjdp#include "runtime/frame.hpp" 3133965Sjdp#ifdef TARGET_ARCH_MODEL_x86_32 3233965Sjdp# include "interp_masm_x86_32.hpp" 3333965Sjdp#endif 3433965Sjdp#ifdef TARGET_ARCH_MODEL_x86_64 3533965Sjdp# include "interp_masm_x86_64.hpp" 3633965Sjdp#endif 3733965Sjdp#ifdef TARGET_ARCH_MODEL_sparc 3833965Sjdp# include "interp_masm_sparc.hpp" 3933965Sjdp#endif 4033965Sjdp#ifdef TARGET_ARCH_MODEL_zero 4133965Sjdp# include "interp_masm_zero.hpp" 4233965Sjdp#endif 4333965Sjdp#ifdef TARGET_ARCH_MODEL_arm 4433965Sjdp# include "interp_masm_arm.hpp" 4533965Sjdp#endif 4633965Sjdp#ifdef TARGET_ARCH_MODEL_ppc 4733965Sjdp# include "interp_masm_ppc.hpp" 4833965Sjdp#endif 4933965Sjdp 5033965Sjdp#ifndef CC_INTERP 5133965Sjdp// All the necessary definitions used for (bytecode) template generation. Instead of 5233965Sjdp// spreading the implementation functionality for each bytecode in the interpreter 5333965Sjdp// and the snippet generator, a template is assigned to each bytecode which can be 5433965Sjdp// used to generate the bytecode's implementation if needed. 5538889Sjdp 5633965Sjdp 5733965Sjdp// A Template describes the properties of a code template for a given bytecode 5833965Sjdp// and provides a generator to generate the code template. 5933965Sjdp 6033965Sjdpclass Template VALUE_OBJ_CLASS_SPEC { 6133965Sjdp private: 6233965Sjdp enum Flags { 6333965Sjdp uses_bcp_bit, // set if template needs the bcp pointing to bytecode 6433965Sjdp does_dispatch_bit, // set if template dispatches on its own 6533965Sjdp calls_vm_bit, // set if template calls the vm 6633965Sjdp wide_bit // set if template belongs to a wide instruction 6733965Sjdp }; 6833965Sjdp 6933965Sjdp typedef void (*generator)(int arg); 7033965Sjdp 7133965Sjdp int _flags; // describes interpreter template properties (bcp unknown) 7233965Sjdp TosState _tos_in; // tos cache state before template execution 7333965Sjdp TosState _tos_out; // tos cache state after template execution 7433965Sjdp generator _gen; // template code generator 7533965Sjdp int _arg; // argument for template code generator 7633965Sjdp 7733965Sjdp void initialize(int flags, TosState tos_in, TosState tos_out, generator gen, int arg); 7833965Sjdp 7933965Sjdp friend class TemplateTable; 8033965Sjdp 8133965Sjdp public: 8233965Sjdp Bytecodes::Code bytecode() const; 8333965Sjdp bool is_valid() const { return _gen != NULL; } 8433965Sjdp bool uses_bcp() const { return (_flags & (1 << uses_bcp_bit )) != 0; } 8533965Sjdp bool does_dispatch() const { return (_flags & (1 << does_dispatch_bit)) != 0; } 8633965Sjdp bool calls_vm() const { return (_flags & (1 << calls_vm_bit )) != 0; } 8733965Sjdp bool is_wide() const { return (_flags & (1 << wide_bit )) != 0; } 8833965Sjdp TosState tos_in() const { return _tos_in; } 8933965Sjdp TosState tos_out() const { return _tos_out; } 9033965Sjdp void generate(InterpreterMacroAssembler* masm); 9133965Sjdp}; 9233965Sjdp 9333965Sjdp 9433965Sjdp// The TemplateTable defines all Templates and provides accessor functions 9533965Sjdp// to get the template for a given bytecode. 9633965Sjdp 9733965Sjdpclass TemplateTable: AllStatic { 9833965Sjdp public: 9933965Sjdp enum Operation { add, sub, mul, div, rem, _and, _or, _xor, shl, shr, ushr }; 10033965Sjdp enum Condition { equal, not_equal, less, less_equal, greater, greater_equal }; 10133965Sjdp enum CacheByte { f1_byte = 1, f2_byte = 2 }; // byte_no codes 10233965Sjdp 10333965Sjdp private: 10433965Sjdp static bool _is_initialized; // true if TemplateTable has been initialized 10533965Sjdp static Template _template_table [Bytecodes::number_of_codes]; 10633965Sjdp static Template _template_table_wide[Bytecodes::number_of_codes]; 10733965Sjdp 10833965Sjdp static Template* _desc; // the current template to be generated 10933965Sjdp static Bytecodes::Code bytecode() { return _desc->bytecode(); } 11033965Sjdp 11133965Sjdp static BarrierSet* _bs; // Cache the barrier set. 11233965Sjdp public: 11333965Sjdp //%note templates_1 11433965Sjdp static InterpreterMacroAssembler* _masm; // the assembler used when generating templates 11533965Sjdp 11633965Sjdp private: 11733965Sjdp 11833965Sjdp // special registers 11933965Sjdp static inline Address at_bcp(int offset); 12033965Sjdp 12133965Sjdp // helpers 12233965Sjdp static void unimplemented_bc(); 12333965Sjdp static void patch_bytecode(Bytecodes::Code bc, Register bc_reg, 12433965Sjdp Register temp_reg, bool load_bc_into_bc_reg = true, int byte_no = -1); 12533965Sjdp 12633965Sjdp // C calls 12733965Sjdp static void call_VM(Register oop_result, address entry_point); 12833965Sjdp static void call_VM(Register oop_result, address entry_point, Register arg_1); 12933965Sjdp static void call_VM(Register oop_result, address entry_point, Register arg_1, Register arg_2); 13033965Sjdp static void call_VM(Register oop_result, address entry_point, Register arg_1, Register arg_2, Register arg_3); 13133965Sjdp 13233965Sjdp // these overloadings are not presently used on SPARC: 13333965Sjdp static void call_VM(Register oop_result, Register last_java_sp, address entry_point); 13433965Sjdp static void call_VM(Register oop_result, Register last_java_sp, address entry_point, Register arg_1); 13533965Sjdp static void call_VM(Register oop_result, Register last_java_sp, address entry_point, Register arg_1, Register arg_2); 13633965Sjdp static void call_VM(Register oop_result, Register last_java_sp, address entry_point, Register arg_1, Register arg_2, Register arg_3); 13733965Sjdp 13833965Sjdp // bytecodes 13933965Sjdp static void nop(); 14033965Sjdp 14133965Sjdp static void aconst_null(); 14233965Sjdp static void iconst(int value); 14333965Sjdp static void lconst(int value); 14433965Sjdp static void fconst(int value); 14533965Sjdp static void dconst(int value); 14633965Sjdp 14733965Sjdp static void bipush(); 14833965Sjdp static void sipush(); 14938889Sjdp static void ldc(bool wide); 15033965Sjdp static void ldc2_w(); 15133965Sjdp static void fast_aldc(bool wide); 15233965Sjdp 15333965Sjdp static void locals_index(Register reg, int offset = 1); 15433965Sjdp static void iload(); 15533965Sjdp static void fast_iload(); 15633965Sjdp static void fast_iload2(); 15733965Sjdp static void fast_icaload(); 15833965Sjdp static void lload(); 15933965Sjdp static void fload(); 16033965Sjdp static void dload(); 16133965Sjdp static void aload(); 16233965Sjdp 16333965Sjdp static void locals_index_wide(Register reg); 16433965Sjdp static void wide_iload(); 16533965Sjdp static void wide_lload(); 16633965Sjdp static void wide_fload(); 16733965Sjdp static void wide_dload(); 16833965Sjdp static void wide_aload(); 16933965Sjdp 17033965Sjdp static void iaload(); 17133965Sjdp static void laload(); 17233965Sjdp static void faload(); 17333965Sjdp static void daload(); 17433965Sjdp static void aaload(); 17533965Sjdp static void baload(); 17633965Sjdp static void caload(); 17733965Sjdp static void saload(); 17833965Sjdp 17933965Sjdp static void iload(int n); 18033965Sjdp static void lload(int n); 18133965Sjdp static void fload(int n); 18233965Sjdp static void dload(int n); 18333965Sjdp static void aload(int n); 18433965Sjdp static void aload_0(); 18533965Sjdp 18633965Sjdp static void istore(); 18733965Sjdp static void lstore(); 18833965Sjdp static void fstore(); 18933965Sjdp static void dstore(); 19033965Sjdp static void astore(); 19133965Sjdp 19233965Sjdp static void wide_istore(); 19333965Sjdp static void wide_lstore(); 19433965Sjdp static void wide_fstore(); 19533965Sjdp static void wide_dstore(); 19633965Sjdp static void wide_astore(); 19733965Sjdp 19833965Sjdp static void iastore(); 19933965Sjdp static void lastore(); 20033965Sjdp static void fastore(); 20133965Sjdp static void dastore(); 20233965Sjdp static void aastore(); 20333965Sjdp static void bastore(); 20433965Sjdp static void castore(); 20533965Sjdp static void sastore(); 20633965Sjdp 20733965Sjdp static void istore(int n); 20833965Sjdp static void lstore(int n); 20933965Sjdp static void fstore(int n); 21033965Sjdp static void dstore(int n); 21133965Sjdp static void astore(int n); 21233965Sjdp 21333965Sjdp static void pop(); 21433965Sjdp static void pop2(); 21533965Sjdp static void dup(); 21633965Sjdp static void dup_x1(); 21733965Sjdp static void dup_x2(); 21833965Sjdp static void dup2(); 21933965Sjdp static void dup2_x1(); 22033965Sjdp static void dup2_x2(); 22133965Sjdp static void swap(); 22233965Sjdp 22333965Sjdp static void iop2(Operation op); 22433965Sjdp static void lop2(Operation op); 22533965Sjdp static void fop2(Operation op); 22633965Sjdp static void dop2(Operation op); 22733965Sjdp 22838889Sjdp static void idiv(); 22933965Sjdp static void irem(); 23033965Sjdp 23133965Sjdp static void lmul(); 23233965Sjdp static void ldiv(); 23333965Sjdp static void lrem(); 23433965Sjdp static void lshl(); 23533965Sjdp static void lshr(); 23633965Sjdp static void lushr(); 23733965Sjdp 23838889Sjdp static void ineg(); 23933965Sjdp static void lneg(); 24033965Sjdp static void fneg(); 24133965Sjdp static void dneg(); 24233965Sjdp 24333965Sjdp static void iinc(); 24433965Sjdp static void wide_iinc(); 24533965Sjdp static void convert(); 24633965Sjdp static void lcmp(); 24733965Sjdp 24833965Sjdp static void float_cmp (bool is_float, int unordered_result); 24933965Sjdp static void float_cmp (int unordered_result); 25033965Sjdp static void double_cmp(int unordered_result); 25133965Sjdp 25233965Sjdp static void count_calls(Register method, Register temp); 25333965Sjdp static void branch(bool is_jsr, bool is_wide); 25433965Sjdp static void if_0cmp (Condition cc); 25533965Sjdp static void if_icmp (Condition cc); 25633965Sjdp static void if_nullcmp(Condition cc); 25733965Sjdp static void if_acmp (Condition cc); 25833965Sjdp 25933965Sjdp static void _goto(); 26033965Sjdp static void jsr(); 26133965Sjdp static void ret(); 26233965Sjdp static void wide_ret(); 26333965Sjdp 26433965Sjdp static void goto_w(); 26533965Sjdp static void jsr_w(); 26633965Sjdp 26733965Sjdp static void tableswitch(); 26833965Sjdp static void lookupswitch(); 26933965Sjdp static void fast_linearswitch(); 27033965Sjdp static void fast_binaryswitch(); 27133965Sjdp 27233965Sjdp static void _return(TosState state); 27333965Sjdp 27433965Sjdp static void resolve_cache_and_index(int byte_no, // one of 1,2,11 27533965Sjdp Register cache, // output for CP cache 27633965Sjdp Register index, // output for CP index 27733965Sjdp size_t index_size); // one of 1,2,4 27833965Sjdp static void load_invoke_cp_cache_entry(int byte_no, 27933965Sjdp Register method, 28033965Sjdp Register itable_index, 28133965Sjdp Register flags, 28233965Sjdp bool is_invokevirtual, 28333965Sjdp bool is_virtual_final, 28433965Sjdp bool is_invokedynamic); 28533965Sjdp static void load_field_cp_cache_entry(Register obj, 28633965Sjdp Register cache, 28733965Sjdp Register index, 28833965Sjdp Register offset, 28933965Sjdp Register flags, 29033965Sjdp bool is_static); 29133965Sjdp static void invokevirtual(int byte_no); 29233965Sjdp static void invokespecial(int byte_no); 29333965Sjdp static void invokestatic(int byte_no); 29433965Sjdp static void invokeinterface(int byte_no); 29533965Sjdp static void invokedynamic(int byte_no); 29633965Sjdp static void invokehandle(int byte_no); 29733965Sjdp static void fast_invokevfinal(int byte_no); 29833965Sjdp 29933965Sjdp static void getfield_or_static(int byte_no, bool is_static); 30033965Sjdp static void putfield_or_static(int byte_no, bool is_static); 30133965Sjdp static void getfield(int byte_no); 30233965Sjdp static void putfield(int byte_no); 30333965Sjdp static void getstatic(int byte_no); 30433965Sjdp static void putstatic(int byte_no); 30533965Sjdp static void pop_and_check_object(Register obj); 30633965Sjdp 30733965Sjdp static void _new(); 30833965Sjdp static void newarray(); 30933965Sjdp static void anewarray(); 31033965Sjdp static void arraylength(); 31133965Sjdp static void checkcast(); 31233965Sjdp static void instanceof(); 31333965Sjdp 31433965Sjdp static void athrow(); 31533965Sjdp 31633965Sjdp static void monitorenter(); 31733965Sjdp static void monitorexit(); 31833965Sjdp 31933965Sjdp static void wide(); 32033965Sjdp static void multianewarray(); 32133965Sjdp 32233965Sjdp static void fast_xaccess(TosState state); 32333965Sjdp static void fast_accessfield(TosState state); 32433965Sjdp static void fast_storefield(TosState state); 32533965Sjdp 32633965Sjdp static void _breakpoint(); 32733965Sjdp 32833965Sjdp static void shouldnotreachhere(); 32933965Sjdp 33033965Sjdp // jvmti support 33133965Sjdp static void jvmti_post_field_access(Register cache, Register index, bool is_static, bool has_tos); 33233965Sjdp static void jvmti_post_field_mod(Register cache, Register index, bool is_static); 33333965Sjdp static void jvmti_post_fast_field_mod(); 33433965Sjdp 33533965Sjdp // debugging of TemplateGenerator 33633965Sjdp static void transition(TosState tos_in, TosState tos_out);// checks if in/out states expected by template generator correspond to table entries 33733965Sjdp 33833965Sjdp // initialization helpers 33933965Sjdp static void def(Bytecodes::Code code, int flags, TosState in, TosState out, void (*gen)( ), char filler ); 34033965Sjdp static void def(Bytecodes::Code code, int flags, TosState in, TosState out, void (*gen)(int arg ), int arg ); 34133965Sjdp static void def(Bytecodes::Code code, int flags, TosState in, TosState out, void (*gen)(bool arg ), bool arg ); 34233965Sjdp static void def(Bytecodes::Code code, int flags, TosState in, TosState out, void (*gen)(TosState tos), TosState tos); 34333965Sjdp static void def(Bytecodes::Code code, int flags, TosState in, TosState out, void (*gen)(Operation op), Operation op); 34433965Sjdp static void def(Bytecodes::Code code, int flags, TosState in, TosState out, void (*gen)(Condition cc), Condition cc); 34533965Sjdp 34633965Sjdp friend class Template; 34733965Sjdp 34833965Sjdp // InterpreterMacroAssembler::is_a(), etc., need TemplateTable::call_VM(). 34933965Sjdp friend class InterpreterMacroAssembler; 35033965Sjdp 35133965Sjdp public: 35233965Sjdp // Initialization 35333965Sjdp static void initialize(); 35433965Sjdp static void pd_initialize(); 35533965Sjdp 35633965Sjdp // Templates 35733965Sjdp static Template* template_for (Bytecodes::Code code) { Bytecodes::check (code); return &_template_table [code]; } 35833965Sjdp static Template* template_for_wide(Bytecodes::Code code) { Bytecodes::wide_check(code); return &_template_table_wide[code]; } 35933965Sjdp 36033965Sjdp // Platform specifics 36133965Sjdp#ifdef TARGET_ARCH_MODEL_x86_32 36233965Sjdp# include "templateTable_x86_32.hpp" 36333965Sjdp#endif 36433965Sjdp#ifdef TARGET_ARCH_MODEL_x86_64 36533965Sjdp# include "templateTable_x86_64.hpp" 36633965Sjdp#endif 36733965Sjdp#ifdef TARGET_ARCH_MODEL_sparc 36833965Sjdp# include "templateTable_sparc.hpp" 36933965Sjdp#endif 37033965Sjdp#ifdef TARGET_ARCH_MODEL_zero 37133965Sjdp# include "templateTable_zero.hpp" 37233965Sjdp#endif 37333965Sjdp#ifdef TARGET_ARCH_MODEL_arm 37433965Sjdp# include "templateTable_arm.hpp" 37533965Sjdp#endif 37633965Sjdp#ifdef TARGET_ARCH_MODEL_ppc 37733965Sjdp# include "templateTable_ppc.hpp" 37833965Sjdp#endif 37933965Sjdp 38033965Sjdp}; 38133965Sjdp#endif /* !CC_INTERP */ 38233965Sjdp 38333965Sjdp#endif // SHARE_VM_INTERPRETER_TEMPLATETABLE_HPP 38433965Sjdp