src/share/vm/prims/methodHandles.hpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 1
2d8a650513c2
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2008, 2013, 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@0 25 #ifndef SHARE_VM_PRIMS_METHODHANDLES_HPP
aoqi@0 26 #define SHARE_VM_PRIMS_METHODHANDLES_HPP
aoqi@0 27
aoqi@0 28 #include "classfile/javaClasses.hpp"
aoqi@0 29 #include "classfile/vmSymbols.hpp"
aoqi@0 30 #include "runtime/frame.inline.hpp"
aoqi@0 31 #include "runtime/globals.hpp"
aoqi@0 32 #include "runtime/interfaceSupport.hpp"
aoqi@0 33
aoqi@0 34 class MacroAssembler;
aoqi@0 35 class Label;
aoqi@0 36
aoqi@0 37 class MethodHandles: AllStatic {
aoqi@0 38 // JVM support for MethodHandle, MethodType, and related types
aoqi@0 39 // in java.lang.invoke and sun.invoke.
aoqi@0 40 // See also javaClasses for layouts java_lang_invoke_Method{Handle,Type,Type::Form}.
aoqi@0 41 public:
aoqi@0 42 public:
aoqi@0 43 static bool enabled() { return _enabled; }
aoqi@0 44 static void set_enabled(bool z);
aoqi@0 45
aoqi@0 46 private:
aoqi@0 47 static bool _enabled;
aoqi@0 48
aoqi@0 49 // Adapters.
aoqi@0 50 static MethodHandlesAdapterBlob* _adapter_code;
aoqi@0 51
aoqi@0 52 // utility functions for reifying names and types
aoqi@0 53 static oop field_name_or_null(Symbol* s);
aoqi@0 54 static oop field_signature_type_or_null(Symbol* s);
aoqi@0 55
aoqi@0 56 public:
aoqi@0 57 // working with member names
aoqi@0 58 static Handle resolve_MemberName(Handle mname, KlassHandle caller, TRAPS); // compute vmtarget/vmindex from name/type
aoqi@0 59 static void expand_MemberName(Handle mname, int suppress, TRAPS); // expand defc/name/type if missing
aoqi@0 60 static Handle new_MemberName(TRAPS); // must be followed by init_MemberName
aoqi@0 61 static oop init_MemberName(Handle mname_h, Handle target_h); // compute vmtarget/vmindex from target
aoqi@0 62 static oop init_field_MemberName(Handle mname_h, fieldDescriptor& fd, bool is_setter = false);
aoqi@0 63 static oop init_method_MemberName(Handle mname_h, CallInfo& info);
aoqi@0 64 static int method_ref_kind(Method* m, bool do_dispatch_if_possible = true);
aoqi@0 65 static int find_MemberNames(KlassHandle k, Symbol* name, Symbol* sig,
aoqi@0 66 int mflags, KlassHandle caller,
aoqi@0 67 int skip, objArrayHandle results);
aoqi@0 68 // bit values for suppress argument to expand_MemberName:
aoqi@0 69 enum { _suppress_defc = 1, _suppress_name = 2, _suppress_type = 4 };
aoqi@0 70
aoqi@0 71 // Generate MethodHandles adapters.
aoqi@0 72 static void generate_adapters();
aoqi@0 73
aoqi@0 74 // Called from MethodHandlesAdapterGenerator.
aoqi@0 75 static address generate_method_handle_interpreter_entry(MacroAssembler* _masm, vmIntrinsics::ID iid);
aoqi@0 76 static void generate_method_handle_dispatch(MacroAssembler* _masm,
aoqi@0 77 vmIntrinsics::ID iid,
aoqi@0 78 Register receiver_reg,
aoqi@0 79 Register member_reg,
aoqi@0 80 bool for_compiler_entry);
aoqi@0 81
aoqi@0 82 // Queries
aoqi@0 83 static bool is_signature_polymorphic(vmIntrinsics::ID iid) {
aoqi@0 84 return (iid >= vmIntrinsics::FIRST_MH_SIG_POLY &&
aoqi@0 85 iid <= vmIntrinsics::LAST_MH_SIG_POLY);
aoqi@0 86 }
aoqi@0 87
aoqi@0 88 static bool is_signature_polymorphic_intrinsic(vmIntrinsics::ID iid) {
aoqi@0 89 assert(is_signature_polymorphic(iid), "");
aoqi@0 90 // Most sig-poly methods are intrinsics which do not require an
aoqi@0 91 // appeal to Java for adapter code.
aoqi@0 92 return (iid != vmIntrinsics::_invokeGeneric);
aoqi@0 93 }
aoqi@0 94
aoqi@0 95 static bool is_signature_polymorphic_static(vmIntrinsics::ID iid) {
aoqi@0 96 assert(is_signature_polymorphic(iid), "");
aoqi@0 97 return (iid >= vmIntrinsics::FIRST_MH_STATIC &&
aoqi@0 98 iid <= vmIntrinsics::LAST_MH_SIG_POLY);
aoqi@0 99 }
aoqi@0 100
aoqi@0 101 static bool has_member_arg(vmIntrinsics::ID iid) {
aoqi@0 102 assert(is_signature_polymorphic(iid), "");
aoqi@0 103 return (iid >= vmIntrinsics::_linkToVirtual &&
aoqi@0 104 iid <= vmIntrinsics::_linkToInterface);
aoqi@0 105 }
aoqi@0 106 static bool has_member_arg(Symbol* klass, Symbol* name) {
aoqi@0 107 if ((klass == vmSymbols::java_lang_invoke_MethodHandle()) &&
aoqi@0 108 is_signature_polymorphic_name(name)) {
aoqi@0 109 vmIntrinsics::ID iid = signature_polymorphic_name_id(name);
aoqi@0 110 return has_member_arg(iid);
aoqi@0 111 }
aoqi@0 112 return false;
aoqi@0 113 }
aoqi@0 114
aoqi@0 115 static Symbol* signature_polymorphic_intrinsic_name(vmIntrinsics::ID iid);
aoqi@0 116 static int signature_polymorphic_intrinsic_ref_kind(vmIntrinsics::ID iid);
aoqi@0 117
aoqi@0 118 static vmIntrinsics::ID signature_polymorphic_name_id(Klass* klass, Symbol* name);
aoqi@0 119 static vmIntrinsics::ID signature_polymorphic_name_id(Symbol* name);
aoqi@0 120 static bool is_signature_polymorphic_name(Symbol* name) {
aoqi@0 121 return signature_polymorphic_name_id(name) != vmIntrinsics::_none;
aoqi@0 122 }
aoqi@0 123 static bool is_method_handle_invoke_name(Klass* klass, Symbol* name);
aoqi@0 124 static bool is_signature_polymorphic_name(Klass* klass, Symbol* name) {
aoqi@0 125 return signature_polymorphic_name_id(klass, name) != vmIntrinsics::_none;
aoqi@0 126 }
aoqi@0 127
aoqi@0 128 enum {
aoqi@0 129 // format of query to getConstant:
aoqi@0 130 GC_COUNT_GWT = 4,
aoqi@0 131 GC_LAMBDA_SUPPORT = 5
aoqi@0 132 };
aoqi@0 133 static int get_named_constant(int which, Handle name_box, TRAPS);
aoqi@0 134
aoqi@0 135 public:
aoqi@0 136 static Symbol* lookup_signature(oop type_str, bool polymorphic, TRAPS); // use TempNewSymbol
aoqi@0 137 static Symbol* lookup_basic_type_signature(Symbol* sig, bool keep_last_arg, TRAPS); // use TempNewSymbol
aoqi@0 138 static Symbol* lookup_basic_type_signature(Symbol* sig, TRAPS) {
aoqi@0 139 return lookup_basic_type_signature(sig, false, THREAD);
aoqi@0 140 }
aoqi@0 141 static bool is_basic_type_signature(Symbol* sig);
aoqi@0 142
aoqi@0 143 static Symbol* lookup_method_type(Symbol* msig, Handle mtype, TRAPS);
aoqi@0 144
aoqi@0 145 static void print_as_method_type_on(outputStream* st, Symbol* sig) {
aoqi@0 146 print_as_basic_type_signature_on(st, sig, true, true);
aoqi@0 147 }
aoqi@0 148 static void print_as_basic_type_signature_on(outputStream* st, Symbol* sig, bool keep_arrays = false, bool keep_basic_names = false);
aoqi@0 149
aoqi@0 150 // decoding CONSTANT_MethodHandle constants
aoqi@0 151 enum { JVM_REF_MIN = JVM_REF_getField, JVM_REF_MAX = JVM_REF_invokeInterface };
aoqi@0 152 static bool ref_kind_is_valid(int ref_kind) {
aoqi@0 153 return (ref_kind >= JVM_REF_MIN && ref_kind <= JVM_REF_MAX);
aoqi@0 154 }
aoqi@0 155 static bool ref_kind_is_field(int ref_kind) {
aoqi@0 156 assert(ref_kind_is_valid(ref_kind), "");
aoqi@0 157 return (ref_kind <= JVM_REF_putStatic);
aoqi@0 158 }
aoqi@0 159 static bool ref_kind_is_getter(int ref_kind) {
aoqi@0 160 assert(ref_kind_is_valid(ref_kind), "");
aoqi@0 161 return (ref_kind <= JVM_REF_getStatic);
aoqi@0 162 }
aoqi@0 163 static bool ref_kind_is_setter(int ref_kind) {
aoqi@0 164 return ref_kind_is_field(ref_kind) && !ref_kind_is_getter(ref_kind);
aoqi@0 165 }
aoqi@0 166 static bool ref_kind_is_method(int ref_kind) {
aoqi@0 167 return !ref_kind_is_field(ref_kind) && (ref_kind != JVM_REF_newInvokeSpecial);
aoqi@0 168 }
aoqi@0 169 static bool ref_kind_has_receiver(int ref_kind) {
aoqi@0 170 assert(ref_kind_is_valid(ref_kind), "");
aoqi@0 171 return (ref_kind & 1) != 0;
aoqi@0 172 }
aoqi@0 173 static bool ref_kind_is_static(int ref_kind) {
aoqi@0 174 return !ref_kind_has_receiver(ref_kind) && (ref_kind != JVM_REF_newInvokeSpecial);
aoqi@0 175 }
aoqi@0 176 static bool ref_kind_does_dispatch(int ref_kind) {
aoqi@0 177 return (ref_kind == JVM_REF_invokeVirtual ||
aoqi@0 178 ref_kind == JVM_REF_invokeInterface);
aoqi@0 179 }
aoqi@0 180
aoqi@0 181
aoqi@0 182 #ifdef TARGET_ARCH_x86
aoqi@0 183 # include "methodHandles_x86.hpp"
aoqi@0 184 #endif
aoqi@0 185 #ifdef TARGET_ARCH_sparc
aoqi@0 186 # include "methodHandles_sparc.hpp"
aoqi@0 187 #endif
aoqi@0 188 #ifdef TARGET_ARCH_zero
aoqi@0 189 # include "methodHandles_zero.hpp"
aoqi@0 190 #endif
aoqi@0 191 #ifdef TARGET_ARCH_arm
aoqi@0 192 # include "methodHandles_arm.hpp"
aoqi@0 193 #endif
aoqi@0 194 #ifdef TARGET_ARCH_ppc
aoqi@0 195 # include "methodHandles_ppc.hpp"
aoqi@0 196 #endif
aoqi@0 197
aoqi@0 198 // Tracing
aoqi@0 199 static void trace_method_handle(MacroAssembler* _masm, const char* adaptername) PRODUCT_RETURN;
aoqi@0 200 static void trace_method_handle_interpreter_entry(MacroAssembler* _masm, vmIntrinsics::ID iid) {
aoqi@0 201 if (TraceMethodHandles) {
aoqi@0 202 const char* name = vmIntrinsics::name_at(iid);
aoqi@0 203 if (*name == '_') name += 1;
aoqi@0 204 const size_t len = strlen(name) + 50;
aoqi@0 205 char* qname = NEW_C_HEAP_ARRAY(char, len, mtInternal);
aoqi@0 206 const char* suffix = "";
aoqi@0 207 if (is_signature_polymorphic(iid)) {
aoqi@0 208 if (is_signature_polymorphic_static(iid))
aoqi@0 209 suffix = "/static";
aoqi@0 210 else
aoqi@0 211 suffix = "/private";
aoqi@0 212 }
aoqi@0 213 jio_snprintf(qname, len, "MethodHandle::interpreter_entry::%s%s", name, suffix);
aoqi@0 214 trace_method_handle(_masm, qname);
aoqi@0 215 // Note: Don't free the allocated char array because it's used
aoqi@0 216 // during runtime.
aoqi@0 217 }
aoqi@0 218 }
aoqi@0 219 };
aoqi@0 220
aoqi@0 221 //------------------------------------------------------------------------------
aoqi@0 222 // MethodHandlesAdapterGenerator
aoqi@0 223 //
aoqi@0 224 class MethodHandlesAdapterGenerator : public StubCodeGenerator {
aoqi@0 225 public:
aoqi@0 226 MethodHandlesAdapterGenerator(CodeBuffer* code) : StubCodeGenerator(code, PrintMethodHandleStubs) {}
aoqi@0 227
aoqi@0 228 void generate();
aoqi@0 229 };
aoqi@0 230
aoqi@0 231 //------------------------------------------------------------------------------
aoqi@0 232 // MemberNameTable
aoqi@0 233 //
aoqi@0 234
aoqi@0 235 class MemberNameTable : public GrowableArray<jweak> {
aoqi@0 236 public:
aoqi@0 237 MemberNameTable(int methods_cnt);
aoqi@0 238 ~MemberNameTable();
aoqi@0 239 void add_member_name(int index, jweak mem_name_ref);
aoqi@0 240 oop get_member_name(int index);
aoqi@0 241
aoqi@0 242 #if INCLUDE_JVMTI
aoqi@0 243 public:
aoqi@0 244 // RedefineClasses() API support:
aoqi@0 245 // If a MemberName refers to old_method then update it
aoqi@0 246 // to refer to new_method.
aoqi@0 247 void adjust_method_entries(Method** old_methods, Method** new_methods,
aoqi@0 248 int methods_length, bool *trace_name_printed);
aoqi@0 249 private:
aoqi@0 250 oop find_member_name_by_method(Method* old_method);
aoqi@0 251 #endif // INCLUDE_JVMTI
aoqi@0 252 };
aoqi@0 253
aoqi@0 254 #endif // SHARE_VM_PRIMS_METHODHANDLES_HPP

mercurial