1 /* 2 * Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved. 3 * Copyright (c) 2020, 2023, Huawei Technologies Co., Ltd. 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 "opto/c2_CodeStubs.hpp" 28 #include "opto/c2_MacroAssembler.hpp" 29 #include "runtime/objectMonitor.hpp" 30 #include "runtime/sharedRuntime.hpp" 31 #include "runtime/stubRoutines.hpp" 32 33 #define __ masm. 34 35 int C2SafepointPollStub::max_size() const { 36 return 13 * 4; 37 } 38 39 void C2SafepointPollStub::emit(C2_MacroAssembler& masm) { 40 assert(SharedRuntime::polling_page_return_handler_blob() != nullptr, 41 "polling page return stub not created yet"); 42 address stub = SharedRuntime::polling_page_return_handler_blob()->entry_point(); 43 RuntimeAddress callback_addr(stub); 44 45 __ bind(entry()); 46 InternalAddress safepoint_pc(__ pc() - __ offset() + _safepoint_offset); 47 __ relocate(safepoint_pc.rspec(), [&] { 48 int32_t offset; 49 __ la(t0, safepoint_pc.target(), offset); 50 __ addi(t0, t0, offset); 51 }); 52 __ sd(t0, Address(xthread, JavaThread::saved_exception_pc_offset())); 53 __ far_jump(callback_addr); 54 } 55 56 int C2EntryBarrierStub::max_size() const { 57 // 4 bytes for alignment 58 return 8 * 4 + 4; 59 } 60 61 void C2EntryBarrierStub::emit(C2_MacroAssembler& masm) { 62 __ bind(entry()); 63 __ rt_call(StubRoutines::method_entry_barrier()); 64 65 __ j(continuation()); 66 67 // make guard value 4-byte aligned so that it can be accessed by atomic instructions on RISC-V 68 __ align(4); 69 __ bind(guard()); 70 __ relocate(entry_guard_Relocation::spec()); 71 __ emit_int32(0); // nmethod guard value 72 } 73 74 int C2HandleAnonOMOwnerStub::max_size() const { 75 // Max size of stub has been determined by testing with 0 without using RISC-V compressed 76 // instruction-set extension, in which case C2CodeStubList::emit() will throw an assertion 77 // and report the actual size that is needed. 78 return 20 DEBUG_ONLY(+8); 79 } 80 81 void C2HandleAnonOMOwnerStub::emit(C2_MacroAssembler& masm) { 82 __ bind(entry()); 83 Register mon = monitor(); 84 Register t = tmp(); 85 assert(t != noreg, "need tmp register"); 86 87 // Fix owner to be the current thread. 88 __ sd(xthread, Address(mon, ObjectMonitor::owner_offset())); 89 90 // Pop owner object from lock-stack. 91 __ lwu(t, Address(xthread, JavaThread::lock_stack_top_offset())); 92 __ subw(t, t, oopSize); 93 #ifdef ASSERT 94 __ add(t0, xthread, t); 95 __ sd(zr, Address(t0, 0)); 96 #endif 97 __ sw(t, Address(xthread, JavaThread::lock_stack_top_offset())); 98 99 __ j(continuation()); 100 } 101 102 #undef __