/* * Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2014, Red Hat Inc. All rights reserved. * Copyright (c) 2020, 2022, Huawei Technologies Co., Ltd. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. *
*/
// check for pending exceptions
{ Label L; // check for pending exceptions (java_thread is set upon return)
ld(t0, Address(xthread, in_bytes(Thread::pending_exception_offset())));
beqz(t0, L); // exception pending => remove activation and forward to exception handler // make sure that the vm_results are cleared if (oop_result->is_valid()) {
sd(zr, Address(xthread, JavaThread::vm_result_offset()));
} if (metadata_result->is_valid()) {
sd(zr, Address(xthread, JavaThread::vm_result_2_offset()));
} if (frame_size() == no_frame_size) {
leave();
far_jump(RuntimeAddress(StubRoutines::forward_exception_entry()));
} elseif (_stub_id == Runtime1::forward_exception_id) {
should_not_reach_here();
} else {
far_jump(RuntimeAddress(Runtime1::entry_for(Runtime1::forward_exception_id)));
}
bind(L);
} // get oop results if there are any and reset the values in the thread if (oop_result->is_valid()) {
get_vm_result(oop_result, xthread);
} if (metadata_result->is_valid()) {
get_vm_result_2(metadata_result, xthread);
} return call_offset;
}
// load parameters that were stored with LIR_Assembler::store_parameter // Note: offsets for store_parameter and load_argument must match void StubFrame::load_argument(int offset_in_words, Register reg) {
__ load_parameter(offset_in_words, reg);
}
// Stack layout for saving/restoring all the registers needed during a runtime // call (this includes deoptimization) // Note: note that users of this frame may well have arguments to some runtime // while these values are on the stack. These positions neglect those arguments // but the code in save_live_registers will take the argument count into // account. //
// Save off registers which might be killed by calls into the runtime. // Tries to smart of about FPU registers. In particular we separate // saving and describing the FPU registers for deoptimization since we // have to save the FPU registers twice if we describe them. The // deopt blob is the only thing which needs to describe FPU registers. // In all other cases it should be sufficient to simply save their // current value.
// caller save registers only, see FrameMap::initialize // in c1_FrameMap_riscv.cpp for detail. conststaticRegister caller_save_cpu_regs[FrameMap::max_nof_caller_save_cpu_regs] = {
x7, x10, x11, x12, x13, x14, x15, x16, x17, x28, x29, x30, x31
};
for (int i = 0; i < FrameMap::max_nof_caller_save_cpu_regs; i++) { Register r = caller_save_cpu_regs[i]; int sp_offset = cpu_reg_save_offsets[r->encoding()];
oop_map->set_callee_saved(VMRegImpl::stack2reg(sp_offset),
r->as_VMReg());
}
// fpu_regs if (save_fpu_registers) { for (int i = 0; i < FrameMap::nof_fpu_regs; i++) {
FloatRegister r = as_FloatRegister(i); int sp_offset = fpu_reg_save_offsets[i];
oop_map->set_callee_saved(VMRegImpl::stack2reg(sp_offset),
r->as_VMReg());
}
} return oop_map;
}
// if the number of pushed regs is odd, one slot will be reserved for alignment
__ push_reg(RegSet::range(x5, x31), sp); // integer registers except ra(x1) & sp(x2) & gp(x3) & tp(x4)
if (save_fpu_registers) { // float registers
__ addi(sp, sp, -(FrameMap::nof_fpu_regs * wordSize)); for (int i = 0; i < FrameMap::nof_fpu_regs; i++) {
__ fsd(as_FloatRegister(i), Address(sp, i * wordSize));
}
} else { // we define reg_save_layout = 62 as the fixed frame size, // we should also sub 32 * wordSize to sp when save_fpu_registers == false
__ addi(sp, sp, -32 * wordSize);
}
staticvoid restore_live_registers(StubAssembler* sasm, bool restore_fpu_registers = true) { if (restore_fpu_registers) { for (int i = 0; i < FrameMap::nof_fpu_regs; i++) {
__ fld(as_FloatRegister(i), Address(sp, i * wordSize));
}
__ addi(sp, sp, FrameMap::nof_fpu_regs * wordSize);
} else { // we define reg_save_layout = 64 as the fixed frame size, // we should also add 32 * wordSize to sp when save_fpu_registers == false
__ addi(sp, sp, 32 * wordSize);
}
// if the number of popped regs is odd, the reserved slot for alignment will be removed
__ pop_reg(RegSet::range(x5, x31), sp); // integer registers except ra(x1) & sp(x2) & gp(x3) & tp(x4)
}
staticvoid restore_live_registers_except_r10(StubAssembler* sasm, bool restore_fpu_registers = true) { if (restore_fpu_registers) { for (int i = 0; i < FrameMap::nof_fpu_regs; i++) {
__ fld(as_FloatRegister(i), Address(sp, i * wordSize));
}
__ addi(sp, sp, FrameMap::nof_fpu_regs * wordSize);
} else { // we define reg_save_layout = 64 as the fixed frame size, // we should also add 32 * wordSize to sp when save_fpu_registers == false
__ addi(sp, sp, 32 * wordSize);
}
// pop integer registers except ra(x1) & sp(x2) & gp(x3) & tp(x4) & x10 // there is one reserved slot for alignment on the stack in save_live_registers().
__ pop_reg(RegSet::range(x5, x9), sp); // pop x5 ~ x9 with the reserved slot for alignment
__ pop_reg(RegSet::range(x11, x31), sp); // pop x11 ~ x31; x10 will be automatically skipped here
}
void Runtime1::initialize_pd() { int i = 0; int sp_offset = 0; constint step = 2; // SP offsets are in halfwords
// all float registers are saved explicitly for (i = 0; i < FrameMap::nof_fpu_regs; i++) {
fpu_reg_save_offsets[i] = sp_offset;
sp_offset += step;
}
// a slot reserved for stack 16-byte alignment, see MacroAssembler::push_reg
sp_offset += step; // we save x5 ~ x31, except x0 ~ x4: loop starts from x5 for (i = 5; i < FrameMap::nof_cpu_regs; i++) {
cpu_reg_save_offsets[i] = sp_offset;
sp_offset += step;
}
}
// target: the entry point of the method that creates and posts the exception oop // has_argument: true if the exception needs arguments (passed in t0 and t1)
OopMapSet* Runtime1::generate_exception_throw(StubAssembler* sasm, address target, bool has_argument) { // make a frame and preserve the caller's caller-save registers
OopMap* oop_map = save_live_registers(sasm);
assert_cond(oop_map != NULL); int call_offset = 0; if (!has_argument) {
call_offset = __ call_RT(noreg, noreg, target);
} else {
__ mv(c_rarg1, t0);
__ mv(c_rarg2, t1);
call_offset = __ call_RT(noreg, noreg, target);
}
OopMapSet* oop_maps = new OopMapSet();
assert_cond(oop_maps != NULL);
oop_maps->add_gc_map(call_offset, oop_map);
switch (id) { case forward_exception_id: // We're handling an exception in the context of a compiled frame. // The registers have been saved in the standard places. Perform // an exception lookup in the caller and dispatch to the handler // if found. Otherwise unwind and dispatch to the callers // exception handler.
oop_map = generate_oop_map(sasm, 1 /* thread */);
// load and clear pending exception oop into x10
__ ld(exception_oop, Address(xthread, Thread::pending_exception_offset()));
__ sd(zr, Address(xthread, Thread::pending_exception_offset()));
// load issuing PC (the return address for this stub) into x13
__ ld(exception_pc, Address(fp, frame::return_addr_offset * BytesPerWord));
// make sure that the vm_results are cleared (may be unnecessary)
__ sd(zr, Address(xthread, JavaThread::vm_result_offset()));
__ sd(zr, Address(xthread, JavaThread::vm_result_2_offset())); break; case handle_exception_nofpu_id: case handle_exception_id: // At this point all registers MAY be live.
oop_map = save_live_registers(sasm, id != handle_exception_nofpu_id); break; case handle_exception_from_callee_id: { // At this point all registers except exception oop (x10) and // exception pc (ra) are dead. constint frame_size = 2 /* fp, return address */;
oop_map = new OopMap(frame_size * VMRegImpl::slots_per_word, 0);
sasm->set_frame_size(frame_size); break;
} default: ShouldNotReachHere();
}
// verify that only x10 and x13 are valid at this time
__ invalidate_registers(false, true, true, false, true, true); // verify that x10 contains a valid exception
__ verify_not_null_oop(exception_oop);
#ifdef ASSERT // check that fields in JavaThread for exception oop and issuing pc are // empty before writing to them
Label oop_empty;
__ ld(t0, Address(xthread, JavaThread::exception_oop_offset()));
__ beqz(t0, oop_empty);
__ stop("exception oop already set");
__ bind(oop_empty);
// save exception oop and issuing pc into JavaThread // (exception handler will load it from here)
__ sd(exception_oop, Address(xthread, JavaThread::exception_oop_offset()));
__ sd(exception_pc, Address(xthread, JavaThread::exception_pc_offset()));
// patch throwing pc into return address (has bci & oop map)
__ sd(exception_pc, Address(fp, frame::return_addr_offset * BytesPerWord));
// compute the exception handler. // the exception oop and the throwing pc are read from the fields in JavaThread int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, exception_handler_for_pc));
guarantee(oop_map != NULL, "NULL oop_map!");
oop_maps->add_gc_map(call_offset, oop_map);
// x10: handler address // will be the deopt blob if nmethod was deoptimized while we looked up // handler regardless of whether handler existed in the nmethod.
// only x10 is valid at this time, all other registers have been destroyed by the runtime call
__ invalidate_registers(false, true, true, true, true, true);
// patch the return address, this stub will directly return to the exception handler
__ sd(x10, Address(fp, frame::return_addr_offset * BytesPerWord));
switch (id) { case forward_exception_id: case handle_exception_nofpu_id: case handle_exception_id: // Restore the registers that were saved at the beginning.
restore_live_registers(sasm, id != handle_exception_nofpu_id); break; case handle_exception_from_callee_id: break; default: ShouldNotReachHere();
}
return oop_maps;
}
void Runtime1::generate_unwind_exception(StubAssembler *sasm) { // incoming parameters constRegister exception_oop = x10; // other registers used in this stub constRegister handler_addr = x11;
// verify that only x10, is valid at this time
__ invalidate_registers(false, true, true, true, true, true);
#ifdef ASSERT // check that fields in JavaThread for exception oop and issuing pc are empty
Label oop_empty;
__ ld(t0, Address(xthread, JavaThread::exception_oop_offset()));
__ beqz(t0, oop_empty);
__ stop("exception oop must be empty");
__ bind(oop_empty);
Label pc_empty;
__ ld(t0, Address(xthread, JavaThread::exception_pc_offset()));
__ beqz(t0, pc_empty);
__ stop("exception pc must be empty");
__ bind(pc_empty); #endif
// Save our return address because // exception_handler_for_return_address will destroy it. We also // save exception_oop
__ addi(sp, sp, -2 * wordSize);
__ sd(exception_oop, Address(sp, wordSize));
__ sd(ra, Address(sp));
// search the exception handler address of the caller (using the return address)
__ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::exception_handler_for_return_address), xthread, ra); // x10: exception handler address of the caller
// Only x10 is valid at this time; all other registers have been // destroyed by the call.
__ invalidate_registers(false, true, true, true, false, true);
// move result of call into correct register
__ mv(handler_addr, x10);
// get throwing pc (= return address). // ra has been destroyed by the call
__ ld(ra, Address(sp));
__ ld(exception_oop, Address(sp, wordSize));
__ addi(sp, sp, 2 * wordSize);
__ mv(x13, ra);
__ verify_not_null_oop(exception_oop);
// continue at exception handler (return address removed) // note: do *not* remove arguments when unwinding the // activation since the caller assumes having // all arguments on the stack when entering the // runtime to determine the exception handler // (GC happens at call site with arguments!) // x10: exception oop // x13: throwing pc // x11: exception handler
__ jr(handler_addr);
}
OopMapSet* Runtime1::generate_patching(StubAssembler* sasm, address target) { // use the maximum number of runtime-arguments here because it is difficult to // distinguish each RT-Call. // Note: This number affects also the RT-Call in generate_handle_exception because // the oop-map is shared for all calls.
DeoptimizationBlob* deopt_blob = SharedRuntime::deopt_blob();
assert(deopt_blob != NULL, "deoptimization blob must have been created");
#ifdef ASSERT // Check that fields in JavaThread for exception oop and issuing pc are empty
Label oop_empty;
__ ld(t0, Address(xthread, Thread::pending_exception_offset()));
__ beqz(t0, oop_empty);
__ stop("exception oop must be empty");
__ bind(oop_empty);
Label pc_empty;
__ ld(t0, Address(xthread, JavaThread::exception_pc_offset()));
__ beqz(t0, pc_empty);
__ stop("exception pc must be empty");
__ bind(pc_empty); #endif
// Runtime will return true if the nmethod has been deoptimized, this is the // expected scenario and anything else is an error. Note that we maintain a // check on the result purely as a defensive measure.
Label no_deopt;
__ beqz(x10, no_deopt); // Have we deoptimized?
// Perform a re-execute. The proper return address is already on the stack, // we just need to restore registers, pop all of our frames but the return // address and jump to the deopt blob.
case new_instance_id: case fast_new_instance_id: case fast_new_instance_init_check_id:
{ Register klass = x13; // Incoming Register obj = x10; // Result
oop_maps = new OopMapSet();
assert_cond(oop_maps != NULL);
oop_maps->add_gc_map(call_offset, map);
restore_live_registers_except_r10(sasm);
// x10: new multi array
__ verify_oop(x10);
} break;
case register_finalizer_id:
{
__ set_info("register_finalizer", dont_gc_arguments);
// This is called via call_runtime so the arguments // will be place in C abi locations
__ verify_oop(c_rarg0);
// load the klass and check the has finalizer flag
Label register_finalizer; Register t = x15;
__ load_klass(t, x10);
__ lwu(t, Address(t, Klass::access_flags_offset()));
__ andi(t0, t, JVM_ACC_HAS_FINALIZER);
__ bnez(t0, register_finalizer);
__ ret();
case slow_subtype_check_id:
{ // Typical calling sequence: // push klass_RInfo (object klass or other subclass) // push sup_k_RInfo (array element klass or other superclass) // jump to slow_subtype_check // Note that the subclass is pushed first, and is therefore deepest. enum layout {
x10_off, x10_off_hi,
x12_off, x12_off_hi,
x14_off, x14_off_hi,
x15_off, x15_off_hi,
sup_k_off, sup_k_off_hi,
klass_off, klass_off_hi,
framesize,
result_off = sup_k_off
};
__ ld(x14, Address(sp, (klass_off) * VMRegImpl::stack_slot_size)); // sub klass
__ ld(x10, Address(sp, (sup_k_off) * VMRegImpl::stack_slot_size)); // super klass
case monitorexit_nofpu_id:
save_fpu_registers = false; // fall through case monitorexit_id:
{
StubFrame f(sasm, "monitorexit", dont_gc_arguments);
OopMap* map = save_live_registers(sasm, save_fpu_registers);
assert_cond(map != NULL);
// Called with store_parameter and not C abi
f.load_argument(0, x10); // x10: lock address
// note: really a leaf routine but must setup last java sp // => use call_RT for now (speed can be improved by // doing last java sp setup manually) int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, monitorexit), x10);
case unwind_exception_id:
{
__ set_info("unwind_exception", dont_gc_arguments); // note: no stubframe since we are about to leave the current // activation and we are calling a leaf VM function only.
generate_unwind_exception(sasm);
} break;
case access_field_patching_id:
{
StubFrame f(sasm, "access_field_patching", dont_gc_arguments, does_not_return); // we should set up register map
oop_maps = generate_patching(sasm, CAST_FROM_FN_PTR(address, access_field_patching));
} break;
case load_klass_patching_id:
{
StubFrame f(sasm, "load_klass_patching", dont_gc_arguments, does_not_return); // we should set up register map
oop_maps = generate_patching(sasm, CAST_FROM_FN_PTR(address, move_klass_patching));
} break;
case load_mirror_patching_id:
{
StubFrame f(sasm, "load_mirror_patching", dont_gc_arguments, does_not_return); // we should set up register map
oop_maps = generate_patching(sasm, CAST_FROM_FN_PTR(address, move_mirror_patching));
} break;
case load_appendix_patching_id:
{
StubFrame f(sasm, "load_appendix_patching", dont_gc_arguments, does_not_return); // we should set up register map
oop_maps = generate_patching(sasm, CAST_FROM_FN_PTR(address, move_appendix_patching));
} break;
case handle_exception_nofpu_id: case handle_exception_id:
{
StubFrame f(sasm, "handle_exception", dont_gc_arguments);
oop_maps = generate_handle_exception(id, sasm);
} break;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.