annotate src/share/vm/prims/methodHandles.hpp @ 5820:87ee5ee27509

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