annotate src/cpu/s390/vm/templateInterpreterGenerator_s390.cpp @ 12547:0c6ed760800c

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