src/cpu/sparc/vm/cppInterpreter_sparc.cpp

Tue, 24 Dec 2013 11:48:39 -0800

author
mikael
date
Tue, 24 Dec 2013 11:48:39 -0800
changeset 6198
55fb97c4c58d
parent 6039
bd3237e0e18d
child 6558
2100bf712e2a
permissions
-rw-r--r--

8029233: Update copyright year to match last edit in jdk8 hotspot repository for 2013
Summary: Copyright year updated for files modified during 2013
Reviewed-by: twisti, iveresov

duke@435 1 /*
jiangli@4936 2 * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #include "precompiled.hpp"
stefank@2314 26 #include "asm/assembler.hpp"
stefank@2314 27 #include "interpreter/bytecodeHistogram.hpp"
stefank@2314 28 #include "interpreter/cppInterpreter.hpp"
stefank@2314 29 #include "interpreter/interpreter.hpp"
stefank@2314 30 #include "interpreter/interpreterGenerator.hpp"
stefank@2314 31 #include "interpreter/interpreterRuntime.hpp"
stefank@2314 32 #include "oops/arrayOop.hpp"
coleenp@4037 33 #include "oops/methodData.hpp"
coleenp@4037 34 #include "oops/method.hpp"
stefank@2314 35 #include "oops/oop.inline.hpp"
stefank@2314 36 #include "prims/jvmtiExport.hpp"
stefank@2314 37 #include "prims/jvmtiThreadState.hpp"
stefank@2314 38 #include "runtime/arguments.hpp"
stefank@2314 39 #include "runtime/deoptimization.hpp"
stefank@2314 40 #include "runtime/frame.inline.hpp"
stefank@2314 41 #include "runtime/interfaceSupport.hpp"
stefank@2314 42 #include "runtime/sharedRuntime.hpp"
stefank@2314 43 #include "runtime/stubRoutines.hpp"
stefank@2314 44 #include "runtime/synchronizer.hpp"
stefank@2314 45 #include "runtime/timer.hpp"
stefank@2314 46 #include "runtime/vframeArray.hpp"
stefank@2314 47 #include "utilities/debug.hpp"
jprovino@4542 48 #include "utilities/macros.hpp"
stefank@2314 49 #ifdef SHARK
stefank@2314 50 #include "shark/shark_globals.hpp"
stefank@2314 51 #endif
duke@435 52
duke@435 53 #ifdef CC_INTERP
duke@435 54
duke@435 55 // Routine exists to make tracebacks look decent in debugger
duke@435 56 // while "shadow" interpreter frames are on stack. It is also
duke@435 57 // used to distinguish interpreter frames.
duke@435 58
duke@435 59 extern "C" void RecursiveInterpreterActivation(interpreterState istate) {
duke@435 60 ShouldNotReachHere();
duke@435 61 }
duke@435 62
duke@435 63 bool CppInterpreter::contains(address pc) {
duke@435 64 return ( _code->contains(pc) ||
duke@435 65 ( pc == (CAST_FROM_FN_PTR(address, RecursiveInterpreterActivation) + frame::pc_return_offset)));
duke@435 66 }
duke@435 67
duke@435 68 #define STATE(field_name) Lstate, in_bytes(byte_offset_of(BytecodeInterpreter, field_name))
duke@435 69 #define __ _masm->
duke@435 70
duke@435 71 Label frame_manager_entry;
duke@435 72 Label fast_accessor_slow_entry_path; // fast accessor methods need to be able to jmp to unsynchronized
duke@435 73 // c++ interpreter entry point this holds that entry point label.
duke@435 74
duke@435 75 static address unctrap_frame_manager_entry = NULL;
duke@435 76
duke@435 77 static address interpreter_return_address = NULL;
duke@435 78 static address deopt_frame_manager_return_atos = NULL;
duke@435 79 static address deopt_frame_manager_return_btos = NULL;
duke@435 80 static address deopt_frame_manager_return_itos = NULL;
duke@435 81 static address deopt_frame_manager_return_ltos = NULL;
duke@435 82 static address deopt_frame_manager_return_ftos = NULL;
duke@435 83 static address deopt_frame_manager_return_dtos = NULL;
duke@435 84 static address deopt_frame_manager_return_vtos = NULL;
duke@435 85
duke@435 86 const Register prevState = G1_scratch;
duke@435 87
duke@435 88 void InterpreterGenerator::save_native_result(void) {
duke@435 89 // result potentially in O0/O1: save it across calls
duke@435 90 __ stf(FloatRegisterImpl::D, F0, STATE(_native_fresult));
duke@435 91 #ifdef _LP64
duke@435 92 __ stx(O0, STATE(_native_lresult));
duke@435 93 #else
duke@435 94 __ std(O0, STATE(_native_lresult));
duke@435 95 #endif
duke@435 96 }
duke@435 97
duke@435 98 void InterpreterGenerator::restore_native_result(void) {
duke@435 99
duke@435 100 // Restore any method result value
duke@435 101 __ ldf(FloatRegisterImpl::D, STATE(_native_fresult), F0);
duke@435 102 #ifdef _LP64
duke@435 103 __ ldx(STATE(_native_lresult), O0);
duke@435 104 #else
duke@435 105 __ ldd(STATE(_native_lresult), O0);
duke@435 106 #endif
duke@435 107 }
duke@435 108
duke@435 109 // A result handler converts/unboxes a native call result into
duke@435 110 // a java interpreter/compiler result. The current frame is an
duke@435 111 // interpreter frame. The activation frame unwind code must be
duke@435 112 // consistent with that of TemplateTable::_return(...). In the
duke@435 113 // case of native methods, the caller's SP was not modified.
duke@435 114 address CppInterpreterGenerator::generate_result_handler_for(BasicType type) {
duke@435 115 address entry = __ pc();
duke@435 116 Register Itos_i = Otos_i ->after_save();
duke@435 117 Register Itos_l = Otos_l ->after_save();
duke@435 118 Register Itos_l1 = Otos_l1->after_save();
duke@435 119 Register Itos_l2 = Otos_l2->after_save();
duke@435 120 switch (type) {
duke@435 121 case T_BOOLEAN: __ subcc(G0, O0, G0); __ addc(G0, 0, Itos_i); break; // !0 => true; 0 => false
duke@435 122 case T_CHAR : __ sll(O0, 16, O0); __ srl(O0, 16, Itos_i); break; // cannot use and3, 0xFFFF too big as immediate value!
duke@435 123 case T_BYTE : __ sll(O0, 24, O0); __ sra(O0, 24, Itos_i); break;
duke@435 124 case T_SHORT : __ sll(O0, 16, O0); __ sra(O0, 16, Itos_i); break;
duke@435 125 case T_LONG :
duke@435 126 #ifndef _LP64
duke@435 127 __ mov(O1, Itos_l2); // move other half of long
duke@435 128 #endif // ifdef or no ifdef, fall through to the T_INT case
duke@435 129 case T_INT : __ mov(O0, Itos_i); break;
duke@435 130 case T_VOID : /* nothing to do */ break;
duke@435 131 case T_FLOAT : assert(F0 == Ftos_f, "fix this code" ); break;
duke@435 132 case T_DOUBLE : assert(F0 == Ftos_d, "fix this code" ); break;
duke@435 133 case T_OBJECT :
duke@435 134 __ ld_ptr(STATE(_oop_temp), Itos_i);
duke@435 135 __ verify_oop(Itos_i);
duke@435 136 break;
duke@435 137 default : ShouldNotReachHere();
duke@435 138 }
duke@435 139 __ ret(); // return from interpreter activation
duke@435 140 __ delayed()->restore(I5_savedSP, G0, SP); // remove interpreter frame
twisti@4412 141 NOT_PRODUCT(__ emit_int32(0);) // marker for disassembly
duke@435 142 return entry;
duke@435 143 }
duke@435 144
duke@435 145 // tosca based result to c++ interpreter stack based result.
duke@435 146 // Result goes to address in L1_scratch
duke@435 147
duke@435 148 address CppInterpreterGenerator::generate_tosca_to_stack_converter(BasicType type) {
duke@435 149 // A result is in the native abi result register from a native method call.
duke@435 150 // We need to return this result to the interpreter by pushing the result on the interpreter's
duke@435 151 // stack. This is relatively simple the destination is in L1_scratch
duke@435 152 // i.e. L1_scratch is the first free element on the stack. If we "push" a return value we must
duke@435 153 // adjust L1_scratch
duke@435 154 address entry = __ pc();
duke@435 155 switch (type) {
duke@435 156 case T_BOOLEAN:
duke@435 157 // !0 => true; 0 => false
duke@435 158 __ subcc(G0, O0, G0);
duke@435 159 __ addc(G0, 0, O0);
duke@435 160 __ st(O0, L1_scratch, 0);
duke@435 161 __ sub(L1_scratch, wordSize, L1_scratch);
duke@435 162 break;
duke@435 163
duke@435 164 // cannot use and3, 0xFFFF too big as immediate value!
duke@435 165 case T_CHAR :
duke@435 166 __ sll(O0, 16, O0);
duke@435 167 __ srl(O0, 16, O0);
duke@435 168 __ st(O0, L1_scratch, 0);
duke@435 169 __ sub(L1_scratch, wordSize, L1_scratch);
duke@435 170 break;
duke@435 171
duke@435 172 case T_BYTE :
duke@435 173 __ sll(O0, 24, O0);
duke@435 174 __ sra(O0, 24, O0);
duke@435 175 __ st(O0, L1_scratch, 0);
duke@435 176 __ sub(L1_scratch, wordSize, L1_scratch);
duke@435 177 break;
duke@435 178
duke@435 179 case T_SHORT :
duke@435 180 __ sll(O0, 16, O0);
duke@435 181 __ sra(O0, 16, O0);
duke@435 182 __ st(O0, L1_scratch, 0);
duke@435 183 __ sub(L1_scratch, wordSize, L1_scratch);
duke@435 184 break;
duke@435 185 case T_LONG :
duke@435 186 #ifndef _LP64
sgoldman@558 187 #if defined(COMPILER2)
duke@435 188 // All return values are where we want them, except for Longs. C2 returns
duke@435 189 // longs in G1 in the 32-bit build whereas the interpreter wants them in O0/O1.
duke@435 190 // Since the interpreter will return longs in G1 and O0/O1 in the 32bit
duke@435 191 // build even if we are returning from interpreted we just do a little
duke@435 192 // stupid shuffing.
duke@435 193 // Note: I tried to make c2 return longs in O0/O1 and G1 so we wouldn't have to
duke@435 194 // do this here. Unfortunately if we did a rethrow we'd see an machepilog node
duke@435 195 // first which would move g1 -> O0/O1 and destroy the exception we were throwing.
duke@435 196 __ stx(G1, L1_scratch, -wordSize);
duke@435 197 #else
duke@435 198 // native result is in O0, O1
duke@435 199 __ st(O1, L1_scratch, 0); // Low order
duke@435 200 __ st(O0, L1_scratch, -wordSize); // High order
sgoldman@558 201 #endif /* COMPILER2 */
duke@435 202 #else
sgoldman@558 203 __ stx(O0, L1_scratch, -wordSize);
duke@435 204 #endif
duke@435 205 __ sub(L1_scratch, 2*wordSize, L1_scratch);
duke@435 206 break;
duke@435 207
duke@435 208 case T_INT :
duke@435 209 __ st(O0, L1_scratch, 0);
duke@435 210 __ sub(L1_scratch, wordSize, L1_scratch);
duke@435 211 break;
duke@435 212
duke@435 213 case T_VOID : /* nothing to do */
duke@435 214 break;
duke@435 215
duke@435 216 case T_FLOAT :
duke@435 217 __ stf(FloatRegisterImpl::S, F0, L1_scratch, 0);
duke@435 218 __ sub(L1_scratch, wordSize, L1_scratch);
duke@435 219 break;
duke@435 220
duke@435 221 case T_DOUBLE :
duke@435 222 // Every stack slot is aligned on 64 bit, However is this
duke@435 223 // the correct stack slot on 64bit?? QQQ
duke@435 224 __ stf(FloatRegisterImpl::D, F0, L1_scratch, -wordSize);
duke@435 225 __ sub(L1_scratch, 2*wordSize, L1_scratch);
duke@435 226 break;
duke@435 227 case T_OBJECT :
duke@435 228 __ verify_oop(O0);
duke@435 229 __ st_ptr(O0, L1_scratch, 0);
duke@435 230 __ sub(L1_scratch, wordSize, L1_scratch);
duke@435 231 break;
duke@435 232 default : ShouldNotReachHere();
duke@435 233 }
duke@435 234 __ retl(); // return from interpreter activation
duke@435 235 __ delayed()->nop(); // schedule this better
twisti@4412 236 NOT_PRODUCT(__ emit_int32(0);) // marker for disassembly
duke@435 237 return entry;
duke@435 238 }
duke@435 239
duke@435 240 address CppInterpreterGenerator::generate_stack_to_stack_converter(BasicType type) {
duke@435 241 // A result is in the java expression stack of the interpreted method that has just
duke@435 242 // returned. Place this result on the java expression stack of the caller.
duke@435 243 //
duke@435 244 // The current interpreter activation in Lstate is for the method just returning its
duke@435 245 // result. So we know that the result of this method is on the top of the current
duke@435 246 // execution stack (which is pre-pushed) and will be return to the top of the caller
duke@435 247 // stack. The top of the callers stack is the bottom of the locals of the current
duke@435 248 // activation.
duke@435 249 // Because of the way activation are managed by the frame manager the value of esp is
duke@435 250 // below both the stack top of the current activation and naturally the stack top
duke@435 251 // of the calling activation. This enable this routine to leave the return address
duke@435 252 // to the frame manager on the stack and do a vanilla return.
duke@435 253 //
duke@435 254 // On entry: O0 - points to source (callee stack top)
duke@435 255 // O1 - points to destination (caller stack top [i.e. free location])
duke@435 256 // destroys O2, O3
duke@435 257 //
duke@435 258
duke@435 259 address entry = __ pc();
duke@435 260 switch (type) {
duke@435 261 case T_VOID: break;
duke@435 262 break;
duke@435 263 case T_FLOAT :
duke@435 264 case T_BOOLEAN:
duke@435 265 case T_CHAR :
duke@435 266 case T_BYTE :
duke@435 267 case T_SHORT :
duke@435 268 case T_INT :
duke@435 269 // 1 word result
duke@435 270 __ ld(O0, 0, O2);
duke@435 271 __ st(O2, O1, 0);
duke@435 272 __ sub(O1, wordSize, O1);
duke@435 273 break;
duke@435 274 case T_DOUBLE :
duke@435 275 case T_LONG :
duke@435 276 // return top two words on current expression stack to caller's expression stack
duke@435 277 // The caller's expression stack is adjacent to the current frame manager's intepretState
duke@435 278 // except we allocated one extra word for this intepretState so we won't overwrite it
duke@435 279 // when we return a two word result.
duke@435 280 #ifdef _LP64
duke@435 281 __ ld_ptr(O0, 0, O2);
duke@435 282 __ st_ptr(O2, O1, -wordSize);
duke@435 283 #else
duke@435 284 __ ld(O0, 0, O2);
duke@435 285 __ ld(O0, wordSize, O3);
duke@435 286 __ st(O3, O1, 0);
duke@435 287 __ st(O2, O1, -wordSize);
duke@435 288 #endif
duke@435 289 __ sub(O1, 2*wordSize, O1);
duke@435 290 break;
duke@435 291 case T_OBJECT :
duke@435 292 __ ld_ptr(O0, 0, O2);
duke@435 293 __ verify_oop(O2); // verify it
duke@435 294 __ st_ptr(O2, O1, 0);
duke@435 295 __ sub(O1, wordSize, O1);
duke@435 296 break;
duke@435 297 default : ShouldNotReachHere();
duke@435 298 }
duke@435 299 __ retl();
duke@435 300 __ delayed()->nop(); // QQ schedule this better
duke@435 301 return entry;
duke@435 302 }
duke@435 303
duke@435 304 address CppInterpreterGenerator::generate_stack_to_native_abi_converter(BasicType type) {
duke@435 305 // A result is in the java expression stack of the interpreted method that has just
duke@435 306 // returned. Place this result in the native abi that the caller expects.
duke@435 307 // We are in a new frame registers we set must be in caller (i.e. callstub) frame.
duke@435 308 //
duke@435 309 // Similar to generate_stack_to_stack_converter above. Called at a similar time from the
duke@435 310 // frame manager execept in this situation the caller is native code (c1/c2/call_stub)
duke@435 311 // and so rather than return result onto caller's java expression stack we return the
duke@435 312 // result in the expected location based on the native abi.
duke@435 313 // On entry: O0 - source (stack top)
duke@435 314 // On exit result in expected output register
duke@435 315 // QQQ schedule this better
duke@435 316
duke@435 317 address entry = __ pc();
duke@435 318 switch (type) {
duke@435 319 case T_VOID: break;
duke@435 320 break;
duke@435 321 case T_FLOAT :
duke@435 322 __ ldf(FloatRegisterImpl::S, O0, 0, F0);
duke@435 323 break;
duke@435 324 case T_BOOLEAN:
duke@435 325 case T_CHAR :
duke@435 326 case T_BYTE :
duke@435 327 case T_SHORT :
duke@435 328 case T_INT :
duke@435 329 // 1 word result
duke@435 330 __ ld(O0, 0, O0->after_save());
duke@435 331 break;
duke@435 332 case T_DOUBLE :
duke@435 333 __ ldf(FloatRegisterImpl::D, O0, 0, F0);
duke@435 334 break;
duke@435 335 case T_LONG :
duke@435 336 // return top two words on current expression stack to caller's expression stack
duke@435 337 // The caller's expression stack is adjacent to the current frame manager's interpretState
duke@435 338 // except we allocated one extra word for this intepretState so we won't overwrite it
duke@435 339 // when we return a two word result.
duke@435 340 #ifdef _LP64
duke@435 341 __ ld_ptr(O0, 0, O0->after_save());
duke@435 342 #else
duke@435 343 __ ld(O0, wordSize, O1->after_save());
duke@435 344 __ ld(O0, 0, O0->after_save());
duke@435 345 #endif
duke@435 346 #if defined(COMPILER2) && !defined(_LP64)
duke@435 347 // C2 expects long results in G1 we can't tell if we're returning to interpreted
duke@435 348 // or compiled so just be safe use G1 and O0/O1
duke@435 349
duke@435 350 // Shift bits into high (msb) of G1
duke@435 351 __ sllx(Otos_l1->after_save(), 32, G1);
duke@435 352 // Zero extend low bits
duke@435 353 __ srl (Otos_l2->after_save(), 0, Otos_l2->after_save());
duke@435 354 __ or3 (Otos_l2->after_save(), G1, G1);
duke@435 355 #endif /* COMPILER2 */
duke@435 356 break;
duke@435 357 case T_OBJECT :
duke@435 358 __ ld_ptr(O0, 0, O0->after_save());
duke@435 359 __ verify_oop(O0->after_save()); // verify it
duke@435 360 break;
duke@435 361 default : ShouldNotReachHere();
duke@435 362 }
duke@435 363 __ retl();
duke@435 364 __ delayed()->nop();
duke@435 365 return entry;
duke@435 366 }
duke@435 367
twisti@6039 368 address CppInterpreter::return_entry(TosState state, int length, Bytecodes::Code code) {
duke@435 369 // make it look good in the debugger
duke@435 370 return CAST_FROM_FN_PTR(address, RecursiveInterpreterActivation) + frame::pc_return_offset;
duke@435 371 }
duke@435 372
duke@435 373 address CppInterpreter::deopt_entry(TosState state, int length) {
duke@435 374 address ret = NULL;
duke@435 375 if (length != 0) {
duke@435 376 switch (state) {
duke@435 377 case atos: ret = deopt_frame_manager_return_atos; break;
duke@435 378 case btos: ret = deopt_frame_manager_return_btos; break;
duke@435 379 case ctos:
duke@435 380 case stos:
duke@435 381 case itos: ret = deopt_frame_manager_return_itos; break;
duke@435 382 case ltos: ret = deopt_frame_manager_return_ltos; break;
duke@435 383 case ftos: ret = deopt_frame_manager_return_ftos; break;
duke@435 384 case dtos: ret = deopt_frame_manager_return_dtos; break;
duke@435 385 case vtos: ret = deopt_frame_manager_return_vtos; break;
duke@435 386 }
duke@435 387 } else {
duke@435 388 ret = unctrap_frame_manager_entry; // re-execute the bytecode ( e.g. uncommon trap)
duke@435 389 }
duke@435 390 assert(ret != NULL, "Not initialized");
duke@435 391 return ret;
duke@435 392 }
duke@435 393
duke@435 394 //
duke@435 395 // Helpers for commoning out cases in the various type of method entries.
duke@435 396 //
duke@435 397
duke@435 398 // increment invocation count & check for overflow
duke@435 399 //
duke@435 400 // Note: checking for negative value instead of overflow
duke@435 401 // so we have a 'sticky' overflow test
duke@435 402 //
duke@435 403 // Lmethod: method
duke@435 404 // ??: invocation counter
duke@435 405 //
duke@435 406 void InterpreterGenerator::generate_counter_incr(Label* overflow, Label* profile_method, Label* profile_method_continue) {
jiangli@4936 407 Label done;
jiangli@4936 408 const Register Rcounters = G3_scratch;
jiangli@4936 409
jiangli@4936 410 __ ld_ptr(STATE(_method), G5_method);
jiangli@4936 411 __ get_method_counters(G5_method, Rcounters, done);
jiangli@4936 412
duke@435 413 // Update standard invocation counters
jiangli@4936 414 __ increment_invocation_counter(Rcounters, O0, G4_scratch);
jiangli@4936 415 if (ProfileInterpreter) {
jiangli@4936 416 Address interpreter_invocation_counter(Rcounters, 0,
jiangli@4936 417 in_bytes(MethodCounters::interpreter_invocation_counter_offset()));
jiangli@4936 418 __ ld(interpreter_invocation_counter, G4_scratch);
jiangli@4936 419 __ inc(G4_scratch);
jiangli@4936 420 __ st(G4_scratch, interpreter_invocation_counter);
duke@435 421 }
duke@435 422
duke@435 423 Address invocation_limit(G3_scratch, (address)&InvocationCounter::InterpreterInvocationLimit);
duke@435 424 __ sethi(invocation_limit);
duke@435 425 __ ld(invocation_limit, G3_scratch);
duke@435 426 __ cmp(O0, G3_scratch);
duke@435 427 __ br(Assembler::greaterEqualUnsigned, false, Assembler::pn, *overflow);
duke@435 428 __ delayed()->nop();
jiangli@4936 429 __ bind(done);
duke@435 430 }
duke@435 431
duke@435 432 address InterpreterGenerator::generate_empty_entry(void) {
duke@435 433
duke@435 434 // A method that does nothing but return...
duke@435 435
duke@435 436 address entry = __ pc();
duke@435 437 Label slow_path;
duke@435 438
duke@435 439 // do nothing for empty methods (do not even increment invocation counter)
duke@435 440 if ( UseFastEmptyMethods) {
duke@435 441 // If we need a safepoint check, generate full interpreter entry.
duke@435 442 Address sync_state(G3_scratch, SafepointSynchronize::address_of_state());
duke@435 443 __ load_contents(sync_state, G3_scratch);
duke@435 444 __ cmp(G3_scratch, SafepointSynchronize::_not_synchronized);
duke@435 445 __ br(Assembler::notEqual, false, Assembler::pn, frame_manager_entry);
duke@435 446 __ delayed()->nop();
duke@435 447
duke@435 448 // Code: _return
duke@435 449 __ retl();
duke@435 450 __ delayed()->mov(O5_savedSP, SP);
duke@435 451 return entry;
duke@435 452 }
duke@435 453 return NULL;
duke@435 454 }
duke@435 455
duke@435 456 // Call an accessor method (assuming it is resolved, otherwise drop into
duke@435 457 // vanilla (slow path) entry
duke@435 458
duke@435 459 // Generates code to elide accessor methods
duke@435 460 // Uses G3_scratch and G1_scratch as scratch
duke@435 461 address InterpreterGenerator::generate_accessor_entry(void) {
duke@435 462
duke@435 463 // Code: _aload_0, _(i|a)getfield, _(i|a)return or any rewrites thereof;
duke@435 464 // parameter size = 1
duke@435 465 // Note: We can only use this code if the getfield has been resolved
duke@435 466 // and if we don't have a null-pointer exception => check for
duke@435 467 // these conditions first and use slow path if necessary.
duke@435 468 address entry = __ pc();
duke@435 469 Label slow_path;
duke@435 470
duke@435 471 if ( UseFastAccessorMethods) {
duke@435 472 // Check if we need to reach a safepoint and generate full interpreter
duke@435 473 // frame if so.
duke@435 474 Address sync_state(G3_scratch, SafepointSynchronize::address_of_state());
duke@435 475 __ load_contents(sync_state, G3_scratch);
duke@435 476 __ cmp(G3_scratch, SafepointSynchronize::_not_synchronized);
duke@435 477 __ br(Assembler::notEqual, false, Assembler::pn, slow_path);
duke@435 478 __ delayed()->nop();
duke@435 479
duke@435 480 // Check if local 0 != NULL
duke@435 481 __ ld_ptr(Gargs, G0, Otos_i ); // get local 0
duke@435 482 __ tst(Otos_i); // check if local 0 == NULL and go the slow path
duke@435 483 __ brx(Assembler::zero, false, Assembler::pn, slow_path);
duke@435 484 __ delayed()->nop();
duke@435 485
duke@435 486
duke@435 487 // read first instruction word and extract bytecode @ 1 and index @ 2
duke@435 488 // get first 4 bytes of the bytecodes (big endian!)
coleenp@4037 489 __ ld_ptr(Address(G5_method, 0, in_bytes(Method::const_offset())), G1_scratch);
coleenp@4037 490 __ ld(Address(G1_scratch, 0, in_bytes(ConstMethod::codes_offset())), G1_scratch);
duke@435 491
duke@435 492 // move index @ 2 far left then to the right most two bytes.
duke@435 493 __ sll(G1_scratch, 2*BitsPerByte, G1_scratch);
duke@435 494 __ srl(G1_scratch, 2*BitsPerByte - exact_log2(in_words(
duke@435 495 ConstantPoolCacheEntry::size()) * BytesPerWord), G1_scratch);
duke@435 496
duke@435 497 // get constant pool cache
coleenp@4037 498 __ ld_ptr(G5_method, in_bytes(Method::const_offset()), G3_scratch);
coleenp@4037 499 __ ld_ptr(G3_scratch, in_bytes(ConstMethod::constants_offset()), G3_scratch);
coleenp@4037 500 __ ld_ptr(G3_scratch, ConstantPool::cache_offset_in_bytes(), G3_scratch);
duke@435 501
duke@435 502 // get specific constant pool cache entry
duke@435 503 __ add(G3_scratch, G1_scratch, G3_scratch);
duke@435 504
duke@435 505 // Check the constant Pool cache entry to see if it has been resolved.
duke@435 506 // If not, need the slow path.
coleenp@4037 507 ByteSize cp_base_offset = ConstantPoolCache::base_offset();
duke@435 508 __ ld_ptr(G3_scratch, in_bytes(cp_base_offset + ConstantPoolCacheEntry::indices_offset()), G1_scratch);
duke@435 509 __ srl(G1_scratch, 2*BitsPerByte, G1_scratch);
duke@435 510 __ and3(G1_scratch, 0xFF, G1_scratch);
duke@435 511 __ cmp(G1_scratch, Bytecodes::_getfield);
duke@435 512 __ br(Assembler::notEqual, false, Assembler::pn, slow_path);
duke@435 513 __ delayed()->nop();
duke@435 514
duke@435 515 // Get the type and return field offset from the constant pool cache
duke@435 516 __ ld_ptr(G3_scratch, in_bytes(cp_base_offset + ConstantPoolCacheEntry::flags_offset()), G1_scratch);
duke@435 517 __ ld_ptr(G3_scratch, in_bytes(cp_base_offset + ConstantPoolCacheEntry::f2_offset()), G3_scratch);
duke@435 518
duke@435 519 Label xreturn_path;
duke@435 520 // Need to differentiate between igetfield, agetfield, bgetfield etc.
duke@435 521 // because they are different sizes.
duke@435 522 // Get the type from the constant pool cache
twisti@3969 523 __ srl(G1_scratch, ConstantPoolCacheEntry::tos_state_shift, G1_scratch);
twisti@3969 524 // Make sure we don't need to mask G1_scratch after the above shift
twisti@3969 525 ConstantPoolCacheEntry::verify_tos_state_shift();
duke@435 526 __ cmp(G1_scratch, atos );
duke@435 527 __ br(Assembler::equal, true, Assembler::pt, xreturn_path);
duke@435 528 __ delayed()->ld_ptr(Otos_i, G3_scratch, Otos_i);
duke@435 529 __ cmp(G1_scratch, itos);
duke@435 530 __ br(Assembler::equal, true, Assembler::pt, xreturn_path);
duke@435 531 __ delayed()->ld(Otos_i, G3_scratch, Otos_i);
duke@435 532 __ cmp(G1_scratch, stos);
duke@435 533 __ br(Assembler::equal, true, Assembler::pt, xreturn_path);
duke@435 534 __ delayed()->ldsh(Otos_i, G3_scratch, Otos_i);
duke@435 535 __ cmp(G1_scratch, ctos);
duke@435 536 __ br(Assembler::equal, true, Assembler::pt, xreturn_path);
duke@435 537 __ delayed()->lduh(Otos_i, G3_scratch, Otos_i);
duke@435 538 #ifdef ASSERT
duke@435 539 __ cmp(G1_scratch, btos);
duke@435 540 __ br(Assembler::equal, true, Assembler::pt, xreturn_path);
duke@435 541 __ delayed()->ldsb(Otos_i, G3_scratch, Otos_i);
duke@435 542 __ should_not_reach_here();
duke@435 543 #endif
duke@435 544 __ ldsb(Otos_i, G3_scratch, Otos_i);
duke@435 545 __ bind(xreturn_path);
duke@435 546
duke@435 547 // _ireturn/_areturn
duke@435 548 __ retl(); // return from leaf routine
duke@435 549 __ delayed()->mov(O5_savedSP, SP);
duke@435 550
duke@435 551 // Generate regular method entry
duke@435 552 __ bind(slow_path);
kvn@3037 553 __ ba(fast_accessor_slow_entry_path);
duke@435 554 __ delayed()->nop();
duke@435 555 return entry;
duke@435 556 }
duke@435 557 return NULL;
duke@435 558 }
duke@435 559
johnc@2781 560 address InterpreterGenerator::generate_Reference_get_entry(void) {
jprovino@4542 561 #if INCLUDE_ALL_GCS
johnc@2781 562 if (UseG1GC) {
johnc@2781 563 // We need to generate have a routine that generates code to:
johnc@2781 564 // * load the value in the referent field
johnc@2781 565 // * passes that value to the pre-barrier.
johnc@2781 566 //
johnc@2781 567 // In the case of G1 this will record the value of the
johnc@2781 568 // referent in an SATB buffer if marking is active.
johnc@2781 569 // This will cause concurrent marking to mark the referent
johnc@2781 570 // field as live.
johnc@2781 571 Unimplemented();
johnc@2781 572 }
jprovino@4542 573 #endif // INCLUDE_ALL_GCS
johnc@2781 574
johnc@2781 575 // If G1 is not enabled then attempt to go through the accessor entry point
johnc@2781 576 // Reference.get is an accessor
johnc@2781 577 return generate_accessor_entry();
johnc@2781 578 }
johnc@2781 579
duke@435 580 //
duke@435 581 // Interpreter stub for calling a native method. (C++ interpreter)
duke@435 582 // This sets up a somewhat different looking stack for calling the native method
duke@435 583 // than the typical interpreter frame setup.
duke@435 584 //
duke@435 585
duke@435 586 address InterpreterGenerator::generate_native_entry(bool synchronized) {
duke@435 587 address entry = __ pc();
duke@435 588
duke@435 589 // the following temporary registers are used during frame creation
duke@435 590 const Register Gtmp1 = G3_scratch ;
duke@435 591 const Register Gtmp2 = G1_scratch;
jiangli@4338 592 const Register RconstMethod = Gtmp1;
jiangli@4338 593 const Address constMethod(G5_method, 0, in_bytes(Method::const_offset()));
jiangli@4338 594 const Address size_of_parameters(RconstMethod, 0, in_bytes(ConstMethod::size_of_parameters_offset()));
duke@435 595
duke@435 596 bool inc_counter = UseCompiler || CountCompiledCalls;
duke@435 597
duke@435 598 // make sure registers are different!
duke@435 599 assert_different_registers(G2_thread, G5_method, Gargs, Gtmp1, Gtmp2);
duke@435 600
coleenp@4037 601 const Address access_flags (G5_method, 0, in_bytes(Method::access_flags_offset()));
duke@435 602
duke@435 603 Label Lentry;
duke@435 604 __ bind(Lentry);
duke@435 605
duke@435 606 const Register Glocals_size = G3;
duke@435 607 assert_different_registers(Glocals_size, G4_scratch, Gframe_size);
duke@435 608
duke@435 609 // make sure method is native & not abstract
duke@435 610 // rethink these assertions - they can be simplified and shared (gri 2/25/2000)
duke@435 611 #ifdef ASSERT
duke@435 612 __ ld(access_flags, Gtmp1);
duke@435 613 {
duke@435 614 Label L;
duke@435 615 __ btst(JVM_ACC_NATIVE, Gtmp1);
duke@435 616 __ br(Assembler::notZero, false, Assembler::pt, L);
duke@435 617 __ delayed()->nop();
duke@435 618 __ stop("tried to execute non-native method as native");
duke@435 619 __ bind(L);
duke@435 620 }
duke@435 621 { Label L;
duke@435 622 __ btst(JVM_ACC_ABSTRACT, Gtmp1);
duke@435 623 __ br(Assembler::zero, false, Assembler::pt, L);
duke@435 624 __ delayed()->nop();
duke@435 625 __ stop("tried to execute abstract method as non-abstract");
duke@435 626 __ bind(L);
duke@435 627 }
duke@435 628 #endif // ASSERT
duke@435 629
jiangli@4338 630 __ ld_ptr(constMethod, RconstMethod);
duke@435 631 __ lduh(size_of_parameters, Gtmp1);
duke@435 632 __ sll(Gtmp1, LogBytesPerWord, Gtmp2); // parameter size in bytes
duke@435 633 __ add(Gargs, Gtmp2, Gargs); // points to first local + BytesPerWord
duke@435 634 // NEW
duke@435 635 __ add(Gargs, -wordSize, Gargs); // points to first local[0]
duke@435 636 // generate the code to allocate the interpreter stack frame
duke@435 637 // NEW FRAME ALLOCATED HERE
duke@435 638 // save callers original sp
duke@435 639 // __ mov(SP, I5_savedSP->after_restore());
duke@435 640
duke@435 641 generate_compute_interpreter_state(Lstate, G0, true);
duke@435 642
duke@435 643 // At this point Lstate points to new interpreter state
duke@435 644 //
duke@435 645
duke@435 646 const Address do_not_unlock_if_synchronized(G2_thread, 0,
duke@435 647 in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
duke@435 648 // Since at this point in the method invocation the exception handler
duke@435 649 // would try to exit the monitor of synchronized methods which hasn't
duke@435 650 // been entered yet, we set the thread local variable
duke@435 651 // _do_not_unlock_if_synchronized to true. If any exception was thrown by
duke@435 652 // runtime, exception handling i.e. unlock_if_synchronized_method will
duke@435 653 // check this thread local flag.
duke@435 654 // This flag has two effects, one is to force an unwind in the topmost
duke@435 655 // interpreter frame and not perform an unlock while doing so.
duke@435 656
duke@435 657 __ movbool(true, G3_scratch);
duke@435 658 __ stbool(G3_scratch, do_not_unlock_if_synchronized);
duke@435 659
duke@435 660
duke@435 661 // increment invocation counter and check for overflow
duke@435 662 //
duke@435 663 // Note: checking for negative value instead of overflow
duke@435 664 // so we have a 'sticky' overflow test (may be of
duke@435 665 // importance as soon as we have true MT/MP)
duke@435 666 Label invocation_counter_overflow;
duke@435 667 if (inc_counter) {
duke@435 668 generate_counter_incr(&invocation_counter_overflow, NULL, NULL);
duke@435 669 }
duke@435 670 Label Lcontinue;
duke@435 671 __ bind(Lcontinue);
duke@435 672
duke@435 673 bang_stack_shadow_pages(true);
duke@435 674 // reset the _do_not_unlock_if_synchronized flag
duke@435 675 __ stbool(G0, do_not_unlock_if_synchronized);
duke@435 676
duke@435 677 // check for synchronized methods
duke@435 678 // Must happen AFTER invocation_counter check, so method is not locked
duke@435 679 // if counter overflows.
duke@435 680
duke@435 681 if (synchronized) {
duke@435 682 lock_method();
duke@435 683 // Don't see how G2_thread is preserved here...
duke@435 684 // __ verify_thread(); QQQ destroys L0,L1 can't use
duke@435 685 } else {
duke@435 686 #ifdef ASSERT
duke@435 687 { Label ok;
duke@435 688 __ ld_ptr(STATE(_method), G5_method);
duke@435 689 __ ld(access_flags, O0);
duke@435 690 __ btst(JVM_ACC_SYNCHRONIZED, O0);
duke@435 691 __ br( Assembler::zero, false, Assembler::pt, ok);
duke@435 692 __ delayed()->nop();
duke@435 693 __ stop("method needs synchronization");
duke@435 694 __ bind(ok);
duke@435 695 }
duke@435 696 #endif // ASSERT
duke@435 697 }
duke@435 698
duke@435 699 // start execution
duke@435 700
duke@435 701 // __ verify_thread(); kills L1,L2 can't use at the moment
duke@435 702
duke@435 703 // jvmti/jvmpi support
duke@435 704 __ notify_method_entry();
duke@435 705
duke@435 706 // native call
duke@435 707
duke@435 708 // (note that O0 is never an oop--at most it is a handle)
duke@435 709 // It is important not to smash any handles created by this call,
duke@435 710 // until any oop handle in O0 is dereferenced.
duke@435 711
duke@435 712 // (note that the space for outgoing params is preallocated)
duke@435 713
duke@435 714 // get signature handler
duke@435 715
duke@435 716 Label pending_exception_present;
duke@435 717
duke@435 718 { Label L;
duke@435 719 __ ld_ptr(STATE(_method), G5_method);
coleenp@4037 720 __ ld_ptr(Address(G5_method, 0, in_bytes(Method::signature_handler_offset())), G3_scratch);
duke@435 721 __ tst(G3_scratch);
duke@435 722 __ brx(Assembler::notZero, false, Assembler::pt, L);
duke@435 723 __ delayed()->nop();
duke@435 724 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::prepare_native_call), G5_method, false);
duke@435 725 __ ld_ptr(STATE(_method), G5_method);
duke@435 726
duke@435 727 Address exception_addr(G2_thread, 0, in_bytes(Thread::pending_exception_offset()));
duke@435 728 __ ld_ptr(exception_addr, G3_scratch);
kvn@3037 729 __ br_notnull_short(G3_scratch, Assembler::pn, pending_exception_present);
coleenp@4037 730 __ ld_ptr(Address(G5_method, 0, in_bytes(Method::signature_handler_offset())), G3_scratch);
duke@435 731 __ bind(L);
duke@435 732 }
duke@435 733
duke@435 734 // Push a new frame so that the args will really be stored in
duke@435 735 // Copy a few locals across so the new frame has the variables
duke@435 736 // we need but these values will be dead at the jni call and
duke@435 737 // therefore not gc volatile like the values in the current
duke@435 738 // frame (Lstate in particular)
duke@435 739
duke@435 740 // Flush the state pointer to the register save area
duke@435 741 // Which is the only register we need for a stack walk.
duke@435 742 __ st_ptr(Lstate, SP, (Lstate->sp_offset_in_saved_window() * wordSize) + STACK_BIAS);
duke@435 743
duke@435 744 __ mov(Lstate, O1); // Need to pass the state pointer across the frame
duke@435 745
duke@435 746 // Calculate current frame size
duke@435 747 __ sub(SP, FP, O3); // Calculate negative of current frame size
duke@435 748 __ save(SP, O3, SP); // Allocate an identical sized frame
duke@435 749
duke@435 750 __ mov(I1, Lstate); // In the "natural" register.
duke@435 751
duke@435 752 // Note I7 has leftover trash. Slow signature handler will fill it in
duke@435 753 // should we get there. Normal jni call will set reasonable last_Java_pc
duke@435 754 // below (and fix I7 so the stack trace doesn't have a meaningless frame
duke@435 755 // in it).
duke@435 756
duke@435 757
duke@435 758 // call signature handler
duke@435 759 __ ld_ptr(STATE(_method), Lmethod);
duke@435 760 __ ld_ptr(STATE(_locals), Llocals);
duke@435 761
duke@435 762 __ callr(G3_scratch, 0);
duke@435 763 __ delayed()->nop();
duke@435 764 __ ld_ptr(STATE(_thread), G2_thread); // restore thread (shouldn't be needed)
duke@435 765
duke@435 766 { Label not_static;
duke@435 767
duke@435 768 __ ld_ptr(STATE(_method), G5_method);
duke@435 769 __ ld(access_flags, O0);
duke@435 770 __ btst(JVM_ACC_STATIC, O0);
duke@435 771 __ br( Assembler::zero, false, Assembler::pt, not_static);
duke@435 772 __ delayed()->
duke@435 773 // get native function entry point(O0 is a good temp until the very end)
coleenp@4037 774 ld_ptr(Address(G5_method, 0, in_bytes(Method::native_function_offset())), O0);
duke@435 775 // for static methods insert the mirror argument
stefank@3391 776 const int mirror_offset = in_bytes(Klass::java_mirror_offset());
duke@435 777
coleenp@4037 778 __ ld_ptr(Address(G5_method, 0, in_bytes(Method:: const_offset())), O1);
coleenp@4037 779 __ ld_ptr(Address(O1, 0, in_bytes(ConstMethod::constants_offset())), O1);
coleenp@4037 780 __ ld_ptr(Address(O1, 0, ConstantPool::pool_holder_offset_in_bytes()), O1);
duke@435 781 __ ld_ptr(O1, mirror_offset, O1);
duke@435 782 // where the mirror handle body is allocated:
duke@435 783 #ifdef ASSERT
duke@435 784 if (!PrintSignatureHandlers) // do not dirty the output with this
duke@435 785 { Label L;
duke@435 786 __ tst(O1);
duke@435 787 __ brx(Assembler::notZero, false, Assembler::pt, L);
duke@435 788 __ delayed()->nop();
duke@435 789 __ stop("mirror is missing");
duke@435 790 __ bind(L);
duke@435 791 }
duke@435 792 #endif // ASSERT
duke@435 793 __ st_ptr(O1, STATE(_oop_temp));
duke@435 794 __ add(STATE(_oop_temp), O1); // this is really an LEA not an add
duke@435 795 __ bind(not_static);
duke@435 796 }
duke@435 797
duke@435 798 // At this point, arguments have been copied off of stack into
duke@435 799 // their JNI positions, which are O1..O5 and SP[68..].
duke@435 800 // Oops are boxed in-place on the stack, with handles copied to arguments.
duke@435 801 // The result handler is in Lscratch. O0 will shortly hold the JNIEnv*.
duke@435 802
duke@435 803 #ifdef ASSERT
duke@435 804 { Label L;
duke@435 805 __ tst(O0);
duke@435 806 __ brx(Assembler::notZero, false, Assembler::pt, L);
duke@435 807 __ delayed()->nop();
duke@435 808 __ stop("native entry point is missing");
duke@435 809 __ bind(L);
duke@435 810 }
duke@435 811 #endif // ASSERT
duke@435 812
duke@435 813 //
duke@435 814 // setup the java frame anchor
duke@435 815 //
duke@435 816 // The scavenge function only needs to know that the PC of this frame is
duke@435 817 // in the interpreter method entry code, it doesn't need to know the exact
duke@435 818 // PC and hence we can use O7 which points to the return address from the
duke@435 819 // previous call in the code stream (signature handler function)
duke@435 820 //
duke@435 821 // The other trick is we set last_Java_sp to FP instead of the usual SP because
duke@435 822 // we have pushed the extra frame in order to protect the volatile register(s)
duke@435 823 // in that frame when we return from the jni call
duke@435 824 //
duke@435 825
duke@435 826
duke@435 827 __ set_last_Java_frame(FP, O7);
duke@435 828 __ mov(O7, I7); // make dummy interpreter frame look like one above,
duke@435 829 // not meaningless information that'll confuse me.
duke@435 830
duke@435 831 // flush the windows now. We don't care about the current (protection) frame
duke@435 832 // only the outer frames
duke@435 833
duke@435 834 __ flush_windows();
duke@435 835
duke@435 836 // mark windows as flushed
duke@435 837 Address flags(G2_thread,
duke@435 838 0,
duke@435 839 in_bytes(JavaThread::frame_anchor_offset()) + in_bytes(JavaFrameAnchor::flags_offset()));
duke@435 840 __ set(JavaFrameAnchor::flushed, G3_scratch);
duke@435 841 __ st(G3_scratch, flags);
duke@435 842
duke@435 843 // Transition from _thread_in_Java to _thread_in_native. We are already safepoint ready.
duke@435 844
duke@435 845 Address thread_state(G2_thread, 0, in_bytes(JavaThread::thread_state_offset()));
duke@435 846 #ifdef ASSERT
duke@435 847 { Label L;
duke@435 848 __ ld(thread_state, G3_scratch);
duke@435 849 __ cmp(G3_scratch, _thread_in_Java);
duke@435 850 __ br(Assembler::equal, false, Assembler::pt, L);
duke@435 851 __ delayed()->nop();
duke@435 852 __ stop("Wrong thread state in native stub");
duke@435 853 __ bind(L);
duke@435 854 }
duke@435 855 #endif // ASSERT
duke@435 856 __ set(_thread_in_native, G3_scratch);
duke@435 857 __ st(G3_scratch, thread_state);
duke@435 858
duke@435 859 // Call the jni method, using the delay slot to set the JNIEnv* argument.
duke@435 860 __ callr(O0, 0);
duke@435 861 __ delayed()->
duke@435 862 add(G2_thread, in_bytes(JavaThread::jni_environment_offset()), O0);
duke@435 863 __ ld_ptr(STATE(_thread), G2_thread); // restore thread
duke@435 864
duke@435 865 // must we block?
duke@435 866
duke@435 867 // Block, if necessary, before resuming in _thread_in_Java state.
duke@435 868 // In order for GC to work, don't clear the last_Java_sp until after blocking.
duke@435 869 { Label no_block;
duke@435 870 Address sync_state(G3_scratch, SafepointSynchronize::address_of_state());
duke@435 871
duke@435 872 // Switch thread to "native transition" state before reading the synchronization state.
duke@435 873 // This additional state is necessary because reading and testing the synchronization
duke@435 874 // state is not atomic w.r.t. GC, as this scenario demonstrates:
duke@435 875 // Java thread A, in _thread_in_native state, loads _not_synchronized and is preempted.
duke@435 876 // VM thread changes sync state to synchronizing and suspends threads for GC.
duke@435 877 // Thread A is resumed to finish this native method, but doesn't block here since it
duke@435 878 // didn't see any synchronization is progress, and escapes.
duke@435 879 __ set(_thread_in_native_trans, G3_scratch);
duke@435 880 __ st(G3_scratch, thread_state);
duke@435 881 if(os::is_MP()) {
duke@435 882 // Write serialization page so VM thread can do a pseudo remote membar.
duke@435 883 // We use the current thread pointer to calculate a thread specific
duke@435 884 // offset to write to within the page. This minimizes bus traffic
duke@435 885 // due to cache line collision.
duke@435 886 __ serialize_memory(G2_thread, G1_scratch, G3_scratch);
duke@435 887 }
duke@435 888 __ load_contents(sync_state, G3_scratch);
duke@435 889 __ cmp(G3_scratch, SafepointSynchronize::_not_synchronized);
duke@435 890
duke@435 891
duke@435 892 Label L;
duke@435 893 Address suspend_state(G2_thread, 0, in_bytes(JavaThread::suspend_flags_offset()));
duke@435 894 __ br(Assembler::notEqual, false, Assembler::pn, L);
duke@435 895 __ delayed()->
duke@435 896 ld(suspend_state, G3_scratch);
duke@435 897 __ cmp(G3_scratch, 0);
duke@435 898 __ br(Assembler::equal, false, Assembler::pt, no_block);
duke@435 899 __ delayed()->nop();
duke@435 900 __ bind(L);
duke@435 901
duke@435 902 // Block. Save any potential method result value before the operation and
duke@435 903 // use a leaf call to leave the last_Java_frame setup undisturbed.
duke@435 904 save_native_result();
duke@435 905 __ call_VM_leaf(noreg,
duke@435 906 CAST_FROM_FN_PTR(address, JavaThread::check_safepoint_and_suspend_for_native_trans),
duke@435 907 G2_thread);
duke@435 908 __ ld_ptr(STATE(_thread), G2_thread); // restore thread
duke@435 909 // Restore any method result value
duke@435 910 restore_native_result();
duke@435 911 __ bind(no_block);
duke@435 912 }
duke@435 913
duke@435 914 // Clear the frame anchor now
duke@435 915
duke@435 916 __ reset_last_Java_frame();
duke@435 917
duke@435 918 // Move the result handler address
duke@435 919 __ mov(Lscratch, G3_scratch);
duke@435 920 // return possible result to the outer frame
duke@435 921 #ifndef __LP64
duke@435 922 __ mov(O0, I0);
duke@435 923 __ restore(O1, G0, O1);
duke@435 924 #else
duke@435 925 __ restore(O0, G0, O0);
duke@435 926 #endif /* __LP64 */
duke@435 927
duke@435 928 // Move result handler to expected register
duke@435 929 __ mov(G3_scratch, Lscratch);
duke@435 930
duke@435 931
duke@435 932 // thread state is thread_in_native_trans. Any safepoint blocking has
duke@435 933 // happened in the trampoline we are ready to switch to thread_in_Java.
duke@435 934
duke@435 935 __ set(_thread_in_Java, G3_scratch);
duke@435 936 __ st(G3_scratch, thread_state);
duke@435 937
duke@435 938 // If we have an oop result store it where it will be safe for any further gc
duke@435 939 // until we return now that we've released the handle it might be protected by
duke@435 940
duke@435 941 {
duke@435 942 Label no_oop, store_result;
duke@435 943
duke@435 944 __ set((intptr_t)AbstractInterpreter::result_handler(T_OBJECT), G3_scratch);
duke@435 945 __ cmp(G3_scratch, Lscratch);
duke@435 946 __ brx(Assembler::notEqual, false, Assembler::pt, no_oop);
duke@435 947 __ delayed()->nop();
duke@435 948 __ addcc(G0, O0, O0);
duke@435 949 __ brx(Assembler::notZero, true, Assembler::pt, store_result); // if result is not NULL:
duke@435 950 __ delayed()->ld_ptr(O0, 0, O0); // unbox it
duke@435 951 __ mov(G0, O0);
duke@435 952
duke@435 953 __ bind(store_result);
duke@435 954 // Store it where gc will look for it and result handler expects it.
duke@435 955 __ st_ptr(O0, STATE(_oop_temp));
duke@435 956
duke@435 957 __ bind(no_oop);
duke@435 958
duke@435 959 }
duke@435 960
duke@435 961 // reset handle block
duke@435 962 __ ld_ptr(G2_thread, in_bytes(JavaThread::active_handles_offset()), G3_scratch);
duke@435 963 __ st_ptr(G0, G3_scratch, JNIHandleBlock::top_offset_in_bytes());
duke@435 964
duke@435 965
duke@435 966 // handle exceptions (exception handling will handle unlocking!)
duke@435 967 { Label L;
duke@435 968 Address exception_addr (G2_thread, 0, in_bytes(Thread::pending_exception_offset()));
duke@435 969
duke@435 970 __ ld_ptr(exception_addr, Gtemp);
duke@435 971 __ tst(Gtemp);
duke@435 972 __ brx(Assembler::equal, false, Assembler::pt, L);
duke@435 973 __ delayed()->nop();
duke@435 974 __ bind(pending_exception_present);
duke@435 975 // With c++ interpreter we just leave it pending caller will do the correct thing. However...
duke@435 976 // Like x86 we ignore the result of the native call and leave the method locked. This
duke@435 977 // seems wrong to leave things locked.
duke@435 978
duke@435 979 __ br(Assembler::always, false, Assembler::pt, StubRoutines::forward_exception_entry(), relocInfo::runtime_call_type);
duke@435 980 __ delayed()->restore(I5_savedSP, G0, SP); // remove interpreter frame
duke@435 981
duke@435 982 __ bind(L);
duke@435 983 }
duke@435 984
duke@435 985 // jvmdi/jvmpi support (preserves thread register)
duke@435 986 __ notify_method_exit(true, ilgl, InterpreterMacroAssembler::NotifyJVMTI);
duke@435 987
duke@435 988 if (synchronized) {
duke@435 989 // save and restore any potential method result value around the unlocking operation
duke@435 990 save_native_result();
duke@435 991
duke@435 992 const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
duke@435 993 // Get the initial monitor we allocated
duke@435 994 __ sub(Lstate, entry_size, O1); // initial monitor
duke@435 995 __ unlock_object(O1);
duke@435 996 restore_native_result();
duke@435 997 }
duke@435 998
duke@435 999 #if defined(COMPILER2) && !defined(_LP64)
duke@435 1000
duke@435 1001 // C2 expects long results in G1 we can't tell if we're returning to interpreted
duke@435 1002 // or compiled so just be safe.
duke@435 1003
duke@435 1004 __ sllx(O0, 32, G1); // Shift bits into high G1
duke@435 1005 __ srl (O1, 0, O1); // Zero extend O1
duke@435 1006 __ or3 (O1, G1, G1); // OR 64 bits into G1
duke@435 1007
duke@435 1008 #endif /* COMPILER2 && !_LP64 */
duke@435 1009
duke@435 1010 #ifdef ASSERT
duke@435 1011 {
duke@435 1012 Label ok;
duke@435 1013 __ cmp(I5_savedSP, FP);
duke@435 1014 __ brx(Assembler::greaterEqualUnsigned, false, Assembler::pt, ok);
duke@435 1015 __ delayed()->nop();
duke@435 1016 __ stop("bad I5_savedSP value");
duke@435 1017 __ should_not_reach_here();
duke@435 1018 __ bind(ok);
duke@435 1019 }
duke@435 1020 #endif
duke@435 1021 // Calls result handler which POPS FRAME
duke@435 1022 if (TraceJumps) {
duke@435 1023 // Move target to register that is recordable
duke@435 1024 __ mov(Lscratch, G3_scratch);
duke@435 1025 __ JMP(G3_scratch, 0);
duke@435 1026 } else {
duke@435 1027 __ jmp(Lscratch, 0);
duke@435 1028 }
duke@435 1029 __ delayed()->nop();
duke@435 1030
duke@435 1031 if (inc_counter) {
duke@435 1032 // handle invocation counter overflow
duke@435 1033 __ bind(invocation_counter_overflow);
duke@435 1034 generate_counter_overflow(Lcontinue);
duke@435 1035 }
duke@435 1036
duke@435 1037
duke@435 1038 return entry;
duke@435 1039 }
duke@435 1040
duke@435 1041 void CppInterpreterGenerator::generate_compute_interpreter_state(const Register state,
duke@435 1042 const Register prev_state,
duke@435 1043 bool native) {
duke@435 1044
duke@435 1045 // On entry
duke@435 1046 // G5_method - caller's method
duke@435 1047 // Gargs - points to initial parameters (i.e. locals[0])
duke@435 1048 // G2_thread - valid? (C1 only??)
duke@435 1049 // "prev_state" - contains any previous frame manager state which we must save a link
duke@435 1050 //
duke@435 1051 // On return
duke@435 1052 // "state" is a pointer to the newly allocated state object. We must allocate and initialize
duke@435 1053 // a new interpretState object and the method expression stack.
duke@435 1054
duke@435 1055 assert_different_registers(state, prev_state);
duke@435 1056 assert_different_registers(prev_state, G3_scratch);
duke@435 1057 const Register Gtmp = G3_scratch;
coleenp@4037 1058 const Address constMethod (G5_method, 0, in_bytes(Method::const_offset()));
coleenp@4037 1059 const Address access_flags (G5_method, 0, in_bytes(Method::access_flags_offset()));
duke@435 1060
duke@435 1061 // slop factor is two extra slots on the expression stack so that
duke@435 1062 // we always have room to store a result when returning from a call without parameters
duke@435 1063 // that returns a result.
duke@435 1064
duke@435 1065 const int slop_factor = 2*wordSize;
duke@435 1066
duke@435 1067 const int fixed_size = ((sizeof(BytecodeInterpreter) + slop_factor) >> LogBytesPerWord) + // what is the slop factor?
roland@5225 1068 Method::extra_stack_entries() + // extra stack for jsr 292
duke@435 1069 frame::memory_parameter_word_sp_offset + // register save area + param window
duke@435 1070 (native ? frame::interpreter_frame_extra_outgoing_argument_words : 0); // JNI, class
duke@435 1071
duke@435 1072 // XXX G5_method valid
duke@435 1073
duke@435 1074 // Now compute new frame size
duke@435 1075
duke@435 1076 if (native) {
jiangli@4338 1077 const Register RconstMethod = Gtmp;
jiangli@4338 1078 const Address size_of_parameters(RconstMethod, 0, in_bytes(ConstMethod::size_of_parameters_offset()));
jiangli@4338 1079 __ ld_ptr(constMethod, RconstMethod);
duke@435 1080 __ lduh( size_of_parameters, Gtmp );
duke@435 1081 __ calc_mem_param_words(Gtmp, Gtmp); // space for native call parameters passed on the stack in words
duke@435 1082 } else {
jiangli@4302 1083 // Full size expression stack
jiangli@4302 1084 __ ld_ptr(constMethod, Gtmp);
jiangli@4302 1085 __ lduh(Gtmp, in_bytes(ConstMethod::max_stack_offset()), Gtmp);
duke@435 1086 }
duke@435 1087 __ add(Gtmp, fixed_size, Gtmp); // plus the fixed portion
duke@435 1088
duke@435 1089 __ neg(Gtmp); // negative space for stack/parameters in words
duke@435 1090 __ and3(Gtmp, -WordsPerLong, Gtmp); // make multiple of 2 (SP must be 2-word aligned)
duke@435 1091 __ sll(Gtmp, LogBytesPerWord, Gtmp); // negative space for frame in bytes
duke@435 1092
duke@435 1093 // Need to do stack size check here before we fault on large frames
duke@435 1094
duke@435 1095 Label stack_ok;
duke@435 1096
duke@435 1097 const int max_pages = StackShadowPages > (StackRedPages+StackYellowPages) ? StackShadowPages :
duke@435 1098 (StackRedPages+StackYellowPages);
duke@435 1099
duke@435 1100
duke@435 1101 __ ld_ptr(G2_thread, in_bytes(Thread::stack_base_offset()), O0);
duke@435 1102 __ ld_ptr(G2_thread, in_bytes(Thread::stack_size_offset()), O1);
duke@435 1103 // compute stack bottom
duke@435 1104 __ sub(O0, O1, O0);
duke@435 1105
duke@435 1106 // Avoid touching the guard pages
duke@435 1107 // Also a fudge for frame size of BytecodeInterpreter::run
duke@435 1108 // It varies from 1k->4k depending on build type
duke@435 1109 const int fudge = 6 * K;
duke@435 1110
duke@435 1111 __ set(fudge + (max_pages * os::vm_page_size()), O1);
duke@435 1112
duke@435 1113 __ add(O0, O1, O0);
duke@435 1114 __ sub(O0, Gtmp, O0);
duke@435 1115 __ cmp(SP, O0);
duke@435 1116 __ brx(Assembler::greaterUnsigned, false, Assembler::pt, stack_ok);
duke@435 1117 __ delayed()->nop();
duke@435 1118
duke@435 1119 // throw exception return address becomes throwing pc
duke@435 1120
duke@435 1121 __ call_VM(Oexception, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_StackOverflowError));
duke@435 1122 __ stop("never reached");
duke@435 1123
duke@435 1124 __ bind(stack_ok);
duke@435 1125
duke@435 1126 __ save(SP, Gtmp, SP); // setup new frame and register window
duke@435 1127
duke@435 1128 // New window I7 call_stub or previous activation
duke@435 1129 // O6 - register save area, BytecodeInterpreter just below it, args/locals just above that
duke@435 1130 //
duke@435 1131 __ sub(FP, sizeof(BytecodeInterpreter), state); // Point to new Interpreter state
duke@435 1132 __ add(state, STACK_BIAS, state ); // Account for 64bit bias
duke@435 1133
duke@435 1134 #define XXX_STATE(field_name) state, in_bytes(byte_offset_of(BytecodeInterpreter, field_name))
duke@435 1135
duke@435 1136 // Initialize a new Interpreter state
duke@435 1137 // orig_sp - caller's original sp
duke@435 1138 // G2_thread - thread
duke@435 1139 // Gargs - &locals[0] (unbiased?)
duke@435 1140 // G5_method - method
duke@435 1141 // SP (biased) - accounts for full size java stack, BytecodeInterpreter object, register save area, and register parameter save window
duke@435 1142
duke@435 1143
duke@435 1144 __ set(0xdead0004, O1);
duke@435 1145
duke@435 1146
duke@435 1147 __ st_ptr(Gargs, XXX_STATE(_locals));
duke@435 1148 __ st_ptr(G0, XXX_STATE(_oop_temp));
duke@435 1149
duke@435 1150 __ st_ptr(state, XXX_STATE(_self_link)); // point to self
duke@435 1151 __ st_ptr(prev_state->after_save(), XXX_STATE(_prev_link)); // Chain interpreter states
duke@435 1152 __ st_ptr(G2_thread, XXX_STATE(_thread)); // Store javathread
duke@435 1153
duke@435 1154 if (native) {
duke@435 1155 __ st_ptr(G0, XXX_STATE(_bcp));
duke@435 1156 } else {
coleenp@4037 1157 __ ld_ptr(G5_method, in_bytes(Method::const_offset()), O2); // get ConstMethod*
coleenp@4037 1158 __ add(O2, in_bytes(ConstMethod::codes_offset()), O2); // get bcp
duke@435 1159 __ st_ptr(O2, XXX_STATE(_bcp));
duke@435 1160 }
duke@435 1161
duke@435 1162 __ st_ptr(G0, XXX_STATE(_mdx));
duke@435 1163 __ st_ptr(G5_method, XXX_STATE(_method));
duke@435 1164
duke@435 1165 __ set((int) BytecodeInterpreter::method_entry, O1);
duke@435 1166 __ st(O1, XXX_STATE(_msg));
duke@435 1167
jiangli@3826 1168 __ ld_ptr(constMethod, O3);
coleenp@4037 1169 __ ld_ptr(O3, in_bytes(ConstMethod::constants_offset()), O3);
coleenp@4037 1170 __ ld_ptr(O3, ConstantPool::cache_offset_in_bytes(), O2);
duke@435 1171 __ st_ptr(O2, XXX_STATE(_constants));
duke@435 1172
duke@435 1173 __ st_ptr(G0, XXX_STATE(_result._to_call._callee));
duke@435 1174
duke@435 1175 // Monitor base is just start of BytecodeInterpreter object;
duke@435 1176 __ mov(state, O2);
duke@435 1177 __ st_ptr(O2, XXX_STATE(_monitor_base));
duke@435 1178
duke@435 1179 // Do we need a monitor for synchonized method?
duke@435 1180 {
duke@435 1181 __ ld(access_flags, O1);
duke@435 1182 Label done;
duke@435 1183 Label got_obj;
duke@435 1184 __ btst(JVM_ACC_SYNCHRONIZED, O1);
duke@435 1185 __ br( Assembler::zero, false, Assembler::pt, done);
duke@435 1186
stefank@3391 1187 const int mirror_offset = in_bytes(Klass::java_mirror_offset());
duke@435 1188 __ delayed()->btst(JVM_ACC_STATIC, O1);
duke@435 1189 __ ld_ptr(XXX_STATE(_locals), O1);
duke@435 1190 __ br( Assembler::zero, true, Assembler::pt, got_obj);
duke@435 1191 __ delayed()->ld_ptr(O1, 0, O1); // get receiver for not-static case
jiangli@3826 1192 __ ld_ptr(constMethod, O1);
coleenp@4037 1193 __ ld_ptr( O1, in_bytes(ConstMethod::constants_offset()), O1);
coleenp@4037 1194 __ ld_ptr( O1, ConstantPool::pool_holder_offset_in_bytes(), O1);
coleenp@4037 1195 // lock the mirror, not the Klass*
duke@435 1196 __ ld_ptr( O1, mirror_offset, O1);
duke@435 1197
duke@435 1198 __ bind(got_obj);
duke@435 1199
duke@435 1200 #ifdef ASSERT
duke@435 1201 __ tst(O1);
coleenp@3627 1202 __ breakpoint_trap(Assembler::zero, Assembler::ptr_cc);
duke@435 1203 #endif // ASSERT
duke@435 1204
duke@435 1205 const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
duke@435 1206 __ sub(SP, entry_size, SP); // account for initial monitor
duke@435 1207 __ sub(O2, entry_size, O2); // initial monitor
duke@435 1208 __ st_ptr(O1, O2, BasicObjectLock::obj_offset_in_bytes()); // and allocate it for interpreter use
duke@435 1209 __ bind(done);
duke@435 1210 }
duke@435 1211
duke@435 1212 // Remember initial frame bottom
duke@435 1213
duke@435 1214 __ st_ptr(SP, XXX_STATE(_frame_bottom));
duke@435 1215
duke@435 1216 __ st_ptr(O2, XXX_STATE(_stack_base));
duke@435 1217
duke@435 1218 __ sub(O2, wordSize, O2); // prepush
duke@435 1219 __ st_ptr(O2, XXX_STATE(_stack)); // PREPUSH
duke@435 1220
jiangli@4302 1221 // Full size expression stack
jiangli@4302 1222 __ ld_ptr(constMethod, O3);
jiangli@4302 1223 __ lduh(O3, in_bytes(ConstMethod::max_stack_offset()), O3);
roland@5225 1224 __ inc(O3, Method::extra_stack_entries());
duke@435 1225 __ sll(O3, LogBytesPerWord, O3);
duke@435 1226 __ sub(O2, O3, O3);
duke@435 1227 // __ sub(O3, wordSize, O3); // so prepush doesn't look out of bounds
duke@435 1228 __ st_ptr(O3, XXX_STATE(_stack_limit));
duke@435 1229
duke@435 1230 if (!native) {
duke@435 1231 //
duke@435 1232 // Code to initialize locals
duke@435 1233 //
duke@435 1234 Register init_value = noreg; // will be G0 if we must clear locals
duke@435 1235 // Now zero locals
duke@435 1236 if (true /* zerolocals */ || ClearInterpreterLocals) {
duke@435 1237 // explicitly initialize locals
duke@435 1238 init_value = G0;
duke@435 1239 } else {
duke@435 1240 #ifdef ASSERT
duke@435 1241 // initialize locals to a garbage pattern for better debugging
duke@435 1242 init_value = O3;
duke@435 1243 __ set( 0x0F0F0F0F, init_value );
duke@435 1244 #endif // ASSERT
duke@435 1245 }
duke@435 1246 if (init_value != noreg) {
duke@435 1247 Label clear_loop;
jiangli@4338 1248 const Register RconstMethod = O1;
jiangli@4338 1249 const Address size_of_parameters(RconstMethod, 0, in_bytes(ConstMethod::size_of_parameters_offset()));
jiangli@4338 1250 const Address size_of_locals (RconstMethod, 0, in_bytes(ConstMethod::size_of_locals_offset()));
duke@435 1251
duke@435 1252 // NOTE: If you change the frame layout, this code will need to
duke@435 1253 // be updated!
jiangli@4338 1254 __ ld_ptr( constMethod, RconstMethod );
duke@435 1255 __ lduh( size_of_locals, O2 );
duke@435 1256 __ lduh( size_of_parameters, O1 );
duke@435 1257 __ sll( O2, LogBytesPerWord, O2);
duke@435 1258 __ sll( O1, LogBytesPerWord, O1 );
duke@435 1259 __ ld_ptr(XXX_STATE(_locals), L2_scratch);
duke@435 1260 __ sub( L2_scratch, O2, O2 );
duke@435 1261 __ sub( L2_scratch, O1, O1 );
duke@435 1262
duke@435 1263 __ bind( clear_loop );
duke@435 1264 __ inc( O2, wordSize );
duke@435 1265
duke@435 1266 __ cmp( O2, O1 );
duke@435 1267 __ br( Assembler::lessEqualUnsigned, true, Assembler::pt, clear_loop );
duke@435 1268 __ delayed()->st_ptr( init_value, O2, 0 );
duke@435 1269 }
duke@435 1270 }
duke@435 1271 }
duke@435 1272 // Find preallocated monitor and lock method (C++ interpreter)
duke@435 1273 //
duke@435 1274 void InterpreterGenerator::lock_method(void) {
duke@435 1275 // Lock the current method.
duke@435 1276 // Destroys registers L2_scratch, L3_scratch, O0
duke@435 1277 //
duke@435 1278 // Find everything relative to Lstate
duke@435 1279
duke@435 1280 #ifdef ASSERT
duke@435 1281 __ ld_ptr(STATE(_method), L2_scratch);
coleenp@4037 1282 __ ld(L2_scratch, in_bytes(Method::access_flags_offset()), O0);
duke@435 1283
duke@435 1284 { Label ok;
duke@435 1285 __ btst(JVM_ACC_SYNCHRONIZED, O0);
duke@435 1286 __ br( Assembler::notZero, false, Assembler::pt, ok);
duke@435 1287 __ delayed()->nop();
duke@435 1288 __ stop("method doesn't need synchronization");
duke@435 1289 __ bind(ok);
duke@435 1290 }
duke@435 1291 #endif // ASSERT
duke@435 1292
duke@435 1293 // monitor is already allocated at stack base
duke@435 1294 // and the lockee is already present
duke@435 1295 __ ld_ptr(STATE(_stack_base), L2_scratch);
duke@435 1296 __ ld_ptr(L2_scratch, BasicObjectLock::obj_offset_in_bytes(), O0); // get object
duke@435 1297 __ lock_object(L2_scratch, O0);
duke@435 1298
duke@435 1299 }
duke@435 1300
duke@435 1301 // Generate code for handling resuming a deopted method
duke@435 1302 void CppInterpreterGenerator::generate_deopt_handling() {
duke@435 1303
duke@435 1304 Label return_from_deopt_common;
duke@435 1305
duke@435 1306 // deopt needs to jump to here to enter the interpreter (return a result)
duke@435 1307 deopt_frame_manager_return_atos = __ pc();
duke@435 1308
duke@435 1309 // O0/O1 live
kvn@3037 1310 __ ba(return_from_deopt_common);
duke@435 1311 __ delayed()->set(AbstractInterpreter::BasicType_as_index(T_OBJECT), L3_scratch); // Result stub address array index
duke@435 1312
duke@435 1313
duke@435 1314 // deopt needs to jump to here to enter the interpreter (return a result)
duke@435 1315 deopt_frame_manager_return_btos = __ pc();
duke@435 1316
duke@435 1317 // O0/O1 live
kvn@3037 1318 __ ba(return_from_deopt_common);
duke@435 1319 __ delayed()->set(AbstractInterpreter::BasicType_as_index(T_BOOLEAN), L3_scratch); // Result stub address array index
duke@435 1320
duke@435 1321 // deopt needs to jump to here to enter the interpreter (return a result)
duke@435 1322 deopt_frame_manager_return_itos = __ pc();
duke@435 1323
duke@435 1324 // O0/O1 live
kvn@3037 1325 __ ba(return_from_deopt_common);
duke@435 1326 __ delayed()->set(AbstractInterpreter::BasicType_as_index(T_INT), L3_scratch); // Result stub address array index
duke@435 1327
duke@435 1328 // deopt needs to jump to here to enter the interpreter (return a result)
duke@435 1329
duke@435 1330 deopt_frame_manager_return_ltos = __ pc();
duke@435 1331 #if !defined(_LP64) && defined(COMPILER2)
duke@435 1332 // All return values are where we want them, except for Longs. C2 returns
duke@435 1333 // longs in G1 in the 32-bit build whereas the interpreter wants them in O0/O1.
duke@435 1334 // Since the interpreter will return longs in G1 and O0/O1 in the 32bit
duke@435 1335 // build even if we are returning from interpreted we just do a little
duke@435 1336 // stupid shuffing.
duke@435 1337 // Note: I tried to make c2 return longs in O0/O1 and G1 so we wouldn't have to
duke@435 1338 // do this here. Unfortunately if we did a rethrow we'd see an machepilog node
duke@435 1339 // first which would move g1 -> O0/O1 and destroy the exception we were throwing.
duke@435 1340
duke@435 1341 __ srl (G1, 0,O1);
duke@435 1342 __ srlx(G1,32,O0);
duke@435 1343 #endif /* !_LP64 && COMPILER2 */
duke@435 1344 // O0/O1 live
kvn@3037 1345 __ ba(return_from_deopt_common);
duke@435 1346 __ delayed()->set(AbstractInterpreter::BasicType_as_index(T_LONG), L3_scratch); // Result stub address array index
duke@435 1347
duke@435 1348 // deopt needs to jump to here to enter the interpreter (return a result)
duke@435 1349
duke@435 1350 deopt_frame_manager_return_ftos = __ pc();
duke@435 1351 // O0/O1 live
kvn@3037 1352 __ ba(return_from_deopt_common);
duke@435 1353 __ delayed()->set(AbstractInterpreter::BasicType_as_index(T_FLOAT), L3_scratch); // Result stub address array index
duke@435 1354
duke@435 1355 // deopt needs to jump to here to enter the interpreter (return a result)
duke@435 1356 deopt_frame_manager_return_dtos = __ pc();
duke@435 1357
duke@435 1358 // O0/O1 live
kvn@3037 1359 __ ba(return_from_deopt_common);
duke@435 1360 __ delayed()->set(AbstractInterpreter::BasicType_as_index(T_DOUBLE), L3_scratch); // Result stub address array index
duke@435 1361
duke@435 1362 // deopt needs to jump to here to enter the interpreter (return a result)
duke@435 1363 deopt_frame_manager_return_vtos = __ pc();
duke@435 1364
duke@435 1365 // O0/O1 live
duke@435 1366 __ set(AbstractInterpreter::BasicType_as_index(T_VOID), L3_scratch);
duke@435 1367
duke@435 1368 // Deopt return common
duke@435 1369 // an index is present that lets us move any possible result being
duke@435 1370 // return to the interpreter's stack
duke@435 1371 //
duke@435 1372 __ bind(return_from_deopt_common);
duke@435 1373
duke@435 1374 // Result if any is in native abi result (O0..O1/F0..F1). The java expression
duke@435 1375 // stack is in the state that the calling convention left it.
duke@435 1376 // Copy the result from native abi result and place it on java expression stack.
duke@435 1377
duke@435 1378 // Current interpreter state is present in Lstate
duke@435 1379
duke@435 1380 // Get current pre-pushed top of interpreter stack
duke@435 1381 // Any result (if any) is in native abi
duke@435 1382 // result type index is in L3_scratch
duke@435 1383
duke@435 1384 __ ld_ptr(STATE(_stack), L1_scratch); // get top of java expr stack
duke@435 1385
duke@435 1386 __ set((intptr_t)CppInterpreter::_tosca_to_stack, L4_scratch);
duke@435 1387 __ sll(L3_scratch, LogBytesPerWord, L3_scratch);
duke@435 1388 __ ld_ptr(L4_scratch, L3_scratch, Lscratch); // get typed result converter address
duke@435 1389 __ jmpl(Lscratch, G0, O7); // and convert it
duke@435 1390 __ delayed()->nop();
duke@435 1391
duke@435 1392 // L1_scratch points to top of stack (prepushed)
duke@435 1393 __ st_ptr(L1_scratch, STATE(_stack));
duke@435 1394 }
duke@435 1395
duke@435 1396 // Generate the code to handle a more_monitors message from the c++ interpreter
duke@435 1397 void CppInterpreterGenerator::generate_more_monitors() {
duke@435 1398
duke@435 1399 Label entry, loop;
duke@435 1400 const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
duke@435 1401 // 1. compute new pointers // esp: old expression stack top
duke@435 1402 __ delayed()->ld_ptr(STATE(_stack_base), L4_scratch); // current expression stack bottom
duke@435 1403 __ sub(L4_scratch, entry_size, L4_scratch);
duke@435 1404 __ st_ptr(L4_scratch, STATE(_stack_base));
duke@435 1405
duke@435 1406 __ sub(SP, entry_size, SP); // Grow stack
duke@435 1407 __ st_ptr(SP, STATE(_frame_bottom));
duke@435 1408
duke@435 1409 __ ld_ptr(STATE(_stack_limit), L2_scratch);
duke@435 1410 __ sub(L2_scratch, entry_size, L2_scratch);
duke@435 1411 __ st_ptr(L2_scratch, STATE(_stack_limit));
duke@435 1412
duke@435 1413 __ ld_ptr(STATE(_stack), L1_scratch); // Get current stack top
duke@435 1414 __ sub(L1_scratch, entry_size, L1_scratch);
duke@435 1415 __ st_ptr(L1_scratch, STATE(_stack));
kvn@3037 1416 __ ba(entry);
duke@435 1417 __ delayed()->add(L1_scratch, wordSize, L1_scratch); // first real entry (undo prepush)
duke@435 1418
duke@435 1419 // 2. move expression stack
duke@435 1420
duke@435 1421 __ bind(loop);
duke@435 1422 __ st_ptr(L3_scratch, Address(L1_scratch, 0));
duke@435 1423 __ add(L1_scratch, wordSize, L1_scratch);
duke@435 1424 __ bind(entry);
duke@435 1425 __ cmp(L1_scratch, L4_scratch);
duke@435 1426 __ br(Assembler::notEqual, false, Assembler::pt, loop);
duke@435 1427 __ delayed()->ld_ptr(L1_scratch, entry_size, L3_scratch);
duke@435 1428
duke@435 1429 // now zero the slot so we can find it.
sgoldman@558 1430 __ st_ptr(G0, L4_scratch, BasicObjectLock::obj_offset_in_bytes());
duke@435 1431
duke@435 1432 }
duke@435 1433
duke@435 1434 // Initial entry to C++ interpreter from the call_stub.
duke@435 1435 // This entry point is called the frame manager since it handles the generation
duke@435 1436 // of interpreter activation frames via requests directly from the vm (via call_stub)
duke@435 1437 // and via requests from the interpreter. The requests from the call_stub happen
duke@435 1438 // directly thru the entry point. Requests from the interpreter happen via returning
duke@435 1439 // from the interpreter and examining the message the interpreter has returned to
duke@435 1440 // the frame manager. The frame manager can take the following requests:
duke@435 1441
duke@435 1442 // NO_REQUEST - error, should never happen.
duke@435 1443 // MORE_MONITORS - need a new monitor. Shuffle the expression stack on down and
duke@435 1444 // allocate a new monitor.
duke@435 1445 // CALL_METHOD - setup a new activation to call a new method. Very similar to what
duke@435 1446 // happens during entry during the entry via the call stub.
duke@435 1447 // RETURN_FROM_METHOD - remove an activation. Return to interpreter or call stub.
duke@435 1448 //
duke@435 1449 // Arguments:
duke@435 1450 //
coleenp@4037 1451 // ebx: Method*
duke@435 1452 // ecx: receiver - unused (retrieved from stack as needed)
duke@435 1453 // esi: previous frame manager state (NULL from the call_stub/c1/c2)
duke@435 1454 //
duke@435 1455 //
duke@435 1456 // Stack layout at entry
duke@435 1457 //
duke@435 1458 // [ return address ] <--- esp
duke@435 1459 // [ parameter n ]
duke@435 1460 // ...
duke@435 1461 // [ parameter 1 ]
duke@435 1462 // [ expression stack ]
duke@435 1463 //
duke@435 1464 //
duke@435 1465 // We are free to blow any registers we like because the call_stub which brought us here
duke@435 1466 // initially has preserved the callee save registers already.
duke@435 1467 //
duke@435 1468 //
duke@435 1469
duke@435 1470 static address interpreter_frame_manager = NULL;
duke@435 1471
duke@435 1472 #ifdef ASSERT
duke@435 1473 #define VALIDATE_STATE(scratch, marker) \
duke@435 1474 { \
duke@435 1475 Label skip; \
duke@435 1476 __ ld_ptr(STATE(_self_link), scratch); \
duke@435 1477 __ cmp(Lstate, scratch); \
duke@435 1478 __ brx(Assembler::equal, false, Assembler::pt, skip); \
duke@435 1479 __ delayed()->nop(); \
duke@435 1480 __ breakpoint_trap(); \
twisti@4412 1481 __ emit_int32(marker); \
duke@435 1482 __ bind(skip); \
duke@435 1483 }
duke@435 1484 #else
duke@435 1485 #define VALIDATE_STATE(scratch, marker)
duke@435 1486 #endif /* ASSERT */
duke@435 1487
duke@435 1488 void CppInterpreterGenerator::adjust_callers_stack(Register args) {
duke@435 1489 //
duke@435 1490 // Adjust caller's stack so that all the locals can be contiguous with
duke@435 1491 // the parameters.
duke@435 1492 // Worries about stack overflow make this a pain.
duke@435 1493 //
duke@435 1494 // Destroys args, G3_scratch, G3_scratch
duke@435 1495 // In/Out O5_savedSP (sender's original SP)
duke@435 1496 //
duke@435 1497 // assert_different_registers(state, prev_state);
duke@435 1498 const Register Gtmp = G3_scratch;
jiangli@4338 1499 const RconstMethod = G3_scratch;
duke@435 1500 const Register tmp = O2;
jiangli@4338 1501 const Address constMethod(G5_method, 0, in_bytes(Method::const_offset()));
jiangli@4338 1502 const Address size_of_parameters(RconstMethod, 0, in_bytes(ConstMethod::size_of_parameters_offset()));
jiangli@4338 1503 const Address size_of_locals (RconstMethod, 0, in_bytes(ConstMethod::size_of_locals_offset()));
duke@435 1504
jiangli@4338 1505 __ ld_ptr(constMethod, RconstMethod);
duke@435 1506 __ lduh(size_of_parameters, tmp);
jiangli@4338 1507 __ sll(tmp, LogBytesPerWord, Gargs); // parameter size in bytes
jiangli@4338 1508 __ add(args, Gargs, Gargs); // points to first local + BytesPerWord
duke@435 1509 // NEW
duke@435 1510 __ add(Gargs, -wordSize, Gargs); // points to first local[0]
duke@435 1511 // determine extra space for non-argument locals & adjust caller's SP
duke@435 1512 // Gtmp1: parameter size in words
duke@435 1513 __ lduh(size_of_locals, Gtmp);
duke@435 1514 __ compute_extra_locals_size_in_bytes(tmp, Gtmp, Gtmp);
duke@435 1515
duke@435 1516 #if 1
duke@435 1517 // c2i adapters place the final interpreter argument in the register save area for O0/I0
duke@435 1518 // the call_stub will place the final interpreter argument at
duke@435 1519 // frame::memory_parameter_word_sp_offset. This is mostly not noticable for either asm
duke@435 1520 // or c++ interpreter. However with the c++ interpreter when we do a recursive call
duke@435 1521 // and try to make it look good in the debugger we will store the argument to
duke@435 1522 // RecursiveInterpreterActivation in the register argument save area. Without allocating
duke@435 1523 // extra space for the compiler this will overwrite locals in the local array of the
duke@435 1524 // interpreter.
duke@435 1525 // QQQ still needed with frameless adapters???
duke@435 1526
duke@435 1527 const int c2i_adjust_words = frame::memory_parameter_word_sp_offset - frame::callee_register_argument_save_area_sp_offset;
duke@435 1528
duke@435 1529 __ add(Gtmp, c2i_adjust_words*wordSize, Gtmp);
duke@435 1530 #endif // 1
duke@435 1531
duke@435 1532
duke@435 1533 __ sub(SP, Gtmp, SP); // just caller's frame for the additional space we need.
duke@435 1534 }
duke@435 1535
duke@435 1536 address InterpreterGenerator::generate_normal_entry(bool synchronized) {
duke@435 1537
coleenp@4037 1538 // G5_method: Method*
duke@435 1539 // G2_thread: thread (unused)
duke@435 1540 // Gargs: bottom of args (sender_sp)
duke@435 1541 // O5: sender's sp
duke@435 1542
duke@435 1543 // A single frame manager is plenty as we don't specialize for synchronized. We could and
duke@435 1544 // the code is pretty much ready. Would need to change the test below and for good measure
duke@435 1545 // modify generate_interpreter_state to only do the (pre) sync stuff stuff for synchronized
duke@435 1546 // routines. Not clear this is worth it yet.
duke@435 1547
duke@435 1548 if (interpreter_frame_manager) {
duke@435 1549 return interpreter_frame_manager;
duke@435 1550 }
duke@435 1551
duke@435 1552 __ bind(frame_manager_entry);
duke@435 1553
duke@435 1554 // the following temporary registers are used during frame creation
duke@435 1555 const Register Gtmp1 = G3_scratch;
duke@435 1556 // const Register Lmirror = L1; // native mirror (native calls only)
duke@435 1557
coleenp@4037 1558 const Address constMethod (G5_method, 0, in_bytes(Method::const_offset()));
coleenp@4037 1559 const Address access_flags (G5_method, 0, in_bytes(Method::access_flags_offset()));
duke@435 1560
duke@435 1561 address entry_point = __ pc();
duke@435 1562 __ mov(G0, prevState); // no current activation
duke@435 1563
duke@435 1564
duke@435 1565 Label re_dispatch;
duke@435 1566
duke@435 1567 __ bind(re_dispatch);
duke@435 1568
duke@435 1569 // Interpreter needs to have locals completely contiguous. In order to do that
duke@435 1570 // We must adjust the caller's stack pointer for any locals beyond just the
duke@435 1571 // parameters
duke@435 1572 adjust_callers_stack(Gargs);
duke@435 1573
duke@435 1574 // O5_savedSP still contains sender's sp
duke@435 1575
duke@435 1576 // NEW FRAME
duke@435 1577
duke@435 1578 generate_compute_interpreter_state(Lstate, prevState, false);
duke@435 1579
duke@435 1580 // At this point a new interpreter frame and state object are created and initialized
duke@435 1581 // Lstate has the pointer to the new activation
duke@435 1582 // Any stack banging or limit check should already be done.
duke@435 1583
duke@435 1584 Label call_interpreter;
duke@435 1585
duke@435 1586 __ bind(call_interpreter);
duke@435 1587
duke@435 1588
duke@435 1589 #if 1
duke@435 1590 __ set(0xdead002, Lmirror);
duke@435 1591 __ set(0xdead002, L2_scratch);
duke@435 1592 __ set(0xdead003, L3_scratch);
duke@435 1593 __ set(0xdead004, L4_scratch);
duke@435 1594 __ set(0xdead005, Lscratch);
duke@435 1595 __ set(0xdead006, Lscratch2);
duke@435 1596 __ set(0xdead007, L7_scratch);
duke@435 1597
duke@435 1598 __ set(0xdeaf002, O2);
duke@435 1599 __ set(0xdeaf003, O3);
duke@435 1600 __ set(0xdeaf004, O4);
duke@435 1601 __ set(0xdeaf005, O5);
duke@435 1602 #endif
duke@435 1603
duke@435 1604 // Call interpreter (stack bang complete) enter here if message is
duke@435 1605 // set and we know stack size is valid
duke@435 1606
duke@435 1607 Label call_interpreter_2;
duke@435 1608
duke@435 1609 __ bind(call_interpreter_2);
duke@435 1610
duke@435 1611 #ifdef ASSERT
duke@435 1612 {
duke@435 1613 Label skip;
duke@435 1614 __ ld_ptr(STATE(_frame_bottom), G3_scratch);
duke@435 1615 __ cmp(G3_scratch, SP);
duke@435 1616 __ brx(Assembler::equal, false, Assembler::pt, skip);
duke@435 1617 __ delayed()->nop();
duke@435 1618 __ stop("SP not restored to frame bottom");
duke@435 1619 __ bind(skip);
duke@435 1620 }
duke@435 1621 #endif
duke@435 1622
duke@435 1623 VALIDATE_STATE(G3_scratch, 4);
duke@435 1624 __ set_last_Java_frame(SP, noreg);
duke@435 1625 __ mov(Lstate, O0); // (arg) pointer to current state
duke@435 1626
duke@435 1627 __ call(CAST_FROM_FN_PTR(address,
duke@435 1628 JvmtiExport::can_post_interpreter_events() ?
duke@435 1629 BytecodeInterpreter::runWithChecks
duke@435 1630 : BytecodeInterpreter::run),
duke@435 1631 relocInfo::runtime_call_type);
duke@435 1632
duke@435 1633 __ delayed()->nop();
duke@435 1634
duke@435 1635 __ ld_ptr(STATE(_thread), G2_thread);
duke@435 1636 __ reset_last_Java_frame();
duke@435 1637
duke@435 1638 // examine msg from interpreter to determine next action
duke@435 1639 __ ld_ptr(STATE(_thread), G2_thread); // restore G2_thread
duke@435 1640
duke@435 1641 __ ld(STATE(_msg), L1_scratch); // Get new message
duke@435 1642
duke@435 1643 Label call_method;
duke@435 1644 Label return_from_interpreted_method;
duke@435 1645 Label throw_exception;
duke@435 1646 Label do_OSR;
duke@435 1647 Label bad_msg;
duke@435 1648 Label resume_interpreter;
duke@435 1649
duke@435 1650 __ cmp(L1_scratch, (int)BytecodeInterpreter::call_method);
duke@435 1651 __ br(Assembler::equal, false, Assembler::pt, call_method);
duke@435 1652 __ delayed()->cmp(L1_scratch, (int)BytecodeInterpreter::return_from_method);
duke@435 1653 __ br(Assembler::equal, false, Assembler::pt, return_from_interpreted_method);
duke@435 1654 __ delayed()->cmp(L1_scratch, (int)BytecodeInterpreter::throwing_exception);
duke@435 1655 __ br(Assembler::equal, false, Assembler::pt, throw_exception);
duke@435 1656 __ delayed()->cmp(L1_scratch, (int)BytecodeInterpreter::do_osr);
duke@435 1657 __ br(Assembler::equal, false, Assembler::pt, do_OSR);
duke@435 1658 __ delayed()->cmp(L1_scratch, (int)BytecodeInterpreter::more_monitors);
duke@435 1659 __ br(Assembler::notEqual, false, Assembler::pt, bad_msg);
duke@435 1660
duke@435 1661 // Allocate more monitor space, shuffle expression stack....
duke@435 1662
duke@435 1663 generate_more_monitors();
duke@435 1664
duke@435 1665 // new monitor slot allocated, resume the interpreter.
duke@435 1666
duke@435 1667 __ set((int)BytecodeInterpreter::got_monitors, L1_scratch);
duke@435 1668 VALIDATE_STATE(G3_scratch, 5);
kvn@3037 1669 __ ba(call_interpreter);
duke@435 1670 __ delayed()->st(L1_scratch, STATE(_msg));
duke@435 1671
duke@435 1672 // uncommon trap needs to jump to here to enter the interpreter (re-execute current bytecode)
duke@435 1673 unctrap_frame_manager_entry = __ pc();
duke@435 1674
duke@435 1675 // QQQ what message do we send
duke@435 1676
kvn@3037 1677 __ ba(call_interpreter);
duke@435 1678 __ delayed()->ld_ptr(STATE(_frame_bottom), SP); // restore to full stack frame
duke@435 1679
duke@435 1680 //=============================================================================
duke@435 1681 // Returning from a compiled method into a deopted method. The bytecode at the
duke@435 1682 // bcp has completed. The result of the bytecode is in the native abi (the tosca
duke@435 1683 // for the template based interpreter). Any stack space that was used by the
duke@435 1684 // bytecode that has completed has been removed (e.g. parameters for an invoke)
duke@435 1685 // so all that we have to do is place any pending result on the expression stack
duke@435 1686 // and resume execution on the next bytecode.
duke@435 1687
duke@435 1688 generate_deopt_handling();
duke@435 1689
duke@435 1690 // ready to resume the interpreter
duke@435 1691
duke@435 1692 __ set((int)BytecodeInterpreter::deopt_resume, L1_scratch);
kvn@3037 1693 __ ba(call_interpreter);
duke@435 1694 __ delayed()->st(L1_scratch, STATE(_msg));
duke@435 1695
duke@435 1696 // Current frame has caught an exception we need to dispatch to the
duke@435 1697 // handler. We can get here because a native interpreter frame caught
duke@435 1698 // an exception in which case there is no handler and we must rethrow
duke@435 1699 // If it is a vanilla interpreted frame the we simply drop into the
duke@435 1700 // interpreter and let it do the lookup.
duke@435 1701
duke@435 1702 Interpreter::_rethrow_exception_entry = __ pc();
duke@435 1703
duke@435 1704 Label return_with_exception;
duke@435 1705 Label unwind_and_forward;
duke@435 1706
duke@435 1707 // O0: exception
duke@435 1708 // O7: throwing pc
duke@435 1709
duke@435 1710 // We want exception in the thread no matter what we ultimately decide about frame type.
duke@435 1711
duke@435 1712 Address exception_addr (G2_thread, 0, in_bytes(Thread::pending_exception_offset()));
duke@435 1713 __ verify_thread();
duke@435 1714 __ st_ptr(O0, exception_addr);
duke@435 1715
coleenp@4037 1716 // get the Method*
duke@435 1717 __ ld_ptr(STATE(_method), G5_method);
duke@435 1718
duke@435 1719 // if this current frame vanilla or native?
duke@435 1720
duke@435 1721 __ ld(access_flags, Gtmp1);
duke@435 1722 __ btst(JVM_ACC_NATIVE, Gtmp1);
duke@435 1723 __ br(Assembler::zero, false, Assembler::pt, return_with_exception); // vanilla interpreted frame handle directly
duke@435 1724 __ delayed()->nop();
duke@435 1725
duke@435 1726 // We drop thru to unwind a native interpreted frame with a pending exception
duke@435 1727 // We jump here for the initial interpreter frame with exception pending
duke@435 1728 // We unwind the current acivation and forward it to our caller.
duke@435 1729
duke@435 1730 __ bind(unwind_and_forward);
duke@435 1731
duke@435 1732 // Unwind frame and jump to forward exception. unwinding will place throwing pc in O7
duke@435 1733 // as expected by forward_exception.
duke@435 1734
duke@435 1735 __ restore(FP, G0, SP); // unwind interpreter state frame
duke@435 1736 __ br(Assembler::always, false, Assembler::pt, StubRoutines::forward_exception_entry(), relocInfo::runtime_call_type);
duke@435 1737 __ delayed()->mov(I5_savedSP->after_restore(), SP);
duke@435 1738
duke@435 1739 // Return point from a call which returns a result in the native abi
duke@435 1740 // (c1/c2/jni-native). This result must be processed onto the java
duke@435 1741 // expression stack.
duke@435 1742 //
duke@435 1743 // A pending exception may be present in which case there is no result present
duke@435 1744
duke@435 1745 address return_from_native_method = __ pc();
duke@435 1746
duke@435 1747 VALIDATE_STATE(G3_scratch, 6);
duke@435 1748
duke@435 1749 // Result if any is in native abi result (O0..O1/F0..F1). The java expression
duke@435 1750 // stack is in the state that the calling convention left it.
duke@435 1751 // Copy the result from native abi result and place it on java expression stack.
duke@435 1752
duke@435 1753 // Current interpreter state is present in Lstate
duke@435 1754
duke@435 1755 // Exception pending?
duke@435 1756
duke@435 1757 __ ld_ptr(STATE(_frame_bottom), SP); // restore to full stack frame
duke@435 1758 __ ld_ptr(exception_addr, Lscratch); // get any pending exception
duke@435 1759 __ tst(Lscratch); // exception pending?
duke@435 1760 __ brx(Assembler::notZero, false, Assembler::pt, return_with_exception);
duke@435 1761 __ delayed()->nop();
duke@435 1762
duke@435 1763 // Process the native abi result to java expression stack
duke@435 1764
duke@435 1765 __ ld_ptr(STATE(_result._to_call._callee), L4_scratch); // called method
duke@435 1766 __ ld_ptr(STATE(_stack), L1_scratch); // get top of java expr stack
jiangli@4338 1767 // get parameter size
jiangli@4338 1768 __ ld_ptr(L4_scratch, in_bytes(Method::const_offset()), L2_scratch);
jiangli@4338 1769 __ lduh(L2_scratch, in_bytes(ConstMethod::size_of_parameters_offset()), L2_scratch);
duke@435 1770 __ sll(L2_scratch, LogBytesPerWord, L2_scratch ); // parameter size in bytes
duke@435 1771 __ add(L1_scratch, L2_scratch, L1_scratch); // stack destination for result
coleenp@4037 1772 __ ld(L4_scratch, in_bytes(Method::result_index_offset()), L3_scratch); // called method result type index
duke@435 1773
duke@435 1774 // tosca is really just native abi
duke@435 1775 __ set((intptr_t)CppInterpreter::_tosca_to_stack, L4_scratch);
duke@435 1776 __ sll(L3_scratch, LogBytesPerWord, L3_scratch);
duke@435 1777 __ ld_ptr(L4_scratch, L3_scratch, Lscratch); // get typed result converter address
duke@435 1778 __ jmpl(Lscratch, G0, O7); // and convert it
duke@435 1779 __ delayed()->nop();
duke@435 1780
duke@435 1781 // L1_scratch points to top of stack (prepushed)
duke@435 1782
kvn@3037 1783 __ ba(resume_interpreter);
duke@435 1784 __ delayed()->mov(L1_scratch, O1);
duke@435 1785
duke@435 1786 // An exception is being caught on return to a vanilla interpreter frame.
duke@435 1787 // Empty the stack and resume interpreter
duke@435 1788
duke@435 1789 __ bind(return_with_exception);
duke@435 1790
duke@435 1791 __ ld_ptr(STATE(_frame_bottom), SP); // restore to full stack frame
duke@435 1792 __ ld_ptr(STATE(_stack_base), O1); // empty java expression stack
kvn@3037 1793 __ ba(resume_interpreter);
duke@435 1794 __ delayed()->sub(O1, wordSize, O1); // account for prepush
duke@435 1795
duke@435 1796 // Return from interpreted method we return result appropriate to the caller (i.e. "recursive"
duke@435 1797 // interpreter call, or native) and unwind this interpreter activation.
duke@435 1798 // All monitors should be unlocked.
duke@435 1799
duke@435 1800 __ bind(return_from_interpreted_method);
duke@435 1801
duke@435 1802 VALIDATE_STATE(G3_scratch, 7);
duke@435 1803
duke@435 1804 Label return_to_initial_caller;
duke@435 1805
duke@435 1806 // Interpreted result is on the top of the completed activation expression stack.
duke@435 1807 // We must return it to the top of the callers stack if caller was interpreted
duke@435 1808 // otherwise we convert to native abi result and return to call_stub/c1/c2
duke@435 1809 // The caller's expression stack was truncated by the call however the current activation
duke@435 1810 // has enough stuff on the stack that we have usable space there no matter what. The
duke@435 1811 // other thing that makes it easy is that the top of the caller's stack is stored in STATE(_locals)
duke@435 1812 // for the current activation
duke@435 1813
duke@435 1814 __ ld_ptr(STATE(_prev_link), L1_scratch);
duke@435 1815 __ ld_ptr(STATE(_method), L2_scratch); // get method just executed
coleenp@4037 1816 __ ld(L2_scratch, in_bytes(Method::result_index_offset()), L2_scratch);
duke@435 1817 __ tst(L1_scratch);
duke@435 1818 __ brx(Assembler::zero, false, Assembler::pt, return_to_initial_caller);
duke@435 1819 __ delayed()->sll(L2_scratch, LogBytesPerWord, L2_scratch);
duke@435 1820
duke@435 1821 // Copy result to callers java stack
duke@435 1822
duke@435 1823 __ set((intptr_t)CppInterpreter::_stack_to_stack, L4_scratch);
duke@435 1824 __ ld_ptr(L4_scratch, L2_scratch, Lscratch); // get typed result converter address
duke@435 1825 __ ld_ptr(STATE(_stack), O0); // current top (prepushed)
duke@435 1826 __ ld_ptr(STATE(_locals), O1); // stack destination
duke@435 1827
duke@435 1828 // O0 - will be source, O1 - will be destination (preserved)
duke@435 1829 __ jmpl(Lscratch, G0, O7); // and convert it
duke@435 1830 __ delayed()->add(O0, wordSize, O0); // get source (top of current expr stack)
duke@435 1831
duke@435 1832 // O1 == &locals[0]
duke@435 1833
duke@435 1834 // Result is now on caller's stack. Just unwind current activation and resume
duke@435 1835
duke@435 1836 Label unwind_recursive_activation;
duke@435 1837
duke@435 1838
duke@435 1839 __ bind(unwind_recursive_activation);
duke@435 1840
duke@435 1841 // O1 == &locals[0] (really callers stacktop) for activation now returning
duke@435 1842 // returning to interpreter method from "recursive" interpreter call
duke@435 1843 // result converter left O1 pointing to top of the( prepushed) java stack for method we are returning
duke@435 1844 // to. Now all we must do is unwind the state from the completed call
duke@435 1845
duke@435 1846 // Must restore stack
duke@435 1847 VALIDATE_STATE(G3_scratch, 8);
duke@435 1848
duke@435 1849 // Return to interpreter method after a method call (interpreted/native/c1/c2) has completed.
duke@435 1850 // Result if any is already on the caller's stack. All we must do now is remove the now dead
duke@435 1851 // frame and tell interpreter to resume.
duke@435 1852
duke@435 1853
duke@435 1854 __ mov(O1, I1); // pass back new stack top across activation
duke@435 1855 // POP FRAME HERE ==================================
duke@435 1856 __ restore(FP, G0, SP); // unwind interpreter state frame
duke@435 1857 __ ld_ptr(STATE(_frame_bottom), SP); // restore to full stack frame
duke@435 1858
duke@435 1859
duke@435 1860 // Resume the interpreter. The current frame contains the current interpreter
duke@435 1861 // state object.
duke@435 1862 //
duke@435 1863 // O1 == new java stack pointer
duke@435 1864
duke@435 1865 __ bind(resume_interpreter);
duke@435 1866 VALIDATE_STATE(G3_scratch, 10);
duke@435 1867
duke@435 1868 // A frame we have already used before so no need to bang stack so use call_interpreter_2 entry
duke@435 1869
duke@435 1870 __ set((int)BytecodeInterpreter::method_resume, L1_scratch);
duke@435 1871 __ st(L1_scratch, STATE(_msg));
kvn@3037 1872 __ ba(call_interpreter_2);
duke@435 1873 __ delayed()->st_ptr(O1, STATE(_stack));
duke@435 1874
duke@435 1875
duke@435 1876 // Fast accessor methods share this entry point.
duke@435 1877 // This works because frame manager is in the same codelet
duke@435 1878 // This can either be an entry via call_stub/c1/c2 or a recursive interpreter call
duke@435 1879 // we need to do a little register fixup here once we distinguish the two of them
duke@435 1880 if (UseFastAccessorMethods && !synchronized) {
duke@435 1881 // Call stub_return address still in O7
duke@435 1882 __ bind(fast_accessor_slow_entry_path);
duke@435 1883 __ set((intptr_t)return_from_native_method - 8, Gtmp1);
duke@435 1884 __ cmp(Gtmp1, O7); // returning to interpreter?
duke@435 1885 __ brx(Assembler::equal, true, Assembler::pt, re_dispatch); // yep
duke@435 1886 __ delayed()->nop();
kvn@3037 1887 __ ba(re_dispatch);
kvn@3037 1888 __ delayed()->mov(G0, prevState); // initial entry
duke@435 1889
duke@435 1890 }
duke@435 1891
duke@435 1892 // interpreter returning to native code (call_stub/c1/c2)
duke@435 1893 // convert result and unwind initial activation
duke@435 1894 // L2_scratch - scaled result type index
duke@435 1895
duke@435 1896 __ bind(return_to_initial_caller);
duke@435 1897
duke@435 1898 __ set((intptr_t)CppInterpreter::_stack_to_native_abi, L4_scratch);
duke@435 1899 __ ld_ptr(L4_scratch, L2_scratch, Lscratch); // get typed result converter address
duke@435 1900 __ ld_ptr(STATE(_stack), O0); // current top (prepushed)
duke@435 1901 __ jmpl(Lscratch, G0, O7); // and convert it
duke@435 1902 __ delayed()->add(O0, wordSize, O0); // get source (top of current expr stack)
duke@435 1903
duke@435 1904 Label unwind_initial_activation;
duke@435 1905 __ bind(unwind_initial_activation);
duke@435 1906
duke@435 1907 // RETURN TO CALL_STUB/C1/C2 code (result if any in I0..I1/(F0/..F1)
duke@435 1908 // we can return here with an exception that wasn't handled by interpreted code
duke@435 1909 // how does c1/c2 see it on return?
duke@435 1910
duke@435 1911 // compute resulting sp before/after args popped depending upon calling convention
duke@435 1912 // __ ld_ptr(STATE(_saved_sp), Gtmp1);
duke@435 1913 //
duke@435 1914 // POP FRAME HERE ==================================
duke@435 1915 __ restore(FP, G0, SP);
duke@435 1916 __ retl();
duke@435 1917 __ delayed()->mov(I5_savedSP->after_restore(), SP);
duke@435 1918
duke@435 1919 // OSR request, unwind the current frame and transfer to the OSR entry
duke@435 1920 // and enter OSR nmethod
duke@435 1921
duke@435 1922 __ bind(do_OSR);
duke@435 1923 Label remove_initial_frame;
duke@435 1924 __ ld_ptr(STATE(_prev_link), L1_scratch);
duke@435 1925 __ ld_ptr(STATE(_result._osr._osr_buf), G1_scratch);
duke@435 1926
duke@435 1927 // We are going to pop this frame. Is there another interpreter frame underneath
duke@435 1928 // it or is it callstub/compiled?
duke@435 1929
duke@435 1930 __ tst(L1_scratch);
duke@435 1931 __ brx(Assembler::zero, false, Assembler::pt, remove_initial_frame);
duke@435 1932 __ delayed()->ld_ptr(STATE(_result._osr._osr_entry), G3_scratch);
duke@435 1933
duke@435 1934 // Frame underneath is an interpreter frame simply unwind
duke@435 1935 // POP FRAME HERE ==================================
duke@435 1936 __ restore(FP, G0, SP); // unwind interpreter state frame
duke@435 1937 __ mov(I5_savedSP->after_restore(), SP);
duke@435 1938
duke@435 1939 // Since we are now calling native need to change our "return address" from the
duke@435 1940 // dummy RecursiveInterpreterActivation to a return from native
duke@435 1941
duke@435 1942 __ set((intptr_t)return_from_native_method - 8, O7);
duke@435 1943
duke@435 1944 __ jmpl(G3_scratch, G0, G0);
duke@435 1945 __ delayed()->mov(G1_scratch, O0);
duke@435 1946
duke@435 1947 __ bind(remove_initial_frame);
duke@435 1948
duke@435 1949 // POP FRAME HERE ==================================
duke@435 1950 __ restore(FP, G0, SP);
duke@435 1951 __ mov(I5_savedSP->after_restore(), SP);
duke@435 1952 __ jmpl(G3_scratch, G0, G0);
duke@435 1953 __ delayed()->mov(G1_scratch, O0);
duke@435 1954
duke@435 1955 // Call a new method. All we do is (temporarily) trim the expression stack
duke@435 1956 // push a return address to bring us back to here and leap to the new entry.
duke@435 1957 // At this point we have a topmost frame that was allocated by the frame manager
duke@435 1958 // which contains the current method interpreted state. We trim this frame
duke@435 1959 // of excess java expression stack entries and then recurse.
duke@435 1960
duke@435 1961 __ bind(call_method);
duke@435 1962
duke@435 1963 // stack points to next free location and not top element on expression stack
duke@435 1964 // method expects sp to be pointing to topmost element
duke@435 1965
duke@435 1966 __ ld_ptr(STATE(_thread), G2_thread);
duke@435 1967 __ ld_ptr(STATE(_result._to_call._callee), G5_method);
duke@435 1968
duke@435 1969
duke@435 1970 // SP already takes in to account the 2 extra words we use for slop
duke@435 1971 // when we call a "static long no_params()" method. So if
duke@435 1972 // we trim back sp by the amount of unused java expression stack
duke@435 1973 // there will be automagically the 2 extra words we need.
duke@435 1974 // We also have to worry about keeping SP aligned.
duke@435 1975
duke@435 1976 __ ld_ptr(STATE(_stack), Gargs);
duke@435 1977 __ ld_ptr(STATE(_stack_limit), L1_scratch);
duke@435 1978
duke@435 1979 // compute the unused java stack size
duke@435 1980 __ sub(Gargs, L1_scratch, L2_scratch); // compute unused space
duke@435 1981
sgoldman@558 1982 // Round down the unused space to that stack is always 16-byte aligned
sgoldman@558 1983 // by making the unused space a multiple of the size of two longs.
duke@435 1984
sgoldman@558 1985 __ and3(L2_scratch, -2*BytesPerLong, L2_scratch);
duke@435 1986
duke@435 1987 // Now trim the stack
duke@435 1988 __ add(SP, L2_scratch, SP);
duke@435 1989
duke@435 1990
duke@435 1991 // Now point to the final argument (account for prepush)
duke@435 1992 __ add(Gargs, wordSize, Gargs);
duke@435 1993 #ifdef ASSERT
duke@435 1994 // Make sure we have space for the window
duke@435 1995 __ sub(Gargs, SP, L1_scratch);
duke@435 1996 __ cmp(L1_scratch, 16*wordSize);
duke@435 1997 {
duke@435 1998 Label skip;
duke@435 1999 __ brx(Assembler::greaterEqual, false, Assembler::pt, skip);
duke@435 2000 __ delayed()->nop();
duke@435 2001 __ stop("killed stack");
duke@435 2002 __ bind(skip);
duke@435 2003 }
duke@435 2004 #endif // ASSERT
duke@435 2005
duke@435 2006 // Create a new frame where we can store values that make it look like the interpreter
duke@435 2007 // really recursed.
duke@435 2008
duke@435 2009 // prepare to recurse or call specialized entry
duke@435 2010
duke@435 2011 // First link the registers we need
duke@435 2012
duke@435 2013 // make the pc look good in debugger
duke@435 2014 __ set(CAST_FROM_FN_PTR(intptr_t, RecursiveInterpreterActivation), O7);
duke@435 2015 // argument too
duke@435 2016 __ mov(Lstate, I0);
duke@435 2017
duke@435 2018 // Record our sending SP
duke@435 2019 __ mov(SP, O5_savedSP);
duke@435 2020
duke@435 2021 __ ld_ptr(STATE(_result._to_call._callee_entry_point), L2_scratch);
duke@435 2022 __ set((intptr_t) entry_point, L1_scratch);
duke@435 2023 __ cmp(L1_scratch, L2_scratch);
duke@435 2024 __ brx(Assembler::equal, false, Assembler::pt, re_dispatch);
duke@435 2025 __ delayed()->mov(Lstate, prevState); // link activations
duke@435 2026
duke@435 2027 // method uses specialized entry, push a return so we look like call stub setup
duke@435 2028 // this path will handle fact that result is returned in registers and not
duke@435 2029 // on the java stack.
duke@435 2030
duke@435 2031 __ set((intptr_t)return_from_native_method - 8, O7);
duke@435 2032 __ jmpl(L2_scratch, G0, G0); // Do specialized entry
duke@435 2033 __ delayed()->nop();
duke@435 2034
duke@435 2035 //
duke@435 2036 // Bad Message from interpreter
duke@435 2037 //
duke@435 2038 __ bind(bad_msg);
duke@435 2039 __ stop("Bad message from interpreter");
duke@435 2040
duke@435 2041 // Interpreted method "returned" with an exception pass it on...
duke@435 2042 // Pass result, unwind activation and continue/return to interpreter/call_stub
duke@435 2043 // We handle result (if any) differently based on return to interpreter or call_stub
duke@435 2044
duke@435 2045 __ bind(throw_exception);
duke@435 2046 __ ld_ptr(STATE(_prev_link), L1_scratch);
duke@435 2047 __ tst(L1_scratch);
duke@435 2048 __ brx(Assembler::zero, false, Assembler::pt, unwind_and_forward);
duke@435 2049 __ delayed()->nop();
duke@435 2050
kvn@3037 2051 __ ld_ptr(STATE(_locals), O1); // get result of popping callee's args
kvn@3037 2052 __ ba(unwind_recursive_activation);
duke@435 2053 __ delayed()->nop();
duke@435 2054
duke@435 2055 interpreter_frame_manager = entry_point;
duke@435 2056 return entry_point;
duke@435 2057 }
duke@435 2058
duke@435 2059 InterpreterGenerator::InterpreterGenerator(StubQueue* code)
duke@435 2060 : CppInterpreterGenerator(code) {
duke@435 2061 generate_all(); // down here so it can be "virtual"
duke@435 2062 }
duke@435 2063
duke@435 2064
duke@435 2065 static int size_activation_helper(int callee_extra_locals, int max_stack, int monitor_size) {
duke@435 2066
duke@435 2067 // Figure out the size of an interpreter frame (in words) given that we have a fully allocated
duke@435 2068 // expression stack, the callee will have callee_extra_locals (so we can account for
duke@435 2069 // frame extension) and monitor_size for monitors. Basically we need to calculate
duke@435 2070 // this exactly like generate_fixed_frame/generate_compute_interpreter_state.
duke@435 2071 //
duke@435 2072 //
duke@435 2073 // The big complicating thing here is that we must ensure that the stack stays properly
duke@435 2074 // aligned. This would be even uglier if monitor size wasn't modulo what the stack
duke@435 2075 // needs to be aligned for). We are given that the sp (fp) is already aligned by
duke@435 2076 // the caller so we must ensure that it is properly aligned for our callee.
duke@435 2077 //
duke@435 2078 // Ths c++ interpreter always makes sure that we have a enough extra space on the
duke@435 2079 // stack at all times to deal with the "stack long no_params()" method issue. This
duke@435 2080 // is "slop_factor" here.
duke@435 2081 const int slop_factor = 2;
duke@435 2082
duke@435 2083 const int fixed_size = sizeof(BytecodeInterpreter)/wordSize + // interpreter state object
duke@435 2084 frame::memory_parameter_word_sp_offset; // register save area + param window
duke@435 2085 return (round_to(max_stack +
duke@435 2086 slop_factor +
duke@435 2087 fixed_size +
duke@435 2088 monitor_size +
coleenp@4037 2089 (callee_extra_locals * Interpreter::stackElementWords), WordsPerLong));
duke@435 2090
duke@435 2091 }
duke@435 2092
coleenp@4037 2093 int AbstractInterpreter::size_top_interpreter_activation(Method* method) {
duke@435 2094
duke@435 2095 // See call_stub code
duke@435 2096 int call_stub_size = round_to(7 + frame::memory_parameter_word_sp_offset,
duke@435 2097 WordsPerLong); // 7 + register save area
duke@435 2098
duke@435 2099 // Save space for one monitor to get into the interpreted method in case
duke@435 2100 // the method is synchronized
duke@435 2101 int monitor_size = method->is_synchronized() ?
duke@435 2102 1*frame::interpreter_frame_monitor_size() : 0;
duke@435 2103 return size_activation_helper(method->max_locals(), method->max_stack(),
duke@435 2104 monitor_size) + call_stub_size;
duke@435 2105 }
duke@435 2106
duke@435 2107 void BytecodeInterpreter::layout_interpreterState(interpreterState to_fill,
duke@435 2108 frame* caller,
duke@435 2109 frame* current,
coleenp@4037 2110 Method* method,
duke@435 2111 intptr_t* locals,
duke@435 2112 intptr_t* stack,
duke@435 2113 intptr_t* stack_base,
duke@435 2114 intptr_t* monitor_base,
duke@435 2115 intptr_t* frame_bottom,
duke@435 2116 bool is_top_frame
duke@435 2117 )
duke@435 2118 {
duke@435 2119 // What about any vtable?
duke@435 2120 //
duke@435 2121 to_fill->_thread = JavaThread::current();
duke@435 2122 // This gets filled in later but make it something recognizable for now
duke@435 2123 to_fill->_bcp = method->code_base();
duke@435 2124 to_fill->_locals = locals;
duke@435 2125 to_fill->_constants = method->constants()->cache();
duke@435 2126 to_fill->_method = method;
duke@435 2127 to_fill->_mdx = NULL;
duke@435 2128 to_fill->_stack = stack;
duke@435 2129 if (is_top_frame && JavaThread::current()->popframe_forcing_deopt_reexecution() ) {
duke@435 2130 to_fill->_msg = deopt_resume2;
duke@435 2131 } else {
duke@435 2132 to_fill->_msg = method_resume;
duke@435 2133 }
duke@435 2134 to_fill->_result._to_call._bcp_advance = 0;
duke@435 2135 to_fill->_result._to_call._callee_entry_point = NULL; // doesn't matter to anyone
duke@435 2136 to_fill->_result._to_call._callee = NULL; // doesn't matter to anyone
duke@435 2137 to_fill->_prev_link = NULL;
duke@435 2138
duke@435 2139 // Fill in the registers for the frame
duke@435 2140
duke@435 2141 // Need to install _sender_sp. Actually not too hard in C++!
duke@435 2142 // When the skeletal frames are layed out we fill in a value
duke@435 2143 // for _sender_sp. That value is only correct for the oldest
duke@435 2144 // skeletal frame constructed (because there is only a single
duke@435 2145 // entry for "caller_adjustment". While the skeletal frames
duke@435 2146 // exist that is good enough. We correct that calculation
duke@435 2147 // here and get all the frames correct.
duke@435 2148
duke@435 2149 // to_fill->_sender_sp = locals - (method->size_of_parameters() - 1);
duke@435 2150
duke@435 2151 *current->register_addr(Lstate) = (intptr_t) to_fill;
duke@435 2152 // skeletal already places a useful value here and this doesn't account
duke@435 2153 // for alignment so don't bother.
duke@435 2154 // *current->register_addr(I5_savedSP) = (intptr_t) locals - (method->size_of_parameters() - 1);
duke@435 2155
duke@435 2156 if (caller->is_interpreted_frame()) {
duke@435 2157 interpreterState prev = caller->get_interpreterState();
duke@435 2158 to_fill->_prev_link = prev;
duke@435 2159 // Make the prev callee look proper
duke@435 2160 prev->_result._to_call._callee = method;
duke@435 2161 if (*prev->_bcp == Bytecodes::_invokeinterface) {
duke@435 2162 prev->_result._to_call._bcp_advance = 5;
duke@435 2163 } else {
duke@435 2164 prev->_result._to_call._bcp_advance = 3;
duke@435 2165 }
duke@435 2166 }
duke@435 2167 to_fill->_oop_temp = NULL;
duke@435 2168 to_fill->_stack_base = stack_base;
duke@435 2169 // Need +1 here because stack_base points to the word just above the first expr stack entry
duke@435 2170 // and stack_limit is supposed to point to the word just below the last expr stack entry.
duke@435 2171 // See generate_compute_interpreter_state.
roland@5225 2172 to_fill->_stack_limit = stack_base - (method->max_stack() + 1);
duke@435 2173 to_fill->_monitor_base = (BasicObjectLock*) monitor_base;
duke@435 2174
duke@435 2175 // sparc specific
duke@435 2176 to_fill->_frame_bottom = frame_bottom;
duke@435 2177 to_fill->_self_link = to_fill;
duke@435 2178 #ifdef ASSERT
duke@435 2179 to_fill->_native_fresult = 123456.789;
duke@435 2180 to_fill->_native_lresult = CONST64(0xdeadcafedeafcafe);
duke@435 2181 #endif
duke@435 2182 }
duke@435 2183
duke@435 2184 void BytecodeInterpreter::pd_layout_interpreterState(interpreterState istate, address last_Java_pc, intptr_t* last_Java_fp) {
duke@435 2185 istate->_last_Java_pc = (intptr_t*) last_Java_pc;
duke@435 2186 }
duke@435 2187
duke@435 2188
coleenp@4037 2189 int AbstractInterpreter::layout_activation(Method* method,
duke@435 2190 int tempcount, // Number of slots on java expression stack in use
duke@435 2191 int popframe_extra_args,
duke@435 2192 int moncount, // Number of active monitors
never@2901 2193 int caller_actual_parameters,
duke@435 2194 int callee_param_size,
duke@435 2195 int callee_locals_size,
duke@435 2196 frame* caller,
duke@435 2197 frame* interpreter_frame,
roland@4727 2198 bool is_top_frame,
roland@4727 2199 bool is_bottom_frame) {
duke@435 2200
duke@435 2201 assert(popframe_extra_args == 0, "NEED TO FIX");
duke@435 2202 // NOTE this code must exactly mimic what InterpreterGenerator::generate_compute_interpreter_state()
duke@435 2203 // does as far as allocating an interpreter frame.
duke@435 2204 // If interpreter_frame!=NULL, set up the method, locals, and monitors.
duke@435 2205 // The frame interpreter_frame, if not NULL, is guaranteed to be the right size,
duke@435 2206 // as determined by a previous call to this method.
duke@435 2207 // It is also guaranteed to be walkable even though it is in a skeletal state
duke@435 2208 // NOTE: return size is in words not bytes
duke@435 2209 // NOTE: tempcount is the current size of the java expression stack. For top most
duke@435 2210 // frames we will allocate a full sized expression stack and not the curback
duke@435 2211 // version that non-top frames have.
duke@435 2212
duke@435 2213 // Calculate the amount our frame will be adjust by the callee. For top frame
duke@435 2214 // this is zero.
duke@435 2215
duke@435 2216 // NOTE: ia64 seems to do this wrong (or at least backwards) in that it
duke@435 2217 // calculates the extra locals based on itself. Not what the callee does
duke@435 2218 // to it. So it ignores last_frame_adjust value. Seems suspicious as far
duke@435 2219 // as getting sender_sp correct.
duke@435 2220
duke@435 2221 int extra_locals_size = callee_locals_size - callee_param_size;
duke@435 2222 int monitor_size = (sizeof(BasicObjectLock) * moncount) / wordSize;
duke@435 2223 int full_frame_words = size_activation_helper(extra_locals_size, method->max_stack(), monitor_size);
duke@435 2224 int short_frame_words = size_activation_helper(extra_locals_size, method->max_stack(), monitor_size);
duke@435 2225 int frame_words = is_top_frame ? full_frame_words : short_frame_words;
duke@435 2226
duke@435 2227
duke@435 2228 /*
duke@435 2229 if we actually have a frame to layout we must now fill in all the pieces. This means both
duke@435 2230 the interpreterState and the registers.
duke@435 2231 */
duke@435 2232 if (interpreter_frame != NULL) {
duke@435 2233
duke@435 2234 // MUCHO HACK
duke@435 2235
duke@435 2236 intptr_t* frame_bottom = interpreter_frame->sp() - (full_frame_words - frame_words);
sgoldman@558 2237 // 'interpreter_frame->sp()' is unbiased while 'frame_bottom' must be a biased value in 64bit mode.
sgoldman@558 2238 assert(((intptr_t)frame_bottom & 0xf) == 0, "SP biased in layout_activation");
sgoldman@558 2239 frame_bottom = (intptr_t*)((intptr_t)frame_bottom - STACK_BIAS);
duke@435 2240
duke@435 2241 /* Now fillin the interpreterState object */
duke@435 2242
duke@435 2243 interpreterState cur_state = (interpreterState) ((intptr_t)interpreter_frame->fp() - sizeof(BytecodeInterpreter));
duke@435 2244
duke@435 2245
duke@435 2246 intptr_t* locals;
duke@435 2247
duke@435 2248 // Calculate the postion of locals[0]. This is painful because of
duke@435 2249 // stack alignment (same as ia64). The problem is that we can
duke@435 2250 // not compute the location of locals from fp(). fp() will account
duke@435 2251 // for the extra locals but it also accounts for aligning the stack
duke@435 2252 // and we can't determine if the locals[0] was misaligned but max_locals
duke@435 2253 // was enough to have the
duke@435 2254 // calculate postion of locals. fp already accounts for extra locals.
duke@435 2255 // +2 for the static long no_params() issue.
duke@435 2256
duke@435 2257 if (caller->is_interpreted_frame()) {
duke@435 2258 // locals must agree with the caller because it will be used to set the
duke@435 2259 // caller's tos when we return.
duke@435 2260 interpreterState prev = caller->get_interpreterState();
duke@435 2261 // stack() is prepushed.
duke@435 2262 locals = prev->stack() + method->size_of_parameters();
duke@435 2263 } else {
duke@435 2264 // Lay out locals block in the caller adjacent to the register window save area.
duke@435 2265 //
duke@435 2266 // Compiled frames do not allocate a varargs area which is why this if
duke@435 2267 // statement is needed.
duke@435 2268 //
duke@435 2269 intptr_t* fp = interpreter_frame->fp();
coleenp@4037 2270 int local_words = method->max_locals() * Interpreter::stackElementWords;
duke@435 2271
duke@435 2272 if (caller->is_compiled_frame()) {
duke@435 2273 locals = fp + frame::register_save_words + local_words - 1;
duke@435 2274 } else {
duke@435 2275 locals = fp + frame::memory_parameter_word_sp_offset + local_words - 1;
duke@435 2276 }
duke@435 2277
duke@435 2278 }
duke@435 2279 // END MUCHO HACK
duke@435 2280
duke@435 2281 intptr_t* monitor_base = (intptr_t*) cur_state;
duke@435 2282 intptr_t* stack_base = monitor_base - monitor_size;
duke@435 2283 /* +1 because stack is always prepushed */
duke@435 2284 intptr_t* stack = stack_base - (tempcount + 1);
duke@435 2285
duke@435 2286
duke@435 2287 BytecodeInterpreter::layout_interpreterState(cur_state,
duke@435 2288 caller,
duke@435 2289 interpreter_frame,
duke@435 2290 method,
duke@435 2291 locals,
duke@435 2292 stack,
duke@435 2293 stack_base,
duke@435 2294 monitor_base,
duke@435 2295 frame_bottom,
duke@435 2296 is_top_frame);
duke@435 2297
duke@435 2298 BytecodeInterpreter::pd_layout_interpreterState(cur_state, interpreter_return_address, interpreter_frame->fp());
duke@435 2299
duke@435 2300 }
duke@435 2301 return frame_words;
duke@435 2302 }
duke@435 2303
duke@435 2304 #endif // CC_INTERP

mercurial