src/cpu/ppc/vm/cppInterpreter_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 6876
710a3c8b516e
permissions
-rw-r--r--

merge

aoqi@0 1
aoqi@0 2 /*
aoqi@0 3 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
aoqi@0 4 * Copyright 2012, 2014 SAP AG. All rights reserved.
aoqi@0 5 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 6 *
aoqi@0 7 * This code is free software; you can redistribute it and/or modify it
aoqi@0 8 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 9 * published by the Free Software Foundation.
aoqi@0 10 *
aoqi@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 14 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 15 * accompanied this code).
aoqi@0 16 *
aoqi@0 17 * You should have received a copy of the GNU General Public License version
aoqi@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 20 *
aoqi@0 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 22 * or visit www.oracle.com if you need additional information or have any
aoqi@0 23 * questions.
aoqi@0 24 *
aoqi@0 25 */
aoqi@0 26
aoqi@0 27 #include "precompiled.hpp"
aoqi@0 28 #include "asm/assembler.hpp"
aoqi@0 29 #include "asm/macroAssembler.inline.hpp"
aoqi@0 30 #include "interpreter/bytecodeHistogram.hpp"
aoqi@0 31 #include "interpreter/cppInterpreter.hpp"
aoqi@0 32 #include "interpreter/interpreter.hpp"
aoqi@0 33 #include "interpreter/interpreterGenerator.hpp"
aoqi@0 34 #include "interpreter/interpreterRuntime.hpp"
aoqi@0 35 #include "oops/arrayOop.hpp"
aoqi@0 36 #include "oops/methodData.hpp"
aoqi@0 37 #include "oops/method.hpp"
aoqi@0 38 #include "oops/oop.inline.hpp"
aoqi@0 39 #include "prims/jvmtiExport.hpp"
aoqi@0 40 #include "prims/jvmtiThreadState.hpp"
aoqi@0 41 #include "runtime/arguments.hpp"
aoqi@0 42 #include "runtime/deoptimization.hpp"
aoqi@0 43 #include "runtime/frame.inline.hpp"
aoqi@0 44 #include "runtime/interfaceSupport.hpp"
aoqi@0 45 #include "runtime/sharedRuntime.hpp"
aoqi@0 46 #include "runtime/stubRoutines.hpp"
aoqi@0 47 #include "runtime/synchronizer.hpp"
aoqi@0 48 #include "runtime/timer.hpp"
aoqi@0 49 #include "runtime/vframeArray.hpp"
aoqi@0 50 #include "utilities/debug.hpp"
aoqi@0 51 #ifdef SHARK
aoqi@0 52 #include "shark/shark_globals.hpp"
aoqi@0 53 #endif
aoqi@0 54
aoqi@0 55 #ifdef CC_INTERP
aoqi@0 56
aoqi@0 57 #define __ _masm->
aoqi@0 58
aoqi@0 59 // Contains is used for identifying interpreter frames during a stack-walk.
aoqi@0 60 // A frame with a PC in InterpretMethod must be identified as a normal C frame.
aoqi@0 61 bool CppInterpreter::contains(address pc) {
aoqi@0 62 return _code->contains(pc);
aoqi@0 63 }
aoqi@0 64
aoqi@0 65 #ifdef PRODUCT
aoqi@0 66 #define BLOCK_COMMENT(str) // nothing
aoqi@0 67 #else
aoqi@0 68 #define BLOCK_COMMENT(str) __ block_comment(str)
aoqi@0 69 #endif
aoqi@0 70
aoqi@0 71 #define BIND(label) bind(label); BLOCK_COMMENT(#label ":")
aoqi@0 72
aoqi@0 73 static address interpreter_frame_manager = NULL;
aoqi@0 74 static address frame_manager_specialized_return = NULL;
aoqi@0 75 static address native_entry = NULL;
aoqi@0 76
aoqi@0 77 static address interpreter_return_address = NULL;
aoqi@0 78
aoqi@0 79 static address unctrap_frame_manager_entry = NULL;
aoqi@0 80
aoqi@0 81 static address deopt_frame_manager_return_atos = NULL;
aoqi@0 82 static address deopt_frame_manager_return_btos = NULL;
aoqi@0 83 static address deopt_frame_manager_return_itos = NULL;
aoqi@0 84 static address deopt_frame_manager_return_ltos = NULL;
aoqi@0 85 static address deopt_frame_manager_return_ftos = NULL;
aoqi@0 86 static address deopt_frame_manager_return_dtos = NULL;
aoqi@0 87 static address deopt_frame_manager_return_vtos = NULL;
aoqi@0 88
aoqi@0 89 // A result handler converts/unboxes a native call result into
aoqi@0 90 // a java interpreter/compiler result. The current frame is an
aoqi@0 91 // interpreter frame.
aoqi@0 92 address CppInterpreterGenerator::generate_result_handler_for(BasicType type) {
aoqi@0 93 return AbstractInterpreterGenerator::generate_result_handler_for(type);
aoqi@0 94 }
aoqi@0 95
aoqi@0 96 // tosca based result to c++ interpreter stack based result.
aoqi@0 97 address CppInterpreterGenerator::generate_tosca_to_stack_converter(BasicType type) {
aoqi@0 98 //
aoqi@0 99 // A result is in the native abi result register from a native
aoqi@0 100 // method call. We need to return this result to the interpreter by
aoqi@0 101 // pushing the result on the interpreter's stack.
aoqi@0 102 //
aoqi@0 103 // Registers alive:
aoqi@0 104 // R3_ARG1(R3_RET)/F1_ARG1(F1_RET) - result to move
aoqi@0 105 // R4_ARG2 - address of tos
aoqi@0 106 // LR
aoqi@0 107 //
aoqi@0 108 // Registers updated:
aoqi@0 109 // R3_RET(R3_ARG1) - address of new tos (== R17_tos for T_VOID)
aoqi@0 110 //
aoqi@0 111
aoqi@0 112 int number_of_used_slots = 1;
aoqi@0 113
aoqi@0 114 const Register tos = R4_ARG2;
aoqi@0 115 Label done;
aoqi@0 116 Label is_false;
aoqi@0 117
aoqi@0 118 address entry = __ pc();
aoqi@0 119
aoqi@0 120 switch (type) {
aoqi@0 121 case T_BOOLEAN:
aoqi@0 122 __ cmpwi(CCR0, R3_RET, 0);
aoqi@0 123 __ beq(CCR0, is_false);
aoqi@0 124 __ li(R3_RET, 1);
aoqi@0 125 __ stw(R3_RET, 0, tos);
aoqi@0 126 __ b(done);
aoqi@0 127 __ bind(is_false);
aoqi@0 128 __ li(R3_RET, 0);
aoqi@0 129 __ stw(R3_RET, 0, tos);
aoqi@0 130 break;
aoqi@0 131 case T_BYTE:
aoqi@0 132 case T_CHAR:
aoqi@0 133 case T_SHORT:
aoqi@0 134 case T_INT:
aoqi@0 135 __ stw(R3_RET, 0, tos);
aoqi@0 136 break;
aoqi@0 137 case T_LONG:
aoqi@0 138 number_of_used_slots = 2;
aoqi@0 139 // mark unused slot for debugging
aoqi@0 140 // long goes to topmost slot
aoqi@0 141 __ std(R3_RET, -BytesPerWord, tos);
aoqi@0 142 __ li(R3_RET, 0);
aoqi@0 143 __ std(R3_RET, 0, tos);
aoqi@0 144 break;
aoqi@0 145 case T_OBJECT:
aoqi@0 146 __ verify_oop(R3_RET);
aoqi@0 147 __ std(R3_RET, 0, tos);
aoqi@0 148 break;
aoqi@0 149 case T_FLOAT:
aoqi@0 150 __ stfs(F1_RET, 0, tos);
aoqi@0 151 break;
aoqi@0 152 case T_DOUBLE:
aoqi@0 153 number_of_used_slots = 2;
aoqi@0 154 // mark unused slot for debugging
aoqi@0 155 __ li(R3_RET, 0);
aoqi@0 156 __ std(R3_RET, 0, tos);
aoqi@0 157 // double goes to topmost slot
aoqi@0 158 __ stfd(F1_RET, -BytesPerWord, tos);
aoqi@0 159 break;
aoqi@0 160 case T_VOID:
aoqi@0 161 number_of_used_slots = 0;
aoqi@0 162 break;
aoqi@0 163 default:
aoqi@0 164 ShouldNotReachHere();
aoqi@0 165 }
aoqi@0 166
aoqi@0 167 __ BIND(done);
aoqi@0 168
aoqi@0 169 // new expression stack top
aoqi@0 170 __ addi(R3_RET, tos, -BytesPerWord * number_of_used_slots);
aoqi@0 171
aoqi@0 172 __ blr();
aoqi@0 173
aoqi@0 174 return entry;
aoqi@0 175 }
aoqi@0 176
aoqi@0 177 address CppInterpreterGenerator::generate_stack_to_stack_converter(BasicType type) {
aoqi@0 178 //
aoqi@0 179 // Copy the result from the callee's stack to the caller's stack,
aoqi@0 180 // caller and callee both being interpreted.
aoqi@0 181 //
aoqi@0 182 // Registers alive
aoqi@0 183 // R3_ARG1 - address of callee's tos + BytesPerWord
aoqi@0 184 // R4_ARG2 - address of caller's tos [i.e. free location]
aoqi@0 185 // LR
aoqi@0 186 //
aoqi@0 187 // stack grows upwards, memory grows downwards.
aoqi@0 188 //
aoqi@0 189 // [ free ] <-- callee's tos
aoqi@0 190 // [ optional result ] <-- R3_ARG1
aoqi@0 191 // [ optional dummy ]
aoqi@0 192 // ...
aoqi@0 193 // [ free ] <-- caller's tos, R4_ARG2
aoqi@0 194 // ...
aoqi@0 195 // Registers updated
aoqi@0 196 // R3_RET(R3_ARG1) - address of caller's new tos
aoqi@0 197 //
aoqi@0 198 // stack grows upwards, memory grows downwards.
aoqi@0 199 //
aoqi@0 200 // [ free ] <-- current tos, R3_RET
aoqi@0 201 // [ optional result ]
aoqi@0 202 // [ optional dummy ]
aoqi@0 203 // ...
aoqi@0 204 //
aoqi@0 205
aoqi@0 206 const Register from = R3_ARG1;
aoqi@0 207 const Register ret = R3_ARG1;
aoqi@0 208 const Register tos = R4_ARG2;
aoqi@0 209 const Register tmp1 = R21_tmp1;
aoqi@0 210 const Register tmp2 = R22_tmp2;
aoqi@0 211
aoqi@0 212 address entry = __ pc();
aoqi@0 213
aoqi@0 214 switch (type) {
aoqi@0 215 case T_BOOLEAN:
aoqi@0 216 case T_BYTE:
aoqi@0 217 case T_CHAR:
aoqi@0 218 case T_SHORT:
aoqi@0 219 case T_INT:
aoqi@0 220 case T_FLOAT:
aoqi@0 221 __ lwz(tmp1, 0, from);
aoqi@0 222 __ stw(tmp1, 0, tos);
aoqi@0 223 // New expression stack top.
aoqi@0 224 __ addi(ret, tos, - BytesPerWord);
aoqi@0 225 break;
aoqi@0 226 case T_LONG:
aoqi@0 227 case T_DOUBLE:
aoqi@0 228 // Move both entries for debug purposes even though only one is live.
aoqi@0 229 __ ld(tmp1, BytesPerWord, from);
aoqi@0 230 __ ld(tmp2, 0, from);
aoqi@0 231 __ std(tmp1, 0, tos);
aoqi@0 232 __ std(tmp2, -BytesPerWord, tos);
aoqi@0 233 // New expression stack top.
aoqi@0 234 __ addi(ret, tos, - 2 * BytesPerWord); // two slots
aoqi@0 235 break;
aoqi@0 236 case T_OBJECT:
aoqi@0 237 __ ld(tmp1, 0, from);
aoqi@0 238 __ verify_oop(tmp1);
aoqi@0 239 __ std(tmp1, 0, tos);
aoqi@0 240 // New expression stack top.
aoqi@0 241 __ addi(ret, tos, - BytesPerWord);
aoqi@0 242 break;
aoqi@0 243 case T_VOID:
aoqi@0 244 // New expression stack top.
aoqi@0 245 __ mr(ret, tos);
aoqi@0 246 break;
aoqi@0 247 default:
aoqi@0 248 ShouldNotReachHere();
aoqi@0 249 }
aoqi@0 250
aoqi@0 251 __ blr();
aoqi@0 252
aoqi@0 253 return entry;
aoqi@0 254 }
aoqi@0 255
aoqi@0 256 address CppInterpreterGenerator::generate_stack_to_native_abi_converter(BasicType type) {
aoqi@0 257 //
aoqi@0 258 // Load a result from the callee's stack into the caller's expecting
aoqi@0 259 // return register, callee being interpreted, caller being call stub
aoqi@0 260 // or jit code.
aoqi@0 261 //
aoqi@0 262 // Registers alive
aoqi@0 263 // R3_ARG1 - callee expression tos + BytesPerWord
aoqi@0 264 // LR
aoqi@0 265 //
aoqi@0 266 // stack grows upwards, memory grows downwards.
aoqi@0 267 //
aoqi@0 268 // [ free ] <-- callee's tos
aoqi@0 269 // [ optional result ] <-- R3_ARG1
aoqi@0 270 // [ optional dummy ]
aoqi@0 271 // ...
aoqi@0 272 //
aoqi@0 273 // Registers updated
aoqi@0 274 // R3_RET(R3_ARG1)/F1_RET - result
aoqi@0 275 //
aoqi@0 276
aoqi@0 277 const Register from = R3_ARG1;
aoqi@0 278 const Register ret = R3_ARG1;
aoqi@0 279 const FloatRegister fret = F1_ARG1;
aoqi@0 280
aoqi@0 281 address entry = __ pc();
aoqi@0 282
aoqi@0 283 // Implemented uniformly for both kinds of endianness. The interpreter
aoqi@0 284 // implements boolean, byte, char, and short as jint (4 bytes).
aoqi@0 285 switch (type) {
aoqi@0 286 case T_BOOLEAN:
aoqi@0 287 case T_CHAR:
aoqi@0 288 // zero extension
aoqi@0 289 __ lwz(ret, 0, from);
aoqi@0 290 break;
aoqi@0 291 case T_BYTE:
aoqi@0 292 case T_SHORT:
aoqi@0 293 case T_INT:
aoqi@0 294 // sign extension
aoqi@0 295 __ lwa(ret, 0, from);
aoqi@0 296 break;
aoqi@0 297 case T_LONG:
aoqi@0 298 __ ld(ret, 0, from);
aoqi@0 299 break;
aoqi@0 300 case T_OBJECT:
aoqi@0 301 __ ld(ret, 0, from);
aoqi@0 302 __ verify_oop(ret);
aoqi@0 303 break;
aoqi@0 304 case T_FLOAT:
aoqi@0 305 __ lfs(fret, 0, from);
aoqi@0 306 break;
aoqi@0 307 case T_DOUBLE:
aoqi@0 308 __ lfd(fret, 0, from);
aoqi@0 309 break;
aoqi@0 310 case T_VOID:
aoqi@0 311 break;
aoqi@0 312 default:
aoqi@0 313 ShouldNotReachHere();
aoqi@0 314 }
aoqi@0 315
aoqi@0 316 __ blr();
aoqi@0 317
aoqi@0 318 return entry;
aoqi@0 319 }
aoqi@0 320
aoqi@0 321 address CppInterpreter::return_entry(TosState state, int length, Bytecodes::Code code) {
aoqi@0 322 assert(interpreter_return_address != NULL, "Not initialized");
aoqi@0 323 return interpreter_return_address;
aoqi@0 324 }
aoqi@0 325
aoqi@0 326 address CppInterpreter::deopt_entry(TosState state, int length) {
aoqi@0 327 address ret = NULL;
aoqi@0 328 if (length != 0) {
aoqi@0 329 switch (state) {
aoqi@0 330 case atos: ret = deopt_frame_manager_return_atos; break;
aoqi@0 331 case btos: ret = deopt_frame_manager_return_itos; break;
aoqi@0 332 case ctos:
aoqi@0 333 case stos:
aoqi@0 334 case itos: ret = deopt_frame_manager_return_itos; break;
aoqi@0 335 case ltos: ret = deopt_frame_manager_return_ltos; break;
aoqi@0 336 case ftos: ret = deopt_frame_manager_return_ftos; break;
aoqi@0 337 case dtos: ret = deopt_frame_manager_return_dtos; break;
aoqi@0 338 case vtos: ret = deopt_frame_manager_return_vtos; break;
aoqi@0 339 default: ShouldNotReachHere();
aoqi@0 340 }
aoqi@0 341 } else {
aoqi@0 342 ret = unctrap_frame_manager_entry; // re-execute the bytecode (e.g. uncommon trap, popframe)
aoqi@0 343 }
aoqi@0 344 assert(ret != NULL, "Not initialized");
aoqi@0 345 return ret;
aoqi@0 346 }
aoqi@0 347
aoqi@0 348 //
aoqi@0 349 // Helpers for commoning out cases in the various type of method entries.
aoqi@0 350 //
aoqi@0 351
aoqi@0 352 //
aoqi@0 353 // Registers alive
aoqi@0 354 // R16_thread - JavaThread*
aoqi@0 355 // R1_SP - old stack pointer
aoqi@0 356 // R19_method - callee's Method
aoqi@0 357 // R17_tos - address of caller's tos (prepushed)
aoqi@0 358 // R15_prev_state - address of caller's BytecodeInterpreter or 0
aoqi@0 359 // return_pc in R21_tmp15 (only when called within generate_native_entry)
aoqi@0 360 //
aoqi@0 361 // Registers updated
aoqi@0 362 // R14_state - address of callee's interpreter state
aoqi@0 363 // R1_SP - new stack pointer
aoqi@0 364 // CCR4_is_synced - current method is synchronized
aoqi@0 365 //
aoqi@0 366 void CppInterpreterGenerator::generate_compute_interpreter_state(Label& stack_overflow_return) {
aoqi@0 367 //
aoqi@0 368 // Stack layout at this point:
aoqi@0 369 //
aoqi@0 370 // F1 [TOP_IJAVA_FRAME_ABI] <-- R1_SP
aoqi@0 371 // alignment (optional)
aoqi@0 372 // [F1's outgoing Java arguments] <-- R17_tos
aoqi@0 373 // ...
aoqi@0 374 // F2 [PARENT_IJAVA_FRAME_ABI]
aoqi@0 375 // ...
aoqi@0 376
aoqi@0 377 //=============================================================================
aoqi@0 378 // Allocate space for locals other than the parameters, the
aoqi@0 379 // interpreter state, monitors, and the expression stack.
aoqi@0 380
aoqi@0 381 const Register local_count = R21_tmp1;
aoqi@0 382 const Register parameter_count = R22_tmp2;
aoqi@0 383 const Register max_stack = R23_tmp3;
aoqi@0 384 // Must not be overwritten within this method!
aoqi@0 385 // const Register return_pc = R29_tmp9;
aoqi@0 386
aoqi@0 387 const ConditionRegister is_synced = CCR4_is_synced;
aoqi@0 388 const ConditionRegister is_native = CCR6;
aoqi@0 389 const ConditionRegister is_static = CCR7;
aoqi@0 390
aoqi@0 391 assert(is_synced != is_native, "condition code registers must be distinct");
aoqi@0 392 assert(is_synced != is_static, "condition code registers must be distinct");
aoqi@0 393 assert(is_native != is_static, "condition code registers must be distinct");
aoqi@0 394
aoqi@0 395 {
aoqi@0 396
aoqi@0 397 // Local registers
aoqi@0 398 const Register top_frame_size = R24_tmp4;
aoqi@0 399 const Register access_flags = R25_tmp5;
aoqi@0 400 const Register state_offset = R26_tmp6;
aoqi@0 401 Register mem_stack_limit = R27_tmp7;
aoqi@0 402 const Register page_size = R28_tmp8;
aoqi@0 403
aoqi@0 404 BLOCK_COMMENT("compute_interpreter_state {");
aoqi@0 405
aoqi@0 406 // access_flags = method->access_flags();
aoqi@0 407 // TODO: PPC port: assert(4 == sizeof(AccessFlags), "unexpected field size");
aoqi@0 408 __ lwa(access_flags, method_(access_flags));
aoqi@0 409
aoqi@0 410 // parameter_count = method->constMethod->size_of_parameters();
aoqi@0 411 // TODO: PPC port: assert(2 == ConstMethod::sz_size_of_parameters(), "unexpected field size");
aoqi@0 412 __ ld(max_stack, in_bytes(Method::const_offset()), R19_method); // Max_stack holds constMethod for a while.
aoqi@0 413 __ lhz(parameter_count, in_bytes(ConstMethod::size_of_parameters_offset()), max_stack);
aoqi@0 414
aoqi@0 415 // local_count = method->constMethod()->max_locals();
aoqi@0 416 // TODO: PPC port: assert(2 == ConstMethod::sz_max_locals(), "unexpected field size");
aoqi@0 417 __ lhz(local_count, in_bytes(ConstMethod::size_of_locals_offset()), max_stack);
aoqi@0 418
aoqi@0 419 // max_stack = method->constMethod()->max_stack();
aoqi@0 420 // TODO: PPC port: assert(2 == ConstMethod::sz_max_stack(), "unexpected field size");
aoqi@0 421 __ lhz(max_stack, in_bytes(ConstMethod::max_stack_offset()), max_stack);
aoqi@0 422
aoqi@0 423 if (EnableInvokeDynamic) {
aoqi@0 424 // Take into account 'extra_stack_entries' needed by method handles (see method.hpp).
aoqi@0 425 __ addi(max_stack, max_stack, Method::extra_stack_entries());
aoqi@0 426 }
aoqi@0 427
aoqi@0 428 // mem_stack_limit = thread->stack_limit();
aoqi@0 429 __ ld(mem_stack_limit, thread_(stack_overflow_limit));
aoqi@0 430
aoqi@0 431 // Point locals at the first argument. Method's locals are the
aoqi@0 432 // parameters on top of caller's expression stack.
aoqi@0 433
aoqi@0 434 // tos points past last Java argument
aoqi@0 435 __ sldi(R18_locals, parameter_count, Interpreter::logStackElementSize);
aoqi@0 436 __ add(R18_locals, R17_tos, R18_locals);
aoqi@0 437
aoqi@0 438 // R18_locals - i*BytesPerWord points to i-th Java local (i starts at 0)
aoqi@0 439
aoqi@0 440 // Set is_native, is_synced, is_static - will be used later.
aoqi@0 441 __ testbitdi(is_native, R0, access_flags, JVM_ACC_NATIVE_BIT);
aoqi@0 442 __ testbitdi(is_synced, R0, access_flags, JVM_ACC_SYNCHRONIZED_BIT);
aoqi@0 443 assert(is_synced->is_nonvolatile(), "is_synced must be non-volatile");
aoqi@0 444 __ testbitdi(is_static, R0, access_flags, JVM_ACC_STATIC_BIT);
aoqi@0 445
aoqi@0 446 // PARENT_IJAVA_FRAME_ABI
aoqi@0 447 //
aoqi@0 448 // frame_size =
aoqi@0 449 // round_to((local_count - parameter_count)*BytesPerWord +
aoqi@0 450 // 2*BytesPerWord +
aoqi@0 451 // alignment +
aoqi@0 452 // frame::interpreter_frame_cinterpreterstate_size_in_bytes()
aoqi@0 453 // sizeof(PARENT_IJAVA_FRAME_ABI)
aoqi@0 454 // method->is_synchronized() ? sizeof(BasicObjectLock) : 0 +
aoqi@0 455 // max_stack*BytesPerWord,
aoqi@0 456 // 16)
aoqi@0 457 //
aoqi@0 458 // Note that this calculation is exactly mirrored by
aoqi@0 459 // AbstractInterpreter::layout_activation_impl() [ and
aoqi@0 460 // AbstractInterpreter::size_activation() ]. Which is used by
aoqi@0 461 // deoptimization so that it can allocate the proper sized
aoqi@0 462 // frame. This only happens for interpreted frames so the extra
aoqi@0 463 // notes below about max_stack below are not important. The other
aoqi@0 464 // thing to note is that for interpreter frames other than the
aoqi@0 465 // current activation the size of the stack is the size of the live
aoqi@0 466 // portion of the stack at the particular bcp and NOT the maximum
aoqi@0 467 // stack that the method might use.
aoqi@0 468 //
aoqi@0 469 // If we're calling a native method, we replace max_stack (which is
aoqi@0 470 // zero) with space for the worst-case signature handler varargs
aoqi@0 471 // vector, which is:
aoqi@0 472 //
aoqi@0 473 // max_stack = max(Argument::n_register_parameters, parameter_count+2);
aoqi@0 474 //
aoqi@0 475 // We add two slots to the parameter_count, one for the jni
aoqi@0 476 // environment and one for a possible native mirror. We allocate
aoqi@0 477 // space for at least the number of ABI registers, even though
aoqi@0 478 // InterpreterRuntime::slow_signature_handler won't write more than
aoqi@0 479 // parameter_count+2 words when it creates the varargs vector at the
aoqi@0 480 // top of the stack. The generated slow signature handler will just
aoqi@0 481 // load trash into registers beyond the necessary number. We're
aoqi@0 482 // still going to cut the stack back by the ABI register parameter
aoqi@0 483 // count so as to get SP+16 pointing at the ABI outgoing parameter
aoqi@0 484 // area, so we need to allocate at least that much even though we're
aoqi@0 485 // going to throw it away.
aoqi@0 486 //
aoqi@0 487
aoqi@0 488 // Adjust max_stack for native methods:
aoqi@0 489 Label skip_native_calculate_max_stack;
aoqi@0 490 __ bfalse(is_native, skip_native_calculate_max_stack);
aoqi@0 491 // if (is_native) {
aoqi@0 492 // max_stack = max(Argument::n_register_parameters, parameter_count+2);
aoqi@0 493 __ addi(max_stack, parameter_count, 2*Interpreter::stackElementWords);
aoqi@0 494 __ cmpwi(CCR0, max_stack, Argument::n_register_parameters);
aoqi@0 495 __ bge(CCR0, skip_native_calculate_max_stack);
aoqi@0 496 __ li(max_stack, Argument::n_register_parameters);
aoqi@0 497 // }
aoqi@0 498 __ bind(skip_native_calculate_max_stack);
aoqi@0 499 // max_stack is now in bytes
aoqi@0 500 __ slwi(max_stack, max_stack, Interpreter::logStackElementSize);
aoqi@0 501
aoqi@0 502 // Calculate number of non-parameter locals (in slots):
aoqi@0 503 Label not_java;
aoqi@0 504 __ btrue(is_native, not_java);
aoqi@0 505 // if (!is_native) {
aoqi@0 506 // local_count = non-parameter local count
aoqi@0 507 __ sub(local_count, local_count, parameter_count);
aoqi@0 508 // } else {
aoqi@0 509 // // nothing to do: method->max_locals() == 0 for native methods
aoqi@0 510 // }
aoqi@0 511 __ bind(not_java);
aoqi@0 512
aoqi@0 513
aoqi@0 514 // Calculate top_frame_size and parent_frame_resize.
aoqi@0 515 {
aoqi@0 516 const Register parent_frame_resize = R12_scratch2;
aoqi@0 517
aoqi@0 518 BLOCK_COMMENT("Compute top_frame_size.");
aoqi@0 519 // top_frame_size = TOP_IJAVA_FRAME_ABI
aoqi@0 520 // + size of interpreter state
aoqi@0 521 __ li(top_frame_size, frame::top_ijava_frame_abi_size
aoqi@0 522 + frame::interpreter_frame_cinterpreterstate_size_in_bytes());
aoqi@0 523 // + max_stack
aoqi@0 524 __ add(top_frame_size, top_frame_size, max_stack);
aoqi@0 525 // + stack slots for a BasicObjectLock for synchronized methods
aoqi@0 526 {
aoqi@0 527 Label not_synced;
aoqi@0 528 __ bfalse(is_synced, not_synced);
aoqi@0 529 __ addi(top_frame_size, top_frame_size, frame::interpreter_frame_monitor_size_in_bytes());
aoqi@0 530 __ bind(not_synced);
aoqi@0 531 }
aoqi@0 532 // align
aoqi@0 533 __ round_to(top_frame_size, frame::alignment_in_bytes);
aoqi@0 534
aoqi@0 535
aoqi@0 536 BLOCK_COMMENT("Compute parent_frame_resize.");
aoqi@0 537 // parent_frame_resize = R1_SP - R17_tos
aoqi@0 538 __ sub(parent_frame_resize, R1_SP, R17_tos);
aoqi@0 539 //__ li(parent_frame_resize, 0);
aoqi@0 540 // + PARENT_IJAVA_FRAME_ABI
aoqi@0 541 // + extra two slots for the no-parameter/no-locals
aoqi@0 542 // method result
aoqi@0 543 __ addi(parent_frame_resize, parent_frame_resize,
aoqi@0 544 frame::parent_ijava_frame_abi_size
aoqi@0 545 + 2*Interpreter::stackElementSize);
aoqi@0 546 // + (locals_count - params_count)
aoqi@0 547 __ sldi(R0, local_count, Interpreter::logStackElementSize);
aoqi@0 548 __ add(parent_frame_resize, parent_frame_resize, R0);
aoqi@0 549 // align
aoqi@0 550 __ round_to(parent_frame_resize, frame::alignment_in_bytes);
aoqi@0 551
aoqi@0 552 //
aoqi@0 553 // Stack layout at this point:
aoqi@0 554 //
aoqi@0 555 // The new frame F0 hasn't yet been pushed, F1 is still the top frame.
aoqi@0 556 //
aoqi@0 557 // F0 [TOP_IJAVA_FRAME_ABI]
aoqi@0 558 // alignment (optional)
aoqi@0 559 // [F0's full operand stack]
aoqi@0 560 // [F0's monitors] (optional)
aoqi@0 561 // [F0's BytecodeInterpreter object]
aoqi@0 562 // F1 [PARENT_IJAVA_FRAME_ABI]
aoqi@0 563 // alignment (optional)
aoqi@0 564 // [F0's Java result]
aoqi@0 565 // [F0's non-arg Java locals]
aoqi@0 566 // [F1's outgoing Java arguments] <-- R17_tos
aoqi@0 567 // ...
aoqi@0 568 // F2 [PARENT_IJAVA_FRAME_ABI]
aoqi@0 569 // ...
aoqi@0 570
aoqi@0 571
aoqi@0 572 // Calculate new R14_state
aoqi@0 573 // and
aoqi@0 574 // test that the new memory stack pointer is above the limit,
aoqi@0 575 // throw a StackOverflowError otherwise.
aoqi@0 576 __ sub(R11_scratch1/*F1's SP*/, R1_SP, parent_frame_resize);
aoqi@0 577 __ addi(R14_state, R11_scratch1/*F1's SP*/,
aoqi@0 578 -frame::interpreter_frame_cinterpreterstate_size_in_bytes());
aoqi@0 579 __ sub(R11_scratch1/*F0's SP*/,
aoqi@0 580 R11_scratch1/*F1's SP*/, top_frame_size);
aoqi@0 581
aoqi@0 582 BLOCK_COMMENT("Test for stack overflow:");
aoqi@0 583 __ cmpld(CCR0/*is_stack_overflow*/, R11_scratch1, mem_stack_limit);
aoqi@0 584 __ blt(CCR0/*is_stack_overflow*/, stack_overflow_return);
aoqi@0 585
aoqi@0 586
aoqi@0 587 //=============================================================================
aoqi@0 588 // Frame_size doesn't overflow the stack. Allocate new frame and
aoqi@0 589 // initialize interpreter state.
aoqi@0 590
aoqi@0 591 // Register state
aoqi@0 592 //
aoqi@0 593 // R15 - local_count
aoqi@0 594 // R16 - parameter_count
aoqi@0 595 // R17 - max_stack
aoqi@0 596 //
aoqi@0 597 // R18 - frame_size
aoqi@0 598 // R19 - access_flags
aoqi@0 599 // CCR4_is_synced - is_synced
aoqi@0 600 //
aoqi@0 601 // GR_Lstate - pointer to the uninitialized new BytecodeInterpreter.
aoqi@0 602
aoqi@0 603 // _last_Java_pc just needs to be close enough that we can identify
aoqi@0 604 // the frame as an interpreted frame. It does not need to be the
aoqi@0 605 // exact return address from either calling
aoqi@0 606 // BytecodeInterpreter::InterpretMethod or the call to a jni native method.
aoqi@0 607 // So we can initialize it here with a value of a bundle in this
aoqi@0 608 // code fragment. We only do this initialization for java frames
aoqi@0 609 // where InterpretMethod needs a a way to get a good pc value to
aoqi@0 610 // store in the thread state. For interpreter frames used to call
aoqi@0 611 // jni native code we just zero the value in the state and move an
aoqi@0 612 // ip as needed in the native entry code.
aoqi@0 613 //
aoqi@0 614 // const Register last_Java_pc_addr = GR24_SCRATCH; // QQQ 27
aoqi@0 615 // const Register last_Java_pc = GR26_SCRATCH;
aoqi@0 616
aoqi@0 617 // Must reference stack before setting new SP since Windows
aoqi@0 618 // will not be able to deliver the exception on a bad SP.
aoqi@0 619 // Windows also insists that we bang each page one at a time in order
aoqi@0 620 // for the OS to map in the reserved pages. If we bang only
aoqi@0 621 // the final page, Windows stops delivering exceptions to our
aoqi@0 622 // VectoredExceptionHandler and terminates our program.
aoqi@0 623 // Linux only requires a single bang but it's rare to have
aoqi@0 624 // to bang more than 1 page so the code is enabled for both OS's.
aoqi@0 625
aoqi@0 626 // BANG THE STACK
aoqi@0 627 //
aoqi@0 628 // Nothing to do for PPC, because updating the SP will automatically
aoqi@0 629 // bang the page.
aoqi@0 630
aoqi@0 631 // Up to here we have calculated the delta for the new C-frame and
aoqi@0 632 // checked for a stack-overflow. Now we can savely update SP and
aoqi@0 633 // resize the C-frame.
aoqi@0 634
aoqi@0 635 // R14_state has already been calculated.
aoqi@0 636 __ push_interpreter_frame(top_frame_size, parent_frame_resize,
aoqi@0 637 R25_tmp5, R26_tmp6, R27_tmp7, R28_tmp8);
aoqi@0 638
aoqi@0 639 }
aoqi@0 640
aoqi@0 641 //
aoqi@0 642 // Stack layout at this point:
aoqi@0 643 //
aoqi@0 644 // F0 has been been pushed!
aoqi@0 645 //
aoqi@0 646 // F0 [TOP_IJAVA_FRAME_ABI] <-- R1_SP
aoqi@0 647 // alignment (optional) (now it's here, if required)
aoqi@0 648 // [F0's full operand stack]
aoqi@0 649 // [F0's monitors] (optional)
aoqi@0 650 // [F0's BytecodeInterpreter object]
aoqi@0 651 // F1 [PARENT_IJAVA_FRAME_ABI]
aoqi@0 652 // alignment (optional) (now it's here, if required)
aoqi@0 653 // [F0's Java result]
aoqi@0 654 // [F0's non-arg Java locals]
aoqi@0 655 // [F1's outgoing Java arguments]
aoqi@0 656 // ...
aoqi@0 657 // F2 [PARENT_IJAVA_FRAME_ABI]
aoqi@0 658 // ...
aoqi@0 659 //
aoqi@0 660 // R14_state points to F0's BytecodeInterpreter object.
aoqi@0 661 //
aoqi@0 662
aoqi@0 663 }
aoqi@0 664
aoqi@0 665 //=============================================================================
aoqi@0 666 // new BytecodeInterpreter-object is save, let's initialize it:
aoqi@0 667 BLOCK_COMMENT("New BytecodeInterpreter-object is save.");
aoqi@0 668
aoqi@0 669 {
aoqi@0 670 // Locals
aoqi@0 671 const Register bytecode_addr = R24_tmp4;
aoqi@0 672 const Register constants = R25_tmp5;
aoqi@0 673 const Register tos = R26_tmp6;
aoqi@0 674 const Register stack_base = R27_tmp7;
aoqi@0 675 const Register local_addr = R28_tmp8;
aoqi@0 676 {
aoqi@0 677 Label L;
aoqi@0 678 __ btrue(is_native, L);
aoqi@0 679 // if (!is_native) {
aoqi@0 680 // bytecode_addr = constMethod->codes();
aoqi@0 681 __ ld(bytecode_addr, method_(const));
aoqi@0 682 __ addi(bytecode_addr, bytecode_addr, in_bytes(ConstMethod::codes_offset()));
aoqi@0 683 // }
aoqi@0 684 __ bind(L);
aoqi@0 685 }
aoqi@0 686
aoqi@0 687 __ ld(constants, in_bytes(Method::const_offset()), R19_method);
aoqi@0 688 __ ld(constants, in_bytes(ConstMethod::constants_offset()), constants);
aoqi@0 689
aoqi@0 690 // state->_prev_link = prev_state;
aoqi@0 691 __ std(R15_prev_state, state_(_prev_link));
aoqi@0 692
aoqi@0 693 // For assertions only.
aoqi@0 694 // TODO: not needed anyway because it coincides with `_monitor_base'. remove!
aoqi@0 695 // state->_self_link = state;
aoqi@0 696 DEBUG_ONLY(__ std(R14_state, state_(_self_link));)
aoqi@0 697
aoqi@0 698 // state->_thread = thread;
aoqi@0 699 __ std(R16_thread, state_(_thread));
aoqi@0 700
aoqi@0 701 // state->_method = method;
aoqi@0 702 __ std(R19_method, state_(_method));
aoqi@0 703
aoqi@0 704 // state->_locals = locals;
aoqi@0 705 __ std(R18_locals, state_(_locals));
aoqi@0 706
aoqi@0 707 // state->_oop_temp = NULL;
aoqi@0 708 __ li(R0, 0);
aoqi@0 709 __ std(R0, state_(_oop_temp));
aoqi@0 710
aoqi@0 711 // state->_last_Java_fp = *R1_SP // Use *R1_SP as fp
aoqi@0 712 __ ld(R0, _abi(callers_sp), R1_SP);
aoqi@0 713 __ std(R0, state_(_last_Java_fp));
aoqi@0 714
aoqi@0 715 BLOCK_COMMENT("load Stack base:");
aoqi@0 716 {
aoqi@0 717 // Stack_base.
aoqi@0 718 // if (!method->synchronized()) {
aoqi@0 719 // stack_base = state;
aoqi@0 720 // } else {
aoqi@0 721 // stack_base = (uintptr_t)state - sizeof(BasicObjectLock);
aoqi@0 722 // }
aoqi@0 723 Label L;
aoqi@0 724 __ mr(stack_base, R14_state);
aoqi@0 725 __ bfalse(is_synced, L);
aoqi@0 726 __ addi(stack_base, stack_base, -frame::interpreter_frame_monitor_size_in_bytes());
aoqi@0 727 __ bind(L);
aoqi@0 728 }
aoqi@0 729
aoqi@0 730 // state->_mdx = NULL;
aoqi@0 731 __ li(R0, 0);
aoqi@0 732 __ std(R0, state_(_mdx));
aoqi@0 733
aoqi@0 734 {
aoqi@0 735 // if (method->is_native()) state->_bcp = NULL;
aoqi@0 736 // else state->_bcp = bytecode_addr;
aoqi@0 737 Label label1, label2;
aoqi@0 738 __ bfalse(is_native, label1);
aoqi@0 739 __ std(R0, state_(_bcp));
aoqi@0 740 __ b(label2);
aoqi@0 741 __ bind(label1);
aoqi@0 742 __ std(bytecode_addr, state_(_bcp));
aoqi@0 743 __ bind(label2);
aoqi@0 744 }
aoqi@0 745
aoqi@0 746
aoqi@0 747 // state->_result._to_call._callee = NULL;
aoqi@0 748 __ std(R0, state_(_result._to_call._callee));
aoqi@0 749
aoqi@0 750 // state->_monitor_base = state;
aoqi@0 751 __ std(R14_state, state_(_monitor_base));
aoqi@0 752
aoqi@0 753 // state->_msg = BytecodeInterpreter::method_entry;
aoqi@0 754 __ li(R0, BytecodeInterpreter::method_entry);
aoqi@0 755 __ stw(R0, state_(_msg));
aoqi@0 756
aoqi@0 757 // state->_last_Java_sp = R1_SP;
aoqi@0 758 __ std(R1_SP, state_(_last_Java_sp));
aoqi@0 759
aoqi@0 760 // state->_stack_base = stack_base;
aoqi@0 761 __ std(stack_base, state_(_stack_base));
aoqi@0 762
aoqi@0 763 // tos = stack_base - 1 slot (prepushed);
aoqi@0 764 // state->_stack.Tos(tos);
aoqi@0 765 __ addi(tos, stack_base, - Interpreter::stackElementSize);
aoqi@0 766 __ std(tos, state_(_stack));
aoqi@0 767
aoqi@0 768
aoqi@0 769 {
aoqi@0 770 BLOCK_COMMENT("get last_Java_pc:");
aoqi@0 771 // if (!is_native) state->_last_Java_pc = <some_ip_in_this_code_buffer>;
aoqi@0 772 // else state->_last_Java_pc = NULL; (just for neatness)
aoqi@0 773 Label label1, label2;
aoqi@0 774 __ btrue(is_native, label1);
aoqi@0 775 __ get_PC_trash_LR(R0);
aoqi@0 776 __ std(R0, state_(_last_Java_pc));
aoqi@0 777 __ b(label2);
aoqi@0 778 __ bind(label1);
aoqi@0 779 __ li(R0, 0);
aoqi@0 780 __ std(R0, state_(_last_Java_pc));
aoqi@0 781 __ bind(label2);
aoqi@0 782 }
aoqi@0 783
aoqi@0 784
aoqi@0 785 // stack_limit = tos - max_stack;
aoqi@0 786 __ sub(R0, tos, max_stack);
aoqi@0 787 // state->_stack_limit = stack_limit;
aoqi@0 788 __ std(R0, state_(_stack_limit));
aoqi@0 789
aoqi@0 790
aoqi@0 791 // cache = method->constants()->cache();
aoqi@0 792 __ ld(R0, ConstantPool::cache_offset_in_bytes(), constants);
aoqi@0 793 // state->_constants = method->constants()->cache();
aoqi@0 794 __ std(R0, state_(_constants));
aoqi@0 795
aoqi@0 796
aoqi@0 797
aoqi@0 798 //=============================================================================
aoqi@0 799 // synchronized method, allocate and initialize method object lock.
aoqi@0 800 // if (!method->is_synchronized()) goto fill_locals_with_0x0s;
aoqi@0 801 Label fill_locals_with_0x0s;
aoqi@0 802 __ bfalse(is_synced, fill_locals_with_0x0s);
aoqi@0 803
aoqi@0 804 // pool_holder = method->constants()->pool_holder();
aoqi@0 805 const int mirror_offset = in_bytes(Klass::java_mirror_offset());
aoqi@0 806 {
aoqi@0 807 Label label1, label2;
aoqi@0 808 // lockee = NULL; for java methods, correct value will be inserted in BytecodeInterpretMethod.hpp
aoqi@0 809 __ li(R0,0);
aoqi@0 810 __ bfalse(is_native, label2);
aoqi@0 811
aoqi@0 812 __ bfalse(is_static, label1);
aoqi@0 813 // if (method->is_static()) lockee =
aoqi@0 814 // pool_holder->klass_part()->java_mirror();
aoqi@0 815 __ ld(R11_scratch1/*pool_holder*/, ConstantPool::pool_holder_offset_in_bytes(), constants);
aoqi@0 816 __ ld(R0/*lockee*/, mirror_offset, R11_scratch1/*pool_holder*/);
aoqi@0 817 __ b(label2);
aoqi@0 818
aoqi@0 819 __ bind(label1);
aoqi@0 820 // else lockee = *(oop*)locals;
aoqi@0 821 __ ld(R0/*lockee*/, 0, R18_locals);
aoqi@0 822 __ bind(label2);
aoqi@0 823
aoqi@0 824 // monitor->set_obj(lockee);
aoqi@0 825 __ std(R0/*lockee*/, BasicObjectLock::obj_offset_in_bytes(), stack_base);
aoqi@0 826 }
aoqi@0 827
aoqi@0 828 // See if we need to zero the locals
aoqi@0 829 __ BIND(fill_locals_with_0x0s);
aoqi@0 830
aoqi@0 831
aoqi@0 832 //=============================================================================
aoqi@0 833 // fill locals with 0x0s
aoqi@0 834 Label locals_zeroed;
aoqi@0 835 __ btrue(is_native, locals_zeroed);
aoqi@0 836
aoqi@0 837 if (true /* zerolocals */ || ClearInterpreterLocals) {
aoqi@0 838 // local_count is already num_locals_slots - num_param_slots
aoqi@0 839 __ sldi(R0, parameter_count, Interpreter::logStackElementSize);
aoqi@0 840 __ sub(local_addr, R18_locals, R0);
aoqi@0 841 __ cmpdi(CCR0, local_count, 0);
aoqi@0 842 __ ble(CCR0, locals_zeroed);
aoqi@0 843
aoqi@0 844 __ mtctr(local_count);
aoqi@0 845 //__ ld_const_addr(R0, (address) 0xcafe0000babe);
aoqi@0 846 __ li(R0, 0);
aoqi@0 847
aoqi@0 848 Label zero_slot;
aoqi@0 849 __ bind(zero_slot);
aoqi@0 850
aoqi@0 851 // first local is at local_addr
aoqi@0 852 __ std(R0, 0, local_addr);
aoqi@0 853 __ addi(local_addr, local_addr, -BytesPerWord);
aoqi@0 854 __ bdnz(zero_slot);
aoqi@0 855 }
aoqi@0 856
aoqi@0 857 __ BIND(locals_zeroed);
aoqi@0 858
aoqi@0 859 }
aoqi@0 860 BLOCK_COMMENT("} compute_interpreter_state");
aoqi@0 861 }
aoqi@0 862
aoqi@0 863 // Generate code to initiate compilation on invocation counter overflow.
aoqi@0 864 void CppInterpreterGenerator::generate_counter_overflow(Label& continue_entry) {
aoqi@0 865 // Registers alive
aoqi@0 866 // R14_state
aoqi@0 867 // R16_thread
aoqi@0 868 //
aoqi@0 869 // Registers updated
aoqi@0 870 // R14_state
aoqi@0 871 // R3_ARG1 (=R3_RET)
aoqi@0 872 // R4_ARG2
aoqi@0 873
aoqi@0 874 // After entering the vm we remove the activation and retry the
aoqi@0 875 // entry point in case the compilation is complete.
aoqi@0 876
aoqi@0 877 // InterpreterRuntime::frequency_counter_overflow takes one argument
aoqi@0 878 // that indicates if the counter overflow occurs at a backwards
aoqi@0 879 // branch (NULL bcp). We pass zero. The call returns the address
aoqi@0 880 // of the verified entry point for the method or NULL if the
aoqi@0 881 // compilation did not complete (either went background or bailed
aoqi@0 882 // out).
aoqi@0 883 __ li(R4_ARG2, 0);
aoqi@0 884
aoqi@0 885 // Pass false to call_VM so it doesn't check for pending exceptions,
aoqi@0 886 // since at this point in the method invocation the exception
aoqi@0 887 // handler would try to exit the monitor of synchronized methods
aoqi@0 888 // which haven't been entered yet.
aoqi@0 889 //
aoqi@0 890 // Returns verified_entry_point or NULL, we don't care which.
aoqi@0 891 //
aoqi@0 892 // Do not use the variant `frequency_counter_overflow' that returns
aoqi@0 893 // a structure, because this will change the argument list by a
aoqi@0 894 // hidden parameter (gcc 4.1).
aoqi@0 895
aoqi@0 896 __ call_VM(noreg,
aoqi@0 897 CAST_FROM_FN_PTR(address, InterpreterRuntime::frequency_counter_overflow),
aoqi@0 898 R4_ARG2,
aoqi@0 899 false);
aoqi@0 900 // Returns verified_entry_point or NULL, we don't care which as we ignore it
aoqi@0 901 // and run interpreted.
aoqi@0 902
aoqi@0 903 // Reload method, it may have moved.
aoqi@0 904 __ ld(R19_method, state_(_method));
aoqi@0 905
aoqi@0 906 // We jump now to the label "continue_after_compile".
aoqi@0 907 __ b(continue_entry);
aoqi@0 908 }
aoqi@0 909
aoqi@0 910 // Increment invocation count and check for overflow.
aoqi@0 911 //
aoqi@0 912 // R19_method must contain Method* of method to profile.
aoqi@0 913 void CppInterpreterGenerator::generate_counter_incr(Label& overflow) {
aoqi@0 914 Label done;
aoqi@0 915 const Register Rcounters = R12_scratch2;
aoqi@0 916 const Register iv_be_count = R11_scratch1;
aoqi@0 917 const Register invocation_limit = R12_scratch2;
aoqi@0 918 const Register invocation_limit_addr = invocation_limit;
aoqi@0 919
aoqi@0 920 // Load and ev. allocate MethodCounters object.
aoqi@0 921 __ get_method_counters(R19_method, Rcounters, done);
aoqi@0 922
aoqi@0 923 // Update standard invocation counters.
aoqi@0 924 __ increment_invocation_counter(Rcounters, iv_be_count, R0);
aoqi@0 925
aoqi@0 926 // Compare against limit.
aoqi@0 927 BLOCK_COMMENT("Compare counter against limit:");
aoqi@0 928 assert(4 == sizeof(InvocationCounter::InterpreterInvocationLimit),
aoqi@0 929 "must be 4 bytes");
aoqi@0 930 __ load_const(invocation_limit_addr, (address)&InvocationCounter::InterpreterInvocationLimit);
aoqi@0 931 __ lwa(invocation_limit, 0, invocation_limit_addr);
aoqi@0 932 __ cmpw(CCR0, iv_be_count, invocation_limit);
aoqi@0 933 __ bge(CCR0, overflow);
aoqi@0 934 __ bind(done);
aoqi@0 935 }
aoqi@0 936
aoqi@0 937 //
aoqi@0 938 // Call a JNI method.
aoqi@0 939 //
aoqi@0 940 // Interpreter stub for calling a native method. (C++ interpreter)
aoqi@0 941 // This sets up a somewhat different looking stack for calling the native method
aoqi@0 942 // than the typical interpreter frame setup.
aoqi@0 943 //
aoqi@0 944 address CppInterpreterGenerator::generate_native_entry(void) {
aoqi@0 945 if (native_entry != NULL) return native_entry;
aoqi@0 946 address entry = __ pc();
aoqi@0 947
aoqi@0 948 // Read
aoqi@0 949 // R16_thread
aoqi@0 950 // R15_prev_state - address of caller's BytecodeInterpreter, if this snippet
aoqi@0 951 // gets called by the frame manager.
aoqi@0 952 // R19_method - callee's Method
aoqi@0 953 // R17_tos - address of caller's tos
aoqi@0 954 // R1_SP - caller's stack pointer
aoqi@0 955 // R21_sender_SP - initial caller sp
aoqi@0 956 //
aoqi@0 957 // Update
aoqi@0 958 // R14_state - address of caller's BytecodeInterpreter
aoqi@0 959 // R3_RET - integer result, if any.
aoqi@0 960 // F1_RET - float result, if any.
aoqi@0 961 //
aoqi@0 962 //
aoqi@0 963 // Stack layout at this point:
aoqi@0 964 //
aoqi@0 965 // 0 [TOP_IJAVA_FRAME_ABI] <-- R1_SP
aoqi@0 966 // alignment (optional)
aoqi@0 967 // [outgoing Java arguments] <-- R17_tos
aoqi@0 968 // ...
aoqi@0 969 // PARENT [PARENT_IJAVA_FRAME_ABI]
aoqi@0 970 // ...
aoqi@0 971 //
aoqi@0 972
aoqi@0 973 const bool inc_counter = UseCompiler || CountCompiledCalls;
aoqi@0 974
aoqi@0 975 const Register signature_handler_fd = R21_tmp1;
aoqi@0 976 const Register pending_exception = R22_tmp2;
aoqi@0 977 const Register result_handler_addr = R23_tmp3;
aoqi@0 978 const Register native_method_fd = R24_tmp4;
aoqi@0 979 const Register access_flags = R25_tmp5;
aoqi@0 980 const Register active_handles = R26_tmp6;
aoqi@0 981 const Register sync_state = R27_tmp7;
aoqi@0 982 const Register sync_state_addr = sync_state; // Address is dead after use.
aoqi@0 983 const Register suspend_flags = R24_tmp4;
aoqi@0 984
aoqi@0 985 const Register return_pc = R28_tmp8; // Register will be locked for some time.
aoqi@0 986
aoqi@0 987 const ConditionRegister is_synced = CCR4_is_synced; // Live-on-exit from compute_interpreter_state.
aoqi@0 988
aoqi@0 989
aoqi@0 990 // R1_SP still points to caller's SP at this point.
aoqi@0 991
aoqi@0 992 // Save initial_caller_sp to caller's abi. The caller frame must be
aoqi@0 993 // resized before returning to get rid of the c2i arguments (if
aoqi@0 994 // any).
aoqi@0 995 // Override the saved SP with the senderSP so we can pop c2i
aoqi@0 996 // arguments (if any) off when we return
aoqi@0 997 __ std(R21_sender_SP, _top_ijava_frame_abi(initial_caller_sp), R1_SP);
aoqi@0 998
aoqi@0 999 // Save LR to caller's frame. We don't use _abi(lr) here, because it is not safe.
aoqi@0 1000 __ mflr(return_pc);
aoqi@0 1001 __ std(return_pc, _top_ijava_frame_abi(frame_manager_lr), R1_SP);
aoqi@0 1002
aoqi@0 1003 assert(return_pc->is_nonvolatile(), "return_pc must be a non-volatile register");
aoqi@0 1004
aoqi@0 1005 __ verify_method_ptr(R19_method);
aoqi@0 1006
aoqi@0 1007 //=============================================================================
aoqi@0 1008
aoqi@0 1009 // If this snippet gets called by the frame manager (at label
aoqi@0 1010 // `call_special'), then R15_prev_state is valid. If this snippet
aoqi@0 1011 // is not called by the frame manager, but e.g. by the call stub or
aoqi@0 1012 // by compiled code, then R15_prev_state is invalid.
aoqi@0 1013 {
aoqi@0 1014 // Set R15_prev_state to 0 if we don't return to the frame
aoqi@0 1015 // manager; we will return to the call_stub or to compiled code
aoqi@0 1016 // instead. If R15_prev_state is 0 there will be only one
aoqi@0 1017 // interpreter frame (we will set this up later) in this C frame!
aoqi@0 1018 // So we must take care about retrieving prev_state_(_prev_link)
aoqi@0 1019 // and restoring R1_SP when popping that interpreter.
aoqi@0 1020 Label prev_state_is_valid;
aoqi@0 1021
aoqi@0 1022 __ load_const(R11_scratch1/*frame_manager_returnpc_addr*/, (address)&frame_manager_specialized_return);
aoqi@0 1023 __ ld(R12_scratch2/*frame_manager_returnpc*/, 0, R11_scratch1/*frame_manager_returnpc_addr*/);
aoqi@0 1024 __ cmpd(CCR0, return_pc, R12_scratch2/*frame_manager_returnpc*/);
aoqi@0 1025 __ beq(CCR0, prev_state_is_valid);
aoqi@0 1026
aoqi@0 1027 __ li(R15_prev_state, 0);
aoqi@0 1028
aoqi@0 1029 __ BIND(prev_state_is_valid);
aoqi@0 1030 }
aoqi@0 1031
aoqi@0 1032 //=============================================================================
aoqi@0 1033 // Allocate new frame and initialize interpreter state.
aoqi@0 1034
aoqi@0 1035 Label exception_return;
aoqi@0 1036 Label exception_return_sync_check;
aoqi@0 1037 Label stack_overflow_return;
aoqi@0 1038
aoqi@0 1039 // Generate new interpreter state and jump to stack_overflow_return in case of
aoqi@0 1040 // a stack overflow.
aoqi@0 1041 generate_compute_interpreter_state(stack_overflow_return);
aoqi@0 1042
aoqi@0 1043 //=============================================================================
aoqi@0 1044 // Increment invocation counter. On overflow, entry to JNI method
aoqi@0 1045 // will be compiled.
aoqi@0 1046 Label invocation_counter_overflow;
aoqi@0 1047 if (inc_counter) {
aoqi@0 1048 generate_counter_incr(invocation_counter_overflow);
aoqi@0 1049 }
aoqi@0 1050
aoqi@0 1051 Label continue_after_compile;
aoqi@0 1052 __ BIND(continue_after_compile);
aoqi@0 1053
aoqi@0 1054 // access_flags = method->access_flags();
aoqi@0 1055 // Load access flags.
aoqi@0 1056 assert(access_flags->is_nonvolatile(),
aoqi@0 1057 "access_flags must be in a non-volatile register");
aoqi@0 1058 // Type check.
aoqi@0 1059 // TODO: PPC port: assert(4 == sizeof(AccessFlags), "unexpected field size");
aoqi@0 1060 __ lwz(access_flags, method_(access_flags));
aoqi@0 1061
aoqi@0 1062 // We don't want to reload R19_method and access_flags after calls
aoqi@0 1063 // to some helper functions.
aoqi@0 1064 assert(R19_method->is_nonvolatile(), "R19_method must be a non-volatile register");
aoqi@0 1065
aoqi@0 1066 // Check for synchronized methods. Must happen AFTER invocation counter
aoqi@0 1067 // check, so method is not locked if counter overflows.
aoqi@0 1068
aoqi@0 1069 {
aoqi@0 1070 Label method_is_not_synced;
aoqi@0 1071 // Is_synced is still alive.
aoqi@0 1072 assert(is_synced->is_nonvolatile(), "is_synced must be non-volatile");
aoqi@0 1073 __ bfalse(is_synced, method_is_not_synced);
aoqi@0 1074
aoqi@0 1075 lock_method();
aoqi@0 1076 // Reload method, it may have moved.
aoqi@0 1077 __ ld(R19_method, state_(_method));
aoqi@0 1078
aoqi@0 1079 __ BIND(method_is_not_synced);
aoqi@0 1080 }
aoqi@0 1081
aoqi@0 1082 // jvmti/jvmpi support
aoqi@0 1083 __ notify_method_entry();
aoqi@0 1084
aoqi@0 1085 // Reload method, it may have moved.
aoqi@0 1086 __ ld(R19_method, state_(_method));
aoqi@0 1087
aoqi@0 1088 //=============================================================================
aoqi@0 1089 // Get and call the signature handler
aoqi@0 1090
aoqi@0 1091 __ ld(signature_handler_fd, method_(signature_handler));
aoqi@0 1092 Label call_signature_handler;
aoqi@0 1093
aoqi@0 1094 __ cmpdi(CCR0, signature_handler_fd, 0);
aoqi@0 1095 __ bne(CCR0, call_signature_handler);
aoqi@0 1096
aoqi@0 1097 // Method has never been called. Either generate a specialized
aoqi@0 1098 // handler or point to the slow one.
aoqi@0 1099 //
aoqi@0 1100 // Pass parameter 'false' to avoid exception check in call_VM.
aoqi@0 1101 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::prepare_native_call), R19_method, false);
aoqi@0 1102
aoqi@0 1103 // Check for an exception while looking up the target method. If we
aoqi@0 1104 // incurred one, bail.
aoqi@0 1105 __ ld(pending_exception, thread_(pending_exception));
aoqi@0 1106 __ cmpdi(CCR0, pending_exception, 0);
aoqi@0 1107 __ bne(CCR0, exception_return_sync_check); // has pending exception
aoqi@0 1108
aoqi@0 1109 // reload method
aoqi@0 1110 __ ld(R19_method, state_(_method));
aoqi@0 1111
aoqi@0 1112 // Reload signature handler, it may have been created/assigned in the meanwhile
aoqi@0 1113 __ ld(signature_handler_fd, method_(signature_handler));
aoqi@0 1114
aoqi@0 1115 __ BIND(call_signature_handler);
aoqi@0 1116
aoqi@0 1117 // Before we call the signature handler we push a new frame to
aoqi@0 1118 // protect the interpreter frame volatile registers when we return
aoqi@0 1119 // from jni but before we can get back to Java.
aoqi@0 1120
aoqi@0 1121 // First set the frame anchor while the SP/FP registers are
aoqi@0 1122 // convenient and the slow signature handler can use this same frame
aoqi@0 1123 // anchor.
aoqi@0 1124
aoqi@0 1125 // We have a TOP_IJAVA_FRAME here, which belongs to us.
aoqi@0 1126 __ set_top_ijava_frame_at_SP_as_last_Java_frame(R1_SP, R12_scratch2/*tmp*/);
aoqi@0 1127
aoqi@0 1128 // Now the interpreter frame (and its call chain) have been
aoqi@0 1129 // invalidated and flushed. We are now protected against eager
aoqi@0 1130 // being enabled in native code. Even if it goes eager the
aoqi@0 1131 // registers will be reloaded as clean and we will invalidate after
aoqi@0 1132 // the call so no spurious flush should be possible.
aoqi@0 1133
aoqi@0 1134 // Call signature handler and pass locals address.
aoqi@0 1135 //
aoqi@0 1136 // Our signature handlers copy required arguments to the C stack
aoqi@0 1137 // (outgoing C args), R3_ARG1 to R10_ARG8, and F1_ARG1 to
aoqi@0 1138 // F13_ARG13.
aoqi@0 1139 __ mr(R3_ARG1, R18_locals);
aoqi@0 1140 #if !defined(ABI_ELFv2)
aoqi@0 1141 __ ld(signature_handler_fd, 0, signature_handler_fd);
aoqi@0 1142 #endif
aoqi@0 1143 __ call_stub(signature_handler_fd);
aoqi@0 1144 // reload method
aoqi@0 1145 __ ld(R19_method, state_(_method));
aoqi@0 1146
aoqi@0 1147 // Remove the register parameter varargs slots we allocated in
aoqi@0 1148 // compute_interpreter_state. SP+16 ends up pointing to the ABI
aoqi@0 1149 // outgoing argument area.
aoqi@0 1150 //
aoqi@0 1151 // Not needed on PPC64.
aoqi@0 1152 //__ add(SP, SP, Argument::n_register_parameters*BytesPerWord);
aoqi@0 1153
aoqi@0 1154 assert(result_handler_addr->is_nonvolatile(), "result_handler_addr must be in a non-volatile register");
aoqi@0 1155 // Save across call to native method.
aoqi@0 1156 __ mr(result_handler_addr, R3_RET);
aoqi@0 1157
aoqi@0 1158 // Set up fixed parameters and call the native method.
aoqi@0 1159 // If the method is static, get mirror into R4_ARG2.
aoqi@0 1160
aoqi@0 1161 {
aoqi@0 1162 Label method_is_not_static;
aoqi@0 1163 // access_flags is non-volatile and still, no need to restore it
aoqi@0 1164
aoqi@0 1165 // restore access flags
aoqi@0 1166 __ testbitdi(CCR0, R0, access_flags, JVM_ACC_STATIC_BIT);
aoqi@0 1167 __ bfalse(CCR0, method_is_not_static);
aoqi@0 1168
aoqi@0 1169 // constants = method->constants();
aoqi@0 1170 __ ld(R11_scratch1, in_bytes(Method::const_offset()), R19_method);
aoqi@0 1171 __ ld(R11_scratch1/*constants*/, in_bytes(ConstMethod::constants_offset()), R11_scratch1);
aoqi@0 1172 // pool_holder = method->constants()->pool_holder();
aoqi@0 1173 __ ld(R11_scratch1/*pool_holder*/, ConstantPool::pool_holder_offset_in_bytes(),
aoqi@0 1174 R11_scratch1/*constants*/);
aoqi@0 1175
aoqi@0 1176 const int mirror_offset = in_bytes(Klass::java_mirror_offset());
aoqi@0 1177
aoqi@0 1178 // mirror = pool_holder->klass_part()->java_mirror();
aoqi@0 1179 __ ld(R0/*mirror*/, mirror_offset, R11_scratch1/*pool_holder*/);
aoqi@0 1180 // state->_native_mirror = mirror;
aoqi@0 1181 __ std(R0/*mirror*/, state_(_oop_temp));
aoqi@0 1182 // R4_ARG2 = &state->_oop_temp;
aoqi@0 1183 __ addir(R4_ARG2, state_(_oop_temp));
aoqi@0 1184
aoqi@0 1185 __ BIND(method_is_not_static);
aoqi@0 1186 }
aoqi@0 1187
aoqi@0 1188 // At this point, arguments have been copied off the stack into
aoqi@0 1189 // their JNI positions. Oops are boxed in-place on the stack, with
aoqi@0 1190 // handles copied to arguments. The result handler address is in a
aoqi@0 1191 // register.
aoqi@0 1192
aoqi@0 1193 // pass JNIEnv address as first parameter
aoqi@0 1194 __ addir(R3_ARG1, thread_(jni_environment));
aoqi@0 1195
aoqi@0 1196 // Load the native_method entry before we change the thread state.
aoqi@0 1197 __ ld(native_method_fd, method_(native_function));
aoqi@0 1198
aoqi@0 1199 //=============================================================================
aoqi@0 1200 // Transition from _thread_in_Java to _thread_in_native. As soon as
aoqi@0 1201 // we make this change the safepoint code needs to be certain that
aoqi@0 1202 // the last Java frame we established is good. The pc in that frame
aoqi@0 1203 // just needs to be near here not an actual return address.
aoqi@0 1204
aoqi@0 1205 // We use release_store_fence to update values like the thread state, where
aoqi@0 1206 // we don't want the current thread to continue until all our prior memory
aoqi@0 1207 // accesses (including the new thread state) are visible to other threads.
aoqi@0 1208 __ li(R0, _thread_in_native);
aoqi@0 1209 __ release();
aoqi@0 1210
aoqi@0 1211 // TODO: PPC port: assert(4 == JavaThread::sz_thread_state(), "unexpected field size");
aoqi@0 1212 __ stw(R0, thread_(thread_state));
aoqi@0 1213
aoqi@0 1214 if (UseMembar) {
aoqi@0 1215 __ fence();
aoqi@0 1216 }
aoqi@0 1217
aoqi@0 1218 //=============================================================================
aoqi@0 1219 // Call the native method. Argument registers must not have been
aoqi@0 1220 // overwritten since "__ call_stub(signature_handler);" (except for
aoqi@0 1221 // ARG1 and ARG2 for static methods)
aoqi@0 1222 __ call_c(native_method_fd);
aoqi@0 1223
aoqi@0 1224 __ std(R3_RET, state_(_native_lresult));
aoqi@0 1225 __ stfd(F1_RET, state_(_native_fresult));
aoqi@0 1226
aoqi@0 1227 // The frame_manager_lr field, which we use for setting the last
aoqi@0 1228 // java frame, gets overwritten by the signature handler. Restore
aoqi@0 1229 // it now.
aoqi@0 1230 __ get_PC_trash_LR(R11_scratch1);
aoqi@0 1231 __ std(R11_scratch1, _top_ijava_frame_abi(frame_manager_lr), R1_SP);
aoqi@0 1232
aoqi@0 1233 // Because of GC R19_method may no longer be valid.
aoqi@0 1234
aoqi@0 1235 // Block, if necessary, before resuming in _thread_in_Java state.
aoqi@0 1236 // In order for GC to work, don't clear the last_Java_sp until after
aoqi@0 1237 // blocking.
aoqi@0 1238
aoqi@0 1239
aoqi@0 1240
aoqi@0 1241 //=============================================================================
aoqi@0 1242 // Switch thread to "native transition" state before reading the
aoqi@0 1243 // synchronization state. This additional state is necessary
aoqi@0 1244 // because reading and testing the synchronization state is not
aoqi@0 1245 // atomic w.r.t. GC, as this scenario demonstrates: Java thread A,
aoqi@0 1246 // in _thread_in_native state, loads _not_synchronized and is
aoqi@0 1247 // preempted. VM thread changes sync state to synchronizing and
aoqi@0 1248 // suspends threads for GC. Thread A is resumed to finish this
aoqi@0 1249 // native method, but doesn't block here since it didn't see any
aoqi@0 1250 // synchronization in progress, and escapes.
aoqi@0 1251
aoqi@0 1252 // We use release_store_fence to update values like the thread state, where
aoqi@0 1253 // we don't want the current thread to continue until all our prior memory
aoqi@0 1254 // accesses (including the new thread state) are visible to other threads.
aoqi@0 1255 __ li(R0/*thread_state*/, _thread_in_native_trans);
aoqi@0 1256 __ release();
aoqi@0 1257 __ stw(R0/*thread_state*/, thread_(thread_state));
aoqi@0 1258 if (UseMembar) {
aoqi@0 1259 __ fence();
aoqi@0 1260 }
aoqi@0 1261 // Write serialization page so that the VM thread can do a pseudo remote
aoqi@0 1262 // membar. We use the current thread pointer to calculate a thread
aoqi@0 1263 // specific offset to write to within the page. This minimizes bus
aoqi@0 1264 // traffic due to cache line collision.
aoqi@0 1265 else {
aoqi@0 1266 __ serialize_memory(R16_thread, R11_scratch1, R12_scratch2);
aoqi@0 1267 }
aoqi@0 1268
aoqi@0 1269 // Now before we return to java we must look for a current safepoint
aoqi@0 1270 // (a new safepoint can not start since we entered native_trans).
aoqi@0 1271 // We must check here because a current safepoint could be modifying
aoqi@0 1272 // the callers registers right this moment.
aoqi@0 1273
aoqi@0 1274 // Acquire isn't strictly necessary here because of the fence, but
aoqi@0 1275 // sync_state is declared to be volatile, so we do it anyway.
aoqi@0 1276 __ load_const(sync_state_addr, SafepointSynchronize::address_of_state());
aoqi@0 1277
aoqi@0 1278 // TODO: PPC port: assert(4 == SafepointSynchronize::sz_state(), "unexpected field size");
aoqi@0 1279 __ lwz(sync_state, 0, sync_state_addr);
aoqi@0 1280
aoqi@0 1281 // TODO: PPC port: assert(4 == Thread::sz_suspend_flags(), "unexpected field size");
aoqi@0 1282 __ lwz(suspend_flags, thread_(suspend_flags));
aoqi@0 1283
aoqi@0 1284 __ acquire();
aoqi@0 1285
aoqi@0 1286 Label sync_check_done;
aoqi@0 1287 Label do_safepoint;
aoqi@0 1288 // No synchronization in progress nor yet synchronized
aoqi@0 1289 __ cmpwi(CCR0, sync_state, SafepointSynchronize::_not_synchronized);
aoqi@0 1290 // not suspended
aoqi@0 1291 __ cmpwi(CCR1, suspend_flags, 0);
aoqi@0 1292
aoqi@0 1293 __ bne(CCR0, do_safepoint);
aoqi@0 1294 __ beq(CCR1, sync_check_done);
aoqi@0 1295 __ bind(do_safepoint);
aoqi@0 1296 // Block. We do the call directly and leave the current
aoqi@0 1297 // last_Java_frame setup undisturbed. We must save any possible
aoqi@0 1298 // native result acrosss the call. No oop is present
aoqi@0 1299
aoqi@0 1300 __ mr(R3_ARG1, R16_thread);
aoqi@0 1301 #if defined(ABI_ELFv2)
aoqi@0 1302 __ call_c(CAST_FROM_FN_PTR(address, JavaThread::check_special_condition_for_native_trans),
aoqi@0 1303 relocInfo::none);
aoqi@0 1304 #else
aoqi@0 1305 __ call_c(CAST_FROM_FN_PTR(FunctionDescriptor*, JavaThread::check_special_condition_for_native_trans),
aoqi@0 1306 relocInfo::none);
aoqi@0 1307 #endif
aoqi@0 1308 __ bind(sync_check_done);
aoqi@0 1309
aoqi@0 1310 //=============================================================================
aoqi@0 1311 // <<<<<< Back in Interpreter Frame >>>>>
aoqi@0 1312
aoqi@0 1313 // We are in thread_in_native_trans here and back in the normal
aoqi@0 1314 // interpreter frame. We don't have to do anything special about
aoqi@0 1315 // safepoints and we can switch to Java mode anytime we are ready.
aoqi@0 1316
aoqi@0 1317 // Note: frame::interpreter_frame_result has a dependency on how the
aoqi@0 1318 // method result is saved across the call to post_method_exit. For
aoqi@0 1319 // native methods it assumes that the non-FPU/non-void result is
aoqi@0 1320 // saved in _native_lresult and a FPU result in _native_fresult. If
aoqi@0 1321 // this changes then the interpreter_frame_result implementation
aoqi@0 1322 // will need to be updated too.
aoqi@0 1323
aoqi@0 1324 // On PPC64, we have stored the result directly after the native call.
aoqi@0 1325
aoqi@0 1326 //=============================================================================
aoqi@0 1327 // back in Java
aoqi@0 1328
aoqi@0 1329 // We use release_store_fence to update values like the thread state, where
aoqi@0 1330 // we don't want the current thread to continue until all our prior memory
aoqi@0 1331 // accesses (including the new thread state) are visible to other threads.
aoqi@0 1332 __ li(R0/*thread_state*/, _thread_in_Java);
aoqi@0 1333 __ release();
aoqi@0 1334 __ stw(R0/*thread_state*/, thread_(thread_state));
aoqi@0 1335 if (UseMembar) {
aoqi@0 1336 __ fence();
aoqi@0 1337 }
aoqi@0 1338
aoqi@0 1339 __ reset_last_Java_frame();
aoqi@0 1340
aoqi@0 1341 // Reload GR27_method, call killed it. We can't look at
aoqi@0 1342 // state->_method until we're back in java state because in java
aoqi@0 1343 // state gc can't happen until we get to a safepoint.
aoqi@0 1344 //
aoqi@0 1345 // We've set thread_state to _thread_in_Java already, so restoring
aoqi@0 1346 // R19_method from R14_state works; R19_method is invalid, because
aoqi@0 1347 // GC may have happened.
aoqi@0 1348 __ ld(R19_method, state_(_method)); // reload method, may have moved
aoqi@0 1349
aoqi@0 1350 // jvmdi/jvmpi support. Whether we've got an exception pending or
aoqi@0 1351 // not, and whether unlocking throws an exception or not, we notify
aoqi@0 1352 // on native method exit. If we do have an exception, we'll end up
aoqi@0 1353 // in the caller's context to handle it, so if we don't do the
aoqi@0 1354 // notify here, we'll drop it on the floor.
aoqi@0 1355
aoqi@0 1356 __ notify_method_exit(true/*native method*/,
aoqi@0 1357 ilgl /*illegal state (not used for native methods)*/,
aoqi@0 1358 InterpreterMacroAssembler::NotifyJVMTI,
aoqi@0 1359 false /*check_exceptions*/);
aoqi@0 1360
aoqi@0 1361 //=============================================================================
aoqi@0 1362 // Handle exceptions
aoqi@0 1363
aoqi@0 1364 // See if we must unlock.
aoqi@0 1365 //
aoqi@0 1366 {
aoqi@0 1367 Label method_is_not_synced;
aoqi@0 1368 // is_synced is still alive
aoqi@0 1369 assert(is_synced->is_nonvolatile(), "is_synced must be non-volatile");
aoqi@0 1370 __ bfalse(is_synced, method_is_not_synced);
aoqi@0 1371
aoqi@0 1372 unlock_method();
aoqi@0 1373
aoqi@0 1374 __ bind(method_is_not_synced);
aoqi@0 1375 }
aoqi@0 1376
aoqi@0 1377 // Reset active handles after returning from native.
aoqi@0 1378 // thread->active_handles()->clear();
aoqi@0 1379 __ ld(active_handles, thread_(active_handles));
aoqi@0 1380 // JNIHandleBlock::_top is an int.
aoqi@0 1381 // TODO: PPC port: assert(4 == JNIHandleBlock::top_size_in_bytes(), "unexpected field size");
aoqi@0 1382 __ li(R0, 0);
aoqi@0 1383 __ stw(R0, JNIHandleBlock::top_offset_in_bytes(), active_handles);
aoqi@0 1384
aoqi@0 1385 Label no_pending_exception_from_native_method;
aoqi@0 1386 __ ld(R0/*pending_exception*/, thread_(pending_exception));
aoqi@0 1387 __ cmpdi(CCR0, R0/*pending_exception*/, 0);
aoqi@0 1388 __ beq(CCR0, no_pending_exception_from_native_method);
aoqi@0 1389
aoqi@0 1390
aoqi@0 1391 //-----------------------------------------------------------------------------
aoqi@0 1392 // An exception is pending. We call into the runtime only if the
aoqi@0 1393 // caller was not interpreted. If it was interpreted the
aoqi@0 1394 // interpreter will do the correct thing. If it isn't interpreted
aoqi@0 1395 // (call stub/compiled code) we will change our return and continue.
aoqi@0 1396 __ BIND(exception_return);
aoqi@0 1397
aoqi@0 1398 Label return_to_initial_caller_with_pending_exception;
aoqi@0 1399 __ cmpdi(CCR0, R15_prev_state, 0);
aoqi@0 1400 __ beq(CCR0, return_to_initial_caller_with_pending_exception);
aoqi@0 1401
aoqi@0 1402 // We are returning to an interpreter activation, just pop the state,
aoqi@0 1403 // pop our frame, leave the exception pending, and return.
aoqi@0 1404 __ pop_interpreter_state(/*prev_state_may_be_0=*/false);
aoqi@0 1405 __ pop_interpreter_frame(R11_scratch1, R12_scratch2, R21_tmp1 /* set to return pc */, R22_tmp2);
aoqi@0 1406 __ mtlr(R21_tmp1);
aoqi@0 1407 __ blr();
aoqi@0 1408
aoqi@0 1409 __ BIND(exception_return_sync_check);
aoqi@0 1410
aoqi@0 1411 assert(is_synced->is_nonvolatile(), "is_synced must be non-volatile");
aoqi@0 1412 __ bfalse(is_synced, exception_return);
aoqi@0 1413 unlock_method();
aoqi@0 1414 __ b(exception_return);
aoqi@0 1415
aoqi@0 1416
aoqi@0 1417 __ BIND(return_to_initial_caller_with_pending_exception);
aoqi@0 1418 // We are returning to a c2i-adapter / call-stub, get the address of the
aoqi@0 1419 // exception handler, pop the frame and return to the handler.
aoqi@0 1420
aoqi@0 1421 // First, pop to caller's frame.
aoqi@0 1422 __ pop_interpreter_frame(R11_scratch1, R12_scratch2, R21_tmp1 /* set to return pc */, R22_tmp2);
aoqi@0 1423
aoqi@0 1424 __ push_frame_reg_args(0, R11_scratch1);
aoqi@0 1425 // Get the address of the exception handler.
aoqi@0 1426 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::exception_handler_for_return_address),
aoqi@0 1427 R16_thread,
aoqi@0 1428 R21_tmp1 /* return pc */);
aoqi@0 1429 __ pop_frame();
aoqi@0 1430
aoqi@0 1431 // Load the PC of the the exception handler into LR.
aoqi@0 1432 __ mtlr(R3_RET);
aoqi@0 1433
aoqi@0 1434 // Load exception into R3_ARG1 and clear pending exception in thread.
aoqi@0 1435 __ ld(R3_ARG1/*exception*/, thread_(pending_exception));
aoqi@0 1436 __ li(R4_ARG2, 0);
aoqi@0 1437 __ std(R4_ARG2, thread_(pending_exception));
aoqi@0 1438
aoqi@0 1439 // Load the original return pc into R4_ARG2.
aoqi@0 1440 __ mr(R4_ARG2/*issuing_pc*/, R21_tmp1);
aoqi@0 1441
aoqi@0 1442 // Resize frame to get rid of a potential extension.
aoqi@0 1443 __ resize_frame_to_initial_caller(R11_scratch1, R12_scratch2);
aoqi@0 1444
aoqi@0 1445 // Return to exception handler.
aoqi@0 1446 __ blr();
aoqi@0 1447
aoqi@0 1448
aoqi@0 1449 //-----------------------------------------------------------------------------
aoqi@0 1450 // No exception pending.
aoqi@0 1451 __ BIND(no_pending_exception_from_native_method);
aoqi@0 1452
aoqi@0 1453 // Move native method result back into proper registers and return.
aoqi@0 1454 // Invoke result handler (may unbox/promote).
aoqi@0 1455 __ ld(R3_RET, state_(_native_lresult));
aoqi@0 1456 __ lfd(F1_RET, state_(_native_fresult));
aoqi@0 1457 __ call_stub(result_handler_addr);
aoqi@0 1458
aoqi@0 1459 // We have created a new BytecodeInterpreter object, now we must destroy it.
aoqi@0 1460 //
aoqi@0 1461 // Restore previous R14_state and caller's SP. R15_prev_state may
aoqi@0 1462 // be 0 here, because our caller may be the call_stub or compiled
aoqi@0 1463 // code.
aoqi@0 1464 __ pop_interpreter_state(/*prev_state_may_be_0=*/true);
aoqi@0 1465 __ pop_interpreter_frame(R11_scratch1, R12_scratch2, R21_tmp1 /* set to return pc */, R22_tmp2);
aoqi@0 1466 // Resize frame to get rid of a potential extension.
aoqi@0 1467 __ resize_frame_to_initial_caller(R11_scratch1, R12_scratch2);
aoqi@0 1468
aoqi@0 1469 // Must use the return pc which was loaded from the caller's frame
aoqi@0 1470 // as the VM uses return-pc-patching for deoptimization.
aoqi@0 1471 __ mtlr(R21_tmp1);
aoqi@0 1472 __ blr();
aoqi@0 1473
aoqi@0 1474
aoqi@0 1475
aoqi@0 1476 //=============================================================================
aoqi@0 1477 // We encountered an exception while computing the interpreter
aoqi@0 1478 // state, so R14_state isn't valid. Act as if we just returned from
aoqi@0 1479 // the callee method with a pending exception.
aoqi@0 1480 __ BIND(stack_overflow_return);
aoqi@0 1481
aoqi@0 1482 //
aoqi@0 1483 // Register state:
aoqi@0 1484 // R14_state invalid; trashed by compute_interpreter_state
aoqi@0 1485 // R15_prev_state valid, but may be 0
aoqi@0 1486 //
aoqi@0 1487 // R1_SP valid, points to caller's SP; wasn't yet updated by
aoqi@0 1488 // compute_interpreter_state
aoqi@0 1489 //
aoqi@0 1490
aoqi@0 1491 // Create exception oop and make it pending.
aoqi@0 1492
aoqi@0 1493 // Throw the exception via RuntimeStub "throw_StackOverflowError_entry".
aoqi@0 1494 //
aoqi@0 1495 // Previously, we called C-Code directly. As a consequence, a
aoqi@0 1496 // possible GC tried to process the argument oops of the top frame
aoqi@0 1497 // (see RegisterMap::clear, which sets the corresponding flag to
aoqi@0 1498 // true). This lead to crashes because:
aoqi@0 1499 // 1. The top register map did not contain locations for the argument registers
aoqi@0 1500 // 2. The arguments are dead anyway, could be already overwritten in the worst case
aoqi@0 1501 // Solution: Call via special runtime stub that pushes it's own
aoqi@0 1502 // frame. This runtime stub has the flag "CodeBlob::caller_must_gc_arguments()"
aoqi@0 1503 // set to "false", what prevents the dead arguments getting GC'd.
aoqi@0 1504 //
aoqi@0 1505 // 2 cases exist:
aoqi@0 1506 // 1. We were called by the c2i adapter / call stub
aoqi@0 1507 // 2. We were called by the frame manager
aoqi@0 1508 //
aoqi@0 1509 // Both cases are handled by this code:
aoqi@0 1510 // 1. - initial_caller_sp was saved in both cases on entry, so it's safe to load it back even if it was not changed.
aoqi@0 1511 // - control flow will be:
aoqi@0 1512 // throw_stackoverflow_stub->VM->throw_stackoverflow_stub->forward_excep->excp_blob of caller method
aoqi@0 1513 // 2. - control flow will be:
aoqi@0 1514 // throw_stackoverflow_stub->VM->throw_stackoverflow_stub->forward_excep->rethrow_excp_entry of frame manager->resume_method
aoqi@0 1515 // Since we restored the caller SP above, the rethrow_excp_entry can restore the original interpreter state
aoqi@0 1516 // registers using the stack and resume the calling method with a pending excp.
aoqi@0 1517
aoqi@0 1518 // Pop any c2i extension from the stack, restore LR just to be sure
aoqi@0 1519 __ ld(R0, _top_ijava_frame_abi(frame_manager_lr), R1_SP);
aoqi@0 1520 __ mtlr(R0);
aoqi@0 1521 // Resize frame to get rid of a potential extension.
aoqi@0 1522 __ resize_frame_to_initial_caller(R11_scratch1, R12_scratch2);
aoqi@0 1523
aoqi@0 1524 assert(StubRoutines::throw_StackOverflowError_entry() != NULL, "generated in wrong order");
aoqi@0 1525 // Load target address of the runtime stub.
aoqi@0 1526 __ load_const(R12_scratch2, (StubRoutines::throw_StackOverflowError_entry()));
aoqi@0 1527 __ mtctr(R12_scratch2);
aoqi@0 1528 __ bctr();
aoqi@0 1529
aoqi@0 1530
aoqi@0 1531 //=============================================================================
aoqi@0 1532 // Counter overflow.
aoqi@0 1533
aoqi@0 1534 if (inc_counter) {
aoqi@0 1535 // Handle invocation counter overflow
aoqi@0 1536 __ bind(invocation_counter_overflow);
aoqi@0 1537
aoqi@0 1538 generate_counter_overflow(continue_after_compile);
aoqi@0 1539 }
aoqi@0 1540
aoqi@0 1541 native_entry = entry;
aoqi@0 1542 return entry;
aoqi@0 1543 }
aoqi@0 1544
aoqi@0 1545 bool AbstractInterpreter::can_be_compiled(methodHandle m) {
aoqi@0 1546 // No special entry points that preclude compilation.
aoqi@0 1547 return true;
aoqi@0 1548 }
aoqi@0 1549
aoqi@0 1550 // Unlock the current method.
aoqi@0 1551 //
aoqi@0 1552 void CppInterpreterGenerator::unlock_method(void) {
aoqi@0 1553 // Find preallocated monitor and unlock method. Method monitor is
aoqi@0 1554 // the first one.
aoqi@0 1555
aoqi@0 1556 // Registers alive
aoqi@0 1557 // R14_state
aoqi@0 1558 //
aoqi@0 1559 // Registers updated
aoqi@0 1560 // volatiles
aoqi@0 1561 //
aoqi@0 1562 const Register monitor = R4_ARG2;
aoqi@0 1563
aoqi@0 1564 // Pass address of initial monitor we allocated.
aoqi@0 1565 //
aoqi@0 1566 // First monitor.
aoqi@0 1567 __ addi(monitor, R14_state, -frame::interpreter_frame_monitor_size_in_bytes());
aoqi@0 1568
aoqi@0 1569 // Unlock method
aoqi@0 1570 __ unlock_object(monitor);
aoqi@0 1571 }
aoqi@0 1572
aoqi@0 1573 // Lock the current method.
aoqi@0 1574 //
aoqi@0 1575 void CppInterpreterGenerator::lock_method(void) {
aoqi@0 1576 // Find preallocated monitor and lock method. Method monitor is the
aoqi@0 1577 // first one.
aoqi@0 1578
aoqi@0 1579 //
aoqi@0 1580 // Registers alive
aoqi@0 1581 // R14_state
aoqi@0 1582 //
aoqi@0 1583 // Registers updated
aoqi@0 1584 // volatiles
aoqi@0 1585 //
aoqi@0 1586
aoqi@0 1587 const Register monitor = R4_ARG2;
aoqi@0 1588 const Register object = R5_ARG3;
aoqi@0 1589
aoqi@0 1590 // Pass address of initial monitor we allocated.
aoqi@0 1591 __ addi(monitor, R14_state, -frame::interpreter_frame_monitor_size_in_bytes());
aoqi@0 1592
aoqi@0 1593 // Pass object address.
aoqi@0 1594 __ ld(object, BasicObjectLock::obj_offset_in_bytes(), monitor);
aoqi@0 1595
aoqi@0 1596 // Lock method.
aoqi@0 1597 __ lock_object(monitor, object);
aoqi@0 1598 }
aoqi@0 1599
aoqi@0 1600 // Generate code for handling resuming a deopted method.
aoqi@0 1601 void CppInterpreterGenerator::generate_deopt_handling(Register result_index) {
aoqi@0 1602
aoqi@0 1603 //=============================================================================
aoqi@0 1604 // Returning from a compiled method into a deopted method. The
aoqi@0 1605 // bytecode at the bcp has completed. The result of the bytecode is
aoqi@0 1606 // in the native abi (the tosca for the template based
aoqi@0 1607 // interpreter). Any stack space that was used by the bytecode that
aoqi@0 1608 // has completed has been removed (e.g. parameters for an invoke) so
aoqi@0 1609 // all that we have to do is place any pending result on the
aoqi@0 1610 // expression stack and resume execution on the next bytecode.
aoqi@0 1611
aoqi@0 1612 Label return_from_deopt_common;
aoqi@0 1613
aoqi@0 1614 // R3_RET and F1_RET are live here! Load the array index of the
aoqi@0 1615 // required result stub address and continue at return_from_deopt_common.
aoqi@0 1616
aoqi@0 1617 // Deopt needs to jump to here to enter the interpreter (return a result).
aoqi@0 1618 deopt_frame_manager_return_atos = __ pc();
aoqi@0 1619 __ li(result_index, AbstractInterpreter::BasicType_as_index(T_OBJECT));
aoqi@0 1620 __ b(return_from_deopt_common);
aoqi@0 1621
aoqi@0 1622 deopt_frame_manager_return_btos = __ pc();
aoqi@0 1623 __ li(result_index, AbstractInterpreter::BasicType_as_index(T_BOOLEAN));
aoqi@0 1624 __ b(return_from_deopt_common);
aoqi@0 1625
aoqi@0 1626 deopt_frame_manager_return_itos = __ pc();
aoqi@0 1627 __ li(result_index, AbstractInterpreter::BasicType_as_index(T_INT));
aoqi@0 1628 __ b(return_from_deopt_common);
aoqi@0 1629
aoqi@0 1630 deopt_frame_manager_return_ltos = __ pc();
aoqi@0 1631 __ li(result_index, AbstractInterpreter::BasicType_as_index(T_LONG));
aoqi@0 1632 __ b(return_from_deopt_common);
aoqi@0 1633
aoqi@0 1634 deopt_frame_manager_return_ftos = __ pc();
aoqi@0 1635 __ li(result_index, AbstractInterpreter::BasicType_as_index(T_FLOAT));
aoqi@0 1636 __ b(return_from_deopt_common);
aoqi@0 1637
aoqi@0 1638 deopt_frame_manager_return_dtos = __ pc();
aoqi@0 1639 __ li(result_index, AbstractInterpreter::BasicType_as_index(T_DOUBLE));
aoqi@0 1640 __ b(return_from_deopt_common);
aoqi@0 1641
aoqi@0 1642 deopt_frame_manager_return_vtos = __ pc();
aoqi@0 1643 __ li(result_index, AbstractInterpreter::BasicType_as_index(T_VOID));
aoqi@0 1644 // Last one, fall-through to return_from_deopt_common.
aoqi@0 1645
aoqi@0 1646 // Deopt return common. An index is present that lets us move any
aoqi@0 1647 // possible result being return to the interpreter's stack.
aoqi@0 1648 //
aoqi@0 1649 __ BIND(return_from_deopt_common);
aoqi@0 1650
aoqi@0 1651 }
aoqi@0 1652
aoqi@0 1653 // Generate the code to handle a more_monitors message from the c++ interpreter.
aoqi@0 1654 void CppInterpreterGenerator::generate_more_monitors() {
aoqi@0 1655
aoqi@0 1656 //
aoqi@0 1657 // Registers alive
aoqi@0 1658 // R16_thread - JavaThread*
aoqi@0 1659 // R15_prev_state - previous BytecodeInterpreter or 0
aoqi@0 1660 // R14_state - BytecodeInterpreter* address of receiver's interpreter state
aoqi@0 1661 // R1_SP - old stack pointer
aoqi@0 1662 //
aoqi@0 1663 // Registers updated
aoqi@0 1664 // R1_SP - new stack pointer
aoqi@0 1665 //
aoqi@0 1666
aoqi@0 1667 // Very-local scratch registers.
aoqi@0 1668 const Register old_tos = R21_tmp1;
aoqi@0 1669 const Register new_tos = R22_tmp2;
aoqi@0 1670 const Register stack_base = R23_tmp3;
aoqi@0 1671 const Register stack_limit = R24_tmp4;
aoqi@0 1672 const Register slot = R25_tmp5;
aoqi@0 1673 const Register n_slots = R25_tmp5;
aoqi@0 1674
aoqi@0 1675 // Interpreter state fields.
aoqi@0 1676 const Register msg = R24_tmp4;
aoqi@0 1677
aoqi@0 1678 // Load up relevant interpreter state.
aoqi@0 1679
aoqi@0 1680 __ ld(stack_base, state_(_stack_base)); // Old stack_base
aoqi@0 1681 __ ld(old_tos, state_(_stack)); // Old tos
aoqi@0 1682 __ ld(stack_limit, state_(_stack_limit)); // Old stack_limit
aoqi@0 1683
aoqi@0 1684 // extracted monitor_size
aoqi@0 1685 int monitor_size = frame::interpreter_frame_monitor_size_in_bytes();
aoqi@0 1686 assert(Assembler::is_aligned((unsigned int)monitor_size,
aoqi@0 1687 (unsigned int)frame::alignment_in_bytes),
aoqi@0 1688 "size of a monitor must respect alignment of SP");
aoqi@0 1689
aoqi@0 1690 // Save and restore top LR
aoqi@0 1691 __ ld(R12_scratch2, _top_ijava_frame_abi(frame_manager_lr), R1_SP);
aoqi@0 1692 __ resize_frame(-monitor_size, R11_scratch1);// Allocate space for new monitor
aoqi@0 1693 __ std(R12_scratch2, _top_ijava_frame_abi(frame_manager_lr), R1_SP);
aoqi@0 1694 // Initial_caller_sp is used as unextended_sp for non initial callers.
aoqi@0 1695 __ std(R1_SP, _top_ijava_frame_abi(initial_caller_sp), R1_SP);
aoqi@0 1696 __ addi(stack_base, stack_base, -monitor_size); // New stack_base
aoqi@0 1697 __ addi(new_tos, old_tos, -monitor_size); // New tos
aoqi@0 1698 __ addi(stack_limit, stack_limit, -monitor_size); // New stack_limit
aoqi@0 1699
aoqi@0 1700 __ std(R1_SP, state_(_last_Java_sp)); // Update frame_bottom
aoqi@0 1701
aoqi@0 1702 __ std(stack_base, state_(_stack_base)); // Update stack_base
aoqi@0 1703 __ std(new_tos, state_(_stack)); // Update tos
aoqi@0 1704 __ std(stack_limit, state_(_stack_limit)); // Update stack_limit
aoqi@0 1705
aoqi@0 1706 __ li(msg, BytecodeInterpreter::got_monitors); // Tell interpreter we allocated the lock
aoqi@0 1707 __ stw(msg, state_(_msg));
aoqi@0 1708
aoqi@0 1709 // Shuffle expression stack down. Recall that stack_base points
aoqi@0 1710 // just above the new expression stack bottom. Old_tos and new_tos
aoqi@0 1711 // are used to scan thru the old and new expression stacks.
aoqi@0 1712
aoqi@0 1713 Label copy_slot, copy_slot_finished;
aoqi@0 1714 __ sub(n_slots, stack_base, new_tos);
aoqi@0 1715 __ srdi_(n_slots, n_slots, LogBytesPerWord); // compute number of slots to copy
aoqi@0 1716 assert(LogBytesPerWord == 3, "conflicts assembler instructions");
aoqi@0 1717 __ beq(CCR0, copy_slot_finished); // nothing to copy
aoqi@0 1718
aoqi@0 1719 __ mtctr(n_slots);
aoqi@0 1720
aoqi@0 1721 // loop
aoqi@0 1722 __ bind(copy_slot);
aoqi@0 1723 __ ldu(slot, BytesPerWord, old_tos); // slot = *++old_tos;
aoqi@0 1724 __ stdu(slot, BytesPerWord, new_tos); // *++new_tos = slot;
aoqi@0 1725 __ bdnz(copy_slot);
aoqi@0 1726
aoqi@0 1727 __ bind(copy_slot_finished);
aoqi@0 1728
aoqi@0 1729 // Restart interpreter
aoqi@0 1730 __ li(R0, 0);
aoqi@0 1731 __ std(R0, BasicObjectLock::obj_offset_in_bytes(), stack_base); // Mark lock as unused
aoqi@0 1732 }
aoqi@0 1733
aoqi@0 1734 address CppInterpreterGenerator::generate_normal_entry(void) {
aoqi@0 1735 if (interpreter_frame_manager != NULL) return interpreter_frame_manager;
aoqi@0 1736
aoqi@0 1737 address entry = __ pc();
aoqi@0 1738
aoqi@0 1739 address return_from_native_pc = (address) NULL;
aoqi@0 1740
aoqi@0 1741 // Initial entry to frame manager (from call_stub or c2i_adapter)
aoqi@0 1742
aoqi@0 1743 //
aoqi@0 1744 // Registers alive
aoqi@0 1745 // R16_thread - JavaThread*
aoqi@0 1746 // R19_method - callee's Method (method to be invoked)
aoqi@0 1747 // R17_tos - address of sender tos (prepushed)
aoqi@0 1748 // R1_SP - SP prepared by call stub such that caller's outgoing args are near top
aoqi@0 1749 // LR - return address to caller (call_stub or c2i_adapter)
aoqi@0 1750 // R21_sender_SP - initial caller sp
aoqi@0 1751 //
aoqi@0 1752 // Registers updated
aoqi@0 1753 // R15_prev_state - 0
aoqi@0 1754 //
aoqi@0 1755 // Stack layout at this point:
aoqi@0 1756 //
aoqi@0 1757 // 0 [TOP_IJAVA_FRAME_ABI] <-- R1_SP
aoqi@0 1758 // alignment (optional)
aoqi@0 1759 // [outgoing Java arguments] <-- R17_tos
aoqi@0 1760 // ...
aoqi@0 1761 // PARENT [PARENT_IJAVA_FRAME_ABI]
aoqi@0 1762 // ...
aoqi@0 1763 //
aoqi@0 1764
aoqi@0 1765 // Save initial_caller_sp to caller's abi.
aoqi@0 1766 // The caller frame must be resized before returning to get rid of
aoqi@0 1767 // the c2i part on top of the calling compiled frame (if any).
aoqi@0 1768 // R21_tmp1 must match sender_sp in gen_c2i_adapter.
aoqi@0 1769 // Now override the saved SP with the senderSP so we can pop c2i
aoqi@0 1770 // arguments (if any) off when we return.
aoqi@0 1771 __ std(R21_sender_SP, _top_ijava_frame_abi(initial_caller_sp), R1_SP);
aoqi@0 1772
aoqi@0 1773 // Save LR to caller's frame. We don't use _abi(lr) here,
aoqi@0 1774 // because it is not safe.
aoqi@0 1775 __ mflr(R0);
aoqi@0 1776 __ std(R0, _top_ijava_frame_abi(frame_manager_lr), R1_SP);
aoqi@0 1777
aoqi@0 1778 // If we come here, it is the first invocation of the frame manager.
aoqi@0 1779 // So there is no previous interpreter state.
aoqi@0 1780 __ li(R15_prev_state, 0);
aoqi@0 1781
aoqi@0 1782
aoqi@0 1783 // Fall through to where "recursive" invocations go.
aoqi@0 1784
aoqi@0 1785 //=============================================================================
aoqi@0 1786 // Dispatch an instance of the interpreter. Recursive activations
aoqi@0 1787 // come here.
aoqi@0 1788
aoqi@0 1789 Label re_dispatch;
aoqi@0 1790 __ BIND(re_dispatch);
aoqi@0 1791
aoqi@0 1792 //
aoqi@0 1793 // Registers alive
aoqi@0 1794 // R16_thread - JavaThread*
aoqi@0 1795 // R19_method - callee's Method
aoqi@0 1796 // R17_tos - address of caller's tos (prepushed)
aoqi@0 1797 // R15_prev_state - address of caller's BytecodeInterpreter or 0
aoqi@0 1798 // R1_SP - caller's SP trimmed such that caller's outgoing args are near top.
aoqi@0 1799 //
aoqi@0 1800 // Stack layout at this point:
aoqi@0 1801 //
aoqi@0 1802 // 0 [TOP_IJAVA_FRAME_ABI]
aoqi@0 1803 // alignment (optional)
aoqi@0 1804 // [outgoing Java arguments]
aoqi@0 1805 // ...
aoqi@0 1806 // PARENT [PARENT_IJAVA_FRAME_ABI]
aoqi@0 1807 // ...
aoqi@0 1808
aoqi@0 1809 // fall through to interpreted execution
aoqi@0 1810
aoqi@0 1811 //=============================================================================
aoqi@0 1812 // Allocate a new Java frame and initialize the new interpreter state.
aoqi@0 1813
aoqi@0 1814 Label stack_overflow_return;
aoqi@0 1815
aoqi@0 1816 // Create a suitable new Java frame plus a new BytecodeInterpreter instance
aoqi@0 1817 // in the current (frame manager's) C frame.
aoqi@0 1818 generate_compute_interpreter_state(stack_overflow_return);
aoqi@0 1819
aoqi@0 1820 // fall through
aoqi@0 1821
aoqi@0 1822 //=============================================================================
aoqi@0 1823 // Interpreter dispatch.
aoqi@0 1824
aoqi@0 1825 Label call_interpreter;
aoqi@0 1826 __ BIND(call_interpreter);
aoqi@0 1827
aoqi@0 1828 //
aoqi@0 1829 // Registers alive
aoqi@0 1830 // R16_thread - JavaThread*
aoqi@0 1831 // R15_prev_state - previous BytecodeInterpreter or 0
aoqi@0 1832 // R14_state - address of receiver's BytecodeInterpreter
aoqi@0 1833 // R1_SP - receiver's stack pointer
aoqi@0 1834 //
aoqi@0 1835
aoqi@0 1836 // Thread fields.
aoqi@0 1837 const Register pending_exception = R21_tmp1;
aoqi@0 1838
aoqi@0 1839 // Interpreter state fields.
aoqi@0 1840 const Register msg = R24_tmp4;
aoqi@0 1841
aoqi@0 1842 // Method fields.
aoqi@0 1843 const Register parameter_count = R25_tmp5;
aoqi@0 1844 const Register result_index = R26_tmp6;
aoqi@0 1845
aoqi@0 1846 const Register dummy = R28_tmp8;
aoqi@0 1847
aoqi@0 1848 // Address of various interpreter stubs.
aoqi@0 1849 // R29_tmp9 is reserved.
aoqi@0 1850 const Register stub_addr = R27_tmp7;
aoqi@0 1851
aoqi@0 1852 // Uncommon trap needs to jump to here to enter the interpreter
aoqi@0 1853 // (re-execute current bytecode).
aoqi@0 1854 unctrap_frame_manager_entry = __ pc();
aoqi@0 1855
aoqi@0 1856 // If we are profiling, store our fp (BSP) in the thread so we can
aoqi@0 1857 // find it during a tick.
aoqi@0 1858 if (Arguments::has_profile()) {
aoqi@0 1859 // On PPC64 we store the pointer to the current BytecodeInterpreter,
aoqi@0 1860 // instead of the bsp of ia64. This should suffice to be able to
aoqi@0 1861 // find all interesting information.
aoqi@0 1862 __ std(R14_state, thread_(last_interpreter_fp));
aoqi@0 1863 }
aoqi@0 1864
aoqi@0 1865 // R16_thread, R14_state and R15_prev_state are nonvolatile
aoqi@0 1866 // registers. There is no need to save these. If we needed to save
aoqi@0 1867 // some state in the current Java frame, this could be a place to do
aoqi@0 1868 // so.
aoqi@0 1869
aoqi@0 1870 // Call Java bytecode dispatcher passing "BytecodeInterpreter* istate".
aoqi@0 1871 __ call_VM_leaf(CAST_FROM_FN_PTR(address,
aoqi@0 1872 JvmtiExport::can_post_interpreter_events()
aoqi@0 1873 ? BytecodeInterpreter::runWithChecks
aoqi@0 1874 : BytecodeInterpreter::run),
aoqi@0 1875 R14_state);
aoqi@0 1876
aoqi@0 1877 interpreter_return_address = __ last_calls_return_pc();
aoqi@0 1878
aoqi@0 1879 // R16_thread, R14_state and R15_prev_state have their values preserved.
aoqi@0 1880
aoqi@0 1881 // If we are profiling, clear the fp in the thread to tell
aoqi@0 1882 // the profiler that we are no longer in the interpreter.
aoqi@0 1883 if (Arguments::has_profile()) {
aoqi@0 1884 __ li(R11_scratch1, 0);
aoqi@0 1885 __ std(R11_scratch1, thread_(last_interpreter_fp));
aoqi@0 1886 }
aoqi@0 1887
aoqi@0 1888 // Load message from bytecode dispatcher.
aoqi@0 1889 // TODO: PPC port: guarantee(4 == BytecodeInterpreter::sz_msg(), "unexpected field size");
aoqi@0 1890 __ lwz(msg, state_(_msg));
aoqi@0 1891
aoqi@0 1892
aoqi@0 1893 Label more_monitors;
aoqi@0 1894 Label return_from_native;
aoqi@0 1895 Label return_from_native_common;
aoqi@0 1896 Label return_from_native_no_exception;
aoqi@0 1897 Label return_from_interpreted_method;
aoqi@0 1898 Label return_from_recursive_activation;
aoqi@0 1899 Label unwind_recursive_activation;
aoqi@0 1900 Label resume_interpreter;
aoqi@0 1901 Label return_to_initial_caller;
aoqi@0 1902 Label unwind_initial_activation;
aoqi@0 1903 Label unwind_initial_activation_pending_exception;
aoqi@0 1904 Label call_method;
aoqi@0 1905 Label call_special;
aoqi@0 1906 Label retry_method;
aoqi@0 1907 Label retry_method_osr;
aoqi@0 1908 Label popping_frame;
aoqi@0 1909 Label throwing_exception;
aoqi@0 1910
aoqi@0 1911 // Branch according to the received message
aoqi@0 1912
aoqi@0 1913 __ cmpwi(CCR1, msg, BytecodeInterpreter::call_method);
aoqi@0 1914 __ cmpwi(CCR2, msg, BytecodeInterpreter::return_from_method);
aoqi@0 1915
aoqi@0 1916 __ beq(CCR1, call_method);
aoqi@0 1917 __ beq(CCR2, return_from_interpreted_method);
aoqi@0 1918
aoqi@0 1919 __ cmpwi(CCR3, msg, BytecodeInterpreter::more_monitors);
aoqi@0 1920 __ cmpwi(CCR4, msg, BytecodeInterpreter::throwing_exception);
aoqi@0 1921
aoqi@0 1922 __ beq(CCR3, more_monitors);
aoqi@0 1923 __ beq(CCR4, throwing_exception);
aoqi@0 1924
aoqi@0 1925 __ cmpwi(CCR5, msg, BytecodeInterpreter::popping_frame);
aoqi@0 1926 __ cmpwi(CCR6, msg, BytecodeInterpreter::do_osr);
aoqi@0 1927
aoqi@0 1928 __ beq(CCR5, popping_frame);
aoqi@0 1929 __ beq(CCR6, retry_method_osr);
aoqi@0 1930
aoqi@0 1931 __ stop("bad message from interpreter");
aoqi@0 1932
aoqi@0 1933
aoqi@0 1934 //=============================================================================
aoqi@0 1935 // Add a monitor just below the existing one(s). State->_stack_base
aoqi@0 1936 // points to the lowest existing one, so we insert the new one just
aoqi@0 1937 // below it and shuffle the expression stack down. Ref. the above
aoqi@0 1938 // stack layout picture, we must update _stack_base, _stack, _stack_limit
aoqi@0 1939 // and _last_Java_sp in the interpreter state.
aoqi@0 1940
aoqi@0 1941 __ BIND(more_monitors);
aoqi@0 1942
aoqi@0 1943 generate_more_monitors();
aoqi@0 1944 __ b(call_interpreter);
aoqi@0 1945
aoqi@0 1946 generate_deopt_handling(result_index);
aoqi@0 1947
aoqi@0 1948 // Restoring the R14_state is already done by the deopt_blob.
aoqi@0 1949
aoqi@0 1950 // Current tos includes no parameter slots.
aoqi@0 1951 __ ld(R17_tos, state_(_stack));
aoqi@0 1952 __ li(msg, BytecodeInterpreter::deopt_resume);
aoqi@0 1953 __ b(return_from_native_common);
aoqi@0 1954
aoqi@0 1955 // We are sent here when we are unwinding from a native method or
aoqi@0 1956 // adapter with an exception pending. We need to notify the interpreter
aoqi@0 1957 // that there is an exception to process.
aoqi@0 1958 // We arrive here also if the frame manager called an (interpreted) target
aoqi@0 1959 // which returns with a StackOverflow exception.
aoqi@0 1960 // The control flow is in this case is:
aoqi@0 1961 // frame_manager->throw_excp_stub->forward_excp->rethrow_excp_entry
aoqi@0 1962
aoqi@0 1963 AbstractInterpreter::_rethrow_exception_entry = __ pc();
aoqi@0 1964
aoqi@0 1965 // Restore R14_state.
aoqi@0 1966 __ ld(R14_state, 0, R1_SP);
aoqi@0 1967 __ addi(R14_state, R14_state,
aoqi@0 1968 -frame::interpreter_frame_cinterpreterstate_size_in_bytes());
aoqi@0 1969
aoqi@0 1970 // Store exception oop into thread object.
aoqi@0 1971 __ std(R3_RET, thread_(pending_exception));
aoqi@0 1972 __ li(msg, BytecodeInterpreter::method_resume /*rethrow_exception*/);
aoqi@0 1973 //
aoqi@0 1974 // NOTE: the interpreter frame as setup be deopt does NOT include
aoqi@0 1975 // any parameter slots (good thing since we have no callee here
aoqi@0 1976 // and couldn't remove them) so we don't have to do any calculations
aoqi@0 1977 // here to figure it out.
aoqi@0 1978 //
aoqi@0 1979 __ ld(R17_tos, state_(_stack));
aoqi@0 1980 __ b(return_from_native_common);
aoqi@0 1981
aoqi@0 1982
aoqi@0 1983 //=============================================================================
aoqi@0 1984 // Returning from a native method. Result is in the native abi
aoqi@0 1985 // location so we must move it to the java expression stack.
aoqi@0 1986
aoqi@0 1987 __ BIND(return_from_native);
aoqi@0 1988 guarantee(return_from_native_pc == (address) NULL, "precondition");
aoqi@0 1989 return_from_native_pc = __ pc();
aoqi@0 1990
aoqi@0 1991 // Restore R14_state.
aoqi@0 1992 __ ld(R14_state, 0, R1_SP);
aoqi@0 1993 __ addi(R14_state, R14_state, -frame::interpreter_frame_cinterpreterstate_size_in_bytes());
aoqi@0 1994
aoqi@0 1995 //
aoqi@0 1996 // Registers alive
aoqi@0 1997 // R16_thread
aoqi@0 1998 // R14_state - address of caller's BytecodeInterpreter.
aoqi@0 1999 // R3_RET - integer result, if any.
aoqi@0 2000 // F1_RET - float result, if any.
aoqi@0 2001 //
aoqi@0 2002 // Registers updated
aoqi@0 2003 // R19_method - callee's Method
aoqi@0 2004 // R17_tos - caller's tos, with outgoing args popped
aoqi@0 2005 // result_index - index of result handler.
aoqi@0 2006 // msg - message for resuming interpreter.
aoqi@0 2007 //
aoqi@0 2008
aoqi@0 2009 // Very-local scratch registers.
aoqi@0 2010
aoqi@0 2011 const ConditionRegister have_pending_exception = CCR0;
aoqi@0 2012
aoqi@0 2013 // Load callee Method, gc may have moved it.
aoqi@0 2014 __ ld(R19_method, state_(_result._to_call._callee));
aoqi@0 2015
aoqi@0 2016 // Load address of caller's tos. includes parameter slots.
aoqi@0 2017 __ ld(R17_tos, state_(_stack));
aoqi@0 2018
aoqi@0 2019 // Pop callee's parameters.
aoqi@0 2020
aoqi@0 2021 __ ld(parameter_count, in_bytes(Method::const_offset()), R19_method);
aoqi@0 2022 __ lhz(parameter_count, in_bytes(ConstMethod::size_of_parameters_offset()), parameter_count);
aoqi@0 2023 __ sldi(parameter_count, parameter_count, Interpreter::logStackElementSize);
aoqi@0 2024 __ add(R17_tos, R17_tos, parameter_count);
aoqi@0 2025
aoqi@0 2026 // Result stub address array index
aoqi@0 2027 // TODO: PPC port: assert(4 == sizeof(AccessFlags), "unexpected field size");
aoqi@0 2028 __ lwa(result_index, method_(result_index));
aoqi@0 2029
aoqi@0 2030 __ li(msg, BytecodeInterpreter::method_resume);
aoqi@0 2031
aoqi@0 2032 //
aoqi@0 2033 // Registers alive
aoqi@0 2034 // R16_thread
aoqi@0 2035 // R14_state - address of caller's BytecodeInterpreter.
aoqi@0 2036 // R17_tos - address of caller's tos with outgoing args already popped
aoqi@0 2037 // R3_RET - integer return value, if any.
aoqi@0 2038 // F1_RET - float return value, if any.
aoqi@0 2039 // result_index - index of result handler.
aoqi@0 2040 // msg - message for resuming interpreter.
aoqi@0 2041 //
aoqi@0 2042 // Registers updated
aoqi@0 2043 // R3_RET - new address of caller's tos, including result, if any
aoqi@0 2044 //
aoqi@0 2045
aoqi@0 2046 __ BIND(return_from_native_common);
aoqi@0 2047
aoqi@0 2048 // Check for pending exception
aoqi@0 2049 __ ld(pending_exception, thread_(pending_exception));
aoqi@0 2050 __ cmpdi(CCR0, pending_exception, 0);
aoqi@0 2051 __ beq(CCR0, return_from_native_no_exception);
aoqi@0 2052
aoqi@0 2053 // If there's a pending exception, we really have no result, so
aoqi@0 2054 // R3_RET is dead. Resume_interpreter assumes the new tos is in
aoqi@0 2055 // R3_RET.
aoqi@0 2056 __ mr(R3_RET, R17_tos);
aoqi@0 2057 // `resume_interpreter' expects R15_prev_state to be alive.
aoqi@0 2058 __ ld(R15_prev_state, state_(_prev_link));
aoqi@0 2059 __ b(resume_interpreter);
aoqi@0 2060
aoqi@0 2061 __ BIND(return_from_native_no_exception);
aoqi@0 2062
aoqi@0 2063 // No pending exception, copy method result from native ABI register
aoqi@0 2064 // to tos.
aoqi@0 2065
aoqi@0 2066 // Address of stub descriptor address array.
aoqi@0 2067 __ load_const(stub_addr, CppInterpreter::tosca_result_to_stack());
aoqi@0 2068
aoqi@0 2069 // Pass address of tos to stub.
aoqi@0 2070 __ mr(R4_ARG2, R17_tos);
aoqi@0 2071
aoqi@0 2072 // Address of stub descriptor address.
aoqi@0 2073 __ sldi(result_index, result_index, LogBytesPerWord);
aoqi@0 2074 __ add(stub_addr, stub_addr, result_index);
aoqi@0 2075
aoqi@0 2076 // Stub descriptor address.
aoqi@0 2077 __ ld(stub_addr, 0, stub_addr);
aoqi@0 2078
aoqi@0 2079 // TODO: don't do this via a call, do it in place!
aoqi@0 2080 //
aoqi@0 2081 // call stub via descriptor
aoqi@0 2082 // in R3_ARG1/F1_ARG1: result value (R3_RET or F1_RET)
aoqi@0 2083 __ call_stub(stub_addr);
aoqi@0 2084
aoqi@0 2085 // new tos = result of call in R3_RET
aoqi@0 2086
aoqi@0 2087 // `resume_interpreter' expects R15_prev_state to be alive.
aoqi@0 2088 __ ld(R15_prev_state, state_(_prev_link));
aoqi@0 2089 __ b(resume_interpreter);
aoqi@0 2090
aoqi@0 2091 //=============================================================================
aoqi@0 2092 // We encountered an exception while computing the interpreter
aoqi@0 2093 // state, so R14_state isn't valid. Act as if we just returned from
aoqi@0 2094 // the callee method with a pending exception.
aoqi@0 2095 __ BIND(stack_overflow_return);
aoqi@0 2096
aoqi@0 2097 //
aoqi@0 2098 // Registers alive
aoqi@0 2099 // R16_thread - JavaThread*
aoqi@0 2100 // R1_SP - old stack pointer
aoqi@0 2101 // R19_method - callee's Method
aoqi@0 2102 // R17_tos - address of caller's tos (prepushed)
aoqi@0 2103 // R15_prev_state - address of caller's BytecodeInterpreter or 0
aoqi@0 2104 // R18_locals - address of callee's locals array
aoqi@0 2105 //
aoqi@0 2106 // Registers updated
aoqi@0 2107 // R3_RET - address of resuming tos, if recursive unwind
aoqi@0 2108
aoqi@0 2109 Label Lskip_unextend_SP;
aoqi@0 2110
aoqi@0 2111 {
aoqi@0 2112 const ConditionRegister is_initial_call = CCR0;
aoqi@0 2113 const Register tos_save = R21_tmp1;
aoqi@0 2114 const Register tmp = R22_tmp2;
aoqi@0 2115
aoqi@0 2116 assert(tos_save->is_nonvolatile(), "need a nonvolatile");
aoqi@0 2117
aoqi@0 2118 // Is the exception thrown in the initial Java frame of this frame
aoqi@0 2119 // manager frame?
aoqi@0 2120 __ cmpdi(is_initial_call, R15_prev_state, 0);
aoqi@0 2121 __ bne(is_initial_call, Lskip_unextend_SP);
aoqi@0 2122
aoqi@0 2123 // Pop any c2i extension from the stack. This is necessary in the
aoqi@0 2124 // non-recursive case (that is we were called by the c2i adapter,
aoqi@0 2125 // meaning we have to prev state). In this case we entered the frame
aoqi@0 2126 // manager through a special entry which pushes the orignal
aoqi@0 2127 // unextended SP to the stack. Here we load it back.
aoqi@0 2128 __ ld(R0, _top_ijava_frame_abi(frame_manager_lr), R1_SP);
aoqi@0 2129 __ mtlr(R0);
aoqi@0 2130 // Resize frame to get rid of a potential extension.
aoqi@0 2131 __ resize_frame_to_initial_caller(R11_scratch1, R12_scratch2);
aoqi@0 2132
aoqi@0 2133 // Fall through
aoqi@0 2134
aoqi@0 2135 __ bind(Lskip_unextend_SP);
aoqi@0 2136
aoqi@0 2137 // Throw the exception via RuntimeStub "throw_StackOverflowError_entry".
aoqi@0 2138 //
aoqi@0 2139 // Previously, we called C-Code directly. As a consequence, a
aoqi@0 2140 // possible GC tried to process the argument oops of the top frame
aoqi@0 2141 // (see RegisterMap::clear, which sets the corresponding flag to
aoqi@0 2142 // true). This lead to crashes because:
aoqi@0 2143 // 1. The top register map did not contain locations for the argument registers
aoqi@0 2144 // 2. The arguments are dead anyway, could be already overwritten in the worst case
aoqi@0 2145 // Solution: Call via special runtime stub that pushes it's own frame. This runtime stub has the flag
aoqi@0 2146 // "CodeBlob::caller_must_gc_arguments()" set to "false", what prevents the dead arguments getting GC'd.
aoqi@0 2147 //
aoqi@0 2148 // 2 cases exist:
aoqi@0 2149 // 1. We were called by the c2i adapter / call stub
aoqi@0 2150 // 2. We were called by the frame manager
aoqi@0 2151 //
aoqi@0 2152 // Both cases are handled by this code:
aoqi@0 2153 // 1. - initial_caller_sp was saved on stack => Load it back and we're ok
aoqi@0 2154 // - control flow will be:
aoqi@0 2155 // throw_stackoverflow_stub->VM->throw_stackoverflow_stub->forward_excep->excp_blob of calling method
aoqi@0 2156 // 2. - control flow will be:
aoqi@0 2157 // throw_stackoverflow_stub->VM->throw_stackoverflow_stub->forward_excep->
aoqi@0 2158 // ->rethrow_excp_entry of frame manager->resume_method
aoqi@0 2159 // Since we restored the caller SP above, the rethrow_excp_entry can restore the original interpreter state
aoqi@0 2160 // registers using the stack and resume the calling method with a pending excp.
aoqi@0 2161
aoqi@0 2162 assert(StubRoutines::throw_StackOverflowError_entry() != NULL, "generated in wrong order");
aoqi@0 2163 __ load_const(R3_ARG1, (StubRoutines::throw_StackOverflowError_entry()));
aoqi@0 2164 __ mtctr(R3_ARG1);
aoqi@0 2165 __ bctr();
aoqi@0 2166 }
aoqi@0 2167 //=============================================================================
aoqi@0 2168 // We have popped a frame from an interpreted call. We are assured
aoqi@0 2169 // of returning to an interpreted call by the popframe abi. We have
aoqi@0 2170 // no return value all we have to do is pop the current frame and
aoqi@0 2171 // then make sure that the top of stack (of the caller) gets set to
aoqi@0 2172 // where it was when we entered the callee (i.e. the args are still
aoqi@0 2173 // in place). Or we are returning to the interpreter. In the first
aoqi@0 2174 // case we must extract result (if any) from the java expression
aoqi@0 2175 // stack and store it in the location the native abi would expect
aoqi@0 2176 // for a call returning this type. In the second case we must simply
aoqi@0 2177 // do a stack to stack move as we unwind.
aoqi@0 2178
aoqi@0 2179 __ BIND(popping_frame);
aoqi@0 2180
aoqi@0 2181 // Registers alive
aoqi@0 2182 // R14_state
aoqi@0 2183 // R15_prev_state
aoqi@0 2184 // R17_tos
aoqi@0 2185 //
aoqi@0 2186 // Registers updated
aoqi@0 2187 // R19_method
aoqi@0 2188 // R3_RET
aoqi@0 2189 // msg
aoqi@0 2190 {
aoqi@0 2191 Label L;
aoqi@0 2192
aoqi@0 2193 // Reload callee method, gc may have moved it.
aoqi@0 2194 __ ld(R19_method, state_(_method));
aoqi@0 2195
aoqi@0 2196 // We may be returning to a deoptimized frame in which case the
aoqi@0 2197 // usual assumption of a recursive return is not true.
aoqi@0 2198
aoqi@0 2199 // not equal = is recursive call
aoqi@0 2200 __ cmpdi(CCR0, R15_prev_state, 0);
aoqi@0 2201
aoqi@0 2202 __ bne(CCR0, L);
aoqi@0 2203
aoqi@0 2204 // Pop_frame capability.
aoqi@0 2205 // The pop_frame api says that the underlying frame is a Java frame, in this case
aoqi@0 2206 // (prev_state==null) it must be a compiled frame:
aoqi@0 2207 //
aoqi@0 2208 // Stack at this point: I, C2I + C, ...
aoqi@0 2209 //
aoqi@0 2210 // The outgoing arguments of the call have just been copied (popframe_preserve_args).
aoqi@0 2211 // By the pop_frame api, we must end up in an interpreted frame. So the compiled frame
aoqi@0 2212 // will be deoptimized. Deoptimization will restore the outgoing arguments from
aoqi@0 2213 // popframe_preserve_args, adjust the tos such that it includes the popframe_preserve_args,
aoqi@0 2214 // and adjust the bci such that the call will be executed again.
aoqi@0 2215 // We have no results, just pop the interpreter frame, resize the compiled frame to get rid
aoqi@0 2216 // of the c2i extension and return to the deopt_handler.
aoqi@0 2217 __ b(unwind_initial_activation);
aoqi@0 2218
aoqi@0 2219 // is recursive call
aoqi@0 2220 __ bind(L);
aoqi@0 2221
aoqi@0 2222 // Resume_interpreter expects the original tos in R3_RET.
aoqi@0 2223 __ ld(R3_RET, prev_state_(_stack));
aoqi@0 2224
aoqi@0 2225 // We're done.
aoqi@0 2226 __ li(msg, BytecodeInterpreter::popping_frame);
aoqi@0 2227
aoqi@0 2228 __ b(unwind_recursive_activation);
aoqi@0 2229 }
aoqi@0 2230
aoqi@0 2231
aoqi@0 2232 //=============================================================================
aoqi@0 2233
aoqi@0 2234 // We have finished an interpreted call. We are either returning to
aoqi@0 2235 // native (call_stub/c2) or we are returning to the interpreter.
aoqi@0 2236 // When returning to native, we must extract the result (if any)
aoqi@0 2237 // from the java expression stack and store it in the location the
aoqi@0 2238 // native abi expects. When returning to the interpreter we must
aoqi@0 2239 // simply do a stack to stack move as we unwind.
aoqi@0 2240
aoqi@0 2241 __ BIND(return_from_interpreted_method);
aoqi@0 2242
aoqi@0 2243 //
aoqi@0 2244 // Registers alive
aoqi@0 2245 // R16_thread - JavaThread*
aoqi@0 2246 // R15_prev_state - address of caller's BytecodeInterpreter or 0
aoqi@0 2247 // R14_state - address of callee's interpreter state
aoqi@0 2248 // R1_SP - callee's stack pointer
aoqi@0 2249 //
aoqi@0 2250 // Registers updated
aoqi@0 2251 // R19_method - callee's method
aoqi@0 2252 // R3_RET - address of result (new caller's tos),
aoqi@0 2253 //
aoqi@0 2254 // if returning to interpreted
aoqi@0 2255 // msg - message for interpreter,
aoqi@0 2256 // if returning to interpreted
aoqi@0 2257 //
aoqi@0 2258
aoqi@0 2259 // Check if this is the initial invocation of the frame manager.
aoqi@0 2260 // If so, R15_prev_state will be null.
aoqi@0 2261 __ cmpdi(CCR0, R15_prev_state, 0);
aoqi@0 2262
aoqi@0 2263 // Reload callee method, gc may have moved it.
aoqi@0 2264 __ ld(R19_method, state_(_method));
aoqi@0 2265
aoqi@0 2266 // Load the method's result type.
aoqi@0 2267 __ lwz(result_index, method_(result_index));
aoqi@0 2268
aoqi@0 2269 // Go to return_to_initial_caller if R15_prev_state is null.
aoqi@0 2270 __ beq(CCR0, return_to_initial_caller);
aoqi@0 2271
aoqi@0 2272 // Copy callee's result to caller's expression stack via inline stack-to-stack
aoqi@0 2273 // converters.
aoqi@0 2274 {
aoqi@0 2275 Register new_tos = R3_RET;
aoqi@0 2276 Register from_temp = R4_ARG2;
aoqi@0 2277 Register from = R5_ARG3;
aoqi@0 2278 Register tos = R6_ARG4;
aoqi@0 2279 Register tmp1 = R7_ARG5;
aoqi@0 2280 Register tmp2 = R8_ARG6;
aoqi@0 2281
aoqi@0 2282 ConditionRegister result_type_is_void = CCR1;
aoqi@0 2283 ConditionRegister result_type_is_long = CCR2;
aoqi@0 2284 ConditionRegister result_type_is_double = CCR3;
aoqi@0 2285
aoqi@0 2286 Label stack_to_stack_void;
aoqi@0 2287 Label stack_to_stack_double_slot; // T_LONG, T_DOUBLE
aoqi@0 2288 Label stack_to_stack_single_slot; // T_BOOLEAN, T_BYTE, T_CHAR, T_SHORT, T_INT, T_FLOAT, T_OBJECT
aoqi@0 2289 Label stack_to_stack_done;
aoqi@0 2290
aoqi@0 2291 // Pass callee's address of tos + BytesPerWord
aoqi@0 2292 __ ld(from_temp, state_(_stack));
aoqi@0 2293
aoqi@0 2294 // result type: void
aoqi@0 2295 __ cmpwi(result_type_is_void, result_index, AbstractInterpreter::BasicType_as_index(T_VOID));
aoqi@0 2296
aoqi@0 2297 // Pass caller's tos == callee's locals address
aoqi@0 2298 __ ld(tos, state_(_locals));
aoqi@0 2299
aoqi@0 2300 // result type: long
aoqi@0 2301 __ cmpwi(result_type_is_long, result_index, AbstractInterpreter::BasicType_as_index(T_LONG));
aoqi@0 2302
aoqi@0 2303 __ addi(from, from_temp, Interpreter::stackElementSize);
aoqi@0 2304
aoqi@0 2305 // !! don't branch above this line !!
aoqi@0 2306
aoqi@0 2307 // handle void
aoqi@0 2308 __ beq(result_type_is_void, stack_to_stack_void);
aoqi@0 2309
aoqi@0 2310 // result type: double
aoqi@0 2311 __ cmpwi(result_type_is_double, result_index, AbstractInterpreter::BasicType_as_index(T_DOUBLE));
aoqi@0 2312
aoqi@0 2313 // handle long or double
aoqi@0 2314 __ beq(result_type_is_long, stack_to_stack_double_slot);
aoqi@0 2315 __ beq(result_type_is_double, stack_to_stack_double_slot);
aoqi@0 2316
aoqi@0 2317 // fall through to single slot types (incl. object)
aoqi@0 2318
aoqi@0 2319 {
aoqi@0 2320 __ BIND(stack_to_stack_single_slot);
aoqi@0 2321 // T_BOOLEAN, T_BYTE, T_CHAR, T_SHORT, T_INT, T_FLOAT, T_OBJECT
aoqi@0 2322
aoqi@0 2323 __ ld(tmp1, 0, from);
aoqi@0 2324 __ std(tmp1, 0, tos);
aoqi@0 2325 // New expression stack top
aoqi@0 2326 __ addi(new_tos, tos, - BytesPerWord);
aoqi@0 2327
aoqi@0 2328 __ b(stack_to_stack_done);
aoqi@0 2329 }
aoqi@0 2330
aoqi@0 2331 {
aoqi@0 2332 __ BIND(stack_to_stack_double_slot);
aoqi@0 2333 // T_LONG, T_DOUBLE
aoqi@0 2334
aoqi@0 2335 // Move both entries for debug purposes even though only one is live
aoqi@0 2336 __ ld(tmp1, BytesPerWord, from);
aoqi@0 2337 __ ld(tmp2, 0, from);
aoqi@0 2338 __ std(tmp1, 0, tos);
aoqi@0 2339 __ std(tmp2, -BytesPerWord, tos);
aoqi@0 2340
aoqi@0 2341 // new expression stack top
aoqi@0 2342 __ addi(new_tos, tos, - 2 * BytesPerWord); // two slots
aoqi@0 2343 __ b(stack_to_stack_done);
aoqi@0 2344 }
aoqi@0 2345
aoqi@0 2346 {
aoqi@0 2347 __ BIND(stack_to_stack_void);
aoqi@0 2348 // T_VOID
aoqi@0 2349
aoqi@0 2350 // new expression stack top
aoqi@0 2351 __ mr(new_tos, tos);
aoqi@0 2352 // fall through to stack_to_stack_done
aoqi@0 2353 }
aoqi@0 2354
aoqi@0 2355 __ BIND(stack_to_stack_done);
aoqi@0 2356 }
aoqi@0 2357
aoqi@0 2358 // new tos = R3_RET
aoqi@0 2359
aoqi@0 2360 // Get the message for the interpreter
aoqi@0 2361 __ li(msg, BytecodeInterpreter::method_resume);
aoqi@0 2362
aoqi@0 2363 // And fall thru
aoqi@0 2364
aoqi@0 2365
aoqi@0 2366 //=============================================================================
aoqi@0 2367 // Restore caller's interpreter state and pass pointer to caller's
aoqi@0 2368 // new tos to caller.
aoqi@0 2369
aoqi@0 2370 __ BIND(unwind_recursive_activation);
aoqi@0 2371
aoqi@0 2372 //
aoqi@0 2373 // Registers alive
aoqi@0 2374 // R15_prev_state - address of caller's BytecodeInterpreter
aoqi@0 2375 // R3_RET - address of caller's tos
aoqi@0 2376 // msg - message for caller's BytecodeInterpreter
aoqi@0 2377 // R1_SP - callee's stack pointer
aoqi@0 2378 //
aoqi@0 2379 // Registers updated
aoqi@0 2380 // R14_state - address of caller's BytecodeInterpreter
aoqi@0 2381 // R15_prev_state - address of its parent or 0
aoqi@0 2382 //
aoqi@0 2383
aoqi@0 2384 // Pop callee's interpreter and set R14_state to caller's interpreter.
aoqi@0 2385 __ pop_interpreter_state(/*prev_state_may_be_0=*/false);
aoqi@0 2386
aoqi@0 2387 // And fall thru
aoqi@0 2388
aoqi@0 2389
aoqi@0 2390 //=============================================================================
aoqi@0 2391 // Resume the (calling) interpreter after a call.
aoqi@0 2392
aoqi@0 2393 __ BIND(resume_interpreter);
aoqi@0 2394
aoqi@0 2395 //
aoqi@0 2396 // Registers alive
aoqi@0 2397 // R14_state - address of resuming BytecodeInterpreter
aoqi@0 2398 // R15_prev_state - address of its parent or 0
aoqi@0 2399 // R3_RET - address of resuming tos
aoqi@0 2400 // msg - message for resuming interpreter
aoqi@0 2401 // R1_SP - callee's stack pointer
aoqi@0 2402 //
aoqi@0 2403 // Registers updated
aoqi@0 2404 // R1_SP - caller's stack pointer
aoqi@0 2405 //
aoqi@0 2406
aoqi@0 2407 // Restore C stack pointer of caller (resuming interpreter),
aoqi@0 2408 // R14_state already points to the resuming BytecodeInterpreter.
aoqi@0 2409 __ pop_interpreter_frame_to_state(R14_state, R21_tmp1, R11_scratch1, R12_scratch2);
aoqi@0 2410
aoqi@0 2411 // Store new address of tos (holding return value) in interpreter state.
aoqi@0 2412 __ std(R3_RET, state_(_stack));
aoqi@0 2413
aoqi@0 2414 // Store message for interpreter.
aoqi@0 2415 __ stw(msg, state_(_msg));
aoqi@0 2416
aoqi@0 2417 __ b(call_interpreter);
aoqi@0 2418
aoqi@0 2419 //=============================================================================
aoqi@0 2420 // Interpreter returning to native code (call_stub/c1/c2) from
aoqi@0 2421 // initial activation. Convert stack result and unwind activation.
aoqi@0 2422
aoqi@0 2423 __ BIND(return_to_initial_caller);
aoqi@0 2424
aoqi@0 2425 //
aoqi@0 2426 // Registers alive
aoqi@0 2427 // R19_method - callee's Method
aoqi@0 2428 // R14_state - address of callee's interpreter state
aoqi@0 2429 // R16_thread - JavaThread
aoqi@0 2430 // R1_SP - callee's stack pointer
aoqi@0 2431 //
aoqi@0 2432 // Registers updated
aoqi@0 2433 // R3_RET/F1_RET - result in expected output register
aoqi@0 2434 //
aoqi@0 2435
aoqi@0 2436 // If we have an exception pending we have no result and we
aoqi@0 2437 // must figure out where to really return to.
aoqi@0 2438 //
aoqi@0 2439 __ ld(pending_exception, thread_(pending_exception));
aoqi@0 2440 __ cmpdi(CCR0, pending_exception, 0);
aoqi@0 2441 __ bne(CCR0, unwind_initial_activation_pending_exception);
aoqi@0 2442
aoqi@0 2443 __ lwa(result_index, method_(result_index));
aoqi@0 2444
aoqi@0 2445 // Address of stub descriptor address array.
aoqi@0 2446 __ load_const(stub_addr, CppInterpreter::stack_result_to_native());
aoqi@0 2447
aoqi@0 2448 // Pass address of callee's tos + BytesPerWord.
aoqi@0 2449 // Will then point directly to result.
aoqi@0 2450 __ ld(R3_ARG1, state_(_stack));
aoqi@0 2451 __ addi(R3_ARG1, R3_ARG1, Interpreter::stackElementSize);
aoqi@0 2452
aoqi@0 2453 // Address of stub descriptor address
aoqi@0 2454 __ sldi(result_index, result_index, LogBytesPerWord);
aoqi@0 2455 __ add(stub_addr, stub_addr, result_index);
aoqi@0 2456
aoqi@0 2457 // Stub descriptor address
aoqi@0 2458 __ ld(stub_addr, 0, stub_addr);
aoqi@0 2459
aoqi@0 2460 // TODO: don't do this via a call, do it in place!
aoqi@0 2461 //
aoqi@0 2462 // call stub via descriptor
aoqi@0 2463 __ call_stub(stub_addr);
aoqi@0 2464
aoqi@0 2465 __ BIND(unwind_initial_activation);
aoqi@0 2466
aoqi@0 2467 // Unwind from initial activation. No exception is pending.
aoqi@0 2468
aoqi@0 2469 //
aoqi@0 2470 // Stack layout at this point:
aoqi@0 2471 //
aoqi@0 2472 // 0 [TOP_IJAVA_FRAME_ABI] <-- R1_SP
aoqi@0 2473 // ...
aoqi@0 2474 // CALLER [PARENT_IJAVA_FRAME_ABI]
aoqi@0 2475 // ...
aoqi@0 2476 // CALLER [unextended ABI]
aoqi@0 2477 // ...
aoqi@0 2478 //
aoqi@0 2479 // The CALLER frame has a C2I adapter or is an entry-frame.
aoqi@0 2480 //
aoqi@0 2481
aoqi@0 2482 // An interpreter frame exists, we may pop the TOP_IJAVA_FRAME and
aoqi@0 2483 // turn the caller's PARENT_IJAVA_FRAME back into a TOP_IJAVA_FRAME.
aoqi@0 2484 // But, we simply restore the return pc from the caller's frame and
aoqi@0 2485 // use the caller's initial_caller_sp as the new SP which pops the
aoqi@0 2486 // interpreter frame and "resizes" the caller's frame to its "unextended"
aoqi@0 2487 // size.
aoqi@0 2488
aoqi@0 2489 // get rid of top frame
aoqi@0 2490 __ pop_frame();
aoqi@0 2491
aoqi@0 2492 // Load return PC from parent frame.
aoqi@0 2493 __ ld(R21_tmp1, _parent_ijava_frame_abi(lr), R1_SP);
aoqi@0 2494
aoqi@0 2495 // Resize frame to get rid of a potential extension.
aoqi@0 2496 __ resize_frame_to_initial_caller(R11_scratch1, R12_scratch2);
aoqi@0 2497
aoqi@0 2498 // update LR
aoqi@0 2499 __ mtlr(R21_tmp1);
aoqi@0 2500
aoqi@0 2501 // return
aoqi@0 2502 __ blr();
aoqi@0 2503
aoqi@0 2504 //=============================================================================
aoqi@0 2505 // Unwind from initial activation. An exception is pending
aoqi@0 2506
aoqi@0 2507 __ BIND(unwind_initial_activation_pending_exception);
aoqi@0 2508
aoqi@0 2509 //
aoqi@0 2510 // Stack layout at this point:
aoqi@0 2511 //
aoqi@0 2512 // 0 [TOP_IJAVA_FRAME_ABI] <-- R1_SP
aoqi@0 2513 // ...
aoqi@0 2514 // CALLER [PARENT_IJAVA_FRAME_ABI]
aoqi@0 2515 // ...
aoqi@0 2516 // CALLER [unextended ABI]
aoqi@0 2517 // ...
aoqi@0 2518 //
aoqi@0 2519 // The CALLER frame has a C2I adapter or is an entry-frame.
aoqi@0 2520 //
aoqi@0 2521
aoqi@0 2522 // An interpreter frame exists, we may pop the TOP_IJAVA_FRAME and
aoqi@0 2523 // turn the caller's PARENT_IJAVA_FRAME back into a TOP_IJAVA_FRAME.
aoqi@0 2524 // But, we just pop the current TOP_IJAVA_FRAME and fall through
aoqi@0 2525
aoqi@0 2526 __ pop_frame();
aoqi@0 2527 __ ld(R3_ARG1, _top_ijava_frame_abi(lr), R1_SP);
aoqi@0 2528
aoqi@0 2529 //
aoqi@0 2530 // Stack layout at this point:
aoqi@0 2531 //
aoqi@0 2532 // CALLER [PARENT_IJAVA_FRAME_ABI] <-- R1_SP
aoqi@0 2533 // ...
aoqi@0 2534 // CALLER [unextended ABI]
aoqi@0 2535 // ...
aoqi@0 2536 //
aoqi@0 2537 // The CALLER frame has a C2I adapter or is an entry-frame.
aoqi@0 2538 //
aoqi@0 2539 // Registers alive
aoqi@0 2540 // R16_thread
aoqi@0 2541 // R3_ARG1 - return address to caller
aoqi@0 2542 //
aoqi@0 2543 // Registers updated
aoqi@0 2544 // R3_ARG1 - address of pending exception
aoqi@0 2545 // R4_ARG2 - issuing pc = return address to caller
aoqi@0 2546 // LR - address of exception handler stub
aoqi@0 2547 //
aoqi@0 2548
aoqi@0 2549 // Resize frame to get rid of a potential extension.
aoqi@0 2550 __ resize_frame_to_initial_caller(R11_scratch1, R12_scratch2);
aoqi@0 2551
aoqi@0 2552 __ mr(R14, R3_ARG1); // R14 := ARG1
aoqi@0 2553 __ mr(R4_ARG2, R3_ARG1); // ARG2 := ARG1
aoqi@0 2554
aoqi@0 2555 // Find the address of the "catch_exception" stub.
aoqi@0 2556 __ push_frame_reg_args(0, R11_scratch1);
aoqi@0 2557 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::exception_handler_for_return_address),
aoqi@0 2558 R16_thread,
aoqi@0 2559 R4_ARG2);
aoqi@0 2560 __ pop_frame();
aoqi@0 2561
aoqi@0 2562 // Load continuation address into LR.
aoqi@0 2563 __ mtlr(R3_RET);
aoqi@0 2564
aoqi@0 2565 // Load address of pending exception and clear it in thread object.
aoqi@0 2566 __ ld(R3_ARG1/*R3_RET*/, thread_(pending_exception));
aoqi@0 2567 __ li(R4_ARG2, 0);
aoqi@0 2568 __ std(R4_ARG2, thread_(pending_exception));
aoqi@0 2569
aoqi@0 2570 // re-load issuing pc
aoqi@0 2571 __ mr(R4_ARG2, R14);
aoqi@0 2572
aoqi@0 2573 // Branch to found exception handler.
aoqi@0 2574 __ blr();
aoqi@0 2575
aoqi@0 2576 //=============================================================================
aoqi@0 2577 // Call a new method. Compute new args and trim the expression stack
aoqi@0 2578 // to only what we are currently using and then recurse.
aoqi@0 2579
aoqi@0 2580 __ BIND(call_method);
aoqi@0 2581
aoqi@0 2582 //
aoqi@0 2583 // Registers alive
aoqi@0 2584 // R16_thread
aoqi@0 2585 // R14_state - address of caller's BytecodeInterpreter
aoqi@0 2586 // R1_SP - caller's stack pointer
aoqi@0 2587 //
aoqi@0 2588 // Registers updated
aoqi@0 2589 // R15_prev_state - address of caller's BytecodeInterpreter
aoqi@0 2590 // R17_tos - address of caller's tos
aoqi@0 2591 // R19_method - callee's Method
aoqi@0 2592 // R1_SP - trimmed back
aoqi@0 2593 //
aoqi@0 2594
aoqi@0 2595 // Very-local scratch registers.
aoqi@0 2596
aoqi@0 2597 const Register offset = R21_tmp1;
aoqi@0 2598 const Register tmp = R22_tmp2;
aoqi@0 2599 const Register self_entry = R23_tmp3;
aoqi@0 2600 const Register stub_entry = R24_tmp4;
aoqi@0 2601
aoqi@0 2602 const ConditionRegister cr = CCR0;
aoqi@0 2603
aoqi@0 2604 // Load the address of the frame manager.
aoqi@0 2605 __ load_const(self_entry, &interpreter_frame_manager);
aoqi@0 2606 __ ld(self_entry, 0, self_entry);
aoqi@0 2607
aoqi@0 2608 // Load BytecodeInterpreter._result._to_call._callee (callee's Method).
aoqi@0 2609 __ ld(R19_method, state_(_result._to_call._callee));
aoqi@0 2610 // Load BytecodeInterpreter._stack (outgoing tos).
aoqi@0 2611 __ ld(R17_tos, state_(_stack));
aoqi@0 2612
aoqi@0 2613 // Save address of caller's BytecodeInterpreter.
aoqi@0 2614 __ mr(R15_prev_state, R14_state);
aoqi@0 2615
aoqi@0 2616 // Load the callee's entry point.
aoqi@0 2617 // Load BytecodeInterpreter._result._to_call._callee_entry_point.
aoqi@0 2618 __ ld(stub_entry, state_(_result._to_call._callee_entry_point));
aoqi@0 2619
aoqi@0 2620 // Check whether stub_entry is equal to self_entry.
aoqi@0 2621 __ cmpd(cr, self_entry, stub_entry);
aoqi@0 2622 // if (self_entry == stub_entry)
aoqi@0 2623 // do a re-dispatch
aoqi@0 2624 __ beq(cr, re_dispatch);
aoqi@0 2625 // else
aoqi@0 2626 // call the specialized entry (adapter for jni or compiled code)
aoqi@0 2627 __ BIND(call_special);
aoqi@0 2628
aoqi@0 2629 //
aoqi@0 2630 // Call the entry generated by `InterpreterGenerator::generate_native_entry'.
aoqi@0 2631 //
aoqi@0 2632 // Registers alive
aoqi@0 2633 // R16_thread
aoqi@0 2634 // R15_prev_state - address of caller's BytecodeInterpreter
aoqi@0 2635 // R19_method - callee's Method
aoqi@0 2636 // R17_tos - address of caller's tos
aoqi@0 2637 // R1_SP - caller's stack pointer
aoqi@0 2638 //
aoqi@0 2639
aoqi@0 2640 // Mark return from specialized entry for generate_native_entry.
aoqi@0 2641 guarantee(return_from_native_pc != (address) NULL, "precondition");
aoqi@0 2642 frame_manager_specialized_return = return_from_native_pc;
aoqi@0 2643
aoqi@0 2644 // Set sender_SP in case we call interpreter native wrapper which
aoqi@0 2645 // will expect it. Compiled code should not care.
aoqi@0 2646 __ mr(R21_sender_SP, R1_SP);
aoqi@0 2647
aoqi@0 2648 // Do a tail call here, and let the link register point to
aoqi@0 2649 // frame_manager_specialized_return which is return_from_native_pc.
aoqi@0 2650 __ load_const(tmp, frame_manager_specialized_return);
aoqi@0 2651 __ call_stub_and_return_to(stub_entry, tmp /* return_pc=tmp */);
aoqi@0 2652
aoqi@0 2653
aoqi@0 2654 //=============================================================================
aoqi@0 2655 //
aoqi@0 2656 // InterpretMethod triggered OSR compilation of some Java method M
aoqi@0 2657 // and now asks to run the compiled code. We call this code the
aoqi@0 2658 // `callee'.
aoqi@0 2659 //
aoqi@0 2660 // This is our current idea on how OSR should look like on PPC64:
aoqi@0 2661 //
aoqi@0 2662 // While interpreting a Java method M the stack is:
aoqi@0 2663 //
aoqi@0 2664 // (InterpretMethod (M), IJAVA_FRAME (M), ANY_FRAME, ...).
aoqi@0 2665 //
aoqi@0 2666 // After having OSR compiled M, `InterpretMethod' returns to the
aoqi@0 2667 // frame manager, sending the message `retry_method_osr'. The stack
aoqi@0 2668 // is:
aoqi@0 2669 //
aoqi@0 2670 // (IJAVA_FRAME (M), ANY_FRAME, ...).
aoqi@0 2671 //
aoqi@0 2672 // The compiler will have generated an `nmethod' suitable for
aoqi@0 2673 // continuing execution of M at the bytecode index at which OSR took
aoqi@0 2674 // place. So now the frame manager calls the OSR entry. The OSR
aoqi@0 2675 // entry sets up a JIT_FRAME for M and continues execution of M with
aoqi@0 2676 // initial state determined by the IJAVA_FRAME.
aoqi@0 2677 //
aoqi@0 2678 // (JIT_FRAME (M), IJAVA_FRAME (M), ANY_FRAME, ...).
aoqi@0 2679 //
aoqi@0 2680
aoqi@0 2681 __ BIND(retry_method_osr);
aoqi@0 2682 {
aoqi@0 2683 //
aoqi@0 2684 // Registers alive
aoqi@0 2685 // R16_thread
aoqi@0 2686 // R15_prev_state - address of caller's BytecodeInterpreter
aoqi@0 2687 // R14_state - address of callee's BytecodeInterpreter
aoqi@0 2688 // R1_SP - callee's SP before call to InterpretMethod
aoqi@0 2689 //
aoqi@0 2690 // Registers updated
aoqi@0 2691 // R17 - pointer to callee's locals array
aoqi@0 2692 // (declared via `interpreter_arg_ptr_reg' in the AD file)
aoqi@0 2693 // R19_method - callee's Method
aoqi@0 2694 // R1_SP - callee's SP (will become SP of OSR adapter frame)
aoqi@0 2695 //
aoqi@0 2696
aoqi@0 2697 // Provide a debugger breakpoint in the frame manager if breakpoints
aoqi@0 2698 // in osr'd methods are requested.
aoqi@0 2699 #ifdef COMPILER2
aoqi@0 2700 NOT_PRODUCT( if (OptoBreakpointOSR) { __ illtrap(); } )
aoqi@0 2701 #endif
aoqi@0 2702
aoqi@0 2703 // Load callee's pointer to locals array from callee's state.
aoqi@0 2704 // __ ld(R17, state_(_locals));
aoqi@0 2705
aoqi@0 2706 // Load osr entry.
aoqi@0 2707 __ ld(R12_scratch2, state_(_result._osr._osr_entry));
aoqi@0 2708
aoqi@0 2709 // Load address of temporary osr buffer to arg1.
aoqi@0 2710 __ ld(R3_ARG1, state_(_result._osr._osr_buf));
aoqi@0 2711 __ mtctr(R12_scratch2);
aoqi@0 2712
aoqi@0 2713 // Load method, gc may move it during execution of osr'd method.
aoqi@0 2714 __ ld(R22_tmp2, state_(_method));
aoqi@0 2715 // Load message 'call_method'.
aoqi@0 2716 __ li(R23_tmp3, BytecodeInterpreter::call_method);
aoqi@0 2717
aoqi@0 2718 {
aoqi@0 2719 // Pop the IJAVA frame of the method which we are going to call osr'd.
aoqi@0 2720 Label no_state, skip_no_state;
aoqi@0 2721 __ pop_interpreter_state(/*prev_state_may_be_0=*/true);
aoqi@0 2722 __ cmpdi(CCR0, R14_state,0);
aoqi@0 2723 __ beq(CCR0, no_state);
aoqi@0 2724 // return to interpreter
aoqi@0 2725 __ pop_interpreter_frame_to_state(R14_state, R11_scratch1, R12_scratch2, R21_tmp1);
aoqi@0 2726
aoqi@0 2727 // Init _result._to_call._callee and tell gc that it contains a valid oop
aoqi@0 2728 // by setting _msg to 'call_method'.
aoqi@0 2729 __ std(R22_tmp2, state_(_result._to_call._callee));
aoqi@0 2730 // TODO: PPC port: assert(4 == BytecodeInterpreter::sz_msg(), "unexpected field size");
aoqi@0 2731 __ stw(R23_tmp3, state_(_msg));
aoqi@0 2732
aoqi@0 2733 __ load_const(R21_tmp1, frame_manager_specialized_return);
aoqi@0 2734 __ b(skip_no_state);
aoqi@0 2735 __ bind(no_state);
aoqi@0 2736
aoqi@0 2737 // Return to initial caller.
aoqi@0 2738
aoqi@0 2739 // Get rid of top frame.
aoqi@0 2740 __ pop_frame();
aoqi@0 2741
aoqi@0 2742 // Load return PC from parent frame.
aoqi@0 2743 __ ld(R21_tmp1, _parent_ijava_frame_abi(lr), R1_SP);
aoqi@0 2744
aoqi@0 2745 // Resize frame to get rid of a potential extension.
aoqi@0 2746 __ resize_frame_to_initial_caller(R11_scratch1, R12_scratch2);
aoqi@0 2747
aoqi@0 2748 __ bind(skip_no_state);
aoqi@0 2749
aoqi@0 2750 // Update LR with return pc.
aoqi@0 2751 __ mtlr(R21_tmp1);
aoqi@0 2752 }
aoqi@0 2753 // Jump to the osr entry point.
aoqi@0 2754 __ bctr();
aoqi@0 2755
aoqi@0 2756 }
aoqi@0 2757
aoqi@0 2758 //=============================================================================
aoqi@0 2759 // Interpreted method "returned" with an exception, pass it on.
aoqi@0 2760 // Pass no result, unwind activation and continue/return to
aoqi@0 2761 // interpreter/call_stub/c2.
aoqi@0 2762
aoqi@0 2763 __ BIND(throwing_exception);
aoqi@0 2764
aoqi@0 2765 // Check if this is the initial invocation of the frame manager. If
aoqi@0 2766 // so, previous interpreter state in R15_prev_state will be null.
aoqi@0 2767
aoqi@0 2768 // New tos of caller is callee's first parameter address, that is
aoqi@0 2769 // callee's incoming arguments are popped.
aoqi@0 2770 __ ld(R3_RET, state_(_locals));
aoqi@0 2771
aoqi@0 2772 // Check whether this is an initial call.
aoqi@0 2773 __ cmpdi(CCR0, R15_prev_state, 0);
aoqi@0 2774 // Yes, called from the call stub or from generated code via a c2i frame.
aoqi@0 2775 __ beq(CCR0, unwind_initial_activation_pending_exception);
aoqi@0 2776
aoqi@0 2777 // Send resume message, interpreter will see the exception first.
aoqi@0 2778
aoqi@0 2779 __ li(msg, BytecodeInterpreter::method_resume);
aoqi@0 2780 __ b(unwind_recursive_activation);
aoqi@0 2781
aoqi@0 2782
aoqi@0 2783 //=============================================================================
aoqi@0 2784 // Push the last instruction out to the code buffer.
aoqi@0 2785
aoqi@0 2786 {
aoqi@0 2787 __ unimplemented("end of InterpreterGenerator::generate_normal_entry", 128);
aoqi@0 2788 }
aoqi@0 2789
aoqi@0 2790 interpreter_frame_manager = entry;
aoqi@0 2791 return interpreter_frame_manager;
aoqi@0 2792 }
aoqi@0 2793
aoqi@0 2794 // Generate code for various sorts of method entries
aoqi@0 2795 //
aoqi@0 2796 address AbstractInterpreterGenerator::generate_method_entry(AbstractInterpreter::MethodKind kind) {
aoqi@0 2797 address entry_point = NULL;
aoqi@0 2798
aoqi@0 2799 switch (kind) {
aoqi@0 2800 case Interpreter::zerolocals : break;
aoqi@0 2801 case Interpreter::zerolocals_synchronized : break;
aoqi@0 2802 case Interpreter::native : // Fall thru
aoqi@0 2803 case Interpreter::native_synchronized : entry_point = ((CppInterpreterGenerator*)this)->generate_native_entry(); break;
aoqi@0 2804 case Interpreter::empty : break;
aoqi@0 2805 case Interpreter::accessor : entry_point = ((InterpreterGenerator*)this)->generate_accessor_entry(); break;
aoqi@0 2806 case Interpreter::abstract : entry_point = ((InterpreterGenerator*)this)->generate_abstract_entry(); break;
aoqi@0 2807 // These are special interpreter intrinsics which we don't support so far.
aoqi@0 2808 case Interpreter::java_lang_math_sin : break;
aoqi@0 2809 case Interpreter::java_lang_math_cos : break;
aoqi@0 2810 case Interpreter::java_lang_math_tan : break;
aoqi@0 2811 case Interpreter::java_lang_math_abs : break;
aoqi@0 2812 case Interpreter::java_lang_math_log : break;
aoqi@0 2813 case Interpreter::java_lang_math_log10 : break;
aoqi@0 2814 case Interpreter::java_lang_math_sqrt : break;
aoqi@0 2815 case Interpreter::java_lang_math_pow : break;
aoqi@0 2816 case Interpreter::java_lang_math_exp : break;
aoqi@0 2817 case Interpreter::java_lang_ref_reference_get: entry_point = ((InterpreterGenerator*)this)->generate_Reference_get_entry(); break;
aoqi@0 2818 default : ShouldNotReachHere(); break;
aoqi@0 2819 }
aoqi@0 2820
aoqi@0 2821 if (entry_point) {
aoqi@0 2822 return entry_point;
aoqi@0 2823 }
aoqi@0 2824 return ((InterpreterGenerator*)this)->generate_normal_entry();
aoqi@0 2825 }
aoqi@0 2826
aoqi@0 2827 InterpreterGenerator::InterpreterGenerator(StubQueue* code)
aoqi@0 2828 : CppInterpreterGenerator(code) {
aoqi@0 2829 generate_all(); // down here so it can be "virtual"
aoqi@0 2830 }
aoqi@0 2831
aoqi@0 2832 // How much stack a topmost interpreter method activation needs in words.
aoqi@0 2833 int AbstractInterpreter::size_top_interpreter_activation(Method* method) {
aoqi@0 2834 // Computation is in bytes not words to match layout_activation_impl
aoqi@0 2835 // below, but the return is in words.
aoqi@0 2836
aoqi@0 2837 //
aoqi@0 2838 // 0 [TOP_IJAVA_FRAME_ABI] \
aoqi@0 2839 // alignment (optional) \ |
aoqi@0 2840 // [operand stack / Java parameters] > stack | |
aoqi@0 2841 // [monitors] (optional) > monitors | |
aoqi@0 2842 // [PARENT_IJAVA_FRAME_ABI] \ | |
aoqi@0 2843 // [BytecodeInterpreter object] > interpreter \ | | |
aoqi@0 2844 // alignment (optional) | round | parent | round | top
aoqi@0 2845 // [Java result] (2 slots) > result | | | |
aoqi@0 2846 // [Java non-arg locals] \ locals | | | |
aoqi@0 2847 // [arg locals] / / / / /
aoqi@0 2848 //
aoqi@0 2849
aoqi@0 2850 int locals = method->max_locals() * BytesPerWord;
aoqi@0 2851 int interpreter = frame::interpreter_frame_cinterpreterstate_size_in_bytes();
aoqi@0 2852 int result = 2 * BytesPerWord;
aoqi@0 2853
aoqi@0 2854 int parent = round_to(interpreter + result + locals, 16) + frame::parent_ijava_frame_abi_size;
aoqi@0 2855
aoqi@0 2856 int stack = method->max_stack() * BytesPerWord;
aoqi@0 2857 int monitors = method->is_synchronized() ? frame::interpreter_frame_monitor_size_in_bytes() : 0;
aoqi@0 2858 int top = round_to(parent + monitors + stack, 16) + frame::top_ijava_frame_abi_size;
aoqi@0 2859
aoqi@0 2860 return (top / BytesPerWord);
aoqi@0 2861 }
aoqi@0 2862
aoqi@0 2863 void BytecodeInterpreter::layout_interpreterState(interpreterState to_fill,
aoqi@0 2864 frame* caller,
aoqi@0 2865 frame* current,
aoqi@0 2866 Method* method,
aoqi@0 2867 intptr_t* locals,
aoqi@0 2868 intptr_t* stack,
aoqi@0 2869 intptr_t* stack_base,
aoqi@0 2870 intptr_t* monitor_base,
aoqi@0 2871 intptr_t* frame_sp,
aoqi@0 2872 bool is_top_frame) {
aoqi@0 2873 // What about any vtable?
aoqi@0 2874 //
aoqi@0 2875 to_fill->_thread = JavaThread::current();
aoqi@0 2876 // This gets filled in later but make it something recognizable for now.
aoqi@0 2877 to_fill->_bcp = method->code_base();
aoqi@0 2878 to_fill->_locals = locals;
aoqi@0 2879 to_fill->_constants = method->constants()->cache();
aoqi@0 2880 to_fill->_method = method;
aoqi@0 2881 to_fill->_mdx = NULL;
aoqi@0 2882 to_fill->_stack = stack;
aoqi@0 2883
aoqi@0 2884 if (is_top_frame && JavaThread::current()->popframe_forcing_deopt_reexecution()) {
aoqi@0 2885 to_fill->_msg = deopt_resume2;
aoqi@0 2886 } else {
aoqi@0 2887 to_fill->_msg = method_resume;
aoqi@0 2888 }
aoqi@0 2889 to_fill->_result._to_call._bcp_advance = 0;
aoqi@0 2890 to_fill->_result._to_call._callee_entry_point = NULL; // doesn't matter to anyone
aoqi@0 2891 to_fill->_result._to_call._callee = NULL; // doesn't matter to anyone
aoqi@0 2892 to_fill->_prev_link = NULL;
aoqi@0 2893
aoqi@0 2894 if (caller->is_interpreted_frame()) {
aoqi@0 2895 interpreterState prev = caller->get_interpreterState();
aoqi@0 2896
aoqi@0 2897 // Support MH calls. Make sure the interpreter will return the right address:
aoqi@0 2898 // 1. Caller did ordinary interpreted->compiled call call: Set a prev_state
aoqi@0 2899 // which makes the CPP interpreter return to frame manager "return_from_interpreted_method"
aoqi@0 2900 // entry after finishing execution.
aoqi@0 2901 // 2. Caller did a MH call: If the caller has a MethodHandleInvoke in it's
aoqi@0 2902 // state (invariant: must be the caller of the bottom vframe) we used the
aoqi@0 2903 // "call_special" entry to do the call, meaning the arguments have not been
aoqi@0 2904 // popped from the stack. Therefore, don't enter a prev state in this case
aoqi@0 2905 // in order to return to "return_from_native" frame manager entry which takes
aoqi@0 2906 // care of popping arguments. Also, don't overwrite the MH.invoke Method in
aoqi@0 2907 // the prev_state in order to be able to figure out the number of arguments to
aoqi@0 2908 // pop.
aoqi@0 2909 // The parameter method can represent MethodHandle.invokeExact(...).
aoqi@0 2910 // The MethodHandleCompiler generates these synthetic Methods,
aoqi@0 2911 // including bytecodes, if an invokedynamic call gets inlined. In
aoqi@0 2912 // this case we want to return like from any other interpreted
aoqi@0 2913 // Java call, so we set _prev_link.
aoqi@0 2914 to_fill->_prev_link = prev;
aoqi@0 2915
aoqi@0 2916 if (*prev->_bcp == Bytecodes::_invokeinterface || *prev->_bcp == Bytecodes::_invokedynamic) {
aoqi@0 2917 prev->_result._to_call._bcp_advance = 5;
aoqi@0 2918 } else {
aoqi@0 2919 prev->_result._to_call._bcp_advance = 3;
aoqi@0 2920 }
aoqi@0 2921 }
aoqi@0 2922 to_fill->_oop_temp = NULL;
aoqi@0 2923 to_fill->_stack_base = stack_base;
aoqi@0 2924 // Need +1 here because stack_base points to the word just above the
aoqi@0 2925 // first expr stack entry and stack_limit is supposed to point to
aoqi@0 2926 // the word just below the last expr stack entry. See
aoqi@0 2927 // generate_compute_interpreter_state.
aoqi@0 2928 to_fill->_stack_limit = stack_base - (method->max_stack() + 1);
aoqi@0 2929 to_fill->_monitor_base = (BasicObjectLock*) monitor_base;
aoqi@0 2930
aoqi@0 2931 to_fill->_frame_bottom = frame_sp;
aoqi@0 2932
aoqi@0 2933 // PPC64 specific
aoqi@0 2934 to_fill->_last_Java_pc = NULL;
aoqi@0 2935 to_fill->_last_Java_fp = NULL;
aoqi@0 2936 to_fill->_last_Java_sp = frame_sp;
aoqi@0 2937 #ifdef ASSERT
aoqi@0 2938 to_fill->_self_link = to_fill;
aoqi@0 2939 to_fill->_native_fresult = 123456.789;
aoqi@0 2940 to_fill->_native_lresult = CONST64(0xdeafcafedeadc0de);
aoqi@0 2941 #endif
aoqi@0 2942 }
aoqi@0 2943
aoqi@0 2944 void BytecodeInterpreter::pd_layout_interpreterState(interpreterState istate,
aoqi@0 2945 address last_Java_pc,
aoqi@0 2946 intptr_t* last_Java_fp) {
aoqi@0 2947 istate->_last_Java_pc = last_Java_pc;
aoqi@0 2948 istate->_last_Java_fp = last_Java_fp;
aoqi@0 2949 }
aoqi@0 2950
aoqi@0 2951 // Computes monitor_size and top_frame_size in bytes.
aoqi@0 2952 static void frame_size_helper(int max_stack,
aoqi@0 2953 int monitors,
aoqi@0 2954 int& monitor_size,
aoqi@0 2955 int& top_frame_size) {
aoqi@0 2956 monitor_size = frame::interpreter_frame_monitor_size_in_bytes() * monitors;
aoqi@0 2957 top_frame_size = round_to(frame::interpreter_frame_cinterpreterstate_size_in_bytes()
aoqi@0 2958 + monitor_size
aoqi@0 2959 + max_stack * Interpreter::stackElementSize
aoqi@0 2960 + 2 * Interpreter::stackElementSize,
aoqi@0 2961 frame::alignment_in_bytes)
aoqi@0 2962 + frame::top_ijava_frame_abi_size;
aoqi@0 2963 }
aoqi@0 2964
aoqi@0 2965 // Returns number of stackElementWords needed for the interpreter frame with the
aoqi@0 2966 // given sections.
aoqi@0 2967 int AbstractInterpreter::size_activation(int max_stack,
aoqi@0 2968 int temps,
aoqi@0 2969 int extra_args,
aoqi@0 2970 int monitors,
aoqi@0 2971 int callee_params,
aoqi@0 2972 int callee_locals,
aoqi@0 2973 bool is_top_frame) {
aoqi@0 2974 int monitor_size = 0;
aoqi@0 2975 int top_frame_size = 0;
aoqi@0 2976 frame_size_helper(max_stack, monitors, monitor_size, top_frame_size);
aoqi@0 2977
aoqi@0 2978 int frame_size;
aoqi@0 2979 if (is_top_frame) {
aoqi@0 2980 frame_size = top_frame_size;
aoqi@0 2981 } else {
aoqi@0 2982 frame_size = round_to(frame::interpreter_frame_cinterpreterstate_size_in_bytes()
aoqi@0 2983 + monitor_size
aoqi@0 2984 + (temps - callee_params + callee_locals) * Interpreter::stackElementSize
aoqi@0 2985 + 2 * Interpreter::stackElementSize,
aoqi@0 2986 frame::alignment_in_bytes)
aoqi@0 2987 + frame::parent_ijava_frame_abi_size;
aoqi@0 2988 assert(extra_args == 0, "non-zero for top_frame only");
aoqi@0 2989 }
aoqi@0 2990
aoqi@0 2991 return frame_size / Interpreter::stackElementSize;
aoqi@0 2992 }
aoqi@0 2993
aoqi@0 2994 void AbstractInterpreter::layout_activation(Method* method,
aoqi@0 2995 int temps, // Number of slots on java expression stack in use.
aoqi@0 2996 int popframe_args,
aoqi@0 2997 int monitors, // Number of active monitors.
aoqi@0 2998 int caller_actual_parameters,
aoqi@0 2999 int callee_params,// Number of slots for callee parameters.
aoqi@0 3000 int callee_locals,// Number of slots for locals.
aoqi@0 3001 frame* caller,
aoqi@0 3002 frame* interpreter_frame,
aoqi@0 3003 bool is_top_frame,
aoqi@0 3004 bool is_bottom_frame) {
aoqi@0 3005
aoqi@0 3006 // NOTE this code must exactly mimic what
aoqi@0 3007 // InterpreterGenerator::generate_compute_interpreter_state() does
aoqi@0 3008 // as far as allocating an interpreter frame. However there is an
aoqi@0 3009 // exception. With the C++ based interpreter only the top most frame
aoqi@0 3010 // has a full sized expression stack. The 16 byte slop factor is
aoqi@0 3011 // both the abi scratch area and a place to hold a result from a
aoqi@0 3012 // callee on its way to the callers stack.
aoqi@0 3013
aoqi@0 3014 int monitor_size = 0;
aoqi@0 3015 int top_frame_size = 0;
aoqi@0 3016 frame_size_helper(method->max_stack(), monitors, monitor_size, top_frame_size);
aoqi@0 3017
aoqi@0 3018 intptr_t sp = (intptr_t)interpreter_frame->sp();
aoqi@0 3019 intptr_t fp = *(intptr_t *)sp;
aoqi@0 3020 assert(fp == (intptr_t)caller->sp(), "fp must match");
aoqi@0 3021 interpreterState cur_state =
aoqi@0 3022 (interpreterState)(fp - frame::interpreter_frame_cinterpreterstate_size_in_bytes());
aoqi@0 3023
aoqi@0 3024 // Now fill in the interpreterState object.
aoqi@0 3025
aoqi@0 3026 intptr_t* locals;
aoqi@0 3027 if (caller->is_interpreted_frame()) {
aoqi@0 3028 // Locals must agree with the caller because it will be used to set the
aoqi@0 3029 // caller's tos when we return.
aoqi@0 3030 interpreterState prev = caller->get_interpreterState();
aoqi@0 3031 // Calculate start of "locals" for MH calls. For MH calls, the
aoqi@0 3032 // current method() (= MH target) and prev->callee() (=
aoqi@0 3033 // MH.invoke*()) are different and especially have different
aoqi@0 3034 // signatures. To pop the argumentsof the caller, we must use
aoqi@0 3035 // the prev->callee()->size_of_arguments() because that's what
aoqi@0 3036 // the caller actually pushed. Currently, for synthetic MH
aoqi@0 3037 // calls (deoptimized from inlined MH calls), detected by
aoqi@0 3038 // is_method_handle_invoke(), we use the callee's arguments
aoqi@0 3039 // because here, the caller's and callee's signature match.
aoqi@0 3040 if (true /*!caller->is_at_mh_callsite()*/) {
aoqi@0 3041 locals = prev->stack() + method->size_of_parameters();
aoqi@0 3042 } else {
aoqi@0 3043 // Normal MH call.
aoqi@0 3044 locals = prev->stack() + prev->callee()->size_of_parameters();
aoqi@0 3045 }
aoqi@0 3046 } else {
aoqi@0 3047 bool is_deopted;
aoqi@0 3048 locals = (intptr_t*) (fp + ((method->max_locals() - 1) * BytesPerWord) +
aoqi@0 3049 frame::parent_ijava_frame_abi_size);
aoqi@0 3050 }
aoqi@0 3051
aoqi@0 3052 intptr_t* monitor_base = (intptr_t*) cur_state;
aoqi@0 3053 intptr_t* stack_base = (intptr_t*) ((intptr_t) monitor_base - monitor_size);
aoqi@0 3054
aoqi@0 3055 // Provide pop_frame capability on PPC64, add popframe_args.
aoqi@0 3056 // +1 because stack is always prepushed.
aoqi@0 3057 intptr_t* stack = (intptr_t*) ((intptr_t) stack_base - (temps + popframe_args + 1) * BytesPerWord);
aoqi@0 3058
aoqi@0 3059 BytecodeInterpreter::layout_interpreterState(cur_state,
aoqi@0 3060 caller,
aoqi@0 3061 interpreter_frame,
aoqi@0 3062 method,
aoqi@0 3063 locals,
aoqi@0 3064 stack,
aoqi@0 3065 stack_base,
aoqi@0 3066 monitor_base,
aoqi@0 3067 (intptr_t*)(((intptr_t)fp) - top_frame_size),
aoqi@0 3068 is_top_frame);
aoqi@0 3069
aoqi@0 3070 BytecodeInterpreter::pd_layout_interpreterState(cur_state, interpreter_return_address,
aoqi@0 3071 interpreter_frame->fp());
aoqi@0 3072 }
aoqi@0 3073
aoqi@0 3074 #endif // CC_INTERP

mercurial