/* * Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2014, 2021, Red Hat Inc. 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. *
*/
// do the call
lea(rscratch1, RuntimeAddress(entry));
blr(rscratch1);
bind(retaddr); int call_offset = offset(); // verify callee-saved register #ifdef ASSERT
push(r0, sp);
{ Label L;
get_thread(r0);
cmp(rthread, r0);
br(Assembler::EQ, L);
stop("StubAssembler::call_RT: rthread not callee saved?");
bind(L);
}
pop(r0, sp); #endif
reset_last_Java_frame(true);
// check for pending exceptions
{ Label L; // check for pending exceptions (java_thread is set upon return)
ldr(rscratch1, Address(rthread, in_bytes(Thread::pending_exception_offset())));
cbz(rscratch1, L); // exception pending => remove activation and forward to exception handler // make sure that the vm_results are cleared if (oop_result1->is_valid()) {
str(zr, Address(rthread, JavaThread::vm_result_offset()));
} if (metadata_result->is_valid()) {
str(zr, Address(rthread, 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_result1->is_valid()) {
get_vm_result(oop_result1, rthread);
} if (metadata_result->is_valid()) {
get_vm_result_2(metadata_result, rthread);
} 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 FP 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.
static OopMap* generate_oop_map(StubAssembler* sasm, bool save_fpu_registers) { int frame_size_in_bytes = reg_save_frame_size * BytesPerWord;
sasm->set_frame_size(frame_size_in_bytes / BytesPerWord); int frame_size_in_slots = frame_size_in_bytes / sizeof(jint);
OopMap* oop_map = new OopMap(frame_size_in_slots, 0);
for (int i = 0; i < FrameMap::nof_cpu_regs; i++) { Register r = as_Register(i); if (i <= 18 && i != rscratch1->encoding() && i != rscratch2->encoding()) { int sp_offset = cpu_reg_save_offsets[i];
oop_map->set_callee_saved(VMRegImpl::stack2reg(sp_offset),
r->as_VMReg());
}
}
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;
}
void Runtime1::initialize_pd() { int i; int sp_offset = 0;
// all float registers are saved explicitly
assert(FrameMap::nof_fpu_regs == 32, "double registers not handled here"); for (i = 0; i < FrameMap::nof_fpu_regs; i++) {
fpu_reg_save_offsets[i] = sp_offset;
sp_offset += 2; // SP offsets are in halfwords
}
for (i = 0; i < FrameMap::nof_cpu_regs; i++) { Register r = as_Register(i);
cpu_reg_save_offsets[i] = sp_offset;
sp_offset += 2; // SP offsets are in halfwords
}
}
// target: the entry point of the method that creates and posts the exception oop // has_argument: true if the exception needs arguments (passed in rscratch1 and rscratch2)
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); int call_offset; if (!has_argument) {
call_offset = __ call_RT(noreg, noreg, target);
} else {
__ mov(c_rarg1, rscratch1);
__ mov(c_rarg2, rscratch2);
call_offset = __ call_RT(noreg, noreg, target);
}
OopMapSet* oop_maps = new OopMapSet();
oop_maps->add_gc_map(call_offset, oop_map); return oop_maps;
}
// incoming parameters constRegister exception_oop = r0; constRegister exception_pc = r3; // other registers used in this stub
// Save registers, if required.
OopMapSet* oop_maps = new OopMapSet();
OopMap* oop_map = NULL; 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 r0
__ ldr(exception_oop, Address(rthread, Thread::pending_exception_offset()));
__ str(zr, Address(rthread, Thread::pending_exception_offset()));
// load issuing PC (the return address for this stub) into r3
__ ldr(exception_pc, Address(rfp, 1*BytesPerWord));
__ authenticate_return_address(exception_pc, rscratch1);
// make sure that the vm_results are cleared (may be unnecessary)
__ str(zr, Address(rthread, JavaThread::vm_result_offset()));
__ str(zr, Address(rthread, 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 (r0) and // exception pc (lr) 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 r0 and r3 are valid at this time
__ invalidate_registers(false, true, true, false, true, true); // verify that r0 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;
__ ldr(rscratch1, Address(rthread, JavaThread::exception_oop_offset()));
__ cbz(rscratch1, 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)
__ str(exception_oop, Address(rthread, JavaThread::exception_oop_offset()));
__ str(exception_pc, Address(rthread, JavaThread::exception_pc_offset()));
// patch throwing pc into return address (has bci & oop map)
__ protect_return_address(exception_pc, rscratch1);
__ str(exception_pc, Address(rfp, 1*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));
oop_maps->add_gc_map(call_offset, oop_map);
// r0: 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 r0 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
__ protect_return_address(r0, rscratch1);
__ str(r0, Address(rfp, 1*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 = r0; // callee-saved copy of exception_oop during runtime call constRegister exception_oop_callee_saved = r19; // other registers used in this stub constRegister exception_pc = r3; constRegister handler_addr = r1;
// verify that only r0, 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;
__ ldr(rscratch1, Address(rthread, JavaThread::exception_oop_offset()));
__ cbz(rscratch1, oop_empty);
__ stop("exception oop must be empty");
__ bind(oop_empty);
Label pc_empty;
__ ldr(rscratch1, Address(rthread, JavaThread::exception_pc_offset()));
__ cbz(rscratch1, 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
__ mov(r3, lr);
__ protect_return_address();
__ stp(lr, exception_oop, Address(__ pre(sp, -2 * wordSize)));
// 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), rthread, r3); // r0: exception handler address of the caller
// Only R0 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
__ mov(handler_addr, r0);
// get throwing pc (= return address). // lr has been destroyed by the call
__ ldp(lr, exception_oop, Address(__ post(sp, 2 * wordSize)));
__ authenticate_return_address();
__ mov(r3, lr);
__ 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!) // r0: exception oop // r3: throwing pc // r1: exception handler
__ br(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;
__ ldr(rscratch1, Address(rthread, Thread::pending_exception_offset()));
__ cbz(rscratch1, oop_empty);
__ stop("exception oop must be empty");
__ bind(oop_empty);
Label pc_empty;
__ ldr(rscratch1, Address(rthread, JavaThread::exception_pc_offset()));
__ cbz(rscratch1, 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;
__ cbz(r0, 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 frame but the return // address and jump to the deopt blob.
restore_live_registers(sasm);
__ leave();
__ far_jump(RuntimeAddress(deopt_blob->unpack_with_reexecution()));
__ bind(no_deopt);
__ stop("deopt not performed");
oop_maps = new OopMapSet();
oop_maps->add_gc_map(call_offset, map);
restore_live_registers_except_r0(sasm);
// r0,: new multi array
__ verify_oop(r0);
} 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 = r5;
__ load_klass(t, r0);
__ ldrw(t, Address(t, Klass::access_flags_offset()));
__ tbnz(t, exact_log2(JVM_ACC_HAS_FINALIZER), register_finalizer);
__ ret(lr);
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 // __ bl(slow_subtype_check); // Note that the subclass is pushed first, and is therefore deepest. enum layout {
r0_off, r0_off_hi,
r2_off, r2_off_hi,
r4_off, r4_off_hi,
r5_off, r5_off_hi,
sup_k_off, sup_k_off_hi,
klass_off, klass_off_hi,
framesize,
result_off = sup_k_off
};
// This is called by pushing args and not with C abi // __ ldr(r4, Address(sp, (klass_off) * VMRegImpl::stack_slot_size)); // subclass // __ ldr(r0, Address(sp, (sup_k_off) * VMRegImpl::stack_slot_size)); // superclass
case monitorenter_nofpu_id:
save_fpu_registers = false; // fall through case monitorenter_id:
{
StubFrame f(sasm, "monitorenter", dont_gc_arguments);
OopMap* map = save_live_registers(sasm, save_fpu_registers);
int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, monitorenter), r0, r1);
oop_maps = new OopMapSet();
oop_maps->add_gc_map(call_offset, map);
restore_live_registers(sasm, save_fpu_registers);
} break;
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);
// Called with store_parameter and not C abi
f.load_argument(0, r0); // r0,: 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), r0);
oop_maps = new OopMapSet();
oop_maps->add_gc_map(call_offset, map);
restore_live_registers(sasm, save_fpu_registers);
} break;
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 ist noch experimentell.