2009-04-08 10:56:49 -07:00
|
|
|
/*
|
2020-02-06 14:29:57 +00:00
|
|
|
* Copyright (c) 2008, 2020, Oracle and/or its affiliates. All rights reserved.
|
2009-04-08 10:56:49 -07:00
|
|
|
* 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.
|
|
|
|
*
|
2010-05-27 19:08:38 -07:00
|
|
|
* 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.
|
2009-04-08 10:56:49 -07:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2019-01-10 15:13:51 -05:00
|
|
|
#ifndef SHARE_PRIMS_METHODHANDLES_HPP
|
|
|
|
#define SHARE_PRIMS_METHODHANDLES_HPP
|
2010-11-23 13:22:55 -08:00
|
|
|
|
|
|
|
#include "classfile/javaClasses.hpp"
|
|
|
|
#include "classfile/vmSymbols.hpp"
|
2018-03-21 19:45:24 -04:00
|
|
|
#include "runtime/frame.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "runtime/globals.hpp"
|
2016-07-13 12:23:05 +02:00
|
|
|
#include "utilities/macros.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
|
2016-07-13 12:23:05 +02:00
|
|
|
#ifdef ZERO
|
2015-12-22 11:11:29 -05:00
|
|
|
# include "entry_zero.hpp"
|
2018-03-21 19:45:24 -04:00
|
|
|
# include "interpreter/interpreter.hpp"
|
2015-12-22 11:11:29 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2009-04-08 10:56:49 -07:00
|
|
|
class MacroAssembler;
|
|
|
|
class Label;
|
|
|
|
|
|
|
|
class MethodHandles: AllStatic {
|
|
|
|
// JVM support for MethodHandle, MethodType, and related types
|
2011-03-11 22:34:57 -08:00
|
|
|
// in java.lang.invoke and sun.invoke.
|
|
|
|
// See also javaClasses for layouts java_lang_invoke_Method{Handle,Type,Type::Form}.
|
2009-04-08 10:56:49 -07:00
|
|
|
public:
|
|
|
|
public:
|
|
|
|
static bool enabled() { return _enabled; }
|
|
|
|
static void set_enabled(bool z);
|
|
|
|
|
|
|
|
private:
|
|
|
|
static bool _enabled;
|
2009-10-17 19:51:05 -07:00
|
|
|
|
2010-03-16 11:52:17 +01:00
|
|
|
// Adapters.
|
|
|
|
static MethodHandlesAdapterBlob* _adapter_code;
|
|
|
|
|
2013-09-13 22:38:02 -04:00
|
|
|
// utility functions for reifying names and types
|
|
|
|
static oop field_name_or_null(Symbol* s);
|
|
|
|
static oop field_signature_type_or_null(Symbol* s);
|
|
|
|
|
2009-04-08 10:56:49 -07:00
|
|
|
public:
|
2012-07-24 10:51:00 -07:00
|
|
|
// working with member names
|
2018-03-29 10:38:29 +02:00
|
|
|
static Handle resolve_MemberName(Handle mname, Klass* caller,
|
|
|
|
bool speculative_resolve, TRAPS); // compute vmtarget/vmindex from name/type
|
2012-07-24 10:51:00 -07:00
|
|
|
static void expand_MemberName(Handle mname, int suppress, TRAPS); // expand defc/name/type if missing
|
2017-05-27 09:21:01 -04:00
|
|
|
static oop init_MemberName(Handle mname_h, Handle target_h, TRAPS); // compute vmtarget/vmindex from target
|
2013-09-13 22:38:02 -04:00
|
|
|
static oop init_field_MemberName(Handle mname_h, fieldDescriptor& fd, bool is_setter = false);
|
2017-05-27 09:21:01 -04:00
|
|
|
static oop init_method_MemberName(Handle mname_h, CallInfo& info);
|
2017-03-15 10:25:37 -04:00
|
|
|
static int find_MemberNames(Klass* k, Symbol* name, Symbol* sig,
|
|
|
|
int mflags, Klass* caller,
|
2017-05-27 09:21:01 -04:00
|
|
|
int skip, objArrayHandle results, TRAPS);
|
2018-01-12 01:52:06 +03:00
|
|
|
static Handle resolve_MemberName_type(Handle mname, Klass* caller, TRAPS);
|
|
|
|
|
2012-07-24 10:51:00 -07:00
|
|
|
// bit values for suppress argument to expand_MemberName:
|
|
|
|
enum { _suppress_defc = 1, _suppress_name = 2, _suppress_type = 4 };
|
2011-05-06 16:33:13 -07:00
|
|
|
|
2015-04-17 18:17:06 +03:00
|
|
|
// CallSite support
|
2015-05-15 19:23:11 +03:00
|
|
|
static void add_dependent_nmethod(oop call_site, nmethod* nm);
|
|
|
|
static void remove_dependent_nmethod(oop call_site, nmethod* nm);
|
2018-11-30 11:40:48 +01:00
|
|
|
static void clean_dependency_context(oop call_site);
|
2015-05-15 19:23:11 +03:00
|
|
|
|
|
|
|
static void flush_dependent_nmethods(Handle call_site, Handle target);
|
2015-04-17 18:17:06 +03:00
|
|
|
|
2012-07-24 10:51:00 -07:00
|
|
|
// Generate MethodHandles adapters.
|
2016-02-15 20:26:02 +03:00
|
|
|
static void generate_adapters();
|
2011-05-06 16:33:13 -07:00
|
|
|
|
2012-07-24 10:51:00 -07:00
|
|
|
// Called from MethodHandlesAdapterGenerator.
|
|
|
|
static address generate_method_handle_interpreter_entry(MacroAssembler* _masm, vmIntrinsics::ID iid);
|
|
|
|
static void generate_method_handle_dispatch(MacroAssembler* _masm,
|
|
|
|
vmIntrinsics::ID iid,
|
|
|
|
Register receiver_reg,
|
|
|
|
Register member_reg,
|
|
|
|
bool for_compiler_entry);
|
2011-05-06 16:33:13 -07:00
|
|
|
|
2012-07-24 10:51:00 -07:00
|
|
|
// Queries
|
|
|
|
static bool is_signature_polymorphic(vmIntrinsics::ID iid) {
|
|
|
|
return (iid >= vmIntrinsics::FIRST_MH_SIG_POLY &&
|
|
|
|
iid <= vmIntrinsics::LAST_MH_SIG_POLY);
|
2011-05-06 16:33:13 -07:00
|
|
|
}
|
|
|
|
|
2015-12-04 23:46:19 +03:00
|
|
|
static bool is_signature_polymorphic_method(Method* m) {
|
|
|
|
return is_signature_polymorphic(m->intrinsic_id());
|
|
|
|
}
|
|
|
|
|
2012-07-24 10:51:00 -07:00
|
|
|
static bool is_signature_polymorphic_intrinsic(vmIntrinsics::ID iid) {
|
|
|
|
assert(is_signature_polymorphic(iid), "");
|
|
|
|
// Most sig-poly methods are intrinsics which do not require an
|
|
|
|
// appeal to Java for adapter code.
|
|
|
|
return (iid != vmIntrinsics::_invokeGeneric);
|
2011-05-06 16:33:13 -07:00
|
|
|
}
|
|
|
|
|
2012-07-24 10:51:00 -07:00
|
|
|
static bool is_signature_polymorphic_static(vmIntrinsics::ID iid) {
|
|
|
|
assert(is_signature_polymorphic(iid), "");
|
|
|
|
return (iid >= vmIntrinsics::FIRST_MH_STATIC &&
|
|
|
|
iid <= vmIntrinsics::LAST_MH_SIG_POLY);
|
2011-05-06 16:33:13 -07:00
|
|
|
}
|
|
|
|
|
2012-07-24 10:51:00 -07:00
|
|
|
static bool has_member_arg(vmIntrinsics::ID iid) {
|
|
|
|
assert(is_signature_polymorphic(iid), "");
|
|
|
|
return (iid >= vmIntrinsics::_linkToVirtual &&
|
|
|
|
iid <= vmIntrinsics::_linkToInterface);
|
2011-05-06 16:33:13 -07:00
|
|
|
}
|
2012-07-24 10:51:00 -07:00
|
|
|
static bool has_member_arg(Symbol* klass, Symbol* name) {
|
2016-03-24 11:21:49 +01:00
|
|
|
if ((klass == vmSymbols::java_lang_invoke_MethodHandle() ||
|
|
|
|
klass == vmSymbols::java_lang_invoke_VarHandle()) &&
|
2012-07-24 10:51:00 -07:00
|
|
|
is_signature_polymorphic_name(name)) {
|
|
|
|
vmIntrinsics::ID iid = signature_polymorphic_name_id(name);
|
|
|
|
return has_member_arg(iid);
|
2010-03-18 09:56:51 +01:00
|
|
|
}
|
2012-07-24 10:51:00 -07:00
|
|
|
return false;
|
2010-03-18 09:56:51 +01:00
|
|
|
}
|
|
|
|
|
2012-07-24 10:51:00 -07:00
|
|
|
static Symbol* signature_polymorphic_intrinsic_name(vmIntrinsics::ID iid);
|
|
|
|
static int signature_polymorphic_intrinsic_ref_kind(vmIntrinsics::ID iid);
|
2010-05-01 02:42:18 -07:00
|
|
|
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
static vmIntrinsics::ID signature_polymorphic_name_id(Klass* klass, Symbol* name);
|
2012-07-24 10:51:00 -07:00
|
|
|
static vmIntrinsics::ID signature_polymorphic_name_id(Symbol* name);
|
|
|
|
static bool is_signature_polymorphic_name(Symbol* name) {
|
|
|
|
return signature_polymorphic_name_id(name) != vmIntrinsics::_none;
|
2011-05-06 16:33:13 -07:00
|
|
|
}
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
static bool is_method_handle_invoke_name(Klass* klass, Symbol* name);
|
|
|
|
static bool is_signature_polymorphic_name(Klass* klass, Symbol* name) {
|
2012-07-24 10:51:00 -07:00
|
|
|
return signature_polymorphic_name_id(klass, name) != vmIntrinsics::_none;
|
2009-04-08 10:56:49 -07:00
|
|
|
}
|
2018-06-25 14:39:44 -07:00
|
|
|
static bool is_signature_polymorphic_public_name(Klass* klass, Symbol* name);
|
2009-04-08 10:56:49 -07:00
|
|
|
|
2015-12-04 23:46:19 +03:00
|
|
|
static Bytecodes::Code signature_polymorphic_intrinsic_bytecode(vmIntrinsics::ID id);
|
|
|
|
|
2012-07-24 10:51:00 -07:00
|
|
|
public:
|
|
|
|
static Symbol* lookup_signature(oop type_str, bool polymorphic, TRAPS); // use TempNewSymbol
|
|
|
|
static Symbol* lookup_basic_type_signature(Symbol* sig, bool keep_last_arg, TRAPS); // use TempNewSymbol
|
|
|
|
static Symbol* lookup_basic_type_signature(Symbol* sig, TRAPS) {
|
|
|
|
return lookup_basic_type_signature(sig, false, THREAD);
|
2010-05-01 02:42:18 -07:00
|
|
|
}
|
2012-07-24 10:51:00 -07:00
|
|
|
static bool is_basic_type_signature(Symbol* sig);
|
2010-05-01 02:42:18 -07:00
|
|
|
|
2020-02-06 14:29:57 +00:00
|
|
|
static void print_as_basic_type_signature_on(outputStream* st, Symbol* sig);
|
2012-07-24 10:51:00 -07:00
|
|
|
|
|
|
|
// decoding CONSTANT_MethodHandle constants
|
|
|
|
enum { JVM_REF_MIN = JVM_REF_getField, JVM_REF_MAX = JVM_REF_invokeInterface };
|
|
|
|
static bool ref_kind_is_valid(int ref_kind) {
|
|
|
|
return (ref_kind >= JVM_REF_MIN && ref_kind <= JVM_REF_MAX);
|
2009-04-08 10:56:49 -07:00
|
|
|
}
|
2012-07-24 10:51:00 -07:00
|
|
|
static bool ref_kind_is_field(int ref_kind) {
|
|
|
|
assert(ref_kind_is_valid(ref_kind), "");
|
|
|
|
return (ref_kind <= JVM_REF_putStatic);
|
2009-04-08 10:56:49 -07:00
|
|
|
}
|
2012-07-24 10:51:00 -07:00
|
|
|
static bool ref_kind_is_getter(int ref_kind) {
|
|
|
|
assert(ref_kind_is_valid(ref_kind), "");
|
|
|
|
return (ref_kind <= JVM_REF_getStatic);
|
2009-04-08 10:56:49 -07:00
|
|
|
}
|
2012-07-24 10:51:00 -07:00
|
|
|
static bool ref_kind_is_setter(int ref_kind) {
|
|
|
|
return ref_kind_is_field(ref_kind) && !ref_kind_is_getter(ref_kind);
|
2009-04-08 10:56:49 -07:00
|
|
|
}
|
2012-07-24 10:51:00 -07:00
|
|
|
static bool ref_kind_is_method(int ref_kind) {
|
|
|
|
return !ref_kind_is_field(ref_kind) && (ref_kind != JVM_REF_newInvokeSpecial);
|
2009-04-08 10:56:49 -07:00
|
|
|
}
|
2012-07-24 10:51:00 -07:00
|
|
|
static bool ref_kind_has_receiver(int ref_kind) {
|
|
|
|
assert(ref_kind_is_valid(ref_kind), "");
|
|
|
|
return (ref_kind & 1) != 0;
|
|
|
|
}
|
2009-04-08 10:56:49 -07:00
|
|
|
|
2018-01-12 01:52:06 +03:00
|
|
|
static int ref_kind_to_flags(int ref_kind);
|
|
|
|
|
2016-07-13 12:23:05 +02:00
|
|
|
#include CPU_HEADER(methodHandles)
|
2009-04-08 10:56:49 -07:00
|
|
|
|
2012-10-08 17:04:00 -07:00
|
|
|
// Tracing
|
|
|
|
static void trace_method_handle(MacroAssembler* _masm, const char* adaptername) PRODUCT_RETURN;
|
2017-11-28 21:43:45 +01:00
|
|
|
static void trace_method_handle_interpreter_entry(MacroAssembler* _masm, vmIntrinsics::ID iid);
|
2009-04-08 10:56:49 -07:00
|
|
|
};
|
|
|
|
|
2010-03-16 11:52:17 +01:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// MethodHandlesAdapterGenerator
|
|
|
|
//
|
|
|
|
class MethodHandlesAdapterGenerator : public StubCodeGenerator {
|
|
|
|
public:
|
2011-06-14 14:41:33 -07:00
|
|
|
MethodHandlesAdapterGenerator(CodeBuffer* code) : StubCodeGenerator(code, PrintMethodHandleStubs) {}
|
2010-03-16 11:52:17 +01:00
|
|
|
|
2011-01-10 00:56:39 -08:00
|
|
|
void generate();
|
2010-03-16 11:52:17 +01:00
|
|
|
};
|
2010-11-23 13:22:55 -08:00
|
|
|
|
2019-01-10 15:13:51 -05:00
|
|
|
#endif // SHARE_PRIMS_METHODHANDLES_HPP
|