src/cpu/ppc/vm/interpreter_ppc.cpp

Wed, 27 Nov 2013 16:16:21 -0800

author
goetz
date
Wed, 27 Nov 2013 16:16:21 -0800
changeset 6490
41b780b43b74
parent 6458
ec28f9c041ff
child 6495
67fa91961822
permissions
-rw-r--r--

8029015: PPC64 (part 216): opto: trap based null and range checks
Summary: On PPC64 use tdi instruction that does a compare and raises SIGTRAP for NULL and range checks.
Reviewed-by: kvn

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

mercurial