1 /* 2 * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved. 3 * Copyright (c) 2014, Red Hat Inc. All rights reserved. 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 * 6 * This code is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License version 2 only, as 8 * published by the Free Software Foundation. 9 * 10 * This code is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 * version 2 for more details (a copy is included in the LICENSE file that 14 * accompanied this code). 15 * 16 * You should have received a copy of the GNU General Public License version 17 * 2 along with this work; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 * or visit www.oracle.com if you need additional information or have any 22 * questions. 23 * 24 */ 25 26 #include "precompiled.hpp" 27 #include "asm/macroAssembler.hpp" 28 #include "interpreter/bytecodeHistogram.hpp" 29 #include "interpreter/interpreter.hpp" 30 #include "interpreter/interpreterRuntime.hpp" 31 #include "interpreter/interp_masm.hpp" 32 #include "interpreter/templateInterpreterGenerator.hpp" 33 #include "interpreter/templateTable.hpp" 34 #include "interpreter/bytecodeTracer.hpp" 35 #include "oops/arrayOop.hpp" 36 #include "oops/methodData.hpp" 37 #include "oops/method.hpp" 38 #include "oops/oop.inline.hpp" 39 #include "prims/jvmtiExport.hpp" 40 #include "prims/jvmtiThreadState.hpp" 41 #include "runtime/arguments.hpp" 42 #include "runtime/deoptimization.hpp" 43 #include "runtime/frame.inline.hpp" 44 #include "runtime/sharedRuntime.hpp" 45 #include "runtime/stubRoutines.hpp" 46 #include "runtime/synchronizer.hpp" 47 #include "runtime/timer.hpp" 48 #include "runtime/vframeArray.hpp" 49 #include "utilities/debug.hpp" 50 #include <sys/types.h> 51 52 #ifndef PRODUCT 53 #include "oops/method.hpp" 54 #endif // !PRODUCT 55 56 #ifdef BUILTIN_SIM 57 #include "../../../../../../simulator/simulator.hpp" 58 #endif 59 60 #define __ _masm-> 61 62 //----------------------------------------------------------------------------- 63 64 extern "C" void entry(CodeBuffer*); 65 66 //----------------------------------------------------------------------------- 67 68 address TemplateInterpreterGenerator::generate_StackOverflowError_handler() { 69 address entry = __ pc(); 70 71 #ifdef ASSERT 72 { 73 Label L; 74 __ ldr(rscratch1, Address(rfp, 75 frame::interpreter_frame_monitor_block_top_offset * 76 wordSize)); 77 __ mov(rscratch2, sp); 78 __ cmp(rscratch1, rscratch2); // maximal rsp for current rfp (stack 79 // grows negative) 80 __ br(Assembler::HS, L); // check if frame is complete 81 __ stop ("interpreter frame not set up"); 82 __ bind(L); 83 } 84 #endif // ASSERT 85 // Restore bcp under the assumption that the current frame is still 86 // interpreted 87 __ restore_bcp(); 88 89 // expression stack must be empty before entering the VM if an 90 // exception happened 91 __ empty_expression_stack(); 92 // throw exception 93 __ call_VM(noreg, 94 CAST_FROM_FN_PTR(address, 95 InterpreterRuntime::throw_StackOverflowError)); 96 return entry; 97 } 98 99 address TemplateInterpreterGenerator::generate_ArrayIndexOutOfBounds_handler( 100 const char* name) { 101 address entry = __ pc(); 102 // expression stack must be empty before entering the VM if an 103 // exception happened 104 __ empty_expression_stack(); 105 // setup parameters 106 // ??? convention: expect aberrant index in register r1 107 __ movw(c_rarg2, r1); 108 __ mov(c_rarg1, (address)name); 109 __ call_VM(noreg, 110 CAST_FROM_FN_PTR(address, 111 InterpreterRuntime:: 112 throw_ArrayIndexOutOfBoundsException), 113 c_rarg1, c_rarg2); 114 return entry; 115 } 116 117 address TemplateInterpreterGenerator::generate_ClassCastException_handler() { 118 address entry = __ pc(); 119 120 // object is at TOS 121 __ pop(c_rarg1); 122 123 // expression stack must be empty before entering the VM if an 124 // exception happened 125 __ empty_expression_stack(); 126 127 __ call_VM(noreg, 128 CAST_FROM_FN_PTR(address, 129 InterpreterRuntime:: 130 throw_ClassCastException), 131 c_rarg1); 132 return entry; 133 } 134 135 address TemplateInterpreterGenerator::generate_exception_handler_common( 136 const char* name, const char* message, bool pass_oop) { 137 assert(!pass_oop || message == NULL, "either oop or message but not both"); 138 address entry = __ pc(); 139 if (pass_oop) { 140 // object is at TOS 141 __ pop(c_rarg2); 142 } 143 // expression stack must be empty before entering the VM if an 144 // exception happened 145 __ empty_expression_stack(); 146 // setup parameters 147 __ lea(c_rarg1, Address((address)name)); 148 if (pass_oop) { 149 __ call_VM(r0, CAST_FROM_FN_PTR(address, 150 InterpreterRuntime:: 151 create_klass_exception), 152 c_rarg1, c_rarg2); 153 } else { 154 // kind of lame ExternalAddress can't take NULL because 155 // external_word_Relocation will assert. 156 if (message != NULL) { 157 __ lea(c_rarg2, Address((address)message)); 158 } else { 159 __ mov(c_rarg2, NULL_WORD); 160 } 161 __ call_VM(r0, 162 CAST_FROM_FN_PTR(address, InterpreterRuntime::create_exception), 163 c_rarg1, c_rarg2); 164 } 165 // throw exception 166 __ b(address(Interpreter::throw_exception_entry())); 167 return entry; 168 } 169 170 address TemplateInterpreterGenerator::generate_continuation_for(TosState state) { 171 address entry = __ pc(); 172 // NULL last_sp until next java call 173 __ str(zr, Address(rfp, frame::interpreter_frame_last_sp_offset * wordSize)); 174 __ dispatch_next(state); 175 return entry; 176 } 177 178 address TemplateInterpreterGenerator::generate_return_entry_for(TosState state, int step, size_t index_size) { 179 address entry = __ pc(); 180 181 // Restore stack bottom in case i2c adjusted stack 182 __ ldr(esp, Address(rfp, frame::interpreter_frame_last_sp_offset * wordSize)); 183 // and NULL it as marker that esp is now tos until next java call 184 __ str(zr, Address(rfp, frame::interpreter_frame_last_sp_offset * wordSize)); 185 __ restore_bcp(); 186 __ restore_locals(); 187 __ restore_constant_pool_cache(); 188 __ get_method(rmethod); 189 190 // Pop N words from the stack 191 __ get_cache_and_index_at_bcp(r1, r2, 1, index_size); 192 __ ldr(r1, Address(r1, ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::flags_offset())); 193 __ andr(r1, r1, ConstantPoolCacheEntry::parameter_size_mask); 194 195 __ add(esp, esp, r1, Assembler::LSL, 3); 196 197 // Restore machine SP 198 __ ldr(rscratch1, Address(rmethod, Method::const_offset())); 199 __ ldrh(rscratch1, Address(rscratch1, ConstMethod::max_stack_offset())); 200 __ add(rscratch1, rscratch1, frame::interpreter_frame_monitor_size() + 2); 201 __ ldr(rscratch2, 202 Address(rfp, frame::interpreter_frame_initial_sp_offset * wordSize)); 203 __ sub(rscratch1, rscratch2, rscratch1, ext::uxtw, 3); 204 __ andr(sp, rscratch1, -16); 205 206 #ifndef PRODUCT 207 // tell the simulator that the method has been reentered 208 if (NotifySimulator) { 209 __ notify(Assembler::method_reentry); 210 } 211 #endif 212 __ get_dispatch(); 213 __ dispatch_next(state, step); 214 215 return entry; 216 } 217 218 address TemplateInterpreterGenerator::generate_deopt_entry_for(TosState state, 219 int step) { 220 address entry = __ pc(); 221 __ restore_bcp(); 222 __ restore_locals(); 223 __ restore_constant_pool_cache(); 224 __ get_method(rmethod); 225 226 // handle exceptions 227 { 228 Label L; 229 __ ldr(rscratch1, Address(rthread, Thread::pending_exception_offset())); 230 __ cbz(rscratch1, L); 231 __ call_VM(noreg, 232 CAST_FROM_FN_PTR(address, 233 InterpreterRuntime::throw_pending_exception)); 234 __ should_not_reach_here(); 235 __ bind(L); 236 } 237 238 __ get_dispatch(); 239 240 // Calculate stack limit 241 __ ldr(rscratch1, Address(rmethod, Method::const_offset())); 242 __ ldrh(rscratch1, Address(rscratch1, ConstMethod::max_stack_offset())); 243 __ add(rscratch1, rscratch1, frame::interpreter_frame_monitor_size() + 2); 244 __ ldr(rscratch2, 245 Address(rfp, frame::interpreter_frame_initial_sp_offset * wordSize)); 246 __ sub(rscratch1, rscratch2, rscratch1, ext::uxtx, 3); 247 __ andr(sp, rscratch1, -16); 248 249 // Restore expression stack pointer 250 __ ldr(esp, Address(rfp, frame::interpreter_frame_last_sp_offset * wordSize)); 251 // NULL last_sp until next java call 252 __ str(zr, Address(rfp, frame::interpreter_frame_last_sp_offset * wordSize)); 253 254 __ dispatch_next(state, step); 255 return entry; 256 } 257 258 address TemplateInterpreterGenerator::generate_result_handler_for( 259 BasicType type) { 260 address entry = __ pc(); 261 switch (type) { 262 case T_BOOLEAN: __ uxtb(r0, r0); break; 263 case T_CHAR : __ uxth(r0, r0); break; 264 case T_BYTE : __ sxtb(r0, r0); break; 265 case T_SHORT : __ sxth(r0, r0); break; 266 case T_INT : __ uxtw(r0, r0); break; // FIXME: We almost certainly don't need this 267 case T_LONG : /* nothing to do */ break; 268 case T_VOID : /* nothing to do */ break; 269 case T_FLOAT : /* nothing to do */ break; 270 case T_DOUBLE : /* nothing to do */ break; 271 case T_OBJECT : 272 // retrieve result from frame 273 __ ldr(r0, Address(rfp, frame::interpreter_frame_oop_temp_offset*wordSize)); 274 // and verify it 275 __ verify_oop(r0); 276 break; 277 default : ShouldNotReachHere(); 278 } 279 __ ret(lr); // return from result handler 280 return entry; 281 } 282 283 address TemplateInterpreterGenerator::generate_safept_entry_for( 284 TosState state, 285 address runtime_entry) { 286 address entry = __ pc(); 287 __ push(state); 288 __ call_VM(noreg, runtime_entry); 289 __ membar(Assembler::AnyAny); 290 __ dispatch_via(vtos, Interpreter::_normal_table.table_for(vtos)); 291 return entry; 292 } 293 294 // Helpers for commoning out cases in the various type of method entries. 295 // 296 297 298 // increment invocation count & check for overflow 299 // 300 // Note: checking for negative value instead of overflow 301 // so we have a 'sticky' overflow test 302 // 303 // rmethod: method 304 // 305 void TemplateInterpreterGenerator::generate_counter_incr( 306 Label* overflow, 307 Label* profile_method, 308 Label* profile_method_continue) { 309 Label done; 310 // Note: In tiered we increment either counters in Method* or in MDO depending if we're profiling or not. 311 if (TieredCompilation) { 312 int increment = InvocationCounter::count_increment; 313 Label no_mdo; 314 if (ProfileInterpreter) { 315 // Are we profiling? 316 __ ldr(r0, Address(rmethod, Method::method_data_offset())); 317 __ cbz(r0, no_mdo); 318 // Increment counter in the MDO 319 const Address mdo_invocation_counter(r0, in_bytes(MethodData::invocation_counter_offset()) + 320 in_bytes(InvocationCounter::counter_offset())); 321 const Address mask(r0, in_bytes(MethodData::invoke_mask_offset())); 322 __ increment_mask_and_jump(mdo_invocation_counter, increment, mask, rscratch1, rscratch2, false, Assembler::EQ, overflow); 323 __ b(done); 324 } 325 __ bind(no_mdo); 326 // Increment counter in MethodCounters 327 const Address invocation_counter(rscratch2, 328 MethodCounters::invocation_counter_offset() + 329 InvocationCounter::counter_offset()); 330 __ get_method_counters(rmethod, rscratch2, done); 331 const Address mask(rscratch2, in_bytes(MethodCounters::invoke_mask_offset())); 332 __ increment_mask_and_jump(invocation_counter, increment, mask, rscratch1, r1, false, Assembler::EQ, overflow); 333 __ bind(done); 334 } else { // not TieredCompilation 335 const Address backedge_counter(rscratch2, 336 MethodCounters::backedge_counter_offset() + 337 InvocationCounter::counter_offset()); 338 const Address invocation_counter(rscratch2, 339 MethodCounters::invocation_counter_offset() + 340 InvocationCounter::counter_offset()); 341 342 __ get_method_counters(rmethod, rscratch2, done); 343 344 if (ProfileInterpreter) { // %%% Merge this into MethodData* 345 __ ldrw(r1, Address(rscratch2, MethodCounters::interpreter_invocation_counter_offset())); 346 __ addw(r1, r1, 1); 347 __ strw(r1, Address(rscratch2, MethodCounters::interpreter_invocation_counter_offset())); 348 } 349 // Update standard invocation counters 350 __ ldrw(r1, invocation_counter); 351 __ ldrw(r0, backedge_counter); 352 353 __ addw(r1, r1, InvocationCounter::count_increment); 354 __ andw(r0, r0, InvocationCounter::count_mask_value); 355 356 __ strw(r1, invocation_counter); 357 __ addw(r0, r0, r1); // add both counters 358 359 // profile_method is non-null only for interpreted method so 360 // profile_method != NULL == !native_call 361 362 if (ProfileInterpreter && profile_method != NULL) { 363 // Test to see if we should create a method data oop 364 __ ldr(rscratch2, Address(rmethod, Method::method_counters_offset())); 365 __ ldrw(rscratch2, Address(rscratch2, in_bytes(MethodCounters::interpreter_profile_limit_offset()))); 366 __ cmpw(r0, rscratch2); 367 __ br(Assembler::LT, *profile_method_continue); 368 369 // if no method data exists, go to profile_method 370 __ test_method_data_pointer(r0, *profile_method); 371 } 372 373 { 374 __ ldr(rscratch2, Address(rmethod, Method::method_counters_offset())); 375 __ ldrw(rscratch2, Address(rscratch2, in_bytes(MethodCounters::interpreter_invocation_limit_offset()))); 376 __ cmpw(r0, rscratch2); 377 __ br(Assembler::HS, *overflow); 378 } 379 __ bind(done); 380 } 381 } 382 383 void TemplateInterpreterGenerator::generate_counter_overflow(Label& do_continue) { 384 385 // Asm interpreter on entry 386 // On return (i.e. jump to entry_point) [ back to invocation of interpreter ] 387 // Everything as it was on entry 388 389 // InterpreterRuntime::frequency_counter_overflow takes two 390 // arguments, the first (thread) is passed by call_VM, the second 391 // indicates if the counter overflow occurs at a backwards branch 392 // (NULL bcp). We pass zero for it. The call returns the address 393 // of the verified entry point for the method or NULL if the 394 // compilation did not complete (either went background or bailed 395 // out). 396 __ mov(c_rarg1, 0); 397 __ call_VM(noreg, 398 CAST_FROM_FN_PTR(address, 399 InterpreterRuntime::frequency_counter_overflow), 400 c_rarg1); 401 402 __ b(do_continue); 403 } 404 405 // See if we've got enough room on the stack for locals plus overhead. 406 // The expression stack grows down incrementally, so the normal guard 407 // page mechanism will work for that. 408 // 409 // NOTE: Since the additional locals are also always pushed (wasn't 410 // obvious in generate_method_entry) so the guard should work for them 411 // too. 412 // 413 // Args: 414 // r3: number of additional locals this frame needs (what we must check) 415 // rmethod: Method* 416 // 417 // Kills: 418 // r0 419 void TemplateInterpreterGenerator::generate_stack_overflow_check(void) { 420 421 // monitor entry size: see picture of stack set 422 // (generate_method_entry) and frame_amd64.hpp 423 const int entry_size = frame::interpreter_frame_monitor_size() * wordSize; 424 425 // total overhead size: entry_size + (saved rbp through expr stack 426 // bottom). be sure to change this if you add/subtract anything 427 // to/from the overhead area 428 const int overhead_size = 429 -(frame::interpreter_frame_initial_sp_offset * wordSize) + entry_size; 430 431 const int page_size = os::vm_page_size(); 432 433 Label after_frame_check; 434 435 // see if the frame is greater than one page in size. If so, 436 // then we need to verify there is enough stack space remaining 437 // for the additional locals. 438 // 439 // Note that we use SUBS rather than CMP here because the immediate 440 // field of this instruction may overflow. SUBS can cope with this 441 // because it is a macro that will expand to some number of MOV 442 // instructions and a register operation. 443 __ subs(rscratch1, r3, (page_size - overhead_size) / Interpreter::stackElementSize); 444 __ br(Assembler::LS, after_frame_check); 445 446 // compute rsp as if this were going to be the last frame on 447 // the stack before the red zone 448 449 const Address stack_base(rthread, Thread::stack_base_offset()); 450 const Address stack_size(rthread, Thread::stack_size_offset()); 451 452 // locals + overhead, in bytes 453 __ mov(r0, overhead_size); 454 __ add(r0, r0, r3, Assembler::LSL, Interpreter::logStackElementSize); // 2 slots per parameter. 455 456 __ ldr(rscratch1, stack_base); 457 __ ldr(rscratch2, stack_size); 458 459 #ifdef ASSERT 460 Label stack_base_okay, stack_size_okay; 461 // verify that thread stack base is non-zero 462 __ cbnz(rscratch1, stack_base_okay); 463 __ stop("stack base is zero"); 464 __ bind(stack_base_okay); 465 // verify that thread stack size is non-zero 466 __ cbnz(rscratch2, stack_size_okay); 467 __ stop("stack size is zero"); 468 __ bind(stack_size_okay); 469 #endif 470 471 // Add stack base to locals and subtract stack size 472 __ sub(rscratch1, rscratch1, rscratch2); // Stack limit 473 __ add(r0, r0, rscratch1); 474 475 // Use the maximum number of pages we might bang. 476 const int max_pages = StackShadowPages > (StackRedPages+StackYellowPages) ? StackShadowPages : 477 (StackRedPages+StackYellowPages); 478 479 // add in the red and yellow zone sizes 480 __ add(r0, r0, max_pages * page_size * 2); 481 482 // check against the current stack bottom 483 __ cmp(sp, r0); 484 __ br(Assembler::HI, after_frame_check); 485 486 // Remove the incoming args, peeling the machine SP back to where it 487 // was in the caller. This is not strictly necessary, but unless we 488 // do so the stack frame may have a garbage FP; this ensures a 489 // correct call stack that we can always unwind. The ANDR should be 490 // unnecessary because the sender SP in r13 is always aligned, but 491 // it doesn't hurt. 492 __ andr(sp, r13, -16); 493 494 // Note: the restored frame is not necessarily interpreted. 495 // Use the shared runtime version of the StackOverflowError. 496 assert(StubRoutines::throw_StackOverflowError_entry() != NULL, "stub not yet generated"); 497 __ far_jump(RuntimeAddress(StubRoutines::throw_StackOverflowError_entry())); 498 499 // all done with frame size check 500 __ bind(after_frame_check); 501 } 502 503 // Allocate monitor and lock method (asm interpreter) 504 // 505 // Args: 506 // rmethod: Method* 507 // rlocals: locals 508 // 509 // Kills: 510 // r0 511 // c_rarg0, c_rarg1, c_rarg2, c_rarg3, ...(param regs) 512 // rscratch1, rscratch2 (scratch regs) 513 void TemplateInterpreterGenerator::lock_method() { 514 // synchronize method 515 const Address access_flags(rmethod, Method::access_flags_offset()); 516 const Address monitor_block_top( 517 rfp, 518 frame::interpreter_frame_monitor_block_top_offset * wordSize); 519 const int entry_size = frame::interpreter_frame_monitor_size() * wordSize; 520 521 #ifdef ASSERT 522 { 523 Label L; 524 __ ldrw(r0, access_flags); 525 __ tst(r0, JVM_ACC_SYNCHRONIZED); 526 __ br(Assembler::NE, L); 527 __ stop("method doesn't need synchronization"); 528 __ bind(L); 529 } 530 #endif // ASSERT 531 532 // get synchronization object 533 { 534 const int mirror_offset = in_bytes(Klass::java_mirror_offset()); 535 Label done; 536 __ ldrw(r0, access_flags); 537 __ tst(r0, JVM_ACC_STATIC); 538 // get receiver (assume this is frequent case) 539 __ ldr(r0, Address(rlocals, Interpreter::local_offset_in_bytes(0))); 540 __ br(Assembler::EQ, done); 541 __ ldr(r0, Address(rmethod, Method::const_offset())); 542 __ ldr(r0, Address(r0, ConstMethod::constants_offset())); 543 __ ldr(r0, Address(r0, 544 ConstantPool::pool_holder_offset_in_bytes())); 545 __ ldr(r0, Address(r0, mirror_offset)); 546 547 #ifdef ASSERT 548 { 549 Label L; 550 __ cbnz(r0, L); 551 __ stop("synchronization object is NULL"); 552 __ bind(L); 553 } 554 #endif // ASSERT 555 556 __ bind(done); 557 } 558 559 // add space for monitor & lock 560 __ sub(sp, sp, entry_size); // add space for a monitor entry 561 __ sub(esp, esp, entry_size); 562 __ mov(rscratch1, esp); 563 __ str(rscratch1, monitor_block_top); // set new monitor block top 564 // store object 565 __ str(r0, Address(esp, BasicObjectLock::obj_offset_in_bytes())); 566 __ mov(c_rarg1, esp); // object address 567 __ lock_object(c_rarg1); 568 } 569 570 // Generate a fixed interpreter frame. This is identical setup for 571 // interpreted methods and for native methods hence the shared code. 572 // 573 // Args: 574 // lr: return address 575 // rmethod: Method* 576 // rlocals: pointer to locals 577 // rcpool: cp cache 578 // stack_pointer: previous sp 579 void TemplateInterpreterGenerator::generate_fixed_frame(bool native_call) { 580 // initialize fixed part of activation frame 581 if (native_call) { 582 __ sub(esp, sp, 12 * wordSize); 583 __ mov(rbcp, zr); 584 __ stp(esp, zr, Address(__ pre(sp, -12 * wordSize))); 585 // add 2 zero-initialized slots for native calls 586 __ stp(zr, zr, Address(sp, 10 * wordSize)); 587 } else { 588 __ sub(esp, sp, 10 * wordSize); 589 __ ldr(rscratch1, Address(rmethod, Method::const_offset())); // get ConstMethod 590 __ add(rbcp, rscratch1, in_bytes(ConstMethod::codes_offset())); // get codebase 591 __ stp(esp, rbcp, Address(__ pre(sp, -10 * wordSize))); 592 } 593 594 if (ProfileInterpreter) { 595 Label method_data_continue; 596 __ ldr(rscratch1, Address(rmethod, Method::method_data_offset())); 597 __ cbz(rscratch1, method_data_continue); 598 __ lea(rscratch1, Address(rscratch1, in_bytes(MethodData::data_offset()))); 599 __ bind(method_data_continue); 600 __ stp(rscratch1, rmethod, Address(sp, 4 * wordSize)); // save Method* and mdp (method data pointer) 601 } else { 602 __ stp(zr, rmethod, Address(sp, 4 * wordSize)); // save Method* (no mdp) 603 } 604 605 __ ldr(rcpool, Address(rmethod, Method::const_offset())); 606 __ ldr(rcpool, Address(rcpool, ConstMethod::constants_offset())); 607 __ ldr(rcpool, Address(rcpool, ConstantPool::cache_offset_in_bytes())); 608 __ stp(rlocals, rcpool, Address(sp, 2 * wordSize)); 609 610 __ stp(rfp, lr, Address(sp, 8 * wordSize)); 611 __ lea(rfp, Address(sp, 8 * wordSize)); 612 613 // set sender sp 614 // leave last_sp as null 615 __ stp(zr, r13, Address(sp, 6 * wordSize)); 616 617 // Move SP out of the way 618 if (! native_call) { 619 __ ldr(rscratch1, Address(rmethod, Method::const_offset())); 620 __ ldrh(rscratch1, Address(rscratch1, ConstMethod::max_stack_offset())); 621 __ add(rscratch1, rscratch1, frame::interpreter_frame_monitor_size() + 2); 622 __ sub(rscratch1, sp, rscratch1, ext::uxtw, 3); 623 __ andr(sp, rscratch1, -16); 624 } 625 } 626 627 // End of helpers 628 629 // Various method entries 630 //------------------------------------------------------------------------------------------------------------------------ 631 // 632 // 633 634 // Method entry for java.lang.ref.Reference.get. 635 address TemplateInterpreterGenerator::generate_Reference_get_entry(void) { 636 #if INCLUDE_ALL_GCS 637 // Code: _aload_0, _getfield, _areturn 638 // parameter size = 1 639 // 640 // The code that gets generated by this routine is split into 2 parts: 641 // 1. The "intrinsified" code for G1 (or any SATB based GC), 642 // 2. The slow path - which is an expansion of the regular method entry. 643 // 644 // Notes:- 645 // * In the G1 code we do not check whether we need to block for 646 // a safepoint. If G1 is enabled then we must execute the specialized 647 // code for Reference.get (except when the Reference object is null) 648 // so that we can log the value in the referent field with an SATB 649 // update buffer. 650 // If the code for the getfield template is modified so that the 651 // G1 pre-barrier code is executed when the current method is 652 // Reference.get() then going through the normal method entry 653 // will be fine. 654 // * The G1 code can, however, check the receiver object (the instance 655 // of java.lang.Reference) and jump to the slow path if null. If the 656 // Reference object is null then we obviously cannot fetch the referent 657 // and so we don't need to call the G1 pre-barrier. Thus we can use the 658 // regular method entry code to generate the NPE. 659 // 660 // This code is based on generate_accessor_enty. 661 // 662 // rmethod: Method* 663 // r13: senderSP must preserve for slow path, set SP to it on fast path 664 665 address entry = __ pc(); 666 667 const int referent_offset = java_lang_ref_Reference::referent_offset; 668 guarantee(referent_offset > 0, "referent offset not initialized"); 669 670 if (UseG1GC) { 671 Label slow_path; 672 const Register local_0 = c_rarg0; 673 // Check if local 0 != NULL 674 // If the receiver is null then it is OK to jump to the slow path. 675 __ ldr(local_0, Address(esp, 0)); 676 __ cbz(local_0, slow_path); 677 678 679 // Load the value of the referent field. 680 const Address field_address(local_0, referent_offset); 681 __ load_heap_oop(local_0, field_address); 682 683 // Generate the G1 pre-barrier code to log the value of 684 // the referent field in an SATB buffer. 685 __ enter(); // g1_write may call runtime 686 __ g1_write_barrier_pre(noreg /* obj */, 687 local_0 /* pre_val */, 688 rthread /* thread */, 689 rscratch2 /* tmp */, 690 true /* tosca_live */, 691 true /* expand_call */); 692 __ leave(); 693 // areturn 694 __ andr(sp, r13, -16); // done with stack 695 __ ret(lr); 696 697 // generate a vanilla interpreter entry as the slow path 698 __ bind(slow_path); 699 __ jump_to_entry(Interpreter::entry_for_kind(Interpreter::zerolocals)); 700 return entry; 701 } 702 #endif // INCLUDE_ALL_GCS 703 704 // If G1 is not enabled then attempt to go through the accessor entry point 705 // Reference.get is an accessor 706 return generate_accessor_entry(); 707 } 708 709 /** 710 * Method entry for static native methods: 711 * int java.util.zip.CRC32.update(int crc, int b) 712 */ 713 address TemplateInterpreterGenerator::generate_CRC32_update_entry() { 714 if (UseCRC32Intrinsics) { 715 address entry = __ pc(); 716 717 // rmethod: Method* 718 // r13: senderSP must preserved for slow path 719 // esp: args 720 721 Label slow_path; 722 // If we need a safepoint check, generate full interpreter entry. 723 ExternalAddress state(SafepointSynchronize::address_of_state()); 724 unsigned long offset; 725 __ adrp(rscratch1, ExternalAddress(SafepointSynchronize::address_of_state()), offset); 726 __ ldrw(rscratch1, Address(rscratch1, offset)); 727 assert(SafepointSynchronize::_not_synchronized == 0, "rewrite this code"); 728 __ cbnz(rscratch1, slow_path); 729 730 // We don't generate local frame and don't align stack because 731 // we call stub code and there is no safepoint on this path. 732 733 // Load parameters 734 const Register crc = c_rarg0; // crc 735 const Register val = c_rarg1; // source java byte value 736 const Register tbl = c_rarg2; // scratch 737 738 // Arguments are reversed on java expression stack 739 __ ldrw(val, Address(esp, 0)); // byte value 740 __ ldrw(crc, Address(esp, wordSize)); // Initial CRC 741 742 __ adrp(tbl, ExternalAddress(StubRoutines::crc_table_addr()), offset); 743 __ add(tbl, tbl, offset); 744 745 __ ornw(crc, zr, crc); // ~crc 746 __ update_byte_crc32(crc, val, tbl); 747 __ ornw(crc, zr, crc); // ~crc 748 749 // result in c_rarg0 750 751 __ andr(sp, r13, -16); 752 __ ret(lr); 753 754 // generate a vanilla native entry as the slow path 755 __ bind(slow_path); 756 __ jump_to_entry(Interpreter::entry_for_kind(Interpreter::native)); 757 return entry; 758 } 759 return NULL; 760 } 761 762 /** 763 * Method entry for static native methods: 764 * int java.util.zip.CRC32.updateBytes(int crc, byte[] b, int off, int len) 765 * int java.util.zip.CRC32.updateByteBuffer(int crc, long buf, int off, int len) 766 */ 767 address TemplateInterpreterGenerator::generate_CRC32_updateBytes_entry(AbstractInterpreter::MethodKind kind) { 768 if (UseCRC32Intrinsics) { 769 address entry = __ pc(); 770 771 // rmethod,: Method* 772 // r13: senderSP must preserved for slow path 773 774 Label slow_path; 775 // If we need a safepoint check, generate full interpreter entry. 776 ExternalAddress state(SafepointSynchronize::address_of_state()); 777 unsigned long offset; 778 __ adrp(rscratch1, ExternalAddress(SafepointSynchronize::address_of_state()), offset); 779 __ ldrw(rscratch1, Address(rscratch1, offset)); 780 assert(SafepointSynchronize::_not_synchronized == 0, "rewrite this code"); 781 __ cbnz(rscratch1, slow_path); 782 783 // We don't generate local frame and don't align stack because 784 // we call stub code and there is no safepoint on this path. 785 786 // Load parameters 787 const Register crc = c_rarg0; // crc 788 const Register buf = c_rarg1; // source java byte array address 789 const Register len = c_rarg2; // length 790 const Register off = len; // offset (never overlaps with 'len') 791 792 // Arguments are reversed on java expression stack 793 // Calculate address of start element 794 if (kind == Interpreter::java_util_zip_CRC32_updateByteBuffer) { 795 __ ldr(buf, Address(esp, 2*wordSize)); // long buf 796 __ ldrw(off, Address(esp, wordSize)); // offset 797 __ add(buf, buf, off); // + offset 798 __ ldrw(crc, Address(esp, 4*wordSize)); // Initial CRC 799 } else { 800 __ ldr(buf, Address(esp, 2*wordSize)); // byte[] array 801 __ add(buf, buf, arrayOopDesc::base_offset_in_bytes(T_BYTE)); // + header size 802 __ ldrw(off, Address(esp, wordSize)); // offset 803 __ add(buf, buf, off); // + offset 804 __ ldrw(crc, Address(esp, 3*wordSize)); // Initial CRC 805 } 806 // Can now load 'len' since we're finished with 'off' 807 __ ldrw(len, Address(esp, 0x0)); // Length 808 809 __ andr(sp, r13, -16); // Restore the caller's SP 810 811 // We are frameless so we can just jump to the stub. 812 __ b(CAST_FROM_FN_PTR(address, StubRoutines::updateBytesCRC32())); 813 814 // generate a vanilla native entry as the slow path 815 __ bind(slow_path); 816 __ jump_to_entry(Interpreter::entry_for_kind(Interpreter::native)); 817 return entry; 818 } 819 return NULL; 820 } 821 822 // Not supported 823 address TemplateInterpreterGenerator::generate_CRC32C_updateBytes_entry(AbstractInterpreter::MethodKind kind) { 824 return NULL; 825 } 826 827 void TemplateInterpreterGenerator::bang_stack_shadow_pages(bool native_call) { 828 // Bang each page in the shadow zone. We can't assume it's been done for 829 // an interpreter frame with greater than a page of locals, so each page 830 // needs to be checked. Only true for non-native. 831 if (UseStackBanging) { 832 const int start_page = native_call ? StackShadowPages : 1; 833 const int page_size = os::vm_page_size(); 834 for (int pages = start_page; pages <= StackShadowPages ; pages++) { 835 __ sub(rscratch2, sp, pages*page_size); 836 __ str(zr, Address(rscratch2)); 837 } 838 } 839 } 840 841 842 // Interpreter stub for calling a native method. (asm interpreter) 843 // This sets up a somewhat different looking stack for calling the 844 // native method than the typical interpreter frame setup. 845 address TemplateInterpreterGenerator::generate_native_entry(bool synchronized) { 846 // determine code generation flags 847 bool inc_counter = UseCompiler || CountCompiledCalls || LogTouchedMethods; 848 849 // r1: Method* 850 // rscratch1: sender sp 851 852 address entry_point = __ pc(); 853 854 const Address constMethod (rmethod, Method::const_offset()); 855 const Address access_flags (rmethod, Method::access_flags_offset()); 856 const Address size_of_parameters(r2, ConstMethod:: 857 size_of_parameters_offset()); 858 859 // get parameter size (always needed) 860 __ ldr(r2, constMethod); 861 __ load_unsigned_short(r2, size_of_parameters); 862 863 // native calls don't need the stack size check since they have no 864 // expression stack and the arguments are already on the stack and 865 // we only add a handful of words to the stack 866 867 // rmethod: Method* 868 // r2: size of parameters 869 // rscratch1: sender sp 870 871 // for natives the size of locals is zero 872 873 // compute beginning of parameters (rlocals) 874 __ add(rlocals, esp, r2, ext::uxtx, 3); 875 __ add(rlocals, rlocals, -wordSize); 876 877 // Pull SP back to minimum size: this avoids holes in the stack 878 __ andr(sp, esp, -16); 879 880 // initialize fixed part of activation frame 881 generate_fixed_frame(true); 882 #ifndef PRODUCT 883 // tell the simulator that a method has been entered 884 if (NotifySimulator) { 885 __ notify(Assembler::method_entry); 886 } 887 #endif 888 889 // make sure method is native & not abstract 890 #ifdef ASSERT 891 __ ldrw(r0, access_flags); 892 { 893 Label L; 894 __ tst(r0, JVM_ACC_NATIVE); 895 __ br(Assembler::NE, L); 896 __ stop("tried to execute non-native method as native"); 897 __ bind(L); 898 } 899 { 900 Label L; 901 __ tst(r0, JVM_ACC_ABSTRACT); 902 __ br(Assembler::EQ, L); 903 __ stop("tried to execute abstract method in interpreter"); 904 __ bind(L); 905 } 906 #endif 907 908 // Since at this point in the method invocation the exception 909 // handler would try to exit the monitor of synchronized methods 910 // which hasn't been entered yet, we set the thread local variable 911 // _do_not_unlock_if_synchronized to true. The remove_activation 912 // will check this flag. 913 914 const Address do_not_unlock_if_synchronized(rthread, 915 in_bytes(JavaThread::do_not_unlock_if_synchronized_offset())); 916 __ mov(rscratch2, true); 917 __ strb(rscratch2, do_not_unlock_if_synchronized); 918 919 // increment invocation count & check for overflow 920 Label invocation_counter_overflow; 921 if (inc_counter) { 922 generate_counter_incr(&invocation_counter_overflow, NULL, NULL); 923 } 924 925 Label continue_after_compile; 926 __ bind(continue_after_compile); 927 928 bang_stack_shadow_pages(true); 929 930 // reset the _do_not_unlock_if_synchronized flag 931 __ strb(zr, do_not_unlock_if_synchronized); 932 933 // check for synchronized methods 934 // Must happen AFTER invocation_counter check and stack overflow check, 935 // so method is not locked if overflows. 936 if (synchronized) { 937 lock_method(); 938 } else { 939 // no synchronization necessary 940 #ifdef ASSERT 941 { 942 Label L; 943 __ ldrw(r0, access_flags); 944 __ tst(r0, JVM_ACC_SYNCHRONIZED); 945 __ br(Assembler::EQ, L); 946 __ stop("method needs synchronization"); 947 __ bind(L); 948 } 949 #endif 950 } 951 952 // start execution 953 #ifdef ASSERT 954 { 955 Label L; 956 const Address monitor_block_top(rfp, 957 frame::interpreter_frame_monitor_block_top_offset * wordSize); 958 __ ldr(rscratch1, monitor_block_top); 959 __ cmp(esp, rscratch1); 960 __ br(Assembler::EQ, L); 961 __ stop("broken stack frame setup in interpreter"); 962 __ bind(L); 963 } 964 #endif 965 966 // jvmti support 967 __ notify_method_entry(); 968 969 // work registers 970 const Register t = r17; 971 const Register result_handler = r19; 972 973 // allocate space for parameters 974 __ ldr(t, Address(rmethod, Method::const_offset())); 975 __ load_unsigned_short(t, Address(t, ConstMethod::size_of_parameters_offset())); 976 977 __ sub(rscratch1, esp, t, ext::uxtx, Interpreter::logStackElementSize); 978 __ andr(sp, rscratch1, -16); 979 __ mov(esp, rscratch1); 980 981 // get signature handler 982 { 983 Label L; 984 __ ldr(t, Address(rmethod, Method::signature_handler_offset())); 985 __ cbnz(t, L); 986 __ call_VM(noreg, 987 CAST_FROM_FN_PTR(address, 988 InterpreterRuntime::prepare_native_call), 989 rmethod); 990 __ ldr(t, Address(rmethod, Method::signature_handler_offset())); 991 __ bind(L); 992 } 993 994 // call signature handler 995 assert(InterpreterRuntime::SignatureHandlerGenerator::from() == rlocals, 996 "adjust this code"); 997 assert(InterpreterRuntime::SignatureHandlerGenerator::to() == sp, 998 "adjust this code"); 999 assert(InterpreterRuntime::SignatureHandlerGenerator::temp() == rscratch1, 1000 "adjust this code"); 1001 1002 // The generated handlers do not touch rmethod (the method). 1003 // However, large signatures cannot be cached and are generated 1004 // each time here. The slow-path generator can do a GC on return, 1005 // so we must reload it after the call. 1006 __ blr(t); 1007 __ get_method(rmethod); // slow path can do a GC, reload rmethod 1008 1009 1010 // result handler is in r0 1011 // set result handler 1012 __ mov(result_handler, r0); 1013 // pass mirror handle if static call 1014 { 1015 Label L; 1016 const int mirror_offset = in_bytes(Klass::java_mirror_offset()); 1017 __ ldrw(t, Address(rmethod, Method::access_flags_offset())); 1018 __ tst(t, JVM_ACC_STATIC); 1019 __ br(Assembler::EQ, L); 1020 // get mirror 1021 __ ldr(t, Address(rmethod, Method::const_offset())); 1022 __ ldr(t, Address(t, ConstMethod::constants_offset())); 1023 __ ldr(t, Address(t, ConstantPool::pool_holder_offset_in_bytes())); 1024 __ ldr(t, Address(t, mirror_offset)); 1025 // copy mirror into activation frame 1026 __ str(t, Address(rfp, frame::interpreter_frame_oop_temp_offset * wordSize)); 1027 // pass handle to mirror 1028 __ add(c_rarg1, rfp, frame::interpreter_frame_oop_temp_offset * wordSize); 1029 __ bind(L); 1030 } 1031 1032 // get native function entry point in r10 1033 { 1034 Label L; 1035 __ ldr(r10, Address(rmethod, Method::native_function_offset())); 1036 address unsatisfied = (SharedRuntime::native_method_throw_unsatisfied_link_error_entry()); 1037 __ mov(rscratch2, unsatisfied); 1038 __ ldr(rscratch2, rscratch2); 1039 __ cmp(r10, rscratch2); 1040 __ br(Assembler::NE, L); 1041 __ call_VM(noreg, 1042 CAST_FROM_FN_PTR(address, 1043 InterpreterRuntime::prepare_native_call), 1044 rmethod); 1045 __ get_method(rmethod); 1046 __ ldr(r10, Address(rmethod, Method::native_function_offset())); 1047 __ bind(L); 1048 } 1049 1050 // pass JNIEnv 1051 __ add(c_rarg0, rthread, in_bytes(JavaThread::jni_environment_offset())); 1052 1053 // It is enough that the pc() points into the right code 1054 // segment. It does not have to be the correct return pc. 1055 __ set_last_Java_frame(esp, rfp, (address)NULL, rscratch1); 1056 1057 // change thread state 1058 #ifdef ASSERT 1059 { 1060 Label L; 1061 __ ldrw(t, Address(rthread, JavaThread::thread_state_offset())); 1062 __ cmp(t, _thread_in_Java); 1063 __ br(Assembler::EQ, L); 1064 __ stop("Wrong thread state in native stub"); 1065 __ bind(L); 1066 } 1067 #endif 1068 1069 // Change state to native 1070 __ mov(rscratch1, _thread_in_native); 1071 __ lea(rscratch2, Address(rthread, JavaThread::thread_state_offset())); 1072 __ stlrw(rscratch1, rscratch2); 1073 1074 // Call the native method. 1075 __ blrt(r10, rscratch1); 1076 __ maybe_isb(); 1077 __ get_method(rmethod); 1078 // result potentially in r0 or v0 1079 1080 // make room for the pushes we're about to do 1081 __ sub(rscratch1, esp, 4 * wordSize); 1082 __ andr(sp, rscratch1, -16); 1083 1084 // NOTE: The order of these pushes is known to frame::interpreter_frame_result 1085 // in order to extract the result of a method call. If the order of these 1086 // pushes change or anything else is added to the stack then the code in 1087 // interpreter_frame_result must also change. 1088 __ push(dtos); 1089 __ push(ltos); 1090 1091 // change thread state 1092 __ mov(rscratch1, _thread_in_native_trans); 1093 __ lea(rscratch2, Address(rthread, JavaThread::thread_state_offset())); 1094 __ stlrw(rscratch1, rscratch2); 1095 1096 if (os::is_MP()) { 1097 if (UseMembar) { 1098 // Force this write out before the read below 1099 __ dsb(Assembler::SY); 1100 } else { 1101 // Write serialization page so VM thread can do a pseudo remote membar. 1102 // We use the current thread pointer to calculate a thread specific 1103 // offset to write to within the page. This minimizes bus traffic 1104 // due to cache line collision. 1105 __ serialize_memory(rthread, rscratch2); 1106 } 1107 } 1108 1109 // check for safepoint operation in progress and/or pending suspend requests 1110 { 1111 Label Continue; 1112 { 1113 unsigned long offset; 1114 __ adrp(rscratch2, SafepointSynchronize::address_of_state(), offset); 1115 __ ldrw(rscratch2, Address(rscratch2, offset)); 1116 } 1117 assert(SafepointSynchronize::_not_synchronized == 0, 1118 "SafepointSynchronize::_not_synchronized"); 1119 Label L; 1120 __ cbnz(rscratch2, L); 1121 __ ldrw(rscratch2, Address(rthread, JavaThread::suspend_flags_offset())); 1122 __ cbz(rscratch2, Continue); 1123 __ bind(L); 1124 1125 // Don't use call_VM as it will see a possible pending exception 1126 // and forward it and never return here preventing us from 1127 // clearing _last_native_pc down below. So we do a runtime call by 1128 // hand. 1129 // 1130 __ mov(c_rarg0, rthread); 1131 __ mov(rscratch2, CAST_FROM_FN_PTR(address, JavaThread::check_special_condition_for_native_trans)); 1132 __ blrt(rscratch2, 1, 0, 0); 1133 __ maybe_isb(); 1134 __ get_method(rmethod); 1135 __ reinit_heapbase(); 1136 __ bind(Continue); 1137 } 1138 1139 // change thread state 1140 __ mov(rscratch1, _thread_in_Java); 1141 __ lea(rscratch2, Address(rthread, JavaThread::thread_state_offset())); 1142 __ stlrw(rscratch1, rscratch2); 1143 1144 // reset_last_Java_frame 1145 __ reset_last_Java_frame(true, true); 1146 1147 // reset handle block 1148 __ ldr(t, Address(rthread, JavaThread::active_handles_offset())); 1149 __ str(zr, Address(t, JNIHandleBlock::top_offset_in_bytes())); 1150 1151 // If result is an oop unbox and store it in frame where gc will see it 1152 // and result handler will pick it up 1153 1154 { 1155 Label no_oop, store_result; 1156 __ adr(t, ExternalAddress(AbstractInterpreter::result_handler(T_OBJECT))); 1157 __ cmp(t, result_handler); 1158 __ br(Assembler::NE, no_oop); 1159 // retrieve result 1160 __ pop(ltos); 1161 __ cbz(r0, store_result); 1162 __ ldr(r0, Address(r0, 0)); 1163 __ bind(store_result); 1164 __ str(r0, Address(rfp, frame::interpreter_frame_oop_temp_offset*wordSize)); 1165 // keep stack depth as expected by pushing oop which will eventually be discarded 1166 __ push(ltos); 1167 __ bind(no_oop); 1168 } 1169 1170 { 1171 Label no_reguard; 1172 __ lea(rscratch1, Address(rthread, in_bytes(JavaThread::stack_guard_state_offset()))); 1173 __ ldrb(rscratch1, Address(rscratch1)); 1174 __ cmp(rscratch1, JavaThread::stack_guard_yellow_disabled); 1175 __ br(Assembler::NE, no_reguard); 1176 1177 __ pusha(); // XXX only save smashed registers 1178 __ mov(c_rarg0, rthread); 1179 __ mov(rscratch2, CAST_FROM_FN_PTR(address, SharedRuntime::reguard_yellow_pages)); 1180 __ blrt(rscratch2, 0, 0, 0); 1181 __ popa(); // XXX only restore smashed registers 1182 __ bind(no_reguard); 1183 } 1184 1185 // The method register is junk from after the thread_in_native transition 1186 // until here. Also can't call_VM until the bcp has been 1187 // restored. Need bcp for throwing exception below so get it now. 1188 __ get_method(rmethod); 1189 1190 // restore bcp to have legal interpreter frame, i.e., bci == 0 <=> 1191 // rbcp == code_base() 1192 __ ldr(rbcp, Address(rmethod, Method::const_offset())); // get ConstMethod* 1193 __ add(rbcp, rbcp, in_bytes(ConstMethod::codes_offset())); // get codebase 1194 // handle exceptions (exception handling will handle unlocking!) 1195 { 1196 Label L; 1197 __ ldr(rscratch1, Address(rthread, Thread::pending_exception_offset())); 1198 __ cbz(rscratch1, L); 1199 // Note: At some point we may want to unify this with the code 1200 // used in call_VM_base(); i.e., we should use the 1201 // StubRoutines::forward_exception code. For now this doesn't work 1202 // here because the rsp is not correctly set at this point. 1203 __ MacroAssembler::call_VM(noreg, 1204 CAST_FROM_FN_PTR(address, 1205 InterpreterRuntime::throw_pending_exception)); 1206 __ should_not_reach_here(); 1207 __ bind(L); 1208 } 1209 1210 // do unlocking if necessary 1211 { 1212 Label L; 1213 __ ldrw(t, Address(rmethod, Method::access_flags_offset())); 1214 __ tst(t, JVM_ACC_SYNCHRONIZED); 1215 __ br(Assembler::EQ, L); 1216 // the code below should be shared with interpreter macro 1217 // assembler implementation 1218 { 1219 Label unlock; 1220 // BasicObjectLock will be first in list, since this is a 1221 // synchronized method. However, need to check that the object 1222 // has not been unlocked by an explicit monitorexit bytecode. 1223 1224 // monitor expect in c_rarg1 for slow unlock path 1225 __ lea (c_rarg1, Address(rfp, // address of first monitor 1226 (intptr_t)(frame::interpreter_frame_initial_sp_offset * 1227 wordSize - sizeof(BasicObjectLock)))); 1228 1229 __ ldr(t, Address(c_rarg1, BasicObjectLock::obj_offset_in_bytes())); 1230 __ cbnz(t, unlock); 1231 1232 // Entry already unlocked, need to throw exception 1233 __ MacroAssembler::call_VM(noreg, 1234 CAST_FROM_FN_PTR(address, 1235 InterpreterRuntime::throw_illegal_monitor_state_exception)); 1236 __ should_not_reach_here(); 1237 1238 __ bind(unlock); 1239 __ unlock_object(c_rarg1); 1240 } 1241 __ bind(L); 1242 } 1243 1244 // jvmti support 1245 // Note: This must happen _after_ handling/throwing any exceptions since 1246 // the exception handler code notifies the runtime of method exits 1247 // too. If this happens before, method entry/exit notifications are 1248 // not properly paired (was bug - gri 11/22/99). 1249 __ notify_method_exit(vtos, InterpreterMacroAssembler::NotifyJVMTI); 1250 1251 // restore potential result in r0:d0, call result handler to 1252 // restore potential result in ST0 & handle result 1253 1254 __ pop(ltos); 1255 __ pop(dtos); 1256 1257 __ blr(result_handler); 1258 1259 // remove activation 1260 __ ldr(esp, Address(rfp, 1261 frame::interpreter_frame_sender_sp_offset * 1262 wordSize)); // get sender sp 1263 // remove frame anchor 1264 __ leave(); 1265 1266 // resture sender sp 1267 __ mov(sp, esp); 1268 1269 __ ret(lr); 1270 1271 if (inc_counter) { 1272 // Handle overflow of counter and compile method 1273 __ bind(invocation_counter_overflow); 1274 generate_counter_overflow(continue_after_compile); 1275 } 1276 1277 return entry_point; 1278 } 1279 1280 // 1281 // Generic interpreted method entry to (asm) interpreter 1282 // 1283 address TemplateInterpreterGenerator::generate_normal_entry(bool synchronized) { 1284 // determine code generation flags 1285 bool inc_counter = UseCompiler || CountCompiledCalls || LogTouchedMethods; 1286 1287 // rscratch1: sender sp 1288 address entry_point = __ pc(); 1289 1290 const Address constMethod(rmethod, Method::const_offset()); 1291 const Address access_flags(rmethod, Method::access_flags_offset()); 1292 const Address size_of_parameters(r3, 1293 ConstMethod::size_of_parameters_offset()); 1294 const Address size_of_locals(r3, ConstMethod::size_of_locals_offset()); 1295 1296 // get parameter size (always needed) 1297 // need to load the const method first 1298 __ ldr(r3, constMethod); 1299 __ load_unsigned_short(r2, size_of_parameters); 1300 1301 // r2: size of parameters 1302 1303 __ load_unsigned_short(r3, size_of_locals); // get size of locals in words 1304 __ sub(r3, r3, r2); // r3 = no. of additional locals 1305 1306 // see if we've got enough room on the stack for locals plus overhead. 1307 generate_stack_overflow_check(); 1308 1309 // compute beginning of parameters (rlocals) 1310 __ add(rlocals, esp, r2, ext::uxtx, 3); 1311 __ sub(rlocals, rlocals, wordSize); 1312 1313 // Make room for locals 1314 __ sub(rscratch1, esp, r3, ext::uxtx, 3); 1315 __ andr(sp, rscratch1, -16); 1316 1317 // r3 - # of additional locals 1318 // allocate space for locals 1319 // explicitly initialize locals 1320 { 1321 Label exit, loop; 1322 __ ands(zr, r3, r3); 1323 __ br(Assembler::LE, exit); // do nothing if r3 <= 0 1324 __ bind(loop); 1325 __ str(zr, Address(__ post(rscratch1, wordSize))); 1326 __ sub(r3, r3, 1); // until everything initialized 1327 __ cbnz(r3, loop); 1328 __ bind(exit); 1329 } 1330 1331 // And the base dispatch table 1332 __ get_dispatch(); 1333 1334 // initialize fixed part of activation frame 1335 generate_fixed_frame(false); 1336 #ifndef PRODUCT 1337 // tell the simulator that a method has been entered 1338 if (NotifySimulator) { 1339 __ notify(Assembler::method_entry); 1340 } 1341 #endif 1342 // make sure method is not native & not abstract 1343 #ifdef ASSERT 1344 __ ldrw(r0, access_flags); 1345 { 1346 Label L; 1347 __ tst(r0, JVM_ACC_NATIVE); 1348 __ br(Assembler::EQ, L); 1349 __ stop("tried to execute native method as non-native"); 1350 __ bind(L); 1351 } 1352 { 1353 Label L; 1354 __ tst(r0, JVM_ACC_ABSTRACT); 1355 __ br(Assembler::EQ, L); 1356 __ stop("tried to execute abstract method in interpreter"); 1357 __ bind(L); 1358 } 1359 #endif 1360 1361 // Since at this point in the method invocation the exception 1362 // handler would try to exit the monitor of synchronized methods 1363 // which hasn't been entered yet, we set the thread local variable 1364 // _do_not_unlock_if_synchronized to true. The remove_activation 1365 // will check this flag. 1366 1367 const Address do_not_unlock_if_synchronized(rthread, 1368 in_bytes(JavaThread::do_not_unlock_if_synchronized_offset())); 1369 __ mov(rscratch2, true); 1370 __ strb(rscratch2, do_not_unlock_if_synchronized); 1371 1372 // increment invocation count & check for overflow 1373 Label invocation_counter_overflow; 1374 Label profile_method; 1375 Label profile_method_continue; 1376 if (inc_counter) { 1377 generate_counter_incr(&invocation_counter_overflow, 1378 &profile_method, 1379 &profile_method_continue); 1380 if (ProfileInterpreter) { 1381 __ bind(profile_method_continue); 1382 } 1383 } 1384 1385 Label continue_after_compile; 1386 __ bind(continue_after_compile); 1387 1388 bang_stack_shadow_pages(false); 1389 1390 // reset the _do_not_unlock_if_synchronized flag 1391 __ strb(zr, do_not_unlock_if_synchronized); 1392 1393 // check for synchronized methods 1394 // Must happen AFTER invocation_counter check and stack overflow check, 1395 // so method is not locked if overflows. 1396 if (synchronized) { 1397 // Allocate monitor and lock method 1398 lock_method(); 1399 } else { 1400 // no synchronization necessary 1401 #ifdef ASSERT 1402 { 1403 Label L; 1404 __ ldrw(r0, access_flags); 1405 __ tst(r0, JVM_ACC_SYNCHRONIZED); 1406 __ br(Assembler::EQ, L); 1407 __ stop("method needs synchronization"); 1408 __ bind(L); 1409 } 1410 #endif 1411 } 1412 1413 // start execution 1414 #ifdef ASSERT 1415 { 1416 Label L; 1417 const Address monitor_block_top (rfp, 1418 frame::interpreter_frame_monitor_block_top_offset * wordSize); 1419 __ ldr(rscratch1, monitor_block_top); 1420 __ cmp(esp, rscratch1); 1421 __ br(Assembler::EQ, L); 1422 __ stop("broken stack frame setup in interpreter"); 1423 __ bind(L); 1424 } 1425 #endif 1426 1427 // jvmti support 1428 __ notify_method_entry(); 1429 1430 __ dispatch_next(vtos); 1431 1432 // invocation counter overflow 1433 if (inc_counter) { 1434 if (ProfileInterpreter) { 1435 // We have decided to profile this method in the interpreter 1436 __ bind(profile_method); 1437 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::profile_method)); 1438 __ set_method_data_pointer_for_bcp(); 1439 // don't think we need this 1440 __ get_method(r1); 1441 __ b(profile_method_continue); 1442 } 1443 // Handle overflow of counter and compile method 1444 __ bind(invocation_counter_overflow); 1445 generate_counter_overflow(continue_after_compile); 1446 } 1447 1448 return entry_point; 1449 } 1450 1451 //----------------------------------------------------------------------------- 1452 // Exceptions 1453 1454 void TemplateInterpreterGenerator::generate_throw_exception() { 1455 // Entry point in previous activation (i.e., if the caller was 1456 // interpreted) 1457 Interpreter::_rethrow_exception_entry = __ pc(); 1458 // Restore sp to interpreter_frame_last_sp even though we are going 1459 // to empty the expression stack for the exception processing. 1460 __ str(zr, Address(rfp, frame::interpreter_frame_last_sp_offset * wordSize)); 1461 // r0: exception 1462 // r3: return address/pc that threw exception 1463 __ restore_bcp(); // rbcp points to call/send 1464 __ restore_locals(); 1465 __ restore_constant_pool_cache(); 1466 __ reinit_heapbase(); // restore rheapbase as heapbase. 1467 __ get_dispatch(); 1468 1469 #ifndef PRODUCT 1470 // tell the simulator that the caller method has been reentered 1471 if (NotifySimulator) { 1472 __ get_method(rmethod); 1473 __ notify(Assembler::method_reentry); 1474 } 1475 #endif 1476 // Entry point for exceptions thrown within interpreter code 1477 Interpreter::_throw_exception_entry = __ pc(); 1478 // If we came here via a NullPointerException on the receiver of a 1479 // method, rmethod may be corrupt. 1480 __ get_method(rmethod); 1481 // expression stack is undefined here 1482 // r0: exception 1483 // rbcp: exception bcp 1484 __ verify_oop(r0); 1485 __ mov(c_rarg1, r0); 1486 1487 // expression stack must be empty before entering the VM in case of 1488 // an exception 1489 __ empty_expression_stack(); 1490 // find exception handler address and preserve exception oop 1491 __ call_VM(r3, 1492 CAST_FROM_FN_PTR(address, 1493 InterpreterRuntime::exception_handler_for_exception), 1494 c_rarg1); 1495 1496 // Calculate stack limit 1497 __ ldr(rscratch1, Address(rmethod, Method::const_offset())); 1498 __ ldrh(rscratch1, Address(rscratch1, ConstMethod::max_stack_offset())); 1499 __ add(rscratch1, rscratch1, frame::interpreter_frame_monitor_size() + 4); 1500 __ ldr(rscratch2, 1501 Address(rfp, frame::interpreter_frame_initial_sp_offset * wordSize)); 1502 __ sub(rscratch1, rscratch2, rscratch1, ext::uxtx, 3); 1503 __ andr(sp, rscratch1, -16); 1504 1505 // r0: exception handler entry point 1506 // r3: preserved exception oop 1507 // rbcp: bcp for exception handler 1508 __ push_ptr(r3); // push exception which is now the only value on the stack 1509 __ br(r0); // jump to exception handler (may be _remove_activation_entry!) 1510 1511 // If the exception is not handled in the current frame the frame is 1512 // removed and the exception is rethrown (i.e. exception 1513 // continuation is _rethrow_exception). 1514 // 1515 // Note: At this point the bci is still the bxi for the instruction 1516 // which caused the exception and the expression stack is 1517 // empty. Thus, for any VM calls at this point, GC will find a legal 1518 // oop map (with empty expression stack). 1519 1520 // 1521 // JVMTI PopFrame support 1522 // 1523 1524 Interpreter::_remove_activation_preserving_args_entry = __ pc(); 1525 __ empty_expression_stack(); 1526 // Set the popframe_processing bit in pending_popframe_condition 1527 // indicating that we are currently handling popframe, so that 1528 // call_VMs that may happen later do not trigger new popframe 1529 // handling cycles. 1530 __ ldrw(r3, Address(rthread, JavaThread::popframe_condition_offset())); 1531 __ orr(r3, r3, JavaThread::popframe_processing_bit); 1532 __ strw(r3, Address(rthread, JavaThread::popframe_condition_offset())); 1533 1534 { 1535 // Check to see whether we are returning to a deoptimized frame. 1536 // (The PopFrame call ensures that the caller of the popped frame is 1537 // either interpreted or compiled and deoptimizes it if compiled.) 1538 // In this case, we can't call dispatch_next() after the frame is 1539 // popped, but instead must save the incoming arguments and restore 1540 // them after deoptimization has occurred. 1541 // 1542 // Note that we don't compare the return PC against the 1543 // deoptimization blob's unpack entry because of the presence of 1544 // adapter frames in C2. 1545 Label caller_not_deoptimized; 1546 __ ldr(c_rarg1, Address(rfp, frame::return_addr_offset * wordSize)); 1547 __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, 1548 InterpreterRuntime::interpreter_contains), c_rarg1); 1549 __ cbnz(r0, caller_not_deoptimized); 1550 1551 // Compute size of arguments for saving when returning to 1552 // deoptimized caller 1553 __ get_method(r0); 1554 __ ldr(r0, Address(r0, Method::const_offset())); 1555 __ load_unsigned_short(r0, Address(r0, in_bytes(ConstMethod:: 1556 size_of_parameters_offset()))); 1557 __ lsl(r0, r0, Interpreter::logStackElementSize); 1558 __ restore_locals(); // XXX do we need this? 1559 __ sub(rlocals, rlocals, r0); 1560 __ add(rlocals, rlocals, wordSize); 1561 // Save these arguments 1562 __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, 1563 Deoptimization:: 1564 popframe_preserve_args), 1565 rthread, r0, rlocals); 1566 1567 __ remove_activation(vtos, 1568 /* throw_monitor_exception */ false, 1569 /* install_monitor_exception */ false, 1570 /* notify_jvmdi */ false); 1571 1572 // Inform deoptimization that it is responsible for restoring 1573 // these arguments 1574 __ mov(rscratch1, JavaThread::popframe_force_deopt_reexecution_bit); 1575 __ strw(rscratch1, Address(rthread, JavaThread::popframe_condition_offset())); 1576 1577 // Continue in deoptimization handler 1578 __ ret(lr); 1579 1580 __ bind(caller_not_deoptimized); 1581 } 1582 1583 __ remove_activation(vtos, 1584 /* throw_monitor_exception */ false, 1585 /* install_monitor_exception */ false, 1586 /* notify_jvmdi */ false); 1587 1588 // Restore the last_sp and null it out 1589 __ ldr(esp, Address(rfp, frame::interpreter_frame_last_sp_offset * wordSize)); 1590 __ str(zr, Address(rfp, frame::interpreter_frame_last_sp_offset * wordSize)); 1591 1592 __ restore_bcp(); 1593 __ restore_locals(); 1594 __ restore_constant_pool_cache(); 1595 __ get_method(rmethod); 1596 1597 // The method data pointer was incremented already during 1598 // call profiling. We have to restore the mdp for the current bcp. 1599 if (ProfileInterpreter) { 1600 __ set_method_data_pointer_for_bcp(); 1601 } 1602 1603 // Clear the popframe condition flag 1604 __ strw(zr, Address(rthread, JavaThread::popframe_condition_offset())); 1605 assert(JavaThread::popframe_inactive == 0, "fix popframe_inactive"); 1606 1607 #if INCLUDE_JVMTI 1608 { 1609 Label L_done; 1610 1611 __ ldrb(rscratch1, Address(rbcp, 0)); 1612 __ cmpw(r1, Bytecodes::_invokestatic); 1613 __ br(Assembler::EQ, L_done); 1614 1615 // The member name argument must be restored if _invokestatic is re-executed after a PopFrame call. 1616 // Detect such a case in the InterpreterRuntime function and return the member name argument, or NULL. 1617 1618 __ ldr(c_rarg0, Address(rlocals, 0)); 1619 __ call_VM(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::member_name_arg_or_null), c_rarg0, rmethod, rbcp); 1620 1621 __ cbz(r0, L_done); 1622 1623 __ str(r0, Address(esp, 0)); 1624 __ bind(L_done); 1625 } 1626 #endif // INCLUDE_JVMTI 1627 1628 // Restore machine SP 1629 __ ldr(rscratch1, Address(rmethod, Method::const_offset())); 1630 __ ldrh(rscratch1, Address(rscratch1, ConstMethod::max_stack_offset())); 1631 __ add(rscratch1, rscratch1, frame::interpreter_frame_monitor_size() + 4); 1632 __ ldr(rscratch2, 1633 Address(rfp, frame::interpreter_frame_initial_sp_offset * wordSize)); 1634 __ sub(rscratch1, rscratch2, rscratch1, ext::uxtw, 3); 1635 __ andr(sp, rscratch1, -16); 1636 1637 __ dispatch_next(vtos); 1638 // end of PopFrame support 1639 1640 Interpreter::_remove_activation_entry = __ pc(); 1641 1642 // preserve exception over this code sequence 1643 __ pop_ptr(r0); 1644 __ str(r0, Address(rthread, JavaThread::vm_result_offset())); 1645 // remove the activation (without doing throws on illegalMonitorExceptions) 1646 __ remove_activation(vtos, false, true, false); 1647 // restore exception 1648 // restore exception 1649 __ get_vm_result(r0, rthread); 1650 1651 // In between activations - previous activation type unknown yet 1652 // compute continuation point - the continuation point expects the 1653 // following registers set up: 1654 // 1655 // r0: exception 1656 // lr: return address/pc that threw exception 1657 // rsp: expression stack of caller 1658 // rfp: fp of caller 1659 // FIXME: There's no point saving LR here because VM calls don't trash it 1660 __ stp(r0, lr, Address(__ pre(sp, -2 * wordSize))); // save exception & return address 1661 __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, 1662 SharedRuntime::exception_handler_for_return_address), 1663 rthread, lr); 1664 __ mov(r1, r0); // save exception handler 1665 __ ldp(r0, lr, Address(__ post(sp, 2 * wordSize))); // restore exception & return address 1666 // We might be returning to a deopt handler that expects r3 to 1667 // contain the exception pc 1668 __ mov(r3, lr); 1669 // Note that an "issuing PC" is actually the next PC after the call 1670 __ br(r1); // jump to exception 1671 // handler of caller 1672 } 1673 1674 1675 // 1676 // JVMTI ForceEarlyReturn support 1677 // 1678 address TemplateInterpreterGenerator::generate_earlyret_entry_for(TosState state) { 1679 address entry = __ pc(); 1680 1681 __ restore_bcp(); 1682 __ restore_locals(); 1683 __ empty_expression_stack(); 1684 __ load_earlyret_value(state); 1685 1686 __ ldr(rscratch1, Address(rthread, JavaThread::jvmti_thread_state_offset())); 1687 Address cond_addr(rscratch1, JvmtiThreadState::earlyret_state_offset()); 1688 1689 // Clear the earlyret state 1690 assert(JvmtiThreadState::earlyret_inactive == 0, "should be"); 1691 __ str(zr, cond_addr); 1692 1693 __ remove_activation(state, 1694 false, /* throw_monitor_exception */ 1695 false, /* install_monitor_exception */ 1696 true); /* notify_jvmdi */ 1697 __ ret(lr); 1698 1699 return entry; 1700 } // end of ForceEarlyReturn support 1701 1702 1703 1704 //----------------------------------------------------------------------------- 1705 // Helper for vtos entry point generation 1706 1707 void TemplateInterpreterGenerator::set_vtos_entry_points(Template* t, 1708 address& bep, 1709 address& cep, 1710 address& sep, 1711 address& aep, 1712 address& iep, 1713 address& lep, 1714 address& fep, 1715 address& dep, 1716 address& vep) { 1717 assert(t->is_valid() && t->tos_in() == vtos, "illegal template"); 1718 Label L; 1719 aep = __ pc(); __ push_ptr(); __ b(L); 1720 fep = __ pc(); __ push_f(); __ b(L); 1721 dep = __ pc(); __ push_d(); __ b(L); 1722 lep = __ pc(); __ push_l(); __ b(L); 1723 bep = cep = sep = 1724 iep = __ pc(); __ push_i(); 1725 vep = __ pc(); 1726 __ bind(L); 1727 generate_and_dispatch(t); 1728 } 1729 1730 //----------------------------------------------------------------------------- 1731 1732 // Non-product code 1733 #ifndef PRODUCT 1734 address TemplateInterpreterGenerator::generate_trace_code(TosState state) { 1735 address entry = __ pc(); 1736 1737 __ push(lr); 1738 __ push(state); 1739 __ push(RegSet::range(r0, r15), sp); 1740 __ mov(c_rarg2, r0); // Pass itos 1741 __ call_VM(noreg, 1742 CAST_FROM_FN_PTR(address, SharedRuntime::trace_bytecode), 1743 c_rarg1, c_rarg2, c_rarg3); 1744 __ pop(RegSet::range(r0, r15), sp); 1745 __ pop(state); 1746 __ pop(lr); 1747 __ ret(lr); // return from result handler 1748 1749 return entry; 1750 } 1751 1752 void TemplateInterpreterGenerator::count_bytecode() { 1753 Register rscratch3 = r0; 1754 __ push(rscratch1); 1755 __ push(rscratch2); 1756 __ push(rscratch3); 1757 Label L; 1758 __ mov(rscratch2, (address) &BytecodeCounter::_counter_value); 1759 __ bind(L); 1760 __ ldxr(rscratch1, rscratch2); 1761 __ add(rscratch1, rscratch1, 1); 1762 __ stxr(rscratch3, rscratch1, rscratch2); 1763 __ cbnzw(rscratch3, L); 1764 __ pop(rscratch3); 1765 __ pop(rscratch2); 1766 __ pop(rscratch1); 1767 } 1768 1769 void TemplateInterpreterGenerator::histogram_bytecode(Template* t) { ; } 1770 1771 void TemplateInterpreterGenerator::histogram_bytecode_pair(Template* t) { ; } 1772 1773 1774 void TemplateInterpreterGenerator::trace_bytecode(Template* t) { 1775 // Call a little run-time stub to avoid blow-up for each bytecode. 1776 // The run-time runtime saves the right registers, depending on 1777 // the tosca in-state for the given template. 1778 1779 assert(Interpreter::trace_code(t->tos_in()) != NULL, 1780 "entry must have been generated"); 1781 __ bl(Interpreter::trace_code(t->tos_in())); 1782 __ reinit_heapbase(); 1783 } 1784 1785 1786 void TemplateInterpreterGenerator::stop_interpreter_at() { 1787 Label L; 1788 __ push(rscratch1); 1789 __ mov(rscratch1, (address) &BytecodeCounter::_counter_value); 1790 __ ldr(rscratch1, Address(rscratch1)); 1791 __ mov(rscratch2, StopInterpreterAt); 1792 __ cmpw(rscratch1, rscratch2); 1793 __ br(Assembler::NE, L); 1794 __ brk(0); 1795 __ bind(L); 1796 __ pop(rscratch1); 1797 } 1798 1799 #ifdef BUILTIN_SIM 1800 1801 #include <sys/mman.h> 1802 #include <unistd.h> 1803 1804 extern "C" { 1805 static int PAGESIZE = getpagesize(); 1806 int is_mapped_address(u_int64_t address) 1807 { 1808 address = (address & ~((u_int64_t)PAGESIZE - 1)); 1809 if (msync((void *)address, PAGESIZE, MS_ASYNC) == 0) { 1810 return true; 1811 } 1812 if (errno != ENOMEM) { 1813 return true; 1814 } 1815 return false; 1816 } 1817 1818 void bccheck1(u_int64_t pc, u_int64_t fp, char *method, int *bcidx, int *framesize, char *decode) 1819 { 1820 if (method != 0) { 1821 method[0] = '\0'; 1822 } 1823 if (bcidx != 0) { 1824 *bcidx = -2; 1825 } 1826 if (decode != 0) { 1827 decode[0] = 0; 1828 } 1829 1830 if (framesize != 0) { 1831 *framesize = -1; 1832 } 1833 1834 if (Interpreter::contains((address)pc)) { 1835 AArch64Simulator *sim = AArch64Simulator::get_current(UseSimulatorCache, DisableBCCheck); 1836 Method* meth; 1837 address bcp; 1838 if (fp) { 1839 #define FRAME_SLOT_METHOD 3 1840 #define FRAME_SLOT_BCP 7 1841 meth = (Method*)sim->getMemory()->loadU64(fp - (FRAME_SLOT_METHOD << 3)); 1842 bcp = (address)sim->getMemory()->loadU64(fp - (FRAME_SLOT_BCP << 3)); 1843 #undef FRAME_SLOT_METHOD 1844 #undef FRAME_SLOT_BCP 1845 } else { 1846 meth = (Method*)sim->getCPUState().xreg(RMETHOD, 0); 1847 bcp = (address)sim->getCPUState().xreg(RBCP, 0); 1848 } 1849 if (meth->is_native()) { 1850 return; 1851 } 1852 if(method && meth->is_method()) { 1853 ResourceMark rm; 1854 method[0] = 'I'; 1855 method[1] = ' '; 1856 meth->name_and_sig_as_C_string(method + 2, 398); 1857 } 1858 if (bcidx) { 1859 if (meth->contains(bcp)) { 1860 *bcidx = meth->bci_from(bcp); 1861 } else { 1862 *bcidx = -2; 1863 } 1864 } 1865 if (decode) { 1866 if (!BytecodeTracer::closure()) { 1867 BytecodeTracer::set_closure(BytecodeTracer::std_closure()); 1868 } 1869 stringStream str(decode, 400); 1870 BytecodeTracer::trace(meth, bcp, &str); 1871 } 1872 } else { 1873 if (method) { 1874 CodeBlob *cb = CodeCache::find_blob((address)pc); 1875 if (cb != NULL) { 1876 if (cb->is_nmethod()) { 1877 ResourceMark rm; 1878 nmethod* nm = (nmethod*)cb; 1879 method[0] = 'C'; 1880 method[1] = ' '; 1881 nm->method()->name_and_sig_as_C_string(method + 2, 398); 1882 } else if (cb->is_adapter_blob()) { 1883 strcpy(method, "B adapter blob"); 1884 } else if (cb->is_runtime_stub()) { 1885 strcpy(method, "B runtime stub"); 1886 } else if (cb->is_exception_stub()) { 1887 strcpy(method, "B exception stub"); 1888 } else if (cb->is_deoptimization_stub()) { 1889 strcpy(method, "B deoptimization stub"); 1890 } else if (cb->is_safepoint_stub()) { 1891 strcpy(method, "B safepoint stub"); 1892 } else if (cb->is_uncommon_trap_stub()) { 1893 strcpy(method, "B uncommon trap stub"); 1894 } else if (cb->contains((address)StubRoutines::call_stub())) { 1895 strcpy(method, "B call stub"); 1896 } else { 1897 strcpy(method, "B unknown blob : "); 1898 strcat(method, cb->name()); 1899 } 1900 if (framesize != NULL) { 1901 *framesize = cb->frame_size(); 1902 } 1903 } 1904 } 1905 } 1906 } 1907 1908 1909 JNIEXPORT void bccheck(u_int64_t pc, u_int64_t fp, char *method, int *bcidx, int *framesize, char *decode) 1910 { 1911 bccheck1(pc, fp, method, bcidx, framesize, decode); 1912 } 1913 } 1914 1915 #endif // BUILTIN_SIM 1916 #endif // !PRODUCT