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 #ifndef _WINDOWS
27 #include "alloca.h"
28 #endif
29 #include "asm/macroAssembler.hpp"
30 #include "asm/macroAssembler.inline.hpp"
31 #include "code/debugInfoRec.hpp"
32 #include "code/icBuffer.hpp"
33 #include "code/vtableStubs.hpp"
34 #include "interpreter/interpreter.hpp"
35 #include "logging/log.hpp"
36 #include "memory/resourceArea.hpp"
37 #include "oops/compiledICHolder.hpp"
38 #include "runtime/sharedRuntime.hpp"
39 #include "runtime/vframeArray.hpp"
40 #include "utilities/align.hpp"
41 #include "vm_version_x86.hpp"
42 #include "vmreg_x86.inline.hpp"
43 #ifdef COMPILER1
44 #include "c1/c1_Runtime1.hpp"
45 #endif
46 #ifdef COMPILER2
47 #include "opto/runtime.hpp"
48 #endif
49 #if INCLUDE_JVMCI
50 #include "jvmci/jvmciJavaClasses.hpp"
51 #endif
52
2457 if(os::is_MP()) {
2458 if (UseMembar) {
2459 // Force this write out before the read below
2460 __ membar(Assembler::Membar_mask_bits(
2461 Assembler::LoadLoad | Assembler::LoadStore |
2462 Assembler::StoreLoad | Assembler::StoreStore));
2463 } else {
2464 // Write serialization page so VM thread can do a pseudo remote membar.
2465 // We use the current thread pointer to calculate a thread specific
2466 // offset to write to within the page. This minimizes bus traffic
2467 // due to cache line collision.
2468 __ serialize_memory(r15_thread, rcx);
2469 }
2470 }
2471
2472 Label after_transition;
2473
2474 // check for safepoint operation in progress and/or pending suspend requests
2475 {
2476 Label Continue;
2477
2478 __ cmp32(ExternalAddress((address)SafepointSynchronize::address_of_state()),
2479 SafepointSynchronize::_not_synchronized);
2480
2481 Label L;
2482 __ jcc(Assembler::notEqual, L);
2483 __ cmpl(Address(r15_thread, JavaThread::suspend_flags_offset()), 0);
2484 __ jcc(Assembler::equal, Continue);
2485 __ bind(L);
2486
2487 // Don't use call_VM as it will see a possible pending exception and forward it
2488 // and never return here preventing us from clearing _last_native_pc down below.
2489 // Also can't use call_VM_leaf either as it will check to see if rsi & rdi are
2490 // preserved and correspond to the bcp/locals pointers. So we do a runtime call
2491 // by hand.
2492 //
2493 __ vzeroupper();
2494 save_native_result(masm, ret_type, stack_slots);
2495 __ mov(c_rarg0, r15_thread);
2496 __ mov(r12, rsp); // remember sp
2497 __ subptr(rsp, frame::arg_reg_save_area_bytes); // windows
2498 __ andptr(rsp, -16); // align stack as required by ABI
2499 if (!is_critical_native) {
2500 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, JavaThread::check_special_condition_for_native_trans)));
2501 } else {
2502 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, JavaThread::check_special_condition_for_native_trans_and_transition)));
2503 }
2504 __ mov(rsp, r12); // restore sp
2505 __ reinit_heapbase();
3338 }
3339
3340 // Make room for return address (or push it again)
3341 if (!cause_return) {
3342 __ push(rbx);
3343 }
3344
3345 // Save registers, fpu state, and flags
3346 map = RegisterSaver::save_live_registers(masm, 0, &frame_size_in_words, save_vectors);
3347
3348 // The following is basically a call_VM. However, we need the precise
3349 // address of the call in order to generate an oopmap. Hence, we do all the
3350 // work outselves.
3351
3352 __ set_last_Java_frame(noreg, noreg, NULL);
3353
3354 // The return address must always be correct so that frame constructor never
3355 // sees an invalid pc.
3356
3357 if (!cause_return) {
3358 // overwrite the dummy value we pushed on entry
3359 __ movptr(c_rarg0, Address(r15_thread, JavaThread::saved_exception_pc_offset()));
3360 __ movptr(Address(rbp, wordSize), c_rarg0);
3361 }
3362
3363 // Do the call
3364 __ mov(c_rarg0, r15_thread);
3365 __ call(RuntimeAddress(call_ptr));
3366
3367 // Set an oopmap for the call site. This oopmap will map all
3368 // oop-registers and debug-info registers as callee-saved. This
3369 // will allow deoptimization at this safepoint to find all possible
3370 // debug-info recordings, as well as let GC find all oops.
3371
3372 oop_maps->add_gc_map( __ pc() - start, map);
3373
3374 Label noException;
3375
3376 __ reset_last_Java_frame(false);
3377
3378 __ cmpptr(Address(r15_thread, Thread::pending_exception_offset()), (int32_t)NULL_WORD);
3379 __ jcc(Assembler::equal, noException);
3380
3381 // Exception pending
3382
3383 RegisterSaver::restore_live_registers(masm, save_vectors);
3384
3385 __ jump(RuntimeAddress(StubRoutines::forward_exception_entry()));
3386
3387 // No exception case
3388 __ bind(noException);
3389
3390 // Normal exit, restore registers and exit.
3391 RegisterSaver::restore_live_registers(masm, save_vectors);
3392
3393 __ ret(0);
3394
3395 // Make sure all code is generated
3396 masm->flush();
3397
3398 // Fill-out other meta info
3399 return SafepointBlob::create(&buffer, oop_maps, frame_size_in_words);
3400 }
3401
3402 //
3403 // generate_resolve_blob - call resolution (static/virtual/opt-virtual/ic-miss
3404 //
3405 // Generate a stub that calls into vm to find out the proper destination
3406 // of a java call. All the argument registers are live at this point
3407 // but since this is generic code we don't know what they are and the caller
3408 // must do any gc of the args.
3409 //
3410 RuntimeStub* SharedRuntime::generate_resolve_blob(address destination, const char* name) {
3411 assert (StubRoutines::forward_exception_entry() != NULL, "must be generated before");
3412
3413 // allocate space for the code
|
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 #ifndef _WINDOWS
27 #include "alloca.h"
28 #endif
29 #include "asm/macroAssembler.hpp"
30 #include "asm/macroAssembler.inline.hpp"
31 #include "code/debugInfoRec.hpp"
32 #include "code/icBuffer.hpp"
33 #include "code/nativeInst.hpp"
34 #include "code/vtableStubs.hpp"
35 #include "interpreter/interpreter.hpp"
36 #include "logging/log.hpp"
37 #include "memory/resourceArea.hpp"
38 #include "oops/compiledICHolder.hpp"
39 #include "runtime/sharedRuntime.hpp"
40 #include "runtime/vframeArray.hpp"
41 #include "utilities/align.hpp"
42 #include "vm_version_x86.hpp"
43 #include "vmreg_x86.inline.hpp"
44 #ifdef COMPILER1
45 #include "c1/c1_Runtime1.hpp"
46 #endif
47 #ifdef COMPILER2
48 #include "opto/runtime.hpp"
49 #endif
50 #if INCLUDE_JVMCI
51 #include "jvmci/jvmciJavaClasses.hpp"
52 #endif
53
2458 if(os::is_MP()) {
2459 if (UseMembar) {
2460 // Force this write out before the read below
2461 __ membar(Assembler::Membar_mask_bits(
2462 Assembler::LoadLoad | Assembler::LoadStore |
2463 Assembler::StoreLoad | Assembler::StoreStore));
2464 } else {
2465 // Write serialization page so VM thread can do a pseudo remote membar.
2466 // We use the current thread pointer to calculate a thread specific
2467 // offset to write to within the page. This minimizes bus traffic
2468 // due to cache line collision.
2469 __ serialize_memory(r15_thread, rcx);
2470 }
2471 }
2472
2473 Label after_transition;
2474
2475 // check for safepoint operation in progress and/or pending suspend requests
2476 {
2477 Label Continue;
2478 Label slow_path;
2479
2480 __ safepoint_poll(slow_path, r15_thread, rscratch1);
2481
2482 __ cmpl(Address(r15_thread, JavaThread::suspend_flags_offset()), 0);
2483 __ jcc(Assembler::equal, Continue);
2484 __ bind(slow_path);
2485
2486 // Don't use call_VM as it will see a possible pending exception and forward it
2487 // and never return here preventing us from clearing _last_native_pc down below.
2488 // Also can't use call_VM_leaf either as it will check to see if rsi & rdi are
2489 // preserved and correspond to the bcp/locals pointers. So we do a runtime call
2490 // by hand.
2491 //
2492 __ vzeroupper();
2493 save_native_result(masm, ret_type, stack_slots);
2494 __ mov(c_rarg0, r15_thread);
2495 __ mov(r12, rsp); // remember sp
2496 __ subptr(rsp, frame::arg_reg_save_area_bytes); // windows
2497 __ andptr(rsp, -16); // align stack as required by ABI
2498 if (!is_critical_native) {
2499 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, JavaThread::check_special_condition_for_native_trans)));
2500 } else {
2501 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, JavaThread::check_special_condition_for_native_trans_and_transition)));
2502 }
2503 __ mov(rsp, r12); // restore sp
2504 __ reinit_heapbase();
3337 }
3338
3339 // Make room for return address (or push it again)
3340 if (!cause_return) {
3341 __ push(rbx);
3342 }
3343
3344 // Save registers, fpu state, and flags
3345 map = RegisterSaver::save_live_registers(masm, 0, &frame_size_in_words, save_vectors);
3346
3347 // The following is basically a call_VM. However, we need the precise
3348 // address of the call in order to generate an oopmap. Hence, we do all the
3349 // work outselves.
3350
3351 __ set_last_Java_frame(noreg, noreg, NULL);
3352
3353 // The return address must always be correct so that frame constructor never
3354 // sees an invalid pc.
3355
3356 if (!cause_return) {
3357 // Get the return pc saved by the signal handler and stash it in its appropriate place on the stack.
3358 // Additionally, rbx is a callee saved register and we can look at it later to determine
3359 // if someone changed the return address for us!
3360 __ movptr(rbx, Address(r15_thread, JavaThread::saved_exception_pc_offset()));
3361 __ movptr(Address(rbp, wordSize), rbx);
3362 }
3363
3364 // Do the call
3365 __ mov(c_rarg0, r15_thread);
3366 __ call(RuntimeAddress(call_ptr));
3367
3368 // Set an oopmap for the call site. This oopmap will map all
3369 // oop-registers and debug-info registers as callee-saved. This
3370 // will allow deoptimization at this safepoint to find all possible
3371 // debug-info recordings, as well as let GC find all oops.
3372
3373 oop_maps->add_gc_map( __ pc() - start, map);
3374
3375 Label noException;
3376
3377 __ reset_last_Java_frame(false);
3378
3379 __ cmpptr(Address(r15_thread, Thread::pending_exception_offset()), (int32_t)NULL_WORD);
3380 __ jcc(Assembler::equal, noException);
3381
3382 // Exception pending
3383
3384 RegisterSaver::restore_live_registers(masm, save_vectors);
3385
3386 __ jump(RuntimeAddress(StubRoutines::forward_exception_entry()));
3387
3388 // No exception case
3389 __ bind(noException);
3390
3391 Label no_adjust, bail;
3392 if (SafepointMechanism::uses_thread_local_poll() && !cause_return) {
3393 // If our stashed return pc was modified by the runtime we avoid touching it
3394 __ cmpptr(rbx, Address(rbp, wordSize));
3395 __ jccb(Assembler::notEqual, no_adjust);
3396
3397 #ifdef ASSERT
3398 // Verify the correct encoding of the poll we're about to skip.
3399 // See NativeInstruction::is_safepoint_poll()
3400 __ cmpb(Address(rbx, 0), NativeTstRegMem::instruction_rex_b_prefix);
3401 __ jcc(Assembler::notEqual, bail);
3402 __ cmpb(Address(rbx, 1), NativeTstRegMem::instruction_code_memXregl);
3403 __ jcc(Assembler::notEqual, bail);
3404 // Mask out the modrm bits
3405 __ testb(Address(rbx, 2), NativeTstRegMem::modrm_mask);
3406 // rax encodes to 0, so if the bits are nonzero it's incorrect
3407 __ jcc(Assembler::notZero, bail);
3408 #endif
3409 // Adjust return pc forward to step over the safepoint poll instruction
3410 __ addptr(Address(rbp, wordSize), 3);
3411 }
3412
3413 __ bind(no_adjust);
3414 // Normal exit, restore registers and exit.
3415 RegisterSaver::restore_live_registers(masm, save_vectors);
3416 __ ret(0);
3417
3418 #ifdef ASSERT
3419 __ bind(bail);
3420 __ stop("Attempting to adjust pc to skip safepoint poll but the return point is not what we expected");
3421 #endif
3422
3423 // Make sure all code is generated
3424 masm->flush();
3425
3426 // Fill-out other meta info
3427 return SafepointBlob::create(&buffer, oop_maps, frame_size_in_words);
3428 }
3429
3430 //
3431 // generate_resolve_blob - call resolution (static/virtual/opt-virtual/ic-miss
3432 //
3433 // Generate a stub that calls into vm to find out the proper destination
3434 // of a java call. All the argument registers are live at this point
3435 // but since this is generic code we don't know what they are and the caller
3436 // must do any gc of the args.
3437 //
3438 RuntimeStub* SharedRuntime::generate_resolve_blob(address destination, const char* name) {
3439 assert (StubRoutines::forward_exception_entry() != NULL, "must be generated before");
3440
3441 // allocate space for the code
|