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