/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* 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.
*
*/
#include "precompiled.hpp"
#include "interpreter/interpreter.hpp"
#include "interpreter/interpreterRuntime.hpp"
#include "memory/allocation.inline.hpp"
#include "prims/methodHandles.hpp"
#ifdef PRODUCT
#else
#endif
// Workaround for C++ overloading nastiness on '0' for RegisterOrConstant.
return RegisterOrConstant(value);
}
if (VerifyMethodHandles)
"MH argument is a Class");
}
#ifdef ASSERT
return x;
}
#else //ASSERT
#define NONZERO(x) (x)
#endif //ASSERT
#ifdef ASSERT
const char* error_message) {
"must be one of the SystemDictionaryHandles");
BLOCK_COMMENT("verify_klass {");
BLOCK_COMMENT("} verify_klass");
}
void MethodHandles::verify_ref_kind(MacroAssembler* _masm, int ref_kind, Register member_reg, Register temp) {
Label L;
BLOCK_COMMENT("verify_ref_kind {");
if (ref_kind == JVM_REF_invokeVirtual ||
// could do this for all ref_kinds, but would explode assembly code size
}
BLOCK_COMMENT("} verify_ref_kind");
}
#endif //ASSERT
bool for_compiler_entry) {
// 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.
#ifdef _LP64
#else
#endif
// interp_only is an int, on little endian it is sufficient to test the byte only
// Is a cmpl faster?
}
}
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.
//NOT_PRODUCT({ FlagSetting fs(TraceMethodHandles, true); trace_method_handle(_masm, "LZMH"); });
// Load the invoker, as MH -> MH.form -> LF.vmentry
__ load_heap_oop(method_temp, Address(recv, NONZERO(java_lang_invoke_MethodHandle::form_offset_in_bytes())));
__ load_heap_oop(method_temp, Address(method_temp, NONZERO(java_lang_invoke_LambdaForm::vmentry_offset_in_bytes())));
// the following assumes that a methodOop is normally compressed in the vmtarget field:
__ load_heap_oop(method_temp, Address(method_temp, NONZERO(java_lang_invoke_MemberName::vmtarget_offset_in_bytes())));
if (VerifyMethodHandles && !for_compiler_entry) {
// make sure recv is already on stack
sizeof(u2), /*is_signed*/ false);
// assert(sizeof(u2) == sizeof(methodOopDesc::_size_of_parameters), "");
Label L;
}
BLOCK_COMMENT("} jump_to_lambda_form");
}
// Code generation
// Perhaps surprisingly, the symbolic references visible to Java are not directly used.
// They are linked to Java-generated adapters via MethodHandleNatives.linkMethod.
// They all allow an appendix argument.
return NULL;
}
// rbx: methodOop
// rdx: argument locator (parameter slot count, added to rsp)
// rcx: used as temp to hold mh or receiver
// rax, rdi: garbage temps, blown away
// here's where control starts out:
if (VerifyMethodHandles) {
Label L;
BLOCK_COMMENT("verify_intrinsic_id {");
// could do this for all kinds, but would explode assembly code size
}
BLOCK_COMMENT("} verify_intrinsic_id");
}
// First task: Find out how big the argument list is.
assert(ref_kind != 0 || iid == vmIntrinsics::_invokeBasic, "must be _invokeBasic or a linkTo intrinsic");
sizeof(u2), /*is_signed*/ false);
// assert(sizeof(u2) == sizeof(methodOopDesc::_size_of_parameters), "");
} else {
}
if (!is_signature_polymorphic_static(iid)) {
}
// rdx_first_arg_addr is live!
} else {
// Adjust argument list by popping the trailing MemberName argument.
// Load the receiver (not the MH; the actual MemberName's receiver) up from the interpreter stack.
}
}
return entry_point;
}
bool for_compiler_entry) {
// temps used in this code are not used in *either* compiled or interpreted calling sequences
#ifdef _LP64
if (for_compiler_entry) {
assert(receiver_reg == (iid == vmIntrinsics::_linkToStatic ? noreg : j_rarg0), "only valid assignment");
}
#else
if (for_compiler_entry) {
assert(receiver_reg == (iid == vmIntrinsics::_linkToStatic ? noreg : rcx), "only valid assignment");
}
#endif
else {
}
// indirect through MH.form.vmentry.vmtarget
} 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)
"MemberName required for invokeVirtual etc.");
}
Address member_vmindex( member_reg, NONZERO(java_lang_invoke_MemberName::vmindex_offset_in_bytes()));
Address member_vmtarget( member_reg, NONZERO(java_lang_invoke_MemberName::vmtarget_offset_in_bytes()));
// Don't actually load the klass; just null-check the receiver.
} else {
// load receiver klass itself
}
BLOCK_COMMENT("check_receiver {");
// The receiver for the MemberName must be in receiver_reg.
// Check the receiver against the MemberName.clazz
// Did not load it above...
}
// If we get here, the type check failed!
}
BLOCK_COMMENT("} check_receiver");
}
}
// Live registers at this point:
// member_reg - MemberName that was the trailing argument
// temp1_recv_klass - klass of stacked receiver, if needed
// rcx, rdx, rsi, rdi, r8, r8 - compiler arguments (if compiled)
switch (iid) {
case vmIntrinsics::_linkToSpecial:
if (VerifyMethodHandles) {
}
break;
case vmIntrinsics::_linkToStatic:
if (VerifyMethodHandles) {
}
break;
case vmIntrinsics::_linkToVirtual:
{
// same as TemplateTable::invokevirtual,
// minus the CP setup and profiling:
if (VerifyMethodHandles) {
}
// pick out the vtable index from the MemberName, and then we can discard it:
if (VerifyMethodHandles) {
}
// 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 methodOop & entry point
break;
}
case vmIntrinsics::_linkToInterface:
{
// same as TemplateTable::invokeinterface
// (minus the CP setup and profiling, with different argument motion)
if (VerifyMethodHandles) {
}
if (VerifyMethodHandles) {
Label L;
}
// given intf, index, and recv klass, dispatch to the implementation method
// note: next two args must be the same:
break;
}
default:
break;
}
// Live at this point:
// rbx_method
// After figuring out which concrete method to call, jump into it.
// Note that this works in the interpreter with no data motion.
// But the compiled version will require that rcx_recv be shifted out.
}
}
}
#ifndef PRODUCT
// called as a leaf from native code: do not block the JVM!
if (Verbose) {
for (int i = 0; i < saved_regs_count; i++) {
Register r = as_Register(i);
// The registers are stored in reverse order on the stack (by pusha).
if ((i + 1) % 4 == 0) {
} else {
}
}
{
// dumping last frame with frame::describe
PRESERVE_EXCEPTION_MARK; // may not be needed by safer and unexpensive here
// Note: We want to allow trace_method_handle from any call site.
// While trace_method_handle creates a frame, it may be entered
// without a PC on the stack top (e.g. not just after a call).
// Walking that frame could lead to failures due to that invalid PC.
// => carefully detect that frame when doing the stack walking
// Current C frame
// Robust search of trace_calling_frame (independant of inlining).
// Assumes saved_regs comes from a pusha in the trace_calling_frame.
}
// safely create a frame and call frame::describe
if (walkable) {
// The previous definition of walkable may have to be refined
// if new call sites cause the next frame constructor to start
// failing. Alternatively, frame constructors could be
// modified to support the current or future non walkable
// frames (but this is more intrusive and is not considered as
// part of this RFE, which will instead use a simpler output).
} else {
// Stack may not be walkable (invalid PC above FP):
// Add descriptions without building a Java frame to avoid issues
}
}
if (java_lang_invoke_MethodHandle::form_offset_in_bytes() != 0)
}
}
}
}
// The stub wraps the arguments in a struct on the stack to avoid
// dealing with the different calling conventions for passing 6
// arguments.
struct MethodHandleStubArguments {
const char* adaptername;
};
}
if (!TraceMethodHandles) return;
BLOCK_COMMENT("trace_method_handle {");
// Note: saved_regs must be in the entered frame for the
// robust stack walking implemented in trace_method_handle_stub.
// save FP result, valid at some call sites (adapter_opt_return_float, ...)
if (UseSSE >= 2) {
} else if (UseSSE == 1) {
} else {
}
// Incoming state:
// rcx: method handle
//
// To avoid calling convention issues, build a record on the stack
// and pass the pointer to that instead.
if (UseSSE >= 2) {
} else if (UseSSE == 1) {
} else {
}
BLOCK_COMMENT("} trace_method_handle");
}
#endif //PRODUCT