Tue, 16 Aug 2016 12:48:43 -0700
Merge
jrose@1145 | 1 | /* |
coleenp@7391 | 2 | * Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved. |
jrose@1145 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jrose@1145 | 4 | * |
jrose@1145 | 5 | * This code is free software; you can redistribute it and/or modify it |
jrose@1145 | 6 | * under the terms of the GNU General Public License version 2 only, as |
jrose@1145 | 7 | * published by the Free Software Foundation. |
jrose@1145 | 8 | * |
jrose@1145 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jrose@1145 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jrose@1145 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jrose@1145 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
jrose@1145 | 13 | * accompanied this code). |
jrose@1145 | 14 | * |
jrose@1145 | 15 | * You should have received a copy of the GNU General Public License version |
jrose@1145 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
jrose@1145 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jrose@1145 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
jrose@1145 | 22 | * |
jrose@1145 | 23 | */ |
jrose@1145 | 24 | |
stefank@2314 | 25 | #ifndef SHARE_VM_PRIMS_METHODHANDLES_HPP |
stefank@2314 | 26 | #define SHARE_VM_PRIMS_METHODHANDLES_HPP |
stefank@2314 | 27 | |
stefank@2314 | 28 | #include "classfile/javaClasses.hpp" |
stefank@2314 | 29 | #include "classfile/vmSymbols.hpp" |
stefank@2314 | 30 | #include "runtime/frame.inline.hpp" |
stefank@2314 | 31 | #include "runtime/globals.hpp" |
stefank@2314 | 32 | #include "runtime/interfaceSupport.hpp" |
stefank@2314 | 33 | |
jrose@1145 | 34 | class MacroAssembler; |
jrose@1145 | 35 | class Label; |
jrose@1145 | 36 | |
jrose@1145 | 37 | class MethodHandles: AllStatic { |
jrose@1145 | 38 | // JVM support for MethodHandle, MethodType, and related types |
jrose@2639 | 39 | // in java.lang.invoke and sun.invoke. |
jrose@2639 | 40 | // See also javaClasses for layouts java_lang_invoke_Method{Handle,Type,Type::Form}. |
jrose@1145 | 41 | public: |
jrose@1145 | 42 | public: |
jrose@1145 | 43 | static bool enabled() { return _enabled; } |
jrose@1145 | 44 | static void set_enabled(bool z); |
jrose@1145 | 45 | |
jrose@1145 | 46 | private: |
jrose@1145 | 47 | static bool _enabled; |
jrose@1474 | 48 | |
twisti@1734 | 49 | // Adapters. |
twisti@1734 | 50 | static MethodHandlesAdapterBlob* _adapter_code; |
twisti@1734 | 51 | |
drchase@5732 | 52 | // utility functions for reifying names and types |
drchase@5732 | 53 | static oop field_name_or_null(Symbol* s); |
drchase@5732 | 54 | static oop field_signature_type_or_null(Symbol* s); |
drchase@5732 | 55 | |
jrose@1145 | 56 | public: |
jrose@1145 | 57 | // working with member names |
jrose@6246 | 58 | static Handle resolve_MemberName(Handle mname, KlassHandle caller, TRAPS); // compute vmtarget/vmindex from name/type |
jrose@1145 | 59 | static void expand_MemberName(Handle mname, int suppress, TRAPS); // expand defc/name/type if missing |
jrose@1862 | 60 | static Handle new_MemberName(TRAPS); // must be followed by init_MemberName |
sspitsyn@4965 | 61 | static oop init_MemberName(Handle mname_h, Handle target_h); // compute vmtarget/vmindex from target |
drchase@5732 | 62 | static oop init_field_MemberName(Handle mname_h, fieldDescriptor& fd, bool is_setter = false); |
drchase@5732 | 63 | static oop init_method_MemberName(Handle mname_h, CallInfo& info); |
coleenp@4037 | 64 | static int method_ref_kind(Method* m, bool do_dispatch_if_possible = true); |
sspitsyn@4965 | 65 | static int find_MemberNames(KlassHandle k, Symbol* name, Symbol* sig, |
sspitsyn@4965 | 66 | int mflags, KlassHandle caller, |
sspitsyn@4965 | 67 | int skip, objArrayHandle results); |
jrose@1145 | 68 | // bit values for suppress argument to expand_MemberName: |
jrose@1145 | 69 | enum { _suppress_defc = 1, _suppress_name = 2, _suppress_type = 4 }; |
jrose@1145 | 70 | |
twisti@1734 | 71 | // Generate MethodHandles adapters. |
sspitsyn@4965 | 72 | static void generate_adapters(); |
twisti@1734 | 73 | |
twisti@3969 | 74 | // Called from MethodHandlesAdapterGenerator. |
twisti@3969 | 75 | static address generate_method_handle_interpreter_entry(MacroAssembler* _masm, vmIntrinsics::ID iid); |
twisti@3969 | 76 | static void generate_method_handle_dispatch(MacroAssembler* _masm, |
twisti@3969 | 77 | vmIntrinsics::ID iid, |
twisti@3969 | 78 | Register receiver_reg, |
twisti@3969 | 79 | Register member_reg, |
twisti@3969 | 80 | bool for_compiler_entry); |
jrose@1145 | 81 | |
twisti@3969 | 82 | // Queries |
twisti@3969 | 83 | static bool is_signature_polymorphic(vmIntrinsics::ID iid) { |
twisti@3969 | 84 | return (iid >= vmIntrinsics::FIRST_MH_SIG_POLY && |
twisti@3969 | 85 | iid <= vmIntrinsics::LAST_MH_SIG_POLY); |
twisti@3969 | 86 | } |
jrose@1145 | 87 | |
twisti@3969 | 88 | static bool is_signature_polymorphic_intrinsic(vmIntrinsics::ID iid) { |
twisti@3969 | 89 | assert(is_signature_polymorphic(iid), ""); |
twisti@3969 | 90 | // Most sig-poly methods are intrinsics which do not require an |
twisti@3969 | 91 | // appeal to Java for adapter code. |
twisti@3969 | 92 | return (iid != vmIntrinsics::_invokeGeneric); |
twisti@3969 | 93 | } |
twisti@3969 | 94 | |
twisti@3969 | 95 | static bool is_signature_polymorphic_static(vmIntrinsics::ID iid) { |
twisti@3969 | 96 | assert(is_signature_polymorphic(iid), ""); |
twisti@3969 | 97 | return (iid >= vmIntrinsics::FIRST_MH_STATIC && |
twisti@3969 | 98 | iid <= vmIntrinsics::LAST_MH_SIG_POLY); |
twisti@3969 | 99 | } |
twisti@3969 | 100 | |
twisti@3969 | 101 | static bool has_member_arg(vmIntrinsics::ID iid) { |
twisti@3969 | 102 | assert(is_signature_polymorphic(iid), ""); |
twisti@3969 | 103 | return (iid >= vmIntrinsics::_linkToVirtual && |
twisti@3969 | 104 | iid <= vmIntrinsics::_linkToInterface); |
twisti@3969 | 105 | } |
twisti@3969 | 106 | static bool has_member_arg(Symbol* klass, Symbol* name) { |
twisti@3969 | 107 | if ((klass == vmSymbols::java_lang_invoke_MethodHandle()) && |
twisti@3969 | 108 | is_signature_polymorphic_name(name)) { |
twisti@3969 | 109 | vmIntrinsics::ID iid = signature_polymorphic_name_id(name); |
twisti@3969 | 110 | return has_member_arg(iid); |
twisti@3969 | 111 | } |
twisti@3969 | 112 | return false; |
twisti@3969 | 113 | } |
twisti@3969 | 114 | |
twisti@3969 | 115 | static Symbol* signature_polymorphic_intrinsic_name(vmIntrinsics::ID iid); |
twisti@3969 | 116 | static int signature_polymorphic_intrinsic_ref_kind(vmIntrinsics::ID iid); |
twisti@3969 | 117 | |
coleenp@4037 | 118 | static vmIntrinsics::ID signature_polymorphic_name_id(Klass* klass, Symbol* name); |
twisti@3969 | 119 | static vmIntrinsics::ID signature_polymorphic_name_id(Symbol* name); |
twisti@3969 | 120 | static bool is_signature_polymorphic_name(Symbol* name) { |
twisti@3969 | 121 | return signature_polymorphic_name_id(name) != vmIntrinsics::_none; |
twisti@3969 | 122 | } |
coleenp@4037 | 123 | static bool is_method_handle_invoke_name(Klass* klass, Symbol* name); |
coleenp@4037 | 124 | static bool is_signature_polymorphic_name(Klass* klass, Symbol* name) { |
twisti@3969 | 125 | return signature_polymorphic_name_id(klass, name) != vmIntrinsics::_none; |
twisti@3969 | 126 | } |
twisti@3969 | 127 | |
jrose@1145 | 128 | enum { |
jrose@1145 | 129 | // format of query to getConstant: |
never@3105 | 130 | GC_COUNT_GWT = 4, |
twisti@3969 | 131 | GC_LAMBDA_SUPPORT = 5 |
jrose@1145 | 132 | }; |
jrose@1145 | 133 | static int get_named_constant(int which, Handle name_box, TRAPS); |
jrose@1145 | 134 | |
twisti@3969 | 135 | public: |
twisti@3969 | 136 | static Symbol* lookup_signature(oop type_str, bool polymorphic, TRAPS); // use TempNewSymbol |
twisti@3969 | 137 | static Symbol* lookup_basic_type_signature(Symbol* sig, bool keep_last_arg, TRAPS); // use TempNewSymbol |
twisti@3969 | 138 | static Symbol* lookup_basic_type_signature(Symbol* sig, TRAPS) { |
twisti@3969 | 139 | return lookup_basic_type_signature(sig, false, THREAD); |
twisti@3969 | 140 | } |
twisti@3969 | 141 | static bool is_basic_type_signature(Symbol* sig); |
twisti@3969 | 142 | |
twisti@3969 | 143 | static Symbol* lookup_method_type(Symbol* msig, Handle mtype, TRAPS); |
twisti@3969 | 144 | |
twisti@3969 | 145 | static void print_as_method_type_on(outputStream* st, Symbol* sig) { |
twisti@3969 | 146 | print_as_basic_type_signature_on(st, sig, true, true); |
twisti@3969 | 147 | } |
twisti@3969 | 148 | static void print_as_basic_type_signature_on(outputStream* st, Symbol* sig, bool keep_arrays = false, bool keep_basic_names = false); |
twisti@3969 | 149 | |
twisti@3969 | 150 | // decoding CONSTANT_MethodHandle constants |
twisti@3969 | 151 | enum { JVM_REF_MIN = JVM_REF_getField, JVM_REF_MAX = JVM_REF_invokeInterface }; |
twisti@3969 | 152 | static bool ref_kind_is_valid(int ref_kind) { |
twisti@3969 | 153 | return (ref_kind >= JVM_REF_MIN && ref_kind <= JVM_REF_MAX); |
twisti@3969 | 154 | } |
twisti@3969 | 155 | static bool ref_kind_is_field(int ref_kind) { |
twisti@3969 | 156 | assert(ref_kind_is_valid(ref_kind), ""); |
twisti@3969 | 157 | return (ref_kind <= JVM_REF_putStatic); |
twisti@3969 | 158 | } |
twisti@3969 | 159 | static bool ref_kind_is_getter(int ref_kind) { |
twisti@3969 | 160 | assert(ref_kind_is_valid(ref_kind), ""); |
twisti@3969 | 161 | return (ref_kind <= JVM_REF_getStatic); |
twisti@3969 | 162 | } |
twisti@3969 | 163 | static bool ref_kind_is_setter(int ref_kind) { |
twisti@3969 | 164 | return ref_kind_is_field(ref_kind) && !ref_kind_is_getter(ref_kind); |
twisti@3969 | 165 | } |
twisti@3969 | 166 | static bool ref_kind_is_method(int ref_kind) { |
twisti@3969 | 167 | return !ref_kind_is_field(ref_kind) && (ref_kind != JVM_REF_newInvokeSpecial); |
twisti@3969 | 168 | } |
twisti@3969 | 169 | static bool ref_kind_has_receiver(int ref_kind) { |
twisti@3969 | 170 | assert(ref_kind_is_valid(ref_kind), ""); |
twisti@3969 | 171 | return (ref_kind & 1) != 0; |
twisti@3969 | 172 | } |
twisti@3969 | 173 | static bool ref_kind_is_static(int ref_kind) { |
twisti@3969 | 174 | return !ref_kind_has_receiver(ref_kind) && (ref_kind != JVM_REF_newInvokeSpecial); |
twisti@3969 | 175 | } |
twisti@3969 | 176 | static bool ref_kind_does_dispatch(int ref_kind) { |
twisti@3969 | 177 | return (ref_kind == JVM_REF_invokeVirtual || |
twisti@3969 | 178 | ref_kind == JVM_REF_invokeInterface); |
jrose@1862 | 179 | } |
jrose@1862 | 180 | |
never@2895 | 181 | |
never@2895 | 182 | #ifdef TARGET_ARCH_x86 |
never@2895 | 183 | # include "methodHandles_x86.hpp" |
never@2895 | 184 | #endif |
never@2895 | 185 | #ifdef TARGET_ARCH_sparc |
never@2950 | 186 | # include "methodHandles_sparc.hpp" |
never@2895 | 187 | #endif |
never@2895 | 188 | #ifdef TARGET_ARCH_zero |
never@2950 | 189 | # include "methodHandles_zero.hpp" |
never@2895 | 190 | #endif |
never@2895 | 191 | #ifdef TARGET_ARCH_arm |
bdelsart@2917 | 192 | # include "methodHandles_arm.hpp" |
never@2895 | 193 | #endif |
never@2895 | 194 | #ifdef TARGET_ARCH_ppc |
bdelsart@2917 | 195 | # include "methodHandles_ppc.hpp" |
never@2895 | 196 | #endif |
twisti@3969 | 197 | |
twisti@4158 | 198 | // Tracing |
twisti@4158 | 199 | static void trace_method_handle(MacroAssembler* _masm, const char* adaptername) PRODUCT_RETURN; |
twisti@4158 | 200 | static void trace_method_handle_interpreter_entry(MacroAssembler* _masm, vmIntrinsics::ID iid) { |
twisti@4158 | 201 | if (TraceMethodHandles) { |
twisti@4158 | 202 | const char* name = vmIntrinsics::name_at(iid); |
twisti@4158 | 203 | if (*name == '_') name += 1; |
twisti@4158 | 204 | const size_t len = strlen(name) + 50; |
twisti@4158 | 205 | char* qname = NEW_C_HEAP_ARRAY(char, len, mtInternal); |
twisti@4158 | 206 | const char* suffix = ""; |
twisti@4158 | 207 | if (is_signature_polymorphic(iid)) { |
twisti@4158 | 208 | if (is_signature_polymorphic_static(iid)) |
twisti@4158 | 209 | suffix = "/static"; |
twisti@4158 | 210 | else |
twisti@4158 | 211 | suffix = "/private"; |
twisti@4158 | 212 | } |
twisti@4158 | 213 | jio_snprintf(qname, len, "MethodHandle::interpreter_entry::%s%s", name, suffix); |
twisti@4158 | 214 | trace_method_handle(_masm, qname); |
twisti@4158 | 215 | // Note: Don't free the allocated char array because it's used |
twisti@4158 | 216 | // during runtime. |
twisti@4158 | 217 | } |
twisti@4158 | 218 | } |
jrose@1145 | 219 | }; |
jrose@1145 | 220 | |
twisti@1734 | 221 | //------------------------------------------------------------------------------ |
twisti@1734 | 222 | // MethodHandlesAdapterGenerator |
twisti@1734 | 223 | // |
twisti@1734 | 224 | class MethodHandlesAdapterGenerator : public StubCodeGenerator { |
twisti@1734 | 225 | public: |
never@2954 | 226 | MethodHandlesAdapterGenerator(CodeBuffer* code) : StubCodeGenerator(code, PrintMethodHandleStubs) {} |
twisti@1734 | 227 | |
twisti@2436 | 228 | void generate(); |
twisti@1734 | 229 | }; |
stefank@2314 | 230 | |
sspitsyn@4965 | 231 | //------------------------------------------------------------------------------ |
sspitsyn@4965 | 232 | // MemberNameTable |
sspitsyn@4965 | 233 | // |
sspitsyn@5178 | 234 | |
sspitsyn@4965 | 235 | class MemberNameTable : public GrowableArray<jweak> { |
sspitsyn@4965 | 236 | public: |
sspitsyn@5178 | 237 | MemberNameTable(int methods_cnt); |
sspitsyn@4965 | 238 | ~MemberNameTable(); |
coleenp@7391 | 239 | void add_member_name(jweak mem_name_ref); |
sspitsyn@4965 | 240 | |
sspitsyn@4965 | 241 | #if INCLUDE_JVMTI |
sspitsyn@4965 | 242 | // RedefineClasses() API support: |
sspitsyn@7795 | 243 | // If a MemberName refers to old_method then update it to refer to new_method. |
sspitsyn@7795 | 244 | void adjust_method_entries(InstanceKlass* holder, bool * trace_name_printed); |
sspitsyn@4965 | 245 | #endif // INCLUDE_JVMTI |
sspitsyn@4965 | 246 | }; |
sspitsyn@4965 | 247 | |
stefank@2314 | 248 | #endif // SHARE_VM_PRIMS_METHODHANDLES_HPP |