jdk

Форк
0
/
methodHandles_arm.cpp 
581 строка · 23.1 Кб
1
/*
2
 * Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
 *
5
 * This code is free software; you can redistribute it and/or modify it
6
 * under the terms of the GNU General Public License version 2 only, as
7
 * published by the Free Software Foundation.
8
 *
9
 * This code is distributed in the hope that it will be useful, but WITHOUT
10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12
 * version 2 for more details (a copy is included in the LICENSE file that
13
 * accompanied this code).
14
 *
15
 * You should have received a copy of the GNU General Public License version
16
 * 2 along with this work; if not, write to the Free Software Foundation,
17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
 *
19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
 * or visit www.oracle.com if you need additional information or have any
21
 * questions.
22
 *
23
 */
24

25
// This file mirror as much as possible methodHandles_x86.cpp to ease
26
// cross platform development for JSR292.
27
// Last synchronization: changeset f8c9417e3571
28

29
#include "precompiled.hpp"
30
#include "classfile/javaClasses.inline.hpp"
31
#include "classfile/vmClasses.hpp"
32
#include "interpreter/interpreter.hpp"
33
#include "interpreter/interpreterRuntime.hpp"
34
#include "jvm.h"
35
#include "logging/log.hpp"
36
#include "logging/logStream.hpp"
37
#include "memory/allocation.inline.hpp"
38
#include "memory/resourceArea.hpp"
39
#include "prims/jvmtiExport.hpp"
40
#include "prims/methodHandles.hpp"
41
#include "runtime/frame.inline.hpp"
42
#include "runtime/stubRoutines.hpp"
43
#include "utilities/preserveException.hpp"
44

45
#define __ _masm->
46

47
#ifdef PRODUCT
48
#define BLOCK_COMMENT(str) /* nothing */
49
#else
50
#define BLOCK_COMMENT(str) __ block_comment(str)
51
#endif
52

53
#define BIND(label) bind(label); BLOCK_COMMENT(#label ":")
54

55
void MethodHandles::load_klass_from_Class(MacroAssembler* _masm, Register klass_reg, Register temp1, Register temp2) {
56
  if (VerifyMethodHandles) {
57
    verify_klass(_masm, klass_reg, temp1, temp2, VM_CLASS_ID(java_lang_Class),
58
                 "MH argument is a Class");
59
  }
60
  __ ldr(klass_reg, Address(klass_reg, java_lang_Class::klass_offset()));
61
}
62

63
#ifdef ASSERT
64
static int check_nonzero(const char* xname, int x) {
65
  assert(x != 0, "%s should be nonzero", xname);
66
  return x;
67
}
68
#define NONZERO(x) check_nonzero(#x, x)
69
#else //ASSERT
70
#define NONZERO(x) (x)
71
#endif //ASSERT
72

73
#ifdef ASSERT
74
void MethodHandles::verify_klass(MacroAssembler* _masm,
75
                                 Register obj, Register temp1, Register temp2, vmClassID klass_id,
76
                                 const char* error_message) {
77
  InstanceKlass** klass_addr = vmClasses::klass_addr_at(klass_id);
78
  Klass* klass = vmClasses::klass_at(klass_id);
79
  Label L_ok, L_bad;
80
  BLOCK_COMMENT("verify_klass {");
81
  __ verify_oop(obj);
82
  __ cbz(obj, L_bad);
83
  __ load_klass(temp1, obj);
84
  __ lea(temp2, ExternalAddress((address) klass_addr));
85
  __ ldr(temp2, temp2); // the cmpptr on x86 dereferences the AddressLiteral (not lea)
86
  __ cmp(temp1, temp2);
87
  __ b(L_ok, eq);
88
  intptr_t super_check_offset = klass->super_check_offset();
89
  __ ldr(temp1, Address(temp1, super_check_offset));
90
  __ cmp(temp1, temp2);
91
  __ b(L_ok, eq);
92

93
  __ bind(L_bad);
94
  __ stop(error_message);
95
  __ BIND(L_ok);
96
  BLOCK_COMMENT("} verify_klass");
97
}
98

99
void MethodHandles::verify_ref_kind(MacroAssembler* _masm, int ref_kind, Register member_reg, Register temp) {
100
  Label L;
101
  BLOCK_COMMENT("verify_ref_kind {");
102
  __ ldr_u32(temp, Address(member_reg, NONZERO(java_lang_invoke_MemberName::flags_offset())));
103
  __ logical_shift_right(temp, temp, java_lang_invoke_MemberName::MN_REFERENCE_KIND_SHIFT);
104
  __ andr(temp, temp, (unsigned)java_lang_invoke_MemberName::MN_REFERENCE_KIND_MASK);
105
  __ cmp(temp, ref_kind);
106
  __ b(L, eq);
107
  { char* buf = NEW_C_HEAP_ARRAY(char, 100, mtInternal);
108
  jio_snprintf(buf, 100, "verify_ref_kind expected %x", ref_kind);
109
  if (ref_kind == JVM_REF_invokeVirtual ||
110
      ref_kind == JVM_REF_invokeSpecial)
111
    // could do this for all ref_kinds, but would explode assembly code size
112
    trace_method_handle(_masm, buf);
113
  __ stop(buf);
114
  }
115
  BLOCK_COMMENT("} verify_ref_kind");
116
  __ bind(L);
117
}
118

119
#endif //ASSERT
120

121
void MethodHandles::jump_from_method_handle(MacroAssembler* _masm, bool for_compiler_entry) {
122
  Label L_no_such_method;
123
  __ cbz(Rmethod, L_no_such_method);
124

125
  // Note: JVMTI overhead seems small enough compared to invocation
126
  // cost and is not worth the complexity or code size overhead of
127
  // supporting several variants of each adapter.
128
  if (!for_compiler_entry && (JvmtiExport::can_post_interpreter_events())) {
129
    // JVMTI events, such as single-stepping, are implemented partly by avoiding running
130
    // compiled code in threads for which the event is enabled.  Check here for
131
    // interp_only_mode if these events CAN be enabled.
132
    __ ldr_s32(Rtemp, Address(Rthread, JavaThread::interp_only_mode_offset()));
133
    __ cmp(Rtemp, 0);
134
    __ ldr(PC, Address(Rmethod, Method::interpreter_entry_offset()), ne);
135
  }
136
  const ByteSize entry_offset = for_compiler_entry ? Method::from_compiled_offset() :
137
                                                     Method::from_interpreted_offset();
138

139
  __ indirect_jump(Address(Rmethod, entry_offset), Rtemp);
140

141
  __ bind(L_no_such_method);
142
  // throw exception
143
  __ jump(StubRoutines::throw_AbstractMethodError_entry(), relocInfo::runtime_call_type, Rtemp);
144
}
145

146
void MethodHandles::jump_to_lambda_form(MacroAssembler* _masm,
147
                                        Register recv, Register tmp,
148
                                        bool for_compiler_entry) {
149
  BLOCK_COMMENT("jump_to_lambda_form {");
150
  // This is the initial entry point of a lazy method handle.
151
  // After type checking, it picks up the invoker from the LambdaForm.
152
  assert_different_registers(recv, tmp, Rmethod);
153

154
  // Load the invoker, as MH -> MH.form -> LF.vmentry
155
  __ load_heap_oop(tmp, Address(recv, NONZERO(java_lang_invoke_MethodHandle::form_offset())));
156
  __ verify_oop(tmp);
157

158
  __ load_heap_oop(tmp, Address(tmp, NONZERO(java_lang_invoke_LambdaForm::vmentry_offset())));
159
  __ verify_oop(tmp);
160

161
  __ load_heap_oop(Rmethod, Address(tmp, NONZERO(java_lang_invoke_MemberName::method_offset())));
162
  __ verify_oop(Rmethod);
163
  __ access_load_at(T_ADDRESS, IN_HEAP, Address(Rmethod, NONZERO(java_lang_invoke_ResolvedMethodName::vmtarget_offset())), Rmethod, noreg, noreg, noreg);
164

165
  if (VerifyMethodHandles && !for_compiler_entry) {
166
    // make sure recv is already on stack
167
    __ ldr(tmp, Address(Rmethod, Method::const_offset()));
168
    __ load_sized_value(tmp,
169
                        Address(tmp, ConstMethod::size_of_parameters_offset()),
170
                        sizeof(u2), /*is_signed*/ false);
171
    // assert(sizeof(u2) == sizeof(Method::_size_of_parameters), "");
172
    Label L;
173
    __ ldr(tmp, __ receiver_argument_address(Rparams, tmp, tmp));
174
    __ cmpoop(tmp, recv);
175
    __ b(L, eq);
176
    __ stop("receiver not on stack");
177
    __ bind(L);
178
  }
179

180
  jump_from_method_handle(_masm, for_compiler_entry);
181
  BLOCK_COMMENT("} jump_to_lambda_form");
182
}
183

184

185
// Code generation
186
address MethodHandles::generate_method_handle_interpreter_entry(MacroAssembler* _masm,
187
                                                                vmIntrinsics::ID iid) {
188
  const bool not_for_compiler_entry = false;  // this is the interpreter entry
189
  assert(is_signature_polymorphic(iid), "expected invoke iid");
190
  if (iid == vmIntrinsics::_invokeGeneric ||
191
      iid == vmIntrinsics::_compiledLambdaForm ||
192
      iid == vmIntrinsics::_linkToNative) {
193
    // Perhaps surprisingly, the user-visible names, and linkToCallSite, are not directly used.
194
    // They are linked to Java-generated adapters via MethodHandleNatives.linkMethod.
195
    // They all require an extra argument.
196
    __ should_not_reach_here();           // empty stubs make SG sick
197
    return nullptr;
198
  }
199

200
  // Rmethod: Method*
201
  // Rparams (SP on 32-bit ARM): pointer to parameters
202
  // Rsender_sp (R4/R19): sender SP (must preserve; see prepare_to_jump_from_interpreted)
203
  // R5_mh: receiver method handle (must load from sp[MethodTypeForm.vmslots])
204
  // R1, R2, Rtemp: garbage temp, blown away
205

206
  // Use same name as x86 to ease future merges
207
  Register rdx_temp       = R2_tmp;
208
  Register rdx_param_size = rdx_temp;  // size of parameters
209
  Register rax_temp       = R1_tmp;
210
  Register rcx_mh         = R5_mh;     // MH receiver; dies quickly and is recycled
211
  Register rbx_method     = Rmethod;   // eventual target of this invocation
212
  Register rdi_temp       = Rtemp;
213

214
  // here's where control starts out:
215
  __ align(CodeEntryAlignment);
216
  address entry_point = __ pc();
217

218
  if (VerifyMethodHandles) {
219
    Label L;
220
    BLOCK_COMMENT("verify_intrinsic_id {");
221
    __ ldrh(rdi_temp, Address(rbx_method, Method::intrinsic_id_offset()));
222
    __ sub_slow(rdi_temp, rdi_temp, (int) iid);
223
    __ cbz(rdi_temp, L);
224
    if (iid == vmIntrinsics::_linkToVirtual ||
225
        iid == vmIntrinsics::_linkToSpecial) {
226
      // could do this for all kinds, but would explode assembly code size
227
      trace_method_handle(_masm, "bad Method*::intrinsic_id");
228
    }
229
    __ stop("bad Method*::intrinsic_id");
230
    __ bind(L);
231
    BLOCK_COMMENT("} verify_intrinsic_id");
232
  }
233

234
  // First task:  Find out how big the argument list is.
235
  Address rdx_first_arg_addr;
236
  int ref_kind = signature_polymorphic_intrinsic_ref_kind(iid);
237
  assert(ref_kind != 0 || iid == vmIntrinsics::_invokeBasic, "must be _invokeBasic or a linkTo intrinsic");
238
  if (ref_kind == 0 || MethodHandles::ref_kind_has_receiver(ref_kind)) {
239
    __ ldr(rdx_param_size, Address(rbx_method, Method::const_offset()));
240
    __ load_sized_value(rdx_param_size,
241
                        Address(rdx_param_size, ConstMethod::size_of_parameters_offset()),
242
                        sizeof(u2), /*is_signed*/ false);
243
    // assert(sizeof(u2) == sizeof(Method::_size_of_parameters), "");
244
    rdx_first_arg_addr = __ receiver_argument_address(Rparams, rdx_param_size, rdi_temp);
245
  } else {
246
    DEBUG_ONLY(rdx_param_size = noreg);
247
  }
248

249
  if (!is_signature_polymorphic_static(iid)) {
250
    __ ldr(rcx_mh, rdx_first_arg_addr);
251
    DEBUG_ONLY(rdx_param_size = noreg);
252
  }
253

254
  // rdx_first_arg_addr is live!
255

256
  trace_method_handle_interpreter_entry(_masm, iid);
257

258
  if (iid == vmIntrinsics::_invokeBasic) {
259
    generate_method_handle_dispatch(_masm, iid, rcx_mh, noreg, not_for_compiler_entry);
260

261
  } else {
262
    // Adjust argument list by popping the trailing MemberName argument.
263
    Register rcx_recv = noreg;
264
    if (MethodHandles::ref_kind_has_receiver(ref_kind)) {
265
      // Load the receiver (not the MH; the actual MemberName's receiver) up from the interpreter stack.
266
      __ ldr(rcx_recv = rcx_mh, rdx_first_arg_addr);
267
      DEBUG_ONLY(rdx_param_size = noreg);
268
    }
269
    Register rbx_member = rbx_method;  // MemberName ptr; incoming method ptr is dead now
270
    __ pop(rbx_member);
271
    generate_method_handle_dispatch(_masm, iid, rcx_recv, rbx_member, not_for_compiler_entry);
272
  }
273
  return entry_point;
274
}
275

276
void MethodHandles::jump_to_native_invoker(MacroAssembler* _masm, Register nep_reg, Register temp_target) {
277
  BLOCK_COMMENT("jump_to_native_invoker {");
278
  __ stop("Should not reach here");
279
  BLOCK_COMMENT("} jump_to_native_invoker");
280
}
281

282
void MethodHandles::generate_method_handle_dispatch(MacroAssembler* _masm,
283
                                                    vmIntrinsics::ID iid,
284
                                                    Register receiver_reg,
285
                                                    Register member_reg,
286
                                                    bool for_compiler_entry) {
287
  assert(is_signature_polymorphic(iid), "expected invoke iid");
288
  // Use same name as x86 to ease future merges
289
  Register rbx_method = Rmethod;   // eventual target of this invocation
290
  // temps used in this code are not used in *either* compiled or interpreted calling sequences
291
  Register temp1 = (for_compiler_entry ? saved_last_sp_register() : R1_tmp);
292
  Register temp2 = R8;
293
  Register temp3 = Rtemp; // R12/R16
294
  Register temp4 = R5;
295
  if (for_compiler_entry) {
296
    assert(receiver_reg == (iid == vmIntrinsics::_linkToStatic ? noreg : j_rarg0), "only valid assignment");
297
    assert_different_registers(temp1, j_rarg0, j_rarg1, j_rarg2, j_rarg3);
298
    assert_different_registers(temp2, j_rarg0, j_rarg1, j_rarg2, j_rarg3);
299
    assert_different_registers(temp3, j_rarg0, j_rarg1, j_rarg2, j_rarg3);
300
    assert_different_registers(temp4, j_rarg0, j_rarg1, j_rarg2, j_rarg3);
301
  }
302
  assert_different_registers(temp1, temp2, temp3, receiver_reg);
303
  assert_different_registers(temp1, temp2, temp3, temp4, member_reg);
304
  if (!for_compiler_entry)
305
    assert_different_registers(temp1, temp2, temp3, temp4, saved_last_sp_register());  // don't trash lastSP
306

307
  if (iid == vmIntrinsics::_invokeBasic) {
308
    // indirect through MH.form.exactInvoker.vmtarget
309
    jump_to_lambda_form(_masm, receiver_reg, temp3, for_compiler_entry);
310

311
  } else if (iid == vmIntrinsics::_linkToNative) {
312
    assert(for_compiler_entry, "only compiler entry is supported");
313
    jump_to_native_invoker(_masm, member_reg, temp1);
314
  } else {
315
    // The method is a member invoker used by direct method handles.
316
    if (VerifyMethodHandles) {
317
      // make sure the trailing argument really is a MemberName (caller responsibility)
318
      verify_klass(_masm, member_reg, temp2, temp3, VM_CLASS_ID(java_lang_invoke_MemberName),
319
                   "MemberName required for invokeVirtual etc.");
320
    }
321

322
    Address member_clazz(   member_reg, NONZERO(java_lang_invoke_MemberName::clazz_offset()));
323
    Address member_vmindex( member_reg, NONZERO(java_lang_invoke_MemberName::vmindex_offset()));
324
    Address member_vmtarget(member_reg, NONZERO(java_lang_invoke_MemberName::method_offset()));
325
    Address vmtarget_method(Rmethod, NONZERO(java_lang_invoke_ResolvedMethodName::vmtarget_offset()));
326

327
    Register temp1_recv_klass = temp1;
328
    if (iid != vmIntrinsics::_linkToStatic) {
329
      if (iid == vmIntrinsics::_linkToSpecial) {
330
        // Don't actually load the klass; just null-check the receiver.
331
        __ null_check(receiver_reg, temp3);
332
      } else {
333
        // load receiver klass itself
334
        __ load_klass(temp1_recv_klass, receiver_reg);
335
        __ verify_klass_ptr(temp1_recv_klass);
336
      }
337
      BLOCK_COMMENT("check_receiver {");
338
      // The receiver for the MemberName must be in receiver_reg.
339
      // Check the receiver against the MemberName.clazz
340
      if (VerifyMethodHandles && iid == vmIntrinsics::_linkToSpecial) {
341
        // Did not load it above...
342
        __ load_klass(temp1_recv_klass, receiver_reg);
343
        __ verify_klass_ptr(temp1_recv_klass);
344
      }
345
      // Check the receiver against the MemberName.clazz
346
      if (VerifyMethodHandles && iid != vmIntrinsics::_linkToInterface) {
347
        Label L_ok;
348
        Register temp2_defc = temp2;
349
        __ load_heap_oop(temp2_defc, member_clazz);
350
        load_klass_from_Class(_masm, temp2_defc, temp3, temp4);
351
        __ verify_klass_ptr(temp2_defc);
352
        __ check_klass_subtype(temp1_recv_klass, temp2_defc, temp3, temp4, noreg, L_ok);
353
        // If we get here, the type check failed!
354
        __ stop("receiver class disagrees with MemberName.clazz");
355
        __ bind(L_ok);
356
      }
357
      BLOCK_COMMENT("} check_receiver");
358
    }
359
    if (iid == vmIntrinsics::_linkToSpecial ||
360
        iid == vmIntrinsics::_linkToStatic) {
361
      DEBUG_ONLY(temp1_recv_klass = noreg);  // these guys didn't load the recv_klass
362
    }
363

364
    // Live registers at this point:
365
    //  member_reg - MemberName that was the extra argument
366
    //  temp1_recv_klass - klass of stacked receiver, if needed
367

368
    Label L_incompatible_class_change_error;
369
    switch (iid) {
370
    case vmIntrinsics::_linkToSpecial:
371
      if (VerifyMethodHandles) {
372
        verify_ref_kind(_masm, JVM_REF_invokeSpecial, member_reg, temp3);
373
      }
374
      __ load_heap_oop(Rmethod, member_vmtarget);
375
      __ access_load_at(T_ADDRESS, IN_HEAP, vmtarget_method, Rmethod, noreg, noreg, noreg);
376
      break;
377

378
    case vmIntrinsics::_linkToStatic:
379
      if (VerifyMethodHandles) {
380
        verify_ref_kind(_masm, JVM_REF_invokeStatic, member_reg, temp3);
381
      }
382
      __ load_heap_oop(Rmethod, member_vmtarget);
383
      __ access_load_at(T_ADDRESS, IN_HEAP, vmtarget_method, Rmethod, noreg, noreg, noreg);
384
      break;
385
      break;
386

387
    case vmIntrinsics::_linkToVirtual:
388
    {
389
      // same as TemplateTable::invokevirtual,
390
      // minus the CP setup and profiling:
391

392
      if (VerifyMethodHandles) {
393
        verify_ref_kind(_masm, JVM_REF_invokeVirtual, member_reg, temp3);
394
      }
395

396
      // pick out the vtable index from the MemberName, and then we can discard it:
397
      Register temp2_index = temp2;
398
      __ access_load_at(T_ADDRESS, IN_HEAP, member_vmindex, temp2_index, noreg, noreg, noreg);
399

400
      if (VerifyMethodHandles) {
401
        Label L_index_ok;
402
        __ cmp(temp2_index, 0);
403
        __ b(L_index_ok, ge);
404
        __ stop("no virtual index");
405
        __ bind(L_index_ok);
406
      }
407

408
      // Note:  The verifier invariants allow us to ignore MemberName.clazz and vmtarget
409
      // at this point.  And VerifyMethodHandles has already checked clazz, if needed.
410

411
      // get target Method* & entry point
412
      __ lookup_virtual_method(temp1_recv_klass, temp2_index, Rmethod);
413
      break;
414
    }
415

416
    case vmIntrinsics::_linkToInterface:
417
    {
418
      // same as TemplateTable::invokeinterface
419
      // (minus the CP setup and profiling, with different argument motion)
420
      if (VerifyMethodHandles) {
421
        verify_ref_kind(_masm, JVM_REF_invokeInterface, member_reg, temp3);
422
      }
423

424
      Register temp3_intf = temp3;
425
      __ load_heap_oop(temp3_intf, member_clazz);
426
      load_klass_from_Class(_masm, temp3_intf, temp2, temp4);
427
      __ verify_klass_ptr(temp3_intf);
428

429
      Register rbx_index = rbx_method;
430
      __ access_load_at(T_ADDRESS, IN_HEAP, member_vmindex, rbx_index, noreg, noreg, noreg);
431
      if (VerifyMethodHandles) {
432
        Label L;
433
        __ cmp(rbx_index, 0);
434
        __ b(L, ge);
435
        __ stop("invalid vtable index for MH.invokeInterface");
436
        __ bind(L);
437
      }
438

439
      // given intf, index, and recv klass, dispatch to the implementation method
440
      __ lookup_interface_method(temp1_recv_klass, temp3_intf,
441
                                 // note: next two args must be the same:
442
                                 rbx_index, rbx_method,
443
                                 temp2, temp4,
444
                                 L_incompatible_class_change_error);
445
      break;
446
    }
447

448
    default:
449
      fatal("unexpected intrinsic %d: %s", vmIntrinsics::as_int(iid), vmIntrinsics::name_at(iid));
450
      break;
451
    }
452

453
    // Live at this point:
454
    //   Rmethod (target method)
455
    //   Rsender_sp, Rparams (if interpreted)
456
    //   register arguments (if compiled)
457

458
    // After figuring out which concrete method to call, jump into it.
459
    __ verify_method_ptr(Rmethod);
460
    jump_from_method_handle(_masm, for_compiler_entry);
461

462
    if (iid == vmIntrinsics::_linkToInterface) {
463
      __ bind(L_incompatible_class_change_error);
464
      __ jump(StubRoutines::throw_IncompatibleClassChangeError_entry(), relocInfo::runtime_call_type, Rtemp);
465
    }
466
  }
467
}
468

469

470
#ifndef PRODUCT
471
enum {
472
  ARG_LIMIT = 255, SLOP = 4,
473
  // use this parameter for checking for garbage stack movements:
474
  UNREASONABLE_STACK_MOVE = (ARG_LIMIT + SLOP)
475
  // the slop defends against false alarms due to fencepost errors
476
};
477

478
const int trace_mh_nregs = 15;
479
const Register trace_mh_regs[trace_mh_nregs] =
480
  {R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, LR, PC};
481

482
void trace_method_handle_stub(const char* adaptername,
483
                              intptr_t* saved_regs,
484
                              intptr_t* saved_bp,
485
                              oop mh) {
486
  // called as a leaf from native code: do not block the JVM!
487
  bool has_mh = (strstr(adaptername, "/static") == nullptr &&
488
                 strstr(adaptername, "linkTo") == nullptr);    // static linkers don't have MH
489
  intptr_t* entry_sp = (intptr_t*) &saved_regs[trace_mh_nregs]; // just after the saved regs
490
  intptr_t* saved_sp = (intptr_t*)  saved_regs[Rsender_sp->encoding()]; // save of Rsender_sp
491
  intptr_t* last_sp  = (intptr_t*)  saved_bp[frame::interpreter_frame_last_sp_offset];
492
  intptr_t* base_sp  = last_sp;
493

494
  intptr_t    mh_reg = (intptr_t)saved_regs[R5_mh->encoding()];
495
  const char* mh_reg_name = "R5_mh";
496
  if (!has_mh) {
497
    mh_reg_name = "R5";
498
  }
499
  log_info(methodhandles)("MH %s %s=" PTR_FORMAT " sp=(" PTR_FORMAT "+" INTX_FORMAT ") stack_size=" INTX_FORMAT " bp=" PTR_FORMAT,
500
                          adaptername, mh_reg_name, mh_reg,
501
                          (intptr_t)entry_sp, (intptr_t)saved_sp - (intptr_t)entry_sp, (intptr_t)(base_sp - last_sp), (intptr_t)saved_bp);
502

503
  if (last_sp != saved_sp && last_sp != nullptr) {
504
    log_info(methodhandles)("*** last_sp=" INTPTR_FORMAT, p2i(last_sp));
505
  }
506
  LogTarget(Trace, methodhandles) lt;
507
  if (lt.is_enabled()) {
508
    ResourceMark rm;
509
    LogStream ls(lt);
510
    ls.print(" reg dump: ");
511
    int i;
512
    for (i = 0; i < trace_mh_nregs; i++) {
513
      if (i > 0 && i % 4 == 0)
514
        ls.print("\n   + dump: ");
515
      const char* reg_name = trace_mh_regs[i]->name();
516
      ls.print(" %s: " INTPTR_FORMAT, reg_name, p2i((void*)saved_regs[i]));
517
    }
518
    ls.cr();
519

520
    {
521
      // dump last frame (from JavaThread::print_frame_layout)
522

523
      // Note: code is robust but the dumped information may not be
524
      // 100% correct, particularly with respect to the dumped
525
      // "unextended_sp". Getting it right for all trace_method_handle
526
      // call paths is not worth the complexity/risk. The correct slot
527
      // will be identified by *Rsender_sp anyway in the dump.
528
      JavaThread* p = JavaThread::active();
529

530
      // may not be needed by safer and unexpensive here
531
      PreserveExceptionMark pem(Thread::current());
532
      FrameValues values;
533

534
      intptr_t* dump_fp = (intptr_t *) saved_bp;
535
      address dump_pc = (address) saved_regs[trace_mh_nregs-2]; // LR (with LR,PC last in saved_regs)
536
      frame dump_frame((intptr_t *)entry_sp, dump_fp, dump_pc);
537

538
      dump_frame.describe(values, 1);
539
      // mark Rsender_sp if seems valid
540
      if (has_mh) {
541
        if ((saved_sp >= entry_sp - UNREASONABLE_STACK_MOVE) && (saved_sp < dump_fp)) {
542
          values.describe(-1, saved_sp, "*Rsender_sp");
543
        }
544
      }
545

546
      // Note: the unextended_sp may not be correct
547
      ls.print_cr("  stack layout:");
548
      values.print_on(p, &ls);
549
    }
550

551
    if (has_mh && oopDesc::is_oop(mh)) {
552
      mh->print_on(&ls);
553
      if (java_lang_invoke_MethodHandle::is_instance(mh)) {
554
        java_lang_invoke_MethodHandle::form(mh)->print_on(&ls);
555
      }
556
    }
557
  }
558
}
559

560
void MethodHandles::trace_method_handle(MacroAssembler* _masm, const char* adaptername) {
561
  if (!log_is_enabled(Info, methodhandles))  return;
562
  BLOCK_COMMENT("trace_method_handle {");
563
  // register saving
564
  //  must correspond to trace_mh_nregs and trace_mh_regs defined above
565
  int push_size = __ save_all_registers();
566
  assert(trace_mh_nregs*wordSize == push_size,"saved register count mismatch");
567

568
  __ mov_slow(R0, adaptername);
569
  __ mov(R1, SP); // entry_sp (after pushes)
570
  __ mov(R2, FP);
571
  if (R5_mh != R3) {
572
    assert_different_registers(R0, R1, R2, R5_mh);
573
    __ mov(R3, R5_mh);
574
  }
575

576
  __ call_VM_leaf(CAST_FROM_FN_PTR(address, trace_method_handle_stub), R0, R1, R2, R3);
577

578
  __ restore_all_registers();
579
  BLOCK_COMMENT("} trace_method_handle");
580
}
581
#endif //PRODUCT
582

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.