templateTable.hpp revision 5776:de6a9e811145
1/*
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25#ifndef SHARE_VM_INTERPRETER_TEMPLATETABLE_HPP
26#define SHARE_VM_INTERPRETER_TEMPLATETABLE_HPP
27
28#include "interpreter/bytecodes.hpp"
29#include "memory/allocation.hpp"
30#include "runtime/frame.hpp"
31#ifdef TARGET_ARCH_x86
32# include "interp_masm_x86.hpp"
33#endif
34#ifdef TARGET_ARCH_MODEL_sparc
35# include "interp_masm_sparc.hpp"
36#endif
37#ifdef TARGET_ARCH_MODEL_zero
38# include "interp_masm_zero.hpp"
39#endif
40#ifdef TARGET_ARCH_MODEL_arm
41# include "interp_masm_arm.hpp"
42#endif
43#ifdef TARGET_ARCH_MODEL_ppc
44# include "interp_masm_ppc.hpp"
45#endif
46
47#ifndef CC_INTERP
48// All the necessary definitions used for (bytecode) template generation. Instead of
49// spreading the implementation functionality for each bytecode in the interpreter
50// and the snippet generator, a template is assigned to each bytecode which can be
51// used to generate the bytecode's implementation if needed.
52
53
54// A Template describes the properties of a code template for a given bytecode
55// and provides a generator to generate the code template.
56
57class Template VALUE_OBJ_CLASS_SPEC {
58 private:
59  enum Flags {
60    uses_bcp_bit,                                // set if template needs the bcp pointing to bytecode
61    does_dispatch_bit,                           // set if template dispatches on its own
62    calls_vm_bit,                                // set if template calls the vm
63    wide_bit                                     // set if template belongs to a wide instruction
64  };
65
66  typedef void (*generator)(int arg);
67
68  int       _flags;                              // describes interpreter template properties (bcp unknown)
69  TosState  _tos_in;                             // tos cache state before template execution
70  TosState  _tos_out;                            // tos cache state after  template execution
71  generator _gen;                                // template code generator
72  int       _arg;                                // argument for template code generator
73
74  void      initialize(int flags, TosState tos_in, TosState tos_out, generator gen, int arg);
75
76  friend class TemplateTable;
77
78 public:
79  Bytecodes::Code bytecode() const;
80  bool      is_valid() const                     { return _gen != NULL; }
81  bool      uses_bcp() const                     { return (_flags & (1 << uses_bcp_bit     )) != 0; }
82  bool      does_dispatch() const                { return (_flags & (1 << does_dispatch_bit)) != 0; }
83  bool      calls_vm() const                     { return (_flags & (1 << calls_vm_bit     )) != 0; }
84  bool      is_wide() const                      { return (_flags & (1 << wide_bit         )) != 0; }
85  TosState  tos_in() const                       { return _tos_in; }
86  TosState  tos_out() const                      { return _tos_out; }
87  void      generate(InterpreterMacroAssembler* masm);
88};
89
90
91// The TemplateTable defines all Templates and provides accessor functions
92// to get the template for a given bytecode.
93
94class TemplateTable: AllStatic {
95 public:
96  enum Operation { add, sub, mul, div, rem, _and, _or, _xor, shl, shr, ushr };
97  enum Condition { equal, not_equal, less, less_equal, greater, greater_equal };
98  enum CacheByte { f1_byte = 1, f2_byte = 2 };  // byte_no codes
99
100 private:
101  static bool            _is_initialized;        // true if TemplateTable has been initialized
102  static Template        _template_table     [Bytecodes::number_of_codes];
103  static Template        _template_table_wide[Bytecodes::number_of_codes];
104
105  static Template*       _desc;                  // the current template to be generated
106  static Bytecodes::Code bytecode()              { return _desc->bytecode(); }
107
108  static BarrierSet*     _bs;                    // Cache the barrier set.
109 public:
110  //%note templates_1
111  static InterpreterMacroAssembler* _masm;       // the assembler used when generating templates
112
113 private:
114
115  // special registers
116  static inline Address at_bcp(int offset);
117
118  // helpers
119  static void unimplemented_bc();
120  static void patch_bytecode(Bytecodes::Code bc, Register bc_reg,
121                             Register temp_reg, bool load_bc_into_bc_reg = true, int byte_no = -1);
122
123  // C calls
124  static void call_VM(Register oop_result, address entry_point);
125  static void call_VM(Register oop_result, address entry_point, Register arg_1);
126  static void call_VM(Register oop_result, address entry_point, Register arg_1, Register arg_2);
127  static void call_VM(Register oop_result, address entry_point, Register arg_1, Register arg_2, Register arg_3);
128
129  // these overloadings are not presently used on SPARC:
130  static void call_VM(Register oop_result, Register last_java_sp, address entry_point);
131  static void call_VM(Register oop_result, Register last_java_sp, address entry_point, Register arg_1);
132  static void call_VM(Register oop_result, Register last_java_sp, address entry_point, Register arg_1, Register arg_2);
133  static void call_VM(Register oop_result, Register last_java_sp, address entry_point, Register arg_1, Register arg_2, Register arg_3);
134
135  // bytecodes
136  static void nop();
137
138  static void aconst_null();
139  static void iconst(int value);
140  static void lconst(int value);
141  static void fconst(int value);
142  static void dconst(int value);
143
144  static void bipush();
145  static void sipush();
146  static void ldc(bool wide);
147  static void ldc2_w();
148  static void fast_aldc(bool wide);
149
150  static void locals_index(Register reg, int offset = 1);
151  static void iload();
152  static void fast_iload();
153  static void fast_iload2();
154  static void fast_icaload();
155  static void lload();
156  static void fload();
157  static void dload();
158  static void aload();
159
160  static void locals_index_wide(Register reg);
161  static void wide_iload();
162  static void wide_lload();
163  static void wide_fload();
164  static void wide_dload();
165  static void wide_aload();
166
167  static void iaload();
168  static void laload();
169  static void faload();
170  static void daload();
171  static void aaload();
172  static void baload();
173  static void caload();
174  static void saload();
175
176  static void iload(int n);
177  static void lload(int n);
178  static void fload(int n);
179  static void dload(int n);
180  static void aload(int n);
181  static void aload_0();
182
183  static void istore();
184  static void lstore();
185  static void fstore();
186  static void dstore();
187  static void astore();
188
189  static void wide_istore();
190  static void wide_lstore();
191  static void wide_fstore();
192  static void wide_dstore();
193  static void wide_astore();
194
195  static void iastore();
196  static void lastore();
197  static void fastore();
198  static void dastore();
199  static void aastore();
200  static void bastore();
201  static void castore();
202  static void sastore();
203
204  static void istore(int n);
205  static void lstore(int n);
206  static void fstore(int n);
207  static void dstore(int n);
208  static void astore(int n);
209
210  static void pop();
211  static void pop2();
212  static void dup();
213  static void dup_x1();
214  static void dup_x2();
215  static void dup2();
216  static void dup2_x1();
217  static void dup2_x2();
218  static void swap();
219
220  static void iop2(Operation op);
221  static void lop2(Operation op);
222  static void fop2(Operation op);
223  static void dop2(Operation op);
224
225  static void idiv();
226  static void irem();
227
228  static void lmul();
229  static void ldiv();
230  static void lrem();
231  static void lshl();
232  static void lshr();
233  static void lushr();
234
235  static void ineg();
236  static void lneg();
237  static void fneg();
238  static void dneg();
239
240  static void iinc();
241  static void wide_iinc();
242  static void convert();
243  static void lcmp();
244
245  static void float_cmp (bool is_float, int unordered_result);
246  static void float_cmp (int unordered_result);
247  static void double_cmp(int unordered_result);
248
249  static void count_calls(Register method, Register temp);
250  static void branch(bool is_jsr, bool is_wide);
251  static void if_0cmp   (Condition cc);
252  static void if_icmp   (Condition cc);
253  static void if_nullcmp(Condition cc);
254  static void if_acmp   (Condition cc);
255
256  static void _goto();
257  static void jsr();
258  static void ret();
259  static void wide_ret();
260
261  static void goto_w();
262  static void jsr_w();
263
264  static void tableswitch();
265  static void lookupswitch();
266  static void fast_linearswitch();
267  static void fast_binaryswitch();
268
269  static void _return(TosState state);
270
271  static void resolve_cache_and_index(int byte_no,       // one of 1,2,11
272                                      Register cache,    // output for CP cache
273                                      Register index,    // output for CP index
274                                      size_t index_size); // one of 1,2,4
275  static void load_invoke_cp_cache_entry(int byte_no,
276                                         Register method,
277                                         Register itable_index,
278                                         Register flags,
279                                         bool is_invokevirtual,
280                                         bool is_virtual_final,
281                                         bool is_invokedynamic);
282  static void load_field_cp_cache_entry(Register obj,
283                                        Register cache,
284                                        Register index,
285                                        Register offset,
286                                        Register flags,
287                                        bool is_static);
288  static void invokevirtual(int byte_no);
289  static void invokespecial(int byte_no);
290  static void invokestatic(int byte_no);
291  static void invokeinterface(int byte_no);
292  static void invokedynamic(int byte_no);
293  static void invokehandle(int byte_no);
294  static void fast_invokevfinal(int byte_no);
295
296  static void getfield_or_static(int byte_no, bool is_static);
297  static void putfield_or_static(int byte_no, bool is_static);
298  static void getfield(int byte_no);
299  static void putfield(int byte_no);
300  static void getstatic(int byte_no);
301  static void putstatic(int byte_no);
302  static void pop_and_check_object(Register obj);
303
304  static void _new();
305  static void newarray();
306  static void anewarray();
307  static void arraylength();
308  static void checkcast();
309  static void instanceof();
310
311  static void athrow();
312
313  static void monitorenter();
314  static void monitorexit();
315
316  static void wide();
317  static void multianewarray();
318
319  static void fast_xaccess(TosState state);
320  static void fast_accessfield(TosState state);
321  static void fast_storefield(TosState state);
322
323  static void _breakpoint();
324
325  static void shouldnotreachhere();
326
327  // jvmti support
328  static void jvmti_post_field_access(Register cache, Register index, bool is_static, bool has_tos);
329  static void jvmti_post_field_mod(Register cache, Register index, bool is_static);
330  static void jvmti_post_fast_field_mod();
331
332  // debugging of TemplateGenerator
333  static void transition(TosState tos_in, TosState tos_out);// checks if in/out states expected by template generator correspond to table entries
334
335  // initialization helpers
336  static void def(Bytecodes::Code code, int flags, TosState in, TosState out, void (*gen)(            ), char filler );
337  static void def(Bytecodes::Code code, int flags, TosState in, TosState out, void (*gen)(int arg     ), int arg     );
338 static void def(Bytecodes::Code code, int flags, TosState in, TosState out, void (*gen)(bool arg    ), bool arg    );
339  static void def(Bytecodes::Code code, int flags, TosState in, TosState out, void (*gen)(TosState tos), TosState tos);
340  static void def(Bytecodes::Code code, int flags, TosState in, TosState out, void (*gen)(Operation op), Operation op);
341  static void def(Bytecodes::Code code, int flags, TosState in, TosState out, void (*gen)(Condition cc), Condition cc);
342
343  friend class Template;
344
345  // InterpreterMacroAssembler::is_a(), etc., need TemplateTable::call_VM().
346  friend class InterpreterMacroAssembler;
347
348 public:
349  // Initialization
350  static void initialize();
351  static void pd_initialize();
352
353  // Templates
354  static Template* template_for     (Bytecodes::Code code)  { Bytecodes::check     (code); return &_template_table     [code]; }
355  static Template* template_for_wide(Bytecodes::Code code)  { Bytecodes::wide_check(code); return &_template_table_wide[code]; }
356
357  // Platform specifics
358#ifdef TARGET_ARCH_MODEL_x86_32
359# include "templateTable_x86_32.hpp"
360#endif
361#ifdef TARGET_ARCH_MODEL_x86_64
362# include "templateTable_x86_64.hpp"
363#endif
364#ifdef TARGET_ARCH_MODEL_sparc
365# include "templateTable_sparc.hpp"
366#endif
367#ifdef TARGET_ARCH_MODEL_zero
368# include "templateTable_zero.hpp"
369#endif
370#ifdef TARGET_ARCH_MODEL_arm
371# include "templateTable_arm.hpp"
372#endif
373#ifdef TARGET_ARCH_MODEL_ppc
374# include "templateTable_ppc.hpp"
375#endif
376
377};
378#endif /* !CC_INTERP */
379
380#endif // SHARE_VM_INTERPRETER_TEMPLATETABLE_HPP
381