src/cpu/ppc/vm/interpreter_ppc.cpp

Tue, 17 Oct 2017 12:58:25 +0800

author
aoqi
date
Tue, 17 Oct 2017 12:58:25 +0800
changeset 7994
04ff2f6cd0eb
parent 7794
231481a06214
parent 7535
7ae4e26cb1e0
child 8604
04d83ba48607
permissions
-rw-r--r--

merge

aoqi@0 1 /*
goetz@7794 2 * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
goetz@7794 3 * Copyright 2012, 2015 SAP AG. All rights reserved.
aoqi@0 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 5 *
aoqi@0 6 * This code is free software; you can redistribute it and/or modify it
aoqi@0 7 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 8 * published by the Free Software Foundation.
aoqi@0 9 *
aoqi@0 10 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 13 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 14 * accompanied this code).
aoqi@0 15 *
aoqi@0 16 * You should have received a copy of the GNU General Public License version
aoqi@0 17 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 19 *
aoqi@0 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 21 * or visit www.oracle.com if you need additional information or have any
aoqi@0 22 * questions.
aoqi@0 23 *
aoqi@0 24 */
aoqi@0 25
aoqi@0 26 #include "precompiled.hpp"
aoqi@0 27 #include "asm/macroAssembler.inline.hpp"
aoqi@0 28 #include "interpreter/bytecodeHistogram.hpp"
aoqi@0 29 #include "interpreter/interpreter.hpp"
aoqi@0 30 #include "interpreter/interpreterGenerator.hpp"
aoqi@0 31 #include "interpreter/interpreterRuntime.hpp"
aoqi@0 32 #include "interpreter/templateTable.hpp"
aoqi@0 33 #include "oops/arrayOop.hpp"
aoqi@0 34 #include "oops/methodData.hpp"
aoqi@0 35 #include "oops/method.hpp"
aoqi@0 36 #include "oops/oop.inline.hpp"
aoqi@0 37 #include "prims/jvmtiExport.hpp"
aoqi@0 38 #include "prims/jvmtiThreadState.hpp"
aoqi@0 39 #include "prims/methodHandles.hpp"
aoqi@0 40 #include "runtime/arguments.hpp"
aoqi@0 41 #include "runtime/deoptimization.hpp"
aoqi@0 42 #include "runtime/frame.inline.hpp"
aoqi@0 43 #include "runtime/sharedRuntime.hpp"
aoqi@0 44 #include "runtime/stubRoutines.hpp"
aoqi@0 45 #include "runtime/synchronizer.hpp"
aoqi@0 46 #include "runtime/timer.hpp"
aoqi@0 47 #include "runtime/vframeArray.hpp"
aoqi@0 48 #include "utilities/debug.hpp"
aoqi@0 49 #ifdef COMPILER1
aoqi@0 50 #include "c1/c1_Runtime1.hpp"
aoqi@0 51 #endif
aoqi@0 52
aoqi@0 53 #define __ _masm->
aoqi@0 54
aoqi@0 55 #ifdef PRODUCT
aoqi@0 56 #define BLOCK_COMMENT(str) // nothing
aoqi@0 57 #else
aoqi@0 58 #define BLOCK_COMMENT(str) __ block_comment(str)
aoqi@0 59 #endif
aoqi@0 60
aoqi@0 61 #define BIND(label) bind(label); BLOCK_COMMENT(#label ":")
aoqi@0 62
aoqi@0 63 int AbstractInterpreter::BasicType_as_index(BasicType type) {
aoqi@0 64 int i = 0;
aoqi@0 65 switch (type) {
aoqi@0 66 case T_BOOLEAN: i = 0; break;
aoqi@0 67 case T_CHAR : i = 1; break;
aoqi@0 68 case T_BYTE : i = 2; break;
aoqi@0 69 case T_SHORT : i = 3; break;
aoqi@0 70 case T_INT : i = 4; break;
aoqi@0 71 case T_LONG : i = 5; break;
aoqi@0 72 case T_VOID : i = 6; break;
aoqi@0 73 case T_FLOAT : i = 7; break;
aoqi@0 74 case T_DOUBLE : i = 8; break;
aoqi@0 75 case T_OBJECT : i = 9; break;
aoqi@0 76 case T_ARRAY : i = 9; break;
aoqi@0 77 default : ShouldNotReachHere();
aoqi@0 78 }
aoqi@0 79 assert(0 <= i && i < AbstractInterpreter::number_of_result_handlers, "index out of bounds");
aoqi@0 80 return i;
aoqi@0 81 }
aoqi@0 82
aoqi@0 83 address AbstractInterpreterGenerator::generate_slow_signature_handler() {
aoqi@0 84 // Slow_signature handler that respects the PPC C calling conventions.
aoqi@0 85 //
aoqi@0 86 // We get called by the native entry code with our output register
aoqi@0 87 // area == 8. First we call InterpreterRuntime::get_result_handler
aoqi@0 88 // to copy the pointer to the signature string temporarily to the
aoqi@0 89 // first C-argument and to return the result_handler in
aoqi@0 90 // R3_RET. Since native_entry will copy the jni-pointer to the
aoqi@0 91 // first C-argument slot later on, it is OK to occupy this slot
aoqi@0 92 // temporarilly. Then we copy the argument list on the java
aoqi@0 93 // expression stack into native varargs format on the native stack
aoqi@0 94 // and load arguments into argument registers. Integer arguments in
aoqi@0 95 // the varargs vector will be sign-extended to 8 bytes.
aoqi@0 96 //
aoqi@0 97 // On entry:
aoqi@0 98 // R3_ARG1 - intptr_t* Address of java argument list in memory.
aoqi@0 99 // R15_prev_state - BytecodeInterpreter* Address of interpreter state for
aoqi@0 100 // this method
aoqi@0 101 // R19_method
aoqi@0 102 //
aoqi@0 103 // On exit (just before return instruction):
aoqi@0 104 // R3_RET - contains the address of the result_handler.
aoqi@0 105 // R4_ARG2 - is not updated for static methods and contains "this" otherwise.
aoqi@0 106 // R5_ARG3-R10_ARG8: - When the (i-2)th Java argument is not of type float or double,
aoqi@0 107 // ARGi contains this argument. Otherwise, ARGi is not updated.
aoqi@0 108 // F1_ARG1-F13_ARG13 - contain the first 13 arguments of type float or double.
aoqi@0 109
aoqi@0 110 const int LogSizeOfTwoInstructions = 3;
aoqi@0 111
aoqi@0 112 // FIXME: use Argument:: GL: Argument names different numbers!
aoqi@0 113 const int max_fp_register_arguments = 13;
aoqi@0 114 const int max_int_register_arguments = 6; // first 2 are reserved
aoqi@0 115
aoqi@0 116 const Register arg_java = R21_tmp1;
aoqi@0 117 const Register arg_c = R22_tmp2;
aoqi@0 118 const Register signature = R23_tmp3; // is string
aoqi@0 119 const Register sig_byte = R24_tmp4;
aoqi@0 120 const Register fpcnt = R25_tmp5;
aoqi@0 121 const Register argcnt = R26_tmp6;
aoqi@0 122 const Register intSlot = R27_tmp7;
aoqi@0 123 const Register target_sp = R28_tmp8;
aoqi@0 124 const FloatRegister floatSlot = F0;
aoqi@0 125
aoqi@0 126 address entry = __ function_entry();
aoqi@0 127
aoqi@0 128 __ save_LR_CR(R0);
aoqi@0 129 __ save_nonvolatile_gprs(R1_SP, _spill_nonvolatiles_neg(r14));
aoqi@0 130 // We use target_sp for storing arguments in the C frame.
aoqi@0 131 __ mr(target_sp, R1_SP);
aoqi@0 132 __ push_frame_reg_args_nonvolatiles(0, R11_scratch1);
aoqi@0 133
aoqi@0 134 __ mr(arg_java, R3_ARG1);
aoqi@0 135
aoqi@0 136 __ call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::get_signature), R16_thread, R19_method);
aoqi@0 137
aoqi@0 138 // Signature is in R3_RET. Signature is callee saved.
aoqi@0 139 __ mr(signature, R3_RET);
aoqi@0 140
aoqi@0 141 // Get the result handler.
aoqi@0 142 __ call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::get_result_handler), R16_thread, R19_method);
aoqi@0 143
aoqi@0 144 {
aoqi@0 145 Label L;
aoqi@0 146 // test if static
aoqi@0 147 // _access_flags._flags must be at offset 0.
aoqi@0 148 // TODO PPC port: requires change in shared code.
aoqi@0 149 //assert(in_bytes(AccessFlags::flags_offset()) == 0,
aoqi@0 150 // "MethodDesc._access_flags == MethodDesc._access_flags._flags");
aoqi@0 151 // _access_flags must be a 32 bit value.
aoqi@0 152 assert(sizeof(AccessFlags) == 4, "wrong size");
aoqi@0 153 __ lwa(R11_scratch1/*access_flags*/, method_(access_flags));
aoqi@0 154 // testbit with condition register.
aoqi@0 155 __ testbitdi(CCR0, R0, R11_scratch1/*access_flags*/, JVM_ACC_STATIC_BIT);
aoqi@0 156 __ btrue(CCR0, L);
aoqi@0 157 // For non-static functions, pass "this" in R4_ARG2 and copy it
aoqi@0 158 // to 2nd C-arg slot.
aoqi@0 159 // We need to box the Java object here, so we use arg_java
aoqi@0 160 // (address of current Java stack slot) as argument and don't
aoqi@0 161 // dereference it as in case of ints, floats, etc.
aoqi@0 162 __ mr(R4_ARG2, arg_java);
aoqi@0 163 __ addi(arg_java, arg_java, -BytesPerWord);
aoqi@0 164 __ std(R4_ARG2, _abi(carg_2), target_sp);
aoqi@0 165 __ bind(L);
aoqi@0 166 }
aoqi@0 167
aoqi@0 168 // Will be incremented directly after loop_start. argcnt=0
aoqi@0 169 // corresponds to 3rd C argument.
aoqi@0 170 __ li(argcnt, -1);
aoqi@0 171 // arg_c points to 3rd C argument
aoqi@0 172 __ addi(arg_c, target_sp, _abi(carg_3));
aoqi@0 173 // no floating-point args parsed so far
aoqi@0 174 __ li(fpcnt, 0);
aoqi@0 175
aoqi@0 176 Label move_intSlot_to_ARG, move_floatSlot_to_FARG;
aoqi@0 177 Label loop_start, loop_end;
aoqi@0 178 Label do_int, do_long, do_float, do_double, do_dontreachhere, do_object, do_array, do_boxed;
aoqi@0 179
aoqi@0 180 // signature points to '(' at entry
aoqi@0 181 #ifdef ASSERT
aoqi@0 182 __ lbz(sig_byte, 0, signature);
aoqi@0 183 __ cmplwi(CCR0, sig_byte, '(');
aoqi@0 184 __ bne(CCR0, do_dontreachhere);
aoqi@0 185 #endif
aoqi@0 186
aoqi@0 187 __ bind(loop_start);
aoqi@0 188
aoqi@0 189 __ addi(argcnt, argcnt, 1);
aoqi@0 190 __ lbzu(sig_byte, 1, signature);
aoqi@0 191
aoqi@0 192 __ cmplwi(CCR0, sig_byte, ')'); // end of signature
aoqi@0 193 __ beq(CCR0, loop_end);
aoqi@0 194
aoqi@0 195 __ cmplwi(CCR0, sig_byte, 'B'); // byte
aoqi@0 196 __ beq(CCR0, do_int);
aoqi@0 197
aoqi@0 198 __ cmplwi(CCR0, sig_byte, 'C'); // char
aoqi@0 199 __ beq(CCR0, do_int);
aoqi@0 200
aoqi@0 201 __ cmplwi(CCR0, sig_byte, 'D'); // double
aoqi@0 202 __ beq(CCR0, do_double);
aoqi@0 203
aoqi@0 204 __ cmplwi(CCR0, sig_byte, 'F'); // float
aoqi@0 205 __ beq(CCR0, do_float);
aoqi@0 206
aoqi@0 207 __ cmplwi(CCR0, sig_byte, 'I'); // int
aoqi@0 208 __ beq(CCR0, do_int);
aoqi@0 209
aoqi@0 210 __ cmplwi(CCR0, sig_byte, 'J'); // long
aoqi@0 211 __ beq(CCR0, do_long);
aoqi@0 212
aoqi@0 213 __ cmplwi(CCR0, sig_byte, 'S'); // short
aoqi@0 214 __ beq(CCR0, do_int);
aoqi@0 215
aoqi@0 216 __ cmplwi(CCR0, sig_byte, 'Z'); // boolean
aoqi@0 217 __ beq(CCR0, do_int);
aoqi@0 218
aoqi@0 219 __ cmplwi(CCR0, sig_byte, 'L'); // object
aoqi@0 220 __ beq(CCR0, do_object);
aoqi@0 221
aoqi@0 222 __ cmplwi(CCR0, sig_byte, '['); // array
aoqi@0 223 __ beq(CCR0, do_array);
aoqi@0 224
aoqi@0 225 // __ cmplwi(CCR0, sig_byte, 'V'); // void cannot appear since we do not parse the return type
aoqi@0 226 // __ beq(CCR0, do_void);
aoqi@0 227
aoqi@0 228 __ bind(do_dontreachhere);
aoqi@0 229
aoqi@0 230 __ unimplemented("ShouldNotReachHere in slow_signature_handler", 120);
aoqi@0 231
aoqi@0 232 __ bind(do_array);
aoqi@0 233
aoqi@0 234 {
aoqi@0 235 Label start_skip, end_skip;
aoqi@0 236
aoqi@0 237 __ bind(start_skip);
aoqi@0 238 __ lbzu(sig_byte, 1, signature);
aoqi@0 239 __ cmplwi(CCR0, sig_byte, '[');
aoqi@0 240 __ beq(CCR0, start_skip); // skip further brackets
aoqi@0 241 __ cmplwi(CCR0, sig_byte, '9');
aoqi@0 242 __ bgt(CCR0, end_skip); // no optional size
aoqi@0 243 __ cmplwi(CCR0, sig_byte, '0');
aoqi@0 244 __ bge(CCR0, start_skip); // skip optional size
aoqi@0 245 __ bind(end_skip);
aoqi@0 246
aoqi@0 247 __ cmplwi(CCR0, sig_byte, 'L');
aoqi@0 248 __ beq(CCR0, do_object); // for arrays of objects, the name of the object must be skipped
aoqi@0 249 __ b(do_boxed); // otherwise, go directly to do_boxed
aoqi@0 250 }
aoqi@0 251
aoqi@0 252 __ bind(do_object);
aoqi@0 253 {
aoqi@0 254 Label L;
aoqi@0 255 __ bind(L);
aoqi@0 256 __ lbzu(sig_byte, 1, signature);
aoqi@0 257 __ cmplwi(CCR0, sig_byte, ';');
aoqi@0 258 __ bne(CCR0, L);
aoqi@0 259 }
aoqi@0 260 // Need to box the Java object here, so we use arg_java (address of
aoqi@0 261 // current Java stack slot) as argument and don't dereference it as
aoqi@0 262 // in case of ints, floats, etc.
aoqi@0 263 Label do_null;
aoqi@0 264 __ bind(do_boxed);
aoqi@0 265 __ ld(R0,0, arg_java);
aoqi@0 266 __ cmpdi(CCR0, R0, 0);
aoqi@0 267 __ li(intSlot,0);
aoqi@0 268 __ beq(CCR0, do_null);
aoqi@0 269 __ mr(intSlot, arg_java);
aoqi@0 270 __ bind(do_null);
aoqi@0 271 __ std(intSlot, 0, arg_c);
aoqi@0 272 __ addi(arg_java, arg_java, -BytesPerWord);
aoqi@0 273 __ addi(arg_c, arg_c, BytesPerWord);
aoqi@0 274 __ cmplwi(CCR0, argcnt, max_int_register_arguments);
aoqi@0 275 __ blt(CCR0, move_intSlot_to_ARG);
aoqi@0 276 __ b(loop_start);
aoqi@0 277
aoqi@0 278 __ bind(do_int);
aoqi@0 279 __ lwa(intSlot, 0, arg_java);
aoqi@0 280 __ std(intSlot, 0, arg_c);
aoqi@0 281 __ addi(arg_java, arg_java, -BytesPerWord);
aoqi@0 282 __ addi(arg_c, arg_c, BytesPerWord);
aoqi@0 283 __ cmplwi(CCR0, argcnt, max_int_register_arguments);
aoqi@0 284 __ blt(CCR0, move_intSlot_to_ARG);
aoqi@0 285 __ b(loop_start);
aoqi@0 286
aoqi@0 287 __ bind(do_long);
aoqi@0 288 __ ld(intSlot, -BytesPerWord, arg_java);
aoqi@0 289 __ std(intSlot, 0, arg_c);
aoqi@0 290 __ addi(arg_java, arg_java, - 2 * BytesPerWord);
aoqi@0 291 __ addi(arg_c, arg_c, BytesPerWord);
aoqi@0 292 __ cmplwi(CCR0, argcnt, max_int_register_arguments);
aoqi@0 293 __ blt(CCR0, move_intSlot_to_ARG);
aoqi@0 294 __ b(loop_start);
aoqi@0 295
aoqi@0 296 __ bind(do_float);
aoqi@0 297 __ lfs(floatSlot, 0, arg_java);
aoqi@0 298 #if defined(LINUX)
aoqi@0 299 __ stfs(floatSlot, 4, arg_c);
aoqi@0 300 #elif defined(AIX)
aoqi@0 301 __ stfs(floatSlot, 0, arg_c);
aoqi@0 302 #else
aoqi@0 303 #error "unknown OS"
aoqi@0 304 #endif
aoqi@0 305 __ addi(arg_java, arg_java, -BytesPerWord);
aoqi@0 306 __ addi(arg_c, arg_c, BytesPerWord);
aoqi@0 307 __ cmplwi(CCR0, fpcnt, max_fp_register_arguments);
aoqi@0 308 __ blt(CCR0, move_floatSlot_to_FARG);
aoqi@0 309 __ b(loop_start);
aoqi@0 310
aoqi@0 311 __ bind(do_double);
aoqi@0 312 __ lfd(floatSlot, - BytesPerWord, arg_java);
aoqi@0 313 __ stfd(floatSlot, 0, arg_c);
aoqi@0 314 __ addi(arg_java, arg_java, - 2 * BytesPerWord);
aoqi@0 315 __ addi(arg_c, arg_c, BytesPerWord);
aoqi@0 316 __ cmplwi(CCR0, fpcnt, max_fp_register_arguments);
aoqi@0 317 __ blt(CCR0, move_floatSlot_to_FARG);
aoqi@0 318 __ b(loop_start);
aoqi@0 319
aoqi@0 320 __ bind(loop_end);
aoqi@0 321
aoqi@0 322 __ pop_frame();
aoqi@0 323 __ restore_nonvolatile_gprs(R1_SP, _spill_nonvolatiles_neg(r14));
aoqi@0 324 __ restore_LR_CR(R0);
aoqi@0 325
aoqi@0 326 __ blr();
aoqi@0 327
aoqi@0 328 Label move_int_arg, move_float_arg;
aoqi@0 329 __ bind(move_int_arg); // each case must consist of 2 instructions (otherwise adapt LogSizeOfTwoInstructions)
aoqi@0 330 __ mr(R5_ARG3, intSlot); __ b(loop_start);
aoqi@0 331 __ mr(R6_ARG4, intSlot); __ b(loop_start);
aoqi@0 332 __ mr(R7_ARG5, intSlot); __ b(loop_start);
aoqi@0 333 __ mr(R8_ARG6, intSlot); __ b(loop_start);
aoqi@0 334 __ mr(R9_ARG7, intSlot); __ b(loop_start);
aoqi@0 335 __ mr(R10_ARG8, intSlot); __ b(loop_start);
aoqi@0 336
aoqi@0 337 __ bind(move_float_arg); // each case must consist of 2 instructions (otherwise adapt LogSizeOfTwoInstructions)
aoqi@0 338 __ fmr(F1_ARG1, floatSlot); __ b(loop_start);
aoqi@0 339 __ fmr(F2_ARG2, floatSlot); __ b(loop_start);
aoqi@0 340 __ fmr(F3_ARG3, floatSlot); __ b(loop_start);
aoqi@0 341 __ fmr(F4_ARG4, floatSlot); __ b(loop_start);
aoqi@0 342 __ fmr(F5_ARG5, floatSlot); __ b(loop_start);
aoqi@0 343 __ fmr(F6_ARG6, floatSlot); __ b(loop_start);
aoqi@0 344 __ fmr(F7_ARG7, floatSlot); __ b(loop_start);
aoqi@0 345 __ fmr(F8_ARG8, floatSlot); __ b(loop_start);
aoqi@0 346 __ fmr(F9_ARG9, floatSlot); __ b(loop_start);
aoqi@0 347 __ fmr(F10_ARG10, floatSlot); __ b(loop_start);
aoqi@0 348 __ fmr(F11_ARG11, floatSlot); __ b(loop_start);
aoqi@0 349 __ fmr(F12_ARG12, floatSlot); __ b(loop_start);
aoqi@0 350 __ fmr(F13_ARG13, floatSlot); __ b(loop_start);
aoqi@0 351
aoqi@0 352 __ bind(move_intSlot_to_ARG);
aoqi@0 353 __ sldi(R0, argcnt, LogSizeOfTwoInstructions);
aoqi@0 354 __ load_const(R11_scratch1, move_int_arg); // Label must be bound here.
aoqi@0 355 __ add(R11_scratch1, R0, R11_scratch1);
aoqi@0 356 __ mtctr(R11_scratch1/*branch_target*/);
aoqi@0 357 __ bctr();
aoqi@0 358 __ bind(move_floatSlot_to_FARG);
aoqi@0 359 __ sldi(R0, fpcnt, LogSizeOfTwoInstructions);
aoqi@0 360 __ addi(fpcnt, fpcnt, 1);
aoqi@0 361 __ load_const(R11_scratch1, move_float_arg); // Label must be bound here.
aoqi@0 362 __ add(R11_scratch1, R0, R11_scratch1);
aoqi@0 363 __ mtctr(R11_scratch1/*branch_target*/);
aoqi@0 364 __ bctr();
aoqi@0 365
aoqi@0 366 return entry;
aoqi@0 367 }
aoqi@0 368
aoqi@0 369 address AbstractInterpreterGenerator::generate_result_handler_for(BasicType type) {
aoqi@0 370 //
aoqi@0 371 // Registers alive
aoqi@0 372 // R3_RET
aoqi@0 373 // LR
aoqi@0 374 //
aoqi@0 375 // Registers updated
aoqi@0 376 // R3_RET
aoqi@0 377 //
aoqi@0 378
aoqi@0 379 Label done;
aoqi@0 380 address entry = __ pc();
aoqi@0 381
aoqi@0 382 switch (type) {
aoqi@0 383 case T_BOOLEAN:
aoqi@0 384 // convert !=0 to 1
aoqi@0 385 __ neg(R0, R3_RET);
aoqi@0 386 __ orr(R0, R3_RET, R0);
aoqi@0 387 __ srwi(R3_RET, R0, 31);
aoqi@0 388 break;
aoqi@0 389 case T_BYTE:
aoqi@0 390 // sign extend 8 bits
aoqi@0 391 __ extsb(R3_RET, R3_RET);
aoqi@0 392 break;
aoqi@0 393 case T_CHAR:
aoqi@0 394 // zero extend 16 bits
aoqi@0 395 __ clrldi(R3_RET, R3_RET, 48);
aoqi@0 396 break;
aoqi@0 397 case T_SHORT:
aoqi@0 398 // sign extend 16 bits
aoqi@0 399 __ extsh(R3_RET, R3_RET);
aoqi@0 400 break;
aoqi@0 401 case T_INT:
aoqi@0 402 // sign extend 32 bits
aoqi@0 403 __ extsw(R3_RET, R3_RET);
aoqi@0 404 break;
aoqi@0 405 case T_LONG:
aoqi@0 406 break;
aoqi@0 407 case T_OBJECT:
aoqi@0 408 // unbox result if not null
aoqi@0 409 __ cmpdi(CCR0, R3_RET, 0);
aoqi@0 410 __ beq(CCR0, done);
aoqi@0 411 __ ld(R3_RET, 0, R3_RET);
aoqi@0 412 __ verify_oop(R3_RET);
aoqi@0 413 break;
aoqi@0 414 case T_FLOAT:
aoqi@0 415 break;
aoqi@0 416 case T_DOUBLE:
aoqi@0 417 break;
aoqi@0 418 case T_VOID:
aoqi@0 419 break;
aoqi@0 420 default: ShouldNotReachHere();
aoqi@0 421 }
aoqi@0 422
aoqi@0 423 __ BIND(done);
aoqi@0 424 __ blr();
aoqi@0 425
aoqi@0 426 return entry;
aoqi@0 427 }
aoqi@0 428
aoqi@0 429 // Abstract method entry.
aoqi@0 430 //
aoqi@0 431 address InterpreterGenerator::generate_abstract_entry(void) {
aoqi@0 432 address entry = __ pc();
aoqi@0 433
aoqi@0 434 //
aoqi@0 435 // Registers alive
aoqi@0 436 // R16_thread - JavaThread*
aoqi@0 437 // R19_method - callee's method (method to be invoked)
aoqi@0 438 // R1_SP - SP prepared such that caller's outgoing args are near top
aoqi@0 439 // LR - return address to caller
aoqi@0 440 //
aoqi@0 441 // Stack layout at this point:
aoqi@0 442 //
aoqi@0 443 // 0 [TOP_IJAVA_FRAME_ABI] <-- R1_SP
aoqi@0 444 // alignment (optional)
aoqi@0 445 // [outgoing Java arguments]
aoqi@0 446 // ...
aoqi@0 447 // PARENT [PARENT_IJAVA_FRAME_ABI]
aoqi@0 448 // ...
aoqi@0 449 //
aoqi@0 450
aoqi@0 451 // Can't use call_VM here because we have not set up a new
aoqi@0 452 // interpreter state. Make the call to the vm and make it look like
aoqi@0 453 // our caller set up the JavaFrameAnchor.
aoqi@0 454 __ set_top_ijava_frame_at_SP_as_last_Java_frame(R1_SP, R12_scratch2/*tmp*/);
aoqi@0 455
aoqi@0 456 // Push a new C frame and save LR.
aoqi@0 457 __ save_LR_CR(R0);
aoqi@0 458 __ push_frame_reg_args(0, R11_scratch1);
aoqi@0 459
aoqi@0 460 // This is not a leaf but we have a JavaFrameAnchor now and we will
aoqi@0 461 // check (create) exceptions afterward so this is ok.
goetz@7794 462 __ call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_AbstractMethodError),
goetz@7794 463 R16_thread);
aoqi@0 464
aoqi@0 465 // Pop the C frame and restore LR.
aoqi@0 466 __ pop_frame();
aoqi@0 467 __ restore_LR_CR(R0);
aoqi@0 468
aoqi@0 469 // Reset JavaFrameAnchor from call_VM_leaf above.
aoqi@0 470 __ reset_last_Java_frame();
aoqi@0 471
aoqi@0 472 #ifdef CC_INTERP
aoqi@0 473 // Return to frame manager, it will handle the pending exception.
aoqi@0 474 __ blr();
aoqi@0 475 #else
aoqi@0 476 // We don't know our caller, so jump to the general forward exception stub,
aoqi@0 477 // which will also pop our full frame off. Satisfy the interface of
aoqi@0 478 // SharedRuntime::generate_forward_exception()
aoqi@0 479 __ load_const_optimized(R11_scratch1, StubRoutines::forward_exception_entry(), R0);
aoqi@0 480 __ mtctr(R11_scratch1);
aoqi@0 481 __ bctr();
aoqi@0 482 #endif
aoqi@0 483
aoqi@0 484 return entry;
aoqi@0 485 }
aoqi@0 486
aoqi@0 487 // Call an accessor method (assuming it is resolved, otherwise drop into
aoqi@0 488 // vanilla (slow path) entry.
aoqi@0 489 address InterpreterGenerator::generate_accessor_entry(void) {
aoqi@0 490 if (!UseFastAccessorMethods && (!FLAG_IS_ERGO(UseFastAccessorMethods))) {
aoqi@0 491 return NULL;
aoqi@0 492 }
aoqi@0 493
aoqi@0 494 Label Lslow_path, Lacquire;
aoqi@0 495
aoqi@0 496 const Register
aoqi@0 497 Rclass_or_obj = R3_ARG1,
aoqi@0 498 Rconst_method = R4_ARG2,
aoqi@0 499 Rcodes = Rconst_method,
aoqi@0 500 Rcpool_cache = R5_ARG3,
aoqi@0 501 Rscratch = R11_scratch1,
aoqi@0 502 Rjvmti_mode = Rscratch,
aoqi@0 503 Roffset = R12_scratch2,
aoqi@0 504 Rflags = R6_ARG4,
aoqi@0 505 Rbtable = R7_ARG5;
aoqi@0 506
aoqi@0 507 static address branch_table[number_of_states];
aoqi@0 508
aoqi@0 509 address entry = __ pc();
aoqi@0 510
aoqi@0 511 // Check for safepoint:
aoqi@0 512 // Ditch this, real man don't need safepoint checks.
aoqi@0 513
aoqi@0 514 // Also check for JVMTI mode
aoqi@0 515 // Check for null obj, take slow path if so.
aoqi@0 516 __ ld(Rclass_or_obj, Interpreter::stackElementSize, CC_INTERP_ONLY(R17_tos) NOT_CC_INTERP(R15_esp));
aoqi@0 517 __ lwz(Rjvmti_mode, thread_(interp_only_mode));
aoqi@0 518 __ cmpdi(CCR1, Rclass_or_obj, 0);
aoqi@0 519 __ cmpwi(CCR0, Rjvmti_mode, 0);
aoqi@0 520 __ crorc(/*CCR0 eq*/2, /*CCR1 eq*/4+2, /*CCR0 eq*/2);
aoqi@0 521 __ beq(CCR0, Lslow_path); // this==null or jvmti_mode!=0
aoqi@0 522
aoqi@0 523 // Do 2 things in parallel:
aoqi@0 524 // 1. Load the index out of the first instruction word, which looks like this:
aoqi@0 525 // <0x2a><0xb4><index (2 byte, native endianess)>.
aoqi@0 526 // 2. Load constant pool cache base.
aoqi@0 527 __ ld(Rconst_method, in_bytes(Method::const_offset()), R19_method);
aoqi@0 528 __ ld(Rcpool_cache, in_bytes(ConstMethod::constants_offset()), Rconst_method);
aoqi@0 529
aoqi@0 530 __ lhz(Rcodes, in_bytes(ConstMethod::codes_offset()) + 2, Rconst_method); // Lower half of 32 bit field.
aoqi@0 531 __ ld(Rcpool_cache, ConstantPool::cache_offset_in_bytes(), Rcpool_cache);
aoqi@0 532
aoqi@0 533 // Get the const pool entry by means of <index>.
aoqi@0 534 const int codes_shift = exact_log2(in_words(ConstantPoolCacheEntry::size()) * BytesPerWord);
aoqi@0 535 __ slwi(Rscratch, Rcodes, codes_shift); // (codes&0xFFFF)<<codes_shift
aoqi@0 536 __ add(Rcpool_cache, Rscratch, Rcpool_cache);
aoqi@0 537
aoqi@0 538 // Check if cpool cache entry is resolved.
aoqi@0 539 // We are resolved if the indices offset contains the current bytecode.
aoqi@0 540 ByteSize cp_base_offset = ConstantPoolCache::base_offset();
aoqi@0 541 // Big Endian:
aoqi@0 542 __ lbz(Rscratch, in_bytes(cp_base_offset) + in_bytes(ConstantPoolCacheEntry::indices_offset()) + 7 - 2, Rcpool_cache);
aoqi@0 543 __ cmpwi(CCR0, Rscratch, Bytecodes::_getfield);
aoqi@0 544 __ bne(CCR0, Lslow_path);
aoqi@0 545 __ isync(); // Order succeeding loads wrt. load of _indices field from cpool_cache.
aoqi@0 546
aoqi@0 547 // Finally, start loading the value: Get cp cache entry into regs.
aoqi@0 548 __ ld(Rflags, in_bytes(cp_base_offset) + in_bytes(ConstantPoolCacheEntry::flags_offset()), Rcpool_cache);
aoqi@0 549 __ ld(Roffset, in_bytes(cp_base_offset) + in_bytes(ConstantPoolCacheEntry::f2_offset()), Rcpool_cache);
aoqi@0 550
aoqi@0 551 // Following code is from templateTable::getfield_or_static
aoqi@0 552 // Load pointer to branch table
aoqi@0 553 __ load_const_optimized(Rbtable, (address)branch_table, Rscratch);
aoqi@0 554
aoqi@0 555 // Get volatile flag
aoqi@0 556 __ rldicl(Rscratch, Rflags, 64-ConstantPoolCacheEntry::is_volatile_shift, 63); // extract volatile bit
aoqi@0 557 // note: sync is needed before volatile load on PPC64
aoqi@0 558
aoqi@0 559 // Check field type
aoqi@0 560 __ rldicl(Rflags, Rflags, 64-ConstantPoolCacheEntry::tos_state_shift, 64-ConstantPoolCacheEntry::tos_state_bits);
aoqi@0 561
aoqi@0 562 #ifdef ASSERT
aoqi@0 563 Label LFlagInvalid;
aoqi@0 564 __ cmpldi(CCR0, Rflags, number_of_states);
aoqi@0 565 __ bge(CCR0, LFlagInvalid);
aoqi@0 566
aoqi@0 567 __ ld(R9_ARG7, 0, R1_SP);
aoqi@0 568 __ ld(R10_ARG8, 0, R21_sender_SP);
aoqi@0 569 __ cmpd(CCR0, R9_ARG7, R10_ARG8);
aoqi@0 570 __ asm_assert_eq("backlink", 0x543);
aoqi@0 571 #endif // ASSERT
aoqi@0 572 __ mr(R1_SP, R21_sender_SP); // Cut the stack back to where the caller started.
aoqi@0 573
aoqi@0 574 // Load from branch table and dispatch (volatile case: one instruction ahead)
aoqi@0 575 __ sldi(Rflags, Rflags, LogBytesPerWord);
aoqi@0 576 __ cmpwi(CCR6, Rscratch, 1); // volatile?
aoqi@0 577 if (support_IRIW_for_not_multiple_copy_atomic_cpu) {
aoqi@0 578 __ sldi(Rscratch, Rscratch, exact_log2(BytesPerInstWord)); // volatile ? size of 1 instruction : 0
aoqi@0 579 }
aoqi@0 580 __ ldx(Rbtable, Rbtable, Rflags);
aoqi@0 581
aoqi@0 582 if (support_IRIW_for_not_multiple_copy_atomic_cpu) {
aoqi@0 583 __ subf(Rbtable, Rscratch, Rbtable); // point to volatile/non-volatile entry point
aoqi@0 584 }
aoqi@0 585 __ mtctr(Rbtable);
aoqi@0 586 __ bctr();
aoqi@0 587
aoqi@0 588 #ifdef ASSERT
aoqi@0 589 __ bind(LFlagInvalid);
aoqi@0 590 __ stop("got invalid flag", 0x6541);
aoqi@0 591
aoqi@0 592 bool all_uninitialized = true,
aoqi@0 593 all_initialized = true;
aoqi@0 594 for (int i = 0; i<number_of_states; ++i) {
aoqi@0 595 all_uninitialized = all_uninitialized && (branch_table[i] == NULL);
aoqi@0 596 all_initialized = all_initialized && (branch_table[i] != NULL);
aoqi@0 597 }
aoqi@0 598 assert(all_uninitialized != all_initialized, "consistency"); // either or
aoqi@0 599
aoqi@0 600 __ fence(); // volatile entry point (one instruction before non-volatile_entry point)
aoqi@0 601 if (branch_table[vtos] == 0) branch_table[vtos] = __ pc(); // non-volatile_entry point
aoqi@0 602 if (branch_table[dtos] == 0) branch_table[dtos] = __ pc(); // non-volatile_entry point
aoqi@0 603 if (branch_table[ftos] == 0) branch_table[ftos] = __ pc(); // non-volatile_entry point
aoqi@0 604 __ stop("unexpected type", 0x6551);
aoqi@0 605 #endif
aoqi@0 606
aoqi@0 607 if (branch_table[itos] == 0) { // generate only once
aoqi@0 608 __ align(32, 28, 28); // align load
aoqi@0 609 __ fence(); // volatile entry point (one instruction before non-volatile_entry point)
aoqi@0 610 branch_table[itos] = __ pc(); // non-volatile_entry point
aoqi@0 611 __ lwax(R3_RET, Rclass_or_obj, Roffset);
aoqi@0 612 __ beq(CCR6, Lacquire);
aoqi@0 613 __ blr();
aoqi@0 614 }
aoqi@0 615
aoqi@0 616 if (branch_table[ltos] == 0) { // generate only once
aoqi@0 617 __ align(32, 28, 28); // align load
aoqi@0 618 __ fence(); // volatile entry point (one instruction before non-volatile_entry point)
aoqi@0 619 branch_table[ltos] = __ pc(); // non-volatile_entry point
aoqi@0 620 __ ldx(R3_RET, Rclass_or_obj, Roffset);
aoqi@0 621 __ beq(CCR6, Lacquire);
aoqi@0 622 __ blr();
aoqi@0 623 }
aoqi@0 624
aoqi@0 625 if (branch_table[btos] == 0) { // generate only once
aoqi@0 626 __ align(32, 28, 28); // align load
aoqi@0 627 __ fence(); // volatile entry point (one instruction before non-volatile_entry point)
aoqi@0 628 branch_table[btos] = __ pc(); // non-volatile_entry point
aoqi@0 629 __ lbzx(R3_RET, Rclass_or_obj, Roffset);
aoqi@0 630 __ extsb(R3_RET, R3_RET);
aoqi@0 631 __ beq(CCR6, Lacquire);
aoqi@0 632 __ blr();
aoqi@0 633 }
aoqi@0 634
aoqi@0 635 if (branch_table[ctos] == 0) { // generate only once
aoqi@0 636 __ align(32, 28, 28); // align load
aoqi@0 637 __ fence(); // volatile entry point (one instruction before non-volatile_entry point)
aoqi@0 638 branch_table[ctos] = __ pc(); // non-volatile_entry point
aoqi@0 639 __ lhzx(R3_RET, Rclass_or_obj, Roffset);
aoqi@0 640 __ beq(CCR6, Lacquire);
aoqi@0 641 __ blr();
aoqi@0 642 }
aoqi@0 643
aoqi@0 644 if (branch_table[stos] == 0) { // generate only once
aoqi@0 645 __ align(32, 28, 28); // align load
aoqi@0 646 __ fence(); // volatile entry point (one instruction before non-volatile_entry point)
aoqi@0 647 branch_table[stos] = __ pc(); // non-volatile_entry point
aoqi@0 648 __ lhax(R3_RET, Rclass_or_obj, Roffset);
aoqi@0 649 __ beq(CCR6, Lacquire);
aoqi@0 650 __ blr();
aoqi@0 651 }
aoqi@0 652
aoqi@0 653 if (branch_table[atos] == 0) { // generate only once
aoqi@0 654 __ align(32, 28, 28); // align load
aoqi@0 655 __ fence(); // volatile entry point (one instruction before non-volatile_entry point)
aoqi@0 656 branch_table[atos] = __ pc(); // non-volatile_entry point
aoqi@0 657 __ load_heap_oop(R3_RET, (RegisterOrConstant)Roffset, Rclass_or_obj);
aoqi@0 658 __ verify_oop(R3_RET);
aoqi@0 659 //__ dcbt(R3_RET); // prefetch
aoqi@0 660 __ beq(CCR6, Lacquire);
aoqi@0 661 __ blr();
aoqi@0 662 }
aoqi@0 663
aoqi@0 664 __ align(32, 12);
aoqi@0 665 __ bind(Lacquire);
aoqi@0 666 __ twi_0(R3_RET);
aoqi@0 667 __ isync(); // acquire
aoqi@0 668 __ blr();
aoqi@0 669
aoqi@0 670 #ifdef ASSERT
aoqi@0 671 for (int i = 0; i<number_of_states; ++i) {
aoqi@0 672 assert(branch_table[i], "accessor_entry initialization");
aoqi@0 673 //tty->print_cr("accessor_entry: branch_table[%d] = 0x%llx (opcode 0x%llx)", i, branch_table[i], *((unsigned int*)branch_table[i]));
aoqi@0 674 }
aoqi@0 675 #endif
aoqi@0 676
aoqi@0 677 __ bind(Lslow_path);
aoqi@0 678 __ branch_to_entry(Interpreter::entry_for_kind(Interpreter::zerolocals), Rscratch);
aoqi@0 679 __ flush();
aoqi@0 680
aoqi@0 681 return entry;
aoqi@0 682 }
aoqi@0 683
aoqi@0 684 // Interpreter intrinsic for WeakReference.get().
aoqi@0 685 // 1. Don't push a full blown frame and go on dispatching, but fetch the value
aoqi@0 686 // into R8 and return quickly
aoqi@0 687 // 2. If G1 is active we *must* execute this intrinsic for corrrectness:
aoqi@0 688 // It contains a GC barrier which puts the reference into the satb buffer
aoqi@0 689 // to indicate that someone holds a strong reference to the object the
aoqi@0 690 // weak ref points to!
aoqi@0 691 address InterpreterGenerator::generate_Reference_get_entry(void) {
aoqi@0 692 // Code: _aload_0, _getfield, _areturn
aoqi@0 693 // parameter size = 1
aoqi@0 694 //
aoqi@0 695 // The code that gets generated by this routine is split into 2 parts:
aoqi@0 696 // 1. the "intrinsified" code for G1 (or any SATB based GC),
aoqi@0 697 // 2. the slow path - which is an expansion of the regular method entry.
aoqi@0 698 //
aoqi@0 699 // Notes:
aoqi@0 700 // * In the G1 code we do not check whether we need to block for
aoqi@0 701 // a safepoint. If G1 is enabled then we must execute the specialized
aoqi@0 702 // code for Reference.get (except when the Reference object is null)
aoqi@0 703 // so that we can log the value in the referent field with an SATB
aoqi@0 704 // update buffer.
aoqi@0 705 // If the code for the getfield template is modified so that the
aoqi@0 706 // G1 pre-barrier code is executed when the current method is
aoqi@0 707 // Reference.get() then going through the normal method entry
aoqi@0 708 // will be fine.
aoqi@0 709 // * The G1 code can, however, check the receiver object (the instance
aoqi@0 710 // of java.lang.Reference) and jump to the slow path if null. If the
aoqi@0 711 // Reference object is null then we obviously cannot fetch the referent
aoqi@0 712 // and so we don't need to call the G1 pre-barrier. Thus we can use the
aoqi@0 713 // regular method entry code to generate the NPE.
aoqi@0 714 //
aoqi@0 715 // This code is based on generate_accessor_enty.
aoqi@0 716
aoqi@0 717 address entry = __ pc();
aoqi@0 718
aoqi@0 719 const int referent_offset = java_lang_ref_Reference::referent_offset;
aoqi@0 720 guarantee(referent_offset > 0, "referent offset not initialized");
aoqi@0 721
aoqi@0 722 if (UseG1GC) {
aoqi@0 723 Label slow_path;
aoqi@0 724
aoqi@0 725 // Debugging not possible, so can't use __ skip_if_jvmti_mode(slow_path, GR31_SCRATCH);
aoqi@0 726
aoqi@0 727 // In the G1 code we don't check if we need to reach a safepoint. We
aoqi@0 728 // continue and the thread will safepoint at the next bytecode dispatch.
aoqi@0 729
aoqi@0 730 // If the receiver is null then it is OK to jump to the slow path.
aoqi@0 731 __ ld(R3_RET, Interpreter::stackElementSize, CC_INTERP_ONLY(R17_tos) NOT_CC_INTERP(R15_esp)); // get receiver
aoqi@0 732
aoqi@0 733 // Check if receiver == NULL and go the slow path.
aoqi@0 734 __ cmpdi(CCR0, R3_RET, 0);
aoqi@0 735 __ beq(CCR0, slow_path);
aoqi@0 736
aoqi@0 737 // Load the value of the referent field.
aoqi@0 738 __ load_heap_oop(R3_RET, referent_offset, R3_RET);
aoqi@0 739
aoqi@0 740 // Generate the G1 pre-barrier code to log the value of
aoqi@0 741 // the referent field in an SATB buffer. Note with
aoqi@0 742 // these parameters the pre-barrier does not generate
aoqi@0 743 // the load of the previous value.
aoqi@0 744
aoqi@0 745 // Restore caller sp for c2i case.
aoqi@0 746 #ifdef ASSERT
aoqi@0 747 __ ld(R9_ARG7, 0, R1_SP);
aoqi@0 748 __ ld(R10_ARG8, 0, R21_sender_SP);
aoqi@0 749 __ cmpd(CCR0, R9_ARG7, R10_ARG8);
aoqi@0 750 __ asm_assert_eq("backlink", 0x544);
aoqi@0 751 #endif // ASSERT
aoqi@0 752 __ mr(R1_SP, R21_sender_SP); // Cut the stack back to where the caller started.
aoqi@0 753
aoqi@0 754 __ g1_write_barrier_pre(noreg, // obj
aoqi@0 755 noreg, // offset
aoqi@0 756 R3_RET, // pre_val
aoqi@0 757 R11_scratch1, // tmp
aoqi@0 758 R12_scratch2, // tmp
aoqi@0 759 true); // needs_frame
aoqi@0 760
aoqi@0 761 __ blr();
aoqi@0 762
aoqi@0 763 // Generate regular method entry.
aoqi@0 764 __ bind(slow_path);
aoqi@0 765 __ branch_to_entry(Interpreter::entry_for_kind(Interpreter::zerolocals), R11_scratch1);
aoqi@0 766 __ flush();
aoqi@0 767
aoqi@0 768 return entry;
aoqi@0 769 } else {
aoqi@0 770 return generate_accessor_entry();
aoqi@0 771 }
aoqi@0 772 }
aoqi@0 773
aoqi@0 774 void Deoptimization::unwind_callee_save_values(frame* f, vframeArray* vframe_array) {
aoqi@0 775 // This code is sort of the equivalent of C2IAdapter::setup_stack_frame back in
aoqi@0 776 // the days we had adapter frames. When we deoptimize a situation where a
aoqi@0 777 // compiled caller calls a compiled caller will have registers it expects
aoqi@0 778 // to survive the call to the callee. If we deoptimize the callee the only
aoqi@0 779 // way we can restore these registers is to have the oldest interpreter
aoqi@0 780 // frame that we create restore these values. That is what this routine
aoqi@0 781 // will accomplish.
aoqi@0 782
aoqi@0 783 // At the moment we have modified c2 to not have any callee save registers
aoqi@0 784 // so this problem does not exist and this routine is just a place holder.
aoqi@0 785
aoqi@0 786 assert(f->is_interpreted_frame(), "must be interpreted");
aoqi@0 787 }

mercurial