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