src/share/vm/prims/methodHandles.hpp

Sat, 01 Sep 2012 13:25:18 -0400

author
coleenp
date
Sat, 01 Sep 2012 13:25:18 -0400
changeset 4037
da91efe96a93
parent 3969
1d7922586cf6
child 4158
65d07d9ee446
permissions
-rw-r--r--

6964458: Reimplement class meta-data storage to use native memory
Summary: Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
Contributed-by: jmasa <jon.masamitsu@oracle.com>, stefank <stefan.karlsson@oracle.com>, mgerdin <mikael.gerdin@oracle.com>, never <tom.rodriguez@oracle.com>

jrose@1145 1 /*
coleenp@4037 2 * Copyright (c) 2008, 2012, 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
twisti@3969 57 static oop init_MemberName(oop mname_oop, oop target_oop); // compute vmtarget/vmindex from target
coleenp@4037 58 static oop init_method_MemberName(oop mname_oop, Method* m, bool do_dispatch,
coleenp@4037 59 Klass* receiver_limit);
coleenp@4037 60 static oop init_field_MemberName(oop mname_oop, Klass* field_holder,
twisti@3969 61 AccessFlags mods, oop type, oop name,
twisti@3969 62 intptr_t offset, bool is_setter = false);
twisti@3969 63 static Handle init_method_MemberName(oop mname_oop, CallInfo& info, TRAPS);
twisti@3969 64 static Handle init_field_MemberName(oop mname_oop, FieldAccessInfo& info, TRAPS);
coleenp@4037 65 static int method_ref_kind(Method* m, bool do_dispatch_if_possible = true);
coleenp@4037 66 static int find_MemberNames(Klass* k, Symbol* name, Symbol* sig,
coleenp@4037 67 int mflags, Klass* caller,
jrose@1145 68 int skip, objArrayOop 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.
twisti@2436 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@3969 199
jrose@1145 200 };
jrose@1145 201
jrose@1145 202
twisti@1734 203 //------------------------------------------------------------------------------
twisti@1734 204 // MethodHandlesAdapterGenerator
twisti@1734 205 //
twisti@1734 206 class MethodHandlesAdapterGenerator : public StubCodeGenerator {
twisti@1734 207 public:
never@2954 208 MethodHandlesAdapterGenerator(CodeBuffer* code) : StubCodeGenerator(code, PrintMethodHandleStubs) {}
twisti@1734 209
twisti@2436 210 void generate();
twisti@1734 211 };
stefank@2314 212
stefank@2314 213 #endif // SHARE_VM_PRIMS_METHODHANDLES_HPP

mercurial