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