1 /* 2 * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "precompiled.hpp" 26 #include "asm/assembler.hpp" 27 #include "interpreter/bytecodeHistogram.hpp" 28 #include "interpreter/interp_masm.hpp" 29 #include "interpreter/interpreter.hpp" 30 #include "interpreter/interpreterRuntime.hpp" 31 #include "interpreter/templateInterpreterGenerator.hpp" 32 #include "interpreter/templateTable.hpp" 33 #include "oops/arrayOop.hpp" 34 #include "oops/methodData.hpp" 35 #include "oops/method.hpp" 36 #include "oops/oop.inline.hpp" 37 #include "prims/jvmtiExport.hpp" 38 #include "prims/jvmtiThreadState.hpp" 39 #include "prims/methodHandles.hpp" 40 #include "runtime/arguments.hpp" 41 #include "runtime/deoptimization.hpp" 42 #include "runtime/frame.inline.hpp" 43 #include "runtime/sharedRuntime.hpp" 44 #include "runtime/stubRoutines.hpp" 45 #include "runtime/synchronizer.hpp" 46 #include "runtime/timer.hpp" 47 #include "runtime/vframeArray.hpp" 48 #include "utilities/align.hpp" 49 #include "utilities/debug.hpp" 50 #include "utilities/macros.hpp" 51 52 // Size of interpreter code. Increase if too small. Interpreter will 53 // fail with a guarantee ("not enough space for interpreter generation"); 54 // if too small. 55 // Run with +PrintInterpreter to get the VM to print out the size. 56 // Max size with JVMTI 57 int TemplateInterpreter::InterpreterCodeSize = 180 * 1024; 58 59 #define __ _masm-> 60 61 //------------------------------------------------------------------------------------------------------------------------ 62 63 address TemplateInterpreterGenerator::generate_slow_signature_handler() { 64 address entry = __ pc(); 65 66 // callee-save register for saving LR, shared with generate_native_entry 67 const Register Rsaved_ret_addr = AARCH64_ONLY(R21) NOT_AARCH64(Rtmp_save0); 68 69 __ mov(Rsaved_ret_addr, LR); 70 71 __ mov(R1, Rmethod); 72 __ mov(R2, Rlocals); 73 __ mov(R3, SP); 74 75 #ifdef AARCH64 76 // expand expr. stack and extended SP to avoid cutting SP in call_VM 77 __ mov(Rstack_top, SP); 78 __ str(Rstack_top, Address(FP, frame::interpreter_frame_extended_sp_offset * wordSize)); 79 __ check_stack_top(); 80 81 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::slow_signature_handler), R1, R2, R3, false); 82 83 __ ldp(ZR, c_rarg1, Address(SP, 2*wordSize, post_indexed)); 84 __ ldp(c_rarg2, c_rarg3, Address(SP, 2*wordSize, post_indexed)); 85 __ ldp(c_rarg4, c_rarg5, Address(SP, 2*wordSize, post_indexed)); 86 __ ldp(c_rarg6, c_rarg7, Address(SP, 2*wordSize, post_indexed)); 87 88 __ ldp_d(V0, V1, Address(SP, 2*wordSize, post_indexed)); 89 __ ldp_d(V2, V3, Address(SP, 2*wordSize, post_indexed)); 90 __ ldp_d(V4, V5, Address(SP, 2*wordSize, post_indexed)); 91 __ ldp_d(V6, V7, Address(SP, 2*wordSize, post_indexed)); 92 #else 93 94 // Safer to save R9 (when scratched) since callers may have been 95 // written assuming R9 survives. This is suboptimal but 96 // probably not important for this slow case call site. 97 // Note for R9 saving: slow_signature_handler may copy register 98 // arguments above the current SP (passed as R3). It is safe for 99 // call_VM to use push and pop to protect additional values on the 100 // stack if needed. 101 __ call_VM(CAST_FROM_FN_PTR(address, InterpreterRuntime::slow_signature_handler), true /* save R9 if needed*/); 102 __ add(SP, SP, wordSize); // Skip R0 103 __ pop(RegisterSet(R1, R3)); // Load arguments passed in registers 104 #ifdef __ABI_HARD__ 105 // Few alternatives to an always-load-FP-registers approach: 106 // - parse method signature to detect FP arguments 107 // - keep a counter/flag on a stack indicationg number of FP arguments in the method. 108 // The later has been originally implemented and tested but a conditional path could 109 // eliminate any gain imposed by avoiding 8 double word loads. 110 __ fldmiad(SP, FloatRegisterSet(D0, 8), writeback); 111 #endif // __ABI_HARD__ 112 #endif // AARCH64 113 114 __ ret(Rsaved_ret_addr); 115 116 return entry; 117 } 118 119 120 // 121 // Various method entries (that c++ and asm interpreter agree upon) 122 //------------------------------------------------------------------------------------------------------------------------ 123 // 124 // 125 126 // Abstract method entry 127 // Attempt to execute abstract method. Throw exception 128 address TemplateInterpreterGenerator::generate_abstract_entry(void) { 129 address entry_point = __ pc(); 130 131 #ifdef AARCH64 132 __ restore_sp_after_call(Rtemp); 133 __ restore_stack_top(); 134 #endif 135 136 __ empty_expression_stack(); 137 138 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_AbstractMethodError)); 139 140 DEBUG_ONLY(STOP("generate_abstract_entry");) // Should not reach here 141 return entry_point; 142 } 143 144 address TemplateInterpreterGenerator::generate_math_entry(AbstractInterpreter::MethodKind kind) { 145 if (!InlineIntrinsics) return NULL; // Generate a vanilla entry 146 147 // TODO: ARM 148 return NULL; 149 150 address entry_point = __ pc(); 151 STOP("generate_math_entry"); 152 return entry_point; 153 } 154 155 address TemplateInterpreterGenerator::generate_StackOverflowError_handler() { 156 address entry = __ pc(); 157 158 // Note: There should be a minimal interpreter frame set up when stack 159 // overflow occurs since we check explicitly for it now. 160 // 161 #ifdef ASSERT 162 { Label L; 163 __ sub(Rtemp, FP, - frame::interpreter_frame_monitor_block_top_offset * wordSize); 164 __ cmp(SP, Rtemp); // Rtemp = maximal SP for current FP, 165 // (stack grows negative) 166 __ b(L, ls); // check if frame is complete 167 __ stop ("interpreter frame not set up"); 168 __ bind(L); 169 } 170 #endif // ASSERT 171 172 // Restore bcp under the assumption that the current frame is still 173 // interpreted 174 __ restore_bcp(); 175 176 // expression stack must be empty before entering the VM if an exception 177 // happened 178 __ empty_expression_stack(); 179 180 // throw exception 181 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_StackOverflowError)); 182 183 __ should_not_reach_here(); 184 185 return entry; 186 } 187 188 address TemplateInterpreterGenerator::generate_ArrayIndexOutOfBounds_handler() { 189 address entry = __ pc(); 190 191 // index is in R4_ArrayIndexOutOfBounds_index 192 193 // expression stack must be empty before entering the VM if an exception happened 194 __ empty_expression_stack(); 195 196 // setup parameters 197 // Array expected in R1. 198 __ mov(R2, R4_ArrayIndexOutOfBounds_index); 199 200 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_ArrayIndexOutOfBoundsException), R1, R2); 201 202 __ nop(); // to avoid filling CPU pipeline with invalid instructions 203 __ nop(); 204 __ should_not_reach_here(); 205 206 return entry; 207 } 208 209 address TemplateInterpreterGenerator::generate_ClassCastException_handler() { 210 address entry = __ pc(); 211 212 // object is in R2_ClassCastException_obj 213 214 // expression stack must be empty before entering the VM if an exception 215 // happened 216 __ empty_expression_stack(); 217 218 __ mov(R1, R2_ClassCastException_obj); 219 __ call_VM(noreg, 220 CAST_FROM_FN_PTR(address, 221 InterpreterRuntime::throw_ClassCastException), 222 R1); 223 224 __ should_not_reach_here(); 225 226 return entry; 227 } 228 229 address TemplateInterpreterGenerator::generate_exception_handler_common(const char* name, const char* message, bool pass_oop) { 230 assert(!pass_oop || message == NULL, "either oop or message but not both"); 231 address entry = __ pc(); 232 233 InlinedString Lname(name); 234 InlinedString Lmessage(message); 235 236 if (pass_oop) { 237 // object is at TOS 238 __ pop_ptr(R2); 239 } 240 241 // expression stack must be empty before entering the VM if an exception happened 242 __ empty_expression_stack(); 243 244 // setup parameters 245 __ ldr_literal(R1, Lname); 246 247 if (pass_oop) { 248 __ call_VM(Rexception_obj, CAST_FROM_FN_PTR(address, InterpreterRuntime::create_klass_exception), R1, R2); 249 } else { 250 if (message != NULL) { 251 __ ldr_literal(R2, Lmessage); 252 } else { 253 __ mov(R2, 0); 254 } 255 __ call_VM(Rexception_obj, CAST_FROM_FN_PTR(address, InterpreterRuntime::create_exception), R1, R2); 256 } 257 258 // throw exception 259 __ b(Interpreter::throw_exception_entry()); 260 261 __ nop(); // to avoid filling CPU pipeline with invalid instructions 262 __ nop(); 263 __ bind_literal(Lname); 264 if (!pass_oop && (message != NULL)) { 265 __ bind_literal(Lmessage); 266 } 267 268 return entry; 269 } 270 271 address TemplateInterpreterGenerator::generate_return_entry_for(TosState state, int step, size_t index_size) { 272 address entry = __ pc(); 273 274 __ interp_verify_oop(R0_tos, state, __FILE__, __LINE__); 275 276 #ifdef AARCH64 277 __ restore_sp_after_call(Rtemp); // Restore SP to extended SP 278 __ restore_stack_top(); 279 #else 280 // Restore stack bottom in case i2c adjusted stack 281 __ ldr(SP, Address(FP, frame::interpreter_frame_last_sp_offset * wordSize)); 282 // and NULL it as marker that SP is now tos until next java call 283 __ mov(Rtemp, (int)NULL_WORD); 284 __ str(Rtemp, Address(FP, frame::interpreter_frame_last_sp_offset * wordSize)); 285 #endif // AARCH64 286 287 __ restore_method(); 288 __ restore_bcp(); 289 __ restore_dispatch(); 290 __ restore_locals(); 291 292 const Register Rcache = R2_tmp; 293 const Register Rindex = R3_tmp; 294 __ get_cache_and_index_at_bcp(Rcache, Rindex, 1, index_size); 295 296 __ add(Rtemp, Rcache, AsmOperand(Rindex, lsl, LogBytesPerWord)); 297 __ ldrb(Rtemp, Address(Rtemp, ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::flags_offset())); 298 __ check_stack_top(); 299 __ add(Rstack_top, Rstack_top, AsmOperand(Rtemp, lsl, Interpreter::logStackElementSize)); 300 301 #ifndef AARCH64 302 __ convert_retval_to_tos(state); 303 #endif // !AARCH64 304 305 __ check_and_handle_popframe(); 306 __ check_and_handle_earlyret(); 307 308 __ dispatch_next(state, step); 309 310 return entry; 311 } 312 313 314 address TemplateInterpreterGenerator::generate_deopt_entry_for(TosState state, int step, address continuation) { 315 address entry = __ pc(); 316 317 __ interp_verify_oop(R0_tos, state, __FILE__, __LINE__); 318 319 #ifdef AARCH64 320 __ restore_sp_after_call(Rtemp); // Restore SP to extended SP 321 __ restore_stack_top(); 322 #else 323 // The stack is not extended by deopt but we must NULL last_sp as this 324 // entry is like a "return". 325 __ mov(Rtemp, 0); 326 __ str(Rtemp, Address(FP, frame::interpreter_frame_last_sp_offset * wordSize)); 327 #endif // AARCH64 328 329 __ restore_method(); 330 __ restore_bcp(); 331 __ restore_dispatch(); 332 __ restore_locals(); 333 334 // handle exceptions 335 { Label L; 336 __ ldr(Rtemp, Address(Rthread, Thread::pending_exception_offset())); 337 __ cbz(Rtemp, L); 338 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_pending_exception)); 339 __ should_not_reach_here(); 340 __ bind(L); 341 } 342 343 if (continuation == NULL) { 344 __ dispatch_next(state, step); 345 } else { 346 __ jump_to_entry(continuation); 347 } 348 349 return entry; 350 } 351 352 address TemplateInterpreterGenerator::generate_result_handler_for(BasicType type) { 353 #ifdef AARCH64 354 address entry = __ pc(); 355 switch (type) { 356 case T_BOOLEAN: 357 __ tst(R0, 0xff); 358 __ cset(R0, ne); 359 break; 360 case T_CHAR : __ zero_extend(R0, R0, 16); break; 361 case T_BYTE : __ sign_extend(R0, R0, 8); break; 362 case T_SHORT : __ sign_extend(R0, R0, 16); break; 363 case T_INT : // fall through 364 case T_LONG : // fall through 365 case T_VOID : // fall through 366 case T_FLOAT : // fall through 367 case T_DOUBLE : /* nothing to do */ break; 368 case T_OBJECT : 369 // retrieve result from frame 370 __ ldr(R0, Address(FP, frame::interpreter_frame_oop_temp_offset * wordSize)); 371 // and verify it 372 __ verify_oop(R0); 373 break; 374 default : ShouldNotReachHere(); 375 } 376 __ ret(); 377 return entry; 378 #else 379 // Result handlers are not used on 32-bit ARM 380 // since the returned value is already in appropriate format. 381 __ should_not_reach_here(); // to avoid empty code block 382 383 // The result handler non-zero indicates an object is returned and this is 384 // used in the native entry code. 385 return type == T_OBJECT ? (address)(-1) : NULL; 386 #endif // AARCH64 387 } 388 389 address TemplateInterpreterGenerator::generate_safept_entry_for(TosState state, address runtime_entry) { 390 address entry = __ pc(); 391 __ push(state); 392 __ call_VM(noreg, runtime_entry); 393 394 // load current bytecode 395 __ ldrb(R3_bytecode, Address(Rbcp)); 396 __ dispatch_only_normal(vtos); 397 return entry; 398 } 399 400 401 // Helpers for commoning out cases in the various type of method entries. 402 // 403 404 // increment invocation count & check for overflow 405 // 406 // Note: checking for negative value instead of overflow 407 // so we have a 'sticky' overflow test 408 // 409 // In: Rmethod. 410 // 411 // Uses R0, R1, Rtemp. 412 // 413 void TemplateInterpreterGenerator::generate_counter_incr(Label* overflow, 414 Label* profile_method, 415 Label* profile_method_continue) { 416 Label done; 417 const Register Rcounters = Rtemp; 418 const Address invocation_counter(Rcounters, 419 MethodCounters::invocation_counter_offset() + 420 InvocationCounter::counter_offset()); 421 422 // Note: In tiered we increment either counters in MethodCounters* or 423 // in MDO depending if we're profiling or not. 424 if (TieredCompilation) { 425 int increment = InvocationCounter::count_increment; 426 Label no_mdo; 427 if (ProfileInterpreter) { 428 // Are we profiling? 429 __ ldr(R1_tmp, Address(Rmethod, Method::method_data_offset())); 430 __ cbz(R1_tmp, no_mdo); 431 // Increment counter in the MDO 432 const Address mdo_invocation_counter(R1_tmp, 433 in_bytes(MethodData::invocation_counter_offset()) + 434 in_bytes(InvocationCounter::counter_offset())); 435 const Address mask(R1_tmp, in_bytes(MethodData::invoke_mask_offset())); 436 __ increment_mask_and_jump(mdo_invocation_counter, increment, mask, R0_tmp, Rtemp, eq, overflow); 437 __ b(done); 438 } 439 __ bind(no_mdo); 440 __ get_method_counters(Rmethod, Rcounters, done); 441 const Address mask(Rcounters, in_bytes(MethodCounters::invoke_mask_offset())); 442 __ increment_mask_and_jump(invocation_counter, increment, mask, R0_tmp, R1_tmp, eq, overflow); 443 __ bind(done); 444 } else { // not TieredCompilation 445 const Address backedge_counter(Rcounters, 446 MethodCounters::backedge_counter_offset() + 447 InvocationCounter::counter_offset()); 448 449 const Register Ricnt = R0_tmp; // invocation counter 450 const Register Rbcnt = R1_tmp; // backedge counter 451 452 __ get_method_counters(Rmethod, Rcounters, done); 453 454 if (ProfileInterpreter) { 455 const Register Riic = R1_tmp; 456 __ ldr_s32(Riic, Address(Rcounters, MethodCounters::interpreter_invocation_counter_offset())); 457 __ add(Riic, Riic, 1); 458 __ str_32(Riic, Address(Rcounters, MethodCounters::interpreter_invocation_counter_offset())); 459 } 460 461 // Update standard invocation counters 462 463 __ ldr_u32(Ricnt, invocation_counter); 464 __ ldr_u32(Rbcnt, backedge_counter); 465 466 __ add(Ricnt, Ricnt, InvocationCounter::count_increment); 467 468 #ifdef AARCH64 469 __ andr(Rbcnt, Rbcnt, (unsigned int)InvocationCounter::count_mask_value); // mask out the status bits 470 #else 471 __ bic(Rbcnt, Rbcnt, ~InvocationCounter::count_mask_value); // mask out the status bits 472 #endif // AARCH64 473 474 __ str_32(Ricnt, invocation_counter); // save invocation count 475 __ add(Ricnt, Ricnt, Rbcnt); // add both counters 476 477 // profile_method is non-null only for interpreted method so 478 // profile_method != NULL == !native_call 479 // BytecodeInterpreter only calls for native so code is elided. 480 481 if (ProfileInterpreter && profile_method != NULL) { 482 assert(profile_method_continue != NULL, "should be non-null"); 483 484 // Test to see if we should create a method data oop 485 // Reuse R1_tmp as we don't need backedge counters anymore. 486 Address profile_limit(Rcounters, in_bytes(MethodCounters::interpreter_profile_limit_offset())); 487 __ ldr_s32(R1_tmp, profile_limit); 488 __ cmp_32(Ricnt, R1_tmp); 489 __ b(*profile_method_continue, lt); 490 491 // if no method data exists, go to profile_method 492 __ test_method_data_pointer(R1_tmp, *profile_method); 493 } 494 495 Address invoke_limit(Rcounters, in_bytes(MethodCounters::interpreter_invocation_limit_offset())); 496 __ ldr_s32(R1_tmp, invoke_limit); 497 __ cmp_32(Ricnt, R1_tmp); 498 __ b(*overflow, hs); 499 __ bind(done); 500 } 501 } 502 503 void TemplateInterpreterGenerator::generate_counter_overflow(Label& do_continue) { 504 // InterpreterRuntime::frequency_counter_overflow takes one argument 505 // indicating if the counter overflow occurs at a backwards branch (non-NULL bcp). 506 // The call returns the address of the verified entry point for the method or NULL 507 // if the compilation did not complete (either went background or bailed out). 508 __ mov(R1, (int)false); 509 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::frequency_counter_overflow), R1); 510 511 // jump to the interpreted entry. 512 __ b(do_continue); 513 } 514 515 void TemplateInterpreterGenerator::generate_stack_overflow_check(void) { 516 // Check if we've got enough room on the stack for 517 // - overhead; 518 // - locals; 519 // - expression stack. 520 // 521 // Registers on entry: 522 // 523 // R3 = number of additional locals 524 // R11 = max expression stack slots (AArch64 only) 525 // Rthread 526 // Rmethod 527 // Registers used: R0, R1, R2, Rtemp. 528 529 const Register Radditional_locals = R3; 530 const Register RmaxStack = AARCH64_ONLY(R11) NOT_AARCH64(R2); 531 532 // monitor entry size 533 const int entry_size = frame::interpreter_frame_monitor_size() * wordSize; 534 535 // total overhead size: entry_size + (saved registers, thru expr stack bottom). 536 // be sure to change this if you add/subtract anything to/from the overhead area 537 const int overhead_size = (frame::sender_sp_offset - frame::interpreter_frame_initial_sp_offset)*wordSize + entry_size; 538 539 // Pages reserved for VM runtime calls and subsequent Java calls. 540 const int reserved_pages = JavaThread::stack_shadow_zone_size(); 541 542 // Thread::stack_size() includes guard pages, and they should not be touched. 543 const int guard_pages = JavaThread::stack_guard_zone_size(); 544 545 __ ldr(R0, Address(Rthread, Thread::stack_base_offset())); 546 __ ldr(R1, Address(Rthread, Thread::stack_size_offset())); 547 #ifndef AARCH64 548 __ ldr(Rtemp, Address(Rmethod, Method::const_offset())); 549 __ ldrh(RmaxStack, Address(Rtemp, ConstMethod::max_stack_offset())); 550 #endif // !AARCH64 551 __ sub_slow(Rtemp, SP, overhead_size + reserved_pages + guard_pages + Method::extra_stack_words()); 552 553 // reserve space for additional locals 554 __ sub(Rtemp, Rtemp, AsmOperand(Radditional_locals, lsl, Interpreter::logStackElementSize)); 555 556 // stack size 557 __ sub(R0, R0, R1); 558 559 // reserve space for expression stack 560 __ sub(Rtemp, Rtemp, AsmOperand(RmaxStack, lsl, Interpreter::logStackElementSize)); 561 562 __ cmp(Rtemp, R0); 563 564 #ifdef AARCH64 565 Label L; 566 __ b(L, hi); 567 __ mov(SP, Rsender_sp); // restore SP 568 __ b(StubRoutines::throw_StackOverflowError_entry()); 569 __ bind(L); 570 #else 571 __ mov(SP, Rsender_sp, ls); // restore SP 572 __ b(StubRoutines::throw_StackOverflowError_entry(), ls); 573 #endif // AARCH64 574 } 575 576 577 // Allocate monitor and lock method (asm interpreter) 578 // 579 void TemplateInterpreterGenerator::lock_method() { 580 // synchronize method 581 582 const int entry_size = frame::interpreter_frame_monitor_size() * wordSize; 583 assert ((entry_size % StackAlignmentInBytes) == 0, "should keep stack alignment"); 584 585 #ifdef ASSERT 586 { Label L; 587 __ ldr_u32(Rtemp, Address(Rmethod, Method::access_flags_offset())); 588 __ tbnz(Rtemp, JVM_ACC_SYNCHRONIZED_BIT, L); 589 __ stop("method doesn't need synchronization"); 590 __ bind(L); 591 } 592 #endif // ASSERT 593 594 // get synchronization object 595 { Label done; 596 __ ldr_u32(Rtemp, Address(Rmethod, Method::access_flags_offset())); 597 #ifdef AARCH64 598 __ ldr(R0, Address(Rlocals, Interpreter::local_offset_in_bytes(0))); // get receiver (assume this is frequent case) 599 __ tbz(Rtemp, JVM_ACC_STATIC_BIT, done); 600 #else 601 __ tst(Rtemp, JVM_ACC_STATIC); 602 __ ldr(R0, Address(Rlocals, Interpreter::local_offset_in_bytes(0)), eq); // get receiver (assume this is frequent case) 603 __ b(done, eq); 604 #endif // AARCH64 605 __ load_mirror(R0, Rmethod, Rtemp); 606 __ bind(done); 607 } 608 609 // add space for monitor & lock 610 611 #ifdef AARCH64 612 __ check_extended_sp(Rtemp); 613 __ sub(SP, SP, entry_size); // adjust extended SP 614 __ mov(Rtemp, SP); 615 __ str(Rtemp, Address(FP, frame::interpreter_frame_extended_sp_offset * wordSize)); 616 #endif // AARCH64 617 618 __ sub(Rstack_top, Rstack_top, entry_size); 619 __ check_stack_top_on_expansion(); 620 // add space for a monitor entry 621 __ str(Rstack_top, Address(FP, frame::interpreter_frame_monitor_block_top_offset * wordSize)); 622 // set new monitor block top 623 __ str(R0, Address(Rstack_top, BasicObjectLock::obj_offset_in_bytes())); 624 // store object 625 __ mov(R1, Rstack_top); // monitor entry address 626 __ lock_object(R1); 627 } 628 629 #ifdef AARCH64 630 631 // 632 // Generate a fixed interpreter frame. This is identical setup for interpreted methods 633 // and for native methods hence the shared code. 634 // 635 // On entry: 636 // R10 = ConstMethod 637 // R11 = max expr. stack (in slots), if !native_call 638 // 639 // On exit: 640 // Rbcp, Rstack_top are initialized, SP is extended 641 // 642 void TemplateInterpreterGenerator::generate_fixed_frame(bool native_call) { 643 // Incoming registers 644 const Register RconstMethod = R10; 645 const Register RmaxStack = R11; 646 // Temporary registers 647 const Register RextendedSP = R0; 648 const Register Rcache = R1; 649 const Register Rmdp = ProfileInterpreter ? R2 : ZR; 650 651 // Generates the following stack layout (stack grows up in this picture): 652 // 653 // [ expr. stack bottom ] 654 // [ saved Rbcp ] 655 // [ current Rlocals ] 656 // [ cache ] 657 // [ mdx ] 658 // [ mirror ] 659 // [ Method* ] 660 // [ extended SP ] 661 // [ expr. stack top ] 662 // [ sender_sp ] 663 // [ saved FP ] <--- FP 664 // [ saved LR ] 665 666 // initialize fixed part of activation frame 667 __ stp(FP, LR, Address(SP, -2*wordSize, pre_indexed)); 668 __ mov(FP, SP); // establish new FP 669 670 // setup Rbcp 671 if (native_call) { 672 __ mov(Rbcp, ZR); // bcp = 0 for native calls 673 } else { 674 __ add(Rbcp, RconstMethod, in_bytes(ConstMethod::codes_offset())); // get codebase 675 } 676 677 // Rstack_top & RextendedSP 678 __ sub(Rstack_top, SP, 10*wordSize); 679 if (native_call) { 680 __ sub(RextendedSP, Rstack_top, align_up(wordSize, StackAlignmentInBytes)); // reserve 1 slot for exception handling 681 } else { 682 __ sub(RextendedSP, Rstack_top, AsmOperand(RmaxStack, lsl, Interpreter::logStackElementSize)); 683 __ align_reg(RextendedSP, RextendedSP, StackAlignmentInBytes); 684 } 685 __ mov(SP, RextendedSP); 686 __ check_stack_top(); 687 688 // Load Rmdp 689 if (ProfileInterpreter) { 690 __ ldr(Rtemp, Address(Rmethod, Method::method_data_offset())); 691 __ tst(Rtemp, Rtemp); 692 __ add(Rtemp, Rtemp, in_bytes(MethodData::data_offset())); 693 __ csel(Rmdp, ZR, Rtemp, eq); 694 } 695 696 // Load Rcache 697 __ ldr(Rtemp, Address(RconstMethod, ConstMethod::constants_offset())); 698 __ ldr(Rcache, Address(Rtemp, ConstantPool::cache_offset_in_bytes())); 699 // Get mirror and store it in the frame as GC root for this Method* 700 __ load_mirror(Rtemp, Rmethod, Rtemp); 701 702 // Build fixed frame 703 __ stp(Rstack_top, Rbcp, Address(FP, -10*wordSize)); 704 __ stp(Rlocals, Rcache, Address(FP, -8*wordSize)); 705 __ stp(Rmdp, Rtemp, Address(FP, -6*wordSize)); 706 __ stp(Rmethod, RextendedSP, Address(FP, -4*wordSize)); 707 __ stp(ZR, Rsender_sp, Address(FP, -2*wordSize)); 708 assert(frame::interpreter_frame_initial_sp_offset == -10, "interpreter frame broken"); 709 assert(frame::interpreter_frame_stack_top_offset == -2, "stack top broken"); 710 } 711 712 #else // AARCH64 713 714 // 715 // Generate a fixed interpreter frame. This is identical setup for interpreted methods 716 // and for native methods hence the shared code. 717 718 void TemplateInterpreterGenerator::generate_fixed_frame(bool native_call) { 719 // Generates the following stack layout: 720 // 721 // [ expr. stack bottom ] 722 // [ saved Rbcp ] 723 // [ current Rlocals ] 724 // [ cache ] 725 // [ mdx ] 726 // [ Method* ] 727 // [ last_sp ] 728 // [ sender_sp ] 729 // [ saved FP ] <--- FP 730 // [ saved LR ] 731 732 // initialize fixed part of activation frame 733 __ push(LR); // save return address 734 __ push(FP); // save FP 735 __ mov(FP, SP); // establish new FP 736 737 __ push(Rsender_sp); 738 739 __ mov(R0, 0); 740 __ push(R0); // leave last_sp as null 741 742 // setup Rbcp 743 if (native_call) { 744 __ mov(Rbcp, 0); // bcp = 0 for native calls 745 } else { 746 __ ldr(Rtemp, Address(Rmethod, Method::const_offset())); // get ConstMethod* 747 __ add(Rbcp, Rtemp, ConstMethod::codes_offset()); // get codebase 748 } 749 750 __ push(Rmethod); // save Method* 751 // Get mirror and store it in the frame as GC root for this Method* 752 __ load_mirror(Rtemp, Rmethod, Rtemp); 753 __ push(Rtemp); 754 755 if (ProfileInterpreter) { 756 __ ldr(Rtemp, Address(Rmethod, Method::method_data_offset())); 757 __ tst(Rtemp, Rtemp); 758 __ add(Rtemp, Rtemp, in_bytes(MethodData::data_offset()), ne); 759 __ push(Rtemp); // set the mdp (method data pointer) 760 } else { 761 __ push(R0); 762 } 763 764 __ ldr(Rtemp, Address(Rmethod, Method::const_offset())); 765 __ ldr(Rtemp, Address(Rtemp, ConstMethod::constants_offset())); 766 __ ldr(Rtemp, Address(Rtemp, ConstantPool::cache_offset_in_bytes())); 767 __ push(Rtemp); // set constant pool cache 768 __ push(Rlocals); // set locals pointer 769 __ push(Rbcp); // set bcp 770 __ push(R0); // reserve word for pointer to expression stack bottom 771 __ str(SP, Address(SP, 0)); // set expression stack bottom 772 } 773 774 #endif // AARCH64 775 776 // End of helpers 777 778 //------------------------------------------------------------------------------------------------------------------------ 779 // Entry points 780 // 781 // Here we generate the various kind of entries into the interpreter. 782 // The two main entry type are generic bytecode methods and native call method. 783 // These both come in synchronized and non-synchronized versions but the 784 // frame layout they create is very similar. The other method entry 785 // types are really just special purpose entries that are really entry 786 // and interpretation all in one. These are for trivial methods like 787 // accessor, empty, or special math methods. 788 // 789 // When control flow reaches any of the entry types for the interpreter 790 // the following holds -> 791 // 792 // Arguments: 793 // 794 // Rmethod: Method* 795 // Rthread: thread 796 // Rsender_sp: sender sp 797 // Rparams (SP on 32-bit ARM): pointer to method parameters 798 // 799 // LR: return address 800 // 801 // Stack layout immediately at entry 802 // 803 // [ optional padding(*)] <--- SP (AArch64) 804 // [ parameter n ] <--- Rparams (SP on 32-bit ARM) 805 // ... 806 // [ parameter 1 ] 807 // [ expression stack ] (caller's java expression stack) 808 809 // Assuming that we don't go to one of the trivial specialized 810 // entries the stack will look like below when we are ready to execute 811 // the first bytecode (or call the native routine). The register usage 812 // will be as the template based interpreter expects. 813 // 814 // local variables follow incoming parameters immediately; i.e. 815 // the return address is saved at the end of the locals. 816 // 817 // [ reserved stack (*) ] <--- SP (AArch64) 818 // [ expr. stack ] <--- Rstack_top (SP on 32-bit ARM) 819 // [ monitor entry ] 820 // ... 821 // [ monitor entry ] 822 // [ expr. stack bottom ] 823 // [ saved Rbcp ] 824 // [ current Rlocals ] 825 // [ cache ] 826 // [ mdx ] 827 // [ mirror ] 828 // [ Method* ] 829 // 830 // 32-bit ARM: 831 // [ last_sp ] 832 // 833 // AArch64: 834 // [ extended SP (*) ] 835 // [ stack top (*) ] 836 // 837 // [ sender_sp ] 838 // [ saved FP ] <--- FP 839 // [ saved LR ] 840 // [ optional padding(*)] 841 // [ local variable m ] 842 // ... 843 // [ local variable 1 ] 844 // [ parameter n ] 845 // ... 846 // [ parameter 1 ] <--- Rlocals 847 // 848 // (*) - AArch64 only 849 // 850 851 address TemplateInterpreterGenerator::generate_Reference_get_entry(void) { 852 // Code: _aload_0, _getfield, _areturn 853 // parameter size = 1 854 // 855 // The code that gets generated by this routine is split into 2 parts: 856 // 1. The "intrinsified" code performing an ON_WEAK_OOP_REF load, 857 // 2. The slow path - which is an expansion of the regular method entry. 858 // 859 // Notes:- 860 // * An intrinsic is always executed, where an ON_WEAK_OOP_REF load is performed. 861 // * We may jump to the slow path iff the receiver is null. If the 862 // Reference object is null then we no longer perform an ON_WEAK_OOP_REF load 863 // Thus we can use the regular method entry code to generate the NPE. 864 // 865 // Rmethod: Method* 866 // Rthread: thread 867 // Rsender_sp: sender sp, must be preserved for slow path, set SP to it on fast path 868 // Rparams: parameters 869 870 address entry = __ pc(); 871 Label slow_path; 872 const Register Rthis = R0; 873 const Register Rret_addr = Rtmp_save1; 874 assert_different_registers(Rthis, Rret_addr, Rsender_sp); 875 876 const int referent_offset = java_lang_ref_Reference::referent_offset; 877 guarantee(referent_offset > 0, "referent offset not initialized"); 878 879 // Check if local 0 != NULL 880 // If the receiver is null then it is OK to jump to the slow path. 881 __ ldr(Rthis, Address(Rparams)); 882 __ cbz(Rthis, slow_path); 883 884 // Preserve LR 885 __ mov(Rret_addr, LR); 886 887 // Load the value of the referent field. 888 const Address field_address(Rthis, referent_offset); 889 __ load_heap_oop(R0, field_address, Rtemp, R1_tmp, R2_tmp, ON_WEAK_OOP_REF); 890 891 // _areturn 892 __ mov(SP, Rsender_sp); 893 __ ret(Rret_addr); 894 895 // generate a vanilla interpreter entry as the slow path 896 __ bind(slow_path); 897 __ jump_to_entry(Interpreter::entry_for_kind(Interpreter::zerolocals)); 898 return entry; 899 } 900 901 // Not supported 902 address TemplateInterpreterGenerator::generate_CRC32_update_entry() { return NULL; } 903 address TemplateInterpreterGenerator::generate_CRC32_updateBytes_entry(AbstractInterpreter::MethodKind kind) { return NULL; } 904 address TemplateInterpreterGenerator::generate_CRC32C_updateBytes_entry(AbstractInterpreter::MethodKind kind) { return NULL; } 905 906 // 907 // Interpreter stub for calling a native method. (asm interpreter) 908 // This sets up a somewhat different looking stack for calling the native method 909 // than the typical interpreter frame setup. 910 // 911 912 address TemplateInterpreterGenerator::generate_native_entry(bool synchronized) { 913 // determine code generation flags 914 bool inc_counter = UseCompiler || CountCompiledCalls || LogTouchedMethods; 915 916 // Incoming registers: 917 // 918 // Rmethod: Method* 919 // Rthread: thread 920 // Rsender_sp: sender sp 921 // Rparams: parameters 922 923 address entry_point = __ pc(); 924 925 // Register allocation 926 const Register Rsize_of_params = AARCH64_ONLY(R20) NOT_AARCH64(R6); 927 const Register Rsig_handler = AARCH64_ONLY(R21) NOT_AARCH64(Rtmp_save0 /* R4 */); 928 const Register Rnative_code = AARCH64_ONLY(R22) NOT_AARCH64(Rtmp_save1 /* R5 */); 929 const Register Rresult_handler = AARCH64_ONLY(Rsig_handler) NOT_AARCH64(R6); 930 931 #ifdef AARCH64 932 const Register RconstMethod = R10; // also used in generate_fixed_frame (should match) 933 const Register Rsaved_result = Rnative_code; 934 const FloatRegister Dsaved_result = V8; 935 #else 936 const Register Rsaved_result_lo = Rtmp_save0; // R4 937 const Register Rsaved_result_hi = Rtmp_save1; // R5 938 FloatRegister saved_result_fp; 939 #endif // AARCH64 940 941 942 #ifdef AARCH64 943 __ ldr(RconstMethod, Address(Rmethod, Method::const_offset())); 944 __ ldrh(Rsize_of_params, Address(RconstMethod, ConstMethod::size_of_parameters_offset())); 945 #else 946 __ ldr(Rsize_of_params, Address(Rmethod, Method::const_offset())); 947 __ ldrh(Rsize_of_params, Address(Rsize_of_params, ConstMethod::size_of_parameters_offset())); 948 #endif // AARCH64 949 950 // native calls don't need the stack size check since they have no expression stack 951 // and the arguments are already on the stack and we only add a handful of words 952 // to the stack 953 954 // compute beginning of parameters (Rlocals) 955 __ sub(Rlocals, Rparams, wordSize); 956 __ add(Rlocals, Rlocals, AsmOperand(Rsize_of_params, lsl, Interpreter::logStackElementSize)); 957 958 #ifdef AARCH64 959 int extra_stack_reserve = 2*wordSize; // extra space for oop_temp 960 if(__ can_post_interpreter_events()) { 961 // extra space for saved results 962 extra_stack_reserve += 2*wordSize; 963 } 964 // reserve extra stack space and nullify oop_temp slot 965 __ stp(ZR, ZR, Address(SP, -extra_stack_reserve, pre_indexed)); 966 #else 967 // reserve stack space for oop_temp 968 __ mov(R0, 0); 969 __ push(R0); 970 #endif // AARCH64 971 972 generate_fixed_frame(true); // Note: R9 is now saved in the frame 973 974 // make sure method is native & not abstract 975 #ifdef ASSERT 976 __ ldr_u32(Rtemp, Address(Rmethod, Method::access_flags_offset())); 977 { 978 Label L; 979 __ tbnz(Rtemp, JVM_ACC_NATIVE_BIT, L); 980 __ stop("tried to execute non-native method as native"); 981 __ bind(L); 982 } 983 { Label L; 984 __ tbz(Rtemp, JVM_ACC_ABSTRACT_BIT, L); 985 __ stop("tried to execute abstract method in interpreter"); 986 __ bind(L); 987 } 988 #endif 989 990 // increment invocation count & check for overflow 991 Label invocation_counter_overflow; 992 if (inc_counter) { 993 if (synchronized) { 994 // Avoid unlocking method's monitor in case of exception, as it has not 995 // been locked yet. 996 __ set_do_not_unlock_if_synchronized(true, Rtemp); 997 } 998 generate_counter_incr(&invocation_counter_overflow, NULL, NULL); 999 } 1000 1001 Label continue_after_compile; 1002 __ bind(continue_after_compile); 1003 1004 if (inc_counter && synchronized) { 1005 __ set_do_not_unlock_if_synchronized(false, Rtemp); 1006 } 1007 1008 // check for synchronized methods 1009 // Must happen AFTER invocation_counter check and stack overflow check, 1010 // so method is not locked if overflows. 1011 // 1012 if (synchronized) { 1013 lock_method(); 1014 } else { 1015 // no synchronization necessary 1016 #ifdef ASSERT 1017 { Label L; 1018 __ ldr_u32(Rtemp, Address(Rmethod, Method::access_flags_offset())); 1019 __ tbz(Rtemp, JVM_ACC_SYNCHRONIZED_BIT, L); 1020 __ stop("method needs synchronization"); 1021 __ bind(L); 1022 } 1023 #endif 1024 } 1025 1026 // start execution 1027 #ifdef ASSERT 1028 { Label L; 1029 __ ldr(Rtemp, Address(FP, frame::interpreter_frame_monitor_block_top_offset * wordSize)); 1030 __ cmp(Rtemp, Rstack_top); 1031 __ b(L, eq); 1032 __ stop("broken stack frame setup in interpreter"); 1033 __ bind(L); 1034 } 1035 #endif 1036 __ check_extended_sp(Rtemp); 1037 1038 // jvmti/dtrace support 1039 __ notify_method_entry(); 1040 #if R9_IS_SCRATCHED 1041 __ restore_method(); 1042 #endif 1043 1044 { 1045 Label L; 1046 __ ldr(Rsig_handler, Address(Rmethod, Method::signature_handler_offset())); 1047 __ cbnz(Rsig_handler, L); 1048 __ mov(R1, Rmethod); 1049 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::prepare_native_call), R1, true); 1050 __ ldr(Rsig_handler, Address(Rmethod, Method::signature_handler_offset())); 1051 __ bind(L); 1052 } 1053 1054 { 1055 Label L; 1056 __ ldr(Rnative_code, Address(Rmethod, Method::native_function_offset())); 1057 __ cbnz(Rnative_code, L); 1058 __ mov(R1, Rmethod); 1059 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::prepare_native_call), R1); 1060 __ ldr(Rnative_code, Address(Rmethod, Method::native_function_offset())); 1061 __ bind(L); 1062 } 1063 1064 // Allocate stack space for arguments 1065 1066 #ifdef AARCH64 1067 __ sub(Rtemp, SP, Rsize_of_params, ex_uxtw, LogBytesPerWord); 1068 __ align_reg(SP, Rtemp, StackAlignmentInBytes); 1069 1070 // Allocate more stack space to accomodate all arguments passed on GP and FP registers: 1071 // 8 * wordSize for GPRs 1072 // 8 * wordSize for FPRs 1073 int reg_arguments = align_up(8*wordSize + 8*wordSize, StackAlignmentInBytes); 1074 #else 1075 1076 // C functions need aligned stack 1077 __ bic(SP, SP, StackAlignmentInBytes - 1); 1078 // Multiply by BytesPerLong instead of BytesPerWord, because calling convention 1079 // may require empty slots due to long alignment, e.g. func(int, jlong, int, jlong) 1080 __ sub(SP, SP, AsmOperand(Rsize_of_params, lsl, LogBytesPerLong)); 1081 1082 #ifdef __ABI_HARD__ 1083 // Allocate more stack space to accomodate all GP as well as FP registers: 1084 // 4 * wordSize 1085 // 8 * BytesPerLong 1086 int reg_arguments = align_up((4*wordSize) + (8*BytesPerLong), StackAlignmentInBytes); 1087 #else 1088 // Reserve at least 4 words on the stack for loading 1089 // of parameters passed on registers (R0-R3). 1090 // See generate_slow_signature_handler(). 1091 // It is also used for JNIEnv & class additional parameters. 1092 int reg_arguments = 4 * wordSize; 1093 #endif // __ABI_HARD__ 1094 #endif // AARCH64 1095 1096 __ sub(SP, SP, reg_arguments); 1097 1098 1099 // Note: signature handler blows R4 (32-bit ARM) or R21 (AArch64) besides all scratch registers. 1100 // See AbstractInterpreterGenerator::generate_slow_signature_handler(). 1101 __ call(Rsig_handler); 1102 #if R9_IS_SCRATCHED 1103 __ restore_method(); 1104 #endif 1105 __ mov(Rresult_handler, R0); 1106 1107 // Pass JNIEnv and mirror for static methods 1108 { 1109 Label L; 1110 __ ldr_u32(Rtemp, Address(Rmethod, Method::access_flags_offset())); 1111 __ add(R0, Rthread, in_bytes(JavaThread::jni_environment_offset())); 1112 __ tbz(Rtemp, JVM_ACC_STATIC_BIT, L); 1113 __ load_mirror(Rtemp, Rmethod, Rtemp); 1114 __ add(R1, FP, frame::interpreter_frame_oop_temp_offset * wordSize); 1115 __ str(Rtemp, Address(R1, 0)); 1116 __ bind(L); 1117 } 1118 1119 __ set_last_Java_frame(SP, FP, true, Rtemp); 1120 1121 // Changing state to _thread_in_native must be the last thing to do 1122 // before the jump to native code. At this moment stack must be 1123 // safepoint-safe and completely prepared for stack walking. 1124 #ifdef ASSERT 1125 { 1126 Label L; 1127 __ ldr_u32(Rtemp, Address(Rthread, JavaThread::thread_state_offset())); 1128 __ cmp_32(Rtemp, _thread_in_Java); 1129 __ b(L, eq); 1130 __ stop("invalid thread state"); 1131 __ bind(L); 1132 } 1133 #endif 1134 1135 #ifdef AARCH64 1136 __ mov(Rtemp, _thread_in_native); 1137 __ add(Rtemp2, Rthread, in_bytes(JavaThread::thread_state_offset())); 1138 // STLR is used to force all preceding writes to be observed prior to thread state change 1139 __ stlr_w(Rtemp, Rtemp2); 1140 #else 1141 // Force all preceding writes to be observed prior to thread state change 1142 __ membar(MacroAssembler::StoreStore, Rtemp); 1143 1144 __ mov(Rtemp, _thread_in_native); 1145 __ str(Rtemp, Address(Rthread, JavaThread::thread_state_offset())); 1146 #endif // AARCH64 1147 1148 __ call(Rnative_code); 1149 #if R9_IS_SCRATCHED 1150 __ restore_method(); 1151 #endif 1152 1153 // Set FPSCR/FPCR to a known state 1154 if (AlwaysRestoreFPU) { 1155 __ restore_default_fp_mode(); 1156 } 1157 1158 // Do safepoint check 1159 __ mov(Rtemp, _thread_in_native_trans); 1160 __ str_32(Rtemp, Address(Rthread, JavaThread::thread_state_offset())); 1161 1162 // Force this write out before the read below 1163 __ membar(MacroAssembler::StoreLoad, Rtemp); 1164 1165 __ ldr_global_s32(Rtemp, SafepointSynchronize::address_of_state()); 1166 1167 // Protect the return value in the interleaved code: save it to callee-save registers. 1168 #ifdef AARCH64 1169 __ mov(Rsaved_result, R0); 1170 __ fmov_d(Dsaved_result, D0); 1171 #else 1172 __ mov(Rsaved_result_lo, R0); 1173 __ mov(Rsaved_result_hi, R1); 1174 #ifdef __ABI_HARD__ 1175 // preserve native FP result in a callee-saved register 1176 saved_result_fp = D8; 1177 __ fcpyd(saved_result_fp, D0); 1178 #else 1179 saved_result_fp = fnoreg; 1180 #endif // __ABI_HARD__ 1181 #endif // AARCH64 1182 1183 { 1184 __ ldr_u32(R3, Address(Rthread, JavaThread::suspend_flags_offset())); 1185 __ cmp(Rtemp, SafepointSynchronize::_not_synchronized); 1186 __ cond_cmp(R3, 0, eq); 1187 1188 #ifdef AARCH64 1189 Label L; 1190 __ b(L, eq); 1191 __ mov(R0, Rthread); 1192 __ call(CAST_FROM_FN_PTR(address, JavaThread::check_special_condition_for_native_trans), relocInfo::none); 1193 __ bind(L); 1194 #else 1195 __ mov(R0, Rthread, ne); 1196 __ call(CAST_FROM_FN_PTR(address, JavaThread::check_special_condition_for_native_trans), relocInfo::none, ne); 1197 #if R9_IS_SCRATCHED 1198 __ restore_method(); 1199 #endif 1200 #endif // AARCH64 1201 } 1202 1203 // Perform Native->Java thread transition 1204 __ mov(Rtemp, _thread_in_Java); 1205 __ str_32(Rtemp, Address(Rthread, JavaThread::thread_state_offset())); 1206 1207 // Zero handles and last_java_sp 1208 __ reset_last_Java_frame(Rtemp); 1209 __ ldr(R3, Address(Rthread, JavaThread::active_handles_offset())); 1210 __ str_32(__ zero_register(Rtemp), Address(R3, JNIHandleBlock::top_offset_in_bytes())); 1211 if (CheckJNICalls) { 1212 __ str(__ zero_register(Rtemp), Address(Rthread, JavaThread::pending_jni_exception_check_fn_offset())); 1213 } 1214 1215 // Unbox oop result, e.g. JNIHandles::resolve result if it's an oop. 1216 { 1217 Label Lnot_oop; 1218 #ifdef AARCH64 1219 __ mov_slow(Rtemp, AbstractInterpreter::result_handler(T_OBJECT)); 1220 __ cmp(Rresult_handler, Rtemp); 1221 __ b(Lnot_oop, ne); 1222 #else // !AARCH64 1223 // For ARM32, Rresult_handler is -1 for oop result, 0 otherwise. 1224 __ cbz(Rresult_handler, Lnot_oop); 1225 #endif // !AARCH64 1226 Register value = AARCH64_ONLY(Rsaved_result) NOT_AARCH64(Rsaved_result_lo); 1227 __ resolve_jobject(value, // value 1228 Rtemp, // tmp1 1229 R1_tmp); // tmp2 1230 // Store resolved result in frame for GC visibility. 1231 __ str(value, Address(FP, frame::interpreter_frame_oop_temp_offset * wordSize)); 1232 __ bind(Lnot_oop); 1233 } 1234 1235 #ifdef AARCH64 1236 // Restore SP (drop native parameters area), to keep SP in sync with extended_sp in frame 1237 __ restore_sp_after_call(Rtemp); 1238 __ check_stack_top(); 1239 #endif // AARCH64 1240 1241 // reguard stack if StackOverflow exception happened while in native. 1242 { 1243 __ ldr_u32(Rtemp, Address(Rthread, JavaThread::stack_guard_state_offset())); 1244 __ cmp_32(Rtemp, JavaThread::stack_guard_yellow_reserved_disabled); 1245 #ifdef AARCH64 1246 Label L; 1247 __ b(L, ne); 1248 __ call(CAST_FROM_FN_PTR(address, SharedRuntime::reguard_yellow_pages), relocInfo::none); 1249 __ bind(L); 1250 #else 1251 __ call(CAST_FROM_FN_PTR(address, SharedRuntime::reguard_yellow_pages), relocInfo::none, eq); 1252 #if R9_IS_SCRATCHED 1253 __ restore_method(); 1254 #endif 1255 #endif // AARCH64 1256 } 1257 1258 // check pending exceptions 1259 { 1260 __ ldr(Rtemp, Address(Rthread, Thread::pending_exception_offset())); 1261 #ifdef AARCH64 1262 Label L; 1263 __ cbz(Rtemp, L); 1264 __ mov_pc_to(Rexception_pc); 1265 __ b(StubRoutines::forward_exception_entry()); 1266 __ bind(L); 1267 #else 1268 __ cmp(Rtemp, 0); 1269 __ mov(Rexception_pc, PC, ne); 1270 __ b(StubRoutines::forward_exception_entry(), ne); 1271 #endif // AARCH64 1272 } 1273 1274 if (synchronized) { 1275 // address of first monitor 1276 __ sub(R1, FP, - (frame::interpreter_frame_monitor_block_bottom_offset - frame::interpreter_frame_monitor_size()) * wordSize); 1277 __ unlock_object(R1); 1278 } 1279 1280 // jvmti/dtrace support 1281 // Note: This must happen _after_ handling/throwing any exceptions since 1282 // the exception handler code notifies the runtime of method exits 1283 // too. If this happens before, method entry/exit notifications are 1284 // not properly paired (was bug - gri 11/22/99). 1285 #ifdef AARCH64 1286 __ notify_method_exit(vtos, InterpreterMacroAssembler::NotifyJVMTI, true, Rsaved_result, noreg, Dsaved_result); 1287 #else 1288 __ notify_method_exit(vtos, InterpreterMacroAssembler::NotifyJVMTI, true, Rsaved_result_lo, Rsaved_result_hi, saved_result_fp); 1289 #endif // AARCH64 1290 1291 // Restore the result. Oop result is restored from the stack. 1292 #ifdef AARCH64 1293 __ mov(R0, Rsaved_result); 1294 __ fmov_d(D0, Dsaved_result); 1295 1296 __ blr(Rresult_handler); 1297 #else 1298 __ cmp(Rresult_handler, 0); 1299 __ ldr(R0, Address(FP, frame::interpreter_frame_oop_temp_offset * wordSize), ne); 1300 __ mov(R0, Rsaved_result_lo, eq); 1301 __ mov(R1, Rsaved_result_hi); 1302 1303 #ifdef __ABI_HARD__ 1304 // reload native FP result 1305 __ fcpyd(D0, D8); 1306 #endif // __ABI_HARD__ 1307 1308 #ifdef ASSERT 1309 if (VerifyOops) { 1310 Label L; 1311 __ cmp(Rresult_handler, 0); 1312 __ b(L, eq); 1313 __ verify_oop(R0); 1314 __ bind(L); 1315 } 1316 #endif // ASSERT 1317 #endif // AARCH64 1318 1319 // Restore FP/LR, sender_sp and return 1320 #ifdef AARCH64 1321 __ ldr(Rtemp, Address(FP, frame::interpreter_frame_sender_sp_offset * wordSize)); 1322 __ ldp(FP, LR, Address(FP)); 1323 __ mov(SP, Rtemp); 1324 #else 1325 __ mov(Rtemp, FP); 1326 __ ldmia(FP, RegisterSet(FP) | RegisterSet(LR)); 1327 __ ldr(SP, Address(Rtemp, frame::interpreter_frame_sender_sp_offset * wordSize)); 1328 #endif // AARCH64 1329 1330 __ ret(); 1331 1332 if (inc_counter) { 1333 // Handle overflow of counter and compile method 1334 __ bind(invocation_counter_overflow); 1335 generate_counter_overflow(continue_after_compile); 1336 } 1337 1338 return entry_point; 1339 } 1340 1341 // 1342 // Generic interpreted method entry to (asm) interpreter 1343 // 1344 address TemplateInterpreterGenerator::generate_normal_entry(bool synchronized) { 1345 // determine code generation flags 1346 bool inc_counter = UseCompiler || CountCompiledCalls || LogTouchedMethods; 1347 1348 // Rmethod: Method* 1349 // Rthread: thread 1350 // Rsender_sp: sender sp (could differ from SP if we were called via c2i) 1351 // Rparams: pointer to the last parameter in the stack 1352 1353 address entry_point = __ pc(); 1354 1355 const Register RconstMethod = AARCH64_ONLY(R10) NOT_AARCH64(R3); 1356 1357 #ifdef AARCH64 1358 const Register RmaxStack = R11; 1359 const Register RlocalsBase = R12; 1360 #endif // AARCH64 1361 1362 __ ldr(RconstMethod, Address(Rmethod, Method::const_offset())); 1363 1364 __ ldrh(R2, Address(RconstMethod, ConstMethod::size_of_parameters_offset())); 1365 __ ldrh(R3, Address(RconstMethod, ConstMethod::size_of_locals_offset())); 1366 1367 // setup Rlocals 1368 __ sub(Rlocals, Rparams, wordSize); 1369 __ add(Rlocals, Rlocals, AsmOperand(R2, lsl, Interpreter::logStackElementSize)); 1370 1371 __ sub(R3, R3, R2); // number of additional locals 1372 1373 #ifdef AARCH64 1374 // setup RmaxStack 1375 __ ldrh(RmaxStack, Address(RconstMethod, ConstMethod::max_stack_offset())); 1376 // We have to add extra reserved slots to max_stack. There are 3 users of the extra slots, 1377 // none of which are at the same time, so we just need to make sure there is enough room 1378 // for the biggest user: 1379 // -reserved slot for exception handler 1380 // -reserved slots for JSR292. Method::extra_stack_entries() is the size. 1381 // -3 reserved slots so get_method_counters() can save some registers before call_VM(). 1382 __ add(RmaxStack, RmaxStack, MAX2(3, Method::extra_stack_entries())); 1383 #endif // AARCH64 1384 1385 // see if we've got enough room on the stack for locals plus overhead. 1386 generate_stack_overflow_check(); 1387 1388 #ifdef AARCH64 1389 1390 // allocate space for locals 1391 { 1392 __ sub(RlocalsBase, Rparams, AsmOperand(R3, lsl, Interpreter::logStackElementSize)); 1393 __ align_reg(SP, RlocalsBase, StackAlignmentInBytes); 1394 } 1395 1396 // explicitly initialize locals 1397 { 1398 Label zero_loop, done; 1399 __ cbz(R3, done); 1400 1401 __ tbz(R3, 0, zero_loop); 1402 __ subs(R3, R3, 1); 1403 __ str(ZR, Address(RlocalsBase, wordSize, post_indexed)); 1404 __ b(done, eq); 1405 1406 __ bind(zero_loop); 1407 __ subs(R3, R3, 2); 1408 __ stp(ZR, ZR, Address(RlocalsBase, 2*wordSize, post_indexed)); 1409 __ b(zero_loop, ne); 1410 1411 __ bind(done); 1412 } 1413 1414 #else 1415 // allocate space for locals 1416 // explicitly initialize locals 1417 1418 // Loop is unrolled 4 times 1419 Label loop; 1420 __ mov(R0, 0); 1421 __ bind(loop); 1422 1423 // #1 1424 __ subs(R3, R3, 1); 1425 __ push(R0, ge); 1426 1427 // #2 1428 __ subs(R3, R3, 1, ge); 1429 __ push(R0, ge); 1430 1431 // #3 1432 __ subs(R3, R3, 1, ge); 1433 __ push(R0, ge); 1434 1435 // #4 1436 __ subs(R3, R3, 1, ge); 1437 __ push(R0, ge); 1438 1439 __ b(loop, gt); 1440 #endif // AARCH64 1441 1442 // initialize fixed part of activation frame 1443 generate_fixed_frame(false); 1444 1445 __ restore_dispatch(); 1446 1447 // make sure method is not native & not abstract 1448 #ifdef ASSERT 1449 __ ldr_u32(Rtemp, Address(Rmethod, Method::access_flags_offset())); 1450 { 1451 Label L; 1452 __ tbz(Rtemp, JVM_ACC_NATIVE_BIT, L); 1453 __ stop("tried to execute native method as non-native"); 1454 __ bind(L); 1455 } 1456 { Label L; 1457 __ tbz(Rtemp, JVM_ACC_ABSTRACT_BIT, L); 1458 __ stop("tried to execute abstract method in interpreter"); 1459 __ bind(L); 1460 } 1461 #endif 1462 1463 // increment invocation count & check for overflow 1464 Label invocation_counter_overflow; 1465 Label profile_method; 1466 Label profile_method_continue; 1467 if (inc_counter) { 1468 if (synchronized) { 1469 // Avoid unlocking method's monitor in case of exception, as it has not 1470 // been locked yet. 1471 __ set_do_not_unlock_if_synchronized(true, Rtemp); 1472 } 1473 generate_counter_incr(&invocation_counter_overflow, &profile_method, &profile_method_continue); 1474 if (ProfileInterpreter) { 1475 __ bind(profile_method_continue); 1476 } 1477 } 1478 Label continue_after_compile; 1479 __ bind(continue_after_compile); 1480 1481 if (inc_counter && synchronized) { 1482 __ set_do_not_unlock_if_synchronized(false, Rtemp); 1483 } 1484 #if R9_IS_SCRATCHED 1485 __ restore_method(); 1486 #endif 1487 1488 // check for synchronized methods 1489 // Must happen AFTER invocation_counter check and stack overflow check, 1490 // so method is not locked if overflows. 1491 // 1492 if (synchronized) { 1493 // Allocate monitor and lock method 1494 lock_method(); 1495 } else { 1496 // no synchronization necessary 1497 #ifdef ASSERT 1498 { Label L; 1499 __ ldr_u32(Rtemp, Address(Rmethod, Method::access_flags_offset())); 1500 __ tbz(Rtemp, JVM_ACC_SYNCHRONIZED_BIT, L); 1501 __ stop("method needs synchronization"); 1502 __ bind(L); 1503 } 1504 #endif 1505 } 1506 1507 // start execution 1508 #ifdef ASSERT 1509 { Label L; 1510 __ ldr(Rtemp, Address(FP, frame::interpreter_frame_monitor_block_top_offset * wordSize)); 1511 __ cmp(Rtemp, Rstack_top); 1512 __ b(L, eq); 1513 __ stop("broken stack frame setup in interpreter"); 1514 __ bind(L); 1515 } 1516 #endif 1517 __ check_extended_sp(Rtemp); 1518 1519 // jvmti support 1520 __ notify_method_entry(); 1521 #if R9_IS_SCRATCHED 1522 __ restore_method(); 1523 #endif 1524 1525 __ dispatch_next(vtos); 1526 1527 // invocation counter overflow 1528 if (inc_counter) { 1529 if (ProfileInterpreter) { 1530 // We have decided to profile this method in the interpreter 1531 __ bind(profile_method); 1532 1533 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::profile_method)); 1534 __ set_method_data_pointer_for_bcp(); 1535 1536 __ b(profile_method_continue); 1537 } 1538 1539 // Handle overflow of counter and compile method 1540 __ bind(invocation_counter_overflow); 1541 generate_counter_overflow(continue_after_compile); 1542 } 1543 1544 return entry_point; 1545 } 1546 1547 //------------------------------------------------------------------------------------------------------------------------ 1548 // Exceptions 1549 1550 void TemplateInterpreterGenerator::generate_throw_exception() { 1551 // Entry point in previous activation (i.e., if the caller was interpreted) 1552 Interpreter::_rethrow_exception_entry = __ pc(); 1553 // Rexception_obj: exception 1554 1555 #ifndef AARCH64 1556 // Clear interpreter_frame_last_sp. 1557 __ mov(Rtemp, 0); 1558 __ str(Rtemp, Address(FP, frame::interpreter_frame_last_sp_offset * wordSize)); 1559 #endif // !AARCH64 1560 1561 #if R9_IS_SCRATCHED 1562 __ restore_method(); 1563 #endif 1564 __ restore_bcp(); 1565 __ restore_dispatch(); 1566 __ restore_locals(); 1567 1568 #ifdef AARCH64 1569 __ restore_sp_after_call(Rtemp); 1570 #endif // AARCH64 1571 1572 // Entry point for exceptions thrown within interpreter code 1573 Interpreter::_throw_exception_entry = __ pc(); 1574 1575 // expression stack is undefined here 1576 // Rexception_obj: exception 1577 // Rbcp: exception bcp 1578 __ verify_oop(Rexception_obj); 1579 1580 // expression stack must be empty before entering the VM in case of an exception 1581 __ empty_expression_stack(); 1582 // find exception handler address and preserve exception oop 1583 __ mov(R1, Rexception_obj); 1584 __ call_VM(Rexception_obj, CAST_FROM_FN_PTR(address, InterpreterRuntime::exception_handler_for_exception), R1); 1585 // R0: exception handler entry point 1586 // Rexception_obj: preserved exception oop 1587 // Rbcp: bcp for exception handler 1588 __ push_ptr(Rexception_obj); // push exception which is now the only value on the stack 1589 __ jump(R0); // jump to exception handler (may be _remove_activation_entry!) 1590 1591 // If the exception is not handled in the current frame the frame is removed and 1592 // the exception is rethrown (i.e. exception continuation is _rethrow_exception). 1593 // 1594 // Note: At this point the bci is still the bxi for the instruction which caused 1595 // the exception and the expression stack is empty. Thus, for any VM calls 1596 // at this point, GC will find a legal oop map (with empty expression stack). 1597 1598 // In current activation 1599 // tos: exception 1600 // Rbcp: exception bcp 1601 1602 // 1603 // JVMTI PopFrame support 1604 // 1605 Interpreter::_remove_activation_preserving_args_entry = __ pc(); 1606 1607 #ifdef AARCH64 1608 __ restore_sp_after_call(Rtemp); // restore SP to extended SP 1609 #endif // AARCH64 1610 1611 __ empty_expression_stack(); 1612 1613 // Set the popframe_processing bit in _popframe_condition indicating that we are 1614 // currently handling popframe, so that call_VMs that may happen later do not trigger new 1615 // popframe handling cycles. 1616 1617 __ ldr_s32(Rtemp, Address(Rthread, JavaThread::popframe_condition_offset())); 1618 __ orr(Rtemp, Rtemp, (unsigned)JavaThread::popframe_processing_bit); 1619 __ str_32(Rtemp, Address(Rthread, JavaThread::popframe_condition_offset())); 1620 1621 { 1622 // Check to see whether we are returning to a deoptimized frame. 1623 // (The PopFrame call ensures that the caller of the popped frame is 1624 // either interpreted or compiled and deoptimizes it if compiled.) 1625 // In this case, we can't call dispatch_next() after the frame is 1626 // popped, but instead must save the incoming arguments and restore 1627 // them after deoptimization has occurred. 1628 // 1629 // Note that we don't compare the return PC against the 1630 // deoptimization blob's unpack entry because of the presence of 1631 // adapter frames in C2. 1632 Label caller_not_deoptimized; 1633 __ ldr(R0, Address(FP, frame::return_addr_offset * wordSize)); 1634 __ call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::interpreter_contains), R0); 1635 __ cbnz_32(R0, caller_not_deoptimized); 1636 #ifdef AARCH64 1637 __ NOT_TESTED(); 1638 #endif 1639 1640 // Compute size of arguments for saving when returning to deoptimized caller 1641 __ restore_method(); 1642 __ ldr(R0, Address(Rmethod, Method::const_offset())); 1643 __ ldrh(R0, Address(R0, ConstMethod::size_of_parameters_offset())); 1644 1645 __ logical_shift_left(R1, R0, Interpreter::logStackElementSize); 1646 // Save these arguments 1647 __ restore_locals(); 1648 __ sub(R2, Rlocals, R1); 1649 __ add(R2, R2, wordSize); 1650 __ mov(R0, Rthread); 1651 __ call_VM_leaf(CAST_FROM_FN_PTR(address, Deoptimization::popframe_preserve_args), R0, R1, R2); 1652 1653 __ remove_activation(vtos, LR, 1654 /* throw_monitor_exception */ false, 1655 /* install_monitor_exception */ false, 1656 /* notify_jvmdi */ false); 1657 1658 // Inform deoptimization that it is responsible for restoring these arguments 1659 __ mov(Rtemp, JavaThread::popframe_force_deopt_reexecution_bit); 1660 __ str_32(Rtemp, Address(Rthread, JavaThread::popframe_condition_offset())); 1661 1662 // Continue in deoptimization handler 1663 __ ret(); 1664 1665 __ bind(caller_not_deoptimized); 1666 } 1667 1668 __ remove_activation(vtos, R4, 1669 /* throw_monitor_exception */ false, 1670 /* install_monitor_exception */ false, 1671 /* notify_jvmdi */ false); 1672 1673 #ifndef AARCH64 1674 // Finish with popframe handling 1675 // A previous I2C followed by a deoptimization might have moved the 1676 // outgoing arguments further up the stack. PopFrame expects the 1677 // mutations to those outgoing arguments to be preserved and other 1678 // constraints basically require this frame to look exactly as 1679 // though it had previously invoked an interpreted activation with 1680 // no space between the top of the expression stack (current 1681 // last_sp) and the top of stack. Rather than force deopt to 1682 // maintain this kind of invariant all the time we call a small 1683 // fixup routine to move the mutated arguments onto the top of our 1684 // expression stack if necessary. 1685 __ mov(R1, SP); 1686 __ ldr(R2, Address(FP, frame::interpreter_frame_last_sp_offset * wordSize)); 1687 // PC must point into interpreter here 1688 __ set_last_Java_frame(SP, FP, true, Rtemp); 1689 __ mov(R0, Rthread); 1690 __ call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::popframe_move_outgoing_args), R0, R1, R2); 1691 __ reset_last_Java_frame(Rtemp); 1692 #endif // !AARCH64 1693 1694 #ifdef AARCH64 1695 __ restore_sp_after_call(Rtemp); 1696 __ restore_stack_top(); 1697 #else 1698 // Restore the last_sp and null it out 1699 __ ldr(SP, Address(FP, frame::interpreter_frame_last_sp_offset * wordSize)); 1700 __ mov(Rtemp, (int)NULL_WORD); 1701 __ str(Rtemp, Address(FP, frame::interpreter_frame_last_sp_offset * wordSize)); 1702 #endif // AARCH64 1703 1704 __ restore_bcp(); 1705 __ restore_dispatch(); 1706 __ restore_locals(); 1707 __ restore_method(); 1708 1709 // The method data pointer was incremented already during 1710 // call profiling. We have to restore the mdp for the current bcp. 1711 if (ProfileInterpreter) { 1712 __ set_method_data_pointer_for_bcp(); 1713 } 1714 1715 // Clear the popframe condition flag 1716 assert(JavaThread::popframe_inactive == 0, "adjust this code"); 1717 __ str_32(__ zero_register(Rtemp), Address(Rthread, JavaThread::popframe_condition_offset())); 1718 1719 #if INCLUDE_JVMTI 1720 { 1721 Label L_done; 1722 1723 __ ldrb(Rtemp, Address(Rbcp, 0)); 1724 __ cmp(Rtemp, Bytecodes::_invokestatic); 1725 __ b(L_done, ne); 1726 1727 // The member name argument must be restored if _invokestatic is re-executed after a PopFrame call. 1728 // Detect such a case in the InterpreterRuntime function and return the member name argument, or NULL. 1729 1730 // get local0 1731 __ ldr(R1, Address(Rlocals, 0)); 1732 __ mov(R2, Rmethod); 1733 __ mov(R3, Rbcp); 1734 __ call_VM(R0, CAST_FROM_FN_PTR(address, InterpreterRuntime::member_name_arg_or_null), R1, R2, R3); 1735 1736 __ cbz(R0, L_done); 1737 1738 __ str(R0, Address(Rstack_top)); 1739 __ bind(L_done); 1740 } 1741 #endif // INCLUDE_JVMTI 1742 1743 __ dispatch_next(vtos); 1744 // end of PopFrame support 1745 1746 Interpreter::_remove_activation_entry = __ pc(); 1747 1748 // preserve exception over this code sequence 1749 __ pop_ptr(R0_tos); 1750 __ str(R0_tos, Address(Rthread, JavaThread::vm_result_offset())); 1751 // remove the activation (without doing throws on illegalMonitorExceptions) 1752 __ remove_activation(vtos, Rexception_pc, false, true, false); 1753 // restore exception 1754 __ get_vm_result(Rexception_obj, Rtemp); 1755 1756 // Inbetween activations - previous activation type unknown yet 1757 // compute continuation point - the continuation point expects 1758 // the following registers set up: 1759 // 1760 // Rexception_obj: exception 1761 // Rexception_pc: return address/pc that threw exception 1762 // SP: expression stack of caller 1763 // FP: frame pointer of caller 1764 __ mov(c_rarg0, Rthread); 1765 __ mov(c_rarg1, Rexception_pc); 1766 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::exception_handler_for_return_address), c_rarg0, c_rarg1); 1767 // Note that an "issuing PC" is actually the next PC after the call 1768 1769 __ jump(R0); // jump to exception handler of caller 1770 } 1771 1772 1773 // 1774 // JVMTI ForceEarlyReturn support 1775 // 1776 address TemplateInterpreterGenerator::generate_earlyret_entry_for(TosState state) { 1777 address entry = __ pc(); 1778 1779 #ifdef AARCH64 1780 __ restore_sp_after_call(Rtemp); // restore SP to extended SP 1781 #endif // AARCH64 1782 1783 __ restore_bcp(); 1784 __ restore_dispatch(); 1785 __ restore_locals(); 1786 1787 __ empty_expression_stack(); 1788 1789 __ load_earlyret_value(state); 1790 1791 // Clear the earlyret state 1792 __ ldr(Rtemp, Address(Rthread, JavaThread::jvmti_thread_state_offset())); 1793 1794 assert(JvmtiThreadState::earlyret_inactive == 0, "adjust this code"); 1795 __ str_32(__ zero_register(R2), Address(Rtemp, JvmtiThreadState::earlyret_state_offset())); 1796 1797 __ remove_activation(state, LR, 1798 false, /* throw_monitor_exception */ 1799 false, /* install_monitor_exception */ 1800 true); /* notify_jvmdi */ 1801 1802 #ifndef AARCH64 1803 // According to interpreter calling conventions, result is returned in R0/R1, 1804 // so ftos (S0) and dtos (D0) are moved to R0/R1. 1805 // This conversion should be done after remove_activation, as it uses 1806 // push(state) & pop(state) to preserve return value. 1807 __ convert_tos_to_retval(state); 1808 #endif // !AARCH64 1809 __ ret(); 1810 1811 return entry; 1812 } // end of ForceEarlyReturn support 1813 1814 1815 //------------------------------------------------------------------------------------------------------------------------ 1816 // Helper for vtos entry point generation 1817 1818 void TemplateInterpreterGenerator::set_vtos_entry_points (Template* t, address& bep, address& cep, address& sep, address& aep, address& iep, address& lep, address& fep, address& dep, address& vep) { 1819 assert(t->is_valid() && t->tos_in() == vtos, "illegal template"); 1820 Label L; 1821 1822 #ifdef __SOFTFP__ 1823 dep = __ pc(); // fall through 1824 #else 1825 fep = __ pc(); __ push(ftos); __ b(L); 1826 dep = __ pc(); __ push(dtos); __ b(L); 1827 #endif // __SOFTFP__ 1828 1829 lep = __ pc(); __ push(ltos); __ b(L); 1830 1831 if (AARCH64_ONLY(true) NOT_AARCH64(VerifyOops)) { // can't share atos entry with itos on AArch64 or if VerifyOops 1832 aep = __ pc(); __ push(atos); __ b(L); 1833 } else { 1834 aep = __ pc(); // fall through 1835 } 1836 1837 #ifdef __SOFTFP__ 1838 fep = __ pc(); // fall through 1839 #endif // __SOFTFP__ 1840 1841 bep = cep = sep = // fall through 1842 iep = __ pc(); __ push(itos); // fall through 1843 vep = __ pc(); __ bind(L); // fall through 1844 generate_and_dispatch(t); 1845 } 1846 1847 //------------------------------------------------------------------------------------------------------------------------ 1848 1849 // Non-product code 1850 #ifndef PRODUCT 1851 address TemplateInterpreterGenerator::generate_trace_code(TosState state) { 1852 address entry = __ pc(); 1853 1854 // prepare expression stack 1855 __ push(state); // save tosca 1856 1857 // pass tosca registers as arguments 1858 __ mov(R2, R0_tos); 1859 #ifdef AARCH64 1860 __ mov(R3, ZR); 1861 #else 1862 __ mov(R3, R1_tos_hi); 1863 #endif // AARCH64 1864 __ mov(R1, LR); // save return address 1865 1866 // call tracer 1867 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::trace_bytecode), R1, R2, R3); 1868 1869 __ mov(LR, R0); // restore return address 1870 __ pop(state); // restore tosca 1871 1872 // return 1873 __ ret(); 1874 1875 return entry; 1876 } 1877 1878 1879 void TemplateInterpreterGenerator::count_bytecode() { 1880 __ inc_global_counter((address) &BytecodeCounter::_counter_value, 0, Rtemp, R2_tmp, true); 1881 } 1882 1883 1884 void TemplateInterpreterGenerator::histogram_bytecode(Template* t) { 1885 __ inc_global_counter((address)&BytecodeHistogram::_counters[0], sizeof(BytecodeHistogram::_counters[0]) * t->bytecode(), Rtemp, R2_tmp, true); 1886 } 1887 1888 1889 void TemplateInterpreterGenerator::histogram_bytecode_pair(Template* t) { 1890 const Register Rindex_addr = R2_tmp; 1891 Label Lcontinue; 1892 InlinedAddress Lcounters((address)BytecodePairHistogram::_counters); 1893 InlinedAddress Lindex((address)&BytecodePairHistogram::_index); 1894 const Register Rcounters_addr = R2_tmp; 1895 const Register Rindex = R4_tmp; 1896 1897 // calculate new index for counter: 1898 // index = (_index >> log2_number_of_codes) | (bytecode << log2_number_of_codes). 1899 // (_index >> log2_number_of_codes) is previous bytecode 1900 1901 __ ldr_literal(Rindex_addr, Lindex); 1902 __ ldr_s32(Rindex, Address(Rindex_addr)); 1903 __ mov_slow(Rtemp, ((int)t->bytecode()) << BytecodePairHistogram::log2_number_of_codes); 1904 __ orr(Rindex, Rtemp, AsmOperand(Rindex, lsr, BytecodePairHistogram::log2_number_of_codes)); 1905 __ str_32(Rindex, Address(Rindex_addr)); 1906 1907 // Rindex (R4) contains index of counter 1908 1909 __ ldr_literal(Rcounters_addr, Lcounters); 1910 __ ldr_s32(Rtemp, Address::indexed_32(Rcounters_addr, Rindex)); 1911 __ adds_32(Rtemp, Rtemp, 1); 1912 __ b(Lcontinue, mi); // avoid overflow 1913 __ str_32(Rtemp, Address::indexed_32(Rcounters_addr, Rindex)); 1914 1915 __ b(Lcontinue); 1916 1917 __ bind_literal(Lindex); 1918 __ bind_literal(Lcounters); 1919 1920 __ bind(Lcontinue); 1921 } 1922 1923 1924 void TemplateInterpreterGenerator::trace_bytecode(Template* t) { 1925 // Call a little run-time stub to avoid blow-up for each bytecode. 1926 // The run-time runtime saves the right registers, depending on 1927 // the tosca in-state for the given template. 1928 assert(Interpreter::trace_code(t->tos_in()) != NULL, 1929 "entry must have been generated"); 1930 address trace_entry = Interpreter::trace_code(t->tos_in()); 1931 __ call(trace_entry, relocInfo::none); 1932 } 1933 1934 1935 void TemplateInterpreterGenerator::stop_interpreter_at() { 1936 Label Lcontinue; 1937 const Register stop_at = R2_tmp; 1938 1939 __ ldr_global_s32(Rtemp, (address) &BytecodeCounter::_counter_value); 1940 __ mov_slow(stop_at, StopInterpreterAt); 1941 1942 // test bytecode counter 1943 __ cmp(Rtemp, stop_at); 1944 __ b(Lcontinue, ne); 1945 1946 __ trace_state("stop_interpreter_at"); 1947 __ breakpoint(); 1948 1949 __ bind(Lcontinue); 1950 } 1951 #endif // !PRODUCT