src/share/vm/prims/methodHandles.hpp

Sun, 15 Sep 2013 15:28:58 +0200

author
goetz
date
Sun, 15 Sep 2013 15:28:58 +0200
changeset 6470
abe03600372a
parent 5178
b7fa10a3a69a
child 5732
b2e698d2276c
permissions
-rw-r--r--

8024468: PPC64 (part 201): cppInterpreter: implement bytecode profiling
Summary: Implement profiling for c2 jit compilation. Also enable new cppInterpreter features.
Reviewed-by: kvn

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

mercurial