1 /*
2  * Copyright (c) 1997, 2018, 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 "asm/macroAssembler.inline.hpp"
27 #include "interp_masm_sparc.hpp"
28 #include "interpreter/interpreter.hpp"
29 #include "interpreter/interpreterRuntime.hpp"
30 #include "logging/log.hpp"
31 #include "oops/arrayOop.hpp"
32 #include "oops/markOop.hpp"
33 #include "oops/methodData.hpp"
34 #include "oops/method.hpp"
35 #include "oops/methodCounters.hpp"
36 #include "prims/jvmtiExport.hpp"
37 #include "prims/jvmtiThreadState.hpp"
38 #include "runtime/basicLock.hpp"
39 #include "runtime/biasedLocking.hpp"
40 #include "runtime/frame.inline.hpp"
41 #include "runtime/safepointMechanism.hpp"
42 #include "runtime/sharedRuntime.hpp"
43 #include "runtime/thread.inline.hpp"
44 #include "utilities/align.hpp"
45 
46 // Implementation of InterpreterMacroAssembler
47 
48 // This file specializes the assember with interpreter-specific macros
49 
50 const Address InterpreterMacroAssembler::l_tmp(FP, (frame::interpreter_frame_l_scratch_fp_offset * wordSize) + STACK_BIAS);
51 const Address InterpreterMacroAssembler::d_tmp(FP, (frame::interpreter_frame_d_scratch_fp_offset * wordSize) + STACK_BIAS);
52 
jump_to_entry(address entry)53 void InterpreterMacroAssembler::jump_to_entry(address entry) {
54   assert(entry, "Entry must have been generated by now");
55   AddressLiteral al(entry);
56   jump_to(al, G3_scratch);
57   delayed()->nop();
58 }
59 
compute_extra_locals_size_in_bytes(Register args_size,Register locals_size,Register delta)60 void InterpreterMacroAssembler::compute_extra_locals_size_in_bytes(Register args_size, Register locals_size, Register delta) {
61   // Note: this algorithm is also used by C1's OSR entry sequence.
62   // Any changes should also be applied to CodeEmitter::emit_osr_entry().
63   assert_different_registers(args_size, locals_size);
64   // max_locals*2 for TAGS.  Assumes that args_size has already been adjusted.
65   subcc(locals_size, args_size, delta);// extra space for non-arguments locals in words
66   // Use br/mov combination because it works on both V8 and V9 and is
67   // faster.
68   Label skip_move;
69   br(Assembler::negative, true, Assembler::pt, skip_move);
70   delayed()->mov(G0, delta);
71   bind(skip_move);
72   align_up(delta, WordsPerLong);       // make multiple of 2 (SP must be 2-word aligned)
73   sll(delta, LogBytesPerWord, delta);  // extra space for locals in bytes
74 }
75 
76 // Dispatch code executed in the prolog of a bytecode which does not do it's
77 // own dispatch. The dispatch address is computed and placed in IdispatchAddress
dispatch_prolog(TosState state,int bcp_incr)78 void InterpreterMacroAssembler::dispatch_prolog(TosState state, int bcp_incr) {
79   assert_not_delayed();
80   ldub( Lbcp, bcp_incr, Lbyte_code);                    // load next bytecode
81   // dispatch table to use
82   AddressLiteral tbl(Interpreter::dispatch_table(state));
83   sll(Lbyte_code, LogBytesPerWord, Lbyte_code);         // multiply by wordSize
84   set(tbl, G3_scratch);                                 // compute addr of table
85   ld_ptr(G3_scratch, Lbyte_code, IdispatchAddress);     // get entry addr
86 }
87 
88 
89 // Dispatch code executed in the epilog of a bytecode which does not do it's
90 // own dispatch. The dispatch address in IdispatchAddress is used for the
91 // dispatch.
dispatch_epilog(TosState state,int bcp_incr)92 void InterpreterMacroAssembler::dispatch_epilog(TosState state, int bcp_incr) {
93   assert_not_delayed();
94   verify_FPU(1, state);
95   interp_verify_oop(Otos_i, state, __FILE__, __LINE__);
96   jmp( IdispatchAddress, 0 );
97   if (bcp_incr != 0)  delayed()->inc(Lbcp, bcp_incr);
98   else                delayed()->nop();
99 }
100 
dispatch_next(TosState state,int bcp_incr,bool generate_poll)101 void InterpreterMacroAssembler::dispatch_next(TosState state, int bcp_incr, bool generate_poll) {
102   // %%%% consider branching to a single shared dispatch stub (for each bcp_incr)
103   assert_not_delayed();
104   ldub( Lbcp, bcp_incr, Lbyte_code);               // load next bytecode
105   dispatch_Lbyte_code(state, Interpreter::dispatch_table(state), bcp_incr, true, generate_poll);
106 }
107 
108 
dispatch_next_noverify_oop(TosState state,int bcp_incr)109 void InterpreterMacroAssembler::dispatch_next_noverify_oop(TosState state, int bcp_incr) {
110   // %%%% consider branching to a single shared dispatch stub (for each bcp_incr)
111   assert_not_delayed();
112   ldub( Lbcp, bcp_incr, Lbyte_code);               // load next bytecode
113   dispatch_Lbyte_code(state, Interpreter::dispatch_table(state), bcp_incr, false);
114 }
115 
116 
dispatch_via(TosState state,address * table)117 void InterpreterMacroAssembler::dispatch_via(TosState state, address* table) {
118   // load current bytecode
119   assert_not_delayed();
120   ldub( Lbcp, 0, Lbyte_code);               // load next bytecode
121   dispatch_base(state, table);
122 }
123 
124 
call_VM_leaf_base(Register java_thread,address entry_point,int number_of_arguments)125 void InterpreterMacroAssembler::call_VM_leaf_base(
126   Register java_thread,
127   address  entry_point,
128   int      number_of_arguments
129 ) {
130   if (!java_thread->is_valid())
131     java_thread = L7_thread_cache;
132   // super call
133   MacroAssembler::call_VM_leaf_base(java_thread, entry_point, number_of_arguments);
134 }
135 
136 
call_VM_base(Register oop_result,Register java_thread,Register last_java_sp,address entry_point,int number_of_arguments,bool check_exception)137 void InterpreterMacroAssembler::call_VM_base(
138   Register        oop_result,
139   Register        java_thread,
140   Register        last_java_sp,
141   address         entry_point,
142   int             number_of_arguments,
143   bool            check_exception
144 ) {
145   if (!java_thread->is_valid())
146     java_thread = L7_thread_cache;
147   // See class ThreadInVMfromInterpreter, which assumes that the interpreter
148   // takes responsibility for setting its own thread-state on call-out.
149   // However, ThreadInVMfromInterpreter resets the state to "in_Java".
150 
151   //save_bcp();                                  // save bcp
152   MacroAssembler::call_VM_base(oop_result, java_thread, last_java_sp, entry_point, number_of_arguments, check_exception);
153   //restore_bcp();                               // restore bcp
154   //restore_locals();                            // restore locals pointer
155 }
156 
157 
check_and_handle_popframe(Register scratch_reg)158 void InterpreterMacroAssembler::check_and_handle_popframe(Register scratch_reg) {
159   if (JvmtiExport::can_pop_frame()) {
160     Label L;
161 
162     // Check the "pending popframe condition" flag in the current thread
163     ld(G2_thread, JavaThread::popframe_condition_offset(), scratch_reg);
164 
165     // Initiate popframe handling only if it is not already being processed.  If the flag
166     // has the popframe_processing bit set, it means that this code is called *during* popframe
167     // handling - we don't want to reenter.
168     btst(JavaThread::popframe_pending_bit, scratch_reg);
169     br(zero, false, pt, L);
170     delayed()->nop();
171     btst(JavaThread::popframe_processing_bit, scratch_reg);
172     br(notZero, false, pt, L);
173     delayed()->nop();
174 
175     // Call Interpreter::remove_activation_preserving_args_entry() to get the
176     // address of the same-named entrypoint in the generated interpreter code.
177     call_VM_leaf(noreg, CAST_FROM_FN_PTR(address, Interpreter::remove_activation_preserving_args_entry));
178 
179     // Jump to Interpreter::_remove_activation_preserving_args_entry
180     jmpl(O0, G0, G0);
181     delayed()->nop();
182     bind(L);
183   }
184 }
185 
186 
load_earlyret_value(TosState state)187 void InterpreterMacroAssembler::load_earlyret_value(TosState state) {
188   Register thr_state = G4_scratch;
189   ld_ptr(G2_thread, JavaThread::jvmti_thread_state_offset(), thr_state);
190   const Address tos_addr(thr_state, JvmtiThreadState::earlyret_tos_offset());
191   const Address oop_addr(thr_state, JvmtiThreadState::earlyret_oop_offset());
192   const Address val_addr(thr_state, JvmtiThreadState::earlyret_value_offset());
193   switch (state) {
194   case ltos: ld_long(val_addr, Otos_l);                   break;
195   case atos: ld_ptr(oop_addr, Otos_l);
196              st_ptr(G0, oop_addr);                        break;
197   case btos:                                           // fall through
198   case ztos:                                           // fall through
199   case ctos:                                           // fall through
200   case stos:                                           // fall through
201   case itos: ld(val_addr, Otos_l1);                       break;
202   case ftos: ldf(FloatRegisterImpl::S, val_addr, Ftos_f); break;
203   case dtos: ldf(FloatRegisterImpl::D, val_addr, Ftos_d); break;
204   case vtos: /* nothing to do */                          break;
205   default  : ShouldNotReachHere();
206   }
207   // Clean up tos value in the jvmti thread state
208   or3(G0, ilgl, G3_scratch);
209   stw(G3_scratch, tos_addr);
210   st_long(G0, val_addr);
211   interp_verify_oop(Otos_i, state, __FILE__, __LINE__);
212 }
213 
214 
check_and_handle_earlyret(Register scratch_reg)215 void InterpreterMacroAssembler::check_and_handle_earlyret(Register scratch_reg) {
216   if (JvmtiExport::can_force_early_return()) {
217     Label L;
218     Register thr_state = G3_scratch;
219     ld_ptr(G2_thread, JavaThread::jvmti_thread_state_offset(), thr_state);
220     br_null_short(thr_state, pt, L); // if (thread->jvmti_thread_state() == NULL) exit;
221 
222     // Initiate earlyret handling only if it is not already being processed.
223     // If the flag has the earlyret_processing bit set, it means that this code
224     // is called *during* earlyret handling - we don't want to reenter.
225     ld(thr_state, JvmtiThreadState::earlyret_state_offset(), G4_scratch);
226     cmp_and_br_short(G4_scratch, JvmtiThreadState::earlyret_pending, Assembler::notEqual, pt, L);
227 
228     // Call Interpreter::remove_activation_early_entry() to get the address of the
229     // same-named entrypoint in the generated interpreter code
230     ld(thr_state, JvmtiThreadState::earlyret_tos_offset(), Otos_l1);
231     call_VM_leaf(noreg, CAST_FROM_FN_PTR(address, Interpreter::remove_activation_early_entry), Otos_l1);
232 
233     // Jump to Interpreter::_remove_activation_early_entry
234     jmpl(O0, G0, G0);
235     delayed()->nop();
236     bind(L);
237   }
238 }
239 
240 
super_call_VM_leaf(Register thread_cache,address entry_point,Register arg_1,Register arg_2)241 void InterpreterMacroAssembler::super_call_VM_leaf(Register thread_cache, address entry_point, Register arg_1, Register arg_2) {
242   mov(arg_1, O0);
243   mov(arg_2, O1);
244   MacroAssembler::call_VM_leaf_base(thread_cache, entry_point, 2);
245 }
246 
dispatch_base(TosState state,address * table)247 void InterpreterMacroAssembler::dispatch_base(TosState state, address* table) {
248   assert_not_delayed();
249   dispatch_Lbyte_code(state, table);
250 }
251 
252 
dispatch_normal(TosState state)253 void InterpreterMacroAssembler::dispatch_normal(TosState state) {
254   dispatch_base(state, Interpreter::normal_table(state));
255 }
256 
257 
dispatch_only(TosState state)258 void InterpreterMacroAssembler::dispatch_only(TosState state) {
259   dispatch_base(state, Interpreter::dispatch_table(state));
260 }
261 
262 
263 // common code to dispatch and dispatch_only
264 // dispatch value in Lbyte_code and increment Lbcp
265 
dispatch_Lbyte_code(TosState state,address * table,int bcp_incr,bool verify,bool generate_poll)266 void InterpreterMacroAssembler::dispatch_Lbyte_code(TosState state, address* table, int bcp_incr, bool verify, bool generate_poll) {
267   verify_FPU(1, state);
268   // %%%%% maybe implement +VerifyActivationFrameSize here
269   //verify_thread(); //too slow; we will just verify on method entry & exit
270   if (verify) interp_verify_oop(Otos_i, state, __FILE__, __LINE__);
271   // dispatch table to use
272   AddressLiteral tbl(table);
273   Label dispatch;
274 
275   if (SafepointMechanism::uses_thread_local_poll() && generate_poll) {
276     AddressLiteral sfpt_tbl(Interpreter::safept_table(state));
277     Label no_safepoint;
278 
279     if (tbl.value() != sfpt_tbl.value()) {
280       ldx(Address(G2_thread, Thread::polling_page_offset()), G3_scratch, 0);
281       // Armed page has poll_bit set, if poll bit is cleared just continue.
282       and3(G3_scratch, SafepointMechanism::poll_bit(), G3_scratch);
283 
284       br_null_short(G3_scratch, Assembler::pt, no_safepoint);
285       set(sfpt_tbl, G3_scratch);
286       ba_short(dispatch);
287     }
288     bind(no_safepoint);
289   }
290 
291   set(tbl, G3_scratch);                               // compute addr of table
292   bind(dispatch);
293   sll(Lbyte_code, LogBytesPerWord, Lbyte_code);       // multiply by wordSize
294   ld_ptr(G3_scratch, Lbyte_code, G3_scratch);         // get entry addr
295   jmp( G3_scratch, 0 );
296   if (bcp_incr != 0)  delayed()->inc(Lbcp, bcp_incr);
297   else                delayed()->nop();
298 }
299 
300 
301 // Helpers for expression stack
302 
303 // Longs and doubles are Category 2 computational types in the
304 // JVM specification (section 3.11.1) and take 2 expression stack or
305 // local slots.
306 // Aligning them on 32 bit with tagged stacks is hard because the code generated
307 // for the dup* bytecodes depends on what types are already on the stack.
308 // If the types are split into the two stack/local slots, that is much easier
309 // (and we can use 0 for non-reference tags).
310 
311 // Known good alignment in _LP64 but unknown otherwise
load_unaligned_double(Register r1,int offset,FloatRegister d)312 void InterpreterMacroAssembler::load_unaligned_double(Register r1, int offset, FloatRegister d) {
313   assert_not_delayed();
314 
315   ldf(FloatRegisterImpl::D, r1, offset, d);
316 }
317 
318 // Known good alignment in _LP64 but unknown otherwise
store_unaligned_double(FloatRegister d,Register r1,int offset)319 void InterpreterMacroAssembler::store_unaligned_double(FloatRegister d, Register r1, int offset) {
320   assert_not_delayed();
321 
322   stf(FloatRegisterImpl::D, d, r1, offset);
323   // store something more useful here
324   debug_only(stx(G0, r1, offset+Interpreter::stackElementSize);)
325 }
326 
327 
328 // Known good alignment in _LP64 but unknown otherwise
load_unaligned_long(Register r1,int offset,Register rd)329 void InterpreterMacroAssembler::load_unaligned_long(Register r1, int offset, Register rd) {
330   assert_not_delayed();
331   ldx(r1, offset, rd);
332 }
333 
334 // Known good alignment in _LP64 but unknown otherwise
store_unaligned_long(Register l,Register r1,int offset)335 void InterpreterMacroAssembler::store_unaligned_long(Register l, Register r1, int offset) {
336   assert_not_delayed();
337 
338   stx(l, r1, offset);
339   // store something more useful here
340   stx(G0, r1, offset+Interpreter::stackElementSize);
341 }
342 
pop_i(Register r)343 void InterpreterMacroAssembler::pop_i(Register r) {
344   assert_not_delayed();
345   ld(Lesp, Interpreter::expr_offset_in_bytes(0), r);
346   inc(Lesp, Interpreter::stackElementSize);
347   debug_only(verify_esp(Lesp));
348 }
349 
pop_ptr(Register r,Register scratch)350 void InterpreterMacroAssembler::pop_ptr(Register r, Register scratch) {
351   assert_not_delayed();
352   ld_ptr(Lesp, Interpreter::expr_offset_in_bytes(0), r);
353   inc(Lesp, Interpreter::stackElementSize);
354   debug_only(verify_esp(Lesp));
355 }
356 
pop_l(Register r)357 void InterpreterMacroAssembler::pop_l(Register r) {
358   assert_not_delayed();
359   load_unaligned_long(Lesp, Interpreter::expr_offset_in_bytes(0), r);
360   inc(Lesp, 2*Interpreter::stackElementSize);
361   debug_only(verify_esp(Lesp));
362 }
363 
364 
pop_f(FloatRegister f,Register scratch)365 void InterpreterMacroAssembler::pop_f(FloatRegister f, Register scratch) {
366   assert_not_delayed();
367   ldf(FloatRegisterImpl::S, Lesp, Interpreter::expr_offset_in_bytes(0), f);
368   inc(Lesp, Interpreter::stackElementSize);
369   debug_only(verify_esp(Lesp));
370 }
371 
372 
pop_d(FloatRegister f,Register scratch)373 void InterpreterMacroAssembler::pop_d(FloatRegister f, Register scratch) {
374   assert_not_delayed();
375   load_unaligned_double(Lesp, Interpreter::expr_offset_in_bytes(0), f);
376   inc(Lesp, 2*Interpreter::stackElementSize);
377   debug_only(verify_esp(Lesp));
378 }
379 
380 
push_i(Register r)381 void InterpreterMacroAssembler::push_i(Register r) {
382   assert_not_delayed();
383   debug_only(verify_esp(Lesp));
384   st(r, Lesp, 0);
385   dec(Lesp, Interpreter::stackElementSize);
386 }
387 
push_ptr(Register r)388 void InterpreterMacroAssembler::push_ptr(Register r) {
389   assert_not_delayed();
390   st_ptr(r, Lesp, 0);
391   dec(Lesp, Interpreter::stackElementSize);
392 }
393 
394 // remember: our convention for longs in SPARC is:
395 // O0 (Otos_l1) has high-order part in first word,
396 // O1 (Otos_l2) has low-order part in second word
397 
push_l(Register r)398 void InterpreterMacroAssembler::push_l(Register r) {
399   assert_not_delayed();
400   debug_only(verify_esp(Lesp));
401   // Longs are stored in memory-correct order, even if unaligned.
402   int offset = -Interpreter::stackElementSize;
403   store_unaligned_long(r, Lesp, offset);
404   dec(Lesp, 2 * Interpreter::stackElementSize);
405 }
406 
407 
push_f(FloatRegister f)408 void InterpreterMacroAssembler::push_f(FloatRegister f) {
409   assert_not_delayed();
410   debug_only(verify_esp(Lesp));
411   stf(FloatRegisterImpl::S, f, Lesp, 0);
412   dec(Lesp, Interpreter::stackElementSize);
413 }
414 
415 
push_d(FloatRegister d)416 void InterpreterMacroAssembler::push_d(FloatRegister d)   {
417   assert_not_delayed();
418   debug_only(verify_esp(Lesp));
419   // Longs are stored in memory-correct order, even if unaligned.
420   int offset = -Interpreter::stackElementSize;
421   store_unaligned_double(d, Lesp, offset);
422   dec(Lesp, 2 * Interpreter::stackElementSize);
423 }
424 
425 
push(TosState state)426 void InterpreterMacroAssembler::push(TosState state) {
427   interp_verify_oop(Otos_i, state, __FILE__, __LINE__);
428   switch (state) {
429     case atos: push_ptr();            break;
430     case btos:                        // fall through
431     case ztos:                        // fall through
432     case ctos:                        // fall through
433     case stos:                        // fall through
434     case itos: push_i();              break;
435     case ltos: push_l();              break;
436     case ftos: push_f();              break;
437     case dtos: push_d();              break;
438     case vtos: /* nothing to do */    break;
439     default  : ShouldNotReachHere();
440   }
441 }
442 
443 
pop(TosState state)444 void InterpreterMacroAssembler::pop(TosState state) {
445   switch (state) {
446     case atos: pop_ptr();            break;
447     case btos:                       // fall through
448     case ztos:                       // fall through
449     case ctos:                       // fall through
450     case stos:                       // fall through
451     case itos: pop_i();              break;
452     case ltos: pop_l();              break;
453     case ftos: pop_f();              break;
454     case dtos: pop_d();              break;
455     case vtos: /* nothing to do */   break;
456     default  : ShouldNotReachHere();
457   }
458   interp_verify_oop(Otos_i, state, __FILE__, __LINE__);
459 }
460 
461 
462 // Helpers for swap and dup
load_ptr(int n,Register val)463 void InterpreterMacroAssembler::load_ptr(int n, Register val) {
464   ld_ptr(Lesp, Interpreter::expr_offset_in_bytes(n), val);
465 }
store_ptr(int n,Register val)466 void InterpreterMacroAssembler::store_ptr(int n, Register val) {
467   st_ptr(val, Lesp, Interpreter::expr_offset_in_bytes(n));
468 }
469 
470 
load_receiver(Register param_count,Register recv)471 void InterpreterMacroAssembler::load_receiver(Register param_count,
472                                               Register recv) {
473   sll(param_count, Interpreter::logStackElementSize, param_count);
474   ld_ptr(Lesp, param_count, recv);  // gets receiver oop
475 }
476 
empty_expression_stack()477 void InterpreterMacroAssembler::empty_expression_stack() {
478   // Reset Lesp.
479   sub( Lmonitors, wordSize, Lesp );
480 
481   // Reset SP by subtracting more space from Lesp.
482   Label done;
483   assert(G4_scratch != Gframe_size, "Only you can prevent register aliasing!");
484 
485   // A native does not need to do this, since its callee does not change SP.
486   ld(Lmethod, Method::access_flags_offset(), Gframe_size);  // Load access flags.
487   btst(JVM_ACC_NATIVE, Gframe_size);
488   br(Assembler::notZero, false, Assembler::pt, done);
489   delayed()->nop();
490 
491   // Compute max expression stack+register save area
492   ld_ptr(Lmethod, in_bytes(Method::const_offset()), Gframe_size);
493   lduh(Gframe_size, in_bytes(ConstMethod::max_stack_offset()), Gframe_size);  // Load max stack.
494   add(Gframe_size, frame::memory_parameter_word_sp_offset+Method::extra_stack_entries(), Gframe_size );
495 
496   //
497   // now set up a stack frame with the size computed above
498   //
499   //round_to( Gframe_size, WordsPerLong ); // -- moved down to the "and" below
500   sll( Gframe_size, LogBytesPerWord, Gframe_size );
501   sub( Lesp, Gframe_size, Gframe_size );
502   and3( Gframe_size, -(2 * wordSize), Gframe_size );          // align SP (downwards) to an 8/16-byte boundary
503   debug_only(verify_sp(Gframe_size, G4_scratch));
504   sub(Gframe_size, STACK_BIAS, Gframe_size );
505   mov(Gframe_size, SP);
506 
507   bind(done);
508 }
509 
510 
511 #ifdef ASSERT
verify_sp(Register Rsp,Register Rtemp)512 void InterpreterMacroAssembler::verify_sp(Register Rsp, Register Rtemp) {
513   Label Bad, OK;
514 
515   // Saved SP must be aligned.
516   btst(2*BytesPerWord-1, Rsp);
517   br(Assembler::notZero, false, Assembler::pn, Bad);
518   delayed()->nop();
519 
520   // Saved SP, plus register window size, must not be above FP.
521   add(Rsp, frame::register_save_words * wordSize, Rtemp);
522   sub(Rtemp, STACK_BIAS, Rtemp);  // Bias Rtemp before cmp to FP
523   cmp_and_brx_short(Rtemp, FP, Assembler::greaterUnsigned, Assembler::pn, Bad);
524 
525   // Saved SP must not be ridiculously below current SP.
526   size_t maxstack = MAX2(JavaThread::stack_size_at_create(), (size_t) 4*K*K);
527   set(maxstack, Rtemp);
528   sub(SP, Rtemp, Rtemp);
529   add(Rtemp, STACK_BIAS, Rtemp);  // Unbias Rtemp before cmp to Rsp
530   cmp_and_brx_short(Rsp, Rtemp, Assembler::lessUnsigned, Assembler::pn, Bad);
531 
532   ba_short(OK);
533 
534   bind(Bad);
535   stop("on return to interpreted call, restored SP is corrupted");
536 
537   bind(OK);
538 }
539 
540 
verify_esp(Register Resp)541 void InterpreterMacroAssembler::verify_esp(Register Resp) {
542   // about to read or write Resp[0]
543   // make sure it is not in the monitors or the register save area
544   Label OK1, OK2;
545 
546   cmp(Resp, Lmonitors);
547   brx(Assembler::lessUnsigned, true, Assembler::pt, OK1);
548   delayed()->sub(Resp, frame::memory_parameter_word_sp_offset * wordSize, Resp);
549   stop("too many pops:  Lesp points into monitor area");
550   bind(OK1);
551   sub(Resp, STACK_BIAS, Resp);
552   cmp(Resp, SP);
553   brx(Assembler::greaterEqualUnsigned, false, Assembler::pt, OK2);
554   delayed()->add(Resp, STACK_BIAS + frame::memory_parameter_word_sp_offset * wordSize, Resp);
555   stop("too many pushes:  Lesp points into register window");
556   bind(OK2);
557 }
558 #endif // ASSERT
559 
560 // Load compiled (i2c) or interpreter entry when calling from interpreted and
561 // do the call. Centralized so that all interpreter calls will do the same actions.
562 // If jvmti single stepping is on for a thread we must not call compiled code.
call_from_interpreter(Register target,Register scratch,Register Rret)563 void InterpreterMacroAssembler::call_from_interpreter(Register target, Register scratch, Register Rret) {
564 
565   // Assume we want to go compiled if available
566 
567   ld_ptr(G5_method, in_bytes(Method::from_interpreted_offset()), target);
568 
569   if (JvmtiExport::can_post_interpreter_events()) {
570     // JVMTI events, such as single-stepping, are implemented partly by avoiding running
571     // compiled code in threads for which the event is enabled.  Check here for
572     // interp_only_mode if these events CAN be enabled.
573     verify_thread();
574     Label skip_compiled_code;
575 
576     const Address interp_only(G2_thread, JavaThread::interp_only_mode_offset());
577     ld(interp_only, scratch);
578     cmp_zero_and_br(Assembler::notZero, scratch, skip_compiled_code, true, Assembler::pn);
579     delayed()->ld_ptr(G5_method, in_bytes(Method::interpreter_entry_offset()), target);
580     bind(skip_compiled_code);
581   }
582 
583   // the i2c_adapters need Method* in G5_method (right? %%%)
584   // do the call
585 #ifdef ASSERT
586   {
587     Label ok;
588     br_notnull_short(target, Assembler::pt, ok);
589     stop("null entry point");
590     bind(ok);
591   }
592 #endif // ASSERT
593 
594   // Adjust Rret first so Llast_SP can be same as Rret
595   add(Rret, -frame::pc_return_offset, O7);
596   add(Lesp, BytesPerWord, Gargs); // setup parameter pointer
597   // Record SP so we can remove any stack space allocated by adapter transition
598   jmp(target, 0);
599   delayed()->mov(SP, Llast_SP);
600 }
601 
if_cmp(Condition cc,bool ptr_compare)602 void InterpreterMacroAssembler::if_cmp(Condition cc, bool ptr_compare) {
603   assert_not_delayed();
604 
605   Label not_taken;
606   if (ptr_compare) brx(cc, false, Assembler::pn, not_taken);
607   else             br (cc, false, Assembler::pn, not_taken);
608   delayed()->nop();
609 
610   TemplateTable::branch(false,false);
611 
612   bind(not_taken);
613 
614   profile_not_taken_branch(G3_scratch);
615 }
616 
617 
get_2_byte_integer_at_bcp(int bcp_offset,Register Rtmp,Register Rdst,signedOrNot is_signed,setCCOrNot should_set_CC)618 void InterpreterMacroAssembler::get_2_byte_integer_at_bcp(
619                                   int         bcp_offset,
620                                   Register    Rtmp,
621                                   Register    Rdst,
622                                   signedOrNot is_signed,
623                                   setCCOrNot  should_set_CC ) {
624   assert(Rtmp != Rdst, "need separate temp register");
625   assert_not_delayed();
626   switch (is_signed) {
627    default: ShouldNotReachHere();
628 
629    case   Signed:  ldsb( Lbcp, bcp_offset, Rdst  );  break; // high byte
630    case Unsigned:  ldub( Lbcp, bcp_offset, Rdst  );  break; // high byte
631   }
632   ldub( Lbcp, bcp_offset + 1, Rtmp ); // low byte
633   sll( Rdst, BitsPerByte, Rdst);
634   switch (should_set_CC ) {
635    default: ShouldNotReachHere();
636 
637    case      set_CC:  orcc( Rdst, Rtmp, Rdst ); break;
638    case dont_set_CC:  or3(  Rdst, Rtmp, Rdst ); break;
639   }
640 }
641 
642 
get_4_byte_integer_at_bcp(int bcp_offset,Register Rtmp,Register Rdst,setCCOrNot should_set_CC)643 void InterpreterMacroAssembler::get_4_byte_integer_at_bcp(
644                                   int        bcp_offset,
645                                   Register   Rtmp,
646                                   Register   Rdst,
647                                   setCCOrNot should_set_CC ) {
648   assert(Rtmp != Rdst, "need separate temp register");
649   assert_not_delayed();
650   add( Lbcp, bcp_offset, Rtmp);
651   andcc( Rtmp, 3, G0);
652   Label aligned;
653   switch (should_set_CC ) {
654    default: ShouldNotReachHere();
655 
656    case      set_CC: break;
657    case dont_set_CC: break;
658   }
659 
660   br(Assembler::zero, true, Assembler::pn, aligned);
661   delayed()->ldsw(Rtmp, 0, Rdst);
662 
663   ldub(Lbcp, bcp_offset + 3, Rdst);
664   ldub(Lbcp, bcp_offset + 2, Rtmp);  sll(Rtmp,  8, Rtmp);  or3(Rtmp, Rdst, Rdst);
665   ldub(Lbcp, bcp_offset + 1, Rtmp);  sll(Rtmp, 16, Rtmp);  or3(Rtmp, Rdst, Rdst);
666   ldsb(Lbcp, bcp_offset + 0, Rtmp);  sll(Rtmp, 24, Rtmp);
667   or3(Rtmp, Rdst, Rdst );
668 
669   bind(aligned);
670   if (should_set_CC == set_CC) tst(Rdst);
671 }
672 
get_cache_index_at_bcp(Register temp,Register index,int bcp_offset,size_t index_size)673 void InterpreterMacroAssembler::get_cache_index_at_bcp(Register temp, Register index,
674                                                        int bcp_offset, size_t index_size) {
675   assert(bcp_offset > 0, "bcp is still pointing to start of bytecode");
676   if (index_size == sizeof(u2)) {
677     get_2_byte_integer_at_bcp(bcp_offset, temp, index, Unsigned);
678   } else if (index_size == sizeof(u4)) {
679     get_4_byte_integer_at_bcp(bcp_offset, temp, index);
680     assert(ConstantPool::decode_invokedynamic_index(~123) == 123, "else change next line");
681     xor3(index, -1, index);  // convert to plain index
682   } else if (index_size == sizeof(u1)) {
683     ldub(Lbcp, bcp_offset, index);
684   } else {
685     ShouldNotReachHere();
686   }
687 }
688 
689 
get_cache_and_index_at_bcp(Register cache,Register tmp,int bcp_offset,size_t index_size)690 void InterpreterMacroAssembler::get_cache_and_index_at_bcp(Register cache, Register tmp,
691                                                            int bcp_offset, size_t index_size) {
692   assert(bcp_offset > 0, "bcp is still pointing to start of bytecode");
693   assert_different_registers(cache, tmp);
694   assert_not_delayed();
695   get_cache_index_at_bcp(cache, tmp, bcp_offset, index_size);
696   // convert from field index to ConstantPoolCacheEntry index and from
697   // word index to byte offset
698   sll(tmp, exact_log2(in_words(ConstantPoolCacheEntry::size()) * BytesPerWord), tmp);
699   add(LcpoolCache, tmp, cache);
700 }
701 
702 
get_cache_and_index_and_bytecode_at_bcp(Register cache,Register temp,Register bytecode,int byte_no,int bcp_offset,size_t index_size)703 void InterpreterMacroAssembler::get_cache_and_index_and_bytecode_at_bcp(Register cache,
704                                                                         Register temp,
705                                                                         Register bytecode,
706                                                                         int byte_no,
707                                                                         int bcp_offset,
708                                                                         size_t index_size) {
709   get_cache_and_index_at_bcp(cache, temp, bcp_offset, index_size);
710   ld_ptr(cache, ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::indices_offset(), bytecode);
711   const int shift_count = (1 + byte_no) * BitsPerByte;
712   assert((byte_no == TemplateTable::f1_byte && shift_count == ConstantPoolCacheEntry::bytecode_1_shift) ||
713          (byte_no == TemplateTable::f2_byte && shift_count == ConstantPoolCacheEntry::bytecode_2_shift),
714          "correct shift count");
715   srl(bytecode, shift_count, bytecode);
716   assert(ConstantPoolCacheEntry::bytecode_1_mask == ConstantPoolCacheEntry::bytecode_2_mask, "common mask");
717   and3(bytecode, ConstantPoolCacheEntry::bytecode_1_mask, bytecode);
718 }
719 
720 
get_cache_entry_pointer_at_bcp(Register cache,Register tmp,int bcp_offset,size_t index_size)721 void InterpreterMacroAssembler::get_cache_entry_pointer_at_bcp(Register cache, Register tmp,
722                                                                int bcp_offset, size_t index_size) {
723   assert(bcp_offset > 0, "bcp is still pointing to start of bytecode");
724   assert_different_registers(cache, tmp);
725   assert_not_delayed();
726   if (index_size == sizeof(u2)) {
727     get_2_byte_integer_at_bcp(bcp_offset, cache, tmp, Unsigned);
728   } else {
729     ShouldNotReachHere();  // other sizes not supported here
730   }
731               // convert from field index to ConstantPoolCacheEntry index
732               // and from word index to byte offset
733   sll(tmp, exact_log2(in_words(ConstantPoolCacheEntry::size()) * BytesPerWord), tmp);
734               // skip past the header
735   add(tmp, in_bytes(ConstantPoolCache::base_offset()), tmp);
736               // construct pointer to cache entry
737   add(LcpoolCache, tmp, cache);
738 }
739 
740 
741 // Load object from cpool->resolved_references(index)
load_resolved_reference_at_index(Register result,Register index,Register tmp)742 void InterpreterMacroAssembler::load_resolved_reference_at_index(
743                                            Register result, Register index, Register tmp) {
744   assert_different_registers(result, index, tmp);
745   assert_not_delayed();
746   // convert from field index to resolved_references() index and from
747   // word index to byte offset. Since this is a java object, it can be compressed
748   sll(index, LogBytesPerHeapOop, index);
749   get_constant_pool(result);
750   // load pointer for resolved_references[] objArray
751   ld_ptr(result, ConstantPool::cache_offset_in_bytes(), result);
752   ld_ptr(result, ConstantPoolCache::resolved_references_offset_in_bytes(), result);
753   resolve_oop_handle(result, tmp);
754   // Add in the index
755   add(result, index, result);
756   load_heap_oop(result, arrayOopDesc::base_offset_in_bytes(T_OBJECT), result, tmp);
757   // The resulting oop is null if the reference is not yet resolved.
758   // It is Universe::the_null_sentinel() if the reference resolved to NULL via condy.
759 }
760 
761 
762 // load cpool->resolved_klass_at(index)
load_resolved_klass_at_offset(Register Rcpool,Register Roffset,Register Rklass)763 void InterpreterMacroAssembler::load_resolved_klass_at_offset(Register Rcpool,
764                                            Register Roffset, Register Rklass) {
765   // int value = *this_cp->int_at_addr(which);
766   // int resolved_klass_index = extract_low_short_from_int(value);
767   //
768   // Because SPARC is big-endian, the low_short is at (cpool->int_at_addr(which) + 2 bytes)
769   add(Roffset, Rcpool, Roffset);
770   lduh(Roffset, sizeof(ConstantPool) + 2, Roffset);  // Roffset = resolved_klass_index
771 
772   Register Rresolved_klasses = Rklass;
773   ld_ptr(Rcpool, ConstantPool::resolved_klasses_offset_in_bytes(), Rresolved_klasses);
774   sll(Roffset, LogBytesPerWord, Roffset);
775   add(Roffset, Array<Klass*>::base_offset_in_bytes(), Roffset);
776   ld_ptr(Rresolved_klasses, Roffset, Rklass);
777 }
778 
779 
780 // Generate a subtype check: branch to ok_is_subtype if sub_klass is
781 // a subtype of super_klass.  Blows registers Rsuper_klass, Rsub_klass, tmp1, tmp2.
gen_subtype_check(Register Rsub_klass,Register Rsuper_klass,Register Rtmp1,Register Rtmp2,Register Rtmp3,Label & ok_is_subtype)782 void InterpreterMacroAssembler::gen_subtype_check(Register Rsub_klass,
783                                                   Register Rsuper_klass,
784                                                   Register Rtmp1,
785                                                   Register Rtmp2,
786                                                   Register Rtmp3,
787                                                   Label &ok_is_subtype ) {
788   Label not_subtype;
789 
790   // Profile the not-null value's klass.
791   profile_typecheck(Rsub_klass, Rtmp1);
792 
793   check_klass_subtype_fast_path(Rsub_klass, Rsuper_klass,
794                                 Rtmp1, Rtmp2,
795                                 &ok_is_subtype, &not_subtype, NULL);
796 
797   check_klass_subtype_slow_path(Rsub_klass, Rsuper_klass,
798                                 Rtmp1, Rtmp2, Rtmp3, /*hack:*/ noreg,
799                                 &ok_is_subtype, NULL);
800 
801   bind(not_subtype);
802   profile_typecheck_failed(Rtmp1);
803 }
804 
805 // Separate these two to allow for delay slot in middle
806 // These are used to do a test and full jump to exception-throwing code.
807 
808 // %%%%% Could possibly reoptimize this by testing to see if could use
809 // a single conditional branch (i.e. if span is small enough.
810 // If you go that route, than get rid of the split and give up
811 // on the delay-slot hack.
812 
throw_if_not_1_icc(Condition ok_condition,Label & ok)813 void InterpreterMacroAssembler::throw_if_not_1_icc( Condition ok_condition,
814                                                     Label&    ok ) {
815   assert_not_delayed();
816   br(ok_condition, true, pt, ok);
817   // DELAY SLOT
818 }
819 
throw_if_not_1_xcc(Condition ok_condition,Label & ok)820 void InterpreterMacroAssembler::throw_if_not_1_xcc( Condition ok_condition,
821                                                     Label&    ok ) {
822   assert_not_delayed();
823   bp( ok_condition, true, Assembler::xcc, pt, ok);
824   // DELAY SLOT
825 }
826 
throw_if_not_1_x(Condition ok_condition,Label & ok)827 void InterpreterMacroAssembler::throw_if_not_1_x( Condition ok_condition,
828                                                   Label&    ok ) {
829   assert_not_delayed();
830   brx(ok_condition, true, pt, ok);
831   // DELAY SLOT
832 }
833 
throw_if_not_2(address throw_entry_point,Register Rscratch,Label & ok)834 void InterpreterMacroAssembler::throw_if_not_2( address  throw_entry_point,
835                                                 Register Rscratch,
836                                                 Label&   ok ) {
837   assert(throw_entry_point != NULL, "entry point must be generated by now");
838   AddressLiteral dest(throw_entry_point);
839   jump_to(dest, Rscratch);
840   delayed()->nop();
841   bind(ok);
842 }
843 
844 
845 // And if you cannot use the delay slot, here is a shorthand:
846 
throw_if_not_icc(Condition ok_condition,address throw_entry_point,Register Rscratch)847 void InterpreterMacroAssembler::throw_if_not_icc( Condition ok_condition,
848                                                   address   throw_entry_point,
849                                                   Register  Rscratch ) {
850   Label ok;
851   if (ok_condition != never) {
852     throw_if_not_1_icc( ok_condition, ok);
853     delayed()->nop();
854   }
855   throw_if_not_2( throw_entry_point, Rscratch, ok);
856 }
throw_if_not_xcc(Condition ok_condition,address throw_entry_point,Register Rscratch)857 void InterpreterMacroAssembler::throw_if_not_xcc( Condition ok_condition,
858                                                   address   throw_entry_point,
859                                                   Register  Rscratch ) {
860   Label ok;
861   if (ok_condition != never) {
862     throw_if_not_1_xcc( ok_condition, ok);
863     delayed()->nop();
864   }
865   throw_if_not_2( throw_entry_point, Rscratch, ok);
866 }
throw_if_not_x(Condition ok_condition,address throw_entry_point,Register Rscratch)867 void InterpreterMacroAssembler::throw_if_not_x( Condition ok_condition,
868                                                 address   throw_entry_point,
869                                                 Register  Rscratch ) {
870   Label ok;
871   if (ok_condition != never) {
872     throw_if_not_1_x( ok_condition, ok);
873     delayed()->nop();
874   }
875   throw_if_not_2( throw_entry_point, Rscratch, ok);
876 }
877 
878 // Check that index is in range for array, then shift index by index_shift, and put arrayOop + shifted_index into res
879 // Note: res is still shy of address by array offset into object.
880 
index_check_without_pop(Register array,Register index,int index_shift,Register tmp,Register res)881 void InterpreterMacroAssembler::index_check_without_pop(Register array, Register index, int index_shift, Register tmp, Register res) {
882   assert_not_delayed();
883 
884   verify_oop(array);
885   // Sign extend since tos (index) can be a 32bit value.
886   sra(index, G0, index);
887 
888   // Check array.
889   Label ptr_ok;
890   tst(array);
891   throw_if_not_1_x(notZero, ptr_ok);
892   delayed()->ld(array, arrayOopDesc::length_offset_in_bytes(), tmp); // Check index.
893   throw_if_not_2(Interpreter::_throw_NullPointerException_entry, G3_scratch, ptr_ok);
894 
895   Label index_ok;
896   cmp(index, tmp);
897   throw_if_not_1_icc(lessUnsigned, index_ok);
898   if (index_shift > 0) {
899     delayed()->sll(index, index_shift, index);
900   } else {
901     delayed()->add(array, index, res); // addr - const offset in index
902   }
903   // Pass the array to create more detailed exceptions.
904   // Convention: move aberrant index into Otos_i for exception message.
905   mov(index, Otos_i);
906   mov(array, G3_scratch);
907   throw_if_not_2(Interpreter::_throw_ArrayIndexOutOfBoundsException_entry, G4_scratch, index_ok);
908 
909   // add offset if didn't do it in delay slot
910   if (index_shift > 0) { add(array, index, res); } // addr - const offset in index
911 }
912 
913 
index_check(Register array,Register index,int index_shift,Register tmp,Register res)914 void InterpreterMacroAssembler::index_check(Register array, Register index, int index_shift, Register tmp, Register res) {
915   assert_not_delayed();
916 
917   // pop array
918   pop_ptr(array);
919 
920   // check array
921   index_check_without_pop(array, index, index_shift, tmp, res);
922 }
923 
924 
get_const(Register Rdst)925 void InterpreterMacroAssembler::get_const(Register Rdst) {
926   ld_ptr(Lmethod, in_bytes(Method::const_offset()), Rdst);
927 }
928 
929 
get_constant_pool(Register Rdst)930 void InterpreterMacroAssembler::get_constant_pool(Register Rdst) {
931   get_const(Rdst);
932   ld_ptr(Rdst, in_bytes(ConstMethod::constants_offset()), Rdst);
933 }
934 
935 
get_constant_pool_cache(Register Rdst)936 void InterpreterMacroAssembler::get_constant_pool_cache(Register Rdst) {
937   get_constant_pool(Rdst);
938   ld_ptr(Rdst, ConstantPool::cache_offset_in_bytes(), Rdst);
939 }
940 
941 
get_cpool_and_tags(Register Rcpool,Register Rtags)942 void InterpreterMacroAssembler::get_cpool_and_tags(Register Rcpool, Register Rtags) {
943   get_constant_pool(Rcpool);
944   ld_ptr(Rcpool, ConstantPool::tags_offset_in_bytes(), Rtags);
945 }
946 
947 
948 // unlock if synchronized method
949 //
950 // Unlock the receiver if this is a synchronized method.
951 // Unlock any Java monitors from syncronized blocks.
952 //
953 // If there are locked Java monitors
954 //    If throw_monitor_exception
955 //       throws IllegalMonitorStateException
956 //    Else if install_monitor_exception
957 //       installs IllegalMonitorStateException
958 //    Else
959 //       no error processing
unlock_if_synchronized_method(TosState state,bool throw_monitor_exception,bool install_monitor_exception)960 void InterpreterMacroAssembler::unlock_if_synchronized_method(TosState state,
961                                                               bool throw_monitor_exception,
962                                                               bool install_monitor_exception) {
963   Label unlocked, unlock, no_unlock;
964 
965   // get the value of _do_not_unlock_if_synchronized into G1_scratch
966   const Address do_not_unlock_if_synchronized(G2_thread,
967     JavaThread::do_not_unlock_if_synchronized_offset());
968   ldbool(do_not_unlock_if_synchronized, G1_scratch);
969   stbool(G0, do_not_unlock_if_synchronized); // reset the flag
970 
971   // check if synchronized method
972   const Address access_flags(Lmethod, Method::access_flags_offset());
973   interp_verify_oop(Otos_i, state, __FILE__, __LINE__);
974   push(state); // save tos
975   ld(access_flags, G3_scratch); // Load access flags.
976   btst(JVM_ACC_SYNCHRONIZED, G3_scratch);
977   br(zero, false, pt, unlocked);
978   delayed()->nop();
979 
980   // Don't unlock anything if the _do_not_unlock_if_synchronized flag
981   // is set.
982   cmp_zero_and_br(Assembler::notZero, G1_scratch, no_unlock);
983   delayed()->nop();
984 
985   // BasicObjectLock will be first in list, since this is a synchronized method. However, need
986   // to check that the object has not been unlocked by an explicit monitorexit bytecode.
987 
988   //Intel: if (throw_monitor_exception) ... else ...
989   // Entry already unlocked, need to throw exception
990   //...
991 
992   // pass top-most monitor elem
993   add( top_most_monitor(), O1 );
994 
995   ld_ptr(O1, BasicObjectLock::obj_offset_in_bytes(), G3_scratch);
996   br_notnull_short(G3_scratch, pt, unlock);
997 
998   if (throw_monitor_exception) {
999     // Entry already unlocked need to throw an exception
1000     MacroAssembler::call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_illegal_monitor_state_exception));
1001     should_not_reach_here();
1002   } else {
1003     // Monitor already unlocked during a stack unroll.
1004     // If requested, install an illegal_monitor_state_exception.
1005     // Continue with stack unrolling.
1006     if (install_monitor_exception) {
1007       MacroAssembler::call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::new_illegal_monitor_state_exception));
1008     }
1009     ba_short(unlocked);
1010   }
1011 
1012   bind(unlock);
1013 
1014   unlock_object(O1);
1015 
1016   bind(unlocked);
1017 
1018   // I0, I1: Might contain return value
1019 
1020   // Check that all monitors are unlocked
1021   { Label loop, exception, entry, restart;
1022 
1023     Register Rmptr   = O0;
1024     Register Rtemp   = O1;
1025     Register Rlimit  = Lmonitors;
1026     const jint delta = frame::interpreter_frame_monitor_size() * wordSize;
1027     assert( (delta & LongAlignmentMask) == 0,
1028             "sizeof BasicObjectLock must be even number of doublewords");
1029 
1030     #ifdef ASSERT
1031     add(top_most_monitor(), Rmptr, delta);
1032     { Label L;
1033       // ensure that Rmptr starts out above (or at) Rlimit
1034       cmp_and_brx_short(Rmptr, Rlimit, Assembler::greaterEqualUnsigned, pn, L);
1035       stop("monitor stack has negative size");
1036       bind(L);
1037     }
1038     #endif
1039     bind(restart);
1040     ba(entry);
1041     delayed()->
1042     add(top_most_monitor(), Rmptr, delta);      // points to current entry, starting with bottom-most entry
1043 
1044     // Entry is still locked, need to throw exception
1045     bind(exception);
1046     if (throw_monitor_exception) {
1047       MacroAssembler::call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_illegal_monitor_state_exception));
1048       should_not_reach_here();
1049     } else {
1050       // Stack unrolling. Unlock object and if requested, install illegal_monitor_exception.
1051       // Unlock does not block, so don't have to worry about the frame
1052       unlock_object(Rmptr);
1053       if (install_monitor_exception) {
1054         MacroAssembler::call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::new_illegal_monitor_state_exception));
1055       }
1056       ba_short(restart);
1057     }
1058 
1059     bind(loop);
1060     cmp(Rtemp, G0);                             // check if current entry is used
1061     brx(Assembler::notEqual, false, pn, exception);
1062     delayed()->
1063     dec(Rmptr, delta);                          // otherwise advance to next entry
1064     #ifdef ASSERT
1065     { Label L;
1066       // ensure that Rmptr has not somehow stepped below Rlimit
1067       cmp_and_brx_short(Rmptr, Rlimit, Assembler::greaterEqualUnsigned, pn, L);
1068       stop("ran off the end of the monitor stack");
1069       bind(L);
1070     }
1071     #endif
1072     bind(entry);
1073     cmp(Rmptr, Rlimit);                         // check if bottom reached
1074     brx(Assembler::notEqual, true, pn, loop);   // if not at bottom then check this entry
1075     delayed()->
1076     ld_ptr(Rmptr, BasicObjectLock::obj_offset_in_bytes() - delta, Rtemp);
1077   }
1078 
1079   bind(no_unlock);
1080   pop(state);
1081   interp_verify_oop(Otos_i, state, __FILE__, __LINE__);
1082 }
1083 
narrow(Register result)1084 void InterpreterMacroAssembler::narrow(Register result) {
1085 
1086   ld_ptr(Address(Lmethod, Method::const_offset()), G3_scratch);
1087   ldub(G3_scratch, in_bytes(ConstMethod::result_type_offset()), G3_scratch);
1088 
1089   Label notBool, notByte, notChar, done;
1090 
1091   // common case first
1092   cmp(G3_scratch, T_INT);
1093   br(Assembler::equal, true, pn, done);
1094   delayed()->nop();
1095 
1096   cmp(G3_scratch, T_BOOLEAN);
1097   br(Assembler::notEqual, true, pn, notBool);
1098   delayed()->cmp(G3_scratch, T_BYTE);
1099   and3(result, 1, result);
1100   ba(done);
1101   delayed()->nop();
1102 
1103   bind(notBool);
1104   // cmp(G3_scratch, T_BYTE);
1105   br(Assembler::notEqual, true, pn, notByte);
1106   delayed()->cmp(G3_scratch, T_CHAR);
1107   sll(result, 24, result);
1108   sra(result, 24, result);
1109   ba(done);
1110   delayed()->nop();
1111 
1112   bind(notByte);
1113   // cmp(G3_scratch, T_CHAR);
1114   sll(result, 16, result);
1115   br(Assembler::notEqual, true, pn, done);
1116   delayed()->sra(result, 16, result);
1117   // sll(result, 16, result);
1118   srl(result, 16, result);
1119 
1120   // bind(notChar);
1121   // must be short, instructions already executed in delay slot
1122   // sll(result, 16, result);
1123   // sra(result, 16, result);
1124 
1125   bind(done);
1126 }
1127 
1128 // remove activation
1129 //
1130 // Unlock the receiver if this is a synchronized method.
1131 // Unlock any Java monitors from syncronized blocks.
1132 // Remove the activation from the stack.
1133 //
1134 // If there are locked Java monitors
1135 //    If throw_monitor_exception
1136 //       throws IllegalMonitorStateException
1137 //    Else if install_monitor_exception
1138 //       installs IllegalMonitorStateException
1139 //    Else
1140 //       no error processing
remove_activation(TosState state,bool throw_monitor_exception,bool install_monitor_exception)1141 void InterpreterMacroAssembler::remove_activation(TosState state,
1142                                                   bool throw_monitor_exception,
1143                                                   bool install_monitor_exception) {
1144 
1145   unlock_if_synchronized_method(state, throw_monitor_exception, install_monitor_exception);
1146 
1147   // save result (push state before jvmti call and pop it afterwards) and notify jvmti
1148   notify_method_exit(false, state, NotifyJVMTI);
1149 
1150   if (StackReservedPages > 0) {
1151     // testing if Stack Reserved Area needs to be re-enabled
1152     Label no_reserved_zone_enabling;
1153     ld_ptr(G2_thread, JavaThread::reserved_stack_activation_offset(), G3_scratch);
1154     cmp_and_brx_short(SP, G3_scratch, Assembler::lessUnsigned, Assembler::pt, no_reserved_zone_enabling);
1155 
1156     call_VM_leaf(noreg, CAST_FROM_FN_PTR(address, SharedRuntime::enable_stack_reserved_zone), G2_thread);
1157     call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_delayed_StackOverflowError), G2_thread);
1158     should_not_reach_here();
1159 
1160     bind(no_reserved_zone_enabling);
1161   }
1162 
1163   interp_verify_oop(Otos_i, state, __FILE__, __LINE__);
1164   verify_thread();
1165 
1166   // return tos
1167   assert(Otos_l1 == Otos_i, "adjust code below");
1168   switch (state) {
1169   case ltos: mov(Otos_l, Otos_l->after_save()); break; // O0 -> I0
1170   case btos:                                      // fall through
1171   case ztos:                                      // fall through
1172   case ctos:
1173   case stos:                                      // fall through
1174   case atos:                                      // fall through
1175   case itos: mov(Otos_l1, Otos_l1->after_save());    break;        // O0 -> I0
1176   case ftos:                                      // fall through
1177   case dtos:                                      // fall through
1178   case vtos: /* nothing to do */                     break;
1179   default  : ShouldNotReachHere();
1180   }
1181 }
1182 
1183 // Lock object
1184 //
1185 // Argument - lock_reg points to the BasicObjectLock to be used for locking,
1186 //            it must be initialized with the object to lock
lock_object(Register lock_reg,Register Object)1187 void InterpreterMacroAssembler::lock_object(Register lock_reg, Register Object) {
1188   if (UseHeavyMonitors) {
1189     call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter), lock_reg);
1190   }
1191   else {
1192     Register obj_reg = Object;
1193     Register mark_reg = G4_scratch;
1194     Register temp_reg = G1_scratch;
1195     Address  lock_addr(lock_reg, BasicObjectLock::lock_offset_in_bytes());
1196     Address  mark_addr(obj_reg, oopDesc::mark_offset_in_bytes());
1197     Label    done;
1198 
1199     Label slow_case;
1200 
1201     assert_different_registers(lock_reg, obj_reg, mark_reg, temp_reg);
1202 
1203     // load markOop from object into mark_reg
1204     ld_ptr(mark_addr, mark_reg);
1205 
1206     if (UseBiasedLocking) {
1207       biased_locking_enter(obj_reg, mark_reg, temp_reg, done, &slow_case);
1208     }
1209 
1210     // get the address of basicLock on stack that will be stored in the object
1211     // we need a temporary register here as we do not want to clobber lock_reg
1212     // (cas clobbers the destination register)
1213     mov(lock_reg, temp_reg);
1214     // set mark reg to be (markOop of object | UNLOCK_VALUE)
1215     or3(mark_reg, markOopDesc::unlocked_value, mark_reg);
1216     // initialize the box  (Must happen before we update the object mark!)
1217     st_ptr(mark_reg, lock_addr, BasicLock::displaced_header_offset_in_bytes());
1218     // compare and exchange object_addr, markOop | 1, stack address of basicLock
1219     assert(mark_addr.disp() == 0, "cas must take a zero displacement");
1220     cas_ptr(mark_addr.base(), mark_reg, temp_reg);
1221 
1222     // if the compare and exchange succeeded we are done (we saw an unlocked object)
1223     cmp_and_brx_short(mark_reg, temp_reg, Assembler::equal, Assembler::pt, done);
1224 
1225     // We did not see an unlocked object so try the fast recursive case
1226 
1227     // Check if owner is self by comparing the value in the markOop of object
1228     // with the stack pointer
1229     sub(temp_reg, SP, temp_reg);
1230     sub(temp_reg, STACK_BIAS, temp_reg);
1231     assert(os::vm_page_size() > 0xfff, "page size too small - change the constant");
1232 
1233     // Composite "andcc" test:
1234     // (a) %sp -vs- markword proximity check, and,
1235     // (b) verify mark word LSBs == 0 (Stack-locked).
1236     //
1237     // FFFFF003/FFFFFFFFFFFF003 is (markOopDesc::lock_mask_in_place | -os::vm_page_size())
1238     // Note that the page size used for %sp proximity testing is arbitrary and is
1239     // unrelated to the actual MMU page size.  We use a 'logical' page size of
1240     // 4096 bytes.   F..FFF003 is designed to fit conveniently in the SIMM13 immediate
1241     // field of the andcc instruction.
1242     andcc (temp_reg, 0xFFFFF003, G0) ;
1243 
1244     // if condition is true we are done and hence we can store 0 in the displaced
1245     // header indicating it is a recursive lock and be done
1246     brx(Assembler::zero, true, Assembler::pt, done);
1247     delayed()->st_ptr(G0, lock_addr, BasicLock::displaced_header_offset_in_bytes());
1248 
1249     // none of the above fast optimizations worked so we have to get into the
1250     // slow case of monitor enter
1251     bind(slow_case);
1252     call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter), lock_reg);
1253 
1254     bind(done);
1255   }
1256 }
1257 
1258 // Unlocks an object. Used in monitorexit bytecode and remove_activation.
1259 //
1260 // Argument - lock_reg points to the BasicObjectLock for lock
1261 // Throw IllegalMonitorException if object is not locked by current thread
unlock_object(Register lock_reg)1262 void InterpreterMacroAssembler::unlock_object(Register lock_reg) {
1263   if (UseHeavyMonitors) {
1264     call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), lock_reg);
1265   } else {
1266     Register obj_reg = G3_scratch;
1267     Register mark_reg = G4_scratch;
1268     Register displaced_header_reg = G1_scratch;
1269     Address  lockobj_addr(lock_reg, BasicObjectLock::obj_offset_in_bytes());
1270     Address  mark_addr(obj_reg, oopDesc::mark_offset_in_bytes());
1271     Label    done;
1272 
1273     if (UseBiasedLocking) {
1274       // load the object out of the BasicObjectLock
1275       ld_ptr(lockobj_addr, obj_reg);
1276       biased_locking_exit(mark_addr, mark_reg, done, true);
1277       st_ptr(G0, lockobj_addr);  // free entry
1278     }
1279 
1280     // Test first if we are in the fast recursive case
1281     Address lock_addr(lock_reg, BasicObjectLock::lock_offset_in_bytes() + BasicLock::displaced_header_offset_in_bytes());
1282     ld_ptr(lock_addr, displaced_header_reg);
1283     br_null(displaced_header_reg, true, Assembler::pn, done);
1284     delayed()->st_ptr(G0, lockobj_addr);  // free entry
1285 
1286     // See if it is still a light weight lock, if so we just unlock
1287     // the object and we are done
1288 
1289     if (!UseBiasedLocking) {
1290       // load the object out of the BasicObjectLock
1291       ld_ptr(lockobj_addr, obj_reg);
1292     }
1293 
1294     // we have the displaced header in displaced_header_reg
1295     // we expect to see the stack address of the basicLock in case the
1296     // lock is still a light weight lock (lock_reg)
1297     assert(mark_addr.disp() == 0, "cas must take a zero displacement");
1298     cas_ptr(mark_addr.base(), lock_reg, displaced_header_reg);
1299     cmp(lock_reg, displaced_header_reg);
1300     brx(Assembler::equal, true, Assembler::pn, done);
1301     delayed()->st_ptr(G0, lockobj_addr);  // free entry
1302 
1303     // The lock has been converted into a heavy lock and hence
1304     // we need to get into the slow case
1305 
1306     call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), lock_reg);
1307 
1308     bind(done);
1309   }
1310 }
1311 
1312 // Get the method data pointer from the Method* and set the
1313 // specified register to its value.
1314 
set_method_data_pointer()1315 void InterpreterMacroAssembler::set_method_data_pointer() {
1316   assert(ProfileInterpreter, "must be profiling interpreter");
1317   Label get_continue;
1318 
1319   ld_ptr(Lmethod, in_bytes(Method::method_data_offset()), ImethodDataPtr);
1320   test_method_data_pointer(get_continue);
1321   add(ImethodDataPtr, in_bytes(MethodData::data_offset()), ImethodDataPtr);
1322   bind(get_continue);
1323 }
1324 
1325 // Set the method data pointer for the current bcp.
1326 
set_method_data_pointer_for_bcp()1327 void InterpreterMacroAssembler::set_method_data_pointer_for_bcp() {
1328   assert(ProfileInterpreter, "must be profiling interpreter");
1329   Label zero_continue;
1330 
1331   // Test MDO to avoid the call if it is NULL.
1332   ld_ptr(Lmethod, in_bytes(Method::method_data_offset()), ImethodDataPtr);
1333   test_method_data_pointer(zero_continue);
1334   call_VM_leaf(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::bcp_to_di), Lmethod, Lbcp);
1335   add(ImethodDataPtr, in_bytes(MethodData::data_offset()), ImethodDataPtr);
1336   add(ImethodDataPtr, O0, ImethodDataPtr);
1337   bind(zero_continue);
1338 }
1339 
1340 // Test ImethodDataPtr.  If it is null, continue at the specified label
1341 
test_method_data_pointer(Label & zero_continue)1342 void InterpreterMacroAssembler::test_method_data_pointer(Label& zero_continue) {
1343   assert(ProfileInterpreter, "must be profiling interpreter");
1344   br_null_short(ImethodDataPtr, Assembler::pn, zero_continue);
1345 }
1346 
verify_method_data_pointer()1347 void InterpreterMacroAssembler::verify_method_data_pointer() {
1348   assert(ProfileInterpreter, "must be profiling interpreter");
1349 #ifdef ASSERT
1350   Label verify_continue;
1351   test_method_data_pointer(verify_continue);
1352 
1353   // If the mdp is valid, it will point to a DataLayout header which is
1354   // consistent with the bcp.  The converse is highly probable also.
1355   lduh(ImethodDataPtr, in_bytes(DataLayout::bci_offset()), G3_scratch);
1356   ld_ptr(Lmethod, Method::const_offset(), O5);
1357   add(G3_scratch, in_bytes(ConstMethod::codes_offset()), G3_scratch);
1358   add(G3_scratch, O5, G3_scratch);
1359   cmp(Lbcp, G3_scratch);
1360   brx(Assembler::equal, false, Assembler::pt, verify_continue);
1361 
1362   Register temp_reg = O5;
1363   delayed()->mov(ImethodDataPtr, temp_reg);
1364   // %%% should use call_VM_leaf here?
1365   //call_VM_leaf(noreg, ..., Lmethod, Lbcp, ImethodDataPtr);
1366   save_frame_and_mov(sizeof(jdouble) / wordSize, Lmethod, O0, Lbcp, O1);
1367   Address d_save(FP, -sizeof(jdouble) + STACK_BIAS);
1368   stf(FloatRegisterImpl::D, Ftos_d, d_save);
1369   mov(temp_reg->after_save(), O2);
1370   save_thread(L7_thread_cache);
1371   call(CAST_FROM_FN_PTR(address, InterpreterRuntime::verify_mdp), relocInfo::none);
1372   delayed()->nop();
1373   restore_thread(L7_thread_cache);
1374   ldf(FloatRegisterImpl::D, d_save, Ftos_d);
1375   restore();
1376   bind(verify_continue);
1377 #endif // ASSERT
1378 }
1379 
test_invocation_counter_for_mdp(Register invocation_count,Register method_counters,Register Rtmp,Label & profile_continue)1380 void InterpreterMacroAssembler::test_invocation_counter_for_mdp(Register invocation_count,
1381                                                                 Register method_counters,
1382                                                                 Register Rtmp,
1383                                                                 Label &profile_continue) {
1384   assert(ProfileInterpreter, "must be profiling interpreter");
1385   // Control will flow to "profile_continue" if the counter is less than the
1386   // limit or if we call profile_method()
1387 
1388   Label done;
1389 
1390   // if no method data exists, and the counter is high enough, make one
1391   br_notnull_short(ImethodDataPtr, Assembler::pn, done);
1392 
1393   // Test to see if we should create a method data oop
1394   Address profile_limit(method_counters, MethodCounters::interpreter_profile_limit_offset());
1395   ld(profile_limit, Rtmp);
1396   cmp(invocation_count, Rtmp);
1397   // Use long branches because call_VM() code and following code generated by
1398   // test_backedge_count_for_osr() is large in debug VM.
1399   br(Assembler::lessUnsigned, false, Assembler::pn, profile_continue);
1400   delayed()->nop();
1401 
1402   // Build it now.
1403   call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::profile_method));
1404   set_method_data_pointer_for_bcp();
1405   ba(profile_continue);
1406   delayed()->nop();
1407   bind(done);
1408 }
1409 
1410 // Store a value at some constant offset from the method data pointer.
1411 
set_mdp_data_at(int constant,Register value)1412 void InterpreterMacroAssembler::set_mdp_data_at(int constant, Register value) {
1413   assert(ProfileInterpreter, "must be profiling interpreter");
1414   st_ptr(value, ImethodDataPtr, constant);
1415 }
1416 
increment_mdp_data_at(Address counter,Register bumped_count,bool decrement)1417 void InterpreterMacroAssembler::increment_mdp_data_at(Address counter,
1418                                                       Register bumped_count,
1419                                                       bool decrement) {
1420   assert(ProfileInterpreter, "must be profiling interpreter");
1421 
1422   // Load the counter.
1423   ld_ptr(counter, bumped_count);
1424 
1425   if (decrement) {
1426     // Decrement the register.  Set condition codes.
1427     subcc(bumped_count, DataLayout::counter_increment, bumped_count);
1428 
1429     // If the decrement causes the counter to overflow, stay negative
1430     Label L;
1431     brx(Assembler::negative, true, Assembler::pn, L);
1432 
1433     // Store the decremented counter, if it is still negative.
1434     delayed()->st_ptr(bumped_count, counter);
1435     bind(L);
1436   } else {
1437     // Increment the register.  Set carry flag.
1438     addcc(bumped_count, DataLayout::counter_increment, bumped_count);
1439 
1440     // If the increment causes the counter to overflow, pull back by 1.
1441     assert(DataLayout::counter_increment == 1, "subc works");
1442     subc(bumped_count, G0, bumped_count);
1443 
1444     // Store the incremented counter.
1445     st_ptr(bumped_count, counter);
1446   }
1447 }
1448 
1449 // Increment the value at some constant offset from the method data pointer.
1450 
increment_mdp_data_at(int constant,Register bumped_count,bool decrement)1451 void InterpreterMacroAssembler::increment_mdp_data_at(int constant,
1452                                                       Register bumped_count,
1453                                                       bool decrement) {
1454   // Locate the counter at a fixed offset from the mdp:
1455   Address counter(ImethodDataPtr, constant);
1456   increment_mdp_data_at(counter, bumped_count, decrement);
1457 }
1458 
1459 // Increment the value at some non-fixed (reg + constant) offset from
1460 // the method data pointer.
1461 
increment_mdp_data_at(Register reg,int constant,Register bumped_count,Register scratch2,bool decrement)1462 void InterpreterMacroAssembler::increment_mdp_data_at(Register reg,
1463                                                       int constant,
1464                                                       Register bumped_count,
1465                                                       Register scratch2,
1466                                                       bool decrement) {
1467   // Add the constant to reg to get the offset.
1468   add(ImethodDataPtr, reg, scratch2);
1469   Address counter(scratch2, constant);
1470   increment_mdp_data_at(counter, bumped_count, decrement);
1471 }
1472 
1473 // Set a flag value at the current method data pointer position.
1474 // Updates a single byte of the header, to avoid races with other header bits.
1475 
set_mdp_flag_at(int flag_constant,Register scratch)1476 void InterpreterMacroAssembler::set_mdp_flag_at(int flag_constant,
1477                                                 Register scratch) {
1478   assert(ProfileInterpreter, "must be profiling interpreter");
1479   // Load the data header
1480   ldub(ImethodDataPtr, in_bytes(DataLayout::flags_offset()), scratch);
1481 
1482   // Set the flag
1483   or3(scratch, flag_constant, scratch);
1484 
1485   // Store the modified header.
1486   stb(scratch, ImethodDataPtr, in_bytes(DataLayout::flags_offset()));
1487 }
1488 
1489 // Test the location at some offset from the method data pointer.
1490 // If it is not equal to value, branch to the not_equal_continue Label.
1491 // Set condition codes to match the nullness of the loaded value.
1492 
test_mdp_data_at(int offset,Register value,Label & not_equal_continue,Register scratch)1493 void InterpreterMacroAssembler::test_mdp_data_at(int offset,
1494                                                  Register value,
1495                                                  Label& not_equal_continue,
1496                                                  Register scratch) {
1497   assert(ProfileInterpreter, "must be profiling interpreter");
1498   ld_ptr(ImethodDataPtr, offset, scratch);
1499   cmp(value, scratch);
1500   brx(Assembler::notEqual, false, Assembler::pn, not_equal_continue);
1501   delayed()->tst(scratch);
1502 }
1503 
1504 // Update the method data pointer by the displacement located at some fixed
1505 // offset from the method data pointer.
1506 
update_mdp_by_offset(int offset_of_disp,Register scratch)1507 void InterpreterMacroAssembler::update_mdp_by_offset(int offset_of_disp,
1508                                                      Register scratch) {
1509   assert(ProfileInterpreter, "must be profiling interpreter");
1510   ld_ptr(ImethodDataPtr, offset_of_disp, scratch);
1511   add(ImethodDataPtr, scratch, ImethodDataPtr);
1512 }
1513 
1514 // Update the method data pointer by the displacement located at the
1515 // offset (reg + offset_of_disp).
1516 
update_mdp_by_offset(Register reg,int offset_of_disp,Register scratch)1517 void InterpreterMacroAssembler::update_mdp_by_offset(Register reg,
1518                                                      int offset_of_disp,
1519                                                      Register scratch) {
1520   assert(ProfileInterpreter, "must be profiling interpreter");
1521   add(reg, offset_of_disp, scratch);
1522   ld_ptr(ImethodDataPtr, scratch, scratch);
1523   add(ImethodDataPtr, scratch, ImethodDataPtr);
1524 }
1525 
1526 // Update the method data pointer by a simple constant displacement.
1527 
update_mdp_by_constant(int constant)1528 void InterpreterMacroAssembler::update_mdp_by_constant(int constant) {
1529   assert(ProfileInterpreter, "must be profiling interpreter");
1530   add(ImethodDataPtr, constant, ImethodDataPtr);
1531 }
1532 
1533 // Update the method data pointer for a _ret bytecode whose target
1534 // was not among our cached targets.
1535 
update_mdp_for_ret(TosState state,Register return_bci)1536 void InterpreterMacroAssembler::update_mdp_for_ret(TosState state,
1537                                                    Register return_bci) {
1538   assert(ProfileInterpreter, "must be profiling interpreter");
1539   push(state);
1540   st_ptr(return_bci, l_tmp);  // protect return_bci, in case it is volatile
1541   call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::update_mdp_for_ret), return_bci);
1542   ld_ptr(l_tmp, return_bci);
1543   pop(state);
1544 }
1545 
1546 // Count a taken branch in the bytecodes.
1547 
profile_taken_branch(Register scratch,Register bumped_count)1548 void InterpreterMacroAssembler::profile_taken_branch(Register scratch, Register bumped_count) {
1549   if (ProfileInterpreter) {
1550     Label profile_continue;
1551 
1552     // If no method data exists, go to profile_continue.
1553     test_method_data_pointer(profile_continue);
1554 
1555     // We are taking a branch.  Increment the taken count.
1556     increment_mdp_data_at(in_bytes(JumpData::taken_offset()), bumped_count);
1557 
1558     // The method data pointer needs to be updated to reflect the new target.
1559     update_mdp_by_offset(in_bytes(JumpData::displacement_offset()), scratch);
1560     bind (profile_continue);
1561   }
1562 }
1563 
1564 
1565 // Count a not-taken branch in the bytecodes.
1566 
profile_not_taken_branch(Register scratch)1567 void InterpreterMacroAssembler::profile_not_taken_branch(Register scratch) {
1568   if (ProfileInterpreter) {
1569     Label profile_continue;
1570 
1571     // If no method data exists, go to profile_continue.
1572     test_method_data_pointer(profile_continue);
1573 
1574     // We are taking a branch.  Increment the not taken count.
1575     increment_mdp_data_at(in_bytes(BranchData::not_taken_offset()), scratch);
1576 
1577     // The method data pointer needs to be updated to correspond to the
1578     // next bytecode.
1579     update_mdp_by_constant(in_bytes(BranchData::branch_data_size()));
1580     bind (profile_continue);
1581   }
1582 }
1583 
1584 
1585 // Count a non-virtual call in the bytecodes.
1586 
profile_call(Register scratch)1587 void InterpreterMacroAssembler::profile_call(Register scratch) {
1588   if (ProfileInterpreter) {
1589     Label profile_continue;
1590 
1591     // If no method data exists, go to profile_continue.
1592     test_method_data_pointer(profile_continue);
1593 
1594     // We are making a call.  Increment the count.
1595     increment_mdp_data_at(in_bytes(CounterData::count_offset()), scratch);
1596 
1597     // The method data pointer needs to be updated to reflect the new target.
1598     update_mdp_by_constant(in_bytes(CounterData::counter_data_size()));
1599     bind (profile_continue);
1600   }
1601 }
1602 
1603 
1604 // Count a final call in the bytecodes.
1605 
profile_final_call(Register scratch)1606 void InterpreterMacroAssembler::profile_final_call(Register scratch) {
1607   if (ProfileInterpreter) {
1608     Label profile_continue;
1609 
1610     // If no method data exists, go to profile_continue.
1611     test_method_data_pointer(profile_continue);
1612 
1613     // We are making a call.  Increment the count.
1614     increment_mdp_data_at(in_bytes(CounterData::count_offset()), scratch);
1615 
1616     // The method data pointer needs to be updated to reflect the new target.
1617     update_mdp_by_constant(in_bytes(VirtualCallData::virtual_call_data_size()));
1618     bind (profile_continue);
1619   }
1620 }
1621 
1622 
1623 // Count a virtual call in the bytecodes.
1624 
profile_virtual_call(Register receiver,Register scratch,bool receiver_can_be_null)1625 void InterpreterMacroAssembler::profile_virtual_call(Register receiver,
1626                                                      Register scratch,
1627                                                      bool receiver_can_be_null) {
1628   if (ProfileInterpreter) {
1629     Label profile_continue;
1630 
1631     // If no method data exists, go to profile_continue.
1632     test_method_data_pointer(profile_continue);
1633 
1634 
1635     Label skip_receiver_profile;
1636     if (receiver_can_be_null) {
1637       Label not_null;
1638       br_notnull_short(receiver, Assembler::pt, not_null);
1639       // We are making a call.  Increment the count for null receiver.
1640       increment_mdp_data_at(in_bytes(CounterData::count_offset()), scratch);
1641       ba_short(skip_receiver_profile);
1642       bind(not_null);
1643     }
1644 
1645     // Record the receiver type.
1646     record_klass_in_profile(receiver, scratch, true);
1647     bind(skip_receiver_profile);
1648 
1649     // The method data pointer needs to be updated to reflect the new target.
1650 #if INCLUDE_JVMCI
1651     if (MethodProfileWidth == 0) {
1652       update_mdp_by_constant(in_bytes(VirtualCallData::virtual_call_data_size()));
1653     }
1654 #else
1655     update_mdp_by_constant(in_bytes(VirtualCallData::virtual_call_data_size()));
1656 #endif
1657     bind(profile_continue);
1658   }
1659 }
1660 
1661 #if INCLUDE_JVMCI
profile_called_method(Register method,Register scratch)1662 void InterpreterMacroAssembler::profile_called_method(Register method, Register scratch) {
1663   assert_different_registers(method, scratch);
1664   if (ProfileInterpreter && MethodProfileWidth > 0) {
1665     Label profile_continue;
1666 
1667     // If no method data exists, go to profile_continue.
1668     test_method_data_pointer(profile_continue);
1669 
1670     Label done;
1671     record_item_in_profile_helper(method, scratch, 0, done, MethodProfileWidth,
1672       &VirtualCallData::method_offset, &VirtualCallData::method_count_offset, in_bytes(VirtualCallData::nonprofiled_receiver_count_offset()));
1673     bind(done);
1674 
1675     update_mdp_by_constant(in_bytes(VirtualCallData::virtual_call_data_size()));
1676     bind(profile_continue);
1677   }
1678 }
1679 #endif // INCLUDE_JVMCI
1680 
record_klass_in_profile_helper(Register receiver,Register scratch,Label & done,bool is_virtual_call)1681 void InterpreterMacroAssembler::record_klass_in_profile_helper(Register receiver, Register scratch,
1682                                                                Label& done, bool is_virtual_call) {
1683   if (TypeProfileWidth == 0) {
1684     if (is_virtual_call) {
1685       increment_mdp_data_at(in_bytes(CounterData::count_offset()), scratch);
1686     }
1687 #if INCLUDE_JVMCI
1688     else if (EnableJVMCI) {
1689       increment_mdp_data_at(in_bytes(ReceiverTypeData::nonprofiled_receiver_count_offset()), scratch);
1690     }
1691 #endif
1692   } else {
1693     int non_profiled_offset = -1;
1694     if (is_virtual_call) {
1695       non_profiled_offset = in_bytes(CounterData::count_offset());
1696     }
1697 #if INCLUDE_JVMCI
1698     else if (EnableJVMCI) {
1699       non_profiled_offset = in_bytes(ReceiverTypeData::nonprofiled_receiver_count_offset());
1700     }
1701 #endif
1702 
1703     record_item_in_profile_helper(receiver, scratch, 0, done, TypeProfileWidth,
1704       &VirtualCallData::receiver_offset, &VirtualCallData::receiver_count_offset, non_profiled_offset);
1705   }
1706 }
1707 
record_item_in_profile_helper(Register item,Register scratch,int start_row,Label & done,int total_rows,OffsetFunction item_offset_fn,OffsetFunction item_count_offset_fn,int non_profiled_offset)1708 void InterpreterMacroAssembler::record_item_in_profile_helper(Register item,
1709                                           Register scratch, int start_row, Label& done, int total_rows,
1710                                           OffsetFunction item_offset_fn, OffsetFunction item_count_offset_fn,
1711                                           int non_profiled_offset) {
1712   int last_row = total_rows - 1;
1713   assert(start_row <= last_row, "must be work left to do");
1714   // Test this row for both the item and for null.
1715   // Take any of three different outcomes:
1716   //   1. found item => increment count and goto done
1717   //   2. found null => keep looking for case 1, maybe allocate this cell
1718   //   3. found something else => keep looking for cases 1 and 2
1719   // Case 3 is handled by a recursive call.
1720   for (int row = start_row; row <= last_row; row++) {
1721     Label next_test;
1722     bool test_for_null_also = (row == start_row);
1723 
1724     // See if the item is item[n].
1725     int item_offset = in_bytes(item_offset_fn(row));
1726     test_mdp_data_at(item_offset, item, next_test, scratch);
1727     // delayed()->tst(scratch);
1728 
1729     // The receiver is item[n].  Increment count[n].
1730     int count_offset = in_bytes(item_count_offset_fn(row));
1731     increment_mdp_data_at(count_offset, scratch);
1732     ba_short(done);
1733     bind(next_test);
1734 
1735     if (test_for_null_also) {
1736       Label found_null;
1737       // Failed the equality check on item[n]...  Test for null.
1738       if (start_row == last_row) {
1739         // The only thing left to do is handle the null case.
1740         if (non_profiled_offset >= 0) {
1741           brx(Assembler::zero, false, Assembler::pn, found_null);
1742           delayed()->nop();
1743           // Item did not match any saved item and there is no empty row for it.
1744           // Increment total counter to indicate polymorphic case.
1745           increment_mdp_data_at(non_profiled_offset, scratch);
1746           ba_short(done);
1747           bind(found_null);
1748         } else {
1749           brx(Assembler::notZero, false, Assembler::pt, done);
1750           delayed()->nop();
1751         }
1752         break;
1753       }
1754       // Since null is rare, make it be the branch-taken case.
1755       brx(Assembler::zero, false, Assembler::pn, found_null);
1756       delayed()->nop();
1757 
1758       // Put all the "Case 3" tests here.
1759       record_item_in_profile_helper(item, scratch, start_row + 1, done, total_rows,
1760         item_offset_fn, item_count_offset_fn, non_profiled_offset);
1761 
1762       // Found a null.  Keep searching for a matching item,
1763       // but remember that this is an empty (unused) slot.
1764       bind(found_null);
1765     }
1766   }
1767 
1768   // In the fall-through case, we found no matching item, but we
1769   // observed the item[start_row] is NULL.
1770 
1771   // Fill in the item field and increment the count.
1772   int item_offset = in_bytes(item_offset_fn(start_row));
1773   set_mdp_data_at(item_offset, item);
1774   int count_offset = in_bytes(item_count_offset_fn(start_row));
1775   mov(DataLayout::counter_increment, scratch);
1776   set_mdp_data_at(count_offset, scratch);
1777   if (start_row > 0) {
1778     ba_short(done);
1779   }
1780 }
1781 
record_klass_in_profile(Register receiver,Register scratch,bool is_virtual_call)1782 void InterpreterMacroAssembler::record_klass_in_profile(Register receiver,
1783                                                         Register scratch, bool is_virtual_call) {
1784   assert(ProfileInterpreter, "must be profiling");
1785   Label done;
1786 
1787   record_klass_in_profile_helper(receiver, scratch, done, is_virtual_call);
1788 
1789   bind (done);
1790 }
1791 
1792 
1793 // Count a ret in the bytecodes.
1794 
profile_ret(TosState state,Register return_bci,Register scratch)1795 void InterpreterMacroAssembler::profile_ret(TosState state,
1796                                             Register return_bci,
1797                                             Register scratch) {
1798   if (ProfileInterpreter) {
1799     Label profile_continue;
1800     uint row;
1801 
1802     // If no method data exists, go to profile_continue.
1803     test_method_data_pointer(profile_continue);
1804 
1805     // Update the total ret count.
1806     increment_mdp_data_at(in_bytes(CounterData::count_offset()), scratch);
1807 
1808     for (row = 0; row < RetData::row_limit(); row++) {
1809       Label next_test;
1810 
1811       // See if return_bci is equal to bci[n]:
1812       test_mdp_data_at(in_bytes(RetData::bci_offset(row)),
1813                        return_bci, next_test, scratch);
1814 
1815       // return_bci is equal to bci[n].  Increment the count.
1816       increment_mdp_data_at(in_bytes(RetData::bci_count_offset(row)), scratch);
1817 
1818       // The method data pointer needs to be updated to reflect the new target.
1819       update_mdp_by_offset(in_bytes(RetData::bci_displacement_offset(row)), scratch);
1820       ba_short(profile_continue);
1821       bind(next_test);
1822     }
1823 
1824     update_mdp_for_ret(state, return_bci);
1825 
1826     bind (profile_continue);
1827   }
1828 }
1829 
1830 // Profile an unexpected null in the bytecodes.
profile_null_seen(Register scratch)1831 void InterpreterMacroAssembler::profile_null_seen(Register scratch) {
1832   if (ProfileInterpreter) {
1833     Label profile_continue;
1834 
1835     // If no method data exists, go to profile_continue.
1836     test_method_data_pointer(profile_continue);
1837 
1838     set_mdp_flag_at(BitData::null_seen_byte_constant(), scratch);
1839 
1840     // The method data pointer needs to be updated.
1841     int mdp_delta = in_bytes(BitData::bit_data_size());
1842     if (TypeProfileCasts) {
1843       mdp_delta = in_bytes(ReceiverTypeData::receiver_type_data_size());
1844     }
1845     update_mdp_by_constant(mdp_delta);
1846 
1847     bind (profile_continue);
1848   }
1849 }
1850 
profile_typecheck(Register klass,Register scratch)1851 void InterpreterMacroAssembler::profile_typecheck(Register klass,
1852                                                   Register scratch) {
1853   if (ProfileInterpreter) {
1854     Label profile_continue;
1855 
1856     // If no method data exists, go to profile_continue.
1857     test_method_data_pointer(profile_continue);
1858 
1859     int mdp_delta = in_bytes(BitData::bit_data_size());
1860     if (TypeProfileCasts) {
1861       mdp_delta = in_bytes(ReceiverTypeData::receiver_type_data_size());
1862 
1863       // Record the object type.
1864       record_klass_in_profile(klass, scratch, false);
1865     }
1866 
1867     // The method data pointer needs to be updated.
1868     update_mdp_by_constant(mdp_delta);
1869 
1870     bind (profile_continue);
1871   }
1872 }
1873 
profile_typecheck_failed(Register scratch)1874 void InterpreterMacroAssembler::profile_typecheck_failed(Register scratch) {
1875   if (ProfileInterpreter && TypeProfileCasts) {
1876     Label profile_continue;
1877 
1878     // If no method data exists, go to profile_continue.
1879     test_method_data_pointer(profile_continue);
1880 
1881     int count_offset = in_bytes(CounterData::count_offset());
1882     // Back up the address, since we have already bumped the mdp.
1883     count_offset -= in_bytes(ReceiverTypeData::receiver_type_data_size());
1884 
1885     // *Decrement* the counter.  We expect to see zero or small negatives.
1886     increment_mdp_data_at(count_offset, scratch, true);
1887 
1888     bind (profile_continue);
1889   }
1890 }
1891 
1892 // Count the default case of a switch construct.
1893 
profile_switch_default(Register scratch)1894 void InterpreterMacroAssembler::profile_switch_default(Register scratch) {
1895   if (ProfileInterpreter) {
1896     Label profile_continue;
1897 
1898     // If no method data exists, go to profile_continue.
1899     test_method_data_pointer(profile_continue);
1900 
1901     // Update the default case count
1902     increment_mdp_data_at(in_bytes(MultiBranchData::default_count_offset()),
1903                           scratch);
1904 
1905     // The method data pointer needs to be updated.
1906     update_mdp_by_offset(
1907                     in_bytes(MultiBranchData::default_displacement_offset()),
1908                     scratch);
1909 
1910     bind (profile_continue);
1911   }
1912 }
1913 
1914 // Count the index'th case of a switch construct.
1915 
profile_switch_case(Register index,Register scratch,Register scratch2,Register scratch3)1916 void InterpreterMacroAssembler::profile_switch_case(Register index,
1917                                                     Register scratch,
1918                                                     Register scratch2,
1919                                                     Register scratch3) {
1920   if (ProfileInterpreter) {
1921     Label profile_continue;
1922 
1923     // If no method data exists, go to profile_continue.
1924     test_method_data_pointer(profile_continue);
1925 
1926     // Build the base (index * per_case_size_in_bytes()) + case_array_offset_in_bytes()
1927     set(in_bytes(MultiBranchData::per_case_size()), scratch);
1928     smul(index, scratch, scratch);
1929     add(scratch, in_bytes(MultiBranchData::case_array_offset()), scratch);
1930 
1931     // Update the case count
1932     increment_mdp_data_at(scratch,
1933                           in_bytes(MultiBranchData::relative_count_offset()),
1934                           scratch2,
1935                           scratch3);
1936 
1937     // The method data pointer needs to be updated.
1938     update_mdp_by_offset(scratch,
1939                      in_bytes(MultiBranchData::relative_displacement_offset()),
1940                      scratch2);
1941 
1942     bind (profile_continue);
1943   }
1944 }
1945 
profile_obj_type(Register obj,const Address & mdo_addr,Register tmp)1946 void InterpreterMacroAssembler::profile_obj_type(Register obj, const Address& mdo_addr, Register tmp) {
1947   Label not_null, do_nothing, do_update;
1948 
1949   assert_different_registers(obj, mdo_addr.base(), tmp);
1950 
1951   verify_oop(obj);
1952 
1953   ld_ptr(mdo_addr, tmp);
1954 
1955   br_notnull_short(obj, pt, not_null);
1956   or3(tmp, TypeEntries::null_seen, tmp);
1957   ba_short(do_update);
1958 
1959   bind(not_null);
1960   load_klass(obj, obj);
1961 
1962   xor3(obj, tmp, obj);
1963   btst(TypeEntries::type_klass_mask, obj);
1964   // klass seen before, nothing to do. The unknown bit may have been
1965   // set already but no need to check.
1966   brx(zero, false, pt, do_nothing);
1967   delayed()->
1968 
1969   btst(TypeEntries::type_unknown, obj);
1970   // already unknown. Nothing to do anymore.
1971   brx(notZero, false, pt, do_nothing);
1972   delayed()->
1973 
1974   btst(TypeEntries::type_mask, tmp);
1975   brx(zero, true, pt, do_update);
1976   // first time here. Set profile type.
1977   delayed()->or3(tmp, obj, tmp);
1978 
1979   // different than before. Cannot keep accurate profile.
1980   or3(tmp, TypeEntries::type_unknown, tmp);
1981 
1982   bind(do_update);
1983   // update profile
1984   st_ptr(tmp, mdo_addr);
1985 
1986   bind(do_nothing);
1987 }
1988 
profile_arguments_type(Register callee,Register tmp1,Register tmp2,bool is_virtual)1989 void InterpreterMacroAssembler::profile_arguments_type(Register callee, Register tmp1, Register tmp2, bool is_virtual) {
1990   if (!ProfileInterpreter) {
1991     return;
1992   }
1993 
1994   assert_different_registers(callee, tmp1, tmp2, ImethodDataPtr);
1995 
1996   if (MethodData::profile_arguments() || MethodData::profile_return()) {
1997     Label profile_continue;
1998 
1999     test_method_data_pointer(profile_continue);
2000 
2001     int off_to_start = is_virtual ? in_bytes(VirtualCallData::virtual_call_data_size()) : in_bytes(CounterData::counter_data_size());
2002 
2003     ldub(ImethodDataPtr, in_bytes(DataLayout::tag_offset()) - off_to_start, tmp1);
2004     cmp_and_br_short(tmp1, is_virtual ? DataLayout::virtual_call_type_data_tag : DataLayout::call_type_data_tag, notEqual, pn, profile_continue);
2005 
2006     if (MethodData::profile_arguments()) {
2007       Label done;
2008       int off_to_args = in_bytes(TypeEntriesAtCall::args_data_offset());
2009       add(ImethodDataPtr, off_to_args, ImethodDataPtr);
2010 
2011       for (int i = 0; i < TypeProfileArgsLimit; i++) {
2012         if (i > 0 || MethodData::profile_return()) {
2013           // If return value type is profiled we may have no argument to profile
2014           ld_ptr(ImethodDataPtr, in_bytes(TypeEntriesAtCall::cell_count_offset())-off_to_args, tmp1);
2015           sub(tmp1, i*TypeStackSlotEntries::per_arg_count(), tmp1);
2016           cmp_and_br_short(tmp1, TypeStackSlotEntries::per_arg_count(), less, pn, done);
2017         }
2018         ld_ptr(Address(callee, Method::const_offset()), tmp1);
2019         lduh(Address(tmp1, ConstMethod::size_of_parameters_offset()), tmp1);
2020         // stack offset o (zero based) from the start of the argument
2021         // list, for n arguments translates into offset n - o - 1 from
2022         // the end of the argument list. But there's an extra slot at
2023         // the stop of the stack. So the offset is n - o from Lesp.
2024         ld_ptr(ImethodDataPtr, in_bytes(TypeEntriesAtCall::stack_slot_offset(i))-off_to_args, tmp2);
2025         sub(tmp1, tmp2, tmp1);
2026 
2027         // Can't use MacroAssembler::argument_address() which needs Gargs to be set up
2028         sll(tmp1, Interpreter::logStackElementSize, tmp1);
2029         ld_ptr(Lesp, tmp1, tmp1);
2030 
2031         Address mdo_arg_addr(ImethodDataPtr, in_bytes(TypeEntriesAtCall::argument_type_offset(i))-off_to_args);
2032         profile_obj_type(tmp1, mdo_arg_addr, tmp2);
2033 
2034         int to_add = in_bytes(TypeStackSlotEntries::per_arg_size());
2035         add(ImethodDataPtr, to_add, ImethodDataPtr);
2036         off_to_args += to_add;
2037       }
2038 
2039       if (MethodData::profile_return()) {
2040         ld_ptr(ImethodDataPtr, in_bytes(TypeEntriesAtCall::cell_count_offset())-off_to_args, tmp1);
2041         sub(tmp1, TypeProfileArgsLimit*TypeStackSlotEntries::per_arg_count(), tmp1);
2042       }
2043 
2044       bind(done);
2045 
2046       if (MethodData::profile_return()) {
2047         // We're right after the type profile for the last
2048         // argument. tmp1 is the number of cells left in the
2049         // CallTypeData/VirtualCallTypeData to reach its end. Non null
2050         // if there's a return to profile.
2051         assert(ReturnTypeEntry::static_cell_count() < TypeStackSlotEntries::per_arg_count(), "can't move past ret type");
2052         sll(tmp1, exact_log2(DataLayout::cell_size), tmp1);
2053         add(ImethodDataPtr, tmp1, ImethodDataPtr);
2054       }
2055     } else {
2056       assert(MethodData::profile_return(), "either profile call args or call ret");
2057       update_mdp_by_constant(in_bytes(TypeEntriesAtCall::return_only_size()));
2058     }
2059 
2060     // mdp points right after the end of the
2061     // CallTypeData/VirtualCallTypeData, right after the cells for the
2062     // return value type if there's one.
2063 
2064     bind(profile_continue);
2065   }
2066 }
2067 
profile_return_type(Register ret,Register tmp1,Register tmp2)2068 void InterpreterMacroAssembler::profile_return_type(Register ret, Register tmp1, Register tmp2) {
2069   assert_different_registers(ret, tmp1, tmp2);
2070   if (ProfileInterpreter && MethodData::profile_return()) {
2071     Label profile_continue, done;
2072 
2073     test_method_data_pointer(profile_continue);
2074 
2075     if (MethodData::profile_return_jsr292_only()) {
2076       assert(Method::intrinsic_id_size_in_bytes() == 2, "assuming Method::_intrinsic_id is u2");
2077 
2078       // If we don't profile all invoke bytecodes we must make sure
2079       // it's a bytecode we indeed profile. We can't go back to the
2080       // begining of the ProfileData we intend to update to check its
2081       // type because we're right after it and we don't known its
2082       // length.
2083       Label do_profile;
2084       ldub(Lbcp, 0, tmp1);
2085       cmp_and_br_short(tmp1, Bytecodes::_invokedynamic, equal, pn, do_profile);
2086       cmp(tmp1, Bytecodes::_invokehandle);
2087       br(equal, false, pn, do_profile);
2088       delayed()->lduh(Lmethod, Method::intrinsic_id_offset_in_bytes(), tmp1);
2089       cmp_and_br_short(tmp1, vmIntrinsics::_compiledLambdaForm, notEqual, pt, profile_continue);
2090 
2091       bind(do_profile);
2092     }
2093 
2094     Address mdo_ret_addr(ImethodDataPtr, -in_bytes(ReturnTypeEntry::size()));
2095     mov(ret, tmp1);
2096     profile_obj_type(tmp1, mdo_ret_addr, tmp2);
2097 
2098     bind(profile_continue);
2099   }
2100 }
2101 
profile_parameters_type(Register tmp1,Register tmp2,Register tmp3,Register tmp4)2102 void InterpreterMacroAssembler::profile_parameters_type(Register tmp1, Register tmp2, Register tmp3, Register tmp4) {
2103   if (ProfileInterpreter && MethodData::profile_parameters()) {
2104     Label profile_continue, done;
2105 
2106     test_method_data_pointer(profile_continue);
2107 
2108     // Load the offset of the area within the MDO used for
2109     // parameters. If it's negative we're not profiling any parameters.
2110     lduw(ImethodDataPtr, in_bytes(MethodData::parameters_type_data_di_offset()) - in_bytes(MethodData::data_offset()), tmp1);
2111     cmp_and_br_short(tmp1, 0, less, pn, profile_continue);
2112 
2113     // Compute a pointer to the area for parameters from the offset
2114     // and move the pointer to the slot for the last
2115     // parameters. Collect profiling from last parameter down.
2116     // mdo start + parameters offset + array length - 1
2117 
2118     // Pointer to the parameter area in the MDO
2119     Register mdp = tmp1;
2120     add(ImethodDataPtr, tmp1, mdp);
2121 
2122     // offset of the current profile entry to update
2123     Register entry_offset = tmp2;
2124     // entry_offset = array len in number of cells
2125     ld_ptr(mdp, ArrayData::array_len_offset(), entry_offset);
2126 
2127     int off_base = in_bytes(ParametersTypeData::stack_slot_offset(0));
2128     assert(off_base % DataLayout::cell_size == 0, "should be a number of cells");
2129 
2130     // entry_offset (number of cells)  = array len - size of 1 entry + offset of the stack slot field
2131     sub(entry_offset, TypeStackSlotEntries::per_arg_count() - (off_base / DataLayout::cell_size), entry_offset);
2132     // entry_offset in bytes
2133     sll(entry_offset, exact_log2(DataLayout::cell_size), entry_offset);
2134 
2135     Label loop;
2136     bind(loop);
2137 
2138     // load offset on the stack from the slot for this parameter
2139     ld_ptr(mdp, entry_offset, tmp3);
2140     sll(tmp3,Interpreter::logStackElementSize, tmp3);
2141     neg(tmp3);
2142     // read the parameter from the local area
2143     ld_ptr(Llocals, tmp3, tmp3);
2144 
2145     // make entry_offset now point to the type field for this parameter
2146     int type_base = in_bytes(ParametersTypeData::type_offset(0));
2147     assert(type_base > off_base, "unexpected");
2148     add(entry_offset, type_base - off_base, entry_offset);
2149 
2150     // profile the parameter
2151     Address arg_type(mdp, entry_offset);
2152     profile_obj_type(tmp3, arg_type, tmp4);
2153 
2154     // go to next parameter
2155     sub(entry_offset, TypeStackSlotEntries::per_arg_count() * DataLayout::cell_size + (type_base - off_base), entry_offset);
2156     cmp_and_br_short(entry_offset, off_base, greaterEqual, pt, loop);
2157 
2158     bind(profile_continue);
2159   }
2160 }
2161 
2162 // add a InterpMonitorElem to stack (see frame_sparc.hpp)
2163 
add_monitor_to_stack(bool stack_is_empty,Register Rtemp,Register Rtemp2)2164 void InterpreterMacroAssembler::add_monitor_to_stack( bool stack_is_empty,
2165                                                       Register Rtemp,
2166                                                       Register Rtemp2 ) {
2167 
2168   Register Rlimit = Lmonitors;
2169   const jint delta = frame::interpreter_frame_monitor_size() * wordSize;
2170   assert( (delta & LongAlignmentMask) == 0,
2171           "sizeof BasicObjectLock must be even number of doublewords");
2172 
2173   sub( SP,        delta, SP);
2174   sub( Lesp,      delta, Lesp);
2175   sub( Lmonitors, delta, Lmonitors);
2176 
2177   if (!stack_is_empty) {
2178 
2179     // must copy stack contents down
2180 
2181     Label start_copying, next;
2182 
2183     // untested("monitor stack expansion");
2184     compute_stack_base(Rtemp);
2185     ba(start_copying);
2186     delayed()->cmp(Rtemp, Rlimit); // done? duplicated below
2187 
2188     // note: must copy from low memory upwards
2189     // On entry to loop,
2190     // Rtemp points to new base of stack, Lesp points to new end of stack (1 past TOS)
2191     // Loop mutates Rtemp
2192 
2193     bind( next);
2194 
2195     st_ptr(Rtemp2, Rtemp, 0);
2196     inc(Rtemp, wordSize);
2197     cmp(Rtemp, Rlimit); // are we done? (duplicated above)
2198 
2199     bind( start_copying );
2200 
2201     brx( notEqual, true, pn, next );
2202     delayed()->ld_ptr( Rtemp, delta, Rtemp2 );
2203 
2204     // done copying stack
2205   }
2206 }
2207 
2208 // Locals
access_local_ptr(Register index,Register dst)2209 void InterpreterMacroAssembler::access_local_ptr( Register index, Register dst ) {
2210   assert_not_delayed();
2211   sll(index, Interpreter::logStackElementSize, index);
2212   sub(Llocals, index, index);
2213   ld_ptr(index, 0, dst);
2214   // Note:  index must hold the effective address--the iinc template uses it
2215 }
2216 
2217 // Just like access_local_ptr but the tag is a returnAddress
access_local_returnAddress(Register index,Register dst)2218 void InterpreterMacroAssembler::access_local_returnAddress(Register index,
2219                                                            Register dst ) {
2220   assert_not_delayed();
2221   sll(index, Interpreter::logStackElementSize, index);
2222   sub(Llocals, index, index);
2223   ld_ptr(index, 0, dst);
2224 }
2225 
access_local_int(Register index,Register dst)2226 void InterpreterMacroAssembler::access_local_int( Register index, Register dst ) {
2227   assert_not_delayed();
2228   sll(index, Interpreter::logStackElementSize, index);
2229   sub(Llocals, index, index);
2230   ld(index, 0, dst);
2231   // Note:  index must hold the effective address--the iinc template uses it
2232 }
2233 
2234 
access_local_long(Register index,Register dst)2235 void InterpreterMacroAssembler::access_local_long( Register index, Register dst ) {
2236   assert_not_delayed();
2237   sll(index, Interpreter::logStackElementSize, index);
2238   sub(Llocals, index, index);
2239   // First half stored at index n+1 (which grows down from Llocals[n])
2240   load_unaligned_long(index, Interpreter::local_offset_in_bytes(1), dst);
2241 }
2242 
2243 
access_local_float(Register index,FloatRegister dst)2244 void InterpreterMacroAssembler::access_local_float( Register index, FloatRegister dst ) {
2245   assert_not_delayed();
2246   sll(index, Interpreter::logStackElementSize, index);
2247   sub(Llocals, index, index);
2248   ldf(FloatRegisterImpl::S, index, 0, dst);
2249 }
2250 
2251 
access_local_double(Register index,FloatRegister dst)2252 void InterpreterMacroAssembler::access_local_double( Register index, FloatRegister dst ) {
2253   assert_not_delayed();
2254   sll(index, Interpreter::logStackElementSize, index);
2255   sub(Llocals, index, index);
2256   load_unaligned_double(index, Interpreter::local_offset_in_bytes(1), dst);
2257 }
2258 
2259 
2260 #ifdef ASSERT
check_for_regarea_stomp(Register Rindex,int offset,Register Rlimit,Register Rscratch,Register Rscratch1)2261 void InterpreterMacroAssembler::check_for_regarea_stomp(Register Rindex, int offset, Register Rlimit, Register Rscratch, Register Rscratch1) {
2262   Label L;
2263 
2264   assert(Rindex != Rscratch, "Registers cannot be same");
2265   assert(Rindex != Rscratch1, "Registers cannot be same");
2266   assert(Rlimit != Rscratch, "Registers cannot be same");
2267   assert(Rlimit != Rscratch1, "Registers cannot be same");
2268   assert(Rscratch1 != Rscratch, "Registers cannot be same");
2269 
2270   // untested("reg area corruption");
2271   add(Rindex, offset, Rscratch);
2272   add(Rlimit, 64 + STACK_BIAS, Rscratch1);
2273   cmp_and_brx_short(Rscratch, Rscratch1, Assembler::greaterEqualUnsigned, pn, L);
2274   stop("regsave area is being clobbered");
2275   bind(L);
2276 }
2277 #endif // ASSERT
2278 
2279 
store_local_int(Register index,Register src)2280 void InterpreterMacroAssembler::store_local_int( Register index, Register src ) {
2281   assert_not_delayed();
2282   sll(index, Interpreter::logStackElementSize, index);
2283   sub(Llocals, index, index);
2284   debug_only(check_for_regarea_stomp(index, 0, FP, G1_scratch, G4_scratch);)
2285   st(src, index, 0);
2286 }
2287 
store_local_ptr(Register index,Register src)2288 void InterpreterMacroAssembler::store_local_ptr( Register index, Register src ) {
2289   assert_not_delayed();
2290   sll(index, Interpreter::logStackElementSize, index);
2291   sub(Llocals, index, index);
2292 #ifdef ASSERT
2293   check_for_regarea_stomp(index, 0, FP, G1_scratch, G4_scratch);
2294 #endif
2295   st_ptr(src, index, 0);
2296 }
2297 
2298 
2299 
store_local_ptr(int n,Register src)2300 void InterpreterMacroAssembler::store_local_ptr( int n, Register src ) {
2301   st_ptr(src, Llocals, Interpreter::local_offset_in_bytes(n));
2302 }
2303 
store_local_long(Register index,Register src)2304 void InterpreterMacroAssembler::store_local_long( Register index, Register src ) {
2305   assert_not_delayed();
2306   sll(index, Interpreter::logStackElementSize, index);
2307   sub(Llocals, index, index);
2308 #ifdef ASSERT
2309   check_for_regarea_stomp(index, Interpreter::local_offset_in_bytes(1), FP, G1_scratch, G4_scratch);
2310 #endif
2311   store_unaligned_long(src, index, Interpreter::local_offset_in_bytes(1)); // which is n+1
2312 }
2313 
2314 
store_local_float(Register index,FloatRegister src)2315 void InterpreterMacroAssembler::store_local_float( Register index, FloatRegister src ) {
2316   assert_not_delayed();
2317   sll(index, Interpreter::logStackElementSize, index);
2318   sub(Llocals, index, index);
2319 #ifdef ASSERT
2320   check_for_regarea_stomp(index, 0, FP, G1_scratch, G4_scratch);
2321 #endif
2322   stf(FloatRegisterImpl::S, src, index, 0);
2323 }
2324 
2325 
store_local_double(Register index,FloatRegister src)2326 void InterpreterMacroAssembler::store_local_double( Register index, FloatRegister src ) {
2327   assert_not_delayed();
2328   sll(index, Interpreter::logStackElementSize, index);
2329   sub(Llocals, index, index);
2330 #ifdef ASSERT
2331   check_for_regarea_stomp(index, Interpreter::local_offset_in_bytes(1), FP, G1_scratch, G4_scratch);
2332 #endif
2333   store_unaligned_double(src, index, Interpreter::local_offset_in_bytes(1));
2334 }
2335 
2336 
top_most_monitor_byte_offset()2337 int InterpreterMacroAssembler::top_most_monitor_byte_offset() {
2338   const jint delta = frame::interpreter_frame_monitor_size() * wordSize;
2339   int rounded_vm_local_words = align_up((int)frame::interpreter_frame_vm_local_words, WordsPerLong);
2340   return ((-rounded_vm_local_words * wordSize) - delta ) + STACK_BIAS;
2341 }
2342 
2343 
top_most_monitor()2344 Address InterpreterMacroAssembler::top_most_monitor() {
2345   return Address(FP, top_most_monitor_byte_offset());
2346 }
2347 
2348 
compute_stack_base(Register Rdest)2349 void InterpreterMacroAssembler::compute_stack_base( Register Rdest ) {
2350   add( Lesp,      wordSize,                                    Rdest );
2351 }
2352 
get_method_counters(Register method,Register Rcounters,Label & skip)2353 void InterpreterMacroAssembler::get_method_counters(Register method,
2354                                                     Register Rcounters,
2355                                                     Label& skip) {
2356   Label has_counters;
2357   Address method_counters(method, in_bytes(Method::method_counters_offset()));
2358   ld_ptr(method_counters, Rcounters);
2359   br_notnull_short(Rcounters, Assembler::pt, has_counters);
2360   call_VM(noreg, CAST_FROM_FN_PTR(address,
2361           InterpreterRuntime::build_method_counters), method);
2362   ld_ptr(method_counters, Rcounters);
2363   br_null(Rcounters, false, Assembler::pn, skip); // No MethodCounters, OutOfMemory
2364   delayed()->nop();
2365   bind(has_counters);
2366 }
2367 
increment_invocation_counter(Register Rcounters,Register Rtmp,Register Rtmp2)2368 void InterpreterMacroAssembler::increment_invocation_counter( Register Rcounters, Register Rtmp, Register Rtmp2 ) {
2369   assert(UseCompiler || LogTouchedMethods, "incrementing must be useful");
2370   assert_different_registers(Rcounters, Rtmp, Rtmp2);
2371 
2372   Address inv_counter(Rcounters, MethodCounters::invocation_counter_offset() +
2373                                  InvocationCounter::counter_offset());
2374   Address be_counter (Rcounters, MethodCounters::backedge_counter_offset() +
2375                                  InvocationCounter::counter_offset());
2376   int delta = InvocationCounter::count_increment;
2377 
2378   // Load each counter in a register
2379   ld( inv_counter, Rtmp );
2380   ld( be_counter, Rtmp2 );
2381 
2382   assert( is_simm13( delta ), " delta too large.");
2383 
2384   // Add the delta to the invocation counter and store the result
2385   add( Rtmp, delta, Rtmp );
2386 
2387   // Mask the backedge counter
2388   and3( Rtmp2, InvocationCounter::count_mask_value, Rtmp2 );
2389 
2390   // Store value
2391   st( Rtmp, inv_counter);
2392 
2393   // Add invocation counter + backedge counter
2394   add( Rtmp, Rtmp2, Rtmp);
2395 
2396   // Note that this macro must leave the backedge_count + invocation_count in Rtmp!
2397 }
2398 
increment_backedge_counter(Register Rcounters,Register Rtmp,Register Rtmp2)2399 void InterpreterMacroAssembler::increment_backedge_counter( Register Rcounters, Register Rtmp, Register Rtmp2 ) {
2400   assert(UseCompiler, "incrementing must be useful");
2401   assert_different_registers(Rcounters, Rtmp, Rtmp2);
2402 
2403   Address be_counter (Rcounters, MethodCounters::backedge_counter_offset() +
2404                                  InvocationCounter::counter_offset());
2405   Address inv_counter(Rcounters, MethodCounters::invocation_counter_offset() +
2406                                  InvocationCounter::counter_offset());
2407 
2408   int delta = InvocationCounter::count_increment;
2409   // Load each counter in a register
2410   ld( be_counter, Rtmp );
2411   ld( inv_counter, Rtmp2 );
2412 
2413   // Add the delta to the backedge counter
2414   add( Rtmp, delta, Rtmp );
2415 
2416   // Mask the invocation counter, add to backedge counter
2417   and3( Rtmp2, InvocationCounter::count_mask_value, Rtmp2 );
2418 
2419   // and store the result to memory
2420   st( Rtmp, be_counter );
2421 
2422   // Add backedge + invocation counter
2423   add( Rtmp, Rtmp2, Rtmp );
2424 
2425   // Note that this macro must leave backedge_count + invocation_count in Rtmp!
2426 }
2427 
test_backedge_count_for_osr(Register backedge_count,Register method_counters,Register branch_bcp,Register Rtmp)2428 void InterpreterMacroAssembler::test_backedge_count_for_osr( Register backedge_count,
2429                                                              Register method_counters,
2430                                                              Register branch_bcp,
2431                                                              Register Rtmp ) {
2432   Label did_not_overflow;
2433   Label overflow_with_error;
2434   assert_different_registers(backedge_count, Rtmp, branch_bcp);
2435   assert(UseOnStackReplacement,"Must UseOnStackReplacement to test_backedge_count_for_osr");
2436 
2437   Address limit(method_counters, in_bytes(MethodCounters::interpreter_backward_branch_limit_offset()));
2438   ld(limit, Rtmp);
2439   cmp_and_br_short(backedge_count, Rtmp, Assembler::lessUnsigned, Assembler::pt, did_not_overflow);
2440 
2441   // When ProfileInterpreter is on, the backedge_count comes from the
2442   // MethodData*, which value does not get reset on the call to
2443   // frequency_counter_overflow().  To avoid excessive calls to the overflow
2444   // routine while the method is being compiled, add a second test to make sure
2445   // the overflow function is called only once every overflow_frequency.
2446   if (ProfileInterpreter) {
2447     const int overflow_frequency = 1024;
2448     andcc(backedge_count, overflow_frequency-1, Rtmp);
2449     brx(Assembler::notZero, false, Assembler::pt, did_not_overflow);
2450     delayed()->nop();
2451   }
2452 
2453   // overflow in loop, pass branch bytecode
2454   set(6,Rtmp);
2455   call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::frequency_counter_overflow), branch_bcp, Rtmp);
2456 
2457   // Was an OSR adapter generated?
2458   // O0 = osr nmethod
2459   br_null_short(O0, Assembler::pn, overflow_with_error);
2460 
2461   // Has the nmethod been invalidated already?
2462   ldub(O0, nmethod::state_offset(), O2);
2463   cmp_and_br_short(O2, nmethod::in_use, Assembler::notEqual, Assembler::pn, overflow_with_error);
2464 
2465   // migrate the interpreter frame off of the stack
2466 
2467   mov(G2_thread, L7);
2468   // save nmethod
2469   mov(O0, L6);
2470   set_last_Java_frame(SP, noreg);
2471   call_VM_leaf(noreg, CAST_FROM_FN_PTR(address, SharedRuntime::OSR_migration_begin), L7);
2472   reset_last_Java_frame();
2473   mov(L7, G2_thread);
2474 
2475   // move OSR nmethod to I1
2476   mov(L6, I1);
2477 
2478   // OSR buffer to I0
2479   mov(O0, I0);
2480 
2481   // remove the interpreter frame
2482   restore(I5_savedSP, 0, SP);
2483 
2484   // Jump to the osr code.
2485   ld_ptr(O1, nmethod::osr_entry_point_offset(), O2);
2486   jmp(O2, G0);
2487   delayed()->nop();
2488 
2489   bind(overflow_with_error);
2490 
2491   bind(did_not_overflow);
2492 }
2493 
2494 
2495 
interp_verify_oop(Register reg,TosState state,const char * file,int line)2496 void InterpreterMacroAssembler::interp_verify_oop(Register reg, TosState state, const char * file, int line) {
2497   if (state == atos) { MacroAssembler::_verify_oop(reg, "broken oop ", file, line); }
2498 }
2499 
2500 
2501 // local helper function for the verify_oop_or_return_address macro
verify_return_address(Method * m,int bci)2502 static bool verify_return_address(Method* m, int bci) {
2503 #ifndef PRODUCT
2504   address pc = (address)(m->constMethod())
2505              + in_bytes(ConstMethod::codes_offset()) + bci;
2506   // assume it is a valid return address if it is inside m and is preceded by a jsr
2507   if (!m->contains(pc))                                          return false;
2508   address jsr_pc;
2509   jsr_pc = pc - Bytecodes::length_for(Bytecodes::_jsr);
2510   if (*jsr_pc == Bytecodes::_jsr   && jsr_pc >= m->code_base())    return true;
2511   jsr_pc = pc - Bytecodes::length_for(Bytecodes::_jsr_w);
2512   if (*jsr_pc == Bytecodes::_jsr_w && jsr_pc >= m->code_base())    return true;
2513 #endif // PRODUCT
2514   return false;
2515 }
2516 
2517 
verify_oop_or_return_address(Register reg,Register Rtmp)2518 void InterpreterMacroAssembler::verify_oop_or_return_address(Register reg, Register Rtmp) {
2519   if (!VerifyOops)  return;
2520   // the VM documentation for the astore[_wide] bytecode allows
2521   // the TOS to be not only an oop but also a return address
2522   Label test;
2523   Label skip;
2524   // See if it is an address (in the current method):
2525 
2526   mov(reg, Rtmp);
2527   const int log2_bytecode_size_limit = 16;
2528   srl(Rtmp, log2_bytecode_size_limit, Rtmp);
2529   br_notnull_short( Rtmp, pt, test );
2530 
2531   // %%% should use call_VM_leaf here?
2532   save_frame_and_mov(0, Lmethod, O0, reg, O1);
2533   save_thread(L7_thread_cache);
2534   call(CAST_FROM_FN_PTR(address,verify_return_address), relocInfo::none);
2535   delayed()->nop();
2536   restore_thread(L7_thread_cache);
2537   br_notnull( O0, false, pt, skip );
2538   delayed()->restore();
2539 
2540   // Perform a more elaborate out-of-line call
2541   // Not an address; verify it:
2542   bind(test);
2543   verify_oop(reg);
2544   bind(skip);
2545 }
2546 
2547 
verify_FPU(int stack_depth,TosState state)2548 void InterpreterMacroAssembler::verify_FPU(int stack_depth, TosState state) {
2549   if (state == ftos || state == dtos) MacroAssembler::verify_FPU(stack_depth);
2550 }
2551 
2552 
2553 // Jump if ((*counter_addr += increment) & mask) satisfies the condition.
increment_mask_and_jump(Address counter_addr,int increment,Address mask_addr,Register scratch1,Register scratch2,Condition cond,Label * where)2554 void InterpreterMacroAssembler::increment_mask_and_jump(Address counter_addr,
2555                                                         int increment, Address mask_addr,
2556                                                         Register scratch1, Register scratch2,
2557                                                         Condition cond, Label *where) {
2558   ld(counter_addr, scratch1);
2559   add(scratch1, increment, scratch1);
2560   ld(mask_addr, scratch2);
2561   andcc(scratch1, scratch2,  G0);
2562   br(cond, false, Assembler::pn, *where);
2563   delayed()->st(scratch1, counter_addr);
2564 }
2565 
2566 // Inline assembly for:
2567 //
2568 // if (thread is in interp_only_mode) {
2569 //   InterpreterRuntime::post_method_entry();
2570 // }
2571 // if (DTraceMethodProbes) {
2572 //   SharedRuntime::dtrace_method_entry(method, receiver);
2573 // }
2574 // if (RC_TRACE_IN_RANGE(0x00001000, 0x00002000)) {
2575 //   SharedRuntime::rc_trace_method_entry(method, receiver);
2576 // }
2577 
notify_method_entry()2578 void InterpreterMacroAssembler::notify_method_entry() {
2579 
2580   // Whenever JVMTI puts a thread in interp_only_mode, method
2581   // entry/exit events are sent for that thread to track stack
2582   // depth.  If it is possible to enter interp_only_mode we add
2583   // the code to check if the event should be sent.
2584   if (JvmtiExport::can_post_interpreter_events()) {
2585     Label L;
2586     Register temp_reg = O5;
2587     const Address interp_only(G2_thread, JavaThread::interp_only_mode_offset());
2588     ld(interp_only, temp_reg);
2589     cmp_and_br_short(temp_reg, 0, equal, pt, L);
2590     call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_entry));
2591     bind(L);
2592   }
2593 
2594   {
2595     Register temp_reg = O5;
2596     SkipIfEqual skip_if(this, temp_reg, &DTraceMethodProbes, zero);
2597     call_VM_leaf(noreg,
2598       CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry),
2599       G2_thread, Lmethod);
2600   }
2601 
2602   // RedefineClasses() tracing support for obsolete method entry
2603   if (log_is_enabled(Trace, redefine, class, obsolete)) {
2604     call_VM_leaf(noreg,
2605       CAST_FROM_FN_PTR(address, SharedRuntime::rc_trace_method_entry),
2606       G2_thread, Lmethod);
2607   }
2608 }
2609 
2610 
2611 // Inline assembly for:
2612 //
2613 // if (thread is in interp_only_mode) {
2614 //   // save result
2615 //   InterpreterRuntime::post_method_exit();
2616 //   // restore result
2617 // }
2618 // if (DTraceMethodProbes) {
2619 //   SharedRuntime::dtrace_method_exit(thread, method);
2620 // }
2621 //
2622 // Native methods have their result stored in d_tmp and l_tmp
2623 // Java methods have their result stored in the expression stack
2624 
notify_method_exit(bool is_native_method,TosState state,NotifyMethodExitMode mode)2625 void InterpreterMacroAssembler::notify_method_exit(bool is_native_method,
2626                                                    TosState state,
2627                                                    NotifyMethodExitMode mode) {
2628 
2629   // Whenever JVMTI puts a thread in interp_only_mode, method
2630   // entry/exit events are sent for that thread to track stack
2631   // depth.  If it is possible to enter interp_only_mode we add
2632   // the code to check if the event should be sent.
2633   if (mode == NotifyJVMTI && JvmtiExport::can_post_interpreter_events()) {
2634     Label L;
2635     Register temp_reg = O5;
2636     const Address interp_only(G2_thread, JavaThread::interp_only_mode_offset());
2637     ld(interp_only, temp_reg);
2638     cmp_and_br_short(temp_reg, 0, equal, pt, L);
2639 
2640     // Note: frame::interpreter_frame_result has a dependency on how the
2641     // method result is saved across the call to post_method_exit. For
2642     // native methods it assumes the result registers are saved to
2643     // l_scratch and d_scratch. If this changes then the interpreter_frame_result
2644     // implementation will need to be updated too.
2645 
2646     save_return_value(state, is_native_method);
2647     call_VM(noreg,
2648             CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_exit));
2649     restore_return_value(state, is_native_method);
2650     bind(L);
2651   }
2652 
2653   {
2654     Register temp_reg = O5;
2655     // Dtrace notification
2656     SkipIfEqual skip_if(this, temp_reg, &DTraceMethodProbes, zero);
2657     save_return_value(state, is_native_method);
2658     call_VM_leaf(
2659       noreg,
2660       CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit),
2661       G2_thread, Lmethod);
2662     restore_return_value(state, is_native_method);
2663   }
2664 }
2665 
save_return_value(TosState state,bool is_native_call)2666 void InterpreterMacroAssembler::save_return_value(TosState state, bool is_native_call) {
2667   if (is_native_call) {
2668     stf(FloatRegisterImpl::D, F0, d_tmp);
2669     stx(O0, l_tmp);
2670   } else {
2671     push(state);
2672   }
2673 }
2674 
restore_return_value(TosState state,bool is_native_call)2675 void InterpreterMacroAssembler::restore_return_value( TosState state, bool is_native_call) {
2676   if (is_native_call) {
2677     ldf(FloatRegisterImpl::D, d_tmp, F0);
2678     ldx(l_tmp, O0);
2679   } else {
2680     pop(state);
2681   }
2682 }
2683