interp_masm_x86.cpp revision 8488:968044dba2a5
1/*
2 * Copyright (c) 1997, 2015, 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#include "precompiled.hpp"
26#include "interp_masm_x86.hpp"
27#include "interpreter/interpreter.hpp"
28#include "interpreter/interpreterRuntime.hpp"
29#include "oops/arrayOop.hpp"
30#include "oops/markOop.hpp"
31#include "oops/methodData.hpp"
32#include "oops/method.hpp"
33#include "prims/jvmtiExport.hpp"
34#include "prims/jvmtiRedefineClassesTrace.hpp"
35#include "prims/jvmtiThreadState.hpp"
36#include "runtime/basicLock.hpp"
37#include "runtime/biasedLocking.hpp"
38#include "runtime/sharedRuntime.hpp"
39#include "runtime/thread.inline.hpp"
40
41// Implementation of InterpreterMacroAssembler
42
43#ifndef CC_INTERP
44void InterpreterMacroAssembler::profile_obj_type(Register obj, const Address& mdo_addr) {
45  Label update, next, none;
46
47  verify_oop(obj);
48
49  testptr(obj, obj);
50  jccb(Assembler::notZero, update);
51  orptr(mdo_addr, TypeEntries::null_seen);
52  jmpb(next);
53
54  bind(update);
55  load_klass(obj, obj);
56
57  xorptr(obj, mdo_addr);
58  testptr(obj, TypeEntries::type_klass_mask);
59  jccb(Assembler::zero, next); // klass seen before, nothing to
60                               // do. The unknown bit may have been
61                               // set already but no need to check.
62
63  testptr(obj, TypeEntries::type_unknown);
64  jccb(Assembler::notZero, next); // already unknown. Nothing to do anymore.
65
66  cmpptr(mdo_addr, 0);
67  jccb(Assembler::equal, none);
68  cmpptr(mdo_addr, TypeEntries::null_seen);
69  jccb(Assembler::equal, none);
70  // There is a chance that the checks above (re-reading profiling
71  // data from memory) fail if another thread has just set the
72  // profiling to this obj's klass
73  xorptr(obj, mdo_addr);
74  testptr(obj, TypeEntries::type_klass_mask);
75  jccb(Assembler::zero, next);
76
77  // different than before. Cannot keep accurate profile.
78  orptr(mdo_addr, TypeEntries::type_unknown);
79  jmpb(next);
80
81  bind(none);
82  // first time here. Set profile type.
83  movptr(mdo_addr, obj);
84
85  bind(next);
86}
87
88void InterpreterMacroAssembler::profile_arguments_type(Register mdp, Register callee, Register tmp, bool is_virtual) {
89  if (!ProfileInterpreter) {
90    return;
91  }
92
93  if (MethodData::profile_arguments() || MethodData::profile_return()) {
94    Label profile_continue;
95
96    test_method_data_pointer(mdp, profile_continue);
97
98    int off_to_start = is_virtual ? in_bytes(VirtualCallData::virtual_call_data_size()) : in_bytes(CounterData::counter_data_size());
99
100    cmpb(Address(mdp, in_bytes(DataLayout::tag_offset()) - off_to_start), is_virtual ? DataLayout::virtual_call_type_data_tag : DataLayout::call_type_data_tag);
101    jcc(Assembler::notEqual, profile_continue);
102
103    if (MethodData::profile_arguments()) {
104      Label done;
105      int off_to_args = in_bytes(TypeEntriesAtCall::args_data_offset());
106      addptr(mdp, off_to_args);
107
108      for (int i = 0; i < TypeProfileArgsLimit; i++) {
109        if (i > 0 || MethodData::profile_return()) {
110          // If return value type is profiled we may have no argument to profile
111          movptr(tmp, Address(mdp, in_bytes(TypeEntriesAtCall::cell_count_offset())-off_to_args));
112          subl(tmp, i*TypeStackSlotEntries::per_arg_count());
113          cmpl(tmp, TypeStackSlotEntries::per_arg_count());
114          jcc(Assembler::less, done);
115        }
116        movptr(tmp, Address(callee, Method::const_offset()));
117        load_unsigned_short(tmp, Address(tmp, ConstMethod::size_of_parameters_offset()));
118        // stack offset o (zero based) from the start of the argument
119        // list, for n arguments translates into offset n - o - 1 from
120        // the end of the argument list
121        subptr(tmp, Address(mdp, in_bytes(TypeEntriesAtCall::stack_slot_offset(i))-off_to_args));
122        subl(tmp, 1);
123        Address arg_addr = argument_address(tmp);
124        movptr(tmp, arg_addr);
125
126        Address mdo_arg_addr(mdp, in_bytes(TypeEntriesAtCall::argument_type_offset(i))-off_to_args);
127        profile_obj_type(tmp, mdo_arg_addr);
128
129        int to_add = in_bytes(TypeStackSlotEntries::per_arg_size());
130        addptr(mdp, to_add);
131        off_to_args += to_add;
132      }
133
134      if (MethodData::profile_return()) {
135        movptr(tmp, Address(mdp, in_bytes(TypeEntriesAtCall::cell_count_offset())-off_to_args));
136        subl(tmp, TypeProfileArgsLimit*TypeStackSlotEntries::per_arg_count());
137      }
138
139      bind(done);
140
141      if (MethodData::profile_return()) {
142        // We're right after the type profile for the last
143        // argument. tmp is the number of cells left in the
144        // CallTypeData/VirtualCallTypeData to reach its end. Non null
145        // if there's a return to profile.
146        assert(ReturnTypeEntry::static_cell_count() < TypeStackSlotEntries::per_arg_count(), "can't move past ret type");
147        shll(tmp, exact_log2(DataLayout::cell_size));
148        addptr(mdp, tmp);
149      }
150      movptr(Address(rbp, frame::interpreter_frame_mdp_offset * wordSize), mdp);
151    } else {
152      assert(MethodData::profile_return(), "either profile call args or call ret");
153      update_mdp_by_constant(mdp, in_bytes(TypeEntriesAtCall::return_only_size()));
154    }
155
156    // mdp points right after the end of the
157    // CallTypeData/VirtualCallTypeData, right after the cells for the
158    // return value type if there's one
159
160    bind(profile_continue);
161  }
162}
163
164void InterpreterMacroAssembler::profile_return_type(Register mdp, Register ret, Register tmp) {
165  assert_different_registers(mdp, ret, tmp, _bcp_register);
166  if (ProfileInterpreter && MethodData::profile_return()) {
167    Label profile_continue, done;
168
169    test_method_data_pointer(mdp, profile_continue);
170
171    if (MethodData::profile_return_jsr292_only()) {
172      // If we don't profile all invoke bytecodes we must make sure
173      // it's a bytecode we indeed profile. We can't go back to the
174      // begining of the ProfileData we intend to update to check its
175      // type because we're right after it and we don't known its
176      // length
177      Label do_profile;
178      cmpb(Address(_bcp_register, 0), Bytecodes::_invokedynamic);
179      jcc(Assembler::equal, do_profile);
180      cmpb(Address(_bcp_register, 0), Bytecodes::_invokehandle);
181      jcc(Assembler::equal, do_profile);
182      get_method(tmp);
183      cmpb(Address(tmp, Method::intrinsic_id_offset_in_bytes()), vmIntrinsics::_compiledLambdaForm);
184      jcc(Assembler::notEqual, profile_continue);
185
186      bind(do_profile);
187    }
188
189    Address mdo_ret_addr(mdp, -in_bytes(ReturnTypeEntry::size()));
190    mov(tmp, ret);
191    profile_obj_type(tmp, mdo_ret_addr);
192
193    bind(profile_continue);
194  }
195}
196
197void InterpreterMacroAssembler::profile_parameters_type(Register mdp, Register tmp1, Register tmp2) {
198  if (ProfileInterpreter && MethodData::profile_parameters()) {
199    Label profile_continue, done;
200
201    test_method_data_pointer(mdp, profile_continue);
202
203    // Load the offset of the area within the MDO used for
204    // parameters. If it's negative we're not profiling any parameters
205    movl(tmp1, Address(mdp, in_bytes(MethodData::parameters_type_data_di_offset()) - in_bytes(MethodData::data_offset())));
206    testl(tmp1, tmp1);
207    jcc(Assembler::negative, profile_continue);
208
209    // Compute a pointer to the area for parameters from the offset
210    // and move the pointer to the slot for the last
211    // parameters. Collect profiling from last parameter down.
212    // mdo start + parameters offset + array length - 1
213    addptr(mdp, tmp1);
214    movptr(tmp1, Address(mdp, ArrayData::array_len_offset()));
215    decrement(tmp1, TypeStackSlotEntries::per_arg_count());
216
217    Label loop;
218    bind(loop);
219
220    int off_base = in_bytes(ParametersTypeData::stack_slot_offset(0));
221    int type_base = in_bytes(ParametersTypeData::type_offset(0));
222    Address::ScaleFactor per_arg_scale = Address::times(DataLayout::cell_size);
223    Address arg_off(mdp, tmp1, per_arg_scale, off_base);
224    Address arg_type(mdp, tmp1, per_arg_scale, type_base);
225
226    // load offset on the stack from the slot for this parameter
227    movptr(tmp2, arg_off);
228    negptr(tmp2);
229    // read the parameter from the local area
230    movptr(tmp2, Address(_locals_register, tmp2, Interpreter::stackElementScale()));
231
232    // profile the parameter
233    profile_obj_type(tmp2, arg_type);
234
235    // go to next parameter
236    decrement(tmp1, TypeStackSlotEntries::per_arg_count());
237    jcc(Assembler::positive, loop);
238
239    bind(profile_continue);
240  }
241}
242#endif
243
244#ifdef CC_INTERP
245void InterpreterMacroAssembler::get_method(Register reg) {
246  movptr(reg, Address(rbp, -(sizeof(BytecodeInterpreter) + 2 * wordSize)));
247  movptr(reg, Address(reg, byte_offset_of(BytecodeInterpreter, _method)));
248}
249#endif // CC_INTERP
250
251#ifndef CC_INTERP
252void InterpreterMacroAssembler::call_VM_leaf_base(address entry_point,
253                                                  int number_of_arguments) {
254  // interpreter specific
255  //
256  // Note: No need to save/restore bcp & locals registers
257  //       since these are callee saved registers and no blocking/
258  //       GC can happen in leaf calls.
259  // Further Note: DO NOT save/restore bcp/locals. If a caller has
260  // already saved them so that it can use rsi/rdi as temporaries
261  // then a save/restore here will DESTROY the copy the caller
262  // saved! There used to be a save_bcp() that only happened in
263  // the ASSERT path (no restore_bcp). Which caused bizarre failures
264  // when jvm built with ASSERTs.
265#ifdef ASSERT
266  {
267    Label L;
268    cmpptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD);
269    jcc(Assembler::equal, L);
270    stop("InterpreterMacroAssembler::call_VM_leaf_base:"
271         " last_sp != NULL");
272    bind(L);
273  }
274#endif
275  // super call
276  MacroAssembler::call_VM_leaf_base(entry_point, number_of_arguments);
277  // interpreter specific
278  // LP64: Used to ASSERT that r13/r14 were equal to frame's bcp/locals
279  // but since they may not have been saved (and we don't want to
280  // save them here (see note above) the assert is invalid.
281}
282
283void InterpreterMacroAssembler::call_VM_base(Register oop_result,
284                                             Register java_thread,
285                                             Register last_java_sp,
286                                             address  entry_point,
287                                             int      number_of_arguments,
288                                             bool     check_exceptions) {
289  // interpreter specific
290  //
291  // Note: Could avoid restoring locals ptr (callee saved) - however doesn't
292  //       really make a difference for these runtime calls, since they are
293  //       slow anyway. Btw., bcp must be saved/restored since it may change
294  //       due to GC.
295  NOT_LP64(assert(java_thread == noreg , "not expecting a precomputed java thread");)
296  save_bcp();
297#ifdef ASSERT
298  {
299    Label L;
300    cmpptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD);
301    jcc(Assembler::equal, L);
302    stop("InterpreterMacroAssembler::call_VM_leaf_base:"
303         " last_sp != NULL");
304    bind(L);
305  }
306#endif /* ASSERT */
307  // super call
308  MacroAssembler::call_VM_base(oop_result, noreg, last_java_sp,
309                               entry_point, number_of_arguments,
310                               check_exceptions);
311  // interpreter specific
312  restore_bcp();
313  restore_locals();
314}
315
316void InterpreterMacroAssembler::check_and_handle_popframe(Register java_thread) {
317  if (JvmtiExport::can_pop_frame()) {
318    Label L;
319    // Initiate popframe handling only if it is not already being
320    // processed.  If the flag has the popframe_processing bit set, it
321    // means that this code is called *during* popframe handling - we
322    // don't want to reenter.
323    // This method is only called just after the call into the vm in
324    // call_VM_base, so the arg registers are available.
325    Register pop_cond = NOT_LP64(java_thread) // Not clear if any other register is available on 32 bit
326                        LP64_ONLY(c_rarg0);
327    movl(pop_cond, Address(java_thread, JavaThread::popframe_condition_offset()));
328    testl(pop_cond, JavaThread::popframe_pending_bit);
329    jcc(Assembler::zero, L);
330    testl(pop_cond, JavaThread::popframe_processing_bit);
331    jcc(Assembler::notZero, L);
332    // Call Interpreter::remove_activation_preserving_args_entry() to get the
333    // address of the same-named entrypoint in the generated interpreter code.
334    call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_preserving_args_entry));
335    jmp(rax);
336    bind(L);
337    NOT_LP64(get_thread(java_thread);)
338  }
339}
340
341void InterpreterMacroAssembler::load_earlyret_value(TosState state) {
342  Register thread = LP64_ONLY(r15_thread) NOT_LP64(rcx);
343  NOT_LP64(get_thread(thread);)
344  movptr(rcx, Address(thread, JavaThread::jvmti_thread_state_offset()));
345  const Address tos_addr(rcx, JvmtiThreadState::earlyret_tos_offset());
346  const Address oop_addr(rcx, JvmtiThreadState::earlyret_oop_offset());
347  const Address val_addr(rcx, JvmtiThreadState::earlyret_value_offset());
348#ifdef _LP64
349  switch (state) {
350    case atos: movptr(rax, oop_addr);
351               movptr(oop_addr, (int32_t)NULL_WORD);
352               verify_oop(rax, state);              break;
353    case ltos: movptr(rax, val_addr);                 break;
354    case btos:                                   // fall through
355    case ctos:                                   // fall through
356    case stos:                                   // fall through
357    case itos: movl(rax, val_addr);                 break;
358    case ftos: movflt(xmm0, val_addr);              break;
359    case dtos: movdbl(xmm0, val_addr);              break;
360    case vtos: /* nothing to do */                  break;
361    default  : ShouldNotReachHere();
362  }
363  // Clean up tos value in the thread object
364  movl(tos_addr,  (int) ilgl);
365  movl(val_addr,  (int32_t) NULL_WORD);
366#else
367  const Address val_addr1(rcx, JvmtiThreadState::earlyret_value_offset()
368                             + in_ByteSize(wordSize));
369  switch (state) {
370    case atos: movptr(rax, oop_addr);
371               movptr(oop_addr, NULL_WORD);
372               verify_oop(rax, state);                break;
373    case ltos:
374               movl(rdx, val_addr1);               // fall through
375    case btos:                                     // fall through
376    case ctos:                                     // fall through
377    case stos:                                     // fall through
378    case itos: movl(rax, val_addr);                   break;
379    case ftos: fld_s(val_addr);                       break;
380    case dtos: fld_d(val_addr);                       break;
381    case vtos: /* nothing to do */                    break;
382    default  : ShouldNotReachHere();
383  }
384#endif // _LP64
385  // Clean up tos value in the thread object
386  movl(tos_addr,  (int32_t) ilgl);
387  movptr(val_addr,  NULL_WORD);
388  NOT_LP64(movptr(val_addr1, NULL_WORD);)
389}
390
391
392void InterpreterMacroAssembler::check_and_handle_earlyret(Register java_thread) {
393  if (JvmtiExport::can_force_early_return()) {
394    Label L;
395    Register tmp = LP64_ONLY(c_rarg0) NOT_LP64(java_thread);
396    Register rthread = LP64_ONLY(r15_thread) NOT_LP64(java_thread);
397
398    movptr(tmp, Address(rthread, JavaThread::jvmti_thread_state_offset()));
399    testptr(tmp, tmp);
400    jcc(Assembler::zero, L); // if (thread->jvmti_thread_state() == NULL) exit;
401
402    // Initiate earlyret handling only if it is not already being processed.
403    // If the flag has the earlyret_processing bit set, it means that this code
404    // is called *during* earlyret handling - we don't want to reenter.
405    movl(tmp, Address(tmp, JvmtiThreadState::earlyret_state_offset()));
406    cmpl(tmp, JvmtiThreadState::earlyret_pending);
407    jcc(Assembler::notEqual, L);
408
409    // Call Interpreter::remove_activation_early_entry() to get the address of the
410    // same-named entrypoint in the generated interpreter code.
411    NOT_LP64(get_thread(java_thread);)
412    movptr(tmp, Address(rthread, JavaThread::jvmti_thread_state_offset()));
413#ifdef _LP64
414    movl(tmp, Address(tmp, JvmtiThreadState::earlyret_tos_offset()));
415    call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_early_entry), tmp);
416#else
417    pushl(Address(tmp, JvmtiThreadState::earlyret_tos_offset()));
418    call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_early_entry), 1);
419#endif // _LP64
420    jmp(rax);
421    bind(L);
422    NOT_LP64(get_thread(java_thread);)
423  }
424}
425
426void InterpreterMacroAssembler::get_unsigned_2_byte_index_at_bcp(Register reg, int bcp_offset) {
427  assert(bcp_offset >= 0, "bcp is still pointing to start of bytecode");
428  load_unsigned_short(reg, Address(_bcp_register, bcp_offset));
429  bswapl(reg);
430  shrl(reg, 16);
431}
432
433void InterpreterMacroAssembler::get_cache_index_at_bcp(Register index,
434                                                       int bcp_offset,
435                                                       size_t index_size) {
436  assert(bcp_offset > 0, "bcp is still pointing to start of bytecode");
437  if (index_size == sizeof(u2)) {
438    load_unsigned_short(index, Address(_bcp_register, bcp_offset));
439  } else if (index_size == sizeof(u4)) {
440    movl(index, Address(_bcp_register, bcp_offset));
441    // Check if the secondary index definition is still ~x, otherwise
442    // we have to change the following assembler code to calculate the
443    // plain index.
444    assert(ConstantPool::decode_invokedynamic_index(~123) == 123, "else change next line");
445    notl(index);  // convert to plain index
446  } else if (index_size == sizeof(u1)) {
447    load_unsigned_byte(index, Address(_bcp_register, bcp_offset));
448  } else {
449    ShouldNotReachHere();
450  }
451}
452
453void InterpreterMacroAssembler::get_cache_and_index_at_bcp(Register cache,
454                                                           Register index,
455                                                           int bcp_offset,
456                                                           size_t index_size) {
457  assert_different_registers(cache, index);
458  get_cache_index_at_bcp(index, bcp_offset, index_size);
459  movptr(cache, Address(rbp, frame::interpreter_frame_cache_offset * wordSize));
460  assert(sizeof(ConstantPoolCacheEntry) == 4 * wordSize, "adjust code below");
461  // convert from field index to ConstantPoolCacheEntry index
462  assert(exact_log2(in_words(ConstantPoolCacheEntry::size())) == 2, "else change next line");
463  shll(index, 2);
464}
465
466void InterpreterMacroAssembler::get_cache_and_index_and_bytecode_at_bcp(Register cache,
467                                                                        Register index,
468                                                                        Register bytecode,
469                                                                        int byte_no,
470                                                                        int bcp_offset,
471                                                                        size_t index_size) {
472  get_cache_and_index_at_bcp(cache, index, bcp_offset, index_size);
473  // We use a 32-bit load here since the layout of 64-bit words on
474  // little-endian machines allow us that.
475  movl(bytecode, Address(cache, index, Address::times_ptr, ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::indices_offset()));
476  const int shift_count = (1 + byte_no) * BitsPerByte;
477  assert((byte_no == TemplateTable::f1_byte && shift_count == ConstantPoolCacheEntry::bytecode_1_shift) ||
478         (byte_no == TemplateTable::f2_byte && shift_count == ConstantPoolCacheEntry::bytecode_2_shift),
479         "correct shift count");
480  shrl(bytecode, shift_count);
481  assert(ConstantPoolCacheEntry::bytecode_1_mask == ConstantPoolCacheEntry::bytecode_2_mask, "common mask");
482  andl(bytecode, ConstantPoolCacheEntry::bytecode_1_mask);
483}
484
485void InterpreterMacroAssembler::get_resolved_references(Register reg) {
486  get_constant_pool(reg);
487  movptr(reg, Address(reg, ConstantPool::pool_holder_offset_in_bytes()));
488  movptr(reg, Address(reg, Klass::java_mirror_offset()));
489  assert(java_lang_Class::resolved_references_offset_in_bytes() > 0, "");
490  load_heap_oop(reg, Address(reg, java_lang_Class::resolved_references_offset_in_bytes()));
491}
492
493void InterpreterMacroAssembler::get_cache_entry_pointer_at_bcp(Register cache,
494                                                               Register tmp,
495                                                               int bcp_offset,
496                                                               size_t index_size) {
497  assert(cache != tmp, "must use different register");
498  get_cache_index_at_bcp(tmp, bcp_offset, index_size);
499  assert(sizeof(ConstantPoolCacheEntry) == 4 * wordSize, "adjust code below");
500  // convert from field index to ConstantPoolCacheEntry index
501  // and from word offset to byte offset
502  assert(exact_log2(in_bytes(ConstantPoolCacheEntry::size_in_bytes())) == 2 + LogBytesPerWord, "else change next line");
503  shll(tmp, 2 + LogBytesPerWord);
504  movptr(cache, Address(rbp, frame::interpreter_frame_cache_offset * wordSize));
505  // skip past the header
506  addptr(cache, in_bytes(ConstantPoolCache::base_offset()));
507  addptr(cache, tmp);  // construct pointer to cache entry
508}
509
510// Load object from cpool->pool_holder->mirror->resolved_references(index)
511void InterpreterMacroAssembler::load_resolved_reference_at_index(Register result, Register index) {
512  assert_different_registers(result, index);
513  // convert from field index to resolved_references() index and from
514  // word index to byte offset. Since this is a java object, it can be compressed
515  Register tmp = index;  // reuse
516  shll(tmp, LogBytesPerHeapOop);
517
518  // load pointer for resolved_references[] objArray
519  get_resolved_references(result);
520  // Add in the index
521  addptr(result, tmp);
522  load_heap_oop(result, Address(result, arrayOopDesc::base_offset_in_bytes(T_OBJECT)));
523}
524
525
526// Generate a subtype check: branch to ok_is_subtype if sub_klass is a
527// subtype of super_klass.
528//
529// Args:
530//      rax: superklass
531//      Rsub_klass: subklass
532//
533// Kills:
534//      rcx, rdi
535void InterpreterMacroAssembler::gen_subtype_check(Register Rsub_klass,
536                                                  Label& ok_is_subtype) {
537  assert(Rsub_klass != rax, "rax holds superklass");
538  LP64_ONLY(assert(Rsub_klass != r14, "r14 holds locals");)
539  LP64_ONLY(assert(Rsub_klass != r13, "r13 holds bcp");)
540  assert(Rsub_klass != rcx, "rcx holds 2ndary super array length");
541  assert(Rsub_klass != rdi, "rdi holds 2ndary super array scan ptr");
542
543  // Profile the not-null value's klass.
544  profile_typecheck(rcx, Rsub_klass, rdi); // blows rcx, reloads rdi
545
546  // Do the check.
547  check_klass_subtype(Rsub_klass, rax, rcx, ok_is_subtype); // blows rcx
548
549  // Profile the failure of the check.
550  profile_typecheck_failed(rcx); // blows rcx
551}
552
553
554#ifndef _LP64
555void InterpreterMacroAssembler::f2ieee() {
556  if (IEEEPrecision) {
557    fstp_s(Address(rsp, 0));
558    fld_s(Address(rsp, 0));
559  }
560}
561
562
563void InterpreterMacroAssembler::d2ieee() {
564  if (IEEEPrecision) {
565    fstp_d(Address(rsp, 0));
566    fld_d(Address(rsp, 0));
567  }
568}
569#endif // _LP64
570
571// Java Expression Stack
572
573void InterpreterMacroAssembler::pop_ptr(Register r) {
574  pop(r);
575}
576
577void InterpreterMacroAssembler::push_ptr(Register r) {
578  push(r);
579}
580
581void InterpreterMacroAssembler::push_i(Register r) {
582  push(r);
583}
584
585#ifdef _LP64
586void InterpreterMacroAssembler::pop_i(Register r) {
587  // XXX can't use pop currently, upper half non clean
588  movl(r, Address(rsp, 0));
589  addptr(rsp, wordSize);
590}
591
592void InterpreterMacroAssembler::pop_l(Register r) {
593  movq(r, Address(rsp, 0));
594  addptr(rsp, 2 * Interpreter::stackElementSize);
595}
596
597void InterpreterMacroAssembler::pop_f(XMMRegister r) {
598  movflt(r, Address(rsp, 0));
599  addptr(rsp, wordSize);
600}
601
602void InterpreterMacroAssembler::pop_d(XMMRegister r) {
603  movdbl(r, Address(rsp, 0));
604  addptr(rsp, 2 * Interpreter::stackElementSize);
605}
606
607void InterpreterMacroAssembler::push_l(Register r) {
608  subptr(rsp, 2 * wordSize);
609  movq(Address(rsp, 0), r);
610}
611
612void InterpreterMacroAssembler::push_f(XMMRegister r) {
613  subptr(rsp, wordSize);
614  movflt(Address(rsp, 0), r);
615}
616
617void InterpreterMacroAssembler::push_d(XMMRegister r) {
618  subptr(rsp, 2 * wordSize);
619  movdbl(Address(rsp, 0), r);
620}
621
622void InterpreterMacroAssembler::pop(TosState state) {
623  switch (state) {
624  case atos: pop_ptr();                 break;
625  case btos:
626  case ctos:
627  case stos:
628  case itos: pop_i();                   break;
629  case ltos: pop_l();                   break;
630  case ftos: pop_f();                   break;
631  case dtos: pop_d();                   break;
632  case vtos: /* nothing to do */        break;
633  default:   ShouldNotReachHere();
634  }
635  verify_oop(rax, state);
636}
637
638void InterpreterMacroAssembler::push(TosState state) {
639  verify_oop(rax, state);
640  switch (state) {
641  case atos: push_ptr();                break;
642  case btos:
643  case ctos:
644  case stos:
645  case itos: push_i();                  break;
646  case ltos: push_l();                  break;
647  case ftos: push_f();                  break;
648  case dtos: push_d();                  break;
649  case vtos: /* nothing to do */        break;
650  default  : ShouldNotReachHere();
651  }
652}
653#else
654void InterpreterMacroAssembler::pop_i(Register r) {
655  pop(r);
656}
657
658void InterpreterMacroAssembler::pop_l(Register lo, Register hi) {
659  pop(lo);
660  pop(hi);
661}
662
663void InterpreterMacroAssembler::pop_f() {
664  fld_s(Address(rsp, 0));
665  addptr(rsp, 1 * wordSize);
666}
667
668void InterpreterMacroAssembler::pop_d() {
669  fld_d(Address(rsp, 0));
670  addptr(rsp, 2 * wordSize);
671}
672
673
674void InterpreterMacroAssembler::pop(TosState state) {
675  switch (state) {
676    case atos: pop_ptr(rax);                                 break;
677    case btos:                                               // fall through
678    case ctos:                                               // fall through
679    case stos:                                               // fall through
680    case itos: pop_i(rax);                                   break;
681    case ltos: pop_l(rax, rdx);                              break;
682    case ftos: pop_f();                                      break;
683    case dtos: pop_d();                                      break;
684    case vtos: /* nothing to do */                           break;
685    default  : ShouldNotReachHere();
686  }
687  verify_oop(rax, state);
688}
689
690
691void InterpreterMacroAssembler::push_l(Register lo, Register hi) {
692  push(hi);
693  push(lo);
694}
695
696void InterpreterMacroAssembler::push_f() {
697  // Do not schedule for no AGI! Never write beyond rsp!
698  subptr(rsp, 1 * wordSize);
699  fstp_s(Address(rsp, 0));
700}
701
702void InterpreterMacroAssembler::push_d(Register r) {
703  // Do not schedule for no AGI! Never write beyond rsp!
704  subptr(rsp, 2 * wordSize);
705  fstp_d(Address(rsp, 0));
706}
707
708
709void InterpreterMacroAssembler::push(TosState state) {
710  verify_oop(rax, state);
711  switch (state) {
712    case atos: push_ptr(rax); break;
713    case btos:                                               // fall through
714    case ctos:                                               // fall through
715    case stos:                                               // fall through
716    case itos: push_i(rax);                                    break;
717    case ltos: push_l(rax, rdx);                               break;
718    case ftos: push_f();                                       break;
719    case dtos: push_d(rax);                                    break;
720    case vtos: /* nothing to do */                             break;
721    default  : ShouldNotReachHere();
722  }
723}
724#endif // _LP64
725
726
727// Helpers for swap and dup
728void InterpreterMacroAssembler::load_ptr(int n, Register val) {
729  movptr(val, Address(rsp, Interpreter::expr_offset_in_bytes(n)));
730}
731
732void InterpreterMacroAssembler::store_ptr(int n, Register val) {
733  movptr(Address(rsp, Interpreter::expr_offset_in_bytes(n)), val);
734}
735
736
737void InterpreterMacroAssembler::prepare_to_jump_from_interpreted() {
738  // set sender sp
739  lea(_bcp_register, Address(rsp, wordSize));
740  // record last_sp
741  movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), _bcp_register);
742}
743
744
745// Jump to from_interpreted entry of a call unless single stepping is possible
746// in this thread in which case we must call the i2i entry
747void InterpreterMacroAssembler::jump_from_interpreted(Register method, Register temp) {
748  prepare_to_jump_from_interpreted();
749
750  if (JvmtiExport::can_post_interpreter_events()) {
751    Label run_compiled_code;
752    // JVMTI events, such as single-stepping, are implemented partly by avoiding running
753    // compiled code in threads for which the event is enabled.  Check here for
754    // interp_only_mode if these events CAN be enabled.
755    // interp_only is an int, on little endian it is sufficient to test the byte only
756    // Is a cmpl faster?
757    LP64_ONLY(temp = r15_thread;)
758    NOT_LP64(get_thread(temp);)
759    cmpb(Address(temp, JavaThread::interp_only_mode_offset()), 0);
760    jccb(Assembler::zero, run_compiled_code);
761    jmp(Address(method, Method::interpreter_entry_offset()));
762    bind(run_compiled_code);
763  }
764
765  jmp(Address(method, Method::from_interpreted_offset()));
766}
767
768// The following two routines provide a hook so that an implementation
769// can schedule the dispatch in two parts.  x86 does not do this.
770void InterpreterMacroAssembler::dispatch_prolog(TosState state, int step) {
771  // Nothing x86 specific to be done here
772}
773
774void InterpreterMacroAssembler::dispatch_epilog(TosState state, int step) {
775  dispatch_next(state, step);
776}
777
778void InterpreterMacroAssembler::dispatch_base(TosState state,
779                                              address* table,
780                                              bool verifyoop) {
781  verify_FPU(1, state);
782  if (VerifyActivationFrameSize) {
783    Label L;
784    mov(rcx, rbp);
785    subptr(rcx, rsp);
786    int32_t min_frame_size =
787      (frame::link_offset - frame::interpreter_frame_initial_sp_offset) *
788      wordSize;
789    cmpptr(rcx, (int32_t)min_frame_size);
790    jcc(Assembler::greaterEqual, L);
791    stop("broken stack frame");
792    bind(L);
793  }
794  if (verifyoop) {
795    verify_oop(rax, state);
796  }
797#ifdef _LP64
798  lea(rscratch1, ExternalAddress((address)table));
799  jmp(Address(rscratch1, rbx, Address::times_8));
800#else
801  Address index(noreg, rbx, Address::times_ptr);
802  ExternalAddress tbl((address)table);
803  ArrayAddress dispatch(tbl, index);
804  jump(dispatch);
805#endif // _LP64
806}
807
808void InterpreterMacroAssembler::dispatch_only(TosState state) {
809  dispatch_base(state, Interpreter::dispatch_table(state));
810}
811
812void InterpreterMacroAssembler::dispatch_only_normal(TosState state) {
813  dispatch_base(state, Interpreter::normal_table(state));
814}
815
816void InterpreterMacroAssembler::dispatch_only_noverify(TosState state) {
817  dispatch_base(state, Interpreter::normal_table(state), false);
818}
819
820
821void InterpreterMacroAssembler::dispatch_next(TosState state, int step) {
822  // load next bytecode (load before advancing _bcp_register to prevent AGI)
823  load_unsigned_byte(rbx, Address(_bcp_register, step));
824  // advance _bcp_register
825  increment(_bcp_register, step);
826  dispatch_base(state, Interpreter::dispatch_table(state));
827}
828
829void InterpreterMacroAssembler::dispatch_via(TosState state, address* table) {
830  // load current bytecode
831  load_unsigned_byte(rbx, Address(_bcp_register, 0));
832  dispatch_base(state, table);
833}
834
835// remove activation
836//
837// Unlock the receiver if this is a synchronized method.
838// Unlock any Java monitors from syncronized blocks.
839// Remove the activation from the stack.
840//
841// If there are locked Java monitors
842//    If throw_monitor_exception
843//       throws IllegalMonitorStateException
844//    Else if install_monitor_exception
845//       installs IllegalMonitorStateException
846//    Else
847//       no error processing
848void InterpreterMacroAssembler::remove_activation(
849        TosState state,
850        Register ret_addr,
851        bool throw_monitor_exception,
852        bool install_monitor_exception,
853        bool notify_jvmdi) {
854  // Note: Registers rdx xmm0 may be in use for the
855  // result check if synchronized method
856  Label unlocked, unlock, no_unlock;
857
858  const Register rthread = LP64_ONLY(r15_thread) NOT_LP64(rcx);
859  const Register robj    = LP64_ONLY(c_rarg1) NOT_LP64(rdx);
860  const Register rmon    = LP64_ONLY(c_rarg1) NOT_LP64(rcx);
861                              // monitor pointers need different register
862                              // because rdx may have the result in it
863  NOT_LP64(get_thread(rcx);)
864
865  // get the value of _do_not_unlock_if_synchronized into rdx
866  const Address do_not_unlock_if_synchronized(rthread,
867    in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
868  movbool(rbx, do_not_unlock_if_synchronized);
869  movbool(do_not_unlock_if_synchronized, false); // reset the flag
870
871 // get method access flags
872  movptr(rcx, Address(rbp, frame::interpreter_frame_method_offset * wordSize));
873  movl(rcx, Address(rcx, Method::access_flags_offset()));
874  testl(rcx, JVM_ACC_SYNCHRONIZED);
875  jcc(Assembler::zero, unlocked);
876
877  // Don't unlock anything if the _do_not_unlock_if_synchronized flag
878  // is set.
879  testbool(rbx);
880  jcc(Assembler::notZero, no_unlock);
881
882  // unlock monitor
883  push(state); // save result
884
885  // BasicObjectLock will be first in list, since this is a
886  // synchronized method. However, need to check that the object has
887  // not been unlocked by an explicit monitorexit bytecode.
888  const Address monitor(rbp, frame::interpreter_frame_initial_sp_offset *
889                        wordSize - (int) sizeof(BasicObjectLock));
890  // We use c_rarg1/rdx so that if we go slow path it will be the correct
891  // register for unlock_object to pass to VM directly
892  lea(robj, monitor); // address of first monitor
893
894  movptr(rax, Address(robj, BasicObjectLock::obj_offset_in_bytes()));
895  testptr(rax, rax);
896  jcc(Assembler::notZero, unlock);
897
898  pop(state);
899  if (throw_monitor_exception) {
900    // Entry already unlocked, need to throw exception
901    NOT_LP64(empty_FPU_stack();)  // remove possible return value from FPU-stack, otherwise stack could overflow
902    call_VM(noreg, CAST_FROM_FN_PTR(address,
903                   InterpreterRuntime::throw_illegal_monitor_state_exception));
904    should_not_reach_here();
905  } else {
906    // Monitor already unlocked during a stack unroll. If requested,
907    // install an illegal_monitor_state_exception.  Continue with
908    // stack unrolling.
909    if (install_monitor_exception) {
910      NOT_LP64(empty_FPU_stack();)
911      call_VM(noreg, CAST_FROM_FN_PTR(address,
912                     InterpreterRuntime::new_illegal_monitor_state_exception));
913    }
914    jmp(unlocked);
915  }
916
917  bind(unlock);
918  unlock_object(robj);
919  pop(state);
920
921  // Check that for block-structured locking (i.e., that all locked
922  // objects has been unlocked)
923  bind(unlocked);
924
925  // rax, rdx: Might contain return value
926
927  // Check that all monitors are unlocked
928  {
929    Label loop, exception, entry, restart;
930    const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
931    const Address monitor_block_top(
932        rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
933    const Address monitor_block_bot(
934        rbp, frame::interpreter_frame_initial_sp_offset * wordSize);
935
936    bind(restart);
937    // We use c_rarg1 so that if we go slow path it will be the correct
938    // register for unlock_object to pass to VM directly
939    movptr(rmon, monitor_block_top); // points to current entry, starting
940                                  // with top-most entry
941    lea(rbx, monitor_block_bot);  // points to word before bottom of
942                                  // monitor block
943    jmp(entry);
944
945    // Entry already locked, need to throw exception
946    bind(exception);
947
948    if (throw_monitor_exception) {
949      // Throw exception
950      NOT_LP64(empty_FPU_stack();)
951      MacroAssembler::call_VM(noreg,
952                              CAST_FROM_FN_PTR(address, InterpreterRuntime::
953                                   throw_illegal_monitor_state_exception));
954      should_not_reach_here();
955    } else {
956      // Stack unrolling. Unlock object and install illegal_monitor_exception.
957      // Unlock does not block, so don't have to worry about the frame.
958      // We don't have to preserve c_rarg1 since we are going to throw an exception.
959
960      push(state);
961      mov(robj, rmon);   // nop if robj and rmon are the same
962      unlock_object(robj);
963      pop(state);
964
965      if (install_monitor_exception) {
966        NOT_LP64(empty_FPU_stack();)
967        call_VM(noreg, CAST_FROM_FN_PTR(address,
968                                        InterpreterRuntime::
969                                        new_illegal_monitor_state_exception));
970      }
971
972      jmp(restart);
973    }
974
975    bind(loop);
976    // check if current entry is used
977    cmpptr(Address(rmon, BasicObjectLock::obj_offset_in_bytes()), (int32_t) NULL);
978    jcc(Assembler::notEqual, exception);
979
980    addptr(rmon, entry_size); // otherwise advance to next entry
981    bind(entry);
982    cmpptr(rmon, rbx); // check if bottom reached
983    jcc(Assembler::notEqual, loop); // if not at bottom then check this entry
984  }
985
986  bind(no_unlock);
987
988  // jvmti support
989  if (notify_jvmdi) {
990    notify_method_exit(state, NotifyJVMTI);    // preserve TOSCA
991  } else {
992    notify_method_exit(state, SkipNotifyJVMTI); // preserve TOSCA
993  }
994
995  // remove activation
996  // get sender sp
997  movptr(rbx,
998         Address(rbp, frame::interpreter_frame_sender_sp_offset * wordSize));
999  leave();                           // remove frame anchor
1000  pop(ret_addr);                     // get return address
1001  mov(rsp, rbx);                     // set sp to sender sp
1002#ifndef _LP64
1003  if (UseSSE) {
1004    // float and double are returned in xmm register in SSE-mode
1005    if (state == ftos && UseSSE >= 1) {
1006      subptr(rsp, wordSize);
1007      fstp_s(Address(rsp, 0));
1008      movflt(xmm0, Address(rsp, 0));
1009      addptr(rsp, wordSize);
1010    } else if (state == dtos && UseSSE >= 2) {
1011      subptr(rsp, 2*wordSize);
1012      fstp_d(Address(rsp, 0));
1013      movdbl(xmm0, Address(rsp, 0));
1014      addptr(rsp, 2*wordSize);
1015    }
1016  }
1017#endif // _LP64
1018}
1019#endif // !CC_INTERP
1020
1021void InterpreterMacroAssembler::get_method_counters(Register method,
1022                                                    Register mcs, Label& skip) {
1023  Label has_counters;
1024  movptr(mcs, Address(method, Method::method_counters_offset()));
1025  testptr(mcs, mcs);
1026  jcc(Assembler::notZero, has_counters);
1027  call_VM(noreg, CAST_FROM_FN_PTR(address,
1028          InterpreterRuntime::build_method_counters), method);
1029  movptr(mcs, Address(method,Method::method_counters_offset()));
1030  testptr(mcs, mcs);
1031  jcc(Assembler::zero, skip); // No MethodCounters allocated, OutOfMemory
1032  bind(has_counters);
1033}
1034
1035
1036// Lock object
1037//
1038// Args:
1039//      rdx, c_rarg1: BasicObjectLock to be used for locking
1040//
1041// Kills:
1042//      rax, rbx
1043void InterpreterMacroAssembler::lock_object(Register lock_reg) {
1044  assert(lock_reg == LP64_ONLY(c_rarg1) NOT_LP64(rdx),
1045         "The argument is only for looks. It must be c_rarg1");
1046
1047  if (UseHeavyMonitors) {
1048    call_VM(noreg,
1049            CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter),
1050            lock_reg);
1051  } else {
1052    Label done;
1053
1054    const Register swap_reg = rax; // Must use rax for cmpxchg instruction
1055    const Register tmp_reg = rbx; // Will be passed to biased_locking_enter to avoid a
1056                                  // problematic case where tmp_reg = no_reg.
1057    const Register obj_reg = LP64_ONLY(c_rarg3) NOT_LP64(rcx); // Will contain the oop
1058
1059    const int obj_offset = BasicObjectLock::obj_offset_in_bytes();
1060    const int lock_offset = BasicObjectLock::lock_offset_in_bytes ();
1061    const int mark_offset = lock_offset +
1062                            BasicLock::displaced_header_offset_in_bytes();
1063
1064    Label slow_case;
1065
1066    // Load object pointer into obj_reg
1067    movptr(obj_reg, Address(lock_reg, obj_offset));
1068
1069    if (UseBiasedLocking) {
1070      biased_locking_enter(lock_reg, obj_reg, swap_reg, tmp_reg, false, done, &slow_case);
1071    }
1072
1073    // Load immediate 1 into swap_reg %rax
1074    movl(swap_reg, (int32_t)1);
1075
1076    // Load (object->mark() | 1) into swap_reg %rax
1077    orptr(swap_reg, Address(obj_reg, 0));
1078
1079    // Save (object->mark() | 1) into BasicLock's displaced header
1080    movptr(Address(lock_reg, mark_offset), swap_reg);
1081
1082    assert(lock_offset == 0,
1083           "displached header must be first word in BasicObjectLock");
1084
1085    if (os::is_MP()) lock();
1086    cmpxchgptr(lock_reg, Address(obj_reg, 0));
1087    if (PrintBiasedLockingStatistics) {
1088      cond_inc32(Assembler::zero,
1089                 ExternalAddress((address) BiasedLocking::fast_path_entry_count_addr()));
1090    }
1091    jcc(Assembler::zero, done);
1092
1093    const int zero_bits = LP64_ONLY(7) NOT_LP64(3);
1094
1095    // Test if the oopMark is an obvious stack pointer, i.e.,
1096    //  1) (mark & zero_bits) == 0, and
1097    //  2) rsp <= mark < mark + os::pagesize()
1098    //
1099    // These 3 tests can be done by evaluating the following
1100    // expression: ((mark - rsp) & (zero_bits - os::vm_page_size())),
1101    // assuming both stack pointer and pagesize have their
1102    // least significant bits clear.
1103    // NOTE: the oopMark is in swap_reg %rax as the result of cmpxchg
1104    subptr(swap_reg, rsp);
1105    andptr(swap_reg, zero_bits - os::vm_page_size());
1106
1107    // Save the test result, for recursive case, the result is zero
1108    movptr(Address(lock_reg, mark_offset), swap_reg);
1109
1110    if (PrintBiasedLockingStatistics) {
1111      cond_inc32(Assembler::zero,
1112                 ExternalAddress((address) BiasedLocking::fast_path_entry_count_addr()));
1113    }
1114    jcc(Assembler::zero, done);
1115
1116    bind(slow_case);
1117
1118    // Call the runtime routine for slow case
1119    call_VM(noreg,
1120            CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter),
1121            lock_reg);
1122
1123    bind(done);
1124  }
1125}
1126
1127
1128// Unlocks an object. Used in monitorexit bytecode and
1129// remove_activation.  Throws an IllegalMonitorException if object is
1130// not locked by current thread.
1131//
1132// Args:
1133//      rdx, c_rarg1: BasicObjectLock for lock
1134//
1135// Kills:
1136//      rax
1137//      c_rarg0, c_rarg1, c_rarg2, c_rarg3, ... (param regs)
1138//      rscratch1, rscratch2 (scratch regs)
1139// rax, rbx, rcx, rdx
1140void InterpreterMacroAssembler::unlock_object(Register lock_reg) {
1141  assert(lock_reg == LP64_ONLY(c_rarg1) NOT_LP64(rdx),
1142         "The argument is only for looks. It must be c_rarg1");
1143
1144  if (UseHeavyMonitors) {
1145    call_VM(noreg,
1146            CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit),
1147            lock_reg);
1148  } else {
1149    Label done;
1150
1151    const Register swap_reg   = rax;  // Must use rax for cmpxchg instruction
1152    const Register header_reg = LP64_ONLY(c_rarg2) NOT_LP64(rbx);  // Will contain the old oopMark
1153    const Register obj_reg    = LP64_ONLY(c_rarg3) NOT_LP64(rcx);  // Will contain the oop
1154
1155    save_bcp(); // Save in case of exception
1156
1157    // Convert from BasicObjectLock structure to object and BasicLock
1158    // structure Store the BasicLock address into %rax
1159    lea(swap_reg, Address(lock_reg, BasicObjectLock::lock_offset_in_bytes()));
1160
1161    // Load oop into obj_reg(%c_rarg3)
1162    movptr(obj_reg, Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()));
1163
1164    // Free entry
1165    movptr(Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()), (int32_t)NULL_WORD);
1166
1167    if (UseBiasedLocking) {
1168      biased_locking_exit(obj_reg, header_reg, done);
1169    }
1170
1171    // Load the old header from BasicLock structure
1172    movptr(header_reg, Address(swap_reg,
1173                               BasicLock::displaced_header_offset_in_bytes()));
1174
1175    // Test for recursion
1176    testptr(header_reg, header_reg);
1177
1178    // zero for recursive case
1179    jcc(Assembler::zero, done);
1180
1181    // Atomic swap back the old header
1182    if (os::is_MP()) lock();
1183    cmpxchgptr(header_reg, Address(obj_reg, 0));
1184
1185    // zero for recursive case
1186    jcc(Assembler::zero, done);
1187
1188    // Call the runtime routine for slow case.
1189    movptr(Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()),
1190         obj_reg); // restore obj
1191    call_VM(noreg,
1192            CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit),
1193            lock_reg);
1194
1195    bind(done);
1196
1197    restore_bcp();
1198  }
1199}
1200#ifndef CC_INTERP
1201void InterpreterMacroAssembler::test_method_data_pointer(Register mdp,
1202                                                         Label& zero_continue) {
1203  assert(ProfileInterpreter, "must be profiling interpreter");
1204  movptr(mdp, Address(rbp, frame::interpreter_frame_mdp_offset * wordSize));
1205  testptr(mdp, mdp);
1206  jcc(Assembler::zero, zero_continue);
1207}
1208
1209
1210// Set the method data pointer for the current bcp.
1211void InterpreterMacroAssembler::set_method_data_pointer_for_bcp() {
1212  assert(ProfileInterpreter, "must be profiling interpreter");
1213  Label set_mdp;
1214  push(rax);
1215  push(rbx);
1216
1217  get_method(rbx);
1218  // Test MDO to avoid the call if it is NULL.
1219  movptr(rax, Address(rbx, in_bytes(Method::method_data_offset())));
1220  testptr(rax, rax);
1221  jcc(Assembler::zero, set_mdp);
1222  // rbx: method
1223  // _bcp_register: bcp
1224  call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::bcp_to_di), rbx, _bcp_register);
1225  // rax: mdi
1226  // mdo is guaranteed to be non-zero here, we checked for it before the call.
1227  movptr(rbx, Address(rbx, in_bytes(Method::method_data_offset())));
1228  addptr(rbx, in_bytes(MethodData::data_offset()));
1229  addptr(rax, rbx);
1230  bind(set_mdp);
1231  movptr(Address(rbp, frame::interpreter_frame_mdp_offset * wordSize), rax);
1232  pop(rbx);
1233  pop(rax);
1234}
1235
1236void InterpreterMacroAssembler::verify_method_data_pointer() {
1237  assert(ProfileInterpreter, "must be profiling interpreter");
1238#ifdef ASSERT
1239  Label verify_continue;
1240  push(rax);
1241  push(rbx);
1242  Register arg3_reg = LP64_ONLY(c_rarg3) NOT_LP64(rcx);
1243  Register arg2_reg = LP64_ONLY(c_rarg2) NOT_LP64(rdx);
1244  push(arg3_reg);
1245  push(arg2_reg);
1246  test_method_data_pointer(arg3_reg, verify_continue); // If mdp is zero, continue
1247  get_method(rbx);
1248
1249  // If the mdp is valid, it will point to a DataLayout header which is
1250  // consistent with the bcp.  The converse is highly probable also.
1251  load_unsigned_short(arg2_reg,
1252                      Address(arg3_reg, in_bytes(DataLayout::bci_offset())));
1253  addptr(arg2_reg, Address(rbx, Method::const_offset()));
1254  lea(arg2_reg, Address(arg2_reg, ConstMethod::codes_offset()));
1255  cmpptr(arg2_reg, _bcp_register);
1256  jcc(Assembler::equal, verify_continue);
1257  // rbx: method
1258  // _bcp_register: bcp
1259  // c_rarg3: mdp
1260  call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::verify_mdp),
1261               rbx, _bcp_register, arg3_reg);
1262  bind(verify_continue);
1263  pop(arg2_reg);
1264  pop(arg3_reg);
1265  pop(rbx);
1266  pop(rax);
1267#endif // ASSERT
1268}
1269
1270
1271void InterpreterMacroAssembler::set_mdp_data_at(Register mdp_in,
1272                                                int constant,
1273                                                Register value) {
1274  assert(ProfileInterpreter, "must be profiling interpreter");
1275  Address data(mdp_in, constant);
1276  movptr(data, value);
1277}
1278
1279
1280void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in,
1281                                                      int constant,
1282                                                      bool decrement) {
1283  // Counter address
1284  Address data(mdp_in, constant);
1285
1286  increment_mdp_data_at(data, decrement);
1287}
1288
1289void InterpreterMacroAssembler::increment_mdp_data_at(Address data,
1290                                                      bool decrement) {
1291  assert(ProfileInterpreter, "must be profiling interpreter");
1292  // %%% this does 64bit counters at best it is wasting space
1293  // at worst it is a rare bug when counters overflow
1294
1295  if (decrement) {
1296    // Decrement the register.  Set condition codes.
1297    addptr(data, (int32_t) -DataLayout::counter_increment);
1298    // If the decrement causes the counter to overflow, stay negative
1299    Label L;
1300    jcc(Assembler::negative, L);
1301    addptr(data, (int32_t) DataLayout::counter_increment);
1302    bind(L);
1303  } else {
1304    assert(DataLayout::counter_increment == 1,
1305           "flow-free idiom only works with 1");
1306    // Increment the register.  Set carry flag.
1307    addptr(data, DataLayout::counter_increment);
1308    // If the increment causes the counter to overflow, pull back by 1.
1309    sbbptr(data, (int32_t)0);
1310  }
1311}
1312
1313
1314void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in,
1315                                                      Register reg,
1316                                                      int constant,
1317                                                      bool decrement) {
1318  Address data(mdp_in, reg, Address::times_1, constant);
1319
1320  increment_mdp_data_at(data, decrement);
1321}
1322
1323void InterpreterMacroAssembler::set_mdp_flag_at(Register mdp_in,
1324                                                int flag_byte_constant) {
1325  assert(ProfileInterpreter, "must be profiling interpreter");
1326  int header_offset = in_bytes(DataLayout::header_offset());
1327  int header_bits = DataLayout::flag_mask_to_header_mask(flag_byte_constant);
1328  // Set the flag
1329  orl(Address(mdp_in, header_offset), header_bits);
1330}
1331
1332
1333
1334void InterpreterMacroAssembler::test_mdp_data_at(Register mdp_in,
1335                                                 int offset,
1336                                                 Register value,
1337                                                 Register test_value_out,
1338                                                 Label& not_equal_continue) {
1339  assert(ProfileInterpreter, "must be profiling interpreter");
1340  if (test_value_out == noreg) {
1341    cmpptr(value, Address(mdp_in, offset));
1342  } else {
1343    // Put the test value into a register, so caller can use it:
1344    movptr(test_value_out, Address(mdp_in, offset));
1345    cmpptr(test_value_out, value);
1346  }
1347  jcc(Assembler::notEqual, not_equal_continue);
1348}
1349
1350
1351void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in,
1352                                                     int offset_of_disp) {
1353  assert(ProfileInterpreter, "must be profiling interpreter");
1354  Address disp_address(mdp_in, offset_of_disp);
1355  addptr(mdp_in, disp_address);
1356  movptr(Address(rbp, frame::interpreter_frame_mdp_offset * wordSize), mdp_in);
1357}
1358
1359
1360void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in,
1361                                                     Register reg,
1362                                                     int offset_of_disp) {
1363  assert(ProfileInterpreter, "must be profiling interpreter");
1364  Address disp_address(mdp_in, reg, Address::times_1, offset_of_disp);
1365  addptr(mdp_in, disp_address);
1366  movptr(Address(rbp, frame::interpreter_frame_mdp_offset * wordSize), mdp_in);
1367}
1368
1369
1370void InterpreterMacroAssembler::update_mdp_by_constant(Register mdp_in,
1371                                                       int constant) {
1372  assert(ProfileInterpreter, "must be profiling interpreter");
1373  addptr(mdp_in, constant);
1374  movptr(Address(rbp, frame::interpreter_frame_mdp_offset * wordSize), mdp_in);
1375}
1376
1377
1378void InterpreterMacroAssembler::update_mdp_for_ret(Register return_bci) {
1379  assert(ProfileInterpreter, "must be profiling interpreter");
1380  push(return_bci); // save/restore across call_VM
1381  call_VM(noreg,
1382          CAST_FROM_FN_PTR(address, InterpreterRuntime::update_mdp_for_ret),
1383          return_bci);
1384  pop(return_bci);
1385}
1386
1387
1388void InterpreterMacroAssembler::profile_taken_branch(Register mdp,
1389                                                     Register bumped_count) {
1390  if (ProfileInterpreter) {
1391    Label profile_continue;
1392
1393    // If no method data exists, go to profile_continue.
1394    // Otherwise, assign to mdp
1395    test_method_data_pointer(mdp, profile_continue);
1396
1397    // We are taking a branch.  Increment the taken count.
1398    // We inline increment_mdp_data_at to return bumped_count in a register
1399    //increment_mdp_data_at(mdp, in_bytes(JumpData::taken_offset()));
1400    Address data(mdp, in_bytes(JumpData::taken_offset()));
1401    movptr(bumped_count, data);
1402    assert(DataLayout::counter_increment == 1,
1403            "flow-free idiom only works with 1");
1404    addptr(bumped_count, DataLayout::counter_increment);
1405    sbbptr(bumped_count, 0);
1406    movptr(data, bumped_count); // Store back out
1407
1408    // The method data pointer needs to be updated to reflect the new target.
1409    update_mdp_by_offset(mdp, in_bytes(JumpData::displacement_offset()));
1410    bind(profile_continue);
1411  }
1412}
1413
1414
1415void InterpreterMacroAssembler::profile_not_taken_branch(Register mdp) {
1416  if (ProfileInterpreter) {
1417    Label profile_continue;
1418
1419    // If no method data exists, go to profile_continue.
1420    test_method_data_pointer(mdp, profile_continue);
1421
1422    // We are taking a branch.  Increment the not taken count.
1423    increment_mdp_data_at(mdp, in_bytes(BranchData::not_taken_offset()));
1424
1425    // The method data pointer needs to be updated to correspond to
1426    // the next bytecode
1427    update_mdp_by_constant(mdp, in_bytes(BranchData::branch_data_size()));
1428    bind(profile_continue);
1429  }
1430}
1431
1432void InterpreterMacroAssembler::profile_call(Register mdp) {
1433  if (ProfileInterpreter) {
1434    Label profile_continue;
1435
1436    // If no method data exists, go to profile_continue.
1437    test_method_data_pointer(mdp, profile_continue);
1438
1439    // We are making a call.  Increment the count.
1440    increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1441
1442    // The method data pointer needs to be updated to reflect the new target.
1443    update_mdp_by_constant(mdp, in_bytes(CounterData::counter_data_size()));
1444    bind(profile_continue);
1445  }
1446}
1447
1448
1449void InterpreterMacroAssembler::profile_final_call(Register mdp) {
1450  if (ProfileInterpreter) {
1451    Label profile_continue;
1452
1453    // If no method data exists, go to profile_continue.
1454    test_method_data_pointer(mdp, profile_continue);
1455
1456    // We are making a call.  Increment the count.
1457    increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1458
1459    // The method data pointer needs to be updated to reflect the new target.
1460    update_mdp_by_constant(mdp,
1461                           in_bytes(VirtualCallData::
1462                                    virtual_call_data_size()));
1463    bind(profile_continue);
1464  }
1465}
1466
1467
1468void InterpreterMacroAssembler::profile_virtual_call(Register receiver,
1469                                                     Register mdp,
1470                                                     Register reg2,
1471                                                     bool receiver_can_be_null) {
1472  if (ProfileInterpreter) {
1473    Label profile_continue;
1474
1475    // If no method data exists, go to profile_continue.
1476    test_method_data_pointer(mdp, profile_continue);
1477
1478    Label skip_receiver_profile;
1479    if (receiver_can_be_null) {
1480      Label not_null;
1481      testptr(receiver, receiver);
1482      jccb(Assembler::notZero, not_null);
1483      // We are making a call.  Increment the count for null receiver.
1484      increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1485      jmp(skip_receiver_profile);
1486      bind(not_null);
1487    }
1488
1489    // Record the receiver type.
1490    record_klass_in_profile(receiver, mdp, reg2, true);
1491    bind(skip_receiver_profile);
1492
1493    // The method data pointer needs to be updated to reflect the new target.
1494    update_mdp_by_constant(mdp,
1495                           in_bytes(VirtualCallData::
1496                                    virtual_call_data_size()));
1497    bind(profile_continue);
1498  }
1499}
1500
1501// This routine creates a state machine for updating the multi-row
1502// type profile at a virtual call site (or other type-sensitive bytecode).
1503// The machine visits each row (of receiver/count) until the receiver type
1504// is found, or until it runs out of rows.  At the same time, it remembers
1505// the location of the first empty row.  (An empty row records null for its
1506// receiver, and can be allocated for a newly-observed receiver type.)
1507// Because there are two degrees of freedom in the state, a simple linear
1508// search will not work; it must be a decision tree.  Hence this helper
1509// function is recursive, to generate the required tree structured code.
1510// It's the interpreter, so we are trading off code space for speed.
1511// See below for example code.
1512void InterpreterMacroAssembler::record_klass_in_profile_helper(
1513                                        Register receiver, Register mdp,
1514                                        Register reg2, int start_row,
1515                                        Label& done, bool is_virtual_call) {
1516  if (TypeProfileWidth == 0) {
1517    if (is_virtual_call) {
1518      increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1519    }
1520    return;
1521  }
1522
1523  int last_row = VirtualCallData::row_limit() - 1;
1524  assert(start_row <= last_row, "must be work left to do");
1525  // Test this row for both the receiver and for null.
1526  // Take any of three different outcomes:
1527  //   1. found receiver => increment count and goto done
1528  //   2. found null => keep looking for case 1, maybe allocate this cell
1529  //   3. found something else => keep looking for cases 1 and 2
1530  // Case 3 is handled by a recursive call.
1531  for (int row = start_row; row <= last_row; row++) {
1532    Label next_test;
1533    bool test_for_null_also = (row == start_row);
1534
1535    // See if the receiver is receiver[n].
1536    int recvr_offset = in_bytes(VirtualCallData::receiver_offset(row));
1537    test_mdp_data_at(mdp, recvr_offset, receiver,
1538                     (test_for_null_also ? reg2 : noreg),
1539                     next_test);
1540    // (Reg2 now contains the receiver from the CallData.)
1541
1542    // The receiver is receiver[n].  Increment count[n].
1543    int count_offset = in_bytes(VirtualCallData::receiver_count_offset(row));
1544    increment_mdp_data_at(mdp, count_offset);
1545    jmp(done);
1546    bind(next_test);
1547
1548    if (test_for_null_also) {
1549      Label found_null;
1550      // Failed the equality check on receiver[n]...  Test for null.
1551      testptr(reg2, reg2);
1552      if (start_row == last_row) {
1553        // The only thing left to do is handle the null case.
1554        if (is_virtual_call) {
1555          jccb(Assembler::zero, found_null);
1556          // Receiver did not match any saved receiver and there is no empty row for it.
1557          // Increment total counter to indicate polymorphic case.
1558          increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1559          jmp(done);
1560          bind(found_null);
1561        } else {
1562          jcc(Assembler::notZero, done);
1563        }
1564        break;
1565      }
1566      // Since null is rare, make it be the branch-taken case.
1567      jcc(Assembler::zero, found_null);
1568
1569      // Put all the "Case 3" tests here.
1570      record_klass_in_profile_helper(receiver, mdp, reg2, start_row + 1, done, is_virtual_call);
1571
1572      // Found a null.  Keep searching for a matching receiver,
1573      // but remember that this is an empty (unused) slot.
1574      bind(found_null);
1575    }
1576  }
1577
1578  // In the fall-through case, we found no matching receiver, but we
1579  // observed the receiver[start_row] is NULL.
1580
1581  // Fill in the receiver field and increment the count.
1582  int recvr_offset = in_bytes(VirtualCallData::receiver_offset(start_row));
1583  set_mdp_data_at(mdp, recvr_offset, receiver);
1584  int count_offset = in_bytes(VirtualCallData::receiver_count_offset(start_row));
1585  movl(reg2, DataLayout::counter_increment);
1586  set_mdp_data_at(mdp, count_offset, reg2);
1587  if (start_row > 0) {
1588    jmp(done);
1589  }
1590}
1591
1592// Example state machine code for three profile rows:
1593//   // main copy of decision tree, rooted at row[1]
1594//   if (row[0].rec == rec) { row[0].incr(); goto done; }
1595//   if (row[0].rec != NULL) {
1596//     // inner copy of decision tree, rooted at row[1]
1597//     if (row[1].rec == rec) { row[1].incr(); goto done; }
1598//     if (row[1].rec != NULL) {
1599//       // degenerate decision tree, rooted at row[2]
1600//       if (row[2].rec == rec) { row[2].incr(); goto done; }
1601//       if (row[2].rec != NULL) { count.incr(); goto done; } // overflow
1602//       row[2].init(rec); goto done;
1603//     } else {
1604//       // remember row[1] is empty
1605//       if (row[2].rec == rec) { row[2].incr(); goto done; }
1606//       row[1].init(rec); goto done;
1607//     }
1608//   } else {
1609//     // remember row[0] is empty
1610//     if (row[1].rec == rec) { row[1].incr(); goto done; }
1611//     if (row[2].rec == rec) { row[2].incr(); goto done; }
1612//     row[0].init(rec); goto done;
1613//   }
1614//   done:
1615
1616void InterpreterMacroAssembler::record_klass_in_profile(Register receiver,
1617                                                        Register mdp, Register reg2,
1618                                                        bool is_virtual_call) {
1619  assert(ProfileInterpreter, "must be profiling");
1620  Label done;
1621
1622  record_klass_in_profile_helper(receiver, mdp, reg2, 0, done, is_virtual_call);
1623
1624  bind (done);
1625}
1626
1627void InterpreterMacroAssembler::profile_ret(Register return_bci,
1628                                            Register mdp) {
1629  if (ProfileInterpreter) {
1630    Label profile_continue;
1631    uint row;
1632
1633    // If no method data exists, go to profile_continue.
1634    test_method_data_pointer(mdp, profile_continue);
1635
1636    // Update the total ret count.
1637    increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1638
1639    for (row = 0; row < RetData::row_limit(); row++) {
1640      Label next_test;
1641
1642      // See if return_bci is equal to bci[n]:
1643      test_mdp_data_at(mdp,
1644                       in_bytes(RetData::bci_offset(row)),
1645                       return_bci, noreg,
1646                       next_test);
1647
1648      // return_bci is equal to bci[n].  Increment the count.
1649      increment_mdp_data_at(mdp, in_bytes(RetData::bci_count_offset(row)));
1650
1651      // The method data pointer needs to be updated to reflect the new target.
1652      update_mdp_by_offset(mdp,
1653                           in_bytes(RetData::bci_displacement_offset(row)));
1654      jmp(profile_continue);
1655      bind(next_test);
1656    }
1657
1658    update_mdp_for_ret(return_bci);
1659
1660    bind(profile_continue);
1661  }
1662}
1663
1664
1665void InterpreterMacroAssembler::profile_null_seen(Register mdp) {
1666  if (ProfileInterpreter) {
1667    Label profile_continue;
1668
1669    // If no method data exists, go to profile_continue.
1670    test_method_data_pointer(mdp, profile_continue);
1671
1672    set_mdp_flag_at(mdp, BitData::null_seen_byte_constant());
1673
1674    // The method data pointer needs to be updated.
1675    int mdp_delta = in_bytes(BitData::bit_data_size());
1676    if (TypeProfileCasts) {
1677      mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
1678    }
1679    update_mdp_by_constant(mdp, mdp_delta);
1680
1681    bind(profile_continue);
1682  }
1683}
1684
1685
1686void InterpreterMacroAssembler::profile_typecheck_failed(Register mdp) {
1687  if (ProfileInterpreter && TypeProfileCasts) {
1688    Label profile_continue;
1689
1690    // If no method data exists, go to profile_continue.
1691    test_method_data_pointer(mdp, profile_continue);
1692
1693    int count_offset = in_bytes(CounterData::count_offset());
1694    // Back up the address, since we have already bumped the mdp.
1695    count_offset -= in_bytes(VirtualCallData::virtual_call_data_size());
1696
1697    // *Decrement* the counter.  We expect to see zero or small negatives.
1698    increment_mdp_data_at(mdp, count_offset, true);
1699
1700    bind (profile_continue);
1701  }
1702}
1703
1704
1705void InterpreterMacroAssembler::profile_typecheck(Register mdp, Register klass, Register reg2) {
1706  if (ProfileInterpreter) {
1707    Label profile_continue;
1708
1709    // If no method data exists, go to profile_continue.
1710    test_method_data_pointer(mdp, profile_continue);
1711
1712    // The method data pointer needs to be updated.
1713    int mdp_delta = in_bytes(BitData::bit_data_size());
1714    if (TypeProfileCasts) {
1715      mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
1716
1717      // Record the object type.
1718      record_klass_in_profile(klass, mdp, reg2, false);
1719      NOT_LP64(assert(reg2 == rdi, "we know how to fix this blown reg");)
1720      NOT_LP64(restore_locals();)         // Restore EDI
1721    }
1722    update_mdp_by_constant(mdp, mdp_delta);
1723
1724    bind(profile_continue);
1725  }
1726}
1727
1728
1729void InterpreterMacroAssembler::profile_switch_default(Register mdp) {
1730  if (ProfileInterpreter) {
1731    Label profile_continue;
1732
1733    // If no method data exists, go to profile_continue.
1734    test_method_data_pointer(mdp, profile_continue);
1735
1736    // Update the default case count
1737    increment_mdp_data_at(mdp,
1738                          in_bytes(MultiBranchData::default_count_offset()));
1739
1740    // The method data pointer needs to be updated.
1741    update_mdp_by_offset(mdp,
1742                         in_bytes(MultiBranchData::
1743                                  default_displacement_offset()));
1744
1745    bind(profile_continue);
1746  }
1747}
1748
1749
1750void InterpreterMacroAssembler::profile_switch_case(Register index,
1751                                                    Register mdp,
1752                                                    Register reg2) {
1753  if (ProfileInterpreter) {
1754    Label profile_continue;
1755
1756    // If no method data exists, go to profile_continue.
1757    test_method_data_pointer(mdp, profile_continue);
1758
1759    // Build the base (index * per_case_size_in_bytes()) +
1760    // case_array_offset_in_bytes()
1761    movl(reg2, in_bytes(MultiBranchData::per_case_size()));
1762    imulptr(index, reg2); // XXX l ?
1763    addptr(index, in_bytes(MultiBranchData::case_array_offset())); // XXX l ?
1764
1765    // Update the case count
1766    increment_mdp_data_at(mdp,
1767                          index,
1768                          in_bytes(MultiBranchData::relative_count_offset()));
1769
1770    // The method data pointer needs to be updated.
1771    update_mdp_by_offset(mdp,
1772                         index,
1773                         in_bytes(MultiBranchData::
1774                                  relative_displacement_offset()));
1775
1776    bind(profile_continue);
1777  }
1778}
1779
1780
1781
1782void InterpreterMacroAssembler::verify_oop(Register reg, TosState state) {
1783  if (state == atos) {
1784    MacroAssembler::verify_oop(reg);
1785  }
1786}
1787
1788void InterpreterMacroAssembler::verify_FPU(int stack_depth, TosState state) {
1789#ifndef _LP64
1790  if (state == ftos || state == dtos) MacroAssembler::verify_FPU(stack_depth);
1791#endif
1792}
1793
1794// Jump if ((*counter_addr += increment) & mask) satisfies the condition.
1795void InterpreterMacroAssembler::increment_mask_and_jump(Address counter_addr,
1796                                                        int increment, Address mask,
1797                                                        Register scratch, bool preloaded,
1798                                                        Condition cond, Label* where) {
1799  if (!preloaded) {
1800    movl(scratch, counter_addr);
1801  }
1802  incrementl(scratch, increment);
1803  movl(counter_addr, scratch);
1804  andl(scratch, mask);
1805  jcc(cond, *where);
1806}
1807#endif // CC_INTERP
1808
1809void InterpreterMacroAssembler::notify_method_entry() {
1810  // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to
1811  // track stack depth.  If it is possible to enter interp_only_mode we add
1812  // the code to check if the event should be sent.
1813  Register rthread = LP64_ONLY(r15_thread) NOT_LP64(rcx);
1814  Register rarg = LP64_ONLY(c_rarg1) NOT_LP64(rbx);
1815  if (JvmtiExport::can_post_interpreter_events()) {
1816    Label L;
1817    NOT_LP64(get_thread(rthread);)
1818    movl(rdx, Address(rthread, JavaThread::interp_only_mode_offset()));
1819    testl(rdx, rdx);
1820    jcc(Assembler::zero, L);
1821    call_VM(noreg, CAST_FROM_FN_PTR(address,
1822                                    InterpreterRuntime::post_method_entry));
1823    bind(L);
1824  }
1825
1826  {
1827    SkipIfEqual skip(this, &DTraceMethodProbes, false);
1828    NOT_LP64(get_thread(rthread);)
1829    get_method(rarg);
1830    call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry),
1831                 rthread, rarg);
1832  }
1833
1834  // RedefineClasses() tracing support for obsolete method entry
1835  if (RC_TRACE_IN_RANGE(0x00001000, 0x00002000)) {
1836    NOT_LP64(get_thread(rthread);)
1837    get_method(rarg);
1838    call_VM_leaf(
1839      CAST_FROM_FN_PTR(address, SharedRuntime::rc_trace_method_entry),
1840      rthread, rarg);
1841  }
1842}
1843
1844
1845void InterpreterMacroAssembler::notify_method_exit(
1846    TosState state, NotifyMethodExitMode mode) {
1847  // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to
1848  // track stack depth.  If it is possible to enter interp_only_mode we add
1849  // the code to check if the event should be sent.
1850  Register rthread = LP64_ONLY(r15_thread) NOT_LP64(rcx);
1851  Register rarg = LP64_ONLY(c_rarg1) NOT_LP64(rbx);
1852  if (mode == NotifyJVMTI && JvmtiExport::can_post_interpreter_events()) {
1853    Label L;
1854    // Note: frame::interpreter_frame_result has a dependency on how the
1855    // method result is saved across the call to post_method_exit. If this
1856    // is changed then the interpreter_frame_result implementation will
1857    // need to be updated too.
1858
1859    // For c++ interpreter the result is always stored at a known location in the frame
1860    // template interpreter will leave it on the top of the stack.
1861    NOT_CC_INTERP(push(state);)
1862    NOT_LP64(get_thread(rthread);)
1863    movl(rdx, Address(rthread, JavaThread::interp_only_mode_offset()));
1864    testl(rdx, rdx);
1865    jcc(Assembler::zero, L);
1866    call_VM(noreg,
1867            CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_exit));
1868    bind(L);
1869    NOT_CC_INTERP(pop(state));
1870  }
1871
1872  {
1873    SkipIfEqual skip(this, &DTraceMethodProbes, false);
1874    NOT_CC_INTERP(push(state));
1875    NOT_LP64(get_thread(rthread);)
1876    get_method(rarg);
1877    call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit),
1878                 rthread, rarg);
1879    NOT_CC_INTERP(pop(state));
1880  }
1881}
1882