< prev index next >

src/hotspot/cpu/x86/sharedRuntime_x86_32.cpp

Print this page
rev 48494 : 8195112: x86 (32 bit): implementation for Thread-local handshakes
Reviewed-by:


2094       __ membar(Assembler::Membar_mask_bits(
2095            Assembler::LoadLoad | Assembler::LoadStore |
2096            Assembler::StoreLoad | Assembler::StoreStore));
2097     } else {
2098       // Write serialization page so VM thread can do a pseudo remote membar.
2099       // We use the current thread pointer to calculate a thread specific
2100       // offset to write to within the page. This minimizes bus traffic
2101       // due to cache line collision.
2102       __ serialize_memory(thread, rcx);
2103     }
2104   }
2105 
2106   if (AlwaysRestoreFPU) {
2107     // Make sure the control word is correct.
2108     __ fldcw(ExternalAddress(StubRoutines::addr_fpu_cntrl_wrd_std()));
2109   }
2110 
2111   Label after_transition;
2112 
2113   // check for safepoint operation in progress and/or pending suspend requests
2114   { Label Continue;
2115 
2116     __ cmp32(ExternalAddress((address)SafepointSynchronize::address_of_state()),
2117              SafepointSynchronize::_not_synchronized);
2118 
2119     Label L;
2120     __ jcc(Assembler::notEqual, L);
2121     __ cmpl(Address(thread, JavaThread::suspend_flags_offset()), 0);
2122     __ jcc(Assembler::equal, Continue);
2123     __ bind(L);
2124 
2125     // Don't use call_VM as it will see a possible pending exception and forward it
2126     // and never return here preventing us from clearing _last_native_pc down below.
2127     // Also can't use call_VM_leaf either as it will check to see if rsi & rdi are
2128     // preserved and correspond to the bcp/locals pointers. So we do a runtime call
2129     // by hand.
2130     //
2131     __ vzeroupper();
2132 
2133     save_native_result(masm, ret_type, stack_slots);
2134     __ push(thread);
2135     if (!is_critical_native) {
2136       __ call(RuntimeAddress(CAST_FROM_FN_PTR(address,
2137                                               JavaThread::check_special_condition_for_native_trans)));
2138     } else {
2139       __ call(RuntimeAddress(CAST_FROM_FN_PTR(address,
2140                                               JavaThread::check_special_condition_for_native_trans_and_transition)));
2141     }
2142     __ increment(rsp, wordSize);
2143     // Restore any method result value


2979   // that is safepoint. We can leave this return on the stack and
2980   // effectively complete the return and safepoint in the caller.
2981   // Otherwise we push space for a return address that the safepoint
2982   // handler will install later to make the stack walking sensible.
2983   if (!cause_return)
2984     __ push(rbx);  // Make room for return address (or push it again)
2985 
2986   map = RegisterSaver::save_live_registers(masm, additional_words, &frame_size_in_words, false, save_vectors);
2987 
2988   // The following is basically a call_VM. However, we need the precise
2989   // address of the call in order to generate an oopmap. Hence, we do all the
2990   // work ourselves.
2991 
2992   // Push thread argument and setup last_Java_sp
2993   __ get_thread(java_thread);
2994   __ push(java_thread);
2995   __ set_last_Java_frame(java_thread, noreg, noreg, NULL);
2996 
2997   // if this was not a poll_return then we need to correct the return address now.
2998   if (!cause_return) {
2999     __ movptr(rax, Address(java_thread, JavaThread::saved_exception_pc_offset()));
3000     __ movptr(Address(rbp, wordSize), rax);



3001   }
3002 
3003   // do the call
3004   __ call(RuntimeAddress(call_ptr));
3005 
3006   // Set an oopmap for the call site.  This oopmap will map all
3007   // oop-registers and debug-info registers as callee-saved.  This
3008   // will allow deoptimization at this safepoint to find all possible
3009   // debug-info recordings, as well as let GC find all oops.
3010 
3011   oop_maps->add_gc_map( __ pc() - start, map);
3012 
3013   // Discard arg
3014   __ pop(rcx);
3015 
3016   Label noException;
3017 
3018   // Clear last_Java_sp again
3019   __ get_thread(java_thread);
3020   __ reset_last_Java_frame(java_thread, false);
3021 
3022   __ cmpptr(Address(java_thread, Thread::pending_exception_offset()), (int32_t)NULL_WORD);
3023   __ jcc(Assembler::equal, noException);
3024 
3025   // Exception pending
3026   RegisterSaver::restore_live_registers(masm, save_vectors);
3027 
3028   __ jump(RuntimeAddress(StubRoutines::forward_exception_entry()));
3029 
3030   __ bind(noException);
3031 















































3032   // Normal exit, register restoring and exit
3033   RegisterSaver::restore_live_registers(masm, save_vectors);
3034 
3035   __ ret(0);





3036 
3037   // make sure all code is generated
3038   masm->flush();
3039 
3040   // Fill-out other meta info
3041   return SafepointBlob::create(&buffer, oop_maps, frame_size_in_words);
3042 }
3043 
3044 //
3045 // generate_resolve_blob - call resolution (static/virtual/opt-virtual/ic-miss
3046 //
3047 // Generate a stub that calls into vm to find out the proper destination
3048 // of a java call. All the argument registers are live at this point
3049 // but since this is generic code we don't know what they are and the caller
3050 // must do any gc of the args.
3051 //
3052 RuntimeStub* SharedRuntime::generate_resolve_blob(address destination, const char* name) {
3053   assert (StubRoutines::forward_exception_entry() != NULL, "must be generated before");
3054 
3055   // allocate space for the code




2094       __ membar(Assembler::Membar_mask_bits(
2095            Assembler::LoadLoad | Assembler::LoadStore |
2096            Assembler::StoreLoad | Assembler::StoreStore));
2097     } else {
2098       // Write serialization page so VM thread can do a pseudo remote membar.
2099       // We use the current thread pointer to calculate a thread specific
2100       // offset to write to within the page. This minimizes bus traffic
2101       // due to cache line collision.
2102       __ serialize_memory(thread, rcx);
2103     }
2104   }
2105 
2106   if (AlwaysRestoreFPU) {
2107     // Make sure the control word is correct.
2108     __ fldcw(ExternalAddress(StubRoutines::addr_fpu_cntrl_wrd_std()));
2109   }
2110 
2111   Label after_transition;
2112 
2113   // check for safepoint operation in progress and/or pending suspend requests
2114   { Label Continue, slow_path;
2115 
2116     __ safepoint_poll(slow_path, thread, noreg);

2117 


2118     __ cmpl(Address(thread, JavaThread::suspend_flags_offset()), 0);
2119     __ jcc(Assembler::equal, Continue);
2120     __ bind(slow_path);
2121 
2122     // Don't use call_VM as it will see a possible pending exception and forward it
2123     // and never return here preventing us from clearing _last_native_pc down below.
2124     // Also can't use call_VM_leaf either as it will check to see if rsi & rdi are
2125     // preserved and correspond to the bcp/locals pointers. So we do a runtime call
2126     // by hand.
2127     //
2128     __ vzeroupper();
2129 
2130     save_native_result(masm, ret_type, stack_slots);
2131     __ push(thread);
2132     if (!is_critical_native) {
2133       __ call(RuntimeAddress(CAST_FROM_FN_PTR(address,
2134                                               JavaThread::check_special_condition_for_native_trans)));
2135     } else {
2136       __ call(RuntimeAddress(CAST_FROM_FN_PTR(address,
2137                                               JavaThread::check_special_condition_for_native_trans_and_transition)));
2138     }
2139     __ increment(rsp, wordSize);
2140     // Restore any method result value


2976   // that is safepoint. We can leave this return on the stack and
2977   // effectively complete the return and safepoint in the caller.
2978   // Otherwise we push space for a return address that the safepoint
2979   // handler will install later to make the stack walking sensible.
2980   if (!cause_return)
2981     __ push(rbx);  // Make room for return address (or push it again)
2982 
2983   map = RegisterSaver::save_live_registers(masm, additional_words, &frame_size_in_words, false, save_vectors);
2984 
2985   // The following is basically a call_VM. However, we need the precise
2986   // address of the call in order to generate an oopmap. Hence, we do all the
2987   // work ourselves.
2988 
2989   // Push thread argument and setup last_Java_sp
2990   __ get_thread(java_thread);
2991   __ push(java_thread);
2992   __ set_last_Java_frame(java_thread, noreg, noreg, NULL);
2993 
2994   // if this was not a poll_return then we need to correct the return address now.
2995   if (!cause_return) {
2996     // Get the return pc saved by the signal handler and stash it in its appropriate place on the stack.
2997     // Additionally, rbx is a callee saved register and we can look at it later to determine
2998     // if someone changed the return address for us!
2999     __ movptr(rbx, Address(java_thread, JavaThread::saved_exception_pc_offset()));
3000     __ movptr(Address(rbp, wordSize), rbx);
3001   }
3002 
3003   // do the call
3004   __ call(RuntimeAddress(call_ptr));
3005 
3006   // Set an oopmap for the call site.  This oopmap will map all
3007   // oop-registers and debug-info registers as callee-saved.  This
3008   // will allow deoptimization at this safepoint to find all possible
3009   // debug-info recordings, as well as let GC find all oops.
3010 
3011   oop_maps->add_gc_map( __ pc() - start, map);
3012 
3013   // Discard arg
3014   __ pop(rcx);
3015 
3016   Label noException;
3017 
3018   // Clear last_Java_sp again
3019   __ get_thread(java_thread);
3020   __ reset_last_Java_frame(java_thread, false);
3021 
3022   __ cmpptr(Address(java_thread, Thread::pending_exception_offset()), (int32_t)NULL_WORD);
3023   __ jcc(Assembler::equal, noException);
3024 
3025   // Exception pending
3026   RegisterSaver::restore_live_registers(masm, save_vectors);
3027 
3028   __ jump(RuntimeAddress(StubRoutines::forward_exception_entry()));
3029 
3030   __ bind(noException);
3031 
3032   Label no_adjust, bail, not_special;
3033   if (SafepointMechanism::uses_thread_local_poll() && !cause_return) {
3034     // If our stashed return pc was modified by the runtime we avoid touching it
3035     __ cmpptr(rbx, Address(rbp, wordSize));
3036     __ jccb(Assembler::notEqual, no_adjust);
3037 
3038     // Skip over the poll instruction.
3039     // See NativeInstruction::is_safepoint_poll()
3040     // Possible encodings:
3041     //      85 00       test   %eax,(%rax)
3042     //      85 01       test   %eax,(%rcx)
3043     //      85 02       test   %eax,(%rdx)
3044     //      85 03       test   %eax,(%rbx)
3045     //      85 06       test   %eax,(%rsi)
3046     //      85 07       test   %eax,(%rdi)
3047     //
3048     //      85 04 24    test   %eax,(%rsp)
3049     //      85 05 00    test   %eax,0x0(%rbp)
3050 
3051 #ifdef ASSERT
3052     __ movptr(rax, rbx); // remember where 0x85 should be, for verification below
3053 #endif
3054     // rsp/rbp base encoding takes 3 bytes with the following register values:
3055     // rsp 0x04
3056     // rbp 0x05
3057     __ movzbl(rcx, Address(rbx, 1));
3058     __ andptr(rcx, 0x07); // looking for 0x04 .. 0x05
3059     __ subptr(rcx, 4);    // looking for 0x00 .. 0x01
3060     __ cmpptr(rcx, 1);
3061     __ jcc(Assembler::above, not_special);
3062     __ addptr(rbx, 1);
3063     __ bind(not_special);
3064 #ifdef ASSERT
3065     // Verify the correct encoding of the poll we're about to skip.
3066     __ cmpb(Address(rax, 0), NativeTstRegMem::instruction_code_memXregl);
3067     __ jcc(Assembler::notEqual, bail);
3068     // Mask out the modrm bits
3069     __ testb(Address(rax, 1), NativeTstRegMem::modrm_mask);
3070     // rax encodes to 0, so if the bits are nonzero it's incorrect
3071     __ jcc(Assembler::notZero, bail);
3072 #endif
3073     // Adjust return pc forward to step over the safepoint poll instruction
3074     __ addptr(rbx, 2);
3075     __ movptr(Address(rbp, wordSize), rbx);
3076   }
3077 
3078   __ bind(no_adjust);
3079   // Normal exit, register restoring and exit
3080   RegisterSaver::restore_live_registers(masm, save_vectors);
3081 
3082   __ ret(0);
3083 
3084 #ifdef ASSERT
3085   __ bind(bail);
3086   __ stop("Attempting to adjust pc to skip safepoint poll but the return point is not what we expected");
3087 #endif
3088 
3089   // make sure all code is generated
3090   masm->flush();
3091 
3092   // Fill-out other meta info
3093   return SafepointBlob::create(&buffer, oop_maps, frame_size_in_words);
3094 }
3095 
3096 //
3097 // generate_resolve_blob - call resolution (static/virtual/opt-virtual/ic-miss
3098 //
3099 // Generate a stub that calls into vm to find out the proper destination
3100 // of a java call. All the argument registers are live at this point
3101 // but since this is generic code we don't know what they are and the caller
3102 // must do any gc of the args.
3103 //
3104 RuntimeStub* SharedRuntime::generate_resolve_blob(address destination, const char* name) {
3105   assert (StubRoutines::forward_exception_entry() != NULL, "must be generated before");
3106 
3107   // allocate space for the code


< prev index next >