< prev index next >

src/hotspot/cpu/aarch64/sharedRuntime_aarch64.cpp

Print this page

   1 /*
   2  * Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright (c) 2014, 2021, Red Hat Inc. All rights reserved.
   4  * Copyright (c) 2021, Azul Systems, Inc. All rights reserved.
   5  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   6  *
   7  * This code is free software; you can redistribute it and/or modify it
   8  * under the terms of the GNU General Public License version 2 only, as
   9  * published by the Free Software Foundation.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any

1800       // Hmm should this move to the slow path code area???
1801 
1802       // Test if the oopMark is an obvious stack pointer, i.e.,
1803       //  1) (mark & 3) == 0, and
1804       //  2) sp <= mark < mark + os::pagesize()
1805       // These 3 tests can be done by evaluating the following
1806       // expression: ((mark - sp) & (3 - os::vm_page_size())),
1807       // assuming both stack pointer and pagesize have their
1808       // least significant 2 bits clear.
1809       // NOTE: the oopMark is in swap_reg %r0 as the result of cmpxchg
1810 
1811       __ sub(swap_reg, sp, swap_reg);
1812       __ neg(swap_reg, swap_reg);
1813       __ ands(swap_reg, swap_reg, 3 - (int)os::vm_page_size());
1814 
1815       // Save the test result, for recursive case, the result is zero
1816       __ str(swap_reg, Address(lock_reg, mark_word_offset));
1817       __ br(Assembler::NE, slow_path_lock);
1818     } else {
1819       assert(LockingMode == LM_LIGHTWEIGHT, "must be");
1820       __ ldr(swap_reg, Address(obj_reg, oopDesc::mark_offset_in_bytes()));
1821       __ lightweight_lock(obj_reg, swap_reg, tmp, lock_tmp, slow_path_lock);
1822     }
1823     __ bind(count);
1824     __ increment(Address(rthread, JavaThread::held_monitor_count_offset()));
1825 
1826     // Slow path will re-enter here
1827     __ bind(lock_done);
1828   }
1829 
1830 
1831   // Finally just about ready to make the JNI call
1832 
1833   // get JNIEnv* which is first argument to native
1834   __ lea(c_rarg0, Address(rthread, in_bytes(JavaThread::jni_environment_offset())));
1835 
1836   // Now set thread in native
1837   __ mov(rscratch1, _thread_in_native);
1838   __ lea(rscratch2, Address(rthread, JavaThread::thread_state_offset()));
1839   __ stlrw(rscratch1, rscratch2);
1840 

1940     // Must save r0 if if it is live now because cmpxchg must use it
1941     if (ret_type != T_FLOAT && ret_type != T_DOUBLE && ret_type != T_VOID) {
1942       save_native_result(masm, ret_type, stack_slots);
1943     }
1944 
1945     if (LockingMode == LM_MONITOR) {
1946       __ b(slow_path_unlock);
1947     } else if (LockingMode == LM_LEGACY) {
1948       // get address of the stack lock
1949       __ lea(r0, Address(sp, lock_slot_offset * VMRegImpl::stack_slot_size));
1950       //  get old displaced header
1951       __ ldr(old_hdr, Address(r0, 0));
1952 
1953       // Atomic swap old header if oop still contains the stack lock
1954       Label count;
1955       __ cmpxchg_obj_header(r0, old_hdr, obj_reg, rscratch1, count, &slow_path_unlock);
1956       __ bind(count);
1957       __ decrement(Address(rthread, JavaThread::held_monitor_count_offset()));
1958     } else {
1959       assert(LockingMode == LM_LIGHTWEIGHT, "");
1960       __ ldr(old_hdr, Address(obj_reg, oopDesc::mark_offset_in_bytes()));
1961       __ tbnz(old_hdr, exact_log2(markWord::monitor_value), slow_path_unlock);
1962       __ lightweight_unlock(obj_reg, old_hdr, swap_reg, lock_tmp, slow_path_unlock);
1963       __ decrement(Address(rthread, JavaThread::held_monitor_count_offset()));
1964     }
1965 
1966     // slow path re-enters here
1967     __ bind(unlock_done);
1968     if (ret_type != T_FLOAT && ret_type != T_DOUBLE && ret_type != T_VOID) {
1969       restore_native_result(masm, ret_type, stack_slots);
1970     }
1971 
1972     __ bind(done);
1973   }
1974 
1975   Label dtrace_method_exit, dtrace_method_exit_done;
1976   {
1977     uint64_t offset;
1978     __ adrp(rscratch1, ExternalAddress((address)&DTraceMethodProbes), offset);
1979     __ ldrb(rscratch1, Address(rscratch1, offset));
1980     __ cbnzw(rscratch1, dtrace_method_exit);
1981     __ bind(dtrace_method_exit_done);

   1 /*
   2  * Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright (c) 2014, 2021, Red Hat Inc. All rights reserved.
   4  * Copyright (c) 2021, Azul Systems, Inc. All rights reserved.
   5  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   6  *
   7  * This code is free software; you can redistribute it and/or modify it
   8  * under the terms of the GNU General Public License version 2 only, as
   9  * published by the Free Software Foundation.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any

1800       // Hmm should this move to the slow path code area???
1801 
1802       // Test if the oopMark is an obvious stack pointer, i.e.,
1803       //  1) (mark & 3) == 0, and
1804       //  2) sp <= mark < mark + os::pagesize()
1805       // These 3 tests can be done by evaluating the following
1806       // expression: ((mark - sp) & (3 - os::vm_page_size())),
1807       // assuming both stack pointer and pagesize have their
1808       // least significant 2 bits clear.
1809       // NOTE: the oopMark is in swap_reg %r0 as the result of cmpxchg
1810 
1811       __ sub(swap_reg, sp, swap_reg);
1812       __ neg(swap_reg, swap_reg);
1813       __ ands(swap_reg, swap_reg, 3 - (int)os::vm_page_size());
1814 
1815       // Save the test result, for recursive case, the result is zero
1816       __ str(swap_reg, Address(lock_reg, mark_word_offset));
1817       __ br(Assembler::NE, slow_path_lock);
1818     } else {
1819       assert(LockingMode == LM_LIGHTWEIGHT, "must be");

1820       __ lightweight_lock(obj_reg, swap_reg, tmp, lock_tmp, slow_path_lock);
1821     }
1822     __ bind(count);
1823     __ increment(Address(rthread, JavaThread::held_monitor_count_offset()));
1824 
1825     // Slow path will re-enter here
1826     __ bind(lock_done);
1827   }
1828 
1829 
1830   // Finally just about ready to make the JNI call
1831 
1832   // get JNIEnv* which is first argument to native
1833   __ lea(c_rarg0, Address(rthread, in_bytes(JavaThread::jni_environment_offset())));
1834 
1835   // Now set thread in native
1836   __ mov(rscratch1, _thread_in_native);
1837   __ lea(rscratch2, Address(rthread, JavaThread::thread_state_offset()));
1838   __ stlrw(rscratch1, rscratch2);
1839 

1939     // Must save r0 if if it is live now because cmpxchg must use it
1940     if (ret_type != T_FLOAT && ret_type != T_DOUBLE && ret_type != T_VOID) {
1941       save_native_result(masm, ret_type, stack_slots);
1942     }
1943 
1944     if (LockingMode == LM_MONITOR) {
1945       __ b(slow_path_unlock);
1946     } else if (LockingMode == LM_LEGACY) {
1947       // get address of the stack lock
1948       __ lea(r0, Address(sp, lock_slot_offset * VMRegImpl::stack_slot_size));
1949       //  get old displaced header
1950       __ ldr(old_hdr, Address(r0, 0));
1951 
1952       // Atomic swap old header if oop still contains the stack lock
1953       Label count;
1954       __ cmpxchg_obj_header(r0, old_hdr, obj_reg, rscratch1, count, &slow_path_unlock);
1955       __ bind(count);
1956       __ decrement(Address(rthread, JavaThread::held_monitor_count_offset()));
1957     } else {
1958       assert(LockingMode == LM_LIGHTWEIGHT, "");


1959       __ lightweight_unlock(obj_reg, old_hdr, swap_reg, lock_tmp, slow_path_unlock);
1960       __ decrement(Address(rthread, JavaThread::held_monitor_count_offset()));
1961     }
1962 
1963     // slow path re-enters here
1964     __ bind(unlock_done);
1965     if (ret_type != T_FLOAT && ret_type != T_DOUBLE && ret_type != T_VOID) {
1966       restore_native_result(masm, ret_type, stack_slots);
1967     }
1968 
1969     __ bind(done);
1970   }
1971 
1972   Label dtrace_method_exit, dtrace_method_exit_done;
1973   {
1974     uint64_t offset;
1975     __ adrp(rscratch1, ExternalAddress((address)&DTraceMethodProbes), offset);
1976     __ ldrb(rscratch1, Address(rscratch1, offset));
1977     __ cbnzw(rscratch1, dtrace_method_exit);
1978     __ bind(dtrace_method_exit_done);
< prev index next >