< prev index next >

src/hotspot/cpu/x86/sharedRuntime_x86_64.cpp

Print this page

2054 
2055   Label slow_path_lock;
2056   Label lock_done;
2057 
2058   if (method->is_synchronized()) {
2059     assert(!is_critical_native, "unhandled");
2060 
2061 
2062     const int mark_word_offset = BasicLock::displaced_header_offset_in_bytes();
2063 
2064     // Get the handle (the 2nd argument)
2065     __ mov(oop_handle_reg, c_rarg1);
2066 
2067     // Get address of the box
2068 
2069     __ lea(lock_reg, Address(rsp, lock_slot_offset * VMRegImpl::stack_slot_size));
2070 
2071     // Load the oop from the handle
2072     __ movptr(obj_reg, Address(oop_handle_reg, 0));
2073 
2074     if (UseBiasedLocking) {
2075       __ biased_locking_enter(lock_reg, obj_reg, swap_reg, rscratch1, rscratch2, false, lock_done, &slow_path_lock);
2076     }



2077 
2078     // Load immediate 1 into swap_reg %rax
2079     __ movl(swap_reg, 1);
2080 
2081     // Load (object->mark() | 1) into swap_reg %rax
2082     __ orptr(swap_reg, Address(obj_reg, oopDesc::mark_offset_in_bytes()));
2083 
2084     // Save (object->mark() | 1) into BasicLock's displaced header
2085     __ movptr(Address(lock_reg, mark_word_offset), swap_reg);
2086 
2087     // src -> dest iff dest == rax else rax <- dest
2088     __ lock();
2089     __ cmpxchgptr(lock_reg, Address(obj_reg, oopDesc::mark_offset_in_bytes()));
2090     __ jcc(Assembler::equal, lock_done);
2091 
2092     // Hmm should this move to the slow path code area???
2093 
2094     // Test if the oopMark is an obvious stack pointer, i.e.,
2095     //  1) (mark & 3) == 0, and
2096     //  2) rsp <= mark < mark + os::pagesize()
2097     // These 3 tests can be done by evaluating the following
2098     // expression: ((mark - rsp) & (3 - os::vm_page_size())),
2099     // assuming both stack pointer and pagesize have their
2100     // least significant 2 bits clear.
2101     // NOTE: the oopMark is in swap_reg %rax as the result of cmpxchg
2102 
2103     __ subptr(swap_reg, rsp);
2104     __ andptr(swap_reg, 3 - os::vm_page_size());
2105 
2106     // Save the test result, for recursive case, the result is zero
2107     __ movptr(Address(lock_reg, mark_word_offset), swap_reg);
2108     __ jcc(Assembler::notEqual, slow_path_lock);






2109 
2110     // Slow path will re-enter here
2111 
2112     __ bind(lock_done);
2113   }
2114 
2115   // Finally just about ready to make the JNI call
2116 
2117   // get JNIEnv* which is first argument to native
2118   if (!is_critical_native) {
2119     __ lea(c_rarg0, Address(r15_thread, in_bytes(JavaThread::jni_environment_offset())));
2120 
2121     // Now set thread in native
2122     __ movl(Address(r15_thread, JavaThread::thread_state_offset()), _thread_in_native);
2123   }
2124 
2125   __ call(RuntimeAddress(native_func));
2126 
2127   // Verify or restore cpu control state after JNI call
2128   __ restore_cpu_control_state_after_jni();

2213   __ cmpl(Address(r15_thread, JavaThread::stack_guard_state_offset()), StackOverflow::stack_guard_yellow_reserved_disabled);
2214   __ jcc(Assembler::equal, reguard);
2215   __ bind(reguard_done);
2216 
2217   // native result if any is live
2218 
2219   // Unlock
2220   Label unlock_done;
2221   Label slow_path_unlock;
2222   if (method->is_synchronized()) {
2223 
2224     // Get locked oop from the handle we passed to jni
2225     __ movptr(obj_reg, Address(oop_handle_reg, 0));
2226 
2227     Label done;
2228 
2229     if (UseBiasedLocking) {
2230       __ biased_locking_exit(obj_reg, old_hdr, done);
2231     }
2232 
2233     // Simple recursive lock?

2234 
2235     __ cmpptr(Address(rsp, lock_slot_offset * VMRegImpl::stack_slot_size), (int32_t)NULL_WORD);
2236     __ jcc(Assembler::equal, done);

2237 
2238     // Must save rax if if it is live now because cmpxchg must use it
2239     if (ret_type != T_FLOAT && ret_type != T_DOUBLE && ret_type != T_VOID) {
2240       save_native_result(masm, ret_type, stack_slots);
2241     }
2242 
2243 
2244     // get address of the stack lock
2245     __ lea(rax, Address(rsp, lock_slot_offset * VMRegImpl::stack_slot_size));
2246     //  get old displaced header
2247     __ movptr(old_hdr, Address(rax, 0));
2248 
2249     // Atomic swap old header if oop still contains the stack lock
2250     __ lock();
2251     __ cmpxchgptr(old_hdr, Address(obj_reg, oopDesc::mark_offset_in_bytes()));
2252     __ jcc(Assembler::notEqual, slow_path_unlock);








2253 
2254     // slow path re-enters here
2255     __ bind(unlock_done);
2256     if (ret_type != T_FLOAT && ret_type != T_DOUBLE && ret_type != T_VOID) {
2257       restore_native_result(masm, ret_type, stack_slots);
2258     }
2259 
2260     __ bind(done);
2261 
2262   }
2263   {
2264     SkipIfEqual skip(masm, &DTraceMethodProbes, false);
2265     save_native_result(masm, ret_type, stack_slots);
2266     __ mov_metadata(c_rarg1, method());
2267     __ call_VM_leaf(
2268          CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit),
2269          r15_thread, c_rarg1);
2270     restore_native_result(masm, ret_type, stack_slots);
2271   }
2272 

2054 
2055   Label slow_path_lock;
2056   Label lock_done;
2057 
2058   if (method->is_synchronized()) {
2059     assert(!is_critical_native, "unhandled");
2060 
2061 
2062     const int mark_word_offset = BasicLock::displaced_header_offset_in_bytes();
2063 
2064     // Get the handle (the 2nd argument)
2065     __ mov(oop_handle_reg, c_rarg1);
2066 
2067     // Get address of the box
2068 
2069     __ lea(lock_reg, Address(rsp, lock_slot_offset * VMRegImpl::stack_slot_size));
2070 
2071     // Load the oop from the handle
2072     __ movptr(obj_reg, Address(oop_handle_reg, 0));
2073 
2074     if (LockingMode == LM_MONITOR) {
2075       __ jmp(slow_path_lock);
2076     } else if (LockingMode == LM_LEGACY) {
2077       if (UseBiasedLocking) {
2078         __ biased_locking_enter(lock_reg, obj_reg, swap_reg, rscratch1, rscratch2, false, lock_done, &slow_path_lock);
2079       }
2080 
2081       // Load immediate 1 into swap_reg %rax
2082       __ movl(swap_reg, 1);
2083 
2084       // Load (object->mark() | 1) into swap_reg %rax
2085       __ orptr(swap_reg, Address(obj_reg, oopDesc::mark_offset_in_bytes()));
2086 
2087       // Save (object->mark() | 1) into BasicLock's displaced header
2088       __ movptr(Address(lock_reg, mark_word_offset), swap_reg);
2089 
2090       // src -> dest iff dest == rax else rax <- dest
2091       __ lock();
2092       __ cmpxchgptr(lock_reg, Address(obj_reg, oopDesc::mark_offset_in_bytes()));
2093       __ jcc(Assembler::equal, lock_done);
2094 
2095       // Hmm should this move to the slow path code area???
2096 
2097       // Test if the oopMark is an obvious stack pointer, i.e.,
2098       //  1) (mark & 3) == 0, and
2099       //  2) rsp <= mark < mark + os::pagesize()
2100       // These 3 tests can be done by evaluating the following
2101       // expression: ((mark - rsp) & (3 - os::vm_page_size())),
2102       // assuming both stack pointer and pagesize have their
2103       // least significant 2 bits clear.
2104       // NOTE: the oopMark is in swap_reg %rax as the result of cmpxchg
2105 
2106       __ subptr(swap_reg, rsp);
2107       __ andptr(swap_reg, 3 - os::vm_page_size());
2108 
2109       // Save the test result, for recursive case, the result is zero
2110       __ movptr(Address(lock_reg, mark_word_offset), swap_reg);
2111       __ jcc(Assembler::notEqual, slow_path_lock);
2112     } else {
2113       assert(LockingMode == LM_LIGHTWEIGHT, "must be");
2114       // Load object header
2115       __ movptr(swap_reg, Address(obj_reg, oopDesc::mark_offset_in_bytes()));
2116       __ lightweight_lock(obj_reg, swap_reg, r15_thread, rscratch1, slow_path_lock);
2117     }
2118 
2119     // Slow path will re-enter here
2120 
2121     __ bind(lock_done);
2122   }
2123 
2124   // Finally just about ready to make the JNI call
2125 
2126   // get JNIEnv* which is first argument to native
2127   if (!is_critical_native) {
2128     __ lea(c_rarg0, Address(r15_thread, in_bytes(JavaThread::jni_environment_offset())));
2129 
2130     // Now set thread in native
2131     __ movl(Address(r15_thread, JavaThread::thread_state_offset()), _thread_in_native);
2132   }
2133 
2134   __ call(RuntimeAddress(native_func));
2135 
2136   // Verify or restore cpu control state after JNI call
2137   __ restore_cpu_control_state_after_jni();

2222   __ cmpl(Address(r15_thread, JavaThread::stack_guard_state_offset()), StackOverflow::stack_guard_yellow_reserved_disabled);
2223   __ jcc(Assembler::equal, reguard);
2224   __ bind(reguard_done);
2225 
2226   // native result if any is live
2227 
2228   // Unlock
2229   Label unlock_done;
2230   Label slow_path_unlock;
2231   if (method->is_synchronized()) {
2232 
2233     // Get locked oop from the handle we passed to jni
2234     __ movptr(obj_reg, Address(oop_handle_reg, 0));
2235 
2236     Label done;
2237 
2238     if (UseBiasedLocking) {
2239       __ biased_locking_exit(obj_reg, old_hdr, done);
2240     }
2241 
2242     if (LockingMode == LM_LEGACY) {
2243       // Simple recursive lock?
2244 
2245       __ cmpptr(Address(rsp, lock_slot_offset * VMRegImpl::stack_slot_size), (int32_t)NULL_WORD);
2246       __ jcc(Assembler::equal, done);
2247     }
2248 
2249     // Must save rax if if it is live now because cmpxchg must use it
2250     if (ret_type != T_FLOAT && ret_type != T_DOUBLE && ret_type != T_VOID) {
2251       save_native_result(masm, ret_type, stack_slots);
2252     }
2253 
2254     if (LockingMode == LM_MONITOR) {
2255       __ jmp(slow_path_unlock);
2256     } else if (LockingMode == LM_LEGACY) {
2257       // get address of the stack lock
2258       __ lea(rax, Address(rsp, lock_slot_offset * VMRegImpl::stack_slot_size));
2259       //  get old displaced header
2260       __ movptr(old_hdr, Address(rax, 0));
2261 
2262       // Atomic swap old header if oop still contains the stack lock
2263       __ lock();
2264       __ cmpxchgptr(old_hdr, Address(obj_reg, oopDesc::mark_offset_in_bytes()));
2265       __ jcc(Assembler::notEqual, slow_path_unlock);
2266     } else {
2267       assert(LockingMode == LM_LIGHTWEIGHT, "must be");
2268       __ movptr(swap_reg, Address(obj_reg, oopDesc::mark_offset_in_bytes()));
2269       __ andptr(swap_reg, ~(int32_t)markWord::lock_mask_in_place);
2270       __ lightweight_unlock(obj_reg, swap_reg, lock_reg, slow_path_unlock);
2271     }
2272 
2273     // slow path re-enters here
2274     __ bind(unlock_done);
2275     if (ret_type != T_FLOAT && ret_type != T_DOUBLE && ret_type != T_VOID) {
2276       restore_native_result(masm, ret_type, stack_slots);
2277     }
2278 
2279     __ bind(done);
2280 
2281   }
2282   {
2283     SkipIfEqual skip(masm, &DTraceMethodProbes, false);
2284     save_native_result(masm, ret_type, stack_slots);
2285     __ mov_metadata(c_rarg1, method());
2286     __ call_VM_leaf(
2287          CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit),
2288          r15_thread, c_rarg1);
2289     restore_native_result(masm, ret_type, stack_slots);
2290   }
2291 
< prev index next >