hotspot/src/share/vm/interpreter/templateTable.hpp
changeset 1 489c9b5090e2
child 1374 4c24294029a9
equal deleted inserted replaced
0:fd16c54261b3 1:489c9b5090e2
       
     1 /*
       
     2  * Copyright 1997-2005 Sun Microsystems, Inc.  All Rights Reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
       
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
       
    21  * have any questions.
       
    22  *
       
    23  */
       
    24 
       
    25 #ifndef CC_INTERP
       
    26 // All the necessary definitions used for (bytecode) template generation. Instead of
       
    27 // spreading the implementation functionality for each bytecode in the interpreter
       
    28 // and the snippet generator, a template is assigned to each bytecode which can be
       
    29 // used to generate the bytecode's implementation if needed.
       
    30 
       
    31 
       
    32 // A Template describes the properties of a code template for a given bytecode
       
    33 // and provides a generator to generate the code template.
       
    34 
       
    35 class Template VALUE_OBJ_CLASS_SPEC {
       
    36  private:
       
    37   enum Flags {
       
    38     uses_bcp_bit,                                // set if template needs the bcp pointing to bytecode
       
    39     does_dispatch_bit,                           // set if template dispatches on its own
       
    40     calls_vm_bit,                                // set if template calls the vm
       
    41     wide_bit                                     // set if template belongs to a wide instruction
       
    42   };
       
    43 
       
    44   typedef void (*generator)(int arg);
       
    45 
       
    46   int       _flags;                              // describes interpreter template properties (bcp unknown)
       
    47   TosState  _tos_in;                             // tos cache state before template execution
       
    48   TosState  _tos_out;                            // tos cache state after  template execution
       
    49   generator _gen;                                // template code generator
       
    50   int       _arg;                                // argument for template code generator
       
    51 
       
    52   void      initialize(int flags, TosState tos_in, TosState tos_out, generator gen, int arg);
       
    53 
       
    54   friend class TemplateTable;
       
    55 
       
    56  public:
       
    57   Bytecodes::Code bytecode() const;
       
    58   bool      is_valid() const                     { return _gen != NULL; }
       
    59   bool      uses_bcp() const                     { return (_flags & (1 << uses_bcp_bit     )) != 0; }
       
    60   bool      does_dispatch() const                { return (_flags & (1 << does_dispatch_bit)) != 0; }
       
    61   bool      calls_vm() const                     { return (_flags & (1 << calls_vm_bit     )) != 0; }
       
    62   bool      is_wide() const                      { return (_flags & (1 << wide_bit         )) != 0; }
       
    63   TosState  tos_in() const                       { return _tos_in; }
       
    64   TosState  tos_out() const                      { return _tos_out; }
       
    65   void      generate(InterpreterMacroAssembler* masm);
       
    66 };
       
    67 
       
    68 
       
    69 // The TemplateTable defines all Templates and provides accessor functions
       
    70 // to get the template for a given bytecode.
       
    71 
       
    72 class TemplateTable: AllStatic {
       
    73  public:
       
    74   enum Operation { add, sub, mul, div, rem, _and, _or, _xor, shl, shr, ushr };
       
    75   enum Condition { equal, not_equal, less, less_equal, greater, greater_equal };
       
    76 
       
    77  private:
       
    78   static bool            _is_initialized;        // true if TemplateTable has been initialized
       
    79   static Template        _template_table     [Bytecodes::number_of_codes];
       
    80   static Template        _template_table_wide[Bytecodes::number_of_codes];
       
    81 
       
    82   static Template*       _desc;                  // the current template to be generated
       
    83   static Bytecodes::Code bytecode()              { return _desc->bytecode(); }
       
    84 
       
    85  public:
       
    86   //%note templates_1
       
    87   static InterpreterMacroAssembler* _masm;       // the assembler used when generating templates
       
    88 
       
    89  private:
       
    90 
       
    91   // special registers
       
    92   static inline Address at_bcp(int offset);
       
    93 
       
    94   // helpers
       
    95   static void unimplemented_bc();
       
    96   static void patch_bytecode(Bytecodes::Code bc, Register scratch1,
       
    97                              Register scratch2, bool load_bc_in_scratch = true);
       
    98 
       
    99   // C calls
       
   100   static void call_VM(Register oop_result, address entry_point);
       
   101   static void call_VM(Register oop_result, address entry_point, Register arg_1);
       
   102   static void call_VM(Register oop_result, address entry_point, Register arg_1, Register arg_2);
       
   103   static void call_VM(Register oop_result, address entry_point, Register arg_1, Register arg_2, Register arg_3);
       
   104 
       
   105   // these overloadings are not presently used on SPARC:
       
   106   static void call_VM(Register oop_result, Register last_java_sp, address entry_point);
       
   107   static void call_VM(Register oop_result, Register last_java_sp, address entry_point, Register arg_1);
       
   108   static void call_VM(Register oop_result, Register last_java_sp, address entry_point, Register arg_1, Register arg_2);
       
   109   static void call_VM(Register oop_result, Register last_java_sp, address entry_point, Register arg_1, Register arg_2, Register arg_3);
       
   110 
       
   111   // bytecodes
       
   112   static void nop();
       
   113 
       
   114   static void aconst_null();
       
   115   static void iconst(int value);
       
   116   static void lconst(int value);
       
   117   static void fconst(int value);
       
   118   static void dconst(int value);
       
   119 
       
   120   static void bipush();
       
   121   static void sipush();
       
   122   static void ldc(bool wide);
       
   123   static void ldc2_w();
       
   124 
       
   125   static void locals_index(Register reg, int offset = 1);
       
   126   static void iload();
       
   127   static void fast_iload();
       
   128   static void fast_iload2();
       
   129   static void fast_icaload();
       
   130   static void lload();
       
   131   static void fload();
       
   132   static void dload();
       
   133   static void aload();
       
   134 
       
   135   static void locals_index_wide(Register reg);
       
   136   static void wide_iload();
       
   137   static void wide_lload();
       
   138   static void wide_fload();
       
   139   static void wide_dload();
       
   140   static void wide_aload();
       
   141 
       
   142   static void iaload();
       
   143   static void laload();
       
   144   static void faload();
       
   145   static void daload();
       
   146   static void aaload();
       
   147   static void baload();
       
   148   static void caload();
       
   149   static void saload();
       
   150 
       
   151   static void iload(int n);
       
   152   static void lload(int n);
       
   153   static void fload(int n);
       
   154   static void dload(int n);
       
   155   static void aload(int n);
       
   156   static void aload_0();
       
   157 
       
   158   static void istore();
       
   159   static void lstore();
       
   160   static void fstore();
       
   161   static void dstore();
       
   162   static void astore();
       
   163 
       
   164   static void wide_istore();
       
   165   static void wide_lstore();
       
   166   static void wide_fstore();
       
   167   static void wide_dstore();
       
   168   static void wide_astore();
       
   169 
       
   170   static void iastore();
       
   171   static void lastore();
       
   172   static void fastore();
       
   173   static void dastore();
       
   174   static void aastore();
       
   175   static void bastore();
       
   176   static void castore();
       
   177   static void sastore();
       
   178 
       
   179   static void istore(int n);
       
   180   static void lstore(int n);
       
   181   static void fstore(int n);
       
   182   static void dstore(int n);
       
   183   static void astore(int n);
       
   184 
       
   185   static void pop();
       
   186   static void pop2();
       
   187   static void dup();
       
   188   static void dup_x1();
       
   189   static void dup_x2();
       
   190   static void dup2();
       
   191   static void dup2_x1();
       
   192   static void dup2_x2();
       
   193   static void swap();
       
   194 
       
   195   static void iop2(Operation op);
       
   196   static void lop2(Operation op);
       
   197   static void fop2(Operation op);
       
   198   static void dop2(Operation op);
       
   199 
       
   200   static void idiv();
       
   201   static void irem();
       
   202 
       
   203   static void lmul();
       
   204   static void ldiv();
       
   205   static void lrem();
       
   206   static void lshl();
       
   207   static void lshr();
       
   208   static void lushr();
       
   209 
       
   210   static void ineg();
       
   211   static void lneg();
       
   212   static void fneg();
       
   213   static void dneg();
       
   214 
       
   215   static void iinc();
       
   216   static void wide_iinc();
       
   217   static void convert();
       
   218   static void lcmp();
       
   219 
       
   220   static void float_cmp (bool is_float, int unordered_result);
       
   221   static void float_cmp (int unordered_result);
       
   222   static void double_cmp(int unordered_result);
       
   223 
       
   224   static void count_calls(Register method, Register temp);
       
   225   static void branch(bool is_jsr, bool is_wide);
       
   226   static void if_0cmp   (Condition cc);
       
   227   static void if_icmp   (Condition cc);
       
   228   static void if_nullcmp(Condition cc);
       
   229   static void if_acmp   (Condition cc);
       
   230 
       
   231   static void _goto();
       
   232   static void jsr();
       
   233   static void ret();
       
   234   static void wide_ret();
       
   235 
       
   236   static void goto_w();
       
   237   static void jsr_w();
       
   238 
       
   239   static void tableswitch();
       
   240   static void lookupswitch();
       
   241   static void fast_linearswitch();
       
   242   static void fast_binaryswitch();
       
   243 
       
   244   static void _return(TosState state);
       
   245 
       
   246   static void resolve_cache_and_index(int byte_no, Register cache, Register index);
       
   247   static void load_invoke_cp_cache_entry(int byte_no,
       
   248                                          Register method,
       
   249                                          Register itable_index,
       
   250                                          Register flags,
       
   251                                          bool is_invokevirtual = false,
       
   252                                          bool is_virtual_final = false);
       
   253   static void load_field_cp_cache_entry(Register obj,
       
   254                                         Register cache,
       
   255                                         Register index,
       
   256                                         Register offset,
       
   257                                         Register flags,
       
   258                                         bool is_static);
       
   259   static void invokevirtual(int byte_no);
       
   260   static void invokespecial(int byte_no);
       
   261   static void invokestatic(int byte_no);
       
   262   static void invokeinterface(int byte_no);
       
   263   static void fast_invokevfinal(int byte_no);
       
   264 
       
   265   static void getfield_or_static(int byte_no, bool is_static);
       
   266   static void putfield_or_static(int byte_no, bool is_static);
       
   267   static void getfield(int byte_no);
       
   268   static void putfield(int byte_no);
       
   269   static void getstatic(int byte_no);
       
   270   static void putstatic(int byte_no);
       
   271   static void pop_and_check_object(Register obj);
       
   272 
       
   273   static void _new();
       
   274   static void newarray();
       
   275   static void anewarray();
       
   276   static void arraylength();
       
   277   static void checkcast();
       
   278   static void instanceof();
       
   279 
       
   280   static void athrow();
       
   281 
       
   282   static void monitorenter();
       
   283   static void monitorexit();
       
   284 
       
   285   static void wide();
       
   286   static void multianewarray();
       
   287 
       
   288   static void fast_xaccess(TosState state);
       
   289   static void fast_accessfield(TosState state);
       
   290   static void fast_storefield(TosState state);
       
   291 
       
   292   static void _breakpoint();
       
   293 
       
   294   static void shouldnotreachhere();
       
   295 
       
   296   // jvmti support
       
   297   static void jvmti_post_field_access(Register cache, Register index, bool is_static, bool has_tos);
       
   298   static void jvmti_post_field_mod(Register cache, Register index, bool is_static);
       
   299   static void jvmti_post_fast_field_mod();
       
   300 
       
   301   // debugging of TemplateGenerator
       
   302   static void transition(TosState tos_in, TosState tos_out);// checks if in/out states expected by template generator correspond to table entries
       
   303 
       
   304   // initialization helpers
       
   305   static void def(Bytecodes::Code code, int flags, TosState in, TosState out, void (*gen)(            ), char filler );
       
   306   static void def(Bytecodes::Code code, int flags, TosState in, TosState out, void (*gen)(int arg     ), int arg     );
       
   307  static void def(Bytecodes::Code code, int flags, TosState in, TosState out, void (*gen)(bool arg    ), bool arg    );
       
   308   static void def(Bytecodes::Code code, int flags, TosState in, TosState out, void (*gen)(TosState tos), TosState tos);
       
   309   static void def(Bytecodes::Code code, int flags, TosState in, TosState out, void (*gen)(Operation op), Operation op);
       
   310   static void def(Bytecodes::Code code, int flags, TosState in, TosState out, void (*gen)(Condition cc), Condition cc);
       
   311 
       
   312   friend class Template;
       
   313 
       
   314   // InterpreterMacroAssembler::is_a(), etc., need TemplateTable::call_VM().
       
   315   friend class InterpreterMacroAssembler;
       
   316 
       
   317  public:
       
   318   // Initialization
       
   319   static void initialize();
       
   320   static void pd_initialize();
       
   321 
       
   322   // Templates
       
   323   static Template* template_for     (Bytecodes::Code code)  { Bytecodes::check     (code); return &_template_table     [code]; }
       
   324   static Template* template_for_wide(Bytecodes::Code code)  { Bytecodes::wide_check(code); return &_template_table_wide[code]; }
       
   325 
       
   326   // Platform specifics
       
   327   #include "incls/_templateTable_pd.hpp.incl"
       
   328 };
       
   329 #endif /* !CC_INTERP */