0N/A/*
3909N/A * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation.
0N/A *
2362N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
0N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
2362N/A *
2362N/A */
0N/A
0N/A#ifndef SHARE_VM_PRIMS_METHODHANDLES_HPP
0N/A#define SHARE_VM_PRIMS_METHODHANDLES_HPP
0N/A
2956N/A#include "classfile/javaClasses.hpp"
2638N/A#include "classfile/vmSymbols.hpp"
3444N/A#include "runtime/frame.inline.hpp"
2638N/A#include "runtime/globals.hpp"
2956N/A#include "runtime/interfaceSupport.hpp"
2956N/A
2956N/Aclass MacroAssembler;
2638N/Aclass Label;
2956N/A
2956N/Aclass MethodHandles: AllStatic {
2956N/A // JVM support for MethodHandle, MethodType, and related types
3444N/A // in java.lang.invoke and sun.invoke.
2956N/A // See also javaClasses for layouts java_lang_invoke_Method{Handle,Type,Type::Form}.
2638N/A public:
2956N/A public:
2956N/A static bool enabled() { return _enabled; }
2956N/A static void set_enabled(bool z);
3444N/A
3444N/A private:
2956N/A static bool _enabled;
2956N/A
2956N/A // Adapters.
3719N/A static MethodHandlesAdapterBlob* _adapter_code;
3719N/A
3719N/A public:
3719N/A // working with member names
3719N/A static Handle resolve_MemberName(Handle mname, TRAPS); // compute vmtarget/vmindex from name/type
2956N/A static void expand_MemberName(Handle mname, int suppress, TRAPS); // expand defc/name/type if missing
3444N/A static Handle new_MemberName(TRAPS); // must be followed by init_MemberName
2638N/A static oop init_MemberName(oop mname_oop, oop target_oop); // compute vmtarget/vmindex from target
3719N/A static oop init_method_MemberName(oop mname_oop, methodOop m, bool do_dispatch,
3719N/A klassOop receiver_limit);
3444N/A static oop init_field_MemberName(oop mname_oop, klassOop field_holder,
2638N/A AccessFlags mods, oop type, oop name,
2638N/A intptr_t offset, bool is_setter = false);
2956N/A static Handle init_method_MemberName(oop mname_oop, CallInfo& info, TRAPS);
3444N/A static Handle init_field_MemberName(oop mname_oop, FieldAccessInfo& info, TRAPS);
3444N/A static int method_ref_kind(methodOop m, bool do_dispatch_if_possible = true);
3444N/A static int find_MemberNames(klassOop k, Symbol* name, Symbol* sig,
3444N/A int mflags, klassOop caller,
3444N/A int skip, objArrayOop results);
3444N/A // bit values for suppress argument to expand_MemberName:
3444N/A enum { _suppress_defc = 1, _suppress_name = 2, _suppress_type = 4 };
3444N/A
3444N/A // Generate MethodHandles adapters.
3444N/A static void generate_adapters();
3444N/A
3444N/A // Called from MethodHandlesAdapterGenerator.
2956N/A static address generate_method_handle_interpreter_entry(MacroAssembler* _masm, vmIntrinsics::ID iid);
3444N/A static void generate_method_handle_dispatch(MacroAssembler* _masm,
2956N/A vmIntrinsics::ID iid,
3444N/A Register receiver_reg,
3444N/A Register member_reg,
3444N/A bool for_compiler_entry);
3444N/A
2956N/A // Queries
3444N/A static bool is_signature_polymorphic(vmIntrinsics::ID iid) {
3444N/A return (iid >= vmIntrinsics::FIRST_MH_SIG_POLY &&
3444N/A iid <= vmIntrinsics::LAST_MH_SIG_POLY);
3444N/A }
3444N/A
3444N/A static bool is_signature_polymorphic_intrinsic(vmIntrinsics::ID iid) {
3444N/A assert(is_signature_polymorphic(iid), "");
3444N/A // Most sig-poly methods are intrinsics which do not require an
2638N/A // appeal to Java for adapter code.
3444N/A return (iid != vmIntrinsics::_invokeGeneric);
3444N/A }
3444N/A
3444N/A static bool is_signature_polymorphic_static(vmIntrinsics::ID iid) {
3444N/A assert(is_signature_polymorphic(iid), "");
3444N/A return (iid >= vmIntrinsics::FIRST_MH_STATIC &&
3444N/A iid <= vmIntrinsics::LAST_MH_SIG_POLY);
3444N/A }
3444N/A
3444N/A static bool has_member_arg(vmIntrinsics::ID iid) {
3444N/A assert(is_signature_polymorphic(iid), "");
3444N/A return (iid >= vmIntrinsics::_linkToVirtual &&
3444N/A iid <= vmIntrinsics::_linkToInterface);
3444N/A }
3444N/A static bool has_member_arg(Symbol* klass, Symbol* name) {
3444N/A if ((klass == vmSymbols::java_lang_invoke_MethodHandle()) &&
3444N/A is_signature_polymorphic_name(name)) {
3444N/A vmIntrinsics::ID iid = signature_polymorphic_name_id(name);
3444N/A return has_member_arg(iid);
2956N/A }
3444N/A return false;
2638N/A }
2638N/A
2956N/A static Symbol* signature_polymorphic_intrinsic_name(vmIntrinsics::ID iid);
2956N/A static int signature_polymorphic_intrinsic_ref_kind(vmIntrinsics::ID iid);
2638N/A
2638N/A static vmIntrinsics::ID signature_polymorphic_name_id(klassOop klass, Symbol* name);
2956N/A static vmIntrinsics::ID signature_polymorphic_name_id(Symbol* name);
2956N/A static bool is_signature_polymorphic_name(Symbol* name) {
2956N/A return signature_polymorphic_name_id(name) != vmIntrinsics::_none;
2638N/A }
2638N/A static bool is_method_handle_invoke_name(klassOop klass, Symbol* name);
2638N/A static bool is_signature_polymorphic_name(klassOop klass, Symbol* name) {
2638N/A return signature_polymorphic_name_id(klass, name) != vmIntrinsics::_none;
2638N/A }
2638N/A
2956N/A enum {
2956N/A // format of query to getConstant:
2638N/A GC_COUNT_GWT = 4,
2956N/A GC_LAMBDA_SUPPORT = 5
3444N/A };
3444N/A static int get_named_constant(int which, Handle name_box, TRAPS);
3444N/A
2956N/Apublic:
2956N/A static Symbol* lookup_signature(oop type_str, bool polymorphic, TRAPS); // use TempNewSymbol
3444N/A static Symbol* lookup_basic_type_signature(Symbol* sig, bool keep_last_arg, TRAPS); // use TempNewSymbol
3444N/A static Symbol* lookup_basic_type_signature(Symbol* sig, TRAPS) {
3444N/A return lookup_basic_type_signature(sig, false, THREAD);
2956N/A }
2956N/A static bool is_basic_type_signature(Symbol* sig);
2956N/A
2956N/A static Symbol* lookup_method_type(Symbol* msig, Handle mtype, TRAPS);
2956N/A
2956N/A static void print_as_method_type_on(outputStream* st, Symbol* sig) {
3444N/A print_as_basic_type_signature_on(st, sig, true, true);
3444N/A }
3444N/A static void print_as_basic_type_signature_on(outputStream* st, Symbol* sig, bool keep_arrays = false, bool keep_basic_names = false);
2956N/A
3719N/A // decoding CONSTANT_MethodHandle constants
3444N/A enum { JVM_REF_MIN = JVM_REF_getField, JVM_REF_MAX = JVM_REF_invokeInterface };
3444N/A static bool ref_kind_is_valid(int ref_kind) {
2956N/A return (ref_kind >= JVM_REF_MIN && ref_kind <= JVM_REF_MAX);
2638N/A }
2956N/A static bool ref_kind_is_field(int ref_kind) {
2956N/A assert(ref_kind_is_valid(ref_kind), "");
3444N/A return (ref_kind <= JVM_REF_putStatic);
3444N/A }
3719N/A static bool ref_kind_is_getter(int ref_kind) {
3444N/A assert(ref_kind_is_valid(ref_kind), "");
3444N/A return (ref_kind <= JVM_REF_getStatic);
3444N/A }
3444N/A static bool ref_kind_is_setter(int ref_kind) {
3444N/A return ref_kind_is_field(ref_kind) && !ref_kind_is_getter(ref_kind);
3444N/A }
2956N/A static bool ref_kind_is_method(int ref_kind) {
2956N/A return !ref_kind_is_field(ref_kind) && (ref_kind != JVM_REF_newInvokeSpecial);
2956N/A }
3444N/A static bool ref_kind_has_receiver(int ref_kind) {
3444N/A assert(ref_kind_is_valid(ref_kind), "");
3719N/A return (ref_kind & 1) != 0;
3719N/A }
3444N/A static bool ref_kind_is_static(int ref_kind) {
3444N/A return !ref_kind_has_receiver(ref_kind) && (ref_kind != JVM_REF_newInvokeSpecial);
3444N/A }
3444N/A static bool ref_kind_does_dispatch(int ref_kind) {
3444N/A return (ref_kind == JVM_REF_invokeVirtual ||
3444N/A ref_kind == JVM_REF_invokeInterface);
3444N/A }
2956N/A
2956N/A
3444N/A#ifdef TARGET_ARCH_x86
3444N/A# include "methodHandles_x86.hpp"
3444N/A#endif
3444N/A#ifdef TARGET_ARCH_sparc
3444N/A# include "methodHandles_sparc.hpp"
3444N/A#endif
2956N/A#ifdef TARGET_ARCH_zero
3444N/A# include "methodHandles_zero.hpp"
3444N/A#endif
3444N/A#ifdef TARGET_ARCH_arm
3444N/A# include "methodHandles_arm.hpp"
3444N/A#endif
3444N/A#ifdef TARGET_ARCH_ppc
3444N/A# include "methodHandles_ppc.hpp"
3444N/A#endif
2956N/A
3444N/A // Tracing
2956N/A static void trace_method_handle(MacroAssembler* _masm, const char* adaptername) PRODUCT_RETURN;
2956N/A static void trace_method_handle_interpreter_entry(MacroAssembler* _masm, vmIntrinsics::ID iid) {
3444N/A if (TraceMethodHandles) {
3444N/A const char* name = vmIntrinsics::name_at(iid);
3444N/A if (*name == '_') name += 1;
3444N/A const size_t len = strlen(name) + 50;
3444N/A char* qname = NEW_C_HEAP_ARRAY(char, len, mtInternal);
3444N/A const char* suffix = "";
3444N/A if (is_signature_polymorphic(iid)) {
3719N/A if (is_signature_polymorphic_static(iid))
3719N/A suffix = "/static";
2956N/A else
3444N/A suffix = "/private";
2956N/A }
2956N/A jio_snprintf(qname, len, "MethodHandle::interpreter_entry::%s%s", name, suffix);
2956N/A trace_method_handle(_masm, qname);
3444N/A // Note: Don't free the allocated char array because it's used
2956N/A // during runtime.
2956N/A }
2956N/A }
2956N/A};
2956N/A
2956N/A
2956N/A//------------------------------------------------------------------------------
2956N/A// MethodHandlesAdapterGenerator
3444N/A//
3444N/Aclass MethodHandlesAdapterGenerator : public StubCodeGenerator {
3444N/Apublic:
3444N/A MethodHandlesAdapterGenerator(CodeBuffer* code) : StubCodeGenerator(code, PrintMethodHandleStubs) {}
3444N/A
3444N/A void generate();
3444N/A};
3444N/A
3444N/A#endif // SHARE_VM_PRIMS_METHODHANDLES_HPP
3444N/A