Fri, 07 Jan 2011 10:42:32 -0500
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
Summary: Track allocated bytes in Thread's, update on TLAB retirement and direct allocation in Eden and tenured, add JNI methods for ThreadMXBean.
Reviewed-by: coleenp, kvn, dholmes, ysr
jrose@1145 | 1 | /* |
trims@1907 | 2 | * Copyright (c) 2008, 2010, 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 | class MethodHandleEntry; |
jrose@1145 | 37 | |
jrose@1145 | 38 | class MethodHandles: AllStatic { |
jrose@1145 | 39 | // JVM support for MethodHandle, MethodType, and related types |
jrose@1145 | 40 | // in java.dyn and java.dyn.hotspot. |
jrose@1145 | 41 | // See also javaClasses for layouts java_dyn_Method{Handle,Type,Type::Form}. |
jrose@1145 | 42 | public: |
jrose@1145 | 43 | enum EntryKind { |
jrose@1474 | 44 | _raise_exception, // stub for error generation from other stubs |
jrose@1145 | 45 | _invokestatic_mh, // how a MH emulates invokestatic |
jrose@1145 | 46 | _invokespecial_mh, // ditto for the other invokes... |
jrose@1145 | 47 | _invokevirtual_mh, |
jrose@1145 | 48 | _invokeinterface_mh, |
jrose@1145 | 49 | _bound_ref_mh, // reference argument is bound |
jrose@1145 | 50 | _bound_int_mh, // int argument is bound (via an Integer or Float) |
jrose@1145 | 51 | _bound_long_mh, // long argument is bound (via a Long or Double) |
jrose@1145 | 52 | _bound_ref_direct_mh, // same as above, with direct linkage to methodOop |
jrose@1145 | 53 | _bound_int_direct_mh, |
jrose@1145 | 54 | _bound_long_direct_mh, |
jrose@1145 | 55 | |
jrose@1145 | 56 | _adapter_mh_first, // adapter sequence goes here... |
jrose@1145 | 57 | _adapter_retype_only = _adapter_mh_first + sun_dyn_AdapterMethodHandle::OP_RETYPE_ONLY, |
jrose@1474 | 58 | _adapter_retype_raw = _adapter_mh_first + sun_dyn_AdapterMethodHandle::OP_RETYPE_RAW, |
jrose@1145 | 59 | _adapter_check_cast = _adapter_mh_first + sun_dyn_AdapterMethodHandle::OP_CHECK_CAST, |
jrose@1145 | 60 | _adapter_prim_to_prim = _adapter_mh_first + sun_dyn_AdapterMethodHandle::OP_PRIM_TO_PRIM, |
jrose@1145 | 61 | _adapter_ref_to_prim = _adapter_mh_first + sun_dyn_AdapterMethodHandle::OP_REF_TO_PRIM, |
jrose@1145 | 62 | _adapter_prim_to_ref = _adapter_mh_first + sun_dyn_AdapterMethodHandle::OP_PRIM_TO_REF, |
jrose@1145 | 63 | _adapter_swap_args = _adapter_mh_first + sun_dyn_AdapterMethodHandle::OP_SWAP_ARGS, |
jrose@1145 | 64 | _adapter_rot_args = _adapter_mh_first + sun_dyn_AdapterMethodHandle::OP_ROT_ARGS, |
jrose@1145 | 65 | _adapter_dup_args = _adapter_mh_first + sun_dyn_AdapterMethodHandle::OP_DUP_ARGS, |
jrose@1145 | 66 | _adapter_drop_args = _adapter_mh_first + sun_dyn_AdapterMethodHandle::OP_DROP_ARGS, |
jrose@1145 | 67 | _adapter_collect_args = _adapter_mh_first + sun_dyn_AdapterMethodHandle::OP_COLLECT_ARGS, |
jrose@1145 | 68 | _adapter_spread_args = _adapter_mh_first + sun_dyn_AdapterMethodHandle::OP_SPREAD_ARGS, |
jrose@1145 | 69 | _adapter_flyby = _adapter_mh_first + sun_dyn_AdapterMethodHandle::OP_FLYBY, |
jrose@1145 | 70 | _adapter_ricochet = _adapter_mh_first + sun_dyn_AdapterMethodHandle::OP_RICOCHET, |
jrose@1145 | 71 | _adapter_mh_last = _adapter_mh_first + sun_dyn_AdapterMethodHandle::CONV_OP_LIMIT - 1, |
jrose@1145 | 72 | |
jrose@1145 | 73 | // Optimized adapter types |
jrose@1145 | 74 | |
jrose@1145 | 75 | // argument list reordering |
jrose@1145 | 76 | _adapter_opt_swap_1, |
jrose@1145 | 77 | _adapter_opt_swap_2, |
jrose@1145 | 78 | _adapter_opt_rot_1_up, |
jrose@1145 | 79 | _adapter_opt_rot_1_down, |
jrose@1145 | 80 | _adapter_opt_rot_2_up, |
jrose@1145 | 81 | _adapter_opt_rot_2_down, |
jrose@1145 | 82 | // primitive single to single: |
jrose@1145 | 83 | _adapter_opt_i2i, // i2c, i2z, i2b, i2s |
jrose@1145 | 84 | // primitive double to single: |
jrose@1145 | 85 | _adapter_opt_l2i, |
jrose@1145 | 86 | _adapter_opt_d2f, |
jrose@1145 | 87 | // primitive single to double: |
jrose@1145 | 88 | _adapter_opt_i2l, |
jrose@1145 | 89 | _adapter_opt_f2d, |
jrose@1145 | 90 | // conversion between floating point and integer type is handled by Java |
jrose@1145 | 91 | |
jrose@1145 | 92 | // reference to primitive: |
jrose@1145 | 93 | _adapter_opt_unboxi, |
jrose@1145 | 94 | _adapter_opt_unboxl, |
jrose@1145 | 95 | |
jrose@1145 | 96 | // spreading (array length cases 0, 1, >=2) |
jrose@1145 | 97 | _adapter_opt_spread_0, |
jrose@1145 | 98 | _adapter_opt_spread_1, |
jrose@1145 | 99 | _adapter_opt_spread_more, |
jrose@1145 | 100 | |
jrose@1145 | 101 | _EK_LIMIT, |
jrose@1145 | 102 | _EK_FIRST = 0 |
jrose@1145 | 103 | }; |
jrose@1145 | 104 | |
jrose@1145 | 105 | public: |
jrose@1145 | 106 | static bool enabled() { return _enabled; } |
jrose@1145 | 107 | static void set_enabled(bool z); |
jrose@1145 | 108 | |
jrose@1145 | 109 | private: |
jrose@1145 | 110 | enum { // import sun_dyn_AdapterMethodHandle::CONV_OP_* |
jrose@1145 | 111 | CONV_OP_LIMIT = sun_dyn_AdapterMethodHandle::CONV_OP_LIMIT, |
jrose@1145 | 112 | CONV_OP_MASK = sun_dyn_AdapterMethodHandle::CONV_OP_MASK, |
jrose@1145 | 113 | CONV_VMINFO_MASK = sun_dyn_AdapterMethodHandle::CONV_VMINFO_MASK, |
jrose@1145 | 114 | CONV_VMINFO_SHIFT = sun_dyn_AdapterMethodHandle::CONV_VMINFO_SHIFT, |
jrose@1145 | 115 | CONV_OP_SHIFT = sun_dyn_AdapterMethodHandle::CONV_OP_SHIFT, |
jrose@1145 | 116 | CONV_DEST_TYPE_SHIFT = sun_dyn_AdapterMethodHandle::CONV_DEST_TYPE_SHIFT, |
jrose@1145 | 117 | CONV_SRC_TYPE_SHIFT = sun_dyn_AdapterMethodHandle::CONV_SRC_TYPE_SHIFT, |
jrose@1145 | 118 | CONV_STACK_MOVE_SHIFT = sun_dyn_AdapterMethodHandle::CONV_STACK_MOVE_SHIFT, |
jrose@1145 | 119 | CONV_STACK_MOVE_MASK = sun_dyn_AdapterMethodHandle::CONV_STACK_MOVE_MASK |
jrose@1145 | 120 | }; |
jrose@1145 | 121 | |
jrose@1145 | 122 | static bool _enabled; |
jrose@1145 | 123 | static MethodHandleEntry* _entries[_EK_LIMIT]; |
jrose@1145 | 124 | static const char* _entry_names[_EK_LIMIT+1]; |
jrose@1474 | 125 | static jobject _raise_exception_method; |
jrose@1474 | 126 | |
twisti@1734 | 127 | // Adapters. |
twisti@1734 | 128 | static MethodHandlesAdapterBlob* _adapter_code; |
twisti@1734 | 129 | static int _adapter_code_size; |
twisti@1734 | 130 | |
jrose@1145 | 131 | static bool ek_valid(EntryKind ek) { return (uint)ek < (uint)_EK_LIMIT; } |
jrose@1145 | 132 | static bool conv_op_valid(int op) { return (uint)op < (uint)CONV_OP_LIMIT; } |
jrose@1145 | 133 | |
jrose@1145 | 134 | public: |
jrose@1145 | 135 | static bool have_entry(EntryKind ek) { return ek_valid(ek) && _entries[ek] != NULL; } |
jrose@1145 | 136 | static MethodHandleEntry* entry(EntryKind ek) { assert(ek_valid(ek), "initialized"); |
jrose@1145 | 137 | return _entries[ek]; } |
jrose@1145 | 138 | static const char* entry_name(EntryKind ek) { assert(ek_valid(ek), "oob"); |
jrose@1145 | 139 | return _entry_names[ek]; } |
jrose@1145 | 140 | static EntryKind adapter_entry_kind(int op) { assert(conv_op_valid(op), "oob"); |
jrose@1145 | 141 | return EntryKind(_adapter_mh_first + op); } |
jrose@1145 | 142 | |
jrose@1145 | 143 | static void init_entry(EntryKind ek, MethodHandleEntry* me) { |
jrose@1145 | 144 | assert(ek_valid(ek), "oob"); |
jrose@1145 | 145 | assert(_entries[ek] == NULL, "no double initialization"); |
jrose@1145 | 146 | _entries[ek] = me; |
jrose@1145 | 147 | } |
jrose@1145 | 148 | |
twisti@1739 | 149 | // Some adapter helper functions. |
twisti@1739 | 150 | static void get_ek_bound_mh_info(EntryKind ek, BasicType& arg_type, int& arg_mask, int& arg_slots) { |
twisti@1739 | 151 | switch (ek) { |
twisti@1739 | 152 | case _bound_int_mh : // fall-thru |
twisti@1739 | 153 | case _bound_int_direct_mh : arg_type = T_INT; arg_mask = _INSERT_INT_MASK; break; |
twisti@1739 | 154 | case _bound_long_mh : // fall-thru |
twisti@1739 | 155 | case _bound_long_direct_mh: arg_type = T_LONG; arg_mask = _INSERT_LONG_MASK; break; |
twisti@1739 | 156 | case _bound_ref_mh : // fall-thru |
twisti@1739 | 157 | case _bound_ref_direct_mh : arg_type = T_OBJECT; arg_mask = _INSERT_REF_MASK; break; |
twisti@1739 | 158 | default: ShouldNotReachHere(); |
twisti@1739 | 159 | } |
twisti@1739 | 160 | arg_slots = type2size[arg_type]; |
twisti@1739 | 161 | } |
twisti@1739 | 162 | |
twisti@1739 | 163 | static void get_ek_adapter_opt_swap_rot_info(EntryKind ek, int& swap_bytes, int& rotate) { |
twisti@1739 | 164 | int swap_slots = 0; |
twisti@1739 | 165 | switch (ek) { |
twisti@1739 | 166 | case _adapter_opt_swap_1: swap_slots = 1; rotate = 0; break; |
twisti@1739 | 167 | case _adapter_opt_swap_2: swap_slots = 2; rotate = 0; break; |
twisti@1739 | 168 | case _adapter_opt_rot_1_up: swap_slots = 1; rotate = 1; break; |
twisti@1739 | 169 | case _adapter_opt_rot_1_down: swap_slots = 1; rotate = -1; break; |
twisti@1739 | 170 | case _adapter_opt_rot_2_up: swap_slots = 2; rotate = 1; break; |
twisti@1739 | 171 | case _adapter_opt_rot_2_down: swap_slots = 2; rotate = -1; break; |
twisti@1739 | 172 | default: ShouldNotReachHere(); |
twisti@1739 | 173 | } |
twisti@1739 | 174 | // Return the size of the stack slots to move in bytes. |
twisti@1861 | 175 | swap_bytes = swap_slots * Interpreter::stackElementSize; |
twisti@1739 | 176 | } |
twisti@1739 | 177 | |
twisti@1739 | 178 | static int get_ek_adapter_opt_spread_info(EntryKind ek) { |
twisti@1739 | 179 | switch (ek) { |
twisti@1739 | 180 | case _adapter_opt_spread_0: return 0; |
twisti@1739 | 181 | case _adapter_opt_spread_1: return 1; |
twisti@1739 | 182 | default : return -1; |
twisti@1739 | 183 | } |
twisti@1739 | 184 | } |
twisti@1739 | 185 | |
jrose@1474 | 186 | static methodOop raise_exception_method() { |
jrose@1474 | 187 | oop rem = JNIHandles::resolve(_raise_exception_method); |
jrose@1474 | 188 | assert(rem == NULL || rem->is_method(), ""); |
jrose@1474 | 189 | return (methodOop) rem; |
jrose@1474 | 190 | } |
jrose@1474 | 191 | static void set_raise_exception_method(methodOop rem) { |
jrose@1474 | 192 | assert(_raise_exception_method == NULL, ""); |
jrose@1474 | 193 | _raise_exception_method = JNIHandles::make_global(Handle(rem)); |
jrose@1474 | 194 | } |
jrose@1474 | 195 | |
jrose@1145 | 196 | static jint adapter_conversion(int conv_op, BasicType src, BasicType dest, |
jrose@1145 | 197 | int stack_move = 0, int vminfo = 0) { |
jrose@1145 | 198 | assert(conv_op_valid(conv_op), "oob"); |
jrose@1145 | 199 | jint conv = ((conv_op << CONV_OP_SHIFT) |
jrose@1145 | 200 | | (src << CONV_SRC_TYPE_SHIFT) |
jrose@1145 | 201 | | (dest << CONV_DEST_TYPE_SHIFT) |
jrose@1145 | 202 | | (stack_move << CONV_STACK_MOVE_SHIFT) |
jrose@1145 | 203 | | (vminfo << CONV_VMINFO_SHIFT) |
jrose@1145 | 204 | ); |
jrose@1145 | 205 | assert(adapter_conversion_op(conv) == conv_op, "decode conv_op"); |
jrose@1145 | 206 | assert(adapter_conversion_src_type(conv) == src, "decode src"); |
jrose@1145 | 207 | assert(adapter_conversion_dest_type(conv) == dest, "decode dest"); |
jrose@1145 | 208 | assert(adapter_conversion_stack_move(conv) == stack_move, "decode stack_move"); |
jrose@1145 | 209 | assert(adapter_conversion_vminfo(conv) == vminfo, "decode vminfo"); |
jrose@1145 | 210 | return conv; |
jrose@1145 | 211 | } |
jrose@1145 | 212 | static int adapter_conversion_op(jint conv) { |
jrose@1145 | 213 | return ((conv >> CONV_OP_SHIFT) & 0xF); |
jrose@1145 | 214 | } |
jrose@1145 | 215 | static BasicType adapter_conversion_src_type(jint conv) { |
jrose@1145 | 216 | return (BasicType)((conv >> CONV_SRC_TYPE_SHIFT) & 0xF); |
jrose@1145 | 217 | } |
jrose@1145 | 218 | static BasicType adapter_conversion_dest_type(jint conv) { |
jrose@1145 | 219 | return (BasicType)((conv >> CONV_DEST_TYPE_SHIFT) & 0xF); |
jrose@1145 | 220 | } |
jrose@1145 | 221 | static int adapter_conversion_stack_move(jint conv) { |
jrose@1145 | 222 | return (conv >> CONV_STACK_MOVE_SHIFT); |
jrose@1145 | 223 | } |
jrose@1145 | 224 | static int adapter_conversion_vminfo(jint conv) { |
jrose@1145 | 225 | return (conv >> CONV_VMINFO_SHIFT) & CONV_VMINFO_MASK; |
jrose@1145 | 226 | } |
jrose@1145 | 227 | |
jrose@1862 | 228 | // Bit mask of conversion_op values. May vary by platform. |
jrose@1862 | 229 | static int adapter_conversion_ops_supported_mask(); |
jrose@1862 | 230 | |
jrose@1145 | 231 | // Offset in words that the interpreter stack pointer moves when an argument is pushed. |
jrose@1145 | 232 | // The stack_move value must always be a multiple of this. |
jrose@1145 | 233 | static int stack_move_unit() { |
twisti@1861 | 234 | return frame::interpreter_frame_expression_stack_direction() * Interpreter::stackElementWords; |
jrose@1145 | 235 | } |
jrose@1145 | 236 | |
jrose@1145 | 237 | enum { CONV_VMINFO_SIGN_FLAG = 0x80 }; |
twisti@2204 | 238 | // Shift values for prim-to-prim conversions. |
twisti@2204 | 239 | static int adapter_prim_to_prim_subword_vminfo(BasicType dest) { |
twisti@2204 | 240 | if (dest == T_BOOLEAN) return (BitsPerInt - 1); // boolean is 1 bit |
twisti@2204 | 241 | if (dest == T_CHAR) return (BitsPerInt - BitsPerShort); |
twisti@2204 | 242 | if (dest == T_BYTE) return (BitsPerInt - BitsPerByte ) | CONV_VMINFO_SIGN_FLAG; |
twisti@2204 | 243 | if (dest == T_SHORT) return (BitsPerInt - BitsPerShort) | CONV_VMINFO_SIGN_FLAG; |
twisti@2204 | 244 | return 0; // case T_INT |
twisti@2204 | 245 | } |
twisti@2204 | 246 | // Shift values for unboxing a primitive. |
twisti@2204 | 247 | static int adapter_unbox_subword_vminfo(BasicType dest) { |
twisti@2204 | 248 | if (dest == T_BOOLEAN) return (BitsPerInt - BitsPerByte ); // implemented as 1 byte |
twisti@2204 | 249 | if (dest == T_CHAR) return (BitsPerInt - BitsPerShort); |
twisti@2204 | 250 | if (dest == T_BYTE) return (BitsPerInt - BitsPerByte ) | CONV_VMINFO_SIGN_FLAG; |
twisti@2204 | 251 | if (dest == T_SHORT) return (BitsPerInt - BitsPerShort) | CONV_VMINFO_SIGN_FLAG; |
jrose@1145 | 252 | return 0; // case T_INT |
jrose@1145 | 253 | } |
jrose@1145 | 254 | // Here is the transformation the i2i adapter must perform: |
jrose@1145 | 255 | static int truncate_subword_from_vminfo(jint value, int vminfo) { |
jrose@1145 | 256 | jint tem = value << vminfo; |
jrose@1145 | 257 | if ((vminfo & CONV_VMINFO_SIGN_FLAG) != 0) { |
jrose@1145 | 258 | return (jint)tem >> vminfo; |
jrose@1145 | 259 | } else { |
jrose@1145 | 260 | return (juint)tem >> vminfo; |
jrose@1145 | 261 | } |
jrose@1145 | 262 | } |
jrose@1145 | 263 | |
jrose@1145 | 264 | static inline address from_compiled_entry(EntryKind ek); |
jrose@1145 | 265 | static inline address from_interpreted_entry(EntryKind ek); |
jrose@1145 | 266 | |
jrose@1145 | 267 | // helpers for decode_method. |
jrose@1145 | 268 | static methodOop decode_methodOop(methodOop m, int& decode_flags_result); |
jrose@1145 | 269 | static methodOop decode_vmtarget(oop vmtarget, int vmindex, oop mtype, klassOop& receiver_limit_result, int& decode_flags_result); |
jrose@1145 | 270 | static methodOop decode_MemberName(oop mname, klassOop& receiver_limit_result, int& decode_flags_result); |
jrose@1145 | 271 | static methodOop decode_MethodHandle(oop mh, klassOop& receiver_limit_result, int& decode_flags_result); |
jrose@1145 | 272 | static methodOop decode_DirectMethodHandle(oop mh, klassOop& receiver_limit_result, int& decode_flags_result); |
jrose@1145 | 273 | static methodOop decode_BoundMethodHandle(oop mh, klassOop& receiver_limit_result, int& decode_flags_result); |
jrose@1145 | 274 | static methodOop decode_AdapterMethodHandle(oop mh, klassOop& receiver_limit_result, int& decode_flags_result); |
jrose@1145 | 275 | |
jrose@1145 | 276 | // Find out how many stack slots an mh pushes or pops. |
jrose@1145 | 277 | // The result is *not* reported as a multiple of stack_move_unit(); |
jrose@1145 | 278 | // It is a signed net number of pushes (a difference in vmslots). |
jrose@1145 | 279 | // To compare with a stack_move value, first multiply by stack_move_unit(). |
jrose@1145 | 280 | static int decode_MethodHandle_stack_pushes(oop mh); |
jrose@1145 | 281 | |
jrose@1145 | 282 | public: |
jrose@1145 | 283 | // working with member names |
jrose@1145 | 284 | static void resolve_MemberName(Handle mname, TRAPS); // compute vmtarget/vmindex from name/type |
jrose@1145 | 285 | static void expand_MemberName(Handle mname, int suppress, TRAPS); // expand defc/name/type if missing |
jrose@1862 | 286 | static Handle new_MemberName(TRAPS); // must be followed by init_MemberName |
jrose@1145 | 287 | static void init_MemberName(oop mname_oop, oop target); // compute vmtarget/vmindex from target |
jrose@1862 | 288 | static void init_MemberName(oop mname_oop, methodOop m, bool do_dispatch = true); |
jrose@1145 | 289 | static void init_MemberName(oop mname_oop, klassOop field_holder, AccessFlags mods, int offset); |
jrose@1145 | 290 | static int find_MemberNames(klassOop k, symbolOop name, symbolOop sig, |
jrose@1145 | 291 | int mflags, klassOop caller, |
jrose@1145 | 292 | int skip, objArrayOop results); |
jrose@1145 | 293 | // bit values for suppress argument to expand_MemberName: |
jrose@1145 | 294 | enum { _suppress_defc = 1, _suppress_name = 2, _suppress_type = 4 }; |
jrose@1145 | 295 | |
twisti@1734 | 296 | // Generate MethodHandles adapters. |
twisti@1734 | 297 | static void generate_adapters(); |
twisti@1734 | 298 | |
twisti@1734 | 299 | // Called from InterpreterGenerator and MethodHandlesAdapterGenerator. |
jrose@1145 | 300 | static address generate_method_handle_interpreter_entry(MacroAssembler* _masm); |
jrose@1145 | 301 | static void generate_method_handle_stub(MacroAssembler* _masm, EntryKind ek); |
jrose@1145 | 302 | |
jrose@1145 | 303 | // argument list parsing |
jrose@1145 | 304 | static int argument_slot(oop method_type, int arg); |
jrose@1145 | 305 | static int argument_slot_count(oop method_type) { return argument_slot(method_type, -1); } |
jrose@1145 | 306 | static int argument_slot_to_argnum(oop method_type, int argslot); |
jrose@1145 | 307 | |
jrose@1145 | 308 | // Runtime support |
jrose@1145 | 309 | enum { // bit-encoded flags from decode_method or decode_vmref |
jrose@1145 | 310 | _dmf_has_receiver = 0x01, // target method has leading reference argument |
jrose@1145 | 311 | _dmf_does_dispatch = 0x02, // method handle performs virtual or interface dispatch |
jrose@1145 | 312 | _dmf_from_interface = 0x04, // peforms interface dispatch |
jrose@1145 | 313 | _DMF_DIRECT_MASK = (_dmf_from_interface*2 - _dmf_has_receiver), |
jrose@1145 | 314 | _dmf_binds_method = 0x08, |
jrose@1145 | 315 | _dmf_binds_argument = 0x10, |
jrose@1145 | 316 | _DMF_BOUND_MASK = (_dmf_binds_argument*2 - _dmf_binds_method), |
jrose@1145 | 317 | _dmf_adapter_lsb = 0x20, |
jrose@1145 | 318 | _DMF_ADAPTER_MASK = (_dmf_adapter_lsb << CONV_OP_LIMIT) - _dmf_adapter_lsb |
jrose@1145 | 319 | }; |
jrose@1145 | 320 | static methodOop decode_method(oop x, klassOop& receiver_limit_result, int& decode_flags_result); |
jrose@1145 | 321 | enum { |
jrose@1145 | 322 | // format of query to getConstant: |
jrose@1145 | 323 | GC_JVM_PUSH_LIMIT = 0, |
jrose@1474 | 324 | GC_JVM_STACK_MOVE_UNIT = 1, |
jrose@1862 | 325 | GC_CONV_OP_IMPLEMENTED_MASK = 2, |
jrose@1145 | 326 | |
jrose@1145 | 327 | // format of result from getTarget / encode_target: |
jrose@1145 | 328 | ETF_HANDLE_OR_METHOD_NAME = 0, // all available data (immediate MH or method) |
jrose@1145 | 329 | ETF_DIRECT_HANDLE = 1, // ultimate method handle (will be a DMH, may be self) |
jrose@1145 | 330 | ETF_METHOD_NAME = 2, // ultimate method as MemberName |
jrose@1145 | 331 | ETF_REFLECT_METHOD = 3 // ultimate method as java.lang.reflect object (sans refClass) |
jrose@1145 | 332 | }; |
jrose@1145 | 333 | static int get_named_constant(int which, Handle name_box, TRAPS); |
jrose@1145 | 334 | static oop encode_target(Handle mh, int format, TRAPS); // report vmtarget (to Java code) |
jrose@1145 | 335 | static bool class_cast_needed(klassOop src, klassOop dst); |
jrose@1145 | 336 | |
jrose@1862 | 337 | static instanceKlassHandle resolve_instance_klass(oop java_mirror_oop, TRAPS); |
jrose@1862 | 338 | static instanceKlassHandle resolve_instance_klass(jclass java_mirror_jh, TRAPS) { |
jrose@1862 | 339 | return resolve_instance_klass(JNIHandles::resolve(java_mirror_jh), THREAD); |
jrose@1862 | 340 | } |
jrose@1862 | 341 | |
jrose@1145 | 342 | private: |
jrose@1145 | 343 | // These checkers operate on a pair of whole MethodTypes: |
jrose@1145 | 344 | static const char* check_method_type_change(oop src_mtype, int src_beg, int src_end, |
jrose@1145 | 345 | int insert_argnum, oop insert_type, |
jrose@1145 | 346 | int change_argnum, oop change_type, |
jrose@1145 | 347 | int delete_argnum, |
jrose@1474 | 348 | oop dst_mtype, int dst_beg, int dst_end, |
jrose@1474 | 349 | bool raw = false); |
jrose@1145 | 350 | static const char* check_method_type_insertion(oop src_mtype, |
jrose@1145 | 351 | int insert_argnum, oop insert_type, |
jrose@1145 | 352 | oop dst_mtype) { |
jrose@1145 | 353 | oop no_ref = NULL; |
jrose@1145 | 354 | return check_method_type_change(src_mtype, 0, -1, |
jrose@1145 | 355 | insert_argnum, insert_type, |
jrose@1145 | 356 | -1, no_ref, -1, dst_mtype, 0, -1); |
jrose@1145 | 357 | } |
jrose@1145 | 358 | static const char* check_method_type_conversion(oop src_mtype, |
jrose@1145 | 359 | int change_argnum, oop change_type, |
jrose@1145 | 360 | oop dst_mtype) { |
jrose@1145 | 361 | oop no_ref = NULL; |
jrose@1145 | 362 | return check_method_type_change(src_mtype, 0, -1, -1, no_ref, |
jrose@1145 | 363 | change_argnum, change_type, |
jrose@1145 | 364 | -1, dst_mtype, 0, -1); |
jrose@1145 | 365 | } |
jrose@1474 | 366 | static const char* check_method_type_passthrough(oop src_mtype, oop dst_mtype, bool raw) { |
jrose@1145 | 367 | oop no_ref = NULL; |
jrose@1145 | 368 | return check_method_type_change(src_mtype, 0, -1, |
jrose@1145 | 369 | -1, no_ref, -1, no_ref, -1, |
jrose@1474 | 370 | dst_mtype, 0, -1, raw); |
jrose@1145 | 371 | } |
jrose@1145 | 372 | |
jrose@1145 | 373 | // These checkers operate on pairs of argument or return types: |
jrose@1145 | 374 | static const char* check_argument_type_change(BasicType src_type, klassOop src_klass, |
jrose@1145 | 375 | BasicType dst_type, klassOop dst_klass, |
jrose@1474 | 376 | int argnum, bool raw = false); |
jrose@1145 | 377 | |
jrose@1145 | 378 | static const char* check_argument_type_change(oop src_type, oop dst_type, |
jrose@1474 | 379 | int argnum, bool raw = false) { |
jrose@1145 | 380 | klassOop src_klass = NULL, dst_klass = NULL; |
jrose@1145 | 381 | BasicType src_bt = java_lang_Class::as_BasicType(src_type, &src_klass); |
jrose@1145 | 382 | BasicType dst_bt = java_lang_Class::as_BasicType(dst_type, &dst_klass); |
jrose@1145 | 383 | return check_argument_type_change(src_bt, src_klass, |
jrose@1474 | 384 | dst_bt, dst_klass, argnum, raw); |
jrose@1145 | 385 | } |
jrose@1145 | 386 | |
jrose@1474 | 387 | static const char* check_return_type_change(oop src_type, oop dst_type, bool raw = false) { |
jrose@1474 | 388 | return check_argument_type_change(src_type, dst_type, -1, raw); |
jrose@1145 | 389 | } |
jrose@1145 | 390 | |
jrose@1145 | 391 | static const char* check_return_type_change(BasicType src_type, klassOop src_klass, |
jrose@1145 | 392 | BasicType dst_type, klassOop dst_klass) { |
jrose@1145 | 393 | return check_argument_type_change(src_type, src_klass, dst_type, dst_klass, -1); |
jrose@1145 | 394 | } |
jrose@1145 | 395 | |
jrose@1145 | 396 | static const char* check_method_receiver(methodOop m, klassOop passed_recv_type); |
jrose@1145 | 397 | |
jrose@1145 | 398 | // These verifiers can block, and will throw an error if the checking fails: |
jrose@1145 | 399 | static void verify_vmslots(Handle mh, TRAPS); |
jrose@1145 | 400 | static void verify_vmargslot(Handle mh, int argnum, int argslot, TRAPS); |
jrose@1145 | 401 | |
jrose@1145 | 402 | static void verify_method_type(methodHandle m, Handle mtype, |
jrose@1145 | 403 | bool has_bound_oop, |
jrose@1145 | 404 | KlassHandle bound_oop_type, |
jrose@1145 | 405 | TRAPS); |
jrose@1145 | 406 | |
jrose@1145 | 407 | static void verify_method_signature(methodHandle m, Handle mtype, |
jrose@1145 | 408 | int first_ptype_pos, |
jrose@1145 | 409 | KlassHandle insert_ptype, TRAPS); |
jrose@1145 | 410 | |
jrose@1145 | 411 | static void verify_DirectMethodHandle(Handle mh, methodHandle m, TRAPS); |
jrose@1145 | 412 | static void verify_BoundMethodHandle(Handle mh, Handle target, int argnum, |
jrose@1145 | 413 | bool direct_to_method, TRAPS); |
jrose@1145 | 414 | static void verify_BoundMethodHandle_with_receiver(Handle mh, methodHandle m, TRAPS); |
jrose@1145 | 415 | static void verify_AdapterMethodHandle(Handle mh, int argnum, TRAPS); |
jrose@1145 | 416 | |
jrose@1145 | 417 | public: |
jrose@1145 | 418 | |
jrose@1145 | 419 | // Fill in the fields of a DirectMethodHandle mh. (MH.type must be pre-filled.) |
jrose@1145 | 420 | static void init_DirectMethodHandle(Handle mh, methodHandle method, bool do_dispatch, TRAPS); |
jrose@1145 | 421 | |
jrose@1145 | 422 | // Fill in the fields of a BoundMethodHandle mh. (MH.type, BMH.argument must be pre-filled.) |
jrose@1145 | 423 | static void init_BoundMethodHandle(Handle mh, Handle target, int argnum, TRAPS); |
jrose@1145 | 424 | static void init_BoundMethodHandle_with_receiver(Handle mh, |
jrose@1145 | 425 | methodHandle original_m, |
jrose@1145 | 426 | KlassHandle receiver_limit, |
jrose@1145 | 427 | int decode_flags, |
jrose@1145 | 428 | TRAPS); |
jrose@1145 | 429 | |
jrose@1145 | 430 | // Fill in the fields of an AdapterMethodHandle mh. (MH.type must be pre-filled.) |
jrose@1145 | 431 | static void init_AdapterMethodHandle(Handle mh, Handle target, int argnum, TRAPS); |
jrose@1145 | 432 | |
jrose@1145 | 433 | #ifdef ASSERT |
jrose@1145 | 434 | static bool spot_check_entry_names(); |
jrose@1145 | 435 | #endif |
jrose@1145 | 436 | |
jrose@1145 | 437 | private: |
jrose@1145 | 438 | static methodHandle dispatch_decoded_method(methodHandle m, |
jrose@1145 | 439 | KlassHandle receiver_limit, |
jrose@1145 | 440 | int decode_flags, |
jrose@1145 | 441 | KlassHandle receiver_klass, |
jrose@1145 | 442 | TRAPS); |
jrose@1145 | 443 | |
jrose@1145 | 444 | static bool same_basic_type_for_arguments(BasicType src, BasicType dst, |
jrose@1474 | 445 | bool raw = false, |
jrose@1145 | 446 | bool for_return = false); |
jrose@1474 | 447 | static bool same_basic_type_for_returns(BasicType src, BasicType dst, bool raw = false) { |
jrose@1474 | 448 | return same_basic_type_for_arguments(src, dst, raw, true); |
jrose@1145 | 449 | } |
jrose@1145 | 450 | |
jrose@1145 | 451 | enum { // arg_mask values |
jrose@1145 | 452 | _INSERT_NO_MASK = -1, |
jrose@1145 | 453 | _INSERT_REF_MASK = 0, |
jrose@1145 | 454 | _INSERT_INT_MASK = 1, |
jrose@1145 | 455 | _INSERT_LONG_MASK = 3 |
jrose@1145 | 456 | }; |
jrose@1145 | 457 | static void insert_arg_slots(MacroAssembler* _masm, |
jrose@1145 | 458 | RegisterOrConstant arg_slots, |
jrose@1145 | 459 | int arg_mask, |
twisti@1739 | 460 | Register argslot_reg, |
twisti@1858 | 461 | Register temp_reg, Register temp2_reg, Register temp3_reg = noreg); |
jrose@1145 | 462 | |
jrose@1145 | 463 | static void remove_arg_slots(MacroAssembler* _masm, |
jrose@1145 | 464 | RegisterOrConstant arg_slots, |
twisti@1739 | 465 | Register argslot_reg, |
twisti@1858 | 466 | Register temp_reg, Register temp2_reg, Register temp3_reg = noreg); |
jrose@2148 | 467 | |
jrose@2148 | 468 | static void trace_method_handle(MacroAssembler* _masm, const char* adaptername) PRODUCT_RETURN; |
jrose@1145 | 469 | }; |
jrose@1145 | 470 | |
jrose@1145 | 471 | |
jrose@1145 | 472 | // Access methods for the "entry" field of a java.dyn.MethodHandle. |
jrose@1145 | 473 | // The field is primarily a jump target for compiled calls. |
jrose@1145 | 474 | // However, we squirrel away some nice pointers for other uses, |
jrose@1145 | 475 | // just before the jump target. |
jrose@1145 | 476 | // Aspects of a method handle entry: |
jrose@1145 | 477 | // - from_compiled_entry - stub used when compiled code calls the MH |
jrose@1145 | 478 | // - from_interpreted_entry - stub used when the interpreter calls the MH |
jrose@1145 | 479 | // - type_checking_entry - stub for runtime casting between MHForm siblings (NYI) |
jrose@1145 | 480 | class MethodHandleEntry { |
jrose@1145 | 481 | public: |
jrose@1145 | 482 | class Data { |
jrose@1145 | 483 | friend class MethodHandleEntry; |
jrose@1145 | 484 | size_t _total_size; // size including Data and code stub |
jrose@1145 | 485 | MethodHandleEntry* _type_checking_entry; |
jrose@1145 | 486 | address _from_interpreted_entry; |
jrose@1145 | 487 | MethodHandleEntry* method_entry() { return (MethodHandleEntry*)(this + 1); } |
jrose@1145 | 488 | }; |
jrose@1145 | 489 | |
jrose@1145 | 490 | Data* data() { return (Data*)this - 1; } |
jrose@1145 | 491 | |
jrose@1145 | 492 | address start_address() { return (address) data(); } |
jrose@1145 | 493 | address end_address() { return start_address() + data()->_total_size; } |
jrose@1145 | 494 | |
jrose@1145 | 495 | address from_compiled_entry() { return (address) this; } |
jrose@1145 | 496 | |
jrose@1145 | 497 | address from_interpreted_entry() { return data()->_from_interpreted_entry; } |
jrose@1145 | 498 | void set_from_interpreted_entry(address e) { data()->_from_interpreted_entry = e; } |
jrose@1145 | 499 | |
jrose@1145 | 500 | MethodHandleEntry* type_checking_entry() { return data()->_type_checking_entry; } |
jrose@1145 | 501 | void set_type_checking_entry(MethodHandleEntry* e) { data()->_type_checking_entry = e; } |
jrose@1145 | 502 | |
jrose@1145 | 503 | void set_end_address(address end_addr) { |
jrose@1145 | 504 | size_t total_size = end_addr - start_address(); |
jrose@1145 | 505 | assert(total_size > 0 && total_size < 0x1000, "reasonable end address"); |
jrose@1145 | 506 | data()->_total_size = total_size; |
jrose@1145 | 507 | } |
jrose@1145 | 508 | |
jrose@1145 | 509 | // Compiler support: |
jrose@1145 | 510 | static int from_interpreted_entry_offset_in_bytes() { |
jrose@1145 | 511 | return (int)( offset_of(Data, _from_interpreted_entry) - sizeof(Data) ); |
jrose@1145 | 512 | } |
jrose@1145 | 513 | static int type_checking_entry_offset_in_bytes() { |
jrose@1145 | 514 | return (int)( offset_of(Data, _from_interpreted_entry) - sizeof(Data) ); |
jrose@1145 | 515 | } |
jrose@1145 | 516 | |
jrose@1145 | 517 | static address start_compiled_entry(MacroAssembler* _masm, |
jrose@1145 | 518 | address interpreted_entry = NULL); |
jrose@1145 | 519 | static MethodHandleEntry* finish_compiled_entry(MacroAssembler* masm, address start_addr); |
jrose@1145 | 520 | }; |
jrose@1145 | 521 | |
jrose@1145 | 522 | address MethodHandles::from_compiled_entry(EntryKind ek) { return entry(ek)->from_compiled_entry(); } |
jrose@1145 | 523 | address MethodHandles::from_interpreted_entry(EntryKind ek) { return entry(ek)->from_interpreted_entry(); } |
twisti@1734 | 524 | |
twisti@1734 | 525 | |
twisti@1734 | 526 | //------------------------------------------------------------------------------ |
twisti@1734 | 527 | // MethodHandlesAdapterGenerator |
twisti@1734 | 528 | // |
twisti@1734 | 529 | class MethodHandlesAdapterGenerator : public StubCodeGenerator { |
twisti@1734 | 530 | public: |
twisti@1734 | 531 | MethodHandlesAdapterGenerator(CodeBuffer* code) : StubCodeGenerator(code) {} |
twisti@1734 | 532 | |
twisti@1734 | 533 | void generate(); |
twisti@1734 | 534 | }; |
stefank@2314 | 535 | |
stefank@2314 | 536 | #endif // SHARE_VM_PRIMS_METHODHANDLES_HPP |