author | coleenp |
Thu, 01 Dec 2016 14:21:31 -0500 | |
changeset 44738 | 11431bbc9549 |
parent 44406 | a46a6c4d1dd9 |
child 46369 | 3bf4544bec14 |
permissions | -rw-r--r-- |
42065 | 1 |
/* |
44406
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
2 |
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved. |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
3 |
* Copyright (c) 2016, 2017 SAP SE. All rights reserved. |
42065 | 4 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
5 |
* |
|
6 |
* This code is free software; you can redistribute it and/or modify it |
|
7 |
* under the terms of the GNU General Public License version 2 only, as |
|
8 |
* published by the Free Software Foundation. |
|
9 |
* |
|
10 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
11 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
14 |
* accompanied this code). |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License version |
|
17 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
18 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
19 |
* |
|
20 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
21 |
* or visit www.oracle.com if you need additional information or have any |
|
22 |
* questions. |
|
23 |
* |
|
24 |
*/ |
|
25 |
||
26 |
#include "precompiled.hpp" |
|
27 |
#include "asm/macroAssembler.inline.hpp" |
|
28 |
#include "interpreter/abstractInterpreter.hpp" |
|
29 |
#include "interpreter/bytecodeHistogram.hpp" |
|
30 |
#include "interpreter/interpreter.hpp" |
|
31 |
#include "interpreter/interpreterRuntime.hpp" |
|
32 |
#include "interpreter/interp_masm.hpp" |
|
33 |
#include "interpreter/templateInterpreterGenerator.hpp" |
|
34 |
#include "interpreter/templateTable.hpp" |
|
35 |
#include "oops/arrayOop.hpp" |
|
36 |
#include "oops/oop.inline.hpp" |
|
37 |
#include "prims/jvmtiExport.hpp" |
|
38 |
#include "prims/jvmtiThreadState.hpp" |
|
39 |
#include "runtime/arguments.hpp" |
|
40 |
#include "runtime/deoptimization.hpp" |
|
41 |
#include "runtime/frame.inline.hpp" |
|
42 |
#include "runtime/sharedRuntime.hpp" |
|
43 |
#include "runtime/stubRoutines.hpp" |
|
44 |
#include "runtime/synchronizer.hpp" |
|
45 |
#include "runtime/timer.hpp" |
|
46 |
#include "runtime/vframeArray.hpp" |
|
47 |
#include "utilities/debug.hpp" |
|
48 |
||
49 |
||
50 |
// Size of interpreter code. Increase if too small. Interpreter will |
|
51 |
// fail with a guarantee ("not enough space for interpreter generation"); |
|
52 |
// if too small. |
|
53 |
// Run with +PrintInterpreter to get the VM to print out the size. |
|
54 |
// Max size with JVMTI |
|
55 |
int TemplateInterpreter::InterpreterCodeSize = 320*K; |
|
56 |
||
57 |
#undef __ |
|
58 |
#ifdef PRODUCT |
|
59 |
#define __ _masm-> |
|
60 |
#else |
|
61 |
#define __ _masm-> |
|
62 |
// #define __ (Verbose ? (_masm->block_comment(FILE_AND_LINE),_masm):_masm)-> |
|
63 |
#endif |
|
64 |
||
65 |
#define BLOCK_COMMENT(str) __ block_comment(str) |
|
66 |
#define BIND(label) __ bind(label); BLOCK_COMMENT(#label ":") |
|
67 |
||
68 |
#define oop_tmp_offset _z_ijava_state_neg(oop_tmp) |
|
69 |
||
70 |
//----------------------------------------------------------------------------- |
|
71 |
||
72 |
address TemplateInterpreterGenerator::generate_slow_signature_handler() { |
|
73 |
// |
|
74 |
// New slow_signature handler that respects the z/Architecture |
|
75 |
// C calling conventions. |
|
76 |
// |
|
77 |
// We get called by the native entry code with our output register |
|
78 |
// area == 8. First we call InterpreterRuntime::get_result_handler |
|
79 |
// to copy the pointer to the signature string temporarily to the |
|
80 |
// first C-argument and to return the result_handler in |
|
81 |
// Z_RET. Since native_entry will copy the jni-pointer to the |
|
82 |
// first C-argument slot later on, it's OK to occupy this slot |
|
83 |
// temporarily. Then we copy the argument list on the java |
|
84 |
// expression stack into native varargs format on the native stack |
|
85 |
// and load arguments into argument registers. Integer arguments in |
|
86 |
// the varargs vector will be sign-extended to 8 bytes. |
|
87 |
// |
|
88 |
// On entry: |
|
89 |
// Z_ARG1 - intptr_t* Address of java argument list in memory. |
|
90 |
// Z_state - cppInterpreter* Address of interpreter state for |
|
91 |
// this method |
|
92 |
// Z_method |
|
93 |
// |
|
94 |
// On exit (just before return instruction): |
|
95 |
// Z_RET contains the address of the result_handler. |
|
96 |
// Z_ARG2 is not updated for static methods and contains "this" otherwise. |
|
97 |
// Z_ARG3-Z_ARG5 contain the first 3 arguments of types other than float and double. |
|
98 |
// Z_FARG1-Z_FARG4 contain the first 4 arguments of type float or double. |
|
99 |
||
100 |
const int LogSizeOfCase = 3; |
|
101 |
||
102 |
const int max_fp_register_arguments = Argument::n_float_register_parameters; |
|
103 |
const int max_int_register_arguments = Argument::n_register_parameters - 2; // First 2 are reserved. |
|
104 |
||
105 |
const Register arg_java = Z_tmp_2; |
|
106 |
const Register arg_c = Z_tmp_3; |
|
107 |
const Register signature = Z_R1_scratch; // Is a string. |
|
108 |
const Register fpcnt = Z_R0_scratch; |
|
109 |
const Register argcnt = Z_tmp_4; |
|
110 |
const Register intSlot = Z_tmp_1; |
|
111 |
const Register sig_end = Z_tmp_1; // Assumed end of signature (only used in do_object). |
|
112 |
const Register target_sp = Z_tmp_1; |
|
113 |
const FloatRegister floatSlot = Z_F1; |
|
114 |
||
115 |
const int d_signature = _z_abi(gpr6); // Only spill space, register contents not affected. |
|
116 |
const int d_fpcnt = _z_abi(gpr7); // Only spill space, register contents not affected. |
|
117 |
||
118 |
unsigned int entry_offset = __ offset(); |
|
119 |
||
120 |
BLOCK_COMMENT("slow_signature_handler {"); |
|
121 |
||
122 |
// We use target_sp for storing arguments in the C frame. |
|
123 |
__ save_return_pc(); |
|
124 |
||
125 |
__ z_stmg(Z_R10,Z_R13,-32,Z_SP); |
|
126 |
__ push_frame_abi160(32); |
|
127 |
||
128 |
__ z_lgr(arg_java, Z_ARG1); |
|
129 |
||
130 |
Register method = Z_ARG2; // Directly load into correct argument register. |
|
131 |
||
132 |
__ get_method(method); |
|
133 |
__ call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::get_signature), Z_thread, method); |
|
134 |
||
135 |
// Move signature to callee saved register. |
|
136 |
// Don't directly write to stack. Frame is used by VM call. |
|
137 |
__ z_lgr(Z_tmp_1, Z_RET); |
|
138 |
||
139 |
// Reload method. Register may have been altered by VM call. |
|
140 |
__ get_method(method); |
|
141 |
||
142 |
// Get address of result handler. |
|
143 |
__ call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::get_result_handler), Z_thread, method); |
|
144 |
||
145 |
// Save signature address to stack. |
|
146 |
__ z_stg(Z_tmp_1, d_signature, Z_SP); |
|
147 |
||
148 |
// Don't overwrite return value (Z_RET, Z_ARG1) in rest of the method ! |
|
149 |
||
150 |
{ |
|
151 |
Label isStatic; |
|
152 |
||
153 |
// Test if static. |
|
154 |
// We can test the bit directly. |
|
155 |
// Path is Z_method->_access_flags._flags. |
|
156 |
// We only support flag bits in the least significant byte (assert !). |
|
157 |
// Therefore add 3 to address that byte within "_flags". |
|
158 |
// Reload method. VM call above may have destroyed register contents |
|
159 |
__ get_method(method); |
|
160 |
__ testbit(method2_(method, access_flags), JVM_ACC_STATIC_BIT); |
|
161 |
method = noreg; // end of life |
|
162 |
__ z_btrue(isStatic); |
|
163 |
||
164 |
// For non-static functions, pass "this" in Z_ARG2 and copy it to 2nd C-arg slot. |
|
165 |
// Need to box the Java object here, so we use arg_java |
|
166 |
// (address of current Java stack slot) as argument and |
|
167 |
// don't dereference it as in case of ints, floats, etc.. |
|
168 |
__ z_lgr(Z_ARG2, arg_java); |
|
169 |
__ add2reg(arg_java, -BytesPerWord); |
|
170 |
__ bind(isStatic); |
|
171 |
} |
|
172 |
||
173 |
// argcnt == 0 corresponds to 3rd C argument. |
|
174 |
// arg #1 (result handler) and |
|
175 |
// arg #2 (this, for non-statics), unused else |
|
176 |
// are reserved and pre-filled above. |
|
177 |
// arg_java points to the corresponding Java argument here. It |
|
178 |
// has been decremented by one argument (this) in case of non-static. |
|
179 |
__ clear_reg(argcnt, true, false); // Don't set CC. |
|
180 |
__ z_lg(target_sp, 0, Z_SP); |
|
181 |
__ add2reg(arg_c, _z_abi(remaining_cargs), target_sp); |
|
182 |
// No floating-point args parsed so far. |
|
183 |
__ clear_mem(Address(Z_SP, d_fpcnt), 8); |
|
184 |
||
185 |
NearLabel move_intSlot_to_ARG, move_floatSlot_to_FARG; |
|
186 |
NearLabel loop_start, loop_start_restore, loop_end; |
|
187 |
NearLabel do_int, do_long, do_float, do_double; |
|
188 |
NearLabel do_dontreachhere, do_object, do_array, do_boxed; |
|
189 |
||
190 |
#ifdef ASSERT |
|
191 |
// Signature needs to point to '(' (== 0x28) at entry. |
|
192 |
__ z_lg(signature, d_signature, Z_SP); |
|
193 |
__ z_cli(0, signature, (int) '('); |
|
194 |
__ z_brne(do_dontreachhere); |
|
195 |
#endif |
|
196 |
||
197 |
__ bind(loop_start_restore); |
|
198 |
__ z_lg(signature, d_signature, Z_SP); // Restore signature ptr, destroyed by move_XX_to_ARG. |
|
199 |
||
200 |
BIND(loop_start); |
|
201 |
// Advance to next argument type token from the signature. |
|
202 |
__ add2reg(signature, 1); |
|
203 |
||
204 |
// Use CLI, works well on all CPU versions. |
|
205 |
__ z_cli(0, signature, (int) ')'); |
|
206 |
__ z_bre(loop_end); // end of signature |
|
207 |
__ z_cli(0, signature, (int) 'L'); |
|
208 |
__ z_bre(do_object); // object #9 |
|
209 |
__ z_cli(0, signature, (int) 'F'); |
|
210 |
__ z_bre(do_float); // float #7 |
|
211 |
__ z_cli(0, signature, (int) 'J'); |
|
212 |
__ z_bre(do_long); // long #6 |
|
213 |
__ z_cli(0, signature, (int) 'B'); |
|
214 |
__ z_bre(do_int); // byte #1 |
|
215 |
__ z_cli(0, signature, (int) 'Z'); |
|
216 |
__ z_bre(do_int); // boolean #2 |
|
217 |
__ z_cli(0, signature, (int) 'C'); |
|
218 |
__ z_bre(do_int); // char #3 |
|
219 |
__ z_cli(0, signature, (int) 'S'); |
|
220 |
__ z_bre(do_int); // short #4 |
|
221 |
__ z_cli(0, signature, (int) 'I'); |
|
222 |
__ z_bre(do_int); // int #5 |
|
223 |
__ z_cli(0, signature, (int) 'D'); |
|
224 |
__ z_bre(do_double); // double #8 |
|
225 |
__ z_cli(0, signature, (int) '['); |
|
226 |
__ z_bre(do_array); // array #10 |
|
227 |
||
228 |
__ bind(do_dontreachhere); |
|
229 |
||
230 |
__ unimplemented("ShouldNotReachHere in slow_signature_handler", 120); |
|
231 |
||
232 |
// Array argument |
|
233 |
BIND(do_array); |
|
234 |
||
235 |
{ |
|
236 |
Label start_skip, end_skip; |
|
237 |
||
238 |
__ bind(start_skip); |
|
239 |
||
240 |
// Advance to next type tag from signature. |
|
241 |
__ add2reg(signature, 1); |
|
242 |
||
243 |
// Use CLI, works well on all CPU versions. |
|
244 |
__ z_cli(0, signature, (int) '['); |
|
245 |
__ z_bre(start_skip); // Skip further brackets. |
|
246 |
||
247 |
__ z_cli(0, signature, (int) '9'); |
|
248 |
__ z_brh(end_skip); // no optional size |
|
249 |
||
250 |
__ z_cli(0, signature, (int) '0'); |
|
251 |
__ z_brnl(start_skip); // Skip optional size. |
|
252 |
||
253 |
__ bind(end_skip); |
|
254 |
||
255 |
__ z_cli(0, signature, (int) 'L'); |
|
256 |
__ z_brne(do_boxed); // If not array of objects: go directly to do_boxed. |
|
257 |
} |
|
258 |
||
259 |
// OOP argument |
|
260 |
BIND(do_object); |
|
261 |
// Pass by an object's type name. |
|
262 |
{ |
|
263 |
Label L; |
|
264 |
||
265 |
__ add2reg(sig_end, 4095, signature); // Assume object type name is shorter than 4k. |
|
266 |
__ load_const_optimized(Z_R0, (int) ';'); // Type name terminator (must be in Z_R0!). |
|
267 |
__ MacroAssembler::search_string(sig_end, signature); |
|
268 |
__ z_brl(L); |
|
269 |
__ z_illtrap(); // No semicolon found: internal error or object name too long. |
|
270 |
__ bind(L); |
|
271 |
__ z_lgr(signature, sig_end); |
|
272 |
// fallthru to do_boxed |
|
273 |
} |
|
274 |
||
275 |
// Need to box the Java object here, so we use arg_java |
|
276 |
// (address of current Java stack slot) as argument and |
|
277 |
// don't dereference it as in case of ints, floats, etc.. |
|
278 |
||
279 |
// UNBOX argument |
|
280 |
// Load reference and check for NULL. |
|
281 |
Label do_int_Entry4Boxed; |
|
282 |
__ bind(do_boxed); |
|
283 |
{ |
|
284 |
__ load_and_test_long(intSlot, Address(arg_java)); |
|
285 |
__ z_bre(do_int_Entry4Boxed); |
|
286 |
__ z_lgr(intSlot, arg_java); |
|
287 |
__ z_bru(do_int_Entry4Boxed); |
|
288 |
} |
|
289 |
||
290 |
// INT argument |
|
291 |
||
292 |
// (also for byte, boolean, char, short) |
|
293 |
// Use lgf for load (sign-extend) and stg for store. |
|
294 |
BIND(do_int); |
|
295 |
__ z_lgf(intSlot, 0, arg_java); |
|
296 |
||
297 |
__ bind(do_int_Entry4Boxed); |
|
298 |
__ add2reg(arg_java, -BytesPerWord); |
|
299 |
// If argument fits into argument register, go and handle it, otherwise continue. |
|
300 |
__ compare32_and_branch(argcnt, max_int_register_arguments, |
|
301 |
Assembler::bcondLow, move_intSlot_to_ARG); |
|
302 |
__ z_stg(intSlot, 0, arg_c); |
|
303 |
__ add2reg(arg_c, BytesPerWord); |
|
304 |
__ z_bru(loop_start); |
|
305 |
||
306 |
// LONG argument |
|
307 |
||
308 |
BIND(do_long); |
|
309 |
__ add2reg(arg_java, -2*BytesPerWord); // Decrement first to have positive displacement for lg. |
|
310 |
__ z_lg(intSlot, BytesPerWord, arg_java); |
|
311 |
// If argument fits into argument register, go and handle it, otherwise continue. |
|
312 |
__ compare32_and_branch(argcnt, max_int_register_arguments, |
|
313 |
Assembler::bcondLow, move_intSlot_to_ARG); |
|
314 |
__ z_stg(intSlot, 0, arg_c); |
|
315 |
__ add2reg(arg_c, BytesPerWord); |
|
316 |
__ z_bru(loop_start); |
|
317 |
||
318 |
// FLOAT argumen |
|
319 |
||
320 |
BIND(do_float); |
|
321 |
__ z_le(floatSlot, 0, arg_java); |
|
322 |
__ add2reg(arg_java, -BytesPerWord); |
|
323 |
assert(max_fp_register_arguments <= 255, "always true"); // safety net |
|
324 |
__ z_cli(d_fpcnt+7, Z_SP, max_fp_register_arguments); |
|
325 |
__ z_brl(move_floatSlot_to_FARG); |
|
326 |
__ z_ste(floatSlot, 4, arg_c); |
|
327 |
__ add2reg(arg_c, BytesPerWord); |
|
328 |
__ z_bru(loop_start); |
|
329 |
||
330 |
// DOUBLE argument |
|
331 |
||
332 |
BIND(do_double); |
|
333 |
__ add2reg(arg_java, -2*BytesPerWord); // Decrement first to have positive displacement for lg. |
|
334 |
__ z_ld(floatSlot, BytesPerWord, arg_java); |
|
335 |
assert(max_fp_register_arguments <= 255, "always true"); // safety net |
|
336 |
__ z_cli(d_fpcnt+7, Z_SP, max_fp_register_arguments); |
|
337 |
__ z_brl(move_floatSlot_to_FARG); |
|
338 |
__ z_std(floatSlot, 0, arg_c); |
|
339 |
__ add2reg(arg_c, BytesPerWord); |
|
340 |
__ z_bru(loop_start); |
|
341 |
||
342 |
// Method exit, all arguments proocessed. |
|
343 |
__ bind(loop_end); |
|
344 |
__ pop_frame(); |
|
345 |
__ restore_return_pc(); |
|
346 |
__ z_lmg(Z_R10,Z_R13,-32,Z_SP); |
|
347 |
__ z_br(Z_R14); |
|
348 |
||
349 |
// Copy int arguments. |
|
350 |
||
351 |
Label iarg_caselist; // Distance between each case has to be a power of 2 |
|
352 |
// (= 1 << LogSizeOfCase). |
|
353 |
__ align(16); |
|
354 |
BIND(iarg_caselist); |
|
355 |
__ z_lgr(Z_ARG3, intSlot); // 4 bytes |
|
356 |
__ z_bru(loop_start_restore); // 4 bytes |
|
357 |
||
358 |
__ z_lgr(Z_ARG4, intSlot); |
|
359 |
__ z_bru(loop_start_restore); |
|
360 |
||
361 |
__ z_lgr(Z_ARG5, intSlot); |
|
362 |
__ z_bru(loop_start_restore); |
|
363 |
||
364 |
__ align(16); |
|
365 |
__ bind(move_intSlot_to_ARG); |
|
366 |
__ z_stg(signature, d_signature, Z_SP); // Spill since signature == Z_R1_scratch. |
|
367 |
__ z_larl(Z_R1_scratch, iarg_caselist); |
|
368 |
__ z_sllg(Z_R0_scratch, argcnt, LogSizeOfCase); |
|
369 |
__ add2reg(argcnt, 1); |
|
370 |
__ z_agr(Z_R1_scratch, Z_R0_scratch); |
|
371 |
__ z_bcr(Assembler::bcondAlways, Z_R1_scratch); |
|
372 |
||
373 |
// Copy float arguments. |
|
374 |
||
375 |
Label farg_caselist; // Distance between each case has to be a power of 2 |
|
376 |
// (= 1 << logSizeOfCase, padded with nop. |
|
377 |
__ align(16); |
|
378 |
BIND(farg_caselist); |
|
379 |
__ z_ldr(Z_FARG1, floatSlot); // 2 bytes |
|
380 |
__ z_bru(loop_start_restore); // 4 bytes |
|
381 |
__ z_nop(); // 2 bytes |
|
382 |
||
383 |
__ z_ldr(Z_FARG2, floatSlot); |
|
384 |
__ z_bru(loop_start_restore); |
|
385 |
__ z_nop(); |
|
386 |
||
387 |
__ z_ldr(Z_FARG3, floatSlot); |
|
388 |
__ z_bru(loop_start_restore); |
|
389 |
__ z_nop(); |
|
390 |
||
391 |
__ z_ldr(Z_FARG4, floatSlot); |
|
392 |
__ z_bru(loop_start_restore); |
|
393 |
__ z_nop(); |
|
394 |
||
395 |
__ align(16); |
|
396 |
__ bind(move_floatSlot_to_FARG); |
|
397 |
__ z_stg(signature, d_signature, Z_SP); // Spill since signature == Z_R1_scratch. |
|
398 |
__ z_lg(Z_R0_scratch, d_fpcnt, Z_SP); // Need old value for indexing. |
|
399 |
__ add2mem_64(Address(Z_SP, d_fpcnt), 1, Z_R1_scratch); // Increment index. |
|
400 |
__ z_larl(Z_R1_scratch, farg_caselist); |
|
401 |
__ z_sllg(Z_R0_scratch, Z_R0_scratch, LogSizeOfCase); |
|
402 |
__ z_agr(Z_R1_scratch, Z_R0_scratch); |
|
403 |
__ z_bcr(Assembler::bcondAlways, Z_R1_scratch); |
|
404 |
||
405 |
BLOCK_COMMENT("} slow_signature_handler"); |
|
406 |
||
407 |
return __ addr_at(entry_offset); |
|
408 |
} |
|
409 |
||
410 |
address TemplateInterpreterGenerator::generate_result_handler_for (BasicType type) { |
|
411 |
address entry = __ pc(); |
|
412 |
||
413 |
assert(Z_tos == Z_RET, "Result handler: must move result!"); |
|
414 |
assert(Z_ftos == Z_FRET, "Result handler: must move float result!"); |
|
415 |
||
416 |
switch (type) { |
|
417 |
case T_BOOLEAN: |
|
418 |
__ c2bool(Z_tos); |
|
419 |
break; |
|
420 |
case T_CHAR: |
|
421 |
__ and_imm(Z_tos, 0xffff); |
|
422 |
break; |
|
423 |
case T_BYTE: |
|
424 |
__ z_lbr(Z_tos, Z_tos); |
|
425 |
break; |
|
426 |
case T_SHORT: |
|
427 |
__ z_lhr(Z_tos, Z_tos); |
|
428 |
break; |
|
429 |
case T_INT: |
|
430 |
case T_LONG: |
|
431 |
case T_VOID: |
|
432 |
case T_FLOAT: |
|
433 |
case T_DOUBLE: |
|
434 |
break; |
|
435 |
case T_OBJECT: |
|
436 |
// Retrieve result from frame... |
|
437 |
__ mem2reg_opt(Z_tos, Address(Z_fp, oop_tmp_offset)); |
|
438 |
// and verify it. |
|
439 |
__ verify_oop(Z_tos); |
|
440 |
break; |
|
441 |
default: |
|
442 |
ShouldNotReachHere(); |
|
443 |
} |
|
444 |
__ z_br(Z_R14); // Return from result handler. |
|
445 |
return entry; |
|
446 |
} |
|
447 |
||
448 |
// Abstract method entry. |
|
449 |
// Attempt to execute abstract method. Throw exception. |
|
450 |
address TemplateInterpreterGenerator::generate_abstract_entry(void) { |
|
451 |
unsigned int entry_offset = __ offset(); |
|
452 |
||
453 |
// Caller could be the call_stub or a compiled method (x86 version is wrong!). |
|
454 |
||
455 |
BLOCK_COMMENT("abstract_entry {"); |
|
456 |
||
457 |
// Implement call of InterpreterRuntime::throw_AbstractMethodError. |
|
458 |
__ set_top_ijava_frame_at_SP_as_last_Java_frame(Z_SP, Z_R1); |
|
459 |
__ save_return_pc(); // Save Z_R14. |
|
460 |
__ push_frame_abi160(0); // Without new frame the RT call could overwrite the saved Z_R14. |
|
461 |
||
462 |
__ call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_AbstractMethodError), Z_thread); |
|
463 |
||
464 |
__ pop_frame(); |
|
465 |
__ restore_return_pc(); // Restore Z_R14. |
|
466 |
__ reset_last_Java_frame(); |
|
467 |
||
468 |
// Restore caller sp for c2i case. |
|
469 |
__ resize_frame_absolute(Z_R10, Z_R0, true); // Cut the stack back to where the caller started. |
|
470 |
||
471 |
// branch to SharedRuntime::generate_forward_exception() which handles all possible callers, |
|
472 |
// i.e. call stub, compiled method, interpreted method. |
|
473 |
__ load_absolute_address(Z_tmp_1, StubRoutines::forward_exception_entry()); |
|
474 |
__ z_br(Z_tmp_1); |
|
475 |
||
476 |
BLOCK_COMMENT("} abstract_entry"); |
|
477 |
||
478 |
return __ addr_at(entry_offset); |
|
479 |
} |
|
480 |
||
481 |
address TemplateInterpreterGenerator::generate_Reference_get_entry(void) { |
|
482 |
#if INCLUDE_ALL_GCS |
|
483 |
if (UseG1GC) { |
|
484 |
// Inputs: |
|
485 |
// Z_ARG1 - receiver |
|
486 |
// |
|
487 |
// What we do: |
|
488 |
// - Load the referent field address. |
|
489 |
// - Load the value in the referent field. |
|
490 |
// - Pass that value to the pre-barrier. |
|
491 |
// |
|
492 |
// In the case of G1 this will record the value of the |
|
493 |
// referent in an SATB buffer if marking is active. |
|
494 |
// This will cause concurrent marking to mark the referent |
|
495 |
// field as live. |
|
496 |
||
497 |
Register scratch1 = Z_tmp_2; |
|
498 |
Register scratch2 = Z_tmp_3; |
|
499 |
Register pre_val = Z_RET; // return value |
|
500 |
// Z_esp is callers operand stack pointer, i.e. it points to the parameters. |
|
501 |
Register Rargp = Z_esp; |
|
502 |
||
503 |
Label slow_path; |
|
504 |
address entry = __ pc(); |
|
505 |
||
506 |
const int referent_offset = java_lang_ref_Reference::referent_offset; |
|
507 |
guarantee(referent_offset > 0, "referent offset not initialized"); |
|
508 |
||
509 |
BLOCK_COMMENT("Reference_get {"); |
|
510 |
||
511 |
// If the receiver is null then it is OK to jump to the slow path. |
|
512 |
__ load_and_test_long(pre_val, Address(Rargp, Interpreter::stackElementSize)); // Get receiver. |
|
513 |
__ z_bre(slow_path); |
|
514 |
||
515 |
// Load the value of the referent field. |
|
516 |
__ load_heap_oop(pre_val, referent_offset, pre_val); |
|
517 |
||
518 |
// Restore caller sp for c2i case. |
|
519 |
__ resize_frame_absolute(Z_R10, Z_R0, true); // Cut the stack back to where the caller started. |
|
520 |
||
521 |
// Generate the G1 pre-barrier code to log the value of |
|
522 |
// the referent field in an SATB buffer. |
|
523 |
// Note: |
|
524 |
// With these parameters the write_barrier_pre does not |
|
525 |
// generate instructions to load the previous value. |
|
526 |
__ g1_write_barrier_pre(noreg, // obj |
|
527 |
noreg, // offset |
|
528 |
pre_val, // pre_val |
|
529 |
noreg, // no new val to preserve |
|
530 |
scratch1, // tmp |
|
531 |
scratch2, // tmp |
|
532 |
true); // pre_val_needed |
|
533 |
||
534 |
__ z_br(Z_R14); |
|
535 |
||
536 |
// Branch to previously generated regular method entry. |
|
537 |
__ bind(slow_path); |
|
538 |
||
539 |
address meth_entry = Interpreter::entry_for_kind(Interpreter::zerolocals); |
|
540 |
__ jump_to_entry(meth_entry, Z_R1); |
|
541 |
||
542 |
BLOCK_COMMENT("} Reference_get"); |
|
543 |
||
544 |
return entry; |
|
545 |
} |
|
546 |
#endif // INCLUDE_ALL_GCS |
|
547 |
||
548 |
return NULL; |
|
549 |
} |
|
550 |
||
551 |
address TemplateInterpreterGenerator::generate_StackOverflowError_handler() { |
|
552 |
address entry = __ pc(); |
|
553 |
||
554 |
DEBUG_ONLY(__ verify_esp(Z_esp, Z_ARG5)); |
|
555 |
||
556 |
// Restore bcp under the assumption that the current frame is still |
|
557 |
// interpreted. |
|
558 |
__ restore_bcp(); |
|
559 |
||
560 |
// Expression stack must be empty before entering the VM if an |
|
561 |
// exception happened. |
|
562 |
__ empty_expression_stack(); |
|
563 |
// Throw exception. |
|
564 |
__ call_VM(noreg, |
|
565 |
CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_StackOverflowError)); |
|
566 |
return entry; |
|
567 |
} |
|
568 |
||
569 |
// |
|
570 |
// Args: |
|
571 |
// Z_ARG3: aberrant index |
|
572 |
// |
|
573 |
address TemplateInterpreterGenerator::generate_ArrayIndexOutOfBounds_handler(const char * name) { |
|
574 |
address entry = __ pc(); |
|
575 |
address excp = CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_ArrayIndexOutOfBoundsException); |
|
576 |
||
577 |
// Expression stack must be empty before entering the VM if an |
|
578 |
// exception happened. |
|
579 |
__ empty_expression_stack(); |
|
580 |
||
581 |
// Setup parameters. |
|
582 |
// Leave out the name and use register for array to create more detailed exceptions. |
|
583 |
__ load_absolute_address(Z_ARG2, (address) name); |
|
584 |
__ call_VM(noreg, excp, Z_ARG2, Z_ARG3); |
|
585 |
return entry; |
|
586 |
} |
|
587 |
||
588 |
address TemplateInterpreterGenerator::generate_ClassCastException_handler() { |
|
589 |
address entry = __ pc(); |
|
590 |
||
591 |
// Object is at TOS. |
|
592 |
__ pop_ptr(Z_ARG2); |
|
593 |
||
594 |
// Expression stack must be empty before entering the VM if an |
|
595 |
// exception happened. |
|
596 |
__ empty_expression_stack(); |
|
597 |
||
598 |
__ call_VM(Z_ARG1, |
|
599 |
CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_ClassCastException), |
|
600 |
Z_ARG2); |
|
601 |
||
602 |
DEBUG_ONLY(__ should_not_reach_here();) |
|
603 |
||
604 |
return entry; |
|
605 |
} |
|
606 |
||
607 |
address TemplateInterpreterGenerator::generate_exception_handler_common(const char* name, const char* message, bool pass_oop) { |
|
608 |
assert(!pass_oop || message == NULL, "either oop or message but not both"); |
|
609 |
address entry = __ pc(); |
|
610 |
||
611 |
BLOCK_COMMENT("exception_handler_common {"); |
|
612 |
||
613 |
// Expression stack must be empty before entering the VM if an |
|
614 |
// exception happened. |
|
615 |
__ empty_expression_stack(); |
|
616 |
if (name != NULL) { |
|
617 |
__ load_absolute_address(Z_ARG2, (address)name); |
|
618 |
} else { |
|
619 |
__ clear_reg(Z_ARG2, true, false); |
|
620 |
} |
|
621 |
||
622 |
if (pass_oop) { |
|
623 |
__ call_VM(Z_tos, |
|
624 |
CAST_FROM_FN_PTR(address, InterpreterRuntime::create_klass_exception), |
|
625 |
Z_ARG2, Z_tos /*object (see TT::aastore())*/); |
|
626 |
} else { |
|
627 |
if (message != NULL) { |
|
628 |
__ load_absolute_address(Z_ARG3, (address)message); |
|
629 |
} else { |
|
630 |
__ clear_reg(Z_ARG3, true, false); |
|
631 |
} |
|
632 |
__ call_VM(Z_tos, |
|
633 |
CAST_FROM_FN_PTR(address, InterpreterRuntime::create_exception), |
|
634 |
Z_ARG2, Z_ARG3); |
|
635 |
} |
|
636 |
// Throw exception. |
|
637 |
__ load_absolute_address(Z_R1_scratch, Interpreter::throw_exception_entry()); |
|
638 |
__ z_br(Z_R1_scratch); |
|
639 |
||
640 |
BLOCK_COMMENT("} exception_handler_common"); |
|
641 |
||
642 |
return entry; |
|
643 |
} |
|
644 |
||
645 |
// Unused, should never pass by. |
|
646 |
address TemplateInterpreterGenerator::generate_continuation_for (TosState state) { |
|
647 |
address entry = __ pc(); |
|
648 |
__ should_not_reach_here(); |
|
649 |
return entry; |
|
650 |
} |
|
651 |
||
652 |
address TemplateInterpreterGenerator::generate_return_entry_for (TosState state, int step, size_t index_size) { |
|
653 |
address entry = __ pc(); |
|
654 |
||
655 |
BLOCK_COMMENT("return_entry {"); |
|
656 |
||
657 |
// Pop i2c extension or revert top-2-parent-resize done by interpreted callees. |
|
658 |
Register sp_before_i2c_extension = Z_bcp; |
|
659 |
__ z_lg(Z_fp, _z_abi(callers_sp), Z_SP); // Restore frame pointer. |
|
660 |
__ z_lg(sp_before_i2c_extension, Address(Z_fp, _z_ijava_state_neg(top_frame_sp))); |
|
661 |
__ resize_frame_absolute(sp_before_i2c_extension, Z_locals/*tmp*/, true/*load_fp*/); |
|
662 |
||
663 |
// TODO(ZASM): necessary?? |
|
664 |
// // and NULL it as marker that esp is now tos until next java call |
|
665 |
// __ movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD); |
|
666 |
||
667 |
__ restore_bcp(); |
|
668 |
__ restore_locals(); |
|
669 |
__ restore_esp(); |
|
670 |
||
671 |
if (state == atos) { |
|
672 |
__ profile_return_type(Z_tmp_1, Z_tos, Z_tmp_2); |
|
673 |
} |
|
674 |
||
675 |
Register cache = Z_tmp_1; |
|
676 |
Register size = Z_tmp_1; |
|
677 |
Register offset = Z_tmp_2; |
|
678 |
const int flags_offset = in_bytes(ConstantPoolCache::base_offset() + |
|
679 |
ConstantPoolCacheEntry::flags_offset()); |
|
680 |
__ get_cache_and_index_at_bcp(cache, offset, 1, index_size); |
|
681 |
||
682 |
// #args is in rightmost byte of the _flags field. |
|
683 |
__ z_llgc(size, Address(cache, offset, flags_offset+(sizeof(size_t)-1))); |
|
684 |
__ z_sllg(size, size, Interpreter::logStackElementSize); // Each argument size in bytes. |
|
685 |
__ z_agr(Z_esp, size); // Pop arguments. |
|
686 |
__ dispatch_next(state, step); |
|
687 |
||
688 |
BLOCK_COMMENT("} return_entry"); |
|
689 |
||
690 |
return entry; |
|
691 |
} |
|
692 |
||
693 |
address TemplateInterpreterGenerator::generate_deopt_entry_for (TosState state, |
|
694 |
int step) { |
|
695 |
address entry = __ pc(); |
|
696 |
||
697 |
BLOCK_COMMENT("deopt_entry {"); |
|
698 |
||
699 |
// TODO(ZASM): necessary? NULL last_sp until next java call |
|
700 |
// __ movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD); |
|
701 |
__ z_lg(Z_fp, _z_abi(callers_sp), Z_SP); // Restore frame pointer. |
|
702 |
__ restore_bcp(); |
|
703 |
__ restore_locals(); |
|
704 |
__ restore_esp(); |
|
705 |
||
706 |
// Handle exceptions. |
|
707 |
{ |
|
708 |
Label L; |
|
709 |
__ load_and_test_long(Z_R0/*pending_exception*/, thread_(pending_exception)); |
|
710 |
__ z_bre(L); |
|
711 |
__ call_VM(noreg, |
|
712 |
CAST_FROM_FN_PTR(address, |
|
713 |
InterpreterRuntime::throw_pending_exception)); |
|
714 |
__ should_not_reach_here(); |
|
715 |
__ bind(L); |
|
716 |
} |
|
717 |
__ dispatch_next(state, step); |
|
718 |
||
719 |
BLOCK_COMMENT("} deopt_entry"); |
|
720 |
||
721 |
return entry; |
|
722 |
} |
|
723 |
||
724 |
address TemplateInterpreterGenerator::generate_safept_entry_for (TosState state, |
|
725 |
address runtime_entry) { |
|
726 |
address entry = __ pc(); |
|
727 |
__ push(state); |
|
728 |
__ call_VM(noreg, runtime_entry); |
|
729 |
__ dispatch_via(vtos, Interpreter::_normal_table.table_for (vtos)); |
|
730 |
return entry; |
|
731 |
} |
|
732 |
||
733 |
// |
|
734 |
// Helpers for commoning out cases in the various type of method entries. |
|
735 |
// |
|
736 |
||
737 |
// Increment invocation count & check for overflow. |
|
738 |
// |
|
739 |
// Note: checking for negative value instead of overflow |
|
740 |
// so we have a 'sticky' overflow test. |
|
741 |
// |
|
742 |
// Z_ARG2: method (see generate_fixed_frame()) |
|
743 |
// |
|
744 |
void TemplateInterpreterGenerator::generate_counter_incr(Label* overflow, Label* profile_method, Label* profile_method_continue) { |
|
745 |
Label done; |
|
746 |
Register method = Z_ARG2; // Generate_fixed_frame() copies Z_method into Z_ARG2. |
|
747 |
Register m_counters = Z_ARG4; |
|
748 |
||
749 |
BLOCK_COMMENT("counter_incr {"); |
|
750 |
||
751 |
// Note: In tiered we increment either counters in method or in MDO depending |
|
752 |
// if we are profiling or not. |
|
753 |
if (TieredCompilation) { |
|
754 |
int increment = InvocationCounter::count_increment; |
|
755 |
if (ProfileInterpreter) { |
|
756 |
NearLabel no_mdo; |
|
757 |
Register mdo = m_counters; |
|
758 |
// Are we profiling? |
|
759 |
__ load_and_test_long(mdo, method2_(method, method_data)); |
|
760 |
__ branch_optimized(Assembler::bcondZero, no_mdo); |
|
761 |
// Increment counter in the MDO. |
|
762 |
const Address mdo_invocation_counter(mdo, MethodData::invocation_counter_offset() + |
|
763 |
InvocationCounter::counter_offset()); |
|
764 |
const Address mask(mdo, MethodData::invoke_mask_offset()); |
|
765 |
__ increment_mask_and_jump(mdo_invocation_counter, increment, mask, |
|
766 |
Z_R1_scratch, false, Assembler::bcondZero, |
|
767 |
overflow); |
|
768 |
__ z_bru(done); |
|
769 |
__ bind(no_mdo); |
|
770 |
} |
|
771 |
||
772 |
// Increment counter in MethodCounters. |
|
773 |
const Address invocation_counter(m_counters, |
|
774 |
MethodCounters::invocation_counter_offset() + |
|
775 |
InvocationCounter::counter_offset()); |
|
776 |
// Get address of MethodCounters object. |
|
777 |
__ get_method_counters(method, m_counters, done); |
|
778 |
const Address mask(m_counters, MethodCounters::invoke_mask_offset()); |
|
779 |
__ increment_mask_and_jump(invocation_counter, |
|
780 |
increment, mask, |
|
781 |
Z_R1_scratch, false, Assembler::bcondZero, |
|
782 |
overflow); |
|
783 |
} else { |
|
784 |
Register counter_sum = Z_ARG3; // The result of this piece of code. |
|
785 |
Register tmp = Z_R1_scratch; |
|
786 |
#ifdef ASSERT |
|
787 |
{ |
|
788 |
NearLabel ok; |
|
789 |
__ get_method(tmp); |
|
790 |
__ compare64_and_branch(method, tmp, Assembler::bcondEqual, ok); |
|
791 |
__ z_illtrap(0x66); |
|
792 |
__ bind(ok); |
|
793 |
} |
|
794 |
#endif |
|
795 |
||
796 |
// Get address of MethodCounters object. |
|
797 |
__ get_method_counters(method, m_counters, done); |
|
798 |
// Update standard invocation counters. |
|
799 |
__ increment_invocation_counter(m_counters, counter_sum); |
|
800 |
if (ProfileInterpreter) { |
|
801 |
__ add2mem_32(Address(m_counters, MethodCounters::interpreter_invocation_counter_offset()), 1, tmp); |
|
802 |
if (profile_method != NULL) { |
|
803 |
const Address profile_limit(m_counters, MethodCounters::interpreter_profile_limit_offset()); |
|
804 |
__ z_cl(counter_sum, profile_limit); |
|
805 |
__ branch_optimized(Assembler::bcondLow, *profile_method_continue); |
|
806 |
// If no method data exists, go to profile_method. |
|
807 |
__ test_method_data_pointer(tmp, *profile_method); |
|
808 |
} |
|
809 |
} |
|
810 |
||
811 |
const Address invocation_limit(m_counters, MethodCounters::interpreter_invocation_limit_offset()); |
|
812 |
__ z_cl(counter_sum, invocation_limit); |
|
813 |
__ branch_optimized(Assembler::bcondNotLow, *overflow); |
|
814 |
} |
|
815 |
||
816 |
__ bind(done); |
|
817 |
||
818 |
BLOCK_COMMENT("} counter_incr"); |
|
819 |
} |
|
820 |
||
821 |
void TemplateInterpreterGenerator::generate_counter_overflow(Label& do_continue) { |
|
822 |
// InterpreterRuntime::frequency_counter_overflow takes two |
|
823 |
// arguments, the first (thread) is passed by call_VM, the second |
|
824 |
// indicates if the counter overflow occurs at a backwards branch |
|
825 |
// (NULL bcp). We pass zero for it. The call returns the address |
|
826 |
// of the verified entry point for the method or NULL if the |
|
827 |
// compilation did not complete (either went background or bailed |
|
828 |
// out). |
|
829 |
__ clear_reg(Z_ARG2); |
|
830 |
__ call_VM(noreg, |
|
831 |
CAST_FROM_FN_PTR(address, InterpreterRuntime::frequency_counter_overflow), |
|
832 |
Z_ARG2); |
|
833 |
__ z_bru(do_continue); |
|
834 |
} |
|
835 |
||
836 |
void TemplateInterpreterGenerator::generate_stack_overflow_check(Register frame_size, Register tmp1) { |
|
837 |
Register tmp2 = Z_R1_scratch; |
|
838 |
const int page_size = os::vm_page_size(); |
|
839 |
NearLabel after_frame_check; |
|
840 |
||
841 |
BLOCK_COMMENT("counter_overflow {"); |
|
842 |
||
843 |
assert_different_registers(frame_size, tmp1); |
|
844 |
||
845 |
// Stack banging is sufficient overflow check if frame_size < page_size. |
|
846 |
if (Immediate::is_uimm(page_size, 15)) { |
|
847 |
__ z_chi(frame_size, page_size); |
|
848 |
__ z_brl(after_frame_check); |
|
849 |
} else { |
|
850 |
__ load_const_optimized(tmp1, page_size); |
|
851 |
__ compareU32_and_branch(frame_size, tmp1, Assembler::bcondLow, after_frame_check); |
|
852 |
} |
|
853 |
||
854 |
// Get the stack base, and in debug, verify it is non-zero. |
|
855 |
__ z_lg(tmp1, thread_(stack_base)); |
|
856 |
#ifdef ASSERT |
|
857 |
address reentry = NULL; |
|
858 |
NearLabel base_not_zero; |
|
859 |
__ compareU64_and_branch(tmp1, (intptr_t)0L, Assembler::bcondNotEqual, base_not_zero); |
|
860 |
reentry = __ stop_chain_static(reentry, "stack base is zero in generate_stack_overflow_check"); |
|
861 |
__ bind(base_not_zero); |
|
862 |
#endif |
|
863 |
||
864 |
// Get the stack size, and in debug, verify it is non-zero. |
|
865 |
assert(sizeof(size_t) == sizeof(intptr_t), "wrong load size"); |
|
866 |
__ z_lg(tmp2, thread_(stack_size)); |
|
867 |
#ifdef ASSERT |
|
868 |
NearLabel size_not_zero; |
|
869 |
__ compareU64_and_branch(tmp2, (intptr_t)0L, Assembler::bcondNotEqual, size_not_zero); |
|
870 |
reentry = __ stop_chain_static(reentry, "stack size is zero in generate_stack_overflow_check"); |
|
871 |
__ bind(size_not_zero); |
|
872 |
#endif |
|
873 |
||
874 |
// Compute the beginning of the protected zone minus the requested frame size. |
|
875 |
__ z_sgr(tmp1, tmp2); |
|
876 |
__ add2reg(tmp1, JavaThread::stack_guard_zone_size()); |
|
877 |
||
878 |
// Add in the size of the frame (which is the same as subtracting it from the |
|
879 |
// SP, which would take another register. |
|
880 |
__ z_agr(tmp1, frame_size); |
|
881 |
||
882 |
// The frame is greater than one page in size, so check against |
|
883 |
// the bottom of the stack. |
|
884 |
__ compareU64_and_branch(Z_SP, tmp1, Assembler::bcondHigh, after_frame_check); |
|
885 |
||
886 |
// The stack will overflow, throw an exception. |
|
887 |
||
888 |
// Restore SP to sender's sp. This is necessary if the sender's frame is an |
|
889 |
// extended compiled frame (see gen_c2i_adapter()) and safer anyway in case of |
|
890 |
// JSR292 adaptations. |
|
891 |
__ resize_frame_absolute(Z_R10, tmp1, true/*load_fp*/); |
|
892 |
||
893 |
// Note also that the restored frame is not necessarily interpreted. |
|
894 |
// Use the shared runtime version of the StackOverflowError. |
|
895 |
assert(StubRoutines::throw_StackOverflowError_entry() != NULL, "stub not yet generated"); |
|
896 |
AddressLiteral stub(StubRoutines::throw_StackOverflowError_entry()); |
|
897 |
__ load_absolute_address(tmp1, StubRoutines::throw_StackOverflowError_entry()); |
|
898 |
__ z_br(tmp1); |
|
899 |
||
900 |
// If you get to here, then there is enough stack space. |
|
901 |
__ bind(after_frame_check); |
|
902 |
||
903 |
BLOCK_COMMENT("} counter_overflow"); |
|
904 |
} |
|
905 |
||
906 |
// Allocate monitor and lock method (asm interpreter). |
|
907 |
// |
|
908 |
// Args: |
|
909 |
// Z_locals: locals |
|
910 |
||
911 |
void TemplateInterpreterGenerator::lock_method(void) { |
|
912 |
||
913 |
BLOCK_COMMENT("lock_method {"); |
|
914 |
||
915 |
// Synchronize method. |
|
916 |
const Register method = Z_tmp_2; |
|
917 |
__ get_method(method); |
|
918 |
||
919 |
#ifdef ASSERT |
|
920 |
address reentry = NULL; |
|
921 |
{ |
|
922 |
Label L; |
|
923 |
__ testbit(method2_(method, access_flags), JVM_ACC_SYNCHRONIZED_BIT); |
|
924 |
__ z_btrue(L); |
|
925 |
reentry = __ stop_chain_static(reentry, "method doesn't need synchronization"); |
|
926 |
__ bind(L); |
|
927 |
} |
|
928 |
#endif // ASSERT |
|
929 |
||
930 |
// Get synchronization object. |
|
931 |
const Register object = Z_tmp_2; |
|
932 |
||
933 |
{ |
|
934 |
Label done; |
|
935 |
Label static_method; |
|
936 |
||
937 |
__ testbit(method2_(method, access_flags), JVM_ACC_STATIC_BIT); |
|
938 |
__ z_btrue(static_method); |
|
939 |
||
940 |
// non-static method: Load receiver obj from stack. |
|
941 |
__ mem2reg_opt(object, Address(Z_locals, Interpreter::local_offset_in_bytes(0))); |
|
942 |
__ z_bru(done); |
|
943 |
||
944 |
__ bind(static_method); |
|
945 |
||
946 |
// Lock the java mirror. |
|
947 |
__ load_mirror(object, method); |
|
948 |
#ifdef ASSERT |
|
949 |
{ |
|
950 |
NearLabel L; |
|
951 |
__ compare64_and_branch(object, (intptr_t) 0, Assembler::bcondNotEqual, L); |
|
952 |
reentry = __ stop_chain_static(reentry, "synchronization object is NULL"); |
|
953 |
__ bind(L); |
|
954 |
} |
|
955 |
#endif // ASSERT |
|
956 |
||
957 |
__ bind(done); |
|
958 |
} |
|
959 |
||
960 |
__ add_monitor_to_stack(true, Z_ARG3, Z_ARG4, Z_ARG5); // Allocate monitor elem. |
|
961 |
// Store object and lock it. |
|
962 |
__ get_monitors(Z_tmp_1); |
|
963 |
__ reg2mem_opt(object, Address(Z_tmp_1, BasicObjectLock::obj_offset_in_bytes())); |
|
964 |
__ lock_object(Z_tmp_1, object); |
|
965 |
||
966 |
BLOCK_COMMENT("} lock_method"); |
|
967 |
} |
|
968 |
||
969 |
// Generate a fixed interpreter frame. This is identical setup for |
|
970 |
// interpreted methods and for native methods hence the shared code. |
|
971 |
// |
|
972 |
// Registers alive |
|
973 |
// Z_thread - JavaThread* |
|
974 |
// Z_SP - old stack pointer |
|
975 |
// Z_method - callee's method |
|
976 |
// Z_esp - parameter list (slot 'above' last param) |
|
977 |
// Z_R14 - return pc, to be stored in caller's frame |
|
978 |
// Z_R10 - sender sp, note: Z_tmp_1 is Z_R10! |
|
979 |
// |
|
980 |
// Registers updated |
|
981 |
// Z_SP - new stack pointer |
|
982 |
// Z_esp - callee's operand stack pointer |
|
983 |
// points to the slot above the value on top |
|
984 |
// Z_locals - used to access locals: locals[i] := *(Z_locals - i*BytesPerWord) |
|
985 |
// Z_bcp - the bytecode pointer |
|
986 |
// Z_fp - the frame pointer, thereby killing Z_method |
|
987 |
// Z_ARG2 - copy of Z_method |
|
988 |
// |
|
989 |
void TemplateInterpreterGenerator::generate_fixed_frame(bool native_call) { |
|
990 |
||
991 |
// stack layout |
|
992 |
// |
|
993 |
// F1 [TOP_IJAVA_FRAME_ABI] <-- Z_SP, Z_R10 (see note below) |
|
994 |
// [F1's operand stack (unused)] |
|
995 |
// [F1's outgoing Java arguments] <-- Z_esp |
|
996 |
// [F1's operand stack (non args)] |
|
997 |
// [monitors] (optional) |
|
998 |
// [IJAVA_STATE] |
|
999 |
// |
|
1000 |
// F2 [PARENT_IJAVA_FRAME_ABI] |
|
1001 |
// ... |
|
1002 |
// |
|
1003 |
// 0x000 |
|
1004 |
// |
|
1005 |
// Note: Z_R10, the sender sp, will be below Z_SP if F1 was extended by a c2i adapter. |
|
1006 |
||
1007 |
//============================================================================= |
|
1008 |
// Allocate space for locals other than the parameters, the |
|
1009 |
// interpreter state, monitors, and the expression stack. |
|
1010 |
||
1011 |
const Register local_count = Z_ARG5; |
|
1012 |
const Register fp = Z_tmp_2; |
|
1013 |
||
1014 |
BLOCK_COMMENT("generate_fixed_frame {"); |
|
1015 |
||
1016 |
{ |
|
1017 |
// local registers |
|
1018 |
const Register top_frame_size = Z_ARG2; |
|
1019 |
const Register sp_after_resize = Z_ARG3; |
|
1020 |
const Register max_stack = Z_ARG4; |
|
1021 |
||
1022 |
// local_count = method->constMethod->max_locals(); |
|
1023 |
__ z_lg(Z_R1_scratch, Address(Z_method, Method::const_offset())); |
|
1024 |
__ z_llgh(local_count, Address(Z_R1_scratch, ConstMethod::size_of_locals_offset())); |
|
1025 |
||
1026 |
if (native_call) { |
|
1027 |
// If we're calling a native method, we replace max_stack (which is |
|
1028 |
// zero) with space for the worst-case signature handler varargs |
|
1029 |
// vector, which is: |
|
1030 |
// max_stack = max(Argument::n_register_parameters, parameter_count+2); |
|
1031 |
// |
|
1032 |
// We add two slots to the parameter_count, one for the jni |
|
1033 |
// environment and one for a possible native mirror. We allocate |
|
1034 |
// space for at least the number of ABI registers, even though |
|
1035 |
// InterpreterRuntime::slow_signature_handler won't write more than |
|
1036 |
// parameter_count+2 words when it creates the varargs vector at the |
|
1037 |
// top of the stack. The generated slow signature handler will just |
|
1038 |
// load trash into registers beyond the necessary number. We're |
|
1039 |
// still going to cut the stack back by the ABI register parameter |
|
1040 |
// count so as to get SP+16 pointing at the ABI outgoing parameter |
|
1041 |
// area, so we need to allocate at least that much even though we're |
|
1042 |
// going to throw it away. |
|
1043 |
// |
|
1044 |
||
1045 |
__ z_lg(Z_R1_scratch, Address(Z_method, Method::const_offset())); |
|
1046 |
__ z_llgh(max_stack, Address(Z_R1_scratch, ConstMethod::size_of_parameters_offset())); |
|
1047 |
__ add2reg(max_stack, 2); |
|
1048 |
||
1049 |
NearLabel passing_args_on_stack; |
|
1050 |
||
1051 |
// max_stack in bytes |
|
1052 |
__ z_sllg(max_stack, max_stack, LogBytesPerWord); |
|
1053 |
||
1054 |
int argument_registers_in_bytes = Argument::n_register_parameters << LogBytesPerWord; |
|
1055 |
__ compare64_and_branch(max_stack, argument_registers_in_bytes, Assembler::bcondNotLow, passing_args_on_stack); |
|
1056 |
||
1057 |
__ load_const_optimized(max_stack, argument_registers_in_bytes); |
|
1058 |
||
1059 |
__ bind(passing_args_on_stack); |
|
1060 |
} else { |
|
1061 |
// !native_call |
|
1062 |
__ z_lg(max_stack, method_(const)); |
|
1063 |
||
1064 |
// Calculate number of non-parameter locals (in slots): |
|
1065 |
__ z_lg(Z_R1_scratch, Address(Z_method, Method::const_offset())); |
|
1066 |
__ z_sh(local_count, Address(Z_R1_scratch, ConstMethod::size_of_parameters_offset())); |
|
1067 |
||
1068 |
// max_stack = method->max_stack(); |
|
1069 |
__ z_llgh(max_stack, Address(max_stack, ConstMethod::max_stack_offset())); |
|
1070 |
// max_stack in bytes |
|
1071 |
__ z_sllg(max_stack, max_stack, LogBytesPerWord); |
|
1072 |
} |
|
1073 |
||
1074 |
// Resize (i.e. normally shrink) the top frame F1 ... |
|
1075 |
// F1 [TOP_IJAVA_FRAME_ABI] <-- Z_SP, Z_R10 |
|
1076 |
// F1's operand stack (free) |
|
1077 |
// ... |
|
1078 |
// F1's operand stack (free) <-- Z_esp |
|
1079 |
// F1's outgoing Java arg m |
|
1080 |
// ... |
|
1081 |
// F1's outgoing Java arg 0 |
|
1082 |
// ... |
|
1083 |
// |
|
1084 |
// ... into a parent frame (Z_R10 holds F1's SP before any modification, see also above) |
|
1085 |
// |
|
1086 |
// +......................+ |
|
1087 |
// : : <-- Z_R10, saved below as F0's z_ijava_state.sender_sp |
|
1088 |
// : : |
|
1089 |
// F1 [PARENT_IJAVA_FRAME_ABI] <-- Z_SP \ |
|
1090 |
// F0's non arg local | = delta |
|
1091 |
// ... | |
|
1092 |
// F0's non arg local <-- Z_esp / |
|
1093 |
// F1's outgoing Java arg m |
|
1094 |
// ... |
|
1095 |
// F1's outgoing Java arg 0 |
|
1096 |
// ... |
|
1097 |
// |
|
1098 |
// then push the new top frame F0. |
|
1099 |
// |
|
1100 |
// F0 [TOP_IJAVA_FRAME_ABI] = frame::z_top_ijava_frame_abi_size \ |
|
1101 |
// [operand stack] = max_stack | = top_frame_size |
|
1102 |
// [IJAVA_STATE] = frame::z_ijava_state_size / |
|
1103 |
||
1104 |
// sp_after_resize = Z_esp - delta |
|
1105 |
// |
|
1106 |
// delta = PARENT_IJAVA_FRAME_ABI + (locals_count - params_count) |
|
1107 |
||
1108 |
__ add2reg(sp_after_resize, (Interpreter::stackElementSize) - (frame::z_parent_ijava_frame_abi_size), Z_esp); |
|
1109 |
__ z_sllg(Z_R0_scratch, local_count, LogBytesPerWord); // Params have already been subtracted from local_count. |
|
1110 |
__ z_slgr(sp_after_resize, Z_R0_scratch); |
|
1111 |
||
1112 |
// top_frame_size = TOP_IJAVA_FRAME_ABI + max_stack + size of interpreter state |
|
1113 |
__ add2reg(top_frame_size, |
|
1114 |
frame::z_top_ijava_frame_abi_size + |
|
43420
a056d6465ef9
8172049: [s390] Implement "JEP 270: Reserved Stack Areas for Critical Sections".
goetz
parents:
42897
diff
changeset
|
1115 |
frame::z_ijava_state_size + |
a056d6465ef9
8172049: [s390] Implement "JEP 270: Reserved Stack Areas for Critical Sections".
goetz
parents:
42897
diff
changeset
|
1116 |
frame::interpreter_frame_monitor_size() * wordSize, |
42065 | 1117 |
max_stack); |
1118 |
||
43420
a056d6465ef9
8172049: [s390] Implement "JEP 270: Reserved Stack Areas for Critical Sections".
goetz
parents:
42897
diff
changeset
|
1119 |
if (!native_call) { |
a056d6465ef9
8172049: [s390] Implement "JEP 270: Reserved Stack Areas for Critical Sections".
goetz
parents:
42897
diff
changeset
|
1120 |
// Stack overflow check. |
a056d6465ef9
8172049: [s390] Implement "JEP 270: Reserved Stack Areas for Critical Sections".
goetz
parents:
42897
diff
changeset
|
1121 |
// Native calls don't need the stack size check since they have no |
a056d6465ef9
8172049: [s390] Implement "JEP 270: Reserved Stack Areas for Critical Sections".
goetz
parents:
42897
diff
changeset
|
1122 |
// expression stack and the arguments are already on the stack and |
a056d6465ef9
8172049: [s390] Implement "JEP 270: Reserved Stack Areas for Critical Sections".
goetz
parents:
42897
diff
changeset
|
1123 |
// we only add a handful of words to the stack. |
a056d6465ef9
8172049: [s390] Implement "JEP 270: Reserved Stack Areas for Critical Sections".
goetz
parents:
42897
diff
changeset
|
1124 |
Register frame_size = max_stack; // Reuse the regiser for max_stack. |
a056d6465ef9
8172049: [s390] Implement "JEP 270: Reserved Stack Areas for Critical Sections".
goetz
parents:
42897
diff
changeset
|
1125 |
__ z_lgr(frame_size, Z_SP); |
a056d6465ef9
8172049: [s390] Implement "JEP 270: Reserved Stack Areas for Critical Sections".
goetz
parents:
42897
diff
changeset
|
1126 |
__ z_sgr(frame_size, sp_after_resize); |
a056d6465ef9
8172049: [s390] Implement "JEP 270: Reserved Stack Areas for Critical Sections".
goetz
parents:
42897
diff
changeset
|
1127 |
__ z_agr(frame_size, top_frame_size); |
a056d6465ef9
8172049: [s390] Implement "JEP 270: Reserved Stack Areas for Critical Sections".
goetz
parents:
42897
diff
changeset
|
1128 |
generate_stack_overflow_check(frame_size, fp/*tmp1*/); |
a056d6465ef9
8172049: [s390] Implement "JEP 270: Reserved Stack Areas for Critical Sections".
goetz
parents:
42897
diff
changeset
|
1129 |
} |
42065 | 1130 |
|
1131 |
DEBUG_ONLY(__ z_cg(Z_R14, _z_abi16(return_pc), Z_SP)); |
|
1132 |
__ asm_assert_eq("killed Z_R14", 0); |
|
1133 |
__ resize_frame_absolute(sp_after_resize, fp, true); |
|
1134 |
__ save_return_pc(Z_R14); |
|
1135 |
||
1136 |
// ... and push the new frame F0. |
|
1137 |
__ push_frame(top_frame_size, fp, true /*copy_sp*/, false); |
|
1138 |
} |
|
1139 |
||
1140 |
//============================================================================= |
|
1141 |
// Initialize the new frame F0: initialize interpreter state. |
|
1142 |
||
1143 |
{ |
|
1144 |
// locals |
|
1145 |
const Register local_addr = Z_ARG4; |
|
1146 |
||
1147 |
BLOCK_COMMENT("generate_fixed_frame: initialize interpreter state {"); |
|
1148 |
||
1149 |
#ifdef ASSERT |
|
1150 |
// Set the magic number (using local_addr as tmp register). |
|
1151 |
__ load_const_optimized(local_addr, frame::z_istate_magic_number); |
|
1152 |
__ z_stg(local_addr, _z_ijava_state_neg(magic), fp); |
|
1153 |
#endif |
|
1154 |
||
1155 |
// Save sender SP from F1 (i.e. before it was potentially modified by an |
|
1156 |
// adapter) into F0's interpreter state. We us it as well to revert |
|
1157 |
// resizing the frame above. |
|
1158 |
__ z_stg(Z_R10, _z_ijava_state_neg(sender_sp), fp); |
|
1159 |
||
1160 |
// Load cp cache and save it at the and of this block. |
|
1161 |
__ z_lg(Z_R1_scratch, Address(Z_method, Method::const_offset())); |
|
1162 |
__ z_lg(Z_R1_scratch, Address(Z_R1_scratch, ConstMethod::constants_offset())); |
|
1163 |
__ z_lg(Z_R1_scratch, Address(Z_R1_scratch, ConstantPool::cache_offset_in_bytes())); |
|
1164 |
||
1165 |
// z_ijava_state->method = method; |
|
1166 |
__ z_stg(Z_method, _z_ijava_state_neg(method), fp); |
|
1167 |
||
1168 |
// Point locals at the first argument. Method's locals are the |
|
1169 |
// parameters on top of caller's expression stack. |
|
1170 |
// Tos points past last Java argument. |
|
1171 |
||
1172 |
__ z_lg(Z_locals, Address(Z_method, Method::const_offset())); |
|
1173 |
__ z_llgh(Z_locals /*parameter_count words*/, |
|
1174 |
Address(Z_locals, ConstMethod::size_of_parameters_offset())); |
|
1175 |
__ z_sllg(Z_locals /*parameter_count bytes*/, Z_locals /*parameter_count*/, LogBytesPerWord); |
|
1176 |
__ z_agr(Z_locals, Z_esp); |
|
1177 |
// z_ijava_state->locals - i*BytesPerWord points to i-th Java local (i starts at 0) |
|
1178 |
// z_ijava_state->locals = Z_esp + parameter_count bytes |
|
1179 |
__ z_stg(Z_locals, _z_ijava_state_neg(locals), fp); |
|
1180 |
||
1181 |
// z_ijava_state->oop_temp = NULL; |
|
1182 |
__ store_const(Address(fp, oop_tmp_offset), 0); |
|
1183 |
||
1184 |
// Initialize z_ijava_state->mdx. |
|
1185 |
Register Rmdp = Z_bcp; |
|
1186 |
// native_call: assert that mdo == NULL |
|
1187 |
const bool check_for_mdo = !native_call DEBUG_ONLY(|| native_call); |
|
1188 |
if (ProfileInterpreter && check_for_mdo) { |
|
1189 |
#ifdef FAST_DISPATCH |
|
1190 |
// FAST_DISPATCH and ProfileInterpreter are mutually exclusive since |
|
1191 |
// they both use I2. |
|
1192 |
assert(0, "FAST_DISPATCH and +ProfileInterpreter are mutually exclusive"); |
|
1193 |
#endif // FAST_DISPATCH |
|
1194 |
Label get_continue; |
|
1195 |
||
1196 |
__ load_and_test_long(Rmdp, method_(method_data)); |
|
1197 |
__ z_brz(get_continue); |
|
1198 |
DEBUG_ONLY(if (native_call) __ stop("native methods don't have a mdo")); |
|
1199 |
__ add2reg(Rmdp, in_bytes(MethodData::data_offset())); |
|
1200 |
__ bind(get_continue); |
|
1201 |
} |
|
1202 |
__ z_stg(Rmdp, _z_ijava_state_neg(mdx), fp); |
|
1203 |
||
1204 |
// Initialize z_ijava_state->bcp and Z_bcp. |
|
1205 |
if (native_call) { |
|
1206 |
__ clear_reg(Z_bcp); // Must initialize. Will get written into frame where GC reads it. |
|
1207 |
} else { |
|
1208 |
__ z_lg(Z_bcp, method_(const)); |
|
1209 |
__ add2reg(Z_bcp, in_bytes(ConstMethod::codes_offset())); |
|
1210 |
} |
|
1211 |
__ z_stg(Z_bcp, _z_ijava_state_neg(bcp), fp); |
|
1212 |
||
1213 |
// no monitors and empty operand stack |
|
1214 |
// => z_ijava_state->monitors points to the top slot in IJAVA_STATE. |
|
1215 |
// => Z_ijava_state->esp points one slot above into the operand stack. |
|
1216 |
// z_ijava_state->monitors = fp - frame::z_ijava_state_size - Interpreter::stackElementSize; |
|
1217 |
// z_ijava_state->esp = Z_esp = z_ijava_state->monitors; |
|
1218 |
__ add2reg(Z_esp, -frame::z_ijava_state_size, fp); |
|
1219 |
__ z_stg(Z_esp, _z_ijava_state_neg(monitors), fp); |
|
1220 |
__ add2reg(Z_esp, -Interpreter::stackElementSize); |
|
1221 |
__ z_stg(Z_esp, _z_ijava_state_neg(esp), fp); |
|
1222 |
||
1223 |
// z_ijava_state->cpoolCache = Z_R1_scratch (see load above); |
|
1224 |
__ z_stg(Z_R1_scratch, _z_ijava_state_neg(cpoolCache), fp); |
|
1225 |
||
1226 |
// Get mirror and store it in the frame as GC root for this Method*. |
|
1227 |
__ load_mirror(Z_R1_scratch, Z_method); |
|
1228 |
__ z_stg(Z_R1_scratch, _z_ijava_state_neg(mirror), fp); |
|
1229 |
||
1230 |
BLOCK_COMMENT("} generate_fixed_frame: initialize interpreter state"); |
|
1231 |
||
1232 |
//============================================================================= |
|
1233 |
if (!native_call) { |
|
1234 |
// Fill locals with 0x0s. |
|
1235 |
NearLabel locals_zeroed; |
|
1236 |
NearLabel doXC; |
|
1237 |
||
1238 |
// Local_count is already num_locals_slots - num_param_slots. |
|
1239 |
__ compare64_and_branch(local_count, (intptr_t)0L, Assembler::bcondNotHigh, locals_zeroed); |
|
1240 |
||
1241 |
// Advance local_addr to point behind locals (creates positive incr. in loop). |
|
1242 |
__ z_lg(Z_R1_scratch, Address(Z_method, Method::const_offset())); |
|
1243 |
__ z_llgh(Z_R0_scratch, |
|
1244 |
Address(Z_R1_scratch, ConstMethod::size_of_locals_offset())); |
|
1245 |
if (Z_R0_scratch == Z_R0) { |
|
1246 |
__ z_aghi(Z_R0_scratch, -1); |
|
1247 |
} else { |
|
1248 |
__ add2reg(Z_R0_scratch, -1); |
|
1249 |
} |
|
1250 |
__ z_lgr(local_addr/*locals*/, Z_locals); |
|
1251 |
__ z_sllg(Z_R0_scratch, Z_R0_scratch, LogBytesPerWord); |
|
1252 |
__ z_sllg(local_count, local_count, LogBytesPerWord); // Local_count are non param locals. |
|
1253 |
__ z_sgr(local_addr, Z_R0_scratch); |
|
1254 |
||
1255 |
if (VM_Version::has_Prefetch()) { |
|
1256 |
__ z_pfd(0x02, 0, Z_R0, local_addr); |
|
1257 |
__ z_pfd(0x02, 256, Z_R0, local_addr); |
|
1258 |
} |
|
1259 |
||
1260 |
// Can't optimise for Z10 using "compare and branch" (immediate value is too big). |
|
1261 |
__ z_cghi(local_count, 256); |
|
1262 |
__ z_brnh(doXC); |
|
1263 |
||
1264 |
// MVCLE: Initialize if quite a lot locals. |
|
1265 |
// __ bind(doMVCLE); |
|
1266 |
__ z_lgr(Z_R0_scratch, local_addr); |
|
1267 |
__ z_lgr(Z_R1_scratch, local_count); |
|
1268 |
__ clear_reg(Z_ARG2); // Src len of MVCLE is zero. |
|
1269 |
||
1270 |
__ MacroAssembler::move_long_ext(Z_R0_scratch, Z_ARG1, 0); |
|
1271 |
__ z_bru(locals_zeroed); |
|
1272 |
||
1273 |
Label XC_template; |
|
1274 |
__ bind(XC_template); |
|
1275 |
__ z_xc(0, 0, local_addr, 0, local_addr); |
|
1276 |
||
1277 |
__ bind(doXC); |
|
1278 |
__ z_bctgr(local_count, Z_R0); // Get #bytes-1 for EXECUTE. |
|
1279 |
if (VM_Version::has_ExecuteExtensions()) { |
|
1280 |
__ z_exrl(local_count, XC_template); // Execute XC with variable length. |
|
1281 |
} else { |
|
1282 |
__ z_larl(Z_R1_scratch, XC_template); |
|
1283 |
__ z_ex(local_count, 0, Z_R0, Z_R1_scratch); // Execute XC with variable length. |
|
1284 |
} |
|
1285 |
||
1286 |
__ bind(locals_zeroed); |
|
1287 |
} |
|
1288 |
||
1289 |
} |
|
1290 |
// Finally set the frame pointer, destroying Z_method. |
|
1291 |
assert(Z_fp == Z_method, "maybe set Z_fp earlier if other register than Z_method"); |
|
1292 |
// Oprofile analysis suggests to keep a copy in a register to be used by |
|
1293 |
// generate_counter_incr(). |
|
1294 |
__ z_lgr(Z_ARG2, Z_method); |
|
1295 |
__ z_lgr(Z_fp, fp); |
|
1296 |
||
1297 |
BLOCK_COMMENT("} generate_fixed_frame"); |
|
1298 |
} |
|
1299 |
||
1300 |
// Various method entries |
|
1301 |
||
1302 |
// Math function, frame manager must set up an interpreter state, etc. |
|
1303 |
address TemplateInterpreterGenerator::generate_math_entry(AbstractInterpreter::MethodKind kind) { |
|
1304 |
||
42897
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1305 |
// Decide what to do: Use same platform specific instructions and runtime calls as compilers. |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1306 |
bool use_instruction = false; |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1307 |
address runtime_entry = NULL; |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1308 |
int num_args = 1; |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1309 |
bool double_precision = true; |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1310 |
|
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1311 |
// s390 specific: |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1312 |
switch (kind) { |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1313 |
case Interpreter::java_lang_math_sqrt: |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1314 |
case Interpreter::java_lang_math_abs: use_instruction = true; break; |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1315 |
case Interpreter::java_lang_math_fmaF: |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1316 |
case Interpreter::java_lang_math_fmaD: use_instruction = UseFMA; break; |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1317 |
default: break; // Fall back to runtime call. |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1318 |
} |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1319 |
|
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1320 |
switch (kind) { |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1321 |
case Interpreter::java_lang_math_sin : runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dsin); break; |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1322 |
case Interpreter::java_lang_math_cos : runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dcos); break; |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1323 |
case Interpreter::java_lang_math_tan : runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dtan); break; |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1324 |
case Interpreter::java_lang_math_abs : /* run interpreted */ break; |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1325 |
case Interpreter::java_lang_math_sqrt : /* runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dsqrt); not available */ break; |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1326 |
case Interpreter::java_lang_math_log : runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dlog); break; |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1327 |
case Interpreter::java_lang_math_log10: runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dlog10); break; |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1328 |
case Interpreter::java_lang_math_pow : runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dpow); num_args = 2; break; |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1329 |
case Interpreter::java_lang_math_exp : runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dexp); break; |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1330 |
case Interpreter::java_lang_math_fmaF : /* run interpreted */ num_args = 3; double_precision = false; break; |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1331 |
case Interpreter::java_lang_math_fmaD : /* run interpreted */ num_args = 3; break; |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1332 |
default: ShouldNotReachHere(); |
42065 | 1333 |
} |
1334 |
||
42897
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1335 |
// Use normal entry if neither instruction nor runtime call is used. |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1336 |
if (!use_instruction && runtime_entry == NULL) return NULL; |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1337 |
|
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1338 |
address entry = __ pc(); |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1339 |
|
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1340 |
if (use_instruction) { |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1341 |
switch (kind) { |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1342 |
case Interpreter::java_lang_math_sqrt: |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1343 |
// Can use memory operand directly. |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1344 |
__ z_sqdb(Z_FRET, Interpreter::stackElementSize, Z_esp); |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1345 |
break; |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1346 |
case Interpreter::java_lang_math_abs: |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1347 |
// Load operand from stack. |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1348 |
__ mem2freg_opt(Z_FRET, Address(Z_esp, Interpreter::stackElementSize)); |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1349 |
__ z_lpdbr(Z_FRET); |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1350 |
break; |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1351 |
case Interpreter::java_lang_math_fmaF: |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1352 |
__ mem2freg_opt(Z_FRET, Address(Z_esp, Interpreter::stackElementSize)); // result reg = arg3 |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1353 |
__ mem2freg_opt(Z_FARG2, Address(Z_esp, 3 * Interpreter::stackElementSize)); // arg1 |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1354 |
__ z_maeb(Z_FRET, Z_FARG2, Address(Z_esp, 2 * Interpreter::stackElementSize)); |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1355 |
break; |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1356 |
case Interpreter::java_lang_math_fmaD: |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1357 |
__ mem2freg_opt(Z_FRET, Address(Z_esp, Interpreter::stackElementSize)); // result reg = arg3 |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1358 |
__ mem2freg_opt(Z_FARG2, Address(Z_esp, 5 * Interpreter::stackElementSize)); // arg1 |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1359 |
__ z_madb(Z_FRET, Z_FARG2, Address(Z_esp, 3 * Interpreter::stackElementSize)); |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1360 |
break; |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1361 |
default: ShouldNotReachHere(); |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1362 |
} |
42065 | 1363 |
} else { |
42897
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1364 |
// Load arguments |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1365 |
assert(num_args <= 4, "passed in registers"); |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1366 |
if (double_precision) { |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1367 |
int offset = (2 * num_args - 1) * Interpreter::stackElementSize; |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1368 |
for (int i = 0; i < num_args; ++i) { |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1369 |
__ mem2freg_opt(as_FloatRegister(Z_FARG1->encoding() + 2 * i), Address(Z_esp, offset)); |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1370 |
offset -= 2 * Interpreter::stackElementSize; |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1371 |
} |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1372 |
} else { |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1373 |
int offset = num_args * Interpreter::stackElementSize; |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1374 |
for (int i = 0; i < num_args; ++i) { |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1375 |
__ mem2freg_opt(as_FloatRegister(Z_FARG1->encoding() + 2 * i), Address(Z_esp, offset)); |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1376 |
offset -= Interpreter::stackElementSize; |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1377 |
} |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1378 |
} |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1379 |
// Call runtime |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1380 |
__ save_return_pc(); // Save Z_R14. |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1381 |
__ push_frame_abi160(0); // Without new frame the RT call could overwrite the saved Z_R14. |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1382 |
|
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1383 |
__ call_VM_leaf(runtime_entry); |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1384 |
|
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1385 |
__ pop_frame(); |
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1386 |
__ restore_return_pc(); // Restore Z_R14. |
42065 | 1387 |
} |
1388 |
||
42897
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1389 |
// Pop c2i arguments (if any) off when we return. |
42065 | 1390 |
__ resize_frame_absolute(Z_R10, Z_R0, true); // Cut the stack back to where the caller started. |
1391 |
||
1392 |
__ z_br(Z_R14); |
|
1393 |
||
42897
57e7b1c75d17
8171398: s390x: Make interpreter's math entries consistent with C1 and C2 and support FMA
mdoerr
parents:
42065
diff
changeset
|
1394 |
return entry; |
42065 | 1395 |
} |
1396 |
||
1397 |
// Interpreter stub for calling a native method. (asm interpreter). |
|
1398 |
// This sets up a somewhat different looking stack for calling the |
|
1399 |
// native method than the typical interpreter frame setup. |
|
1400 |
address TemplateInterpreterGenerator::generate_native_entry(bool synchronized) { |
|
1401 |
// Determine code generation flags. |
|
1402 |
bool inc_counter = UseCompiler || CountCompiledCalls || LogTouchedMethods; |
|
1403 |
||
1404 |
// Interpreter entry for ordinary Java methods. |
|
1405 |
// |
|
1406 |
// Registers alive |
|
1407 |
// Z_SP - stack pointer |
|
1408 |
// Z_thread - JavaThread* |
|
1409 |
// Z_method - callee's method (method to be invoked) |
|
1410 |
// Z_esp - operand (or expression) stack pointer of caller. one slot above last arg. |
|
1411 |
// Z_R10 - sender sp (before modifications, e.g. by c2i adapter |
|
1412 |
// and as well by generate_fixed_frame below) |
|
1413 |
// Z_R14 - return address to caller (call_stub or c2i_adapter) |
|
1414 |
// |
|
1415 |
// Registers updated |
|
1416 |
// Z_SP - stack pointer |
|
1417 |
// Z_fp - callee's framepointer |
|
1418 |
// Z_esp - callee's operand stack pointer |
|
1419 |
// points to the slot above the value on top |
|
1420 |
// Z_locals - used to access locals: locals[i] := *(Z_locals - i*BytesPerWord) |
|
1421 |
// Z_tos - integer result, if any |
|
1422 |
// z_ftos - floating point result, if any |
|
1423 |
// |
|
1424 |
// Stack layout at this point: |
|
1425 |
// |
|
1426 |
// F1 [TOP_IJAVA_FRAME_ABI] <-- Z_SP, Z_R10 (Z_R10 will be below Z_SP if |
|
1427 |
// frame was extended by c2i adapter) |
|
1428 |
// [outgoing Java arguments] <-- Z_esp |
|
1429 |
// ... |
|
1430 |
// PARENT [PARENT_IJAVA_FRAME_ABI] |
|
1431 |
// ... |
|
1432 |
// |
|
1433 |
||
1434 |
address entry_point = __ pc(); |
|
1435 |
||
1436 |
// Make sure registers are different! |
|
1437 |
assert_different_registers(Z_thread, Z_method, Z_esp); |
|
1438 |
||
1439 |
BLOCK_COMMENT("native_entry {"); |
|
1440 |
||
1441 |
// Make sure method is native and not abstract. |
|
1442 |
#ifdef ASSERT |
|
1443 |
address reentry = NULL; |
|
1444 |
{ Label L; |
|
1445 |
__ testbit(method_(access_flags), JVM_ACC_NATIVE_BIT); |
|
1446 |
__ z_btrue(L); |
|
1447 |
reentry = __ stop_chain_static(reentry, "tried to execute non-native method as native"); |
|
1448 |
__ bind(L); |
|
1449 |
} |
|
1450 |
{ Label L; |
|
1451 |
__ testbit(method_(access_flags), JVM_ACC_ABSTRACT_BIT); |
|
1452 |
__ z_bfalse(L); |
|
1453 |
reentry = __ stop_chain_static(reentry, "tried to execute abstract method as non-abstract"); |
|
1454 |
__ bind(L); |
|
1455 |
} |
|
1456 |
#endif // ASSERT |
|
1457 |
||
1458 |
#ifdef ASSERT |
|
1459 |
// Save the return PC into the callers frame for assertion in generate_fixed_frame. |
|
1460 |
__ save_return_pc(Z_R14); |
|
1461 |
#endif |
|
1462 |
||
1463 |
// Generate the code to allocate the interpreter stack frame. |
|
1464 |
generate_fixed_frame(true); |
|
1465 |
||
1466 |
const Address do_not_unlock_if_synchronized(Z_thread, JavaThread::do_not_unlock_if_synchronized_offset()); |
|
1467 |
// Since at this point in the method invocation the exception handler |
|
1468 |
// would try to exit the monitor of synchronized methods which hasn't |
|
1469 |
// been entered yet, we set the thread local variable |
|
1470 |
// _do_not_unlock_if_synchronized to true. If any exception was thrown by |
|
1471 |
// runtime, exception handling i.e. unlock_if_synchronized_method will |
|
1472 |
// check this thread local flag. |
|
1473 |
__ z_mvi(do_not_unlock_if_synchronized, true); |
|
1474 |
||
1475 |
// Increment invocation count and check for overflow. |
|
1476 |
NearLabel invocation_counter_overflow; |
|
1477 |
if (inc_counter) { |
|
1478 |
generate_counter_incr(&invocation_counter_overflow, NULL, NULL); |
|
1479 |
} |
|
1480 |
||
1481 |
Label continue_after_compile; |
|
1482 |
__ bind(continue_after_compile); |
|
1483 |
||
1484 |
bang_stack_shadow_pages(true); |
|
1485 |
||
1486 |
// Reset the _do_not_unlock_if_synchronized flag. |
|
1487 |
__ z_mvi(do_not_unlock_if_synchronized, false); |
|
1488 |
||
1489 |
// Check for synchronized methods. |
|
1490 |
// This mst happen AFTER invocation_counter check and stack overflow check, |
|
1491 |
// so method is not locked if overflows. |
|
1492 |
if (synchronized) { |
|
1493 |
lock_method(); |
|
1494 |
} else { |
|
1495 |
// No synchronization necessary. |
|
1496 |
#ifdef ASSERT |
|
1497 |
{ Label L; |
|
1498 |
__ get_method(Z_R1_scratch); |
|
1499 |
__ testbit(method2_(Z_R1_scratch, access_flags), JVM_ACC_SYNCHRONIZED_BIT); |
|
1500 |
__ z_bfalse(L); |
|
1501 |
reentry = __ stop_chain_static(reentry, "method needs synchronization"); |
|
1502 |
__ bind(L); |
|
1503 |
} |
|
1504 |
#endif // ASSERT |
|
1505 |
} |
|
1506 |
||
1507 |
// start execution |
|
1508 |
||
1509 |
// jvmti support |
|
1510 |
__ notify_method_entry(); |
|
1511 |
||
1512 |
//============================================================================= |
|
1513 |
// Get and call the signature handler. |
|
1514 |
const Register Rmethod = Z_tmp_2; |
|
1515 |
const Register signature_handler_entry = Z_tmp_1; |
|
1516 |
const Register Rresult_handler = Z_tmp_3; |
|
1517 |
Label call_signature_handler; |
|
1518 |
||
1519 |
assert_different_registers(Z_fp, Rmethod, signature_handler_entry, Rresult_handler); |
|
1520 |
assert(Rresult_handler->is_nonvolatile(), "Rresult_handler must be in a non-volatile register"); |
|
1521 |
||
1522 |
// Reload method. |
|
1523 |
__ get_method(Rmethod); |
|
1524 |
||
1525 |
// Check for signature handler. |
|
1526 |
__ load_and_test_long(signature_handler_entry, method2_(Rmethod, signature_handler)); |
|
1527 |
__ z_brne(call_signature_handler); |
|
1528 |
||
1529 |
// Method has never been called. Either generate a specialized |
|
1530 |
// handler or point to the slow one. |
|
1531 |
__ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::prepare_native_call), |
|
1532 |
Rmethod); |
|
1533 |
||
1534 |
// Reload method. |
|
1535 |
__ get_method(Rmethod); |
|
1536 |
||
1537 |
// Reload signature handler, it must have been created/assigned in the meantime. |
|
1538 |
__ z_lg(signature_handler_entry, method2_(Rmethod, signature_handler)); |
|
1539 |
||
1540 |
__ bind(call_signature_handler); |
|
1541 |
||
1542 |
// We have a TOP_IJAVA_FRAME here, which belongs to us. |
|
1543 |
__ set_top_ijava_frame_at_SP_as_last_Java_frame(Z_SP, Z_R1/*tmp*/); |
|
1544 |
||
1545 |
// Call signature handler and pass locals address in Z_ARG1. |
|
1546 |
__ z_lgr(Z_ARG1, Z_locals); |
|
1547 |
__ call_stub(signature_handler_entry); |
|
1548 |
// Save result handler returned by signature handler. |
|
1549 |
__ z_lgr(Rresult_handler, Z_RET); |
|
1550 |
||
1551 |
// Reload method (the slow signature handler may block for GC). |
|
1552 |
__ get_method(Rmethod); |
|
1553 |
||
1554 |
// Pass mirror handle if static call. |
|
1555 |
{ |
|
1556 |
Label method_is_not_static; |
|
1557 |
__ testbit(method2_(Rmethod, access_flags), JVM_ACC_STATIC_BIT); |
|
1558 |
__ z_bfalse(method_is_not_static); |
|
1559 |
// Get mirror. |
|
1560 |
__ load_mirror(Z_R1, Rmethod); |
|
1561 |
// z_ijava_state.oop_temp = pool_holder->klass_part()->java_mirror(); |
|
1562 |
__ z_stg(Z_R1, oop_tmp_offset, Z_fp); |
|
1563 |
// Pass handle to mirror as 2nd argument to JNI method. |
|
1564 |
__ add2reg(Z_ARG2, oop_tmp_offset, Z_fp); |
|
1565 |
__ bind(method_is_not_static); |
|
1566 |
} |
|
1567 |
||
1568 |
// Pass JNIEnv address as first parameter. |
|
1569 |
__ add2reg(Z_ARG1, in_bytes(JavaThread::jni_environment_offset()), Z_thread); |
|
1570 |
||
1571 |
// Note: last java frame has been set above already. The pc from there |
|
1572 |
// is precise enough. |
|
1573 |
||
1574 |
// Get native function entry point before we change the thread state. |
|
1575 |
__ z_lg(Z_R1/*native_method_entry*/, method2_(Rmethod, native_function)); |
|
1576 |
||
1577 |
//============================================================================= |
|
1578 |
// Transition from _thread_in_Java to _thread_in_native. As soon as |
|
1579 |
// we make this change the safepoint code needs to be certain that |
|
1580 |
// the last Java frame we established is good. The pc in that frame |
|
1581 |
// just need to be near here not an actual return address. |
|
1582 |
#ifdef ASSERT |
|
1583 |
{ |
|
1584 |
NearLabel L; |
|
1585 |
__ mem2reg_opt(Z_R14, Address(Z_thread, JavaThread::thread_state_offset()), false /*32 bits*/); |
|
1586 |
__ compareU32_and_branch(Z_R14, _thread_in_Java, Assembler::bcondEqual, L); |
|
1587 |
reentry = __ stop_chain_static(reentry, "Wrong thread state in native stub"); |
|
1588 |
__ bind(L); |
|
1589 |
} |
|
1590 |
#endif |
|
1591 |
||
1592 |
// Memory ordering: Z does not reorder store/load with subsequent load. That's strong enough. |
|
1593 |
__ set_thread_state(_thread_in_native); |
|
1594 |
||
1595 |
//============================================================================= |
|
1596 |
// Call the native method. Argument registers must not have been |
|
1597 |
// overwritten since "__ call_stub(signature_handler);" (except for |
|
1598 |
// ARG1 and ARG2 for static methods). |
|
1599 |
||
1600 |
__ call_c(Z_R1/*native_method_entry*/); |
|
1601 |
||
1602 |
// NOTE: frame::interpreter_frame_result() depends on these stores. |
|
1603 |
__ z_stg(Z_RET, _z_ijava_state_neg(lresult), Z_fp); |
|
1604 |
__ freg2mem_opt(Z_FRET, Address(Z_fp, _z_ijava_state_neg(fresult))); |
|
1605 |
const Register Rlresult = signature_handler_entry; |
|
1606 |
assert(Rlresult->is_nonvolatile(), "Rlresult must be in a non-volatile register"); |
|
1607 |
__ z_lgr(Rlresult, Z_RET); |
|
1608 |
||
1609 |
// Z_method may no longer be valid, because of GC. |
|
1610 |
||
1611 |
// Block, if necessary, before resuming in _thread_in_Java state. |
|
1612 |
// In order for GC to work, don't clear the last_Java_sp until after |
|
1613 |
// blocking. |
|
1614 |
||
1615 |
//============================================================================= |
|
1616 |
// Switch thread to "native transition" state before reading the |
|
1617 |
// synchronization state. This additional state is necessary |
|
1618 |
// because reading and testing the synchronization state is not |
|
1619 |
// atomic w.r.t. GC, as this scenario demonstrates: Java thread A, |
|
1620 |
// in _thread_in_native state, loads _not_synchronized and is |
|
1621 |
// preempted. VM thread changes sync state to synchronizing and |
|
1622 |
// suspends threads for GC. Thread A is resumed to finish this |
|
1623 |
// native method, but doesn't block here since it didn't see any |
|
1624 |
// synchronization is progress, and escapes. |
|
1625 |
||
1626 |
__ set_thread_state(_thread_in_native_trans); |
|
1627 |
if (UseMembar) { |
|
1628 |
__ z_fence(); |
|
1629 |
} else { |
|
1630 |
// Write serialization page so VM thread can do a pseudo remote |
|
1631 |
// membar. We use the current thread pointer to calculate a thread |
|
1632 |
// specific offset to write to within the page. This minimizes bus |
|
1633 |
// traffic due to cache line collision. |
|
1634 |
__ serialize_memory(Z_thread, Z_R1, Z_R0); |
|
1635 |
} |
|
1636 |
// Now before we return to java we must look for a current safepoint |
|
1637 |
// (a new safepoint can not start since we entered native_trans). |
|
1638 |
// We must check here because a current safepoint could be modifying |
|
1639 |
// the callers registers right this moment. |
|
1640 |
||
1641 |
// Check for safepoint operation in progress and/or pending suspend requests. |
|
1642 |
{ |
|
1643 |
Label Continue, do_safepoint; |
|
1644 |
__ generate_safepoint_check(do_safepoint, Z_R1, true); |
|
1645 |
// Check for suspend. |
|
1646 |
__ load_and_test_int(Z_R0/*suspend_flags*/, thread_(suspend_flags)); |
|
1647 |
__ z_bre(Continue); // 0 -> no flag set -> not suspended |
|
1648 |
__ bind(do_safepoint); |
|
1649 |
__ z_lgr(Z_ARG1, Z_thread); |
|
1650 |
__ call_c(CAST_FROM_FN_PTR(address, JavaThread::check_special_condition_for_native_trans)); |
|
1651 |
__ bind(Continue); |
|
1652 |
} |
|
1653 |
||
1654 |
//============================================================================= |
|
1655 |
// Back in Interpreter Frame. |
|
1656 |
||
1657 |
// We are in thread_in_native_trans here and back in the normal |
|
1658 |
// interpreter frame. We don't have to do anything special about |
|
1659 |
// safepoints and we can switch to Java mode anytime we are ready. |
|
1660 |
||
1661 |
// Note: frame::interpreter_frame_result has a dependency on how the |
|
1662 |
// method result is saved across the call to post_method_exit. For |
|
1663 |
// native methods it assumes that the non-FPU/non-void result is |
|
1664 |
// saved in z_ijava_state.lresult and a FPU result in z_ijava_state.fresult. If |
|
1665 |
// this changes then the interpreter_frame_result implementation |
|
1666 |
// will need to be updated too. |
|
1667 |
||
1668 |
//============================================================================= |
|
1669 |
// Back in Java. |
|
1670 |
||
1671 |
// Memory ordering: Z does not reorder store/load with subsequent |
|
1672 |
// load. That's strong enough. |
|
1673 |
__ set_thread_state(_thread_in_Java); |
|
1674 |
||
1675 |
__ reset_last_Java_frame(); |
|
1676 |
||
1677 |
// We reset the JNI handle block only after unboxing the result; see below. |
|
1678 |
||
1679 |
// The method register is junk from after the thread_in_native transition |
|
1680 |
// until here. Also can't call_VM until the bcp has been |
|
1681 |
// restored. Need bcp for throwing exception below so get it now. |
|
1682 |
__ get_method(Rmethod); |
|
1683 |
||
1684 |
// Restore Z_bcp to have legal interpreter frame, |
|
1685 |
// i.e., bci == 0 <=> Z_bcp == code_base(). |
|
1686 |
__ z_lg(Z_bcp, Address(Rmethod, Method::const_offset())); // get constMethod |
|
1687 |
__ add2reg(Z_bcp, in_bytes(ConstMethod::codes_offset())); // get codebase |
|
1688 |
||
1689 |
if (CheckJNICalls) { |
|
1690 |
// clear_pending_jni_exception_check |
|
1691 |
__ clear_mem(Address(Z_thread, JavaThread::pending_jni_exception_check_fn_offset()), sizeof(oop)); |
|
1692 |
} |
|
1693 |
||
1694 |
// Check if the native method returns an oop, and if so, move it |
|
1695 |
// from the jni handle to z_ijava_state.oop_temp. This is |
|
1696 |
// necessary, because we reset the jni handle block below. |
|
1697 |
// NOTE: frame::interpreter_frame_result() depends on this, too. |
|
44406
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
1698 |
{ NearLabel no_oop_result; |
42065 | 1699 |
__ load_absolute_address(Z_R1, AbstractInterpreter::result_handler(T_OBJECT)); |
1700 |
__ compareU64_and_branch(Z_R1, Rresult_handler, Assembler::bcondNotEqual, no_oop_result); |
|
44406
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
1701 |
__ resolve_jobject(Rlresult, /* tmp1 */ Rmethod, /* tmp2 */ Z_R1); |
42065 | 1702 |
__ z_stg(Rlresult, oop_tmp_offset, Z_fp); |
1703 |
__ bind(no_oop_result); |
|
1704 |
} |
|
1705 |
||
1706 |
// Reset handle block. |
|
1707 |
__ z_lg(Z_R1/*active_handles*/, thread_(active_handles)); |
|
1708 |
__ clear_mem(Address(Z_R1, JNIHandleBlock::top_offset_in_bytes()), 4); |
|
1709 |
||
1710 |
// Bandle exceptions (exception handling will handle unlocking!). |
|
1711 |
{ |
|
1712 |
Label L; |
|
1713 |
__ load_and_test_long(Z_R0/*pending_exception*/, thread_(pending_exception)); |
|
1714 |
__ z_bre(L); |
|
1715 |
__ MacroAssembler::call_VM(noreg, |
|
1716 |
CAST_FROM_FN_PTR(address, |
|
1717 |
InterpreterRuntime::throw_pending_exception)); |
|
1718 |
__ should_not_reach_here(); |
|
1719 |
__ bind(L); |
|
1720 |
} |
|
1721 |
||
1722 |
if (synchronized) { |
|
1723 |
Register Rfirst_monitor = Z_ARG2; |
|
1724 |
__ add2reg(Rfirst_monitor, -(frame::z_ijava_state_size + (int)sizeof(BasicObjectLock)), Z_fp); |
|
1725 |
#ifdef ASSERT |
|
1726 |
NearLabel ok; |
|
1727 |
__ z_lg(Z_R1, _z_ijava_state_neg(monitors), Z_fp); |
|
1728 |
__ compareU64_and_branch(Rfirst_monitor, Z_R1, Assembler::bcondEqual, ok); |
|
1729 |
reentry = __ stop_chain_static(reentry, "native_entry:unlock: inconsistent z_ijava_state.monitors"); |
|
1730 |
__ bind(ok); |
|
1731 |
#endif |
|
1732 |
__ unlock_object(Rfirst_monitor); |
|
1733 |
} |
|
1734 |
||
1735 |
// JVMTI support. Result has already been saved above to the frame. |
|
1736 |
__ notify_method_exit(true/*native_method*/, ilgl, InterpreterMacroAssembler::NotifyJVMTI); |
|
1737 |
||
1738 |
// Move native method result back into proper registers and return. |
|
1739 |
// C++ interpreter does not use result handler. So do we need to here? TODO(ZASM): check if correct. |
|
1740 |
{ NearLabel no_oop_or_null; |
|
1741 |
__ mem2freg_opt(Z_FRET, Address(Z_fp, _z_ijava_state_neg(fresult))); |
|
1742 |
__ load_and_test_long(Z_RET, Address(Z_fp, _z_ijava_state_neg(lresult))); |
|
1743 |
__ z_bre(no_oop_or_null); // No unboxing if the result is NULL. |
|
1744 |
__ load_absolute_address(Z_R1, AbstractInterpreter::result_handler(T_OBJECT)); |
|
1745 |
__ compareU64_and_branch(Z_R1, Rresult_handler, Assembler::bcondNotEqual, no_oop_or_null); |
|
1746 |
__ z_lg(Z_RET, oop_tmp_offset, Z_fp); |
|
1747 |
__ verify_oop(Z_RET); |
|
1748 |
__ bind(no_oop_or_null); |
|
1749 |
} |
|
1750 |
||
1751 |
// Pop the native method's interpreter frame. |
|
1752 |
__ pop_interpreter_frame(Z_R14 /*return_pc*/, Z_ARG2/*tmp1*/, Z_ARG3/*tmp2*/); |
|
1753 |
||
1754 |
// Return to caller. |
|
1755 |
__ z_br(Z_R14); |
|
1756 |
||
1757 |
if (inc_counter) { |
|
1758 |
// Handle overflow of counter and compile method. |
|
1759 |
__ bind(invocation_counter_overflow); |
|
1760 |
generate_counter_overflow(continue_after_compile); |
|
1761 |
} |
|
1762 |
||
1763 |
BLOCK_COMMENT("} native_entry"); |
|
1764 |
||
1765 |
return entry_point; |
|
1766 |
} |
|
1767 |
||
1768 |
// |
|
1769 |
// Generic interpreted method entry to template interpreter. |
|
1770 |
// |
|
1771 |
address TemplateInterpreterGenerator::generate_normal_entry(bool synchronized) { |
|
1772 |
address entry_point = __ pc(); |
|
1773 |
||
1774 |
bool inc_counter = UseCompiler || CountCompiledCalls || LogTouchedMethods; |
|
1775 |
||
1776 |
// Interpreter entry for ordinary Java methods. |
|
1777 |
// |
|
1778 |
// Registers alive |
|
1779 |
// Z_SP - stack pointer |
|
1780 |
// Z_thread - JavaThread* |
|
1781 |
// Z_method - callee's method (method to be invoked) |
|
1782 |
// Z_esp - operand (or expression) stack pointer of caller. one slot above last arg. |
|
1783 |
// Z_R10 - sender sp (before modifications, e.g. by c2i adapter |
|
1784 |
// and as well by generate_fixed_frame below) |
|
1785 |
// Z_R14 - return address to caller (call_stub or c2i_adapter) |
|
1786 |
// |
|
1787 |
// Registers updated |
|
1788 |
// Z_SP - stack pointer |
|
1789 |
// Z_fp - callee's framepointer |
|
1790 |
// Z_esp - callee's operand stack pointer |
|
1791 |
// points to the slot above the value on top |
|
1792 |
// Z_locals - used to access locals: locals[i] := *(Z_locals - i*BytesPerWord) |
|
1793 |
// Z_tos - integer result, if any |
|
1794 |
// z_ftos - floating point result, if any |
|
1795 |
// |
|
1796 |
// |
|
1797 |
// stack layout at this point: |
|
1798 |
// |
|
1799 |
// F1 [TOP_IJAVA_FRAME_ABI] <-- Z_SP, Z_R10 (Z_R10 will be below Z_SP if |
|
1800 |
// frame was extended by c2i adapter) |
|
1801 |
// [outgoing Java arguments] <-- Z_esp |
|
1802 |
// ... |
|
1803 |
// PARENT [PARENT_IJAVA_FRAME_ABI] |
|
1804 |
// ... |
|
1805 |
// |
|
1806 |
// stack layout before dispatching the first bytecode: |
|
1807 |
// |
|
1808 |
// F0 [TOP_IJAVA_FRAME_ABI] <-- Z_SP |
|
1809 |
// [operand stack] <-- Z_esp |
|
1810 |
// monitor (optional, can grow) |
|
1811 |
// [IJAVA_STATE] |
|
1812 |
// F1 [PARENT_IJAVA_FRAME_ABI] <-- Z_fp (== *Z_SP) |
|
1813 |
// [F0's locals] <-- Z_locals |
|
1814 |
// [F1's operand stack] |
|
1815 |
// [F1's monitors] (optional) |
|
1816 |
// [IJAVA_STATE] |
|
1817 |
||
1818 |
// Make sure registers are different! |
|
1819 |
assert_different_registers(Z_thread, Z_method, Z_esp); |
|
1820 |
||
1821 |
BLOCK_COMMENT("normal_entry {"); |
|
1822 |
||
1823 |
// Make sure method is not native and not abstract. |
|
1824 |
// Rethink these assertions - they can be simplified and shared. |
|
1825 |
#ifdef ASSERT |
|
1826 |
address reentry = NULL; |
|
1827 |
{ Label L; |
|
1828 |
__ testbit(method_(access_flags), JVM_ACC_NATIVE_BIT); |
|
1829 |
__ z_bfalse(L); |
|
1830 |
reentry = __ stop_chain_static(reentry, "tried to execute native method as non-native"); |
|
1831 |
__ bind(L); |
|
1832 |
} |
|
1833 |
{ Label L; |
|
1834 |
__ testbit(method_(access_flags), JVM_ACC_ABSTRACT_BIT); |
|
1835 |
__ z_bfalse(L); |
|
1836 |
reentry = __ stop_chain_static(reentry, "tried to execute abstract method as non-abstract"); |
|
1837 |
__ bind(L); |
|
1838 |
} |
|
1839 |
#endif // ASSERT |
|
1840 |
||
1841 |
#ifdef ASSERT |
|
1842 |
// Save the return PC into the callers frame for assertion in generate_fixed_frame. |
|
1843 |
__ save_return_pc(Z_R14); |
|
1844 |
#endif |
|
1845 |
||
1846 |
// Generate the code to allocate the interpreter stack frame. |
|
1847 |
generate_fixed_frame(false); |
|
1848 |
||
1849 |
const Address do_not_unlock_if_synchronized(Z_thread, JavaThread::do_not_unlock_if_synchronized_offset()); |
|
1850 |
// Since at this point in the method invocation the exception handler |
|
1851 |
// would try to exit the monitor of synchronized methods which hasn't |
|
1852 |
// been entered yet, we set the thread local variable |
|
1853 |
// _do_not_unlock_if_synchronized to true. If any exception was thrown by |
|
1854 |
// runtime, exception handling i.e. unlock_if_synchronized_method will |
|
1855 |
// check this thread local flag. |
|
1856 |
__ z_mvi(do_not_unlock_if_synchronized, true); |
|
1857 |
||
1858 |
__ profile_parameters_type(Z_tmp_2, Z_ARG3, Z_ARG4); |
|
1859 |
||
1860 |
// Increment invocation counter and check for overflow. |
|
1861 |
// |
|
1862 |
// Note: checking for negative value instead of overflow so we have a 'sticky' |
|
1863 |
// overflow test (may be of importance as soon as we have true MT/MP). |
|
1864 |
NearLabel invocation_counter_overflow; |
|
1865 |
NearLabel profile_method; |
|
1866 |
NearLabel profile_method_continue; |
|
1867 |
NearLabel Lcontinue; |
|
1868 |
if (inc_counter) { |
|
1869 |
generate_counter_incr(&invocation_counter_overflow, &profile_method, &profile_method_continue); |
|
1870 |
if (ProfileInterpreter) { |
|
1871 |
__ bind(profile_method_continue); |
|
1872 |
} |
|
1873 |
} |
|
1874 |
__ bind(Lcontinue); |
|
1875 |
||
1876 |
bang_stack_shadow_pages(false); |
|
1877 |
||
1878 |
// Reset the _do_not_unlock_if_synchronized flag. |
|
1879 |
__ z_mvi(do_not_unlock_if_synchronized, false); |
|
1880 |
||
1881 |
// Check for synchronized methods. |
|
1882 |
// Must happen AFTER invocation_counter check and stack overflow check, |
|
1883 |
// so method is not locked if overflows. |
|
1884 |
if (synchronized) { |
|
1885 |
// Allocate monitor and lock method. |
|
1886 |
lock_method(); |
|
1887 |
} else { |
|
1888 |
#ifdef ASSERT |
|
1889 |
{ Label L; |
|
1890 |
__ get_method(Z_R1_scratch); |
|
1891 |
__ testbit(method2_(Z_R1_scratch, access_flags), JVM_ACC_SYNCHRONIZED_BIT); |
|
1892 |
__ z_bfalse(L); |
|
1893 |
reentry = __ stop_chain_static(reentry, "method needs synchronization"); |
|
1894 |
__ bind(L); |
|
1895 |
} |
|
1896 |
#endif // ASSERT |
|
1897 |
} |
|
1898 |
||
1899 |
// start execution |
|
1900 |
||
1901 |
#ifdef ASSERT |
|
1902 |
__ verify_esp(Z_esp, Z_R1_scratch); |
|
1903 |
||
1904 |
__ verify_thread(); |
|
1905 |
#endif |
|
1906 |
||
1907 |
// jvmti support |
|
1908 |
__ notify_method_entry(); |
|
1909 |
||
1910 |
// Start executing instructions. |
|
1911 |
__ dispatch_next(vtos); |
|
1912 |
// Dispatch_next does not return. |
|
1913 |
DEBUG_ONLY(__ should_not_reach_here()); |
|
1914 |
||
1915 |
// Invocation counter overflow. |
|
1916 |
if (inc_counter) { |
|
1917 |
if (ProfileInterpreter) { |
|
1918 |
// We have decided to profile this method in the interpreter. |
|
1919 |
__ bind(profile_method); |
|
1920 |
||
1921 |
__ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::profile_method)); |
|
1922 |
__ set_method_data_pointer_for_bcp(); |
|
1923 |
__ z_bru(profile_method_continue); |
|
1924 |
} |
|
1925 |
||
1926 |
// Handle invocation counter overflow. |
|
1927 |
__ bind(invocation_counter_overflow); |
|
1928 |
generate_counter_overflow(Lcontinue); |
|
1929 |
} |
|
1930 |
||
1931 |
BLOCK_COMMENT("} normal_entry"); |
|
1932 |
||
1933 |
return entry_point; |
|
1934 |
} |
|
1935 |
||
1936 |
// Method entry for static native methods: |
|
1937 |
// int java.util.zip.CRC32.update(int crc, int b) |
|
1938 |
address TemplateInterpreterGenerator::generate_CRC32_update_entry() { |
|
1939 |
||
1940 |
if (UseCRC32Intrinsics) { |
|
1941 |
uint64_t entry_off = __ offset(); |
|
1942 |
Label slow_path; |
|
1943 |
||
1944 |
// If we need a safepoint check, generate full interpreter entry. |
|
1945 |
__ generate_safepoint_check(slow_path, Z_R1, false); |
|
1946 |
||
1947 |
BLOCK_COMMENT("CRC32_update {"); |
|
1948 |
||
1949 |
// We don't generate local frame and don't align stack because |
|
1950 |
// we not even call stub code (we generate the code inline) |
|
1951 |
// and there is no safepoint on this path. |
|
1952 |
||
1953 |
// Load java parameters. |
|
1954 |
// Z_esp is callers operand stack pointer, i.e. it points to the parameters. |
|
1955 |
const Register argP = Z_esp; |
|
1956 |
const Register crc = Z_ARG1; // crc value |
|
1957 |
const Register data = Z_ARG2; // address of java byte value (kernel_crc32 needs address) |
|
1958 |
const Register dataLen = Z_ARG3; // source data len (1 byte). Not used because calling the single-byte emitter. |
|
1959 |
const Register table = Z_ARG4; // address of crc32 table |
|
1960 |
||
1961 |
// Arguments are reversed on java expression stack. |
|
1962 |
__ z_la(data, 3+1*wordSize, argP); // byte value (stack address). |
|
1963 |
// Being passed as an int, the single byte is at offset +3. |
|
1964 |
__ z_llgf(crc, 2 * wordSize, argP); // Current crc state, zero extend to 64 bit to have a clean register. |
|
1965 |
||
1966 |
StubRoutines::zarch::generate_load_crc_table_addr(_masm, table); |
|
1967 |
__ kernel_crc32_singleByte(crc, data, dataLen, table, Z_R1); |
|
1968 |
||
1969 |
// Restore caller sp for c2i case. |
|
1970 |
__ resize_frame_absolute(Z_R10, Z_R0, true); // Cut the stack back to where the caller started. |
|
1971 |
||
1972 |
__ z_br(Z_R14); |
|
1973 |
||
1974 |
BLOCK_COMMENT("} CRC32_update"); |
|
1975 |
||
1976 |
// Use a previously generated vanilla native entry as the slow path. |
|
1977 |
BIND(slow_path); |
|
1978 |
__ jump_to_entry(Interpreter::entry_for_kind(Interpreter::native), Z_R1); |
|
1979 |
return __ addr_at(entry_off); |
|
1980 |
} |
|
1981 |
||
1982 |
return NULL; |
|
1983 |
} |
|
1984 |
||
1985 |
||
1986 |
// Method entry for static native methods: |
|
1987 |
// int java.util.zip.CRC32.updateBytes(int crc, byte[] b, int off, int len) |
|
1988 |
// int java.util.zip.CRC32.updateByteBuffer(int crc, long buf, int off, int len) |
|
1989 |
address TemplateInterpreterGenerator::generate_CRC32_updateBytes_entry(AbstractInterpreter::MethodKind kind) { |
|
1990 |
||
1991 |
if (UseCRC32Intrinsics) { |
|
1992 |
uint64_t entry_off = __ offset(); |
|
1993 |
Label slow_path; |
|
1994 |
||
1995 |
// If we need a safepoint check, generate full interpreter entry. |
|
1996 |
__ generate_safepoint_check(slow_path, Z_R1, false); |
|
1997 |
||
1998 |
// We don't generate local frame and don't align stack because |
|
1999 |
// we call stub code and there is no safepoint on this path. |
|
2000 |
||
2001 |
// Load parameters. |
|
2002 |
// Z_esp is callers operand stack pointer, i.e. it points to the parameters. |
|
2003 |
const Register argP = Z_esp; |
|
2004 |
const Register crc = Z_ARG1; // crc value |
|
2005 |
const Register data = Z_ARG2; // address of java byte array |
|
2006 |
const Register dataLen = Z_ARG3; // source data len |
|
2007 |
const Register table = Z_ARG4; // address of crc32 table |
|
2008 |
const Register t0 = Z_R10; // work reg for kernel* emitters |
|
2009 |
const Register t1 = Z_R11; // work reg for kernel* emitters |
|
2010 |
const Register t2 = Z_R12; // work reg for kernel* emitters |
|
2011 |
const Register t3 = Z_R13; // work reg for kernel* emitters |
|
2012 |
||
2013 |
// Arguments are reversed on java expression stack. |
|
2014 |
// Calculate address of start element. |
|
2015 |
if (kind == Interpreter::java_util_zip_CRC32_updateByteBuffer) { // Used for "updateByteBuffer direct". |
|
2016 |
// crc @ (SP + 5W) (32bit) |
|
2017 |
// buf @ (SP + 3W) (64bit ptr to long array) |
|
2018 |
// off @ (SP + 2W) (32bit) |
|
2019 |
// dataLen @ (SP + 1W) (32bit) |
|
2020 |
// data = buf + off |
|
2021 |
BLOCK_COMMENT("CRC32_updateByteBuffer {"); |
|
2022 |
__ z_llgf(crc, 5*wordSize, argP); // current crc state |
|
2023 |
__ z_lg(data, 3*wordSize, argP); // start of byte buffer |
|
2024 |
__ z_agf(data, 2*wordSize, argP); // Add byte buffer offset. |
|
2025 |
__ z_lgf(dataLen, 1*wordSize, argP); // #bytes to process |
|
2026 |
} else { // Used for "updateBytes update". |
|
2027 |
// crc @ (SP + 4W) (32bit) |
|
2028 |
// buf @ (SP + 3W) (64bit ptr to byte array) |
|
2029 |
// off @ (SP + 2W) (32bit) |
|
2030 |
// dataLen @ (SP + 1W) (32bit) |
|
2031 |
// data = buf + off + base_offset |
|
2032 |
BLOCK_COMMENT("CRC32_updateBytes {"); |
|
2033 |
__ z_llgf(crc, 4*wordSize, argP); // current crc state |
|
2034 |
__ z_lg(data, 3*wordSize, argP); // start of byte buffer |
|
2035 |
__ z_agf(data, 2*wordSize, argP); // Add byte buffer offset. |
|
2036 |
__ z_lgf(dataLen, 1*wordSize, argP); // #bytes to process |
|
2037 |
__ z_aghi(data, arrayOopDesc::base_offset_in_bytes(T_BYTE)); |
|
2038 |
} |
|
2039 |
||
2040 |
StubRoutines::zarch::generate_load_crc_table_addr(_masm, table); |
|
2041 |
||
2042 |
__ resize_frame(-(6*8), Z_R0, true); // Resize frame to provide add'l space to spill 5 registers. |
|
2043 |
__ z_stmg(t0, t3, 1*8, Z_SP); // Spill regs 10..13 to make them available as work registers. |
|
2044 |
__ kernel_crc32_1word(crc, data, dataLen, table, t0, t1, t2, t3); |
|
2045 |
__ z_lmg(t0, t3, 1*8, Z_SP); // Spill regs 10..13 back from stack. |
|
2046 |
||
2047 |
// Restore caller sp for c2i case. |
|
2048 |
__ resize_frame_absolute(Z_R10, Z_R0, true); // Cut the stack back to where the caller started. |
|
2049 |
||
2050 |
__ z_br(Z_R14); |
|
2051 |
||
2052 |
BLOCK_COMMENT("} CRC32_update{Bytes|ByteBuffer}"); |
|
2053 |
||
2054 |
// Use a previously generated vanilla native entry as the slow path. |
|
2055 |
BIND(slow_path); |
|
2056 |
__ jump_to_entry(Interpreter::entry_for_kind(Interpreter::native), Z_R1); |
|
2057 |
return __ addr_at(entry_off); |
|
2058 |
} |
|
2059 |
||
2060 |
return NULL; |
|
2061 |
} |
|
2062 |
||
2063 |
// Not supported |
|
2064 |
address TemplateInterpreterGenerator::generate_CRC32C_updateBytes_entry(AbstractInterpreter::MethodKind kind) { |
|
2065 |
return NULL; |
|
2066 |
} |
|
2067 |
||
2068 |
void TemplateInterpreterGenerator::bang_stack_shadow_pages(bool native_call) { |
|
2069 |
// Quick & dirty stack overflow checking: bang the stack & handle trap. |
|
2070 |
// Note that we do the banging after the frame is setup, since the exception |
|
2071 |
// handling code expects to find a valid interpreter frame on the stack. |
|
2072 |
// Doing the banging earlier fails if the caller frame is not an interpreter |
|
2073 |
// frame. |
|
2074 |
// (Also, the exception throwing code expects to unlock any synchronized |
|
2075 |
// method receiver, so do the banging after locking the receiver.) |
|
2076 |
||
2077 |
// Bang each page in the shadow zone. We can't assume it's been done for |
|
2078 |
// an interpreter frame with greater than a page of locals, so each page |
|
2079 |
// needs to be checked. Only true for non-native. For native, we only bang the last page. |
|
2080 |
if (UseStackBanging) { |
|
2081 |
const int page_size = os::vm_page_size(); |
|
2082 |
const int n_shadow_pages = (int)(JavaThread::stack_shadow_zone_size()/page_size); |
|
2083 |
const int start_page_num = native_call ? n_shadow_pages : 1; |
|
2084 |
for (int pages = start_page_num; pages <= n_shadow_pages; pages++) { |
|
2085 |
__ bang_stack_with_offset(pages*page_size); |
|
2086 |
} |
|
2087 |
} |
|
2088 |
} |
|
2089 |
||
2090 |
//----------------------------------------------------------------------------- |
|
2091 |
// Exceptions |
|
2092 |
||
2093 |
void TemplateInterpreterGenerator::generate_throw_exception() { |
|
2094 |
||
2095 |
BLOCK_COMMENT("throw_exception {"); |
|
2096 |
||
2097 |
// Entry point in previous activation (i.e., if the caller was interpreted). |
|
2098 |
Interpreter::_rethrow_exception_entry = __ pc(); |
|
2099 |
__ z_lg(Z_fp, _z_abi(callers_sp), Z_SP); // Frame accessors use Z_fp. |
|
2100 |
// Z_ARG1 (==Z_tos): exception |
|
2101 |
// Z_ARG2 : Return address/pc that threw exception. |
|
2102 |
__ restore_bcp(); // R13 points to call/send. |
|
2103 |
__ restore_locals(); |
|
2104 |
||
2105 |
// Fallthrough, no need to restore Z_esp. |
|
2106 |
||
2107 |
// Entry point for exceptions thrown within interpreter code. |
|
2108 |
Interpreter::_throw_exception_entry = __ pc(); |
|
2109 |
// Expression stack is undefined here. |
|
2110 |
// Z_ARG1 (==Z_tos): exception |
|
2111 |
// Z_bcp: exception bcp |
|
2112 |
__ verify_oop(Z_ARG1); |
|
2113 |
__ z_lgr(Z_ARG2, Z_ARG1); |
|
2114 |
||
2115 |
// Expression stack must be empty before entering the VM in case of |
|
2116 |
// an exception. |
|
2117 |
__ empty_expression_stack(); |
|
2118 |
// Find exception handler address and preserve exception oop. |
|
2119 |
const Register Rpreserved_exc_oop = Z_tmp_1; |
|
2120 |
__ call_VM(Rpreserved_exc_oop, |
|
2121 |
CAST_FROM_FN_PTR(address, InterpreterRuntime::exception_handler_for_exception), |
|
2122 |
Z_ARG2); |
|
2123 |
// Z_RET: exception handler entry point |
|
2124 |
// Z_bcp: bcp for exception handler |
|
2125 |
__ push_ptr(Rpreserved_exc_oop); // Push exception which is now the only value on the stack. |
|
2126 |
__ z_br(Z_RET); // Jump to exception handler (may be _remove_activation_entry!). |
|
2127 |
||
2128 |
// If the exception is not handled in the current frame the frame is |
|
2129 |
// removed and the exception is rethrown (i.e. exception |
|
2130 |
// continuation is _rethrow_exception). |
|
2131 |
// |
|
2132 |
// Note: At this point the bci is still the bci for the instruction |
|
2133 |
// which caused the exception and the expression stack is |
|
2134 |
// empty. Thus, for any VM calls at this point, GC will find a legal |
|
2135 |
// oop map (with empty expression stack). |
|
2136 |
||
2137 |
// |
|
2138 |
// JVMTI PopFrame support |
|
2139 |
// |
|
2140 |
||
2141 |
Interpreter::_remove_activation_preserving_args_entry = __ pc(); |
|
2142 |
__ z_lg(Z_fp, _z_parent_ijava_frame_abi(callers_sp), Z_SP); |
|
2143 |
__ empty_expression_stack(); |
|
2144 |
// Set the popframe_processing bit in pending_popframe_condition |
|
2145 |
// indicating that we are currently handling popframe, so that |
|
2146 |
// call_VMs that may happen later do not trigger new popframe |
|
2147 |
// handling cycles. |
|
2148 |
__ load_sized_value(Z_tmp_1, Address(Z_thread, JavaThread::popframe_condition_offset()), 4, false /*signed*/); |
|
2149 |
__ z_oill(Z_tmp_1, JavaThread::popframe_processing_bit); |
|
2150 |
__ z_sty(Z_tmp_1, thread_(popframe_condition)); |
|
2151 |
||
2152 |
{ |
|
2153 |
// Check to see whether we are returning to a deoptimized frame. |
|
2154 |
// (The PopFrame call ensures that the caller of the popped frame is |
|
2155 |
// either interpreted or compiled and deoptimizes it if compiled.) |
|
2156 |
// In this case, we can't call dispatch_next() after the frame is |
|
2157 |
// popped, but instead must save the incoming arguments and restore |
|
2158 |
// them after deoptimization has occurred. |
|
2159 |
// |
|
2160 |
// Note that we don't compare the return PC against the |
|
2161 |
// deoptimization blob's unpack entry because of the presence of |
|
2162 |
// adapter frames in C2. |
|
2163 |
NearLabel caller_not_deoptimized; |
|
2164 |
__ z_lg(Z_ARG1, _z_parent_ijava_frame_abi(return_pc), Z_fp); |
|
2165 |
__ call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::interpreter_contains), Z_ARG1); |
|
2166 |
__ compareU64_and_branch(Z_RET, (intptr_t)0, Assembler::bcondNotEqual, caller_not_deoptimized); |
|
2167 |
||
2168 |
// Compute size of arguments for saving when returning to |
|
2169 |
// deoptimized caller. |
|
2170 |
__ get_method(Z_ARG2); |
|
2171 |
__ z_lg(Z_ARG2, Address(Z_ARG2, Method::const_offset())); |
|
2172 |
__ z_llgh(Z_ARG2, Address(Z_ARG2, ConstMethod::size_of_parameters_offset())); |
|
2173 |
__ z_sllg(Z_ARG2, Z_ARG2, Interpreter::logStackElementSize); // slots 2 bytes |
|
2174 |
__ restore_locals(); |
|
2175 |
// Compute address of args to be saved. |
|
2176 |
__ z_lgr(Z_ARG3, Z_locals); |
|
2177 |
__ z_slgr(Z_ARG3, Z_ARG2); |
|
2178 |
__ add2reg(Z_ARG3, wordSize); |
|
2179 |
// Save these arguments. |
|
2180 |
__ call_VM_leaf(CAST_FROM_FN_PTR(address, Deoptimization::popframe_preserve_args), |
|
2181 |
Z_thread, Z_ARG2, Z_ARG3); |
|
2182 |
||
2183 |
__ remove_activation(vtos, Z_R14, |
|
2184 |
/* throw_monitor_exception */ false, |
|
2185 |
/* install_monitor_exception */ false, |
|
2186 |
/* notify_jvmdi */ false); |
|
2187 |
||
2188 |
// Inform deoptimization that it is responsible for restoring |
|
2189 |
// these arguments. |
|
2190 |
__ store_const(thread_(popframe_condition), |
|
2191 |
JavaThread::popframe_force_deopt_reexecution_bit, |
|
2192 |
Z_tmp_1, false); |
|
2193 |
||
2194 |
// Continue in deoptimization handler. |
|
2195 |
__ z_br(Z_R14); |
|
2196 |
||
2197 |
__ bind(caller_not_deoptimized); |
|
2198 |
} |
|
2199 |
||
2200 |
// Clear the popframe condition flag. |
|
2201 |
__ clear_mem(thread_(popframe_condition), sizeof(int)); |
|
2202 |
||
2203 |
__ remove_activation(vtos, |
|
2204 |
noreg, // Retaddr is not used. |
|
2205 |
false, // throw_monitor_exception |
|
2206 |
false, // install_monitor_exception |
|
2207 |
false); // notify_jvmdi |
|
2208 |
__ z_lg(Z_fp, _z_abi(callers_sp), Z_SP); // Restore frame pointer. |
|
2209 |
__ restore_bcp(); |
|
2210 |
__ restore_locals(); |
|
2211 |
__ restore_esp(); |
|
2212 |
// The method data pointer was incremented already during |
|
2213 |
// call profiling. We have to restore the mdp for the current bcp. |
|
2214 |
if (ProfileInterpreter) { |
|
2215 |
__ set_method_data_pointer_for_bcp(); |
|
2216 |
} |
|
2217 |
#if INCLUDE_JVMTI |
|
2218 |
{ |
|
2219 |
Label L_done; |
|
2220 |
||
2221 |
__ z_cli(0, Z_bcp, Bytecodes::_invokestatic); |
|
2222 |
__ z_brc(Assembler::bcondNotEqual, L_done); |
|
2223 |
||
2224 |
// The member name argument must be restored if _invokestatic is |
|
2225 |
// re-executed after a PopFrame call. Detect such a case in the |
|
2226 |
// InterpreterRuntime function and return the member name |
|
2227 |
// argument, or NULL. |
|
2228 |
__ z_lg(Z_ARG2, Address(Z_locals)); |
|
2229 |
__ get_method(Z_ARG3); |
|
2230 |
__ call_VM(Z_tmp_1, |
|
2231 |
CAST_FROM_FN_PTR(address, InterpreterRuntime::member_name_arg_or_null), |
|
2232 |
Z_ARG2, Z_ARG3, Z_bcp); |
|
2233 |
||
2234 |
__ z_ltgr(Z_tmp_1, Z_tmp_1); |
|
2235 |
__ z_brc(Assembler::bcondEqual, L_done); |
|
2236 |
||
2237 |
__ z_stg(Z_tmp_1, Address(Z_esp, wordSize)); |
|
2238 |
__ bind(L_done); |
|
2239 |
} |
|
2240 |
#endif // INCLUDE_JVMTI |
|
2241 |
__ dispatch_next(vtos); |
|
2242 |
// End of PopFrame support. |
|
2243 |
Interpreter::_remove_activation_entry = __ pc(); |
|
2244 |
||
2245 |
// In between activations - previous activation type unknown yet |
|
2246 |
// compute continuation point - the continuation point expects the |
|
2247 |
// following registers set up: |
|
2248 |
// |
|
2249 |
// Z_ARG1 (==Z_tos): exception |
|
2250 |
// Z_ARG2 : return address/pc that threw exception |
|
2251 |
||
2252 |
Register return_pc = Z_tmp_1; |
|
2253 |
Register handler = Z_tmp_2; |
|
2254 |
assert(return_pc->is_nonvolatile(), "use non-volatile reg. to preserve exception pc"); |
|
2255 |
assert(handler->is_nonvolatile(), "use non-volatile reg. to handler pc"); |
|
2256 |
__ asm_assert_ijava_state_magic(return_pc/*tmp*/); // The top frame should be an interpreter frame. |
|
2257 |
__ z_lg(return_pc, _z_parent_ijava_frame_abi(return_pc), Z_fp); |
|
2258 |
||
2259 |
// Moved removing the activation after VM call, because the new top |
|
2260 |
// frame does not necessarily have the z_abi_160 required for a VM |
|
2261 |
// call (e.g. if it is compiled). |
|
2262 |
||
2263 |
__ super_call_VM_leaf(CAST_FROM_FN_PTR(address, |
|
2264 |
SharedRuntime::exception_handler_for_return_address), |
|
2265 |
Z_thread, return_pc); |
|
2266 |
__ z_lgr(handler, Z_RET); // Save exception handler. |
|
2267 |
||
2268 |
// Preserve exception over this code sequence. |
|
2269 |
__ pop_ptr(Z_ARG1); |
|
2270 |
__ set_vm_result(Z_ARG1); |
|
2271 |
// Remove the activation (without doing throws on illegalMonitorExceptions). |
|
2272 |
__ remove_activation(vtos, noreg/*ret.pc already loaded*/, false/*throw exc*/, true/*install exc*/, false/*notify jvmti*/); |
|
2273 |
__ z_lg(Z_fp, _z_abi(callers_sp), Z_SP); // Restore frame pointer. |
|
2274 |
||
2275 |
__ get_vm_result(Z_ARG1); // Restore exception. |
|
2276 |
__ verify_oop(Z_ARG1); |
|
2277 |
__ z_lgr(Z_ARG2, return_pc); // Restore return address. |
|
2278 |
||
2279 |
#ifdef ASSERT |
|
2280 |
// The return_pc in the new top frame is dead... at least that's my |
|
2281 |
// current understanding. To assert this I overwrite it. |
|
2282 |
// Note: for compiled frames the handler is the deopt blob |
|
2283 |
// which writes Z_ARG2 into the return_pc slot. |
|
2284 |
__ load_const_optimized(return_pc, 0xb00b1); |
|
2285 |
__ z_stg(return_pc, _z_parent_ijava_frame_abi(return_pc), Z_SP); |
|
2286 |
#endif |
|
2287 |
||
2288 |
// Z_ARG1 (==Z_tos): exception |
|
2289 |
// Z_ARG2 : return address/pc that threw exception |
|
2290 |
||
2291 |
// Note that an "issuing PC" is actually the next PC after the call. |
|
2292 |
__ z_br(handler); // Jump to exception handler of caller. |
|
2293 |
||
2294 |
BLOCK_COMMENT("} throw_exception"); |
|
2295 |
} |
|
2296 |
||
2297 |
// |
|
2298 |
// JVMTI ForceEarlyReturn support |
|
2299 |
// |
|
2300 |
address TemplateInterpreterGenerator::generate_earlyret_entry_for (TosState state) { |
|
2301 |
address entry = __ pc(); |
|
2302 |
||
2303 |
BLOCK_COMMENT("earlyret_entry {"); |
|
2304 |
||
2305 |
__ z_lg(Z_fp, _z_parent_ijava_frame_abi(callers_sp), Z_SP); |
|
2306 |
__ restore_bcp(); |
|
2307 |
__ restore_locals(); |
|
2308 |
__ restore_esp(); |
|
2309 |
__ empty_expression_stack(); |
|
2310 |
__ load_earlyret_value(state); |
|
2311 |
||
2312 |
Register RjvmtiState = Z_tmp_1; |
|
2313 |
__ z_lg(RjvmtiState, thread_(jvmti_thread_state)); |
|
2314 |
__ store_const(Address(RjvmtiState, JvmtiThreadState::earlyret_state_offset()), |
|
2315 |
JvmtiThreadState::earlyret_inactive, 4, 4, Z_R0_scratch); |
|
2316 |
||
2317 |
__ remove_activation(state, |
|
2318 |
Z_tmp_1, // retaddr |
|
2319 |
false, // throw_monitor_exception |
|
2320 |
false, // install_monitor_exception |
|
2321 |
true); // notify_jvmdi |
|
2322 |
__ z_br(Z_tmp_1); |
|
2323 |
||
2324 |
BLOCK_COMMENT("} earlyret_entry"); |
|
2325 |
||
2326 |
return entry; |
|
2327 |
} |
|
2328 |
||
2329 |
//----------------------------------------------------------------------------- |
|
2330 |
// Helper for vtos entry point generation. |
|
2331 |
||
2332 |
void TemplateInterpreterGenerator::set_vtos_entry_points(Template* t, |
|
2333 |
address& bep, |
|
2334 |
address& cep, |
|
2335 |
address& sep, |
|
2336 |
address& aep, |
|
2337 |
address& iep, |
|
2338 |
address& lep, |
|
2339 |
address& fep, |
|
2340 |
address& dep, |
|
2341 |
address& vep) { |
|
2342 |
assert(t->is_valid() && t->tos_in() == vtos, "illegal template"); |
|
2343 |
Label L; |
|
2344 |
aep = __ pc(); __ push_ptr(); __ z_bru(L); |
|
2345 |
fep = __ pc(); __ push_f(); __ z_bru(L); |
|
2346 |
dep = __ pc(); __ push_d(); __ z_bru(L); |
|
2347 |
lep = __ pc(); __ push_l(); __ z_bru(L); |
|
2348 |
bep = cep = sep = |
|
2349 |
iep = __ pc(); __ push_i(); |
|
2350 |
vep = __ pc(); |
|
2351 |
__ bind(L); |
|
2352 |
generate_and_dispatch(t); |
|
2353 |
} |
|
2354 |
||
2355 |
//----------------------------------------------------------------------------- |
|
2356 |
||
2357 |
#ifndef PRODUCT |
|
2358 |
address TemplateInterpreterGenerator::generate_trace_code(TosState state) { |
|
2359 |
address entry = __ pc(); |
|
2360 |
NearLabel counter_below_trace_threshold; |
|
2361 |
||
2362 |
if (TraceBytecodesAt > 0) { |
|
2363 |
// Skip runtime call, if the trace threshold is not yet reached. |
|
2364 |
__ load_absolute_address(Z_tmp_1, (address)&BytecodeCounter::_counter_value); |
|
2365 |
__ load_absolute_address(Z_tmp_2, (address)&TraceBytecodesAt); |
|
2366 |
__ load_sized_value(Z_tmp_1, Address(Z_tmp_1), 4, false /*signed*/); |
|
2367 |
__ load_sized_value(Z_tmp_2, Address(Z_tmp_2), 8, false /*signed*/); |
|
2368 |
__ compareU64_and_branch(Z_tmp_1, Z_tmp_2, Assembler::bcondLow, counter_below_trace_threshold); |
|
2369 |
} |
|
2370 |
||
2371 |
int offset2 = state == ltos || state == dtos ? 2 : 1; |
|
2372 |
||
2373 |
__ push(state); |
|
2374 |
// Preserved return pointer is in Z_R14. |
|
2375 |
// InterpreterRuntime::trace_bytecode() preserved and returns the value passed as second argument. |
|
2376 |
__ z_lgr(Z_ARG2, Z_R14); |
|
2377 |
__ z_lg(Z_ARG3, Address(Z_esp, Interpreter::expr_offset_in_bytes(0))); |
|
2378 |
if (WizardMode) { |
|
2379 |
__ z_lgr(Z_ARG4, Z_esp); // Trace Z_esp in WizardMode. |
|
2380 |
} else { |
|
2381 |
__ z_lg(Z_ARG4, Address(Z_esp, Interpreter::expr_offset_in_bytes(offset2))); |
|
2382 |
} |
|
2383 |
__ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::trace_bytecode), Z_ARG2, Z_ARG3, Z_ARG4); |
|
2384 |
__ z_lgr(Z_R14, Z_RET); // Estore return address (see above). |
|
2385 |
__ pop(state); |
|
2386 |
||
2387 |
__ bind(counter_below_trace_threshold); |
|
2388 |
__ z_br(Z_R14); // return |
|
2389 |
||
2390 |
return entry; |
|
2391 |
} |
|
2392 |
||
2393 |
// Make feasible for old CPUs. |
|
2394 |
void TemplateInterpreterGenerator::count_bytecode() { |
|
2395 |
__ load_absolute_address(Z_R1_scratch, (address) &BytecodeCounter::_counter_value); |
|
2396 |
__ add2mem_32(Address(Z_R1_scratch), 1, Z_R0_scratch); |
|
2397 |
} |
|
2398 |
||
2399 |
void TemplateInterpreterGenerator::histogram_bytecode(Template * t) { |
|
2400 |
__ load_absolute_address(Z_R1_scratch, (address)&BytecodeHistogram::_counters[ t->bytecode() ]); |
|
2401 |
__ add2mem_32(Address(Z_R1_scratch), 1, Z_tmp_1); |
|
2402 |
} |
|
2403 |
||
2404 |
void TemplateInterpreterGenerator::histogram_bytecode_pair(Template * t) { |
|
2405 |
Address index_addr(Z_tmp_1, (intptr_t) 0); |
|
2406 |
Register index = Z_tmp_2; |
|
2407 |
||
2408 |
// Load previous index. |
|
2409 |
__ load_absolute_address(Z_tmp_1, (address) &BytecodePairHistogram::_index); |
|
2410 |
__ mem2reg_opt(index, index_addr, false); |
|
2411 |
||
2412 |
// Mask with current bytecode and store as new previous index. |
|
2413 |
__ z_srl(index, BytecodePairHistogram::log2_number_of_codes); |
|
2414 |
__ load_const_optimized(Z_R0_scratch, |
|
2415 |
(int)t->bytecode() << BytecodePairHistogram::log2_number_of_codes); |
|
2416 |
__ z_or(index, Z_R0_scratch); |
|
2417 |
__ reg2mem_opt(index, index_addr, false); |
|
2418 |
||
2419 |
// Load counter array's address. |
|
2420 |
__ z_lgfr(index, index); // Sign extend for addressing. |
|
2421 |
__ z_sllg(index, index, LogBytesPerInt); // index2bytes |
|
2422 |
__ load_absolute_address(Z_R1_scratch, |
|
2423 |
(address) &BytecodePairHistogram::_counters); |
|
2424 |
// Add index and increment counter. |
|
2425 |
__ z_agr(Z_R1_scratch, index); |
|
2426 |
__ add2mem_32(Address(Z_R1_scratch), 1, Z_tmp_1); |
|
2427 |
} |
|
2428 |
||
2429 |
void TemplateInterpreterGenerator::trace_bytecode(Template* t) { |
|
2430 |
// Call a little run-time stub to avoid blow-up for each bytecode. |
|
2431 |
// The run-time runtime saves the right registers, depending on |
|
2432 |
// the tosca in-state for the given template. |
|
2433 |
address entry = Interpreter::trace_code(t->tos_in()); |
|
2434 |
guarantee(entry != NULL, "entry must have been generated"); |
|
2435 |
__ call_stub(entry); |
|
2436 |
} |
|
2437 |
||
2438 |
void TemplateInterpreterGenerator::stop_interpreter_at() { |
|
2439 |
NearLabel L; |
|
2440 |
||
2441 |
__ load_absolute_address(Z_tmp_1, (address)&BytecodeCounter::_counter_value); |
|
2442 |
__ load_absolute_address(Z_tmp_2, (address)&StopInterpreterAt); |
|
2443 |
__ load_sized_value(Z_tmp_1, Address(Z_tmp_1), 4, false /*signed*/); |
|
2444 |
__ load_sized_value(Z_tmp_2, Address(Z_tmp_2), 8, false /*signed*/); |
|
2445 |
__ compareU64_and_branch(Z_tmp_1, Z_tmp_2, Assembler::bcondLow, L); |
|
2446 |
assert(Z_tmp_1->is_nonvolatile(), "must be nonvolatile to preserve Z_tos"); |
|
2447 |
assert(Z_F8->is_nonvolatile(), "must be nonvolatile to preserve Z_ftos"); |
|
2448 |
__ z_lgr(Z_tmp_1, Z_tos); // Save tos. |
|
2449 |
__ z_lgr(Z_tmp_2, Z_bytecode); // Save Z_bytecode. |
|
2450 |
__ z_ldr(Z_F8, Z_ftos); // Save ftos. |
|
2451 |
// Use -XX:StopInterpreterAt=<num> to set the limit |
|
2452 |
// and break at breakpoint(). |
|
2453 |
__ call_VM(noreg, CAST_FROM_FN_PTR(address, breakpoint), false); |
|
2454 |
__ z_lgr(Z_tos, Z_tmp_1); // Restore tos. |
|
2455 |
__ z_lgr(Z_bytecode, Z_tmp_2); // Save Z_bytecode. |
|
2456 |
__ z_ldr(Z_ftos, Z_F8); // Restore ftos. |
|
2457 |
__ bind(L); |
|
2458 |
} |
|
2459 |
||
2460 |
#endif // !PRODUCT |