/* * Copyright (c) 2008, 2022, Oracle and/or its affiliates. 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. *
*/
// This file mirror as much as possible methodHandles_x86.cpp to ease // cross platform development for JSR292. // Last synchronization: changeset f8c9417e3571
// Note: JVMTI overhead seems small enough compared to invocation // cost and is not worth the complexity or code size overhead of // supporting several variants of each adapter. if (!for_compiler_entry && (JvmtiExport::can_post_interpreter_events())) { // JVMTI events, such as single-stepping, are implemented partly by avoiding running // compiled code in threads for which the event is enabled. Check here for // interp_only_mode if these events CAN be enabled.
__ ldr_s32(Rtemp, Address(Rthread, JavaThread::interp_only_mode_offset()));
__ cmp(Rtemp, 0);
__ ldr(PC, Address(Rmethod, Method::interpreter_entry_offset()), ne);
} const ByteSize entry_offset = for_compiler_entry ? Method::from_compiled_offset() :
Method::from_interpreted_offset();
void MethodHandles::jump_to_lambda_form(MacroAssembler* _masm, Register recv, Register tmp, bool for_compiler_entry) {
BLOCK_COMMENT("jump_to_lambda_form {"); // This is the initial entry point of a lazy method handle. // After type checking, it picks up the invoker from the LambdaForm.
assert_different_registers(recv, tmp, Rmethod);
// Load the invoker, as MH -> MH.form -> LF.vmentry
__ load_heap_oop(tmp, Address(recv, NONZERO(java_lang_invoke_MethodHandle::form_offset())));
__ verify_oop(tmp);
// Code generation
address MethodHandles::generate_method_handle_interpreter_entry(MacroAssembler* _masm,
vmIntrinsics::ID iid) { constbool not_for_compiler_entry = false; // this is the interpreter entry
assert(is_signature_polymorphic(iid), "expected invoke iid"); if (iid == vmIntrinsics::_invokeGeneric ||
iid == vmIntrinsics::_compiledLambdaForm ||
iid == vmIntrinsics::_linkToNative) { // Perhaps surprisingly, the user-visible names, and linkToCallSite, are not directly used. // They are linked to Java-generated adapters via MethodHandleNatives.linkMethod. // They all require an extra argument.
__ should_not_reach_here(); // empty stubs make SG sick return NULL;
}
// Rmethod: Method* // Rparams (SP on 32-bit ARM): pointer to parameters // Rsender_sp (R4/R19): sender SP (must preserve; see prepare_to_jump_from_interpreted) // R5_mh: receiver method handle (must load from sp[MethodTypeForm.vmslots]) // R1, R2, Rtemp: garbage temp, blown away
// Use same name as x86 to ease future merges Register rdx_temp = R2_tmp; Register rdx_param_size = rdx_temp; // size of parameters Register rax_temp = R1_tmp; Register rcx_mh = R5_mh; // MH receiver; dies quickly and is recycled Register rbx_method = Rmethod; // eventual target of this invocation Register rdi_temp = Rtemp;
// here's where control starts out:
__ align(CodeEntryAlignment);
address entry_point = __ pc();
if (VerifyMethodHandles) {
Label L;
BLOCK_COMMENT("verify_intrinsic_id {");
__ ldrh(rdi_temp, Address(rbx_method, Method::intrinsic_id_offset_in_bytes()));
__ sub_slow(rdi_temp, rdi_temp, (int) iid);
__ cbz(rdi_temp, L); if (iid == vmIntrinsics::_linkToVirtual ||
iid == vmIntrinsics::_linkToSpecial) { // could do this for all kinds, but would explode assembly code size
trace_method_handle(_masm, "bad Method*::intrinsic_id");
}
__ stop("bad Method*::intrinsic_id");
__ bind(L);
BLOCK_COMMENT("} verify_intrinsic_id");
}
// First task: Find out how big the argument list is.
Address rdx_first_arg_addr; int ref_kind = signature_polymorphic_intrinsic_ref_kind(iid);
assert(ref_kind != 0 || iid == vmIntrinsics::_invokeBasic, "must be _invokeBasic or a linkTo intrinsic"); if (ref_kind == 0 || MethodHandles::ref_kind_has_receiver(ref_kind)) {
__ ldr(rdx_param_size, Address(rbx_method, Method::const_offset()));
__ load_sized_value(rdx_param_size,
Address(rdx_param_size, ConstMethod::size_of_parameters_offset()), sizeof(u2), /*is_signed*/ false); // assert(sizeof(u2) == sizeof(Method::_size_of_parameters), "");
rdx_first_arg_addr = __ receiver_argument_address(Rparams, rdx_param_size, rdi_temp);
} else {
DEBUG_ONLY(rdx_param_size = noreg);
}
if (!is_signature_polymorphic_static(iid)) {
__ ldr(rcx_mh, rdx_first_arg_addr);
DEBUG_ONLY(rdx_param_size = noreg);
}
if (iid == vmIntrinsics::_invokeBasic) {
generate_method_handle_dispatch(_masm, iid, rcx_mh, noreg, not_for_compiler_entry);
} else { // Adjust argument list by popping the trailing MemberName argument. Register rcx_recv = noreg; if (MethodHandles::ref_kind_has_receiver(ref_kind)) { // Load the receiver (not the MH; the actual MemberName's receiver) up from the interpreter stack.
__ ldr(rcx_recv = rcx_mh, rdx_first_arg_addr);
DEBUG_ONLY(rdx_param_size = noreg);
} Register rbx_member = rbx_method; // MemberName ptr; incoming method ptr is dead now
__ pop(rbx_member);
generate_method_handle_dispatch(_masm, iid, rcx_recv, rbx_member, not_for_compiler_entry);
} return entry_point;
}
void MethodHandles::generate_method_handle_dispatch(MacroAssembler* _masm,
vmIntrinsics::ID iid, Register receiver_reg, Register member_reg, bool for_compiler_entry) {
assert(is_signature_polymorphic(iid), "expected invoke iid"); // Use same name as x86 to ease future merges Register rbx_method = Rmethod; // eventual target of this invocation // temps used in this code are not used in *either* compiled or interpreted calling sequences Register temp1 = (for_compiler_entry ? saved_last_sp_register() : R1_tmp); Register temp2 = R8; Register temp3 = Rtemp; // R12/R16 Register temp4 = R5; if (for_compiler_entry) {
assert(receiver_reg == (iid == vmIntrinsics::_linkToStatic ? noreg : j_rarg0), "only valid assignment");
assert_different_registers(temp1, j_rarg0, j_rarg1, j_rarg2, j_rarg3);
assert_different_registers(temp2, j_rarg0, j_rarg1, j_rarg2, j_rarg3);
assert_different_registers(temp3, j_rarg0, j_rarg1, j_rarg2, j_rarg3);
assert_different_registers(temp4, j_rarg0, j_rarg1, j_rarg2, j_rarg3);
}
assert_different_registers(temp1, temp2, temp3, receiver_reg);
assert_different_registers(temp1, temp2, temp3, temp4, member_reg); if (!for_compiler_entry)
assert_different_registers(temp1, temp2, temp3, temp4, saved_last_sp_register()); // don't trash lastSP
if (iid == vmIntrinsics::_invokeBasic) { // indirect through MH.form.exactInvoker.vmtarget
jump_to_lambda_form(_masm, receiver_reg, temp3, for_compiler_entry);
} elseif (iid == vmIntrinsics::_linkToNative) {
assert(for_compiler_entry, "only compiler entry is supported");
jump_to_native_invoker(_masm, member_reg, temp1);
} else { // The method is a member invoker used by direct method handles. if (VerifyMethodHandles) { // make sure the trailing argument really is a MemberName (caller responsibility)
verify_klass(_masm, member_reg, temp2, temp3, VM_CLASS_ID(java_lang_invoke_MemberName), "MemberName required for invokeVirtual etc.");
}
Register temp1_recv_klass = temp1; if (iid != vmIntrinsics::_linkToStatic) { if (iid == vmIntrinsics::_linkToSpecial) { // Don't actually load the klass; just null-check the receiver.
__ null_check(receiver_reg, temp3);
} else { // load receiver klass itself
__ null_check(receiver_reg, temp3, oopDesc::klass_offset_in_bytes());
__ load_klass(temp1_recv_klass, receiver_reg);
__ verify_klass_ptr(temp1_recv_klass);
}
BLOCK_COMMENT("check_receiver {"); // The receiver for the MemberName must be in receiver_reg. // Check the receiver against the MemberName.clazz if (VerifyMethodHandles && iid == vmIntrinsics::_linkToSpecial) { // Did not load it above...
__ load_klass(temp1_recv_klass, receiver_reg);
__ verify_klass_ptr(temp1_recv_klass);
} // Check the receiver against the MemberName.clazz if (VerifyMethodHandles && iid != vmIntrinsics::_linkToInterface) {
Label L_ok; Register temp2_defc = temp2;
__ load_heap_oop(temp2_defc, member_clazz);
load_klass_from_Class(_masm, temp2_defc, temp3, temp4);
__ verify_klass_ptr(temp2_defc);
__ check_klass_subtype(temp1_recv_klass, temp2_defc, temp3, temp4, noreg, L_ok); // If we get here, the type check failed!
__ stop("receiver class disagrees with MemberName.clazz");
__ bind(L_ok);
}
BLOCK_COMMENT("} check_receiver");
} if (iid == vmIntrinsics::_linkToSpecial ||
iid == vmIntrinsics::_linkToStatic) {
DEBUG_ONLY(temp1_recv_klass = noreg); // these guys didn't load the recv_klass
}
// Live registers at this point: // member_reg - MemberName that was the extra argument // temp1_recv_klass - klass of stacked receiver, if needed
case vmIntrinsics::_linkToVirtual:
{ // same as TemplateTable::invokevirtual, // minus the CP setup and profiling:
if (VerifyMethodHandles) {
verify_ref_kind(_masm, JVM_REF_invokeVirtual, member_reg, temp3);
}
// pick out the vtable index from the MemberName, and then we can discard it: Register temp2_index = temp2;
__ access_load_at(T_ADDRESS, IN_HEAP, member_vmindex, temp2_index, noreg, noreg, noreg);
// Note: The verifier invariants allow us to ignore MemberName.clazz and vmtarget // at this point. And VerifyMethodHandles has already checked clazz, if needed.
// get target Method* & entry point
__ lookup_virtual_method(temp1_recv_klass, temp2_index, Rmethod); break;
}
case vmIntrinsics::_linkToInterface:
{ // same as TemplateTable::invokeinterface // (minus the CP setup and profiling, with different argument motion) if (VerifyMethodHandles) {
verify_ref_kind(_masm, JVM_REF_invokeInterface, member_reg, temp3);
}
// given intf, index, and recv klass, dispatch to the implementation method
__ lookup_interface_method(temp1_recv_klass, temp3_intf, // note: next two args must be the same:
rbx_index, rbx_method,
temp2, temp4,
L_incompatible_class_change_error); break;
}
#ifndef PRODUCT enum {
ARG_LIMIT = 255, SLOP = 4, // use this parameter for checking for garbage stack movements:
UNREASONABLE_STACK_MOVE = (ARG_LIMIT + SLOP) // the slop defends against false alarms due to fencepost errors
};
if (last_sp != saved_sp && last_sp != NULL) {
log_info(methodhandles)("*** last_sp=" INTPTR_FORMAT, p2i(last_sp));
}
LogTarget(Trace, methodhandles) lt; if (lt.is_enabled()) {
ResourceMark rm;
LogStream ls(lt);
ls.print(" reg dump: "); int i; for (i = 0; i < trace_mh_nregs; i++) { if (i > 0 && i % 4 == 0)
ls.print("\n + dump: "); constchar* reg_name = trace_mh_regs[i]->name();
ls.print(" %s: " INTPTR_FORMAT, reg_name, p2i((void*)saved_regs[i]));
}
ls.cr();
{ // dump last frame (from JavaThread::print_frame_layout)
// Note: code is robust but the dumped information may not be // 100% correct, particularly with respect to the dumped // "unextended_sp". Getting it right for all trace_method_handle // call paths is not worth the complexity/risk. The correct slot // will be identified by *Rsender_sp anyway in the dump.
JavaThread* p = JavaThread::active();
// may not be needed by safer and unexpensive here
PreserveExceptionMark pem(Thread::current());
FrameValues values;
intptr_t* dump_fp = (intptr_t *) saved_bp;
address dump_pc = (address) saved_regs[trace_mh_nregs-2]; // LR (with LR,PC last in saved_regs)
frame dump_frame((intptr_t *)entry_sp, dump_fp, dump_pc);
dump_frame.describe(values, 1); // mark Rsender_sp if seems valid if (has_mh) { if ((saved_sp >= entry_sp - UNREASONABLE_STACK_MOVE) && (saved_sp < dump_fp)) {
values.describe(-1, saved_sp, "*Rsender_sp");
}
}
// Note: the unextended_sp may not be correct
ls.print_cr(" stack layout:");
values.print_on(p, &ls);
}
if (has_mh && oopDesc::is_oop(mh)) {
mh->print_on(&ls); if (java_lang_invoke_MethodHandle::is_instance(mh)) {
java_lang_invoke_MethodHandle::form(mh)->print_on(&ls);
}
}
}
}
void MethodHandles::trace_method_handle(MacroAssembler* _masm, constchar* adaptername) { if (!log_is_enabled(Info, methodhandles)) return;
BLOCK_COMMENT("trace_method_handle {"); // register saving // must correspond to trace_mh_nregs and trace_mh_regs defined above int push_size = __ save_all_registers();
assert(trace_mh_nregs*wordSize == push_size,"saved register count mismatch");
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.