src/share/vm/interpreter/templateTable.hpp

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

mercurial