annotate src/share/vm/prims/methodHandles.hpp @ 2707:393f4b789fd0

7077806: ARM: java.lang.InternalError: bound subword value does not fit into the subword type Summary: shared fix necessary for ARM/PPC Reviewed-by: twisti, roland
author bdelsart
date Wed, 14 Sep 2011 16:28:39 +0200
parents c26de9aef2ed
children 15d394228cfa
rev   line source
jrose@710 1 /*
twisti@2001 2 * Copyright (c) 2008, 2011, 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 class MethodHandleEntry;
jrose@710 37
jrose@710 38 class MethodHandles: AllStatic {
jrose@710 39 // JVM support for MethodHandle, MethodType, and related types
jrose@2204 40 // in java.lang.invoke and sun.invoke.
jrose@2204 41 // See also javaClasses for layouts java_lang_invoke_Method{Handle,Type,Type::Form}.
jrose@710 42 public:
jrose@710 43 enum EntryKind {
jrose@1039 44 _raise_exception, // stub for error generation from other stubs
jrose@710 45 _invokestatic_mh, // how a MH emulates invokestatic
jrose@710 46 _invokespecial_mh, // ditto for the other invokes...
jrose@710 47 _invokevirtual_mh,
jrose@710 48 _invokeinterface_mh,
jrose@710 49 _bound_ref_mh, // reference argument is bound
jrose@710 50 _bound_int_mh, // int argument is bound (via an Integer or Float)
jrose@710 51 _bound_long_mh, // long argument is bound (via a Long or Double)
jrose@710 52 _bound_ref_direct_mh, // same as above, with direct linkage to methodOop
jrose@710 53 _bound_int_direct_mh,
jrose@710 54 _bound_long_direct_mh,
jrose@710 55
jrose@710 56 _adapter_mh_first, // adapter sequence goes here...
jrose@2204 57 _adapter_retype_only = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::OP_RETYPE_ONLY,
jrose@2204 58 _adapter_retype_raw = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::OP_RETYPE_RAW,
jrose@2204 59 _adapter_check_cast = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::OP_CHECK_CAST,
jrose@2204 60 _adapter_prim_to_prim = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::OP_PRIM_TO_PRIM,
jrose@2204 61 _adapter_ref_to_prim = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::OP_REF_TO_PRIM,
jrose@2204 62 _adapter_prim_to_ref = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::OP_PRIM_TO_REF,
jrose@2204 63 _adapter_swap_args = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::OP_SWAP_ARGS,
jrose@2204 64 _adapter_rot_args = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::OP_ROT_ARGS,
jrose@2204 65 _adapter_dup_args = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::OP_DUP_ARGS,
jrose@2204 66 _adapter_drop_args = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::OP_DROP_ARGS,
jrose@2204 67 _adapter_collect_args = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::OP_COLLECT_ARGS,
jrose@2204 68 _adapter_spread_args = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::OP_SPREAD_ARGS,
never@2460 69 _adapter_fold_args = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::OP_FOLD_ARGS,
never@2460 70 _adapter_unused_13 = _adapter_mh_first + 13, //hole in the CONV_OP enumeration
jrose@2204 71 _adapter_mh_last = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::CONV_OP_LIMIT - 1,
jrose@710 72
jrose@710 73 // Optimized adapter types
jrose@710 74
jrose@710 75 // argument list reordering
jrose@710 76 _adapter_opt_swap_1,
jrose@710 77 _adapter_opt_swap_2,
jrose@710 78 _adapter_opt_rot_1_up,
jrose@710 79 _adapter_opt_rot_1_down,
jrose@710 80 _adapter_opt_rot_2_up,
jrose@710 81 _adapter_opt_rot_2_down,
jrose@710 82 // primitive single to single:
jrose@710 83 _adapter_opt_i2i, // i2c, i2z, i2b, i2s
jrose@710 84 // primitive double to single:
jrose@710 85 _adapter_opt_l2i,
jrose@710 86 _adapter_opt_d2f,
jrose@710 87 // primitive single to double:
jrose@710 88 _adapter_opt_i2l,
jrose@710 89 _adapter_opt_f2d,
jrose@710 90 // conversion between floating point and integer type is handled by Java
jrose@710 91
jrose@710 92 // reference to primitive:
jrose@710 93 _adapter_opt_unboxi,
jrose@710 94 _adapter_opt_unboxl,
jrose@710 95
never@2460 96 // %% Maybe tame the following with a VM_SYMBOLS_DO type macro?
never@2460 97
never@2460 98 // how a blocking adapter returns (platform-dependent)
never@2460 99 _adapter_opt_return_ref,
never@2460 100 _adapter_opt_return_int,
never@2460 101 _adapter_opt_return_long,
never@2460 102 _adapter_opt_return_float,
never@2460 103 _adapter_opt_return_double,
never@2460 104 _adapter_opt_return_void,
never@2460 105 _adapter_opt_return_S0_ref, // return ref to S=0 (last slot)
never@2460 106 _adapter_opt_return_S1_ref, // return ref to S=1 (2nd-to-last slot)
never@2460 107 _adapter_opt_return_S2_ref,
never@2460 108 _adapter_opt_return_S3_ref,
never@2460 109 _adapter_opt_return_S4_ref,
never@2460 110 _adapter_opt_return_S5_ref,
never@2460 111 _adapter_opt_return_any, // dynamically select r/i/l/f/d
never@2460 112 _adapter_opt_return_FIRST = _adapter_opt_return_ref,
never@2460 113 _adapter_opt_return_LAST = _adapter_opt_return_any,
never@2460 114
never@2460 115 // spreading (array length cases 0, 1, ...)
never@2460 116 _adapter_opt_spread_0, // spread empty array to N=0 arguments
never@2460 117 _adapter_opt_spread_1_ref, // spread Object[] to N=1 argument
never@2460 118 _adapter_opt_spread_2_ref, // spread Object[] to N=2 arguments
never@2460 119 _adapter_opt_spread_3_ref, // spread Object[] to N=3 arguments
never@2460 120 _adapter_opt_spread_4_ref, // spread Object[] to N=4 arguments
never@2460 121 _adapter_opt_spread_5_ref, // spread Object[] to N=5 arguments
never@2460 122 _adapter_opt_spread_ref, // spread Object[] to N arguments
never@2460 123 _adapter_opt_spread_byte, // spread byte[] or boolean[] to N arguments
never@2460 124 _adapter_opt_spread_char, // spread char[], etc., to N arguments
never@2460 125 _adapter_opt_spread_short, // spread short[], etc., to N arguments
never@2460 126 _adapter_opt_spread_int, // spread int[], short[], etc., to N arguments
never@2460 127 _adapter_opt_spread_long, // spread long[] to N arguments
never@2460 128 _adapter_opt_spread_float, // spread float[] to N arguments
never@2460 129 _adapter_opt_spread_double, // spread double[] to N arguments
never@2460 130 _adapter_opt_spread_FIRST = _adapter_opt_spread_0,
never@2460 131 _adapter_opt_spread_LAST = _adapter_opt_spread_double,
never@2460 132
never@2460 133 // blocking filter/collect conversions
never@2460 134 // These collect N arguments and replace them (at slot S) by a return value
never@2460 135 // which is passed to the final target, along with the unaffected arguments.
never@2460 136 // collect_{N}_{T} collects N arguments at any position into a T value
never@2460 137 // collect_{N}_S{S}_{T} collects N arguments at slot S into a T value
never@2460 138 // collect_{T} collects any number of arguments at any position
never@2460 139 // filter_S{S}_{T} is the same as collect_1_S{S}_{T} (a unary collection)
never@2460 140 // (collect_2 is also usable as a filter, with long or double arguments)
never@2460 141 _adapter_opt_collect_ref, // combine N arguments, replace with a reference
never@2460 142 _adapter_opt_collect_int, // combine N arguments, replace with an int, short, etc.
never@2460 143 _adapter_opt_collect_long, // combine N arguments, replace with a long
never@2460 144 _adapter_opt_collect_float, // combine N arguments, replace with a float
never@2460 145 _adapter_opt_collect_double, // combine N arguments, replace with a double
never@2460 146 _adapter_opt_collect_void, // combine N arguments, replace with nothing
never@2460 147 // if there is a small fixed number to push, do so without a loop:
never@2460 148 _adapter_opt_collect_0_ref, // collect N=0 arguments, insert a reference
never@2460 149 _adapter_opt_collect_1_ref, // collect N=1 argument, replace with a reference
never@2460 150 _adapter_opt_collect_2_ref, // combine N=2 arguments, replace with a reference
never@2460 151 _adapter_opt_collect_3_ref, // combine N=3 arguments, replace with a reference
never@2460 152 _adapter_opt_collect_4_ref, // combine N=4 arguments, replace with a reference
never@2460 153 _adapter_opt_collect_5_ref, // combine N=5 arguments, replace with a reference
never@2460 154 // filters are an important special case because they never move arguments:
never@2460 155 _adapter_opt_filter_S0_ref, // filter N=1 argument at S=0, replace with a reference
never@2460 156 _adapter_opt_filter_S1_ref, // filter N=1 argument at S=1, replace with a reference
never@2460 157 _adapter_opt_filter_S2_ref, // filter N=1 argument at S=2, replace with a reference
never@2460 158 _adapter_opt_filter_S3_ref, // filter N=1 argument at S=3, replace with a reference
never@2460 159 _adapter_opt_filter_S4_ref, // filter N=1 argument at S=4, replace with a reference
never@2460 160 _adapter_opt_filter_S5_ref, // filter N=1 argument at S=5, replace with a reference
never@2460 161 // these move arguments, but they are important for boxing
never@2460 162 _adapter_opt_collect_2_S0_ref, // combine last N=2 arguments, replace with a reference
never@2460 163 _adapter_opt_collect_2_S1_ref, // combine N=2 arguments at S=1, replace with a reference
never@2460 164 _adapter_opt_collect_2_S2_ref, // combine N=2 arguments at S=2, replace with a reference
never@2460 165 _adapter_opt_collect_2_S3_ref, // combine N=2 arguments at S=3, replace with a reference
never@2460 166 _adapter_opt_collect_2_S4_ref, // combine N=2 arguments at S=4, replace with a reference
never@2460 167 _adapter_opt_collect_2_S5_ref, // combine N=2 arguments at S=5, replace with a reference
never@2460 168 _adapter_opt_collect_FIRST = _adapter_opt_collect_ref,
never@2460 169 _adapter_opt_collect_LAST = _adapter_opt_collect_2_S5_ref,
never@2460 170
never@2460 171 // blocking folding conversions
never@2460 172 // these are like collects, but retain all the N arguments for the final target
never@2460 173 //_adapter_opt_fold_0_ref, // same as _adapter_opt_collect_0_ref
never@2460 174 // fold_{N}_{T} processes N arguments at any position into a T value, which it inserts
never@2460 175 // fold_{T} processes any number of arguments at any position
never@2460 176 _adapter_opt_fold_ref, // process N arguments, prepend a reference
never@2460 177 _adapter_opt_fold_int, // process N arguments, prepend an int, short, etc.
never@2460 178 _adapter_opt_fold_long, // process N arguments, prepend a long
never@2460 179 _adapter_opt_fold_float, // process N arguments, prepend a float
never@2460 180 _adapter_opt_fold_double, // process N arguments, prepend a double
never@2460 181 _adapter_opt_fold_void, // process N arguments, but leave the list unchanged
never@2460 182 _adapter_opt_fold_1_ref, // process N=1 argument, prepend a reference
never@2460 183 _adapter_opt_fold_2_ref, // process N=2 arguments, prepend a reference
never@2460 184 _adapter_opt_fold_3_ref, // process N=3 arguments, prepend a reference
never@2460 185 _adapter_opt_fold_4_ref, // process N=4 arguments, prepend a reference
never@2460 186 _adapter_opt_fold_5_ref, // process N=5 arguments, prepend a reference
never@2460 187 _adapter_opt_fold_FIRST = _adapter_opt_fold_ref,
never@2460 188 _adapter_opt_fold_LAST = _adapter_opt_fold_5_ref,
jrose@710 189
never@2670 190 _adapter_opt_profiling,
never@2670 191
jrose@710 192 _EK_LIMIT,
jrose@710 193 _EK_FIRST = 0
jrose@710 194 };
jrose@710 195
jrose@710 196 public:
jrose@710 197 static bool enabled() { return _enabled; }
jrose@710 198 static void set_enabled(bool z);
jrose@710 199
jrose@710 200 private:
jrose@2204 201 enum { // import java_lang_invoke_AdapterMethodHandle::CONV_OP_*
jrose@2204 202 CONV_OP_LIMIT = java_lang_invoke_AdapterMethodHandle::CONV_OP_LIMIT,
jrose@2204 203 CONV_OP_MASK = java_lang_invoke_AdapterMethodHandle::CONV_OP_MASK,
never@2460 204 CONV_TYPE_MASK = java_lang_invoke_AdapterMethodHandle::CONV_TYPE_MASK,
jrose@2204 205 CONV_VMINFO_MASK = java_lang_invoke_AdapterMethodHandle::CONV_VMINFO_MASK,
jrose@2204 206 CONV_VMINFO_SHIFT = java_lang_invoke_AdapterMethodHandle::CONV_VMINFO_SHIFT,
jrose@2204 207 CONV_OP_SHIFT = java_lang_invoke_AdapterMethodHandle::CONV_OP_SHIFT,
jrose@2204 208 CONV_DEST_TYPE_SHIFT = java_lang_invoke_AdapterMethodHandle::CONV_DEST_TYPE_SHIFT,
jrose@2204 209 CONV_SRC_TYPE_SHIFT = java_lang_invoke_AdapterMethodHandle::CONV_SRC_TYPE_SHIFT,
jrose@2204 210 CONV_STACK_MOVE_SHIFT = java_lang_invoke_AdapterMethodHandle::CONV_STACK_MOVE_SHIFT,
jrose@2204 211 CONV_STACK_MOVE_MASK = java_lang_invoke_AdapterMethodHandle::CONV_STACK_MOVE_MASK
jrose@710 212 };
jrose@710 213
jrose@710 214 static bool _enabled;
jrose@710 215 static MethodHandleEntry* _entries[_EK_LIMIT];
jrose@710 216 static const char* _entry_names[_EK_LIMIT+1];
jrose@1039 217 static jobject _raise_exception_method;
never@2460 218 static address _adapter_return_handlers[CONV_TYPE_MASK+1];
jrose@1039 219
twisti@1299 220 // Adapters.
twisti@1299 221 static MethodHandlesAdapterBlob* _adapter_code;
twisti@1299 222
jrose@710 223 static bool ek_valid(EntryKind ek) { return (uint)ek < (uint)_EK_LIMIT; }
jrose@710 224 static bool conv_op_valid(int op) { return (uint)op < (uint)CONV_OP_LIMIT; }
jrose@710 225
jrose@710 226 public:
jrose@710 227 static bool have_entry(EntryKind ek) { return ek_valid(ek) && _entries[ek] != NULL; }
jrose@710 228 static MethodHandleEntry* entry(EntryKind ek) { assert(ek_valid(ek), "initialized");
jrose@710 229 return _entries[ek]; }
jrose@710 230 static const char* entry_name(EntryKind ek) { assert(ek_valid(ek), "oob");
jrose@710 231 return _entry_names[ek]; }
jrose@710 232 static EntryKind adapter_entry_kind(int op) { assert(conv_op_valid(op), "oob");
jrose@710 233 return EntryKind(_adapter_mh_first + op); }
jrose@710 234
jrose@710 235 static void init_entry(EntryKind ek, MethodHandleEntry* me) {
jrose@710 236 assert(ek_valid(ek), "oob");
jrose@710 237 assert(_entries[ek] == NULL, "no double initialization");
jrose@710 238 _entries[ek] = me;
jrose@710 239 }
jrose@710 240
twisti@1304 241 // Some adapter helper functions.
never@2460 242 static EntryKind ek_original_kind(EntryKind ek) {
never@2460 243 if (ek <= _adapter_mh_last) return ek;
twisti@1304 244 switch (ek) {
never@2460 245 case _adapter_opt_swap_1:
never@2460 246 case _adapter_opt_swap_2:
never@2460 247 return _adapter_swap_args;
never@2460 248 case _adapter_opt_rot_1_up:
never@2460 249 case _adapter_opt_rot_1_down:
never@2460 250 case _adapter_opt_rot_2_up:
never@2460 251 case _adapter_opt_rot_2_down:
never@2460 252 return _adapter_rot_args;
never@2460 253 case _adapter_opt_i2i:
never@2460 254 case _adapter_opt_l2i:
never@2460 255 case _adapter_opt_d2f:
never@2460 256 case _adapter_opt_i2l:
never@2460 257 case _adapter_opt_f2d:
never@2460 258 return _adapter_prim_to_prim;
never@2460 259 case _adapter_opt_unboxi:
never@2460 260 case _adapter_opt_unboxl:
never@2460 261 return _adapter_ref_to_prim;
twisti@1304 262 }
never@2460 263 if (ek >= _adapter_opt_spread_FIRST && ek <= _adapter_opt_spread_LAST)
never@2460 264 return _adapter_spread_args;
never@2460 265 if (ek >= _adapter_opt_collect_FIRST && ek <= _adapter_opt_collect_LAST)
never@2460 266 return _adapter_collect_args;
never@2460 267 if (ek >= _adapter_opt_fold_FIRST && ek <= _adapter_opt_fold_LAST)
never@2460 268 return _adapter_fold_args;
never@2460 269 if (ek >= _adapter_opt_return_FIRST && ek <= _adapter_opt_return_LAST)
never@2460 270 return _adapter_opt_return_any;
never@2670 271 if (ek == _adapter_opt_profiling)
never@2670 272 return _adapter_retype_only;
never@2460 273 assert(false, "oob");
never@2460 274 return _EK_LIMIT;
twisti@1304 275 }
twisti@1304 276
never@2460 277 static bool ek_supported(MethodHandles::EntryKind ek);
never@2460 278
never@2460 279 static BasicType ek_bound_mh_arg_type(EntryKind ek) {
twisti@1304 280 switch (ek) {
never@2460 281 case _bound_int_mh : // fall-thru
never@2460 282 case _bound_int_direct_mh : return T_INT;
never@2460 283 case _bound_long_mh : // fall-thru
never@2460 284 case _bound_long_direct_mh : return T_LONG;
never@2460 285 default : return T_OBJECT;
twisti@1304 286 }
twisti@1304 287 }
twisti@1304 288
never@2460 289 static int ek_adapter_opt_swap_slots(EntryKind ek) {
twisti@1304 290 switch (ek) {
never@2460 291 case _adapter_opt_swap_1 : return 1;
never@2460 292 case _adapter_opt_swap_2 : return 2;
never@2460 293 case _adapter_opt_rot_1_up : return 1;
never@2460 294 case _adapter_opt_rot_1_down : return 1;
never@2460 295 case _adapter_opt_rot_2_up : return 2;
never@2460 296 case _adapter_opt_rot_2_down : return 2;
never@2460 297 default : ShouldNotReachHere(); return -1;
never@2460 298 }
never@2460 299 }
never@2460 300
never@2460 301 static int ek_adapter_opt_swap_mode(EntryKind ek) {
never@2460 302 switch (ek) {
never@2460 303 case _adapter_opt_swap_1 : return 0;
never@2460 304 case _adapter_opt_swap_2 : return 0;
never@2460 305 case _adapter_opt_rot_1_up : return 1;
never@2460 306 case _adapter_opt_rot_1_down : return -1;
never@2460 307 case _adapter_opt_rot_2_up : return 1;
never@2460 308 case _adapter_opt_rot_2_down : return -1;
never@2460 309 default : ShouldNotReachHere(); return 0;
never@2460 310 }
never@2460 311 }
never@2460 312
never@2460 313 static int ek_adapter_opt_collect_count(EntryKind ek) {
never@2460 314 assert(ek >= _adapter_opt_collect_FIRST && ek <= _adapter_opt_collect_LAST ||
never@2460 315 ek >= _adapter_opt_fold_FIRST && ek <= _adapter_opt_fold_LAST, "");
never@2460 316 switch (ek) {
never@2460 317 case _adapter_opt_collect_0_ref : return 0;
never@2460 318 case _adapter_opt_filter_S0_ref :
never@2460 319 case _adapter_opt_filter_S1_ref :
never@2460 320 case _adapter_opt_filter_S2_ref :
never@2460 321 case _adapter_opt_filter_S3_ref :
never@2460 322 case _adapter_opt_filter_S4_ref :
never@2460 323 case _adapter_opt_filter_S5_ref :
never@2460 324 case _adapter_opt_fold_1_ref :
never@2460 325 case _adapter_opt_collect_1_ref : return 1;
never@2460 326 case _adapter_opt_collect_2_S0_ref :
never@2460 327 case _adapter_opt_collect_2_S1_ref :
never@2460 328 case _adapter_opt_collect_2_S2_ref :
never@2460 329 case _adapter_opt_collect_2_S3_ref :
never@2460 330 case _adapter_opt_collect_2_S4_ref :
never@2460 331 case _adapter_opt_collect_2_S5_ref :
never@2460 332 case _adapter_opt_fold_2_ref :
never@2460 333 case _adapter_opt_collect_2_ref : return 2;
never@2460 334 case _adapter_opt_fold_3_ref :
never@2460 335 case _adapter_opt_collect_3_ref : return 3;
never@2460 336 case _adapter_opt_fold_4_ref :
never@2460 337 case _adapter_opt_collect_4_ref : return 4;
never@2460 338 case _adapter_opt_fold_5_ref :
never@2460 339 case _adapter_opt_collect_5_ref : return 5;
never@2460 340 default : return -1; // sentinel value for "variable"
never@2460 341 }
never@2460 342 }
never@2460 343
never@2460 344 static int ek_adapter_opt_collect_slot(EntryKind ek) {
never@2460 345 assert(ek >= _adapter_opt_collect_FIRST && ek <= _adapter_opt_collect_LAST ||
never@2460 346 ek >= _adapter_opt_fold_FIRST && ek <= _adapter_opt_fold_LAST, "");
never@2460 347 switch (ek) {
never@2460 348 case _adapter_opt_collect_2_S0_ref :
never@2460 349 case _adapter_opt_filter_S0_ref : return 0;
never@2460 350 case _adapter_opt_collect_2_S1_ref :
never@2460 351 case _adapter_opt_filter_S1_ref : return 1;
never@2460 352 case _adapter_opt_collect_2_S2_ref :
never@2460 353 case _adapter_opt_filter_S2_ref : return 2;
never@2460 354 case _adapter_opt_collect_2_S3_ref :
never@2460 355 case _adapter_opt_filter_S3_ref : return 3;
never@2460 356 case _adapter_opt_collect_2_S4_ref :
never@2460 357 case _adapter_opt_filter_S4_ref : return 4;
never@2460 358 case _adapter_opt_collect_2_S5_ref :
never@2460 359 case _adapter_opt_filter_S5_ref : return 5;
never@2460 360 default : return -1; // sentinel value for "variable"
never@2460 361 }
never@2460 362 }
never@2460 363
never@2460 364 static BasicType ek_adapter_opt_collect_type(EntryKind ek) {
never@2460 365 assert(ek >= _adapter_opt_collect_FIRST && ek <= _adapter_opt_collect_LAST ||
never@2460 366 ek >= _adapter_opt_fold_FIRST && ek <= _adapter_opt_fold_LAST, "");
never@2460 367 switch (ek) {
never@2460 368 case _adapter_opt_fold_int :
never@2460 369 case _adapter_opt_collect_int : return T_INT;
never@2460 370 case _adapter_opt_fold_long :
never@2460 371 case _adapter_opt_collect_long : return T_LONG;
never@2460 372 case _adapter_opt_fold_float :
never@2460 373 case _adapter_opt_collect_float : return T_FLOAT;
never@2460 374 case _adapter_opt_fold_double :
never@2460 375 case _adapter_opt_collect_double : return T_DOUBLE;
never@2460 376 case _adapter_opt_fold_void :
never@2460 377 case _adapter_opt_collect_void : return T_VOID;
never@2460 378 default : return T_OBJECT;
never@2460 379 }
never@2460 380 }
never@2460 381
never@2460 382 static int ek_adapter_opt_return_slot(EntryKind ek) {
never@2460 383 assert(ek >= _adapter_opt_return_FIRST && ek <= _adapter_opt_return_LAST, "");
never@2460 384 switch (ek) {
never@2460 385 case _adapter_opt_return_S0_ref : return 0;
never@2460 386 case _adapter_opt_return_S1_ref : return 1;
never@2460 387 case _adapter_opt_return_S2_ref : return 2;
never@2460 388 case _adapter_opt_return_S3_ref : return 3;
never@2460 389 case _adapter_opt_return_S4_ref : return 4;
never@2460 390 case _adapter_opt_return_S5_ref : return 5;
never@2460 391 default : return -1; // sentinel value for "variable"
never@2460 392 }
never@2460 393 }
never@2460 394
never@2460 395 static BasicType ek_adapter_opt_return_type(EntryKind ek) {
never@2460 396 assert(ek >= _adapter_opt_return_FIRST && ek <= _adapter_opt_return_LAST, "");
never@2460 397 switch (ek) {
never@2460 398 case _adapter_opt_return_int : return T_INT;
never@2460 399 case _adapter_opt_return_long : return T_LONG;
never@2460 400 case _adapter_opt_return_float : return T_FLOAT;
never@2460 401 case _adapter_opt_return_double : return T_DOUBLE;
never@2460 402 case _adapter_opt_return_void : return T_VOID;
never@2460 403 case _adapter_opt_return_any : return T_CONFLICT; // sentinel value for "variable"
never@2460 404 default : return T_OBJECT;
never@2460 405 }
never@2460 406 }
never@2460 407
never@2460 408 static int ek_adapter_opt_spread_count(EntryKind ek) {
never@2460 409 assert(ek >= _adapter_opt_spread_FIRST && ek <= _adapter_opt_spread_LAST, "");
never@2460 410 switch (ek) {
never@2460 411 case _adapter_opt_spread_0 : return 0;
never@2460 412 case _adapter_opt_spread_1_ref : return 1;
never@2460 413 case _adapter_opt_spread_2_ref : return 2;
never@2460 414 case _adapter_opt_spread_3_ref : return 3;
never@2460 415 case _adapter_opt_spread_4_ref : return 4;
never@2460 416 case _adapter_opt_spread_5_ref : return 5;
never@2460 417 default : return -1; // sentinel value for "variable"
never@2460 418 }
never@2460 419 }
never@2460 420
never@2460 421 static BasicType ek_adapter_opt_spread_type(EntryKind ek) {
never@2460 422 assert(ek >= _adapter_opt_spread_FIRST && ek <= _adapter_opt_spread_LAST, "");
never@2460 423 switch (ek) {
never@2460 424 // (there is no _adapter_opt_spread_boolean; we use byte)
never@2460 425 case _adapter_opt_spread_byte : return T_BYTE;
never@2460 426 case _adapter_opt_spread_char : return T_CHAR;
never@2460 427 case _adapter_opt_spread_short : return T_SHORT;
never@2460 428 case _adapter_opt_spread_int : return T_INT;
never@2460 429 case _adapter_opt_spread_long : return T_LONG;
never@2460 430 case _adapter_opt_spread_float : return T_FLOAT;
never@2460 431 case _adapter_opt_spread_double : return T_DOUBLE;
never@2460 432 default : return T_OBJECT;
twisti@1304 433 }
twisti@1304 434 }
twisti@1304 435
jrose@1039 436 static methodOop raise_exception_method() {
jrose@1039 437 oop rem = JNIHandles::resolve(_raise_exception_method);
jrose@1039 438 assert(rem == NULL || rem->is_method(), "");
jrose@1039 439 return (methodOop) rem;
jrose@1039 440 }
jrose@1039 441 static void set_raise_exception_method(methodOop rem) {
jrose@1039 442 assert(_raise_exception_method == NULL, "");
jrose@1039 443 _raise_exception_method = JNIHandles::make_global(Handle(rem));
jrose@1039 444 }
jrose@2506 445 static methodOop resolve_raise_exception_method(TRAPS);
jrose@2506 446 // call raise_exception_method from C code:
jrose@2506 447 static void raise_exception(int code, oop actual, oop required, TRAPS);
jrose@1039 448
jrose@710 449 static jint adapter_conversion(int conv_op, BasicType src, BasicType dest,
jrose@710 450 int stack_move = 0, int vminfo = 0) {
jrose@710 451 assert(conv_op_valid(conv_op), "oob");
jrose@710 452 jint conv = ((conv_op << CONV_OP_SHIFT)
jrose@710 453 | (src << CONV_SRC_TYPE_SHIFT)
jrose@710 454 | (dest << CONV_DEST_TYPE_SHIFT)
jrose@710 455 | (stack_move << CONV_STACK_MOVE_SHIFT)
jrose@710 456 | (vminfo << CONV_VMINFO_SHIFT)
jrose@710 457 );
jrose@710 458 assert(adapter_conversion_op(conv) == conv_op, "decode conv_op");
jrose@710 459 assert(adapter_conversion_src_type(conv) == src, "decode src");
jrose@710 460 assert(adapter_conversion_dest_type(conv) == dest, "decode dest");
jrose@710 461 assert(adapter_conversion_stack_move(conv) == stack_move, "decode stack_move");
jrose@710 462 assert(adapter_conversion_vminfo(conv) == vminfo, "decode vminfo");
jrose@710 463 return conv;
jrose@710 464 }
jrose@710 465 static int adapter_conversion_op(jint conv) {
jrose@710 466 return ((conv >> CONV_OP_SHIFT) & 0xF);
jrose@710 467 }
jrose@710 468 static BasicType adapter_conversion_src_type(jint conv) {
jrose@710 469 return (BasicType)((conv >> CONV_SRC_TYPE_SHIFT) & 0xF);
jrose@710 470 }
jrose@710 471 static BasicType adapter_conversion_dest_type(jint conv) {
jrose@710 472 return (BasicType)((conv >> CONV_DEST_TYPE_SHIFT) & 0xF);
jrose@710 473 }
jrose@710 474 static int adapter_conversion_stack_move(jint conv) {
jrose@710 475 return (conv >> CONV_STACK_MOVE_SHIFT);
jrose@710 476 }
jrose@710 477 static int adapter_conversion_vminfo(jint conv) {
jrose@710 478 return (conv >> CONV_VMINFO_SHIFT) & CONV_VMINFO_MASK;
jrose@710 479 }
jrose@710 480
jrose@1427 481 // Bit mask of conversion_op values. May vary by platform.
jrose@1427 482 static int adapter_conversion_ops_supported_mask();
jrose@1427 483
never@2460 484 static bool conv_op_supported(int conv_op) {
never@2460 485 assert(conv_op_valid(conv_op), "");
never@2460 486 return ((adapter_conversion_ops_supported_mask() & nth_bit(conv_op)) != 0);
never@2460 487 }
never@2460 488
jrose@710 489 // Offset in words that the interpreter stack pointer moves when an argument is pushed.
jrose@710 490 // The stack_move value must always be a multiple of this.
jrose@710 491 static int stack_move_unit() {
twisti@1426 492 return frame::interpreter_frame_expression_stack_direction() * Interpreter::stackElementWords;
jrose@710 493 }
jrose@710 494
never@2460 495 // Adapter frame traversal. (Implementation-specific.)
never@2460 496 static frame ricochet_frame_sender(const frame& fr, RegisterMap* reg_map);
never@2460 497 static void ricochet_frame_oops_do(const frame& fr, OopClosure* blk, const RegisterMap* reg_map);
never@2460 498
jrose@710 499 enum { CONV_VMINFO_SIGN_FLAG = 0x80 };
twisti@1769 500 // Shift values for prim-to-prim conversions.
twisti@1769 501 static int adapter_prim_to_prim_subword_vminfo(BasicType dest) {
twisti@1769 502 if (dest == T_BOOLEAN) return (BitsPerInt - 1); // boolean is 1 bit
twisti@1769 503 if (dest == T_CHAR) return (BitsPerInt - BitsPerShort);
twisti@1769 504 if (dest == T_BYTE) return (BitsPerInt - BitsPerByte ) | CONV_VMINFO_SIGN_FLAG;
twisti@1769 505 if (dest == T_SHORT) return (BitsPerInt - BitsPerShort) | CONV_VMINFO_SIGN_FLAG;
twisti@1769 506 return 0; // case T_INT
twisti@1769 507 }
twisti@1769 508 // Shift values for unboxing a primitive.
twisti@1769 509 static int adapter_unbox_subword_vminfo(BasicType dest) {
twisti@1769 510 if (dest == T_BOOLEAN) return (BitsPerInt - BitsPerByte ); // implemented as 1 byte
twisti@1769 511 if (dest == T_CHAR) return (BitsPerInt - BitsPerShort);
twisti@1769 512 if (dest == T_BYTE) return (BitsPerInt - BitsPerByte ) | CONV_VMINFO_SIGN_FLAG;
twisti@1769 513 if (dest == T_SHORT) return (BitsPerInt - BitsPerShort) | CONV_VMINFO_SIGN_FLAG;
jrose@710 514 return 0; // case T_INT
jrose@710 515 }
jrose@710 516 // Here is the transformation the i2i adapter must perform:
jrose@710 517 static int truncate_subword_from_vminfo(jint value, int vminfo) {
bdelsart@2707 518 int shift = vminfo & ~CONV_VMINFO_SIGN_FLAG;
bdelsart@2707 519 jint tem = value << shift;
jrose@710 520 if ((vminfo & CONV_VMINFO_SIGN_FLAG) != 0) {
bdelsart@2707 521 return (jint)tem >> shift;
jrose@710 522 } else {
bdelsart@2707 523 return (juint)tem >> shift;
jrose@710 524 }
jrose@710 525 }
jrose@710 526
jrose@710 527 static inline address from_compiled_entry(EntryKind ek);
jrose@710 528 static inline address from_interpreted_entry(EntryKind ek);
jrose@710 529
jrose@710 530 // helpers for decode_method.
twisti@2371 531 static methodOop decode_methodOop(methodOop m, int& decode_flags_result);
twisti@2371 532 static methodHandle decode_vmtarget(oop vmtarget, int vmindex, oop mtype, KlassHandle& receiver_limit_result, int& decode_flags_result);
twisti@2371 533 static methodHandle decode_MemberName(oop mname, KlassHandle& receiver_limit_result, int& decode_flags_result);
twisti@2371 534 static methodHandle decode_MethodHandle(oop mh, KlassHandle& receiver_limit_result, int& decode_flags_result);
twisti@2371 535 static methodHandle decode_DirectMethodHandle(oop mh, KlassHandle& receiver_limit_result, int& decode_flags_result);
twisti@2371 536 static methodHandle decode_BoundMethodHandle(oop mh, KlassHandle& receiver_limit_result, int& decode_flags_result);
twisti@2371 537 static methodHandle decode_AdapterMethodHandle(oop mh, KlassHandle& receiver_limit_result, int& decode_flags_result);
jrose@710 538
jrose@710 539 // Find out how many stack slots an mh pushes or pops.
jrose@710 540 // The result is *not* reported as a multiple of stack_move_unit();
jrose@710 541 // It is a signed net number of pushes (a difference in vmslots).
jrose@710 542 // To compare with a stack_move value, first multiply by stack_move_unit().
jrose@710 543 static int decode_MethodHandle_stack_pushes(oop mh);
jrose@710 544
jrose@710 545 public:
jrose@710 546 // working with member names
jrose@710 547 static void resolve_MemberName(Handle mname, TRAPS); // compute vmtarget/vmindex from name/type
jrose@710 548 static void expand_MemberName(Handle mname, int suppress, TRAPS); // expand defc/name/type if missing
jrose@1427 549 static Handle new_MemberName(TRAPS); // must be followed by init_MemberName
jrose@710 550 static void init_MemberName(oop mname_oop, oop target); // compute vmtarget/vmindex from target
jrose@1427 551 static void init_MemberName(oop mname_oop, methodOop m, bool do_dispatch = true);
jrose@710 552 static void init_MemberName(oop mname_oop, klassOop field_holder, AccessFlags mods, int offset);
coleenp@2062 553 static int find_MemberNames(klassOop k, Symbol* name, Symbol* sig,
jrose@710 554 int mflags, klassOop caller,
jrose@710 555 int skip, objArrayOop results);
jrose@710 556 // bit values for suppress argument to expand_MemberName:
jrose@710 557 enum { _suppress_defc = 1, _suppress_name = 2, _suppress_type = 4 };
jrose@710 558
twisti@1299 559 // Generate MethodHandles adapters.
twisti@2001 560 static void generate_adapters();
twisti@1299 561
twisti@1299 562 // Called from InterpreterGenerator and MethodHandlesAdapterGenerator.
jrose@710 563 static address generate_method_handle_interpreter_entry(MacroAssembler* _masm);
twisti@2001 564 static void generate_method_handle_stub(MacroAssembler* _masm, EntryKind ek);
jrose@710 565
jrose@710 566 // argument list parsing
jrose@710 567 static int argument_slot(oop method_type, int arg);
jrose@710 568 static int argument_slot_count(oop method_type) { return argument_slot(method_type, -1); }
jrose@710 569 static int argument_slot_to_argnum(oop method_type, int argslot);
jrose@710 570
jrose@710 571 // Runtime support
jrose@710 572 enum { // bit-encoded flags from decode_method or decode_vmref
jrose@710 573 _dmf_has_receiver = 0x01, // target method has leading reference argument
jrose@710 574 _dmf_does_dispatch = 0x02, // method handle performs virtual or interface dispatch
jrose@710 575 _dmf_from_interface = 0x04, // peforms interface dispatch
jrose@710 576 _DMF_DIRECT_MASK = (_dmf_from_interface*2 - _dmf_has_receiver),
jrose@710 577 _dmf_binds_method = 0x08,
jrose@710 578 _dmf_binds_argument = 0x10,
jrose@710 579 _DMF_BOUND_MASK = (_dmf_binds_argument*2 - _dmf_binds_method),
jrose@710 580 _dmf_adapter_lsb = 0x20,
jrose@710 581 _DMF_ADAPTER_MASK = (_dmf_adapter_lsb << CONV_OP_LIMIT) - _dmf_adapter_lsb
jrose@710 582 };
twisti@2371 583 static methodHandle decode_method(oop x, KlassHandle& receiver_limit_result, int& decode_flags_result);
jrose@710 584 enum {
jrose@710 585 // format of query to getConstant:
jrose@710 586 GC_JVM_PUSH_LIMIT = 0,
jrose@1039 587 GC_JVM_STACK_MOVE_UNIT = 1,
jrose@1427 588 GC_CONV_OP_IMPLEMENTED_MASK = 2,
never@2519 589 GC_OP_ROT_ARGS_DOWN_LIMIT_BIAS = 3,
never@2670 590 GC_COUNT_GWT = 4,
jrose@710 591
jrose@710 592 // format of result from getTarget / encode_target:
jrose@710 593 ETF_HANDLE_OR_METHOD_NAME = 0, // all available data (immediate MH or method)
jrose@710 594 ETF_DIRECT_HANDLE = 1, // ultimate method handle (will be a DMH, may be self)
jrose@710 595 ETF_METHOD_NAME = 2, // ultimate method as MemberName
never@2519 596 ETF_REFLECT_METHOD = 3, // ultimate method as java.lang.reflect object (sans refClass)
jrose@2547 597 ETF_FORCE_DIRECT_HANDLE = 64,
jrose@2547 598 ETF_COMPILE_DIRECT_HANDLE = 65,
never@2519 599
never@2519 600 // ad hoc constants
never@2519 601 OP_ROT_ARGS_DOWN_LIMIT_BIAS = -1
jrose@710 602 };
jrose@710 603 static int get_named_constant(int which, Handle name_box, TRAPS);
jrose@710 604 static oop encode_target(Handle mh, int format, TRAPS); // report vmtarget (to Java code)
jrose@710 605 static bool class_cast_needed(klassOop src, klassOop dst);
jrose@710 606
jrose@1427 607 static instanceKlassHandle resolve_instance_klass(oop java_mirror_oop, TRAPS);
jrose@1427 608 static instanceKlassHandle resolve_instance_klass(jclass java_mirror_jh, TRAPS) {
jrose@1427 609 return resolve_instance_klass(JNIHandles::resolve(java_mirror_jh), THREAD);
jrose@1427 610 }
jrose@1427 611
jrose@710 612 private:
jrose@710 613 // These checkers operate on a pair of whole MethodTypes:
jrose@710 614 static const char* check_method_type_change(oop src_mtype, int src_beg, int src_end,
jrose@710 615 int insert_argnum, oop insert_type,
jrose@710 616 int change_argnum, oop change_type,
jrose@710 617 int delete_argnum,
jrose@1039 618 oop dst_mtype, int dst_beg, int dst_end,
jrose@1039 619 bool raw = false);
jrose@710 620 static const char* check_method_type_insertion(oop src_mtype,
jrose@710 621 int insert_argnum, oop insert_type,
jrose@710 622 oop dst_mtype) {
jrose@710 623 oop no_ref = NULL;
jrose@710 624 return check_method_type_change(src_mtype, 0, -1,
jrose@710 625 insert_argnum, insert_type,
jrose@710 626 -1, no_ref, -1, dst_mtype, 0, -1);
jrose@710 627 }
jrose@710 628 static const char* check_method_type_conversion(oop src_mtype,
jrose@710 629 int change_argnum, oop change_type,
jrose@710 630 oop dst_mtype) {
jrose@710 631 oop no_ref = NULL;
jrose@710 632 return check_method_type_change(src_mtype, 0, -1, -1, no_ref,
jrose@710 633 change_argnum, change_type,
jrose@710 634 -1, dst_mtype, 0, -1);
jrose@710 635 }
jrose@1039 636 static const char* check_method_type_passthrough(oop src_mtype, oop dst_mtype, bool raw) {
jrose@710 637 oop no_ref = NULL;
jrose@710 638 return check_method_type_change(src_mtype, 0, -1,
jrose@710 639 -1, no_ref, -1, no_ref, -1,
jrose@1039 640 dst_mtype, 0, -1, raw);
jrose@710 641 }
jrose@710 642
jrose@710 643 // These checkers operate on pairs of argument or return types:
jrose@710 644 static const char* check_argument_type_change(BasicType src_type, klassOop src_klass,
jrose@710 645 BasicType dst_type, klassOop dst_klass,
jrose@1039 646 int argnum, bool raw = false);
jrose@710 647
jrose@710 648 static const char* check_argument_type_change(oop src_type, oop dst_type,
jrose@1039 649 int argnum, bool raw = false) {
jrose@710 650 klassOop src_klass = NULL, dst_klass = NULL;
jrose@710 651 BasicType src_bt = java_lang_Class::as_BasicType(src_type, &src_klass);
jrose@710 652 BasicType dst_bt = java_lang_Class::as_BasicType(dst_type, &dst_klass);
jrose@710 653 return check_argument_type_change(src_bt, src_klass,
jrose@1039 654 dst_bt, dst_klass, argnum, raw);
jrose@710 655 }
jrose@710 656
jrose@1039 657 static const char* check_return_type_change(oop src_type, oop dst_type, bool raw = false) {
jrose@1039 658 return check_argument_type_change(src_type, dst_type, -1, raw);
jrose@710 659 }
jrose@710 660
jrose@710 661 static const char* check_return_type_change(BasicType src_type, klassOop src_klass,
jrose@710 662 BasicType dst_type, klassOop dst_klass) {
jrose@710 663 return check_argument_type_change(src_type, src_klass, dst_type, dst_klass, -1);
jrose@710 664 }
jrose@710 665
jrose@710 666 static const char* check_method_receiver(methodOop m, klassOop passed_recv_type);
jrose@710 667
jrose@710 668 // These verifiers can block, and will throw an error if the checking fails:
jrose@710 669 static void verify_vmslots(Handle mh, TRAPS);
jrose@710 670 static void verify_vmargslot(Handle mh, int argnum, int argslot, TRAPS);
jrose@710 671
jrose@710 672 static void verify_method_type(methodHandle m, Handle mtype,
jrose@710 673 bool has_bound_oop,
jrose@710 674 KlassHandle bound_oop_type,
jrose@710 675 TRAPS);
jrose@710 676
jrose@710 677 static void verify_method_signature(methodHandle m, Handle mtype,
jrose@710 678 int first_ptype_pos,
jrose@710 679 KlassHandle insert_ptype, TRAPS);
jrose@710 680
jrose@710 681 static void verify_DirectMethodHandle(Handle mh, methodHandle m, TRAPS);
jrose@710 682 static void verify_BoundMethodHandle(Handle mh, Handle target, int argnum,
jrose@710 683 bool direct_to_method, TRAPS);
jrose@710 684 static void verify_BoundMethodHandle_with_receiver(Handle mh, methodHandle m, TRAPS);
jrose@710 685 static void verify_AdapterMethodHandle(Handle mh, int argnum, TRAPS);
jrose@710 686
jrose@710 687 public:
jrose@710 688
jrose@710 689 // Fill in the fields of a DirectMethodHandle mh. (MH.type must be pre-filled.)
jrose@710 690 static void init_DirectMethodHandle(Handle mh, methodHandle method, bool do_dispatch, TRAPS);
jrose@710 691
jrose@710 692 // Fill in the fields of a BoundMethodHandle mh. (MH.type, BMH.argument must be pre-filled.)
jrose@710 693 static void init_BoundMethodHandle(Handle mh, Handle target, int argnum, TRAPS);
jrose@710 694 static void init_BoundMethodHandle_with_receiver(Handle mh,
jrose@710 695 methodHandle original_m,
jrose@710 696 KlassHandle receiver_limit,
jrose@710 697 int decode_flags,
jrose@710 698 TRAPS);
jrose@710 699
jrose@710 700 // Fill in the fields of an AdapterMethodHandle mh. (MH.type must be pre-filled.)
jrose@710 701 static void init_AdapterMethodHandle(Handle mh, Handle target, int argnum, TRAPS);
never@2460 702 static void ensure_vmlayout_field(Handle target, TRAPS);
jrose@710 703
jrose@710 704 #ifdef ASSERT
jrose@710 705 static bool spot_check_entry_names();
jrose@710 706 #endif
jrose@710 707
jrose@710 708 private:
jrose@710 709 static methodHandle dispatch_decoded_method(methodHandle m,
jrose@710 710 KlassHandle receiver_limit,
jrose@710 711 int decode_flags,
jrose@710 712 KlassHandle receiver_klass,
jrose@710 713 TRAPS);
jrose@710 714
twisti@2468 715 public:
twisti@2468 716 static bool is_float_fixed_reinterpretation_cast(BasicType src, BasicType dst);
jrose@710 717 static bool same_basic_type_for_arguments(BasicType src, BasicType dst,
jrose@1039 718 bool raw = false,
jrose@710 719 bool for_return = false);
jrose@1039 720 static bool same_basic_type_for_returns(BasicType src, BasicType dst, bool raw = false) {
jrose@1039 721 return same_basic_type_for_arguments(src, dst, raw, true);
jrose@710 722 }
jrose@710 723
never@2460 724 static Symbol* convert_to_signature(oop type_str, bool polymorphic, TRAPS);
never@2460 725
never@2460 726 #ifdef TARGET_ARCH_x86
never@2460 727 # include "methodHandles_x86.hpp"
never@2460 728 #endif
never@2460 729 #ifdef TARGET_ARCH_sparc
never@2515 730 # include "methodHandles_sparc.hpp"
never@2460 731 #endif
never@2460 732 #ifdef TARGET_ARCH_zero
never@2515 733 # include "methodHandles_zero.hpp"
never@2460 734 #endif
never@2460 735 #ifdef TARGET_ARCH_arm
bdelsart@2482 736 # include "methodHandles_arm.hpp"
never@2460 737 #endif
never@2460 738 #ifdef TARGET_ARCH_ppc
bdelsart@2482 739 # include "methodHandles_ppc.hpp"
never@2460 740 #endif
never@2460 741
never@2460 742 #ifdef TARGET_ARCH_NYI_6939861
never@2460 743 // Here are some backward compatible declarations until the 6939861 ports are updated.
never@2460 744 #define _adapter_flyby (_EK_LIMIT + 10)
never@2460 745 #define _adapter_ricochet (_EK_LIMIT + 11)
never@2460 746 #define _adapter_opt_spread_1 _adapter_opt_spread_1_ref
never@2460 747 #define _adapter_opt_spread_more _adapter_opt_spread_ref
never@2460 748 enum {
jrose@710 749 _INSERT_NO_MASK = -1,
jrose@710 750 _INSERT_REF_MASK = 0,
jrose@710 751 _INSERT_INT_MASK = 1,
jrose@710 752 _INSERT_LONG_MASK = 3
jrose@710 753 };
never@2460 754 static void get_ek_bound_mh_info(EntryKind ek, BasicType& arg_type, int& arg_mask, int& arg_slots) {
never@2460 755 arg_type = ek_bound_mh_arg_type(ek);
never@2460 756 arg_mask = 0;
never@2460 757 arg_slots = type2size[arg_type];;
never@2460 758 }
never@2460 759 static void get_ek_adapter_opt_swap_rot_info(EntryKind ek, int& swap_bytes, int& rotate) {
never@2460 760 int swap_slots = ek_adapter_opt_swap_slots(ek);
never@2460 761 rotate = ek_adapter_opt_swap_mode(ek);
never@2460 762 swap_bytes = swap_slots * Interpreter::stackElementSize;
never@2460 763 }
never@2460 764 static int get_ek_adapter_opt_spread_info(EntryKind ek) {
never@2460 765 return ek_adapter_opt_spread_count(ek);
never@2460 766 }
never@2460 767
jrose@710 768 static void insert_arg_slots(MacroAssembler* _masm,
jrose@710 769 RegisterOrConstant arg_slots,
jrose@710 770 int arg_mask,
twisti@1304 771 Register argslot_reg,
twisti@1423 772 Register temp_reg, Register temp2_reg, Register temp3_reg = noreg);
jrose@710 773
jrose@710 774 static void remove_arg_slots(MacroAssembler* _masm,
jrose@710 775 RegisterOrConstant arg_slots,
twisti@1304 776 Register argslot_reg,
twisti@1423 777 Register temp_reg, Register temp2_reg, Register temp3_reg = noreg);
jrose@1713 778
jrose@1713 779 static void trace_method_handle(MacroAssembler* _masm, const char* adaptername) PRODUCT_RETURN;
never@2460 780 #endif //TARGET_ARCH_NYI_6939861
jrose@710 781 };
jrose@710 782
jrose@710 783
jrose@2204 784 // Access methods for the "entry" field of a java.lang.invoke.MethodHandle.
jrose@710 785 // The field is primarily a jump target for compiled calls.
jrose@710 786 // However, we squirrel away some nice pointers for other uses,
jrose@710 787 // just before the jump target.
jrose@710 788 // Aspects of a method handle entry:
jrose@710 789 // - from_compiled_entry - stub used when compiled code calls the MH
jrose@710 790 // - from_interpreted_entry - stub used when the interpreter calls the MH
jrose@710 791 // - type_checking_entry - stub for runtime casting between MHForm siblings (NYI)
jrose@710 792 class MethodHandleEntry {
jrose@710 793 public:
jrose@710 794 class Data {
jrose@710 795 friend class MethodHandleEntry;
jrose@710 796 size_t _total_size; // size including Data and code stub
jrose@710 797 MethodHandleEntry* _type_checking_entry;
jrose@710 798 address _from_interpreted_entry;
jrose@710 799 MethodHandleEntry* method_entry() { return (MethodHandleEntry*)(this + 1); }
jrose@710 800 };
jrose@710 801
jrose@710 802 Data* data() { return (Data*)this - 1; }
jrose@710 803
jrose@710 804 address start_address() { return (address) data(); }
jrose@710 805 address end_address() { return start_address() + data()->_total_size; }
jrose@710 806
jrose@710 807 address from_compiled_entry() { return (address) this; }
jrose@710 808
jrose@710 809 address from_interpreted_entry() { return data()->_from_interpreted_entry; }
jrose@710 810 void set_from_interpreted_entry(address e) { data()->_from_interpreted_entry = e; }
jrose@710 811
jrose@710 812 MethodHandleEntry* type_checking_entry() { return data()->_type_checking_entry; }
jrose@710 813 void set_type_checking_entry(MethodHandleEntry* e) { data()->_type_checking_entry = e; }
jrose@710 814
jrose@710 815 void set_end_address(address end_addr) {
jrose@710 816 size_t total_size = end_addr - start_address();
jrose@710 817 assert(total_size > 0 && total_size < 0x1000, "reasonable end address");
jrose@710 818 data()->_total_size = total_size;
jrose@710 819 }
jrose@710 820
jrose@710 821 // Compiler support:
jrose@710 822 static int from_interpreted_entry_offset_in_bytes() {
jrose@710 823 return (int)( offset_of(Data, _from_interpreted_entry) - sizeof(Data) );
jrose@710 824 }
jrose@710 825 static int type_checking_entry_offset_in_bytes() {
jrose@710 826 return (int)( offset_of(Data, _from_interpreted_entry) - sizeof(Data) );
jrose@710 827 }
jrose@710 828
jrose@710 829 static address start_compiled_entry(MacroAssembler* _masm,
jrose@710 830 address interpreted_entry = NULL);
jrose@710 831 static MethodHandleEntry* finish_compiled_entry(MacroAssembler* masm, address start_addr);
jrose@710 832 };
jrose@710 833
jrose@710 834 address MethodHandles::from_compiled_entry(EntryKind ek) { return entry(ek)->from_compiled_entry(); }
jrose@710 835 address MethodHandles::from_interpreted_entry(EntryKind ek) { return entry(ek)->from_interpreted_entry(); }
twisti@1299 836
twisti@1299 837
twisti@1299 838 //------------------------------------------------------------------------------
twisti@1299 839 // MethodHandlesAdapterGenerator
twisti@1299 840 //
twisti@1299 841 class MethodHandlesAdapterGenerator : public StubCodeGenerator {
twisti@1299 842 public:
never@2519 843 MethodHandlesAdapterGenerator(CodeBuffer* code) : StubCodeGenerator(code, PrintMethodHandleStubs) {}
twisti@1299 844
twisti@2001 845 void generate();
twisti@1299 846 };
stefank@1879 847
stefank@1879 848 #endif // SHARE_VM_PRIMS_METHODHANDLES_HPP