src/cpu/sparc/vm/methodHandles_sparc.cpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #include "precompiled.hpp"
aoqi@0 26 #include "asm/macroAssembler.hpp"
aoqi@0 27 #include "interpreter/interpreter.hpp"
aoqi@0 28 #include "memory/allocation.inline.hpp"
aoqi@0 29 #include "prims/methodHandles.hpp"
aoqi@0 30
aoqi@0 31 #define __ _masm->
aoqi@0 32
aoqi@0 33 #ifdef PRODUCT
aoqi@0 34 #define BLOCK_COMMENT(str) /* nothing */
aoqi@0 35 #define STOP(error) stop(error)
aoqi@0 36 #else
aoqi@0 37 #define BLOCK_COMMENT(str) __ block_comment(str)
aoqi@0 38 #define STOP(error) block_comment(error); __ stop(error)
aoqi@0 39 #endif
aoqi@0 40
aoqi@0 41 #define BIND(label) bind(label); BLOCK_COMMENT(#label ":")
aoqi@0 42
aoqi@0 43 // Workaround for C++ overloading nastiness on '0' for RegisterOrConstant.
aoqi@0 44 static RegisterOrConstant constant(int value) {
aoqi@0 45 return RegisterOrConstant(value);
aoqi@0 46 }
aoqi@0 47
aoqi@0 48 void MethodHandles::load_klass_from_Class(MacroAssembler* _masm, Register klass_reg, Register temp_reg, Register temp2_reg) {
aoqi@0 49 if (VerifyMethodHandles)
aoqi@0 50 verify_klass(_masm, klass_reg, SystemDictionary::WK_KLASS_ENUM_NAME(java_lang_Class), temp_reg, temp2_reg,
aoqi@0 51 "MH argument is a Class");
aoqi@0 52 __ ld_ptr(Address(klass_reg, java_lang_Class::klass_offset_in_bytes()), klass_reg);
aoqi@0 53 }
aoqi@0 54
aoqi@0 55 #ifdef ASSERT
aoqi@0 56 static int check_nonzero(const char* xname, int x) {
aoqi@0 57 assert(x != 0, err_msg("%s should be nonzero", xname));
aoqi@0 58 return x;
aoqi@0 59 }
aoqi@0 60 #define NONZERO(x) check_nonzero(#x, x)
aoqi@0 61 #else //ASSERT
aoqi@0 62 #define NONZERO(x) (x)
aoqi@0 63 #endif //ASSERT
aoqi@0 64
aoqi@0 65 #ifdef ASSERT
aoqi@0 66 void MethodHandles::verify_klass(MacroAssembler* _masm,
aoqi@0 67 Register obj_reg, SystemDictionary::WKID klass_id,
aoqi@0 68 Register temp_reg, Register temp2_reg,
aoqi@0 69 const char* error_message) {
aoqi@0 70 Klass** klass_addr = SystemDictionary::well_known_klass_addr(klass_id);
aoqi@0 71 KlassHandle klass = SystemDictionary::well_known_klass(klass_id);
aoqi@0 72 bool did_save = false;
aoqi@0 73 if (temp_reg == noreg || temp2_reg == noreg) {
aoqi@0 74 temp_reg = L1;
aoqi@0 75 temp2_reg = L2;
aoqi@0 76 __ save_frame_and_mov(0, obj_reg, L0);
aoqi@0 77 obj_reg = L0;
aoqi@0 78 did_save = true;
aoqi@0 79 }
aoqi@0 80 Label L_ok, L_bad;
aoqi@0 81 BLOCK_COMMENT("verify_klass {");
aoqi@0 82 __ verify_oop(obj_reg);
aoqi@0 83 __ br_null_short(obj_reg, Assembler::pn, L_bad);
aoqi@0 84 __ load_klass(obj_reg, temp_reg);
aoqi@0 85 __ set(ExternalAddress((Metadata**)klass_addr), temp2_reg);
aoqi@0 86 __ ld_ptr(Address(temp2_reg, 0), temp2_reg);
aoqi@0 87 __ cmp_and_brx_short(temp_reg, temp2_reg, Assembler::equal, Assembler::pt, L_ok);
aoqi@0 88 intptr_t super_check_offset = klass->super_check_offset();
aoqi@0 89 __ ld_ptr(Address(temp_reg, super_check_offset), temp_reg);
aoqi@0 90 __ set(ExternalAddress((Metadata**)klass_addr), temp2_reg);
aoqi@0 91 __ ld_ptr(Address(temp2_reg, 0), temp2_reg);
aoqi@0 92 __ cmp_and_brx_short(temp_reg, temp2_reg, Assembler::equal, Assembler::pt, L_ok);
aoqi@0 93 __ BIND(L_bad);
aoqi@0 94 if (did_save) __ restore();
aoqi@0 95 __ STOP(error_message);
aoqi@0 96 __ BIND(L_ok);
aoqi@0 97 if (did_save) __ restore();
aoqi@0 98 BLOCK_COMMENT("} verify_klass");
aoqi@0 99 }
aoqi@0 100
aoqi@0 101 void MethodHandles::verify_ref_kind(MacroAssembler* _masm, int ref_kind, Register member_reg, Register temp) {
aoqi@0 102 Label L;
aoqi@0 103 BLOCK_COMMENT("verify_ref_kind {");
aoqi@0 104 __ lduw(Address(member_reg, NONZERO(java_lang_invoke_MemberName::flags_offset_in_bytes())), temp);
aoqi@0 105 __ srl( temp, java_lang_invoke_MemberName::MN_REFERENCE_KIND_SHIFT, temp);
aoqi@0 106 __ and3(temp, java_lang_invoke_MemberName::MN_REFERENCE_KIND_MASK, temp);
aoqi@0 107 __ cmp_and_br_short(temp, ref_kind, Assembler::equal, Assembler::pt, L);
aoqi@0 108 { char* buf = NEW_C_HEAP_ARRAY(char, 100, mtInternal);
aoqi@0 109 jio_snprintf(buf, 100, "verify_ref_kind expected %x", ref_kind);
aoqi@0 110 if (ref_kind == JVM_REF_invokeVirtual ||
aoqi@0 111 ref_kind == JVM_REF_invokeSpecial)
aoqi@0 112 // could do this for all ref_kinds, but would explode assembly code size
aoqi@0 113 trace_method_handle(_masm, buf);
aoqi@0 114 __ STOP(buf);
aoqi@0 115 }
aoqi@0 116 BLOCK_COMMENT("} verify_ref_kind");
aoqi@0 117 __ bind(L);
aoqi@0 118 }
aoqi@0 119
aoqi@0 120 #endif // ASSERT
aoqi@0 121
aoqi@0 122 void MethodHandles::jump_from_method_handle(MacroAssembler* _masm, Register method, Register target, Register temp,
aoqi@0 123 bool for_compiler_entry) {
aoqi@0 124 Label L_no_such_method;
aoqi@0 125 assert(method == G5_method, "interpreter calling convention");
aoqi@0 126 assert_different_registers(method, target, temp);
aoqi@0 127
aoqi@0 128 if (!for_compiler_entry && JvmtiExport::can_post_interpreter_events()) {
aoqi@0 129 Label run_compiled_code;
aoqi@0 130 // JVMTI events, such as single-stepping, are implemented partly by avoiding running
aoqi@0 131 // compiled code in threads for which the event is enabled. Check here for
aoqi@0 132 // interp_only_mode if these events CAN be enabled.
aoqi@0 133 __ verify_thread();
aoqi@0 134 const Address interp_only(G2_thread, JavaThread::interp_only_mode_offset());
aoqi@0 135 __ ld(interp_only, temp);
aoqi@0 136 __ cmp_and_br_short(temp, 0, Assembler::zero, Assembler::pt, run_compiled_code);
aoqi@0 137 // Null method test is replicated below in compiled case,
aoqi@0 138 // it might be able to address across the verify_thread()
aoqi@0 139 __ br_null_short(G5_method, Assembler::pn, L_no_such_method);
aoqi@0 140 __ ld_ptr(G5_method, in_bytes(Method::interpreter_entry_offset()), target);
aoqi@0 141 __ jmp(target, 0);
aoqi@0 142 __ delayed()->nop();
aoqi@0 143 __ BIND(run_compiled_code);
aoqi@0 144 // Note: we could fill some delay slots here, but
aoqi@0 145 // it doesn't matter, since this is interpreter code.
aoqi@0 146 }
aoqi@0 147
aoqi@0 148 // Compiled case, either static or fall-through from runtime conditional
aoqi@0 149 __ br_null_short(G5_method, Assembler::pn, L_no_such_method);
aoqi@0 150
aoqi@0 151 const ByteSize entry_offset = for_compiler_entry ? Method::from_compiled_offset() :
aoqi@0 152 Method::from_interpreted_offset();
aoqi@0 153 __ ld_ptr(G5_method, in_bytes(entry_offset), target);
aoqi@0 154 __ jmp(target, 0);
aoqi@0 155 __ delayed()->nop();
aoqi@0 156
aoqi@0 157 __ bind(L_no_such_method);
aoqi@0 158 AddressLiteral ame(StubRoutines::throw_AbstractMethodError_entry());
aoqi@0 159 __ jump_to(ame, temp);
aoqi@0 160 __ delayed()->nop();
aoqi@0 161 }
aoqi@0 162
aoqi@0 163 void MethodHandles::jump_to_lambda_form(MacroAssembler* _masm,
aoqi@0 164 Register recv, Register method_temp,
aoqi@0 165 Register temp2, Register temp3,
aoqi@0 166 bool for_compiler_entry) {
aoqi@0 167 BLOCK_COMMENT("jump_to_lambda_form {");
aoqi@0 168 // This is the initial entry point of a lazy method handle.
aoqi@0 169 // After type checking, it picks up the invoker from the LambdaForm.
aoqi@0 170 assert_different_registers(recv, method_temp, temp2); // temp3 is only passed on
aoqi@0 171 assert(method_temp == G5_method, "required register for loading method");
aoqi@0 172
aoqi@0 173 //NOT_PRODUCT({ FlagSetting fs(TraceMethodHandles, true); trace_method_handle(_masm, "LZMH"); });
aoqi@0 174
aoqi@0 175 // Load the invoker, as MH -> MH.form -> LF.vmentry
aoqi@0 176 __ verify_oop(recv);
aoqi@0 177 __ load_heap_oop(Address(recv, NONZERO(java_lang_invoke_MethodHandle::form_offset_in_bytes())), method_temp);
aoqi@0 178 __ verify_oop(method_temp);
aoqi@0 179 __ load_heap_oop(Address(method_temp, NONZERO(java_lang_invoke_LambdaForm::vmentry_offset_in_bytes())), method_temp);
aoqi@0 180 __ verify_oop(method_temp);
aoqi@0 181 // the following assumes that a Method* is normally compressed in the vmtarget field:
aoqi@0 182 __ ld_ptr( Address(method_temp, NONZERO(java_lang_invoke_MemberName::vmtarget_offset_in_bytes())), method_temp);
aoqi@0 183
aoqi@0 184 if (VerifyMethodHandles && !for_compiler_entry) {
aoqi@0 185 // make sure recv is already on stack
aoqi@0 186 __ ld_ptr(method_temp, in_bytes(Method::const_offset()), temp2);
aoqi@0 187 __ load_sized_value(Address(temp2, ConstMethod::size_of_parameters_offset()),
aoqi@0 188 temp2,
aoqi@0 189 sizeof(u2), /*is_signed*/ false);
aoqi@0 190 // assert(sizeof(u2) == sizeof(Method::_size_of_parameters), "");
aoqi@0 191 Label L;
aoqi@0 192 __ ld_ptr(__ argument_address(temp2, temp2, -1), temp2);
aoqi@0 193 __ cmp_and_br_short(temp2, recv, Assembler::equal, Assembler::pt, L);
aoqi@0 194 __ STOP("receiver not on stack");
aoqi@0 195 __ BIND(L);
aoqi@0 196 }
aoqi@0 197
aoqi@0 198 jump_from_method_handle(_masm, method_temp, temp2, temp3, for_compiler_entry);
aoqi@0 199 BLOCK_COMMENT("} jump_to_lambda_form");
aoqi@0 200 }
aoqi@0 201
aoqi@0 202
aoqi@0 203 // Code generation
aoqi@0 204 address MethodHandles::generate_method_handle_interpreter_entry(MacroAssembler* _masm,
aoqi@0 205 vmIntrinsics::ID iid) {
aoqi@0 206 const bool not_for_compiler_entry = false; // this is the interpreter entry
aoqi@0 207 assert(is_signature_polymorphic(iid), "expected invoke iid");
aoqi@0 208 if (iid == vmIntrinsics::_invokeGeneric ||
aoqi@0 209 iid == vmIntrinsics::_compiledLambdaForm) {
aoqi@0 210 // Perhaps surprisingly, the symbolic references visible to Java are not directly used.
aoqi@0 211 // They are linked to Java-generated adapters via MethodHandleNatives.linkMethod.
aoqi@0 212 // They all allow an appendix argument.
aoqi@0 213 __ should_not_reach_here(); // empty stubs make SG sick
aoqi@0 214 return NULL;
aoqi@0 215 }
aoqi@0 216
aoqi@0 217 // I5_savedSP/O5_savedSP: sender SP (must preserve; see prepare_to_jump_from_interpreted)
aoqi@0 218 // G5_method: Method*
aoqi@0 219 // G4 (Gargs): incoming argument list (must preserve)
aoqi@0 220 // O0: used as temp to hold mh or receiver
aoqi@0 221 // O1, O4: garbage temps, blown away
aoqi@0 222 Register O1_scratch = O1;
aoqi@0 223 Register O4_param_size = O4; // size of parameters
aoqi@0 224
aoqi@0 225 // here's where control starts out:
aoqi@0 226 __ align(CodeEntryAlignment);
aoqi@0 227 address entry_point = __ pc();
aoqi@0 228
aoqi@0 229 if (VerifyMethodHandles) {
aoqi@0 230 Label L;
aoqi@0 231 BLOCK_COMMENT("verify_intrinsic_id {");
aoqi@0 232 __ ldub(Address(G5_method, Method::intrinsic_id_offset_in_bytes()), O1_scratch);
aoqi@0 233 __ cmp_and_br_short(O1_scratch, (int) iid, Assembler::equal, Assembler::pt, L);
aoqi@0 234 if (iid == vmIntrinsics::_linkToVirtual ||
aoqi@0 235 iid == vmIntrinsics::_linkToSpecial) {
aoqi@0 236 // could do this for all kinds, but would explode assembly code size
aoqi@0 237 trace_method_handle(_masm, "bad Method*::intrinsic_id");
aoqi@0 238 }
aoqi@0 239 __ STOP("bad Method*::intrinsic_id");
aoqi@0 240 __ bind(L);
aoqi@0 241 BLOCK_COMMENT("} verify_intrinsic_id");
aoqi@0 242 }
aoqi@0 243
aoqi@0 244 // First task: Find out how big the argument list is.
aoqi@0 245 Address O4_first_arg_addr;
aoqi@0 246 int ref_kind = signature_polymorphic_intrinsic_ref_kind(iid);
aoqi@0 247 assert(ref_kind != 0 || iid == vmIntrinsics::_invokeBasic, "must be _invokeBasic or a linkTo intrinsic");
aoqi@0 248 if (ref_kind == 0 || MethodHandles::ref_kind_has_receiver(ref_kind)) {
aoqi@0 249 __ ld_ptr(G5_method, in_bytes(Method::const_offset()), O4_param_size);
aoqi@0 250 __ load_sized_value(Address(O4_param_size, ConstMethod::size_of_parameters_offset()),
aoqi@0 251 O4_param_size,
aoqi@0 252 sizeof(u2), /*is_signed*/ false);
aoqi@0 253 // assert(sizeof(u2) == sizeof(Method::_size_of_parameters), "");
aoqi@0 254 O4_first_arg_addr = __ argument_address(O4_param_size, O4_param_size, -1);
aoqi@0 255 } else {
aoqi@0 256 DEBUG_ONLY(O4_param_size = noreg);
aoqi@0 257 }
aoqi@0 258
aoqi@0 259 Register O0_mh = noreg;
aoqi@0 260 if (!is_signature_polymorphic_static(iid)) {
aoqi@0 261 __ ld_ptr(O4_first_arg_addr, O0_mh = O0);
aoqi@0 262 DEBUG_ONLY(O4_param_size = noreg);
aoqi@0 263 }
aoqi@0 264
aoqi@0 265 // O4_first_arg_addr is live!
aoqi@0 266
aoqi@0 267 if (TraceMethodHandles) {
aoqi@0 268 if (O0_mh != noreg)
aoqi@0 269 __ mov(O0_mh, G3_method_handle); // make stub happy
aoqi@0 270 trace_method_handle_interpreter_entry(_masm, iid);
aoqi@0 271 }
aoqi@0 272
aoqi@0 273 if (iid == vmIntrinsics::_invokeBasic) {
aoqi@0 274 generate_method_handle_dispatch(_masm, iid, O0_mh, noreg, not_for_compiler_entry);
aoqi@0 275
aoqi@0 276 } else {
aoqi@0 277 // Adjust argument list by popping the trailing MemberName argument.
aoqi@0 278 Register O0_recv = noreg;
aoqi@0 279 if (MethodHandles::ref_kind_has_receiver(ref_kind)) {
aoqi@0 280 // Load the receiver (not the MH; the actual MemberName's receiver) up from the interpreter stack.
aoqi@0 281 __ ld_ptr(O4_first_arg_addr, O0_recv = O0);
aoqi@0 282 DEBUG_ONLY(O4_param_size = noreg);
aoqi@0 283 }
aoqi@0 284 Register G5_member = G5_method; // MemberName ptr; incoming method ptr is dead now
aoqi@0 285 __ ld_ptr(__ argument_address(constant(0)), G5_member);
aoqi@0 286 __ add(Gargs, Interpreter::stackElementSize, Gargs);
aoqi@0 287 generate_method_handle_dispatch(_masm, iid, O0_recv, G5_member, not_for_compiler_entry);
aoqi@0 288 }
aoqi@0 289
aoqi@0 290 return entry_point;
aoqi@0 291 }
aoqi@0 292
aoqi@0 293 void MethodHandles::generate_method_handle_dispatch(MacroAssembler* _masm,
aoqi@0 294 vmIntrinsics::ID iid,
aoqi@0 295 Register receiver_reg,
aoqi@0 296 Register member_reg,
aoqi@0 297 bool for_compiler_entry) {
aoqi@0 298 assert(is_signature_polymorphic(iid), "expected invoke iid");
aoqi@0 299 Register temp1 = (for_compiler_entry ? G1_scratch : O1);
aoqi@0 300 Register temp2 = (for_compiler_entry ? G3_scratch : O2);
aoqi@0 301 Register temp3 = (for_compiler_entry ? G4_scratch : O3);
aoqi@0 302 Register temp4 = (for_compiler_entry ? noreg : O4);
aoqi@0 303 if (for_compiler_entry) {
aoqi@0 304 assert(receiver_reg == (iid == vmIntrinsics::_linkToStatic ? noreg : O0), "only valid assignment");
aoqi@0 305 assert_different_registers(temp1, O0, O1, O2, O3, O4, O5);
aoqi@0 306 assert_different_registers(temp2, O0, O1, O2, O3, O4, O5);
aoqi@0 307 assert_different_registers(temp3, O0, O1, O2, O3, O4, O5);
aoqi@0 308 assert_different_registers(temp4, O0, O1, O2, O3, O4, O5);
aoqi@0 309 } else {
aoqi@0 310 assert_different_registers(temp1, temp2, temp3, temp4, O5_savedSP); // don't trash lastSP
aoqi@0 311 }
aoqi@0 312 if (receiver_reg != noreg) assert_different_registers(temp1, temp2, temp3, temp4, receiver_reg);
aoqi@0 313 if (member_reg != noreg) assert_different_registers(temp1, temp2, temp3, temp4, member_reg);
aoqi@0 314
aoqi@0 315 if (iid == vmIntrinsics::_invokeBasic) {
aoqi@0 316 // indirect through MH.form.vmentry.vmtarget
aoqi@0 317 jump_to_lambda_form(_masm, receiver_reg, G5_method, temp1, temp2, for_compiler_entry);
aoqi@0 318
aoqi@0 319 } else {
aoqi@0 320 // The method is a member invoker used by direct method handles.
aoqi@0 321 if (VerifyMethodHandles) {
aoqi@0 322 // make sure the trailing argument really is a MemberName (caller responsibility)
aoqi@0 323 verify_klass(_masm, member_reg, SystemDictionary::WK_KLASS_ENUM_NAME(MemberName_klass),
aoqi@0 324 temp1, temp2,
aoqi@0 325 "MemberName required for invokeVirtual etc.");
aoqi@0 326 }
aoqi@0 327
aoqi@0 328 Address member_clazz( member_reg, NONZERO(java_lang_invoke_MemberName::clazz_offset_in_bytes()));
aoqi@0 329 Address member_vmindex( member_reg, NONZERO(java_lang_invoke_MemberName::vmindex_offset_in_bytes()));
aoqi@0 330 Address member_vmtarget( member_reg, NONZERO(java_lang_invoke_MemberName::vmtarget_offset_in_bytes()));
aoqi@0 331
aoqi@0 332 Register temp1_recv_klass = temp1;
aoqi@0 333 if (iid != vmIntrinsics::_linkToStatic) {
aoqi@0 334 __ verify_oop(receiver_reg);
aoqi@0 335 if (iid == vmIntrinsics::_linkToSpecial) {
aoqi@0 336 // Don't actually load the klass; just null-check the receiver.
aoqi@0 337 __ null_check(receiver_reg);
aoqi@0 338 } else {
aoqi@0 339 // load receiver klass itself
aoqi@0 340 __ null_check(receiver_reg, oopDesc::klass_offset_in_bytes());
aoqi@0 341 __ load_klass(receiver_reg, temp1_recv_klass);
aoqi@0 342 __ verify_klass_ptr(temp1_recv_klass);
aoqi@0 343 }
aoqi@0 344 BLOCK_COMMENT("check_receiver {");
aoqi@0 345 // The receiver for the MemberName must be in receiver_reg.
aoqi@0 346 // Check the receiver against the MemberName.clazz
aoqi@0 347 if (VerifyMethodHandles && iid == vmIntrinsics::_linkToSpecial) {
aoqi@0 348 // Did not load it above...
aoqi@0 349 __ load_klass(receiver_reg, temp1_recv_klass);
aoqi@0 350 __ verify_klass_ptr(temp1_recv_klass);
aoqi@0 351 }
aoqi@0 352 if (VerifyMethodHandles && iid != vmIntrinsics::_linkToInterface) {
aoqi@0 353 Label L_ok;
aoqi@0 354 Register temp2_defc = temp2;
aoqi@0 355 __ load_heap_oop(member_clazz, temp2_defc);
aoqi@0 356 load_klass_from_Class(_masm, temp2_defc, temp3, temp4);
aoqi@0 357 __ verify_klass_ptr(temp2_defc);
aoqi@0 358 __ check_klass_subtype(temp1_recv_klass, temp2_defc, temp3, temp4, L_ok);
aoqi@0 359 // If we get here, the type check failed!
aoqi@0 360 __ STOP("receiver class disagrees with MemberName.clazz");
aoqi@0 361 __ bind(L_ok);
aoqi@0 362 }
aoqi@0 363 BLOCK_COMMENT("} check_receiver");
aoqi@0 364 }
aoqi@0 365 if (iid == vmIntrinsics::_linkToSpecial ||
aoqi@0 366 iid == vmIntrinsics::_linkToStatic) {
aoqi@0 367 DEBUG_ONLY(temp1_recv_klass = noreg); // these guys didn't load the recv_klass
aoqi@0 368 }
aoqi@0 369
aoqi@0 370 // Live registers at this point:
aoqi@0 371 // member_reg - MemberName that was the trailing argument
aoqi@0 372 // temp1_recv_klass - klass of stacked receiver, if needed
aoqi@0 373 // O5_savedSP - interpreter linkage (if interpreted)
aoqi@0 374 // O0..O5 - compiler arguments (if compiled)
aoqi@0 375
aoqi@0 376 Label L_incompatible_class_change_error;
aoqi@0 377 switch (iid) {
aoqi@0 378 case vmIntrinsics::_linkToSpecial:
aoqi@0 379 if (VerifyMethodHandles) {
aoqi@0 380 verify_ref_kind(_masm, JVM_REF_invokeSpecial, member_reg, temp2);
aoqi@0 381 }
aoqi@0 382 __ ld_ptr(member_vmtarget, G5_method);
aoqi@0 383 break;
aoqi@0 384
aoqi@0 385 case vmIntrinsics::_linkToStatic:
aoqi@0 386 if (VerifyMethodHandles) {
aoqi@0 387 verify_ref_kind(_masm, JVM_REF_invokeStatic, member_reg, temp2);
aoqi@0 388 }
aoqi@0 389 __ ld_ptr(member_vmtarget, G5_method);
aoqi@0 390 break;
aoqi@0 391
aoqi@0 392 case vmIntrinsics::_linkToVirtual:
aoqi@0 393 {
aoqi@0 394 // same as TemplateTable::invokevirtual,
aoqi@0 395 // minus the CP setup and profiling:
aoqi@0 396
aoqi@0 397 if (VerifyMethodHandles) {
aoqi@0 398 verify_ref_kind(_masm, JVM_REF_invokeVirtual, member_reg, temp2);
aoqi@0 399 }
aoqi@0 400
aoqi@0 401 // pick out the vtable index from the MemberName, and then we can discard it:
aoqi@0 402 Register temp2_index = temp2;
aoqi@0 403 __ ld_ptr(member_vmindex, temp2_index);
aoqi@0 404
aoqi@0 405 if (VerifyMethodHandles) {
aoqi@0 406 Label L_index_ok;
aoqi@0 407 __ cmp_and_br_short(temp2_index, (int) 0, Assembler::greaterEqual, Assembler::pn, L_index_ok);
aoqi@0 408 __ STOP("no virtual index");
aoqi@0 409 __ BIND(L_index_ok);
aoqi@0 410 }
aoqi@0 411
aoqi@0 412 // Note: The verifier invariants allow us to ignore MemberName.clazz and vmtarget
aoqi@0 413 // at this point. And VerifyMethodHandles has already checked clazz, if needed.
aoqi@0 414
aoqi@0 415 // get target Method* & entry point
aoqi@0 416 __ lookup_virtual_method(temp1_recv_klass, temp2_index, G5_method);
aoqi@0 417 break;
aoqi@0 418 }
aoqi@0 419
aoqi@0 420 case vmIntrinsics::_linkToInterface:
aoqi@0 421 {
aoqi@0 422 // same as TemplateTable::invokeinterface
aoqi@0 423 // (minus the CP setup and profiling, with different argument motion)
aoqi@0 424 if (VerifyMethodHandles) {
aoqi@0 425 verify_ref_kind(_masm, JVM_REF_invokeInterface, member_reg, temp2);
aoqi@0 426 }
aoqi@0 427
aoqi@0 428 Register temp2_intf = temp2;
aoqi@0 429 __ load_heap_oop(member_clazz, temp2_intf);
aoqi@0 430 load_klass_from_Class(_masm, temp2_intf, temp3, temp4);
aoqi@0 431 __ verify_klass_ptr(temp2_intf);
aoqi@0 432
aoqi@0 433 Register G5_index = G5_method;
aoqi@0 434 __ ld_ptr(member_vmindex, G5_index);
aoqi@0 435 if (VerifyMethodHandles) {
aoqi@0 436 Label L;
aoqi@0 437 __ cmp_and_br_short(G5_index, 0, Assembler::greaterEqual, Assembler::pt, L);
aoqi@0 438 __ STOP("invalid vtable index for MH.invokeInterface");
aoqi@0 439 __ bind(L);
aoqi@0 440 }
aoqi@0 441
aoqi@0 442 // given intf, index, and recv klass, dispatch to the implementation method
aoqi@0 443 __ lookup_interface_method(temp1_recv_klass, temp2_intf,
aoqi@0 444 // note: next two args must be the same:
aoqi@0 445 G5_index, G5_method,
aoqi@0 446 temp3, temp4,
aoqi@0 447 L_incompatible_class_change_error);
aoqi@0 448 break;
aoqi@0 449 }
aoqi@0 450
aoqi@0 451 default:
aoqi@0 452 fatal(err_msg_res("unexpected intrinsic %d: %s", iid, vmIntrinsics::name_at(iid)));
aoqi@0 453 break;
aoqi@0 454 }
aoqi@0 455
aoqi@0 456 // Live at this point:
aoqi@0 457 // G5_method
aoqi@0 458 // O5_savedSP (if interpreted)
aoqi@0 459
aoqi@0 460 // After figuring out which concrete method to call, jump into it.
aoqi@0 461 // Note that this works in the interpreter with no data motion.
aoqi@0 462 // But the compiled version will require that rcx_recv be shifted out.
aoqi@0 463 __ verify_method_ptr(G5_method);
aoqi@0 464 jump_from_method_handle(_masm, G5_method, temp1, temp2, for_compiler_entry);
aoqi@0 465
aoqi@0 466 if (iid == vmIntrinsics::_linkToInterface) {
aoqi@0 467 __ BIND(L_incompatible_class_change_error);
aoqi@0 468 AddressLiteral icce(StubRoutines::throw_IncompatibleClassChangeError_entry());
aoqi@0 469 __ jump_to(icce, temp1);
aoqi@0 470 __ delayed()->nop();
aoqi@0 471 }
aoqi@0 472 }
aoqi@0 473 }
aoqi@0 474
aoqi@0 475 #ifndef PRODUCT
aoqi@0 476 void trace_method_handle_stub(const char* adaptername,
aoqi@0 477 oopDesc* mh,
aoqi@0 478 intptr_t* saved_sp,
aoqi@0 479 intptr_t* args,
aoqi@0 480 intptr_t* tracing_fp) {
aoqi@0 481 bool has_mh = (strstr(adaptername, "/static") == NULL &&
aoqi@0 482 strstr(adaptername, "linkTo") == NULL); // static linkers don't have MH
aoqi@0 483 const char* mh_reg_name = has_mh ? "G3_mh" : "G3";
aoqi@0 484 tty->print_cr("MH %s %s="INTPTR_FORMAT " saved_sp=" INTPTR_FORMAT " args=" INTPTR_FORMAT,
aoqi@0 485 adaptername, mh_reg_name,
aoqi@0 486 (intptr_t) mh, saved_sp, args);
aoqi@0 487
aoqi@0 488 if (Verbose) {
aoqi@0 489 // dumping last frame with frame::describe
aoqi@0 490
aoqi@0 491 JavaThread* p = JavaThread::active();
aoqi@0 492
aoqi@0 493 ResourceMark rm;
aoqi@0 494 PRESERVE_EXCEPTION_MARK; // may not be needed by safer and unexpensive here
aoqi@0 495 FrameValues values;
aoqi@0 496
aoqi@0 497 // Note: We want to allow trace_method_handle from any call site.
aoqi@0 498 // While trace_method_handle creates a frame, it may be entered
aoqi@0 499 // without a valid return PC in O7 (e.g. not just after a call).
aoqi@0 500 // Walking that frame could lead to failures due to that invalid PC.
aoqi@0 501 // => carefully detect that frame when doing the stack walking
aoqi@0 502
aoqi@0 503 // walk up to the right frame using the "tracing_fp" argument
aoqi@0 504 intptr_t* cur_sp = StubRoutines::Sparc::flush_callers_register_windows_func()();
aoqi@0 505 frame cur_frame(cur_sp, frame::unpatchable, NULL);
aoqi@0 506
aoqi@0 507 while (cur_frame.fp() != (intptr_t *)(STACK_BIAS+(uintptr_t)tracing_fp)) {
aoqi@0 508 cur_frame = os::get_sender_for_C_frame(&cur_frame);
aoqi@0 509 }
aoqi@0 510
aoqi@0 511 // safely create a frame and call frame::describe
aoqi@0 512 intptr_t *dump_sp = cur_frame.sender_sp();
aoqi@0 513 intptr_t *dump_fp = cur_frame.link();
aoqi@0 514
aoqi@0 515 bool walkable = has_mh; // whether the traced frame shoud be walkable
aoqi@0 516
aoqi@0 517 // the sender for cur_frame is the caller of trace_method_handle
aoqi@0 518 if (walkable) {
aoqi@0 519 // The previous definition of walkable may have to be refined
aoqi@0 520 // if new call sites cause the next frame constructor to start
aoqi@0 521 // failing. Alternatively, frame constructors could be
aoqi@0 522 // modified to support the current or future non walkable
aoqi@0 523 // frames (but this is more intrusive and is not considered as
aoqi@0 524 // part of this RFE, which will instead use a simpler output).
aoqi@0 525 frame dump_frame = frame(dump_sp,
aoqi@0 526 cur_frame.sp(), // younger_sp
aoqi@0 527 false); // no adaptation
aoqi@0 528 dump_frame.describe(values, 1);
aoqi@0 529 } else {
aoqi@0 530 // Robust dump for frames which cannot be constructed from sp/younger_sp
aoqi@0 531 // Add descriptions without building a Java frame to avoid issues
aoqi@0 532 values.describe(-1, dump_fp, "fp for #1 <not parsed, cannot trust pc>");
aoqi@0 533 values.describe(-1, dump_sp, "sp");
aoqi@0 534 }
aoqi@0 535
aoqi@0 536 bool has_args = has_mh; // whether Gargs is meaningful
aoqi@0 537
aoqi@0 538 // mark args, if seems valid (may not be valid for some adapters)
aoqi@0 539 if (has_args) {
aoqi@0 540 if ((args >= dump_sp) && (args < dump_fp)) {
aoqi@0 541 values.describe(-1, args, "*G4_args");
aoqi@0 542 }
aoqi@0 543 }
aoqi@0 544
aoqi@0 545 // mark saved_sp, if seems valid (may not be valid for some adapters)
aoqi@0 546 intptr_t *unbiased_sp = (intptr_t *)(STACK_BIAS+(uintptr_t)saved_sp);
aoqi@0 547 const int ARG_LIMIT = 255, SLOP = 45, UNREASONABLE_STACK_MOVE = (ARG_LIMIT + SLOP);
aoqi@0 548 if ((unbiased_sp >= dump_sp - UNREASONABLE_STACK_MOVE) && (unbiased_sp < dump_fp)) {
aoqi@0 549 values.describe(-1, unbiased_sp, "*saved_sp+STACK_BIAS");
aoqi@0 550 }
aoqi@0 551
aoqi@0 552 // Note: the unextended_sp may not be correct
aoqi@0 553 tty->print_cr(" stack layout:");
aoqi@0 554 values.print(p);
aoqi@0 555 if (has_mh && mh->is_oop()) {
aoqi@0 556 mh->print();
aoqi@0 557 if (java_lang_invoke_MethodHandle::is_instance(mh)) {
aoqi@0 558 if (java_lang_invoke_MethodHandle::form_offset_in_bytes() != 0)
aoqi@0 559 java_lang_invoke_MethodHandle::form(mh)->print();
aoqi@0 560 }
aoqi@0 561 }
aoqi@0 562 }
aoqi@0 563 }
aoqi@0 564
aoqi@0 565 void MethodHandles::trace_method_handle(MacroAssembler* _masm, const char* adaptername) {
aoqi@0 566 if (!TraceMethodHandles) return;
aoqi@0 567 BLOCK_COMMENT("trace_method_handle {");
aoqi@0 568 // save: Gargs, O5_savedSP
aoqi@0 569 __ save_frame(16); // need space for saving required FPU state
aoqi@0 570
aoqi@0 571 __ set((intptr_t) adaptername, O0);
aoqi@0 572 __ mov(G3_method_handle, O1);
aoqi@0 573 __ mov(I5_savedSP, O2);
aoqi@0 574 __ mov(Gargs, O3);
aoqi@0 575 __ mov(I6, O4); // frame identifier for safe stack walking
aoqi@0 576
aoqi@0 577 // Save scratched registers that might be needed. Robustness is more
aoqi@0 578 // important than optimizing the saves for this debug only code.
aoqi@0 579
aoqi@0 580 // save FP result, valid at some call sites (adapter_opt_return_float, ...)
aoqi@0 581 Address d_save(FP, -sizeof(jdouble) + STACK_BIAS);
aoqi@0 582 __ stf(FloatRegisterImpl::D, Ftos_d, d_save);
aoqi@0 583 // Safely save all globals but G2 (handled by call_VM_leaf) and G7
aoqi@0 584 // (OS reserved).
aoqi@0 585 __ mov(G3_method_handle, L3);
aoqi@0 586 __ mov(Gargs, L4);
aoqi@0 587 __ mov(G5_method_type, L5);
aoqi@0 588 __ mov(G6, L6);
aoqi@0 589 __ mov(G1, L1);
aoqi@0 590
aoqi@0 591 __ call_VM_leaf(L2 /* for G2 */, CAST_FROM_FN_PTR(address, trace_method_handle_stub));
aoqi@0 592
aoqi@0 593 __ mov(L3, G3_method_handle);
aoqi@0 594 __ mov(L4, Gargs);
aoqi@0 595 __ mov(L5, G5_method_type);
aoqi@0 596 __ mov(L6, G6);
aoqi@0 597 __ mov(L1, G1);
aoqi@0 598 __ ldf(FloatRegisterImpl::D, d_save, Ftos_d);
aoqi@0 599
aoqi@0 600 __ restore();
aoqi@0 601 BLOCK_COMMENT("} trace_method_handle");
aoqi@0 602 }
aoqi@0 603 #endif // PRODUCT

mercurial